ResultDataMgr.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. return ret_list;
  166. }
  167. public List<string> GetSTDIdList()
  168. {
  169. HashSet<string> stdSet = new HashSet<string>();
  170. stdSet.Add("All");
  171. foreach (var f in CurResultFile.List_OTSField)
  172. {
  173. foreach (var p in f.ParticleList)
  174. {
  175. if (!stdSet.Contains(p.TypeName))
  176. {
  177. stdSet.Add(p.TypeName);
  178. }
  179. }
  180. }
  181. return stdSet.ToList();
  182. }
  183. /// <summary>
  184. /// 根据系统设置默认的粒级表的路径,获取粒级表List
  185. /// </summary>
  186. /// <param name="path"></param>
  187. /// <returns></returns>
  188. public List<string> GetPartSizeList()
  189. {
  190. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(m_RptConfigFile.PartSizeFileFolder + m_RptConfigFile.PartSizeFile);
  191. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  192. List<string> sizeList = new List<string>();
  193. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  194. {
  195. if (sizestr.Split(',')[i].Length > 0)
  196. {
  197. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  198. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  199. sizeList.Add(d1.ToString() + "~" + d2.ToString());
  200. }
  201. }
  202. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  203. sizeList.Add(d.ToString() + "~MAX");
  204. return sizeList;
  205. }
  206. /// <summary>
  207. /// 根据传入的粒级表目录,获取粒级表List
  208. /// </summary>
  209. /// <returns></returns>
  210. public List<string> GetPartSizeList(string path)
  211. {
  212. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(path);
  213. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  214. List<string> sizeList = new List<string>();
  215. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  216. {
  217. if (sizestr.Split(',')[i].Length > 0)
  218. {
  219. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  220. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  221. sizeList.Add(d1.ToString() + "~" + d2.ToString());
  222. }
  223. }
  224. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  225. sizeList.Add(d.ToString() + "~MAX");
  226. return sizeList;
  227. }
  228. /// <summary>
  229. /// 获取三元相图模板名称列表
  230. /// </summary>
  231. /// <returns></returns>
  232. public List<string> GetTriTemplateNameList()
  233. {
  234. string pathtpf = m_RptConfigFile.TrigTemplateFileFolder + m_RptConfigFile.TriTempFile;
  235. List<string> ret_list = new List<string>();
  236. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXmlData(pathtpf, "XMLData");
  237. DataTable dt = ds.Tables["Member"];
  238. foreach (DataRow item in dt.Rows)
  239. {
  240. if (item["TemplateName"].ToString() != "")
  241. {
  242. ret_list.Add(item["TemplateName"].ToString());
  243. }
  244. }
  245. return ret_list;
  246. }
  247. /// <summary>
  248. /// 获取测量结果名称列表
  249. /// </summary>
  250. /// <returns></returns>
  251. public string GetDefaultPartSize()
  252. {
  253. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(Application.StartupPath + m_RptConfigFile.ReportMgrParamFile);
  254. string sizestr = ds.Tables[1].Rows[3]["name"].ToString();
  255. return sizestr;
  256. }
  257. public string GetDefaultTRIO_CHART_TYPE()
  258. {
  259. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(Application.StartupPath + m_RptConfigFile.ReportMgrParamFile);
  260. string sizestr = ds.Tables[1].Rows[4]["strValue"].ToString();
  261. return sizestr;
  262. }
  263. public string GetDefaultSIZE_CAL_METHOD_TYPE()
  264. {
  265. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(Application.StartupPath + m_RptConfigFile.ReportMgrParamFile);
  266. string sizestr = ds.Tables[1].Rows[5]["strValue"].ToString();
  267. return sizestr;
  268. }
  269. /// <summary>
  270. /// 获取计算方法列表
  271. /// </summary>
  272. /// <returns></returns>
  273. public List<string> GetSizeCalMethodTypeList()
  274. {
  275. List<string> ret_list = new List<string>() { "DMAX", "DMIN", "FERET", "ECD" };
  276. return ret_list;
  277. }
  278. public List<string> ParticleRange()
  279. {
  280. List<string> pr_str = new List<string>() { "全部颗粒","选择颗粒" };
  281. return pr_str;
  282. }
  283. public List<string> getTableData()
  284. {
  285. List<string> strlist = new List<string>() { "Area", "DMAX", "Hardness", "AveGray" };
  286. return strlist;
  287. }
  288. public List<string> getTableData_INCA()
  289. {
  290. List<string> strlist = new List<string>() { "Area", "DMAX", "AveGray" };
  291. return strlist;
  292. }
  293. public List<string> getTableData_CleannessA()
  294. {
  295. List<string> strlist = new List<string>() { "Area", "DMAX", "Hardness", "AveGray" };
  296. return strlist;
  297. }
  298. #endregion
  299. #region [测量结果treeview]相关封装方法
  300. /// <summary>
  301. /// 获取测量结果treeview树测量结果名
  302. /// </summary>
  303. /// <returns></returns>
  304. public string GetSampleName()
  305. {
  306. //获取样品名
  307. String sWorkSampleName = ResultFilesList[GetWorkingResultId()].anotherFileName;
  308. if (null == sWorkSampleName)
  309. {
  310. return "";
  311. }
  312. return sWorkSampleName;
  313. }
  314. #endregion
  315. }
  316. }