BasicData.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. using OTSCommon.Model;
  2. using OTSIncAReportApp.DataOperation.DataAccess;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using static OTSIncAReportApp.OTSReport_Export;
  10. namespace OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration
  11. {
  12. class BasicData
  13. {
  14. ParticleData fielddata;
  15. private string SizeChart = "";
  16. private DataTable BData = new DataTable();
  17. private DataTable AllClass = new DataTable();
  18. private DataTable AllElement = new DataTable();
  19. private bool IsShereAClassificationGroup = false;
  20. /// <summary>
  21. /// 获取粒级表
  22. /// </summary>
  23. public void SetParticlesizeTable(OTSReport_Export m_otsreport_export)
  24. {
  25. //获取粒级表
  26. string path1 = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFileFolder +
  27. m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile;
  28. DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXml(path1);
  29. SizeChart = ds.Tables[0].Rows[0]["Sizes"].ToString();
  30. }
  31. /// <summary>
  32. /// 获取粒级表
  33. /// </summary>
  34. /// <returns></returns>
  35. public string GetParticlesizeTable()
  36. {
  37. return SizeChart;
  38. }
  39. public void SetDBData(c_TemplateClass m_mbszclass, OTSReport_Export m_otsreport_export, string ComputeMode)
  40. {
  41. DataTable m_bt_DBData = new DataTable();
  42. ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.getSelectedIndex()].FilePath);
  43. List<string> colid = new List<string>() { "TypeName", "ar", "TypeId", "Largest", "Class", "con" };
  44. //获取粒级表
  45. string path1 = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFileFolder +
  46. m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile;
  47. DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXml(path1);
  48. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  49. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  50. {
  51. if (sizestr.Split(',')[i].Length > 0)
  52. {
  53. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  54. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  55. colid.Add(d1.ToString() + "~" + d2.ToString());
  56. }
  57. }
  58. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  59. colid.Add(d.ToString() + "~MAX");
  60. for (int i = 0; i < colid.Count; i++)
  61. {
  62. m_bt_DBData.Columns.Add(colid[i].ToString());
  63. }
  64. DataTable dt = InvalidRemoval(fielddata.GetParticleListForParticlSize("area", ""));
  65. DataTable AreaInformationOfAllElements = InvalidRemoval(fielddata.GetAreaByAllIncA(""));
  66. DataTable dtp = InvalidRemoval(fielddata.GetParticleAll(""));
  67. string po = ComputeMode;
  68. switch (po)
  69. {
  70. case "DMAX":
  71. po = "DMAX";
  72. break;
  73. case "DMIN":
  74. po = "DMIN";
  75. break;
  76. case "ECD":
  77. po = "Area";
  78. break;
  79. case "FERET":
  80. po = "DFERET";
  81. break;
  82. }
  83. for (int i = 0; i < dt.Rows.Count; i++)
  84. {
  85. DataRow dr = m_bt_DBData.NewRow();
  86. dr["TypeName"] = dt.Rows[i]["TypeName"].ToString();
  87. dr["TypeId"] = dt.Rows[i]["TypeId"].ToString();
  88. dr["con"] = dt.Rows[i]["con"].ToString();
  89. if (dt.Rows[i]["GroupName"].ToString() == "")
  90. dr["Class"] = "Default";
  91. else
  92. dr["Class"] = dt.Rows[i]["GroupName"].ToString();
  93. //continue;
  94. dr["Largest"] = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  95. for (int a = 6; a < colid.Count; a++)
  96. {
  97. string d1 = colid[a].Split('~')[0];
  98. string d2 = colid[a].Split('~')[1];
  99. if (d2 == "MAX")
  100. {
  101. d2 = "999";
  102. }
  103. DataRow[] datas = dtp.Select(getWhere(d2, d1, po, dt.Rows[i]["TypeId"].ToString()));
  104. dr[colid[a]] = datas.Count();
  105. }
  106. for (int a = 0; a < AreaInformationOfAllElements.Rows.Count; a++)
  107. {
  108. if (dt.Rows[i]["TypeId"].ToString() == AreaInformationOfAllElements.Rows[a]["TypeId"].ToString())
  109. {
  110. dr["ar"] = AreaInformationOfAllElements.Rows[a]["ar"];
  111. }
  112. }
  113. m_bt_DBData.Rows.Add(dr);
  114. }
  115. //去除物质分类(非夹杂物分类)
  116. for (int a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass.Count; a++)
  117. {
  118. for (int i = m_bt_DBData.Rows.Count - 1; i >= 0; i--)
  119. {
  120. if (m_bt_DBData.Rows[i]["TypeName"].ToString() == m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass[a].ToString())
  121. {
  122. m_bt_DBData.Rows.RemoveAt(i);
  123. }
  124. }
  125. }
  126. if (m_mbszclass.list_str_MainPriority.Count == 0)
  127. {
  128. BData = m_bt_DBData.Copy();
  129. return;
  130. }
  131. DataTable datass = m_bt_DBData.Clone();
  132. for (int i = 0; i < m_mbszclass.list_str_MainPriority.Count; i++)
  133. {
  134. bool bl = false;
  135. for (int a = 0; a < m_bt_DBData.Rows.Count; a++)
  136. {
  137. if (m_bt_DBData.Rows[a]["TypeName"].ToString() == m_mbszclass.list_str_MainPriority[i])
  138. {
  139. datass.Rows.Add(m_bt_DBData.Rows[a].ItemArray);
  140. bl = true;
  141. continue;
  142. }
  143. }
  144. if (!bl)
  145. {
  146. DataTable dta = m_bt_DBData.Clone();
  147. if (m_bt_DBData.Rows.Count != 0)
  148. {
  149. dta.Rows.Add(m_bt_DBData.Rows[0].ItemArray);
  150. for (int b = 0; b < dta.Columns.Count; b++)
  151. {
  152. if (dta.Columns[b].ColumnName == "TypeName")
  153. {
  154. dta.Rows[0][b] = m_mbszclass.list_str_MainPriority[i];
  155. }
  156. else if (dta.Columns[b].ColumnName == "Class")
  157. {
  158. dta.Rows[0][b] = "Default";
  159. }
  160. else
  161. {
  162. dta.Rows[0][b] = 0;
  163. }
  164. }
  165. datass.Rows.Add(dta.Rows[0].ItemArray);
  166. }
  167. }
  168. }
  169. BData = datass.Copy();
  170. //return datass;
  171. }
  172. /// <summary>
  173. /// 获取读取数据库并过滤颗粒
  174. /// </summary>
  175. /// <returns></returns>
  176. public DataTable GetDBData()
  177. {
  178. return BData;
  179. }
  180. public void SetAllClass()
  181. {
  182. AllClass = fielddata.GetAllClass();
  183. }
  184. /// <summary>
  185. /// 获取全部大类
  186. /// </summary>
  187. /// <returns></returns>
  188. public DataTable GetAllClass()
  189. {
  190. return AllClass;
  191. }
  192. /// <summary>
  193. /// 定义ParticleData类
  194. /// </summary>
  195. public void newParticleData(OTSReport_Export m_otsreport_export)
  196. {
  197. fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.getSelectedIndex()].FilePath);
  198. }
  199. public ParticleData getParticleData()
  200. {
  201. return fielddata;
  202. }
  203. public void SetAllElement()
  204. {
  205. AllElement = fielddata.GetAllElement();
  206. }
  207. /// <summary>
  208. /// 获取全部元素
  209. /// </summary>
  210. /// <returns></returns>
  211. public DataTable GetAllElement()
  212. {
  213. return AllElement;
  214. }
  215. /// <summary>
  216. /// 判断是否有大分类,有为true
  217. /// </summary>
  218. /// <param name="m_otsreport_export"></param>
  219. /// <returns></returns>
  220. public void IsThereAMajorClassification()
  221. {
  222. DataTable getClass_dt = fielddata.GetAllClass();
  223. List<string> ClassName = new List<string>();
  224. bool bl = false;
  225. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  226. {
  227. if (getClass_dt.Rows[i]["GroupName"].ToString() != "NOT_INCLUTION" && getClass_dt.Rows[i]["GroupName"].ToString() != "Invalid"
  228. && getClass_dt.Rows[i]["GroupName"].ToString() != "Not Identified")
  229. if (getClass_dt.Rows[i]["GroupName"].ToString() == "")
  230. {
  231. if (!bl)
  232. {
  233. ClassName.Add("Default");
  234. bl = true;
  235. }
  236. }
  237. else
  238. {
  239. if (getClass_dt.Rows[i]["GroupName"].ToString() != "Default")
  240. {
  241. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  242. }
  243. }
  244. }
  245. if (ClassName.Count < 2)
  246. {
  247. IsShereAClassificationGroup= false;
  248. }
  249. else
  250. {
  251. IsShereAClassificationGroup= true;
  252. }
  253. }
  254. public bool GetIsThereAMajorClassification()
  255. {
  256. return IsShereAClassificationGroup;
  257. }
  258. #region 内部函数
  259. private string getWhere(string max, string min, string col, string partic)
  260. {
  261. return col + ">=" + min + " and " + col + "<" + max + " and TypeId=" + partic;
  262. }
  263. private DataTable InvalidRemoval(DataTable dt)
  264. {
  265. DataTable dataTable = dt.Copy();
  266. dataTable.Clear();
  267. for (int i = 0; i < dt.Rows.Count; i++)
  268. {
  269. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 10)
  270. {
  271. dataTable.Rows.Add(dt.Rows[i].ItemArray);
  272. }
  273. }
  274. return dataTable;
  275. }
  276. #endregion
  277. }
  278. }