BasicData.cs 14 KB

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