ResultDataMgr.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. //加载测量结果文件
  71. Dictionary<string, object> suggestions = DataOperation.DataAccess.XMLoperate.GetXMLAllInfo(str_path);
  72. string name = System.IO.Path.GetFileName(str_path);
  73. int workingid = (ResultFileId++);
  74. string path = System.IO.Path.GetDirectoryName(str_path);
  75. if (ResultFilesList.Find(s => s.FilePath == path) != null)
  76. {
  77. MessageBox.Show("Already have the same result!");
  78. return false;
  79. }
  80. string strname = UpdateName(name, ResultFilesList);
  81. if (strname == "")
  82. {
  83. MessageBox.Show("Already have the same result!");
  84. return false;
  85. }
  86. DataOperation.Model.ResultFile result = new DataOperation.Model.ResultFile()
  87. {
  88. FileId = workingid.ToString(),
  89. FileName = strname,
  90. FilePath = path,
  91. ResultInfo = suggestions
  92. };
  93. ResultFilesList.Add(result);
  94. SetWorkingResult(ResultFilesList.IndexOf(result));
  95. FieldData fieldData = new FieldData(path);
  96. List<Field> fieldlist = fieldData.GetFieldList();
  97. CurResultFile.List_OTSField = fieldlist;
  98. return true;
  99. }
  100. private string UpdateName(string name, List<ResultFile> ResultFilesList)
  101. {
  102. int reg = 51;
  103. if (ResultFilesList.Find(s => s.FileName == name) != null)
  104. {
  105. for (int i = 1; i < reg; i++)
  106. {
  107. string str = name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString();
  108. if (ResultFilesList.Find(s => s.FileName == str) == null)
  109. {
  110. return name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString();
  111. }
  112. }
  113. }
  114. else
  115. {
  116. return name;
  117. }
  118. return "";
  119. }
  120. #endregion
  121. #region 获取组合项相关方法
  122. /// <summary>
  123. /// 根据系统设置的默认粒级表路径,获取所有的粒级表文件List
  124. /// </summary>
  125. /// <returns></returns>
  126. public List<string> GetPartSizeFileList()
  127. {
  128. List<string> ret_list = new List<string>();
  129. //遍历粒级文件夹
  130. DirectoryInfo theFolder = new DirectoryInfo(m_RptConfigFile.PartSizeFileFolder);
  131. if (!theFolder.Exists)
  132. return ret_list;
  133. //读取遍历粒级文件信息
  134. foreach (FileInfo nextifile in theFolder.GetFiles())
  135. {
  136. //找出粒级文件
  137. if (nextifile.Name.Contains(".psf") == true || nextifile.Name.Contains(".PSF") == true)
  138. {
  139. ret_list.Add(nextifile.Name);
  140. }
  141. }
  142. return ret_list;
  143. }
  144. public List<string> GetSTDIdList()
  145. {
  146. HashSet<string> stdSet = new HashSet<string>();
  147. stdSet.Add("All");
  148. foreach (var f in CurResultFile.List_OTSField)
  149. {
  150. foreach (var p in f.ParticleList)
  151. {
  152. if (!stdSet.Contains(p.TypeName))
  153. {
  154. stdSet.Add(p.TypeName);
  155. }
  156. }
  157. }
  158. return stdSet.ToList();
  159. }
  160. /// <summary>
  161. /// 根据系统设置默认的粒级表的路径,获取粒级表List
  162. /// </summary>
  163. /// <param name="path"></param>
  164. /// <returns></returns>
  165. public List<string> GetPartSizeList()
  166. {
  167. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(m_RptConfigFile.PartSizeFileFolder + m_RptConfigFile.PartSizeFile);
  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. /// 根据传入的粒级表目录,获取粒级表List
  185. /// </summary>
  186. /// <returns></returns>
  187. public List<string> GetPartSizeList(string path)
  188. {
  189. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(path);
  190. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  191. List<string> sizeList = new List<string>();
  192. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  193. {
  194. if (sizestr.Split(',')[i].Length > 0)
  195. {
  196. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  197. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  198. sizeList.Add(d1.ToString() + "~" + d2.ToString());
  199. }
  200. }
  201. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  202. sizeList.Add(d.ToString() + "~MAX");
  203. return sizeList;
  204. }
  205. /// <summary>
  206. /// 获取三元相图模板名称列表
  207. /// </summary>
  208. /// <returns></returns>
  209. public List<string> GetTriTemplateNameList()
  210. {
  211. string pathtpf = m_RptConfigFile.TrigTemplateFileFolder + m_RptConfigFile.TriTempFile;
  212. List<string> ret_list = new List<string>();
  213. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXmlData(pathtpf, "XMLData");
  214. DataTable dt = ds.Tables["Member"];
  215. foreach (DataRow item in dt.Rows)
  216. {
  217. if (item["TemplateName"].ToString() != "")
  218. {
  219. ret_list.Add(item["TemplateName"].ToString());
  220. }
  221. }
  222. return ret_list;
  223. }
  224. /// <summary>
  225. /// 获取测量结果名称列表
  226. /// </summary>
  227. /// <returns></returns>
  228. public List<string> GetSampleListName()
  229. {
  230. List<string> ret_list = new List<string>();
  231. var resultfileList = ResultFilesList;
  232. foreach (var item in resultfileList)
  233. {
  234. ret_list.Add(item.FileName);
  235. }
  236. if (m_ReportApp.MoreSource != "")
  237. {
  238. ret_list.Add(m_ReportApp.MoreSource);
  239. }
  240. return ret_list;
  241. }
  242. /// <summary>
  243. /// 获取计算方法列表
  244. /// </summary>
  245. /// <returns></returns>
  246. public List<string> GetSizeCalMethodTypeList()
  247. {
  248. List<string> ret_list = new List<string>() { "DMAX", "DMIN", "FERET", "CIRCLE" };
  249. return ret_list;
  250. }
  251. public List<string> ParticleRange()
  252. {
  253. List<string> pr_str = new List<string>() { "全部颗粒","选择颗粒" };
  254. return pr_str;
  255. }
  256. public List<string> getTableData()
  257. {
  258. List<string> strlist = new List<string>() { "Area", "DMAX", "Hardness", "AveGray" };
  259. return strlist;
  260. }
  261. #endregion
  262. #region [测量结果treeview]相关封装方法
  263. /// <summary>
  264. /// 获取测量结果treeview树测量结果名
  265. /// </summary>
  266. /// <returns></returns>
  267. public string GetSampleName()
  268. {
  269. //获取样品名
  270. String sWorkSampleName = ResultFilesList[GetWorkingResult()].FileName;
  271. if (null == sWorkSampleName)
  272. {
  273. return "";
  274. }
  275. return sWorkSampleName;
  276. }
  277. #endregion
  278. }
  279. }