BasicData.cs 16 KB

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