ResultDataMgr.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. using OTSCLRINTERFACE;
  2. using OTSIncAReportApp.DataOperation.DataAccess;
  3. using OTSCommon.Model;
  4. using OTSIncAReportApp.OTSSampleReportInfo;
  5. using OTSIncAReportApp.SysMgrTools;
  6. using OTSIncAReportGraph.OTSIncAReportGraphFuncation;
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Windows.Forms;
  14. namespace OTSIncAReportApp.OTSDataMgrFunction
  15. {
  16. /// <summary>
  17. /// 框架与底层进行交互的操作类
  18. /// </summary>
  19. public class ResultDataMgr
  20. {
  21. #region 变量定义
  22. public static string m_ReportMgrParamFile = "\\Config\\SysData\\OTSReportMgrParam.rpf"; //报告对应使用的参数文件名
  23. /// <summary>
  24. /// 报告主进程框架对象
  25. /// </summary>
  26. private frmReportApp m_ReportApp = null;
  27. public CReportMgrClr m_ReportMgr;
  28. private List<ResultFile> resultFilesList = new List<ResultFile>(); //测量结果列表
  29. private int workingResult = -1;
  30. private int SelectedIndex = 0;
  31. public RptConfigFile m_RptConfigFile = new RptConfigFile(Application.StartupPath +m_ReportMgrParamFile); //报表程序的配置文件
  32. #endregion
  33. int ResultFileId = 0;
  34. private ResultFile m_curResultFile;
  35. public int GetWorkingResult()
  36. {
  37. return workingResult;
  38. }
  39. public void SetWorkingResult(int value)
  40. {
  41. workingResult = value;
  42. m_curResultFile = resultFilesList[value];
  43. }
  44. public void setSelectedIndex(int value)
  45. {
  46. SelectedIndex = value;
  47. }
  48. public int getSelectedIndex()
  49. {
  50. return SelectedIndex;
  51. }
  52. public List<ResultFile> ResultFilesList { get => resultFilesList; set => resultFilesList = value; }
  53. public ResultFile CurResultFile { get => m_curResultFile; set => m_curResultFile = value; }
  54. #region 构造函数
  55. /// <summary>
  56. /// 构造函数
  57. /// </summary>
  58. /// <param name="ReportApp"></param>
  59. public ResultDataMgr(frmReportApp ReportApp)
  60. {
  61. m_ReportApp = ReportApp;
  62. if (null == m_ReportMgr)
  63. {
  64. //初始化相关变量
  65. m_ReportMgr = new CReportMgrClr();
  66. }
  67. }
  68. public bool AddDataResult(string str_path)
  69. {
  70. //加载测量结果文件
  71. Dictionary<string, object> suggestions = DataOperation.DataAccess.XMLoperate.GetXMLAllInfo(str_path);
  72. string name = System.IO.Path.GetFileName(str_path);
  73. int workingid = (ResultFileId++);
  74. string path = System.IO.Path.GetDirectoryName(str_path);
  75. if (ResultFilesList.Find(s => s.FilePath == path) != null)
  76. {
  77. MessageBox.Show("Already have the same result!");
  78. return false;
  79. }
  80. string strname = UpdateName(name, ResultFilesList);
  81. if (strname == "")
  82. {
  83. MessageBox.Show("Already have the same result!");
  84. return false;
  85. }
  86. ResultFile result = new ResultFile()
  87. {
  88. FileId = workingid.ToString(),
  89. anotherFileName = strname,
  90. FileName_real=name,
  91. FilePath = path,
  92. ResultInfo = suggestions
  93. };
  94. ResultFilesList.Add(result);
  95. SetWorkingResult(ResultFilesList.IndexOf(result));
  96. FieldData fieldData = new FieldData(path);
  97. List<Field> fieldlist = fieldData.GetFieldList();
  98. CurResultFile.List_OTSField = fieldlist;
  99. //new OTSImageDisHelp(CurResultFile);
  100. return true;
  101. }
  102. private string UpdateName(string name, List<ResultFile> ResultFilesList)
  103. {
  104. int reg = 51;
  105. if (ResultFilesList.Find(s => s.anotherFileName == name) != null)
  106. {
  107. for (int i = 1; i < reg; i++)
  108. {
  109. string str = name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString();
  110. if (ResultFilesList.Find(s => s.anotherFileName == str) == null)
  111. {
  112. return name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString();
  113. }
  114. }
  115. }
  116. else
  117. {
  118. return name;
  119. }
  120. return "";
  121. }
  122. #endregion
  123. #region 获取组合项相关方法
  124. /// <summary>
  125. /// 根据系统设置的默认粒级表路径,获取所有的粒级表文件List
  126. /// </summary>
  127. /// <returns></returns>
  128. public List<string> GetPartSizeFileList()
  129. {
  130. List<string> ret_list = new List<string>();
  131. //遍历粒级文件夹
  132. DirectoryInfo theFolder = new DirectoryInfo(m_RptConfigFile.PartSizeFileFolder);
  133. if (!theFolder.Exists)
  134. return ret_list;
  135. //读取遍历粒级文件信息
  136. foreach (FileInfo nextifile in theFolder.GetFiles())
  137. {
  138. //找出粒级文件
  139. if (nextifile.Name.Contains(".psf") == true || nextifile.Name.Contains(".PSF") == true)
  140. {
  141. ret_list.Add(nextifile.Name);
  142. }
  143. }
  144. return ret_list;
  145. }
  146. public List<string> GetSTDIdList()
  147. {
  148. HashSet<string> stdSet = new HashSet<string>();
  149. stdSet.Add("All");
  150. foreach (var f in CurResultFile.List_OTSField)
  151. {
  152. foreach (var p in f.ParticleList)
  153. {
  154. if (!stdSet.Contains(p.TypeName))
  155. {
  156. stdSet.Add(p.TypeName);
  157. }
  158. }
  159. }
  160. return stdSet.ToList();
  161. }
  162. /// <summary>
  163. /// 根据系统设置默认的粒级表的路径,获取粒级表List
  164. /// </summary>
  165. /// <param name="path"></param>
  166. /// <returns></returns>
  167. public List<string> GetPartSizeList()
  168. {
  169. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(m_RptConfigFile.PartSizeFileFolder + m_RptConfigFile.PartSizeFile);
  170. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  171. List<string> sizeList = new List<string>();
  172. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  173. {
  174. if (sizestr.Split(',')[i].Length > 0)
  175. {
  176. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  177. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  178. sizeList.Add(d1.ToString() + "~" + d2.ToString());
  179. }
  180. }
  181. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  182. sizeList.Add(d.ToString() + "~MAX");
  183. return sizeList;
  184. }
  185. /// <summary>
  186. /// 根据传入的粒级表目录,获取粒级表List
  187. /// </summary>
  188. /// <returns></returns>
  189. public List<string> GetPartSizeList(string path)
  190. {
  191. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(path);
  192. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  193. List<string> sizeList = new List<string>();
  194. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  195. {
  196. if (sizestr.Split(',')[i].Length > 0)
  197. {
  198. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  199. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  200. sizeList.Add(d1.ToString() + "~" + d2.ToString());
  201. }
  202. }
  203. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  204. sizeList.Add(d.ToString() + "~MAX");
  205. return sizeList;
  206. }
  207. /// <summary>
  208. /// 获取三元相图模板名称列表
  209. /// </summary>
  210. /// <returns></returns>
  211. public List<string> GetTriTemplateNameList()
  212. {
  213. string pathtpf = m_RptConfigFile.TrigTemplateFileFolder + m_RptConfigFile.TriTempFile;
  214. List<string> ret_list = new List<string>();
  215. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXmlData(pathtpf, "XMLData");
  216. DataTable dt = ds.Tables["Member"];
  217. foreach (DataRow item in dt.Rows)
  218. {
  219. if (item["TemplateName"].ToString() != "")
  220. {
  221. ret_list.Add(item["TemplateName"].ToString());
  222. }
  223. }
  224. return ret_list;
  225. }
  226. /// <summary>
  227. /// 获取测量结果名称列表
  228. /// </summary>
  229. /// <returns></returns>
  230. public List<string> GetSampleListName()
  231. {
  232. List<string> ret_list = new List<string>();
  233. var resultfileList = ResultFilesList;
  234. foreach (var item in resultfileList)
  235. {
  236. ret_list.Add(item.anotherFileName);
  237. }
  238. if (m_ReportApp.MoreSource != "")
  239. {
  240. ret_list.Add(m_ReportApp.MoreSource);
  241. }
  242. return ret_list;
  243. }
  244. /// <summary>
  245. /// 获取计算方法列表
  246. /// </summary>
  247. /// <returns></returns>
  248. public List<string> GetSizeCalMethodTypeList()
  249. {
  250. List<string> ret_list = new List<string>() { "DMAX", "DMIN", "FERET", "CIRCLE" };
  251. return ret_list;
  252. }
  253. public List<string> ParticleRange()
  254. {
  255. List<string> pr_str = new List<string>() { "全部颗粒","选择颗粒" };
  256. return pr_str;
  257. }
  258. public List<string> getTableData()
  259. {
  260. List<string> strlist = new List<string>() { "Area", "DMAX", "Hardness", "AveGray" };
  261. return strlist;
  262. }
  263. #endregion
  264. #region [测量结果treeview]相关封装方法
  265. /// <summary>
  266. /// 获取测量结果treeview树测量结果名
  267. /// </summary>
  268. /// <returns></returns>
  269. public string GetSampleName()
  270. {
  271. //获取样品名
  272. String sWorkSampleName = ResultFilesList[GetWorkingResult()].anotherFileName;
  273. if (null == sWorkSampleName)
  274. {
  275. return "";
  276. }
  277. return sWorkSampleName;
  278. }
  279. #endregion
  280. }
  281. }