ResultDataMgr.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. /// <summary>
  23. /// 报告主进程框架对象
  24. /// </summary>
  25. private frmReportApp m_ReportApp = null;
  26. public CReportMgrClr m_ReportMgr;
  27. private List<ResultFile> resultFilesList = new List<ResultFile>(); //测量结果列表
  28. private int workingResultId = -1;
  29. private int SelectedIndex = 0;
  30. public RptConfigFile m_RptConfigFile = RptConfigFile.GetRptConfig(); //报表程序的配置文件
  31. #endregion
  32. private ResultFile m_curResultFile;
  33. public int GetWorkingResultId()
  34. {
  35. return workingResultId;
  36. }
  37. public void SetWorkingResultId(int value)
  38. {
  39. if (resultFilesList.Count > 0)
  40. {
  41. workingResultId = value;
  42. m_curResultFile = resultFilesList[value];
  43. }
  44. }
  45. public void setSelectedIndex(int value)
  46. {
  47. SelectedIndex = value;
  48. }
  49. public int getSelectedIndex()
  50. {
  51. return SelectedIndex;
  52. }
  53. public ResultFile GetResultFileObjByName(string rstName)
  54. {
  55. ResultFile rst = null;
  56. foreach (var r in resultFilesList)
  57. {
  58. if (r.FileName_real == rstName)
  59. {
  60. rst = r;
  61. }
  62. }
  63. return rst;
  64. }
  65. public List<ResultFile> ResultFilesList { get => resultFilesList; set => resultFilesList = value; }
  66. public ResultFile CurResultFile { get => m_curResultFile; set => m_curResultFile = value; }
  67. #region 构造函数
  68. /// <summary>
  69. /// 构造函数
  70. /// </summary>
  71. /// <param name="ReportApp"></param>
  72. public ResultDataMgr(frmReportApp ReportApp)
  73. {
  74. m_ReportApp = ReportApp;
  75. if (null == m_ReportMgr)
  76. {
  77. //初始化相关变量
  78. m_ReportMgr = new CReportMgrClr();
  79. }
  80. }
  81. public bool AddDataResult(string str_path)
  82. {
  83. //加载测量结果文件
  84. Dictionary<string, object> suggestions = DataOperation.DataAccess.XMLoperate.GetXMLAllInfo(str_path);
  85. string name = System.IO.Path.GetFileName(str_path);
  86. int workingid = ResultFilesList.Count + 1;
  87. string path = System.IO.Path.GetDirectoryName(str_path);
  88. if (ResultFilesList.Find(s => s.FilePath == path) != null)
  89. {
  90. MessageBox.Show("Already have the same result!");
  91. return false;
  92. }
  93. string strname = UpdateName(name, ResultFilesList);
  94. if (strname == "")
  95. {
  96. MessageBox.Show("Already have the same result!");
  97. return false;
  98. }
  99. ResultFile result = new ResultFile()
  100. {
  101. FileId = workingid.ToString(),
  102. anotherFileName = strname,
  103. FileName_real=name,
  104. FilePath = path,
  105. };
  106. result.SetResultInfoDic(suggestions);
  107. ResultFilesList.Add(result);
  108. SetWorkingResultId(ResultFilesList.IndexOf(result));
  109. FieldData fieldData = new FieldData(path);
  110. List<Field> fieldlist = fieldData.GetFieldList();
  111. CurResultFile.List_OTSField = fieldlist;
  112. return true;
  113. }
  114. public void RemoveDataResult(string fileName)
  115. {
  116. ResultFile rst=null;
  117. foreach (var r in resultFilesList)
  118. {
  119. if (r.FileName_real == fileName)
  120. {
  121. rst = r;
  122. }
  123. }
  124. if (rst != null)
  125. {
  126. resultFilesList.Remove(rst);
  127. workingResultId = 0;
  128. }
  129. else
  130. {
  131. workingResultId =-1;
  132. }
  133. }
  134. private string UpdateName(string name, List<ResultFile> ResultFilesList)
  135. {
  136. int reg = 51;
  137. if (ResultFilesList.Find(s => s.anotherFileName == name) != null)
  138. {
  139. for (int i = 1; i < reg; i++)
  140. {
  141. string str = name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString();
  142. if (ResultFilesList.Find(s => s.anotherFileName == str) == null)
  143. {
  144. return name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString();
  145. }
  146. }
  147. }
  148. else
  149. {
  150. return name;
  151. }
  152. return "";
  153. }
  154. #endregion
  155. #region 获取组合项相关方法
  156. /// <summary>
  157. /// 根据系统设置的默认粒级表路径,获取所有的粒级表文件List
  158. /// </summary>
  159. /// <returns></returns>
  160. public List<string> GetPartSizeFileList()
  161. {
  162. List<string> ret_list = new List<string>();
  163. //遍历粒级文件夹
  164. DirectoryInfo theFolder = new DirectoryInfo(m_RptConfigFile.PartSizeFileFolder);
  165. if (!theFolder.Exists)
  166. return ret_list;
  167. //读取遍历粒级文件信息
  168. foreach (FileInfo nextifile in theFolder.GetFiles())
  169. {
  170. //找出粒级文件
  171. if (nextifile.Name.Contains(".psf") == true || nextifile.Name.Contains(".PSF") == true)
  172. {
  173. ret_list.Add(nextifile.Name);
  174. }
  175. }
  176. return ret_list;
  177. }
  178. public List<string> GetSTDIdList()
  179. {
  180. HashSet<string> stdSet = new HashSet<string>();
  181. stdSet.Add("All");
  182. foreach (var f in CurResultFile.List_OTSField)
  183. {
  184. foreach (var p in f.ParticleList)
  185. {
  186. if (!stdSet.Contains(p.TypeName))
  187. {
  188. stdSet.Add(p.TypeName);
  189. }
  190. }
  191. }
  192. return stdSet.ToList();
  193. }
  194. /// <summary>
  195. /// 根据系统设置默认的粒级表的路径,获取粒级表List
  196. /// </summary>
  197. /// <param name="path"></param>
  198. /// <returns></returns>
  199. public List<string> GetPartSizeList()
  200. {
  201. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(m_RptConfigFile.PartSizeFileFolder + m_RptConfigFile.PartSizeFile);
  202. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  203. List<string> sizeList = new List<string>();
  204. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  205. {
  206. if (sizestr.Split(',')[i].Length > 0)
  207. {
  208. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  209. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  210. sizeList.Add(d1.ToString() + "~" + d2.ToString());
  211. }
  212. }
  213. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  214. sizeList.Add(d.ToString() + "~MAX");
  215. return sizeList;
  216. }
  217. /// <summary>
  218. /// 根据传入的粒级表目录,获取粒级表List
  219. /// </summary>
  220. /// <returns></returns>
  221. public List<string> GetPartSizeList(string path)
  222. {
  223. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(path);
  224. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  225. List<string> sizeList = new List<string>();
  226. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  227. {
  228. if (sizestr.Split(',')[i].Length > 0)
  229. {
  230. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  231. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  232. sizeList.Add(d1.ToString() + "~" + d2.ToString());
  233. }
  234. }
  235. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  236. sizeList.Add(d.ToString() + "~MAX");
  237. return sizeList;
  238. }
  239. /// <summary>
  240. /// 获取三元相图模板名称列表
  241. /// </summary>
  242. /// <returns></returns>
  243. public List<string> GetTriTemplateNameList()
  244. {
  245. string pathtpf = m_RptConfigFile.TrigTemplateFileFolder + m_RptConfigFile.TriTempFile;
  246. List<string> ret_list = new List<string>();
  247. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXmlData(pathtpf, "XMLData");
  248. DataTable dt = ds.Tables["Member"];
  249. foreach (DataRow item in dt.Rows)
  250. {
  251. if (item["TemplateName"].ToString() != "")
  252. {
  253. ret_list.Add(item["TemplateName"].ToString());
  254. }
  255. }
  256. return ret_list;
  257. }
  258. /// <summary>
  259. /// 获取测量结果名称列表
  260. /// </summary>
  261. /// <returns></returns>
  262. public List<string> GetSampleListName()
  263. {
  264. List<string> ret_list = new List<string>();
  265. var resultfileList = ResultFilesList;
  266. foreach (var item in resultfileList)
  267. {
  268. ret_list.Add(item.anotherFileName);
  269. }
  270. if (m_ReportApp.MoreSource != "")
  271. {
  272. ret_list.Add(m_ReportApp.MoreSource);
  273. }
  274. return ret_list;
  275. }
  276. /// <summary>
  277. /// 获取计算方法列表
  278. /// </summary>
  279. /// <returns></returns>
  280. public List<string> GetSizeCalMethodTypeList()
  281. {
  282. List<string> ret_list = new List<string>() { "DMAX", "DMIN", "FERET", "ECD" };
  283. return ret_list;
  284. }
  285. public List<string> ParticleRange()
  286. {
  287. List<string> pr_str = new List<string>() { "全部颗粒","选择颗粒" };
  288. return pr_str;
  289. }
  290. public List<string> getTableData()
  291. {
  292. List<string> strlist = new List<string>() { "Area", "DMAX", "Hardness", "AveGray" };
  293. return strlist;
  294. }
  295. public List<string> getTableData_INCA()
  296. {
  297. List<string> strlist = new List<string>() { "Area", "DMAX", "AveGray" };
  298. return strlist;
  299. }
  300. public List<string> getTableData_CleannessA()
  301. {
  302. List<string> strlist = new List<string>() { "Area", "DMAX", "Hardness", "AveGray" };
  303. return strlist;
  304. }
  305. #endregion
  306. #region [测量结果treeview]相关封装方法
  307. /// <summary>
  308. /// 获取测量结果treeview树测量结果名
  309. /// </summary>
  310. /// <returns></returns>
  311. public string GetSampleName()
  312. {
  313. //获取样品名
  314. String sWorkSampleName = ResultFilesList[GetWorkingResultId()].anotherFileName;
  315. if (null == sWorkSampleName)
  316. {
  317. return "";
  318. }
  319. return sWorkSampleName;
  320. }
  321. #endregion
  322. }
  323. }