ResultDataMgr.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. using OTSCLRINTERFACE;
  2. using OTSIncAReportApp.DataOperation.DataAccess;
  3. using OTSIncAReportApp.DataOperation.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. public static string m_ReportMgrParamFile = "\\Config\\SysData\\OTSReportMgrParam.rpf"; //报告对应使用的参数文件名
  23. /// <summary>
  24. /// 报告主进程框架对象
  25. /// </summary>
  26. private frmReportApp m_ReportApp = null;
  27. public CReportMgrClr m_ReportMgr;
  28. private List<ResultFile> resultFilesList = new List<ResultFile>(); //测量结果列表
  29. private int workingResult = -1;
  30. public DataOperation.Model.RptConfigFile m_RptConfigFile = new DataOperation.Model.RptConfigFile(Application.StartupPath +m_ReportMgrParamFile); //报表程序的配置文件
  31. #endregion
  32. int ResultFileId = 0;
  33. private ResultFile m_curResultFile;
  34. public int GetWorkingResult()
  35. {
  36. return workingResult;
  37. }
  38. public void SetWorkingResult(int value)
  39. {
  40. workingResult = value;
  41. m_curResultFile = resultFilesList[value];
  42. }
  43. public List<ResultFile> ResultFilesList { get => resultFilesList; set => resultFilesList = value; }
  44. public ResultFile CurResultFile { get => m_curResultFile; set => m_curResultFile = value; }
  45. #region 构造函数
  46. /// <summary>
  47. /// 构造函数
  48. /// </summary>
  49. /// <param name="ReportApp"></param>
  50. public ResultDataMgr(frmReportApp ReportApp)
  51. {
  52. m_ReportApp = ReportApp;
  53. if (null == m_ReportMgr)
  54. {
  55. //初始化相关变量
  56. m_ReportMgr = new CReportMgrClr();
  57. }
  58. }
  59. public bool AddDataResult(string str_path)
  60. {
  61. if (str_path == "")
  62. {
  63. return false;
  64. }
  65. //加载测量结果文件
  66. Dictionary<string, object> suggestions = DataOperation.DataAccess.XMLoperate.GetXMLAllInfo(str_path);
  67. string name = System.IO.Path.GetFileName(str_path);
  68. int workingid = (ResultFileId++);
  69. string path = System.IO.Path.GetDirectoryName(str_path);
  70. if (ResultFilesList.Find(s => s.FileName == name) != null)
  71. {
  72. MessageBox.Show("Already have the same result!");
  73. return false;
  74. }
  75. DataOperation.Model.ResultFile result = new DataOperation.Model.ResultFile()
  76. {
  77. FileId = workingid.ToString(),
  78. FileName = name,
  79. FilePath = path,
  80. ResultInfo = suggestions
  81. };
  82. ResultFilesList.Add(result);
  83. SetWorkingResult(ResultFilesList.IndexOf(result));
  84. FieldData fieldData = new FieldData(path);
  85. List<Field> fieldlist = fieldData.GetFieldList();
  86. CurResultFile.List_OTSField = fieldlist;
  87. return true;
  88. }
  89. #endregion
  90. #region 获取组合项相关方法
  91. /// <summary>
  92. /// 根据系统设置的默认粒级表路径,获取所有的粒级表文件List
  93. /// </summary>
  94. /// <returns></returns>
  95. public List<string> GetPartSizeFileList()
  96. {
  97. List<string> ret_list = new List<string>();
  98. //遍历粒级文件夹
  99. DirectoryInfo theFolder = new DirectoryInfo(m_RptConfigFile.FileFolderSize);
  100. if (!theFolder.Exists)
  101. return ret_list;
  102. //读取遍历粒级文件信息
  103. foreach (FileInfo nextifile in theFolder.GetFiles())
  104. {
  105. //找出粒级文件
  106. if (nextifile.Name.Contains(".psf") == true || nextifile.Name.Contains(".PSF") == true)
  107. {
  108. ret_list.Add(nextifile.Name);
  109. }
  110. }
  111. return ret_list;
  112. }
  113. public List<string> GetSTDIdList()
  114. {
  115. HashSet<string> stdSet = new HashSet<string>();
  116. stdSet.Add("All");
  117. foreach (var f in CurResultFile.List_OTSField)
  118. {
  119. foreach (var p in f.ParticleList)
  120. {
  121. if (!stdSet.Contains(p.TypeName))
  122. {
  123. stdSet.Add(p.TypeName);
  124. }
  125. }
  126. }
  127. return stdSet.ToList();
  128. }
  129. /// <summary>
  130. /// 根据系统设置默认的粒级表的路径,获取粒级表List
  131. /// </summary>
  132. /// <param name="path"></param>
  133. /// <returns></returns>
  134. public List<string> GetPartSizeList()
  135. {
  136. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(m_RptConfigFile.FileFolderSize + m_RptConfigFile.PartSizeFile);
  137. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  138. List<string> sizeList = new List<string>();
  139. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  140. {
  141. if (sizestr.Split(',')[i].Length > 0)
  142. {
  143. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  144. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  145. sizeList.Add(d1.ToString() + "~" + d2.ToString());
  146. }
  147. }
  148. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  149. sizeList.Add(d.ToString() + "~MAX");
  150. return sizeList;
  151. }
  152. /// <summary>
  153. /// 根据传入的粒级表目录,获取粒级表List
  154. /// </summary>
  155. /// <returns></returns>
  156. public List<string> GetPartSizeList(string path)
  157. {
  158. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(path);
  159. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  160. List<string> sizeList = new List<string>();
  161. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  162. {
  163. if (sizestr.Split(',')[i].Length > 0)
  164. {
  165. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  166. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  167. sizeList.Add(d1.ToString() + "~" + d2.ToString());
  168. }
  169. }
  170. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  171. sizeList.Add(d.ToString() + "~MAX");
  172. return sizeList;
  173. }
  174. /// <summary>
  175. /// 获取三元相图模板名称列表
  176. /// </summary>
  177. /// <returns></returns>
  178. public List<string> GetTriTemplateNameList()
  179. {
  180. string pathtpf = m_RptConfigFile.FileFolderTrigTemp + m_RptConfigFile.TriTempFile;
  181. List<string> ret_list = new List<string>();
  182. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXmlData(pathtpf, "XMLData");
  183. DataTable dt = ds.Tables["Member"];
  184. foreach (DataRow item in dt.Rows)
  185. {
  186. if (item["TemplateName"].ToString() != "")
  187. {
  188. ret_list.Add(item["TemplateName"].ToString());
  189. }
  190. }
  191. return ret_list;
  192. }
  193. /// <summary>
  194. /// 获取测量结果名称列表
  195. /// </summary>
  196. /// <returns></returns>
  197. public List<string> GetSampleListName()
  198. {
  199. List<string> ret_list = new List<string>();
  200. var resultfileList = ResultFilesList;
  201. foreach (var item in resultfileList)
  202. {
  203. ret_list.Add(item.FileName);
  204. }
  205. if (m_ReportApp.MoreSource != "")
  206. {
  207. ret_list.Add(m_ReportApp.MoreSource);
  208. }
  209. return ret_list;
  210. }
  211. /// <summary>
  212. /// 获取计算方法列表
  213. /// </summary>
  214. /// <returns></returns>
  215. public List<string> GetSizeCalMethodTypeList()
  216. {
  217. List<string> ret_list = new List<string>() { "DMAX", "DMIN", "CIRCLE", "FERET" };
  218. return ret_list;
  219. }
  220. public List<string> ParticleRange()
  221. {
  222. List<string> pr_str = new List<string>() { "全部颗粒","选择颗粒" };
  223. return pr_str;
  224. }
  225. #endregion
  226. #region [测量结果treeview]相关封装方法
  227. /// <summary>
  228. /// 获取测量结果treeview树测量结果名
  229. /// </summary>
  230. /// <returns></returns>
  231. public string GetSampleName()
  232. {
  233. //获取样品名
  234. String sWorkSampleName = ResultFilesList[GetWorkingResult()].FileName;
  235. if (null == sWorkSampleName)
  236. {
  237. return "";
  238. }
  239. return sWorkSampleName;
  240. }
  241. #endregion
  242. }
  243. }