ResultDataMgr.cs 13 KB

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