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. //new OTSImageDisHelp(CurResultFile);
  99. return true;
  100. }
  101. private string UpdateName(string name, List<ResultFile> ResultFilesList)
  102. {
  103. int reg = 51;
  104. if (ResultFilesList.Find(s => s.FileName == name) != null)
  105. {
  106. for (int i = 1; i < reg; i++)
  107. {
  108. string str = name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString();
  109. if (ResultFilesList.Find(s => s.FileName == str) == null)
  110. {
  111. return name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString();
  112. }
  113. }
  114. }
  115. else
  116. {
  117. return name;
  118. }
  119. return "";
  120. }
  121. #endregion
  122. #region 获取组合项相关方法
  123. /// <summary>
  124. /// 根据系统设置的默认粒级表路径,获取所有的粒级表文件List
  125. /// </summary>
  126. /// <returns></returns>
  127. public List<string> GetPartSizeFileList()
  128. {
  129. List<string> ret_list = new List<string>();
  130. //遍历粒级文件夹
  131. DirectoryInfo theFolder = new DirectoryInfo(m_RptConfigFile.PartSizeFileFolder);
  132. if (!theFolder.Exists)
  133. return ret_list;
  134. //读取遍历粒级文件信息
  135. foreach (FileInfo nextifile in theFolder.GetFiles())
  136. {
  137. //找出粒级文件
  138. if (nextifile.Name.Contains(".psf") == true || nextifile.Name.Contains(".PSF") == true)
  139. {
  140. ret_list.Add(nextifile.Name);
  141. }
  142. }
  143. return ret_list;
  144. }
  145. public List<string> GetSTDIdList()
  146. {
  147. HashSet<string> stdSet = new HashSet<string>();
  148. stdSet.Add("All");
  149. foreach (var f in CurResultFile.List_OTSField)
  150. {
  151. foreach (var p in f.ParticleList)
  152. {
  153. if (!stdSet.Contains(p.TypeName))
  154. {
  155. stdSet.Add(p.TypeName);
  156. }
  157. }
  158. }
  159. return stdSet.ToList();
  160. }
  161. /// <summary>
  162. /// 根据系统设置默认的粒级表的路径,获取粒级表List
  163. /// </summary>
  164. /// <param name="path"></param>
  165. /// <returns></returns>
  166. public List<string> GetPartSizeList()
  167. {
  168. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(m_RptConfigFile.PartSizeFileFolder + m_RptConfigFile.PartSizeFile);
  169. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  170. List<string> sizeList = new List<string>();
  171. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  172. {
  173. if (sizestr.Split(',')[i].Length > 0)
  174. {
  175. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  176. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  177. sizeList.Add(d1.ToString() + "~" + d2.ToString());
  178. }
  179. }
  180. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  181. sizeList.Add(d.ToString() + "~MAX");
  182. return sizeList;
  183. }
  184. /// <summary>
  185. /// 根据传入的粒级表目录,获取粒级表List
  186. /// </summary>
  187. /// <returns></returns>
  188. public List<string> GetPartSizeList(string path)
  189. {
  190. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(path);
  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. /// 获取三元相图模板名称列表
  208. /// </summary>
  209. /// <returns></returns>
  210. public List<string> GetTriTemplateNameList()
  211. {
  212. string pathtpf = m_RptConfigFile.TrigTemplateFileFolder + m_RptConfigFile.TriTempFile;
  213. List<string> ret_list = new List<string>();
  214. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXmlData(pathtpf, "XMLData");
  215. DataTable dt = ds.Tables["Member"];
  216. foreach (DataRow item in dt.Rows)
  217. {
  218. if (item["TemplateName"].ToString() != "")
  219. {
  220. ret_list.Add(item["TemplateName"].ToString());
  221. }
  222. }
  223. return ret_list;
  224. }
  225. /// <summary>
  226. /// 获取测量结果名称列表
  227. /// </summary>
  228. /// <returns></returns>
  229. public List<string> GetSampleListName()
  230. {
  231. List<string> ret_list = new List<string>();
  232. var resultfileList = ResultFilesList;
  233. foreach (var item in resultfileList)
  234. {
  235. ret_list.Add(item.FileName);
  236. }
  237. if (m_ReportApp.MoreSource != "")
  238. {
  239. ret_list.Add(m_ReportApp.MoreSource);
  240. }
  241. return ret_list;
  242. }
  243. /// <summary>
  244. /// 获取计算方法列表
  245. /// </summary>
  246. /// <returns></returns>
  247. public List<string> GetSizeCalMethodTypeList()
  248. {
  249. List<string> ret_list = new List<string>() { "DMAX", "DMIN", "FERET", "CIRCLE" };
  250. return ret_list;
  251. }
  252. public List<string> ParticleRange()
  253. {
  254. List<string> pr_str = new List<string>() { "全部颗粒","选择颗粒" };
  255. return pr_str;
  256. }
  257. public List<string> getTableData()
  258. {
  259. List<string> strlist = new List<string>() { "Area", "DMAX", "Hardness", "AveGray" };
  260. return strlist;
  261. }
  262. #endregion
  263. #region [测量结果treeview]相关封装方法
  264. /// <summary>
  265. /// 获取测量结果treeview树测量结果名
  266. /// </summary>
  267. /// <returns></returns>
  268. public string GetSampleName()
  269. {
  270. //获取样品名
  271. String sWorkSampleName = ResultFilesList[GetWorkingResult()].FileName;
  272. if (null == sWorkSampleName)
  273. {
  274. return "";
  275. }
  276. return sWorkSampleName;
  277. }
  278. #endregion
  279. }
  280. }