ResultDataMgr.cs 13 KB

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