ResultDataMgr.cs 11 KB

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