ResultDataMgr.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. using OTSCLRINTERFACE;
  2. using OTSIncAReportApp.DataOperation.DataAccess;
  3. using OTSCommon.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. /// <summary>
  23. /// 报告主进程框架对象
  24. /// </summary>
  25. private frmReportApp m_ReportApp = null;
  26. public CReportMgrClr m_ReportMgr;
  27. private List<ResultFile> resultFilesList = new List<ResultFile>(); //测量结果列表
  28. private int workingResult = -1;
  29. private int SelectedIndex = 0;
  30. public RptConfigFile m_RptConfigFile = new RptConfigFile(Application.StartupPath + RptConfigFile.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. if (resultFilesList.Count > 0)
  41. {
  42. workingResult = value;
  43. m_curResultFile = resultFilesList[value];
  44. }
  45. }
  46. public void setSelectedIndex(int value)
  47. {
  48. SelectedIndex = value;
  49. }
  50. public int getSelectedIndex()
  51. {
  52. return SelectedIndex;
  53. }
  54. public List<ResultFile> ResultFilesList { get => resultFilesList; set => resultFilesList = value; }
  55. public ResultFile CurResultFile { get => m_curResultFile; set => m_curResultFile = value; }
  56. #region 构造函数
  57. /// <summary>
  58. /// 构造函数
  59. /// </summary>
  60. /// <param name="ReportApp"></param>
  61. public ResultDataMgr(frmReportApp ReportApp)
  62. {
  63. m_ReportApp = ReportApp;
  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 = (ResultFileId++);
  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. ResultInfo = suggestions
  95. };
  96. ResultFilesList.Add(result);
  97. SetWorkingResult(ResultFilesList.IndexOf(result));
  98. FieldData fieldData = new FieldData(path);
  99. List<Field> fieldlist = fieldData.GetFieldList();
  100. CurResultFile.List_OTSField = fieldlist;
  101. //new OTSImageDisHelp(CurResultFile);
  102. return true;
  103. }
  104. public void RemoveDataResult(string fileName)
  105. {
  106. ResultFile rst=null;
  107. foreach (var r in resultFilesList)
  108. {
  109. if (r.FileName_real == fileName)
  110. {
  111. rst = r;
  112. }
  113. }
  114. if (rst != null)
  115. {
  116. resultFilesList.Remove(rst);
  117. workingResult = 0;
  118. }
  119. else
  120. {
  121. workingResult =-1;
  122. }
  123. }
  124. private string UpdateName(string name, List<ResultFile> ResultFilesList)
  125. {
  126. int reg = 51;
  127. if (ResultFilesList.Find(s => s.anotherFileName == name) != null)
  128. {
  129. for (int i = 1; i < reg; i++)
  130. {
  131. string str = name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString();
  132. if (ResultFilesList.Find(s => s.anotherFileName == str) == null)
  133. {
  134. return name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString();
  135. }
  136. }
  137. }
  138. else
  139. {
  140. return name;
  141. }
  142. return "";
  143. }
  144. #endregion
  145. #region 获取组合项相关方法
  146. /// <summary>
  147. /// 根据系统设置的默认粒级表路径,获取所有的粒级表文件List
  148. /// </summary>
  149. /// <returns></returns>
  150. public List<string> GetPartSizeFileList()
  151. {
  152. List<string> ret_list = new List<string>();
  153. //遍历粒级文件夹
  154. DirectoryInfo theFolder = new DirectoryInfo(m_RptConfigFile.PartSizeFileFolder);
  155. if (!theFolder.Exists)
  156. return ret_list;
  157. //读取遍历粒级文件信息
  158. foreach (FileInfo nextifile in theFolder.GetFiles())
  159. {
  160. //找出粒级文件
  161. if (nextifile.Name.Contains(".psf") == true || nextifile.Name.Contains(".PSF") == true)
  162. {
  163. ret_list.Add(nextifile.Name);
  164. }
  165. }
  166. return ret_list;
  167. }
  168. public List<string> GetSTDIdList()
  169. {
  170. HashSet<string> stdSet = new HashSet<string>();
  171. stdSet.Add("All");
  172. foreach (var f in CurResultFile.List_OTSField)
  173. {
  174. foreach (var p in f.ParticleList)
  175. {
  176. if (!stdSet.Contains(p.TypeName))
  177. {
  178. stdSet.Add(p.TypeName);
  179. }
  180. }
  181. }
  182. return stdSet.ToList();
  183. }
  184. /// <summary>
  185. /// 根据系统设置默认的粒级表的路径,获取粒级表List
  186. /// </summary>
  187. /// <param name="path"></param>
  188. /// <returns></returns>
  189. public List<string> GetPartSizeList()
  190. {
  191. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(m_RptConfigFile.PartSizeFileFolder + m_RptConfigFile.PartSizeFile);
  192. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  193. List<string> sizeList = new List<string>();
  194. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  195. {
  196. if (sizestr.Split(',')[i].Length > 0)
  197. {
  198. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  199. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  200. sizeList.Add(d1.ToString() + "~" + d2.ToString());
  201. }
  202. }
  203. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  204. sizeList.Add(d.ToString() + "~MAX");
  205. return sizeList;
  206. }
  207. /// <summary>
  208. /// 根据传入的粒级表目录,获取粒级表List
  209. /// </summary>
  210. /// <returns></returns>
  211. public List<string> GetPartSizeList(string path)
  212. {
  213. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(path);
  214. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  215. List<string> sizeList = new List<string>();
  216. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  217. {
  218. if (sizestr.Split(',')[i].Length > 0)
  219. {
  220. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  221. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  222. sizeList.Add(d1.ToString() + "~" + d2.ToString());
  223. }
  224. }
  225. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  226. sizeList.Add(d.ToString() + "~MAX");
  227. return sizeList;
  228. }
  229. /// <summary>
  230. /// 获取三元相图模板名称列表
  231. /// </summary>
  232. /// <returns></returns>
  233. public List<string> GetTriTemplateNameList()
  234. {
  235. string pathtpf = m_RptConfigFile.TrigTemplateFileFolder + m_RptConfigFile.TriTempFile;
  236. List<string> ret_list = new List<string>();
  237. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXmlData(pathtpf, "XMLData");
  238. DataTable dt = ds.Tables["Member"];
  239. foreach (DataRow item in dt.Rows)
  240. {
  241. if (item["TemplateName"].ToString() != "")
  242. {
  243. ret_list.Add(item["TemplateName"].ToString());
  244. }
  245. }
  246. return ret_list;
  247. }
  248. /// <summary>
  249. /// 获取测量结果名称列表
  250. /// </summary>
  251. /// <returns></returns>
  252. public List<string> GetSampleListName()
  253. {
  254. List<string> ret_list = new List<string>();
  255. var resultfileList = ResultFilesList;
  256. foreach (var item in resultfileList)
  257. {
  258. ret_list.Add(item.anotherFileName);
  259. }
  260. if (m_ReportApp.MoreSource != "")
  261. {
  262. ret_list.Add(m_ReportApp.MoreSource);
  263. }
  264. return ret_list;
  265. }
  266. /// <summary>
  267. /// 获取计算方法列表
  268. /// </summary>
  269. /// <returns></returns>
  270. public List<string> GetSizeCalMethodTypeList()
  271. {
  272. List<string> ret_list = new List<string>() { "DMAX", "DMIN", "FERET", "CIRCLE" };
  273. return ret_list;
  274. }
  275. public List<string> ParticleRange()
  276. {
  277. List<string> pr_str = new List<string>() { "全部颗粒","选择颗粒" };
  278. return pr_str;
  279. }
  280. public List<string> getTableData()
  281. {
  282. List<string> strlist = new List<string>() { "Area", "DMAX", "Hardness", "AveGray" };
  283. return strlist;
  284. }
  285. #endregion
  286. #region [测量结果treeview]相关封装方法
  287. /// <summary>
  288. /// 获取测量结果treeview树测量结果名
  289. /// </summary>
  290. /// <returns></returns>
  291. public string GetSampleName()
  292. {
  293. //获取样品名
  294. String sWorkSampleName = ResultFilesList[GetWorkingResult()].anotherFileName;
  295. if (null == sWorkSampleName)
  296. {
  297. return "";
  298. }
  299. return sWorkSampleName;
  300. }
  301. #endregion
  302. }
  303. }