ResultDataMgr.cs 9.6 KB

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