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