ResultDataMgr.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using OTSCLRINTERFACE;
  2. using OTSIncAReportApp.DataOperation.DataAccess;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Windows.Forms;
  6. using OTSCommon.DBOperate.Model;
  7. namespace OTSIncAReportApp.OTSRstMgrFunction
  8. {
  9. /// <summary>
  10. /// 框架与底层进行交互的操作类
  11. /// </summary>
  12. public class ResultDataMgr
  13. {
  14. #region 变量定义
  15. /// <summary>
  16. /// 报告主进程框架对象
  17. /// </summary>
  18. public CReportMgrClr m_ReportMgr;
  19. private List<ResultFile> resultFilesList = new List<ResultFile>(); //测量结果列表
  20. private int workingResultId = -1;
  21. public RptConfigFile m_RptConfigFile = RptConfigFile.GetRptConfig(); //报表程序的配置文件
  22. #endregion
  23. private ResultFile m_curResultFile;
  24. public int GetWorkingResultId()
  25. {
  26. return workingResultId;
  27. }
  28. public void SetWorkingResultId(int value)
  29. {
  30. if (resultFilesList.Count > 0)
  31. {
  32. workingResultId = value;
  33. m_curResultFile = resultFilesList[value];
  34. }
  35. }
  36. public ResultFile GetResultFileObjByName(string rstName)
  37. {
  38. ResultFile rst = null;
  39. foreach (var r in resultFilesList)
  40. {
  41. if (r.FileName_real == rstName)
  42. {
  43. rst = r;
  44. }
  45. }
  46. return rst;
  47. }
  48. public List<ResultFile> ResultFilesList { get => resultFilesList; set => resultFilesList = value; }
  49. public ResultFile CurResultFile { get => m_curResultFile; set => m_curResultFile = value; }
  50. #region 构造函数
  51. /// <summary>
  52. /// 构造函数
  53. /// </summary>
  54. /// <param name="ReportApp"></param>
  55. public ResultDataMgr()
  56. {
  57. if (null == m_ReportMgr)
  58. {
  59. m_ReportMgr = new CReportMgrClr();
  60. }
  61. }
  62. public bool AddDataResult(string str_path)
  63. {
  64. //加载测量结果文件
  65. Dictionary<string, object> suggestions = DataOperation.DataAccess.XMLoperate.GetXMLAllInfo(str_path);
  66. string name = System.IO.Path.GetFileName(str_path);
  67. int workingid = ResultFilesList.Count + 1;
  68. string path = System.IO.Path.GetDirectoryName(str_path);
  69. if (ResultFilesList.Find(s => s.FilePath == path) != null)
  70. {
  71. MessageBox.Show("Already have the same result!");
  72. return false;
  73. }
  74. string strname = UpdateName(name, ResultFilesList);
  75. if (strname == "")
  76. {
  77. MessageBox.Show("Already have the same result!");
  78. return false;
  79. }
  80. ResultFile result = new ResultFile()
  81. {
  82. FileId = workingid.ToString(),
  83. anotherFileName = strname,
  84. FileName_real=name,
  85. FilePath = path,
  86. };
  87. result.SetResultInfoDic(suggestions);
  88. ResultFilesList.Add(result);
  89. SetWorkingResultId(ResultFilesList.IndexOf(result));
  90. FieldData fieldData = new FieldData(path);
  91. List<Field> fieldlist = fieldData.GetFieldList();
  92. CurResultFile.SetList_OTSField(fieldlist);
  93. return true;
  94. }
  95. public void RemoveDataResult(string fileName)
  96. {
  97. ResultFile rst=null;
  98. foreach (var r in resultFilesList)
  99. {
  100. if (r.FileName_real == fileName)
  101. {
  102. rst = r;
  103. }
  104. }
  105. if (rst != null)
  106. {
  107. resultFilesList.Remove(rst);
  108. workingResultId = 0;
  109. }
  110. else
  111. {
  112. workingResultId =-1;
  113. }
  114. }
  115. private string UpdateName(string name, List<ResultFile> ResultFilesList)
  116. {
  117. int reg = 51;
  118. if (ResultFilesList.Find(s => s.anotherFileName == name) != null)
  119. {
  120. for (int i = 1; i < reg; i++)
  121. {
  122. string str = name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString();
  123. if (ResultFilesList.Find(s => s.anotherFileName == str) == null)
  124. {
  125. return name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString();
  126. }
  127. }
  128. }
  129. else
  130. {
  131. return name;
  132. }
  133. return "";
  134. }
  135. #endregion
  136. public string GetSampleName()
  137. {
  138. String sWorkSampleName = ResultFilesList[GetWorkingResultId()].anotherFileName;
  139. if (null == sWorkSampleName)
  140. {
  141. return "";
  142. }
  143. return sWorkSampleName;
  144. }
  145. }
  146. }