BasicData.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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.GetWorkingResultId()].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_Serial.Count; a++)
  132. {
  133. for (int i = m_bt_DBData.Rows.Count - 1; i >= 0; i--)
  134. {
  135. if (m_bt_DBData.Rows[i]["TypeId"].ToString() == m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial[a].ToString())
  136. {
  137. m_bt_DBData.Rows.RemoveAt(i);
  138. }
  139. }
  140. }
  141. if (m_mbszclass.list_str_MainPriority_Serial.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_Serial.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]["TypeId"].ToString() == m_mbszclass.list_str_MainPriority_Serial[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. if (dta.Columns[b].ColumnName == "TypeId")
  201. {
  202. dta.Rows[0][b] = m_mbszclass.list_str_MainPriority_Serial[i];
  203. }
  204. else
  205. {
  206. dta.Rows[0][b] = 0;
  207. }
  208. }
  209. datass.Rows.Add(dta.Rows[0].ItemArray);
  210. }
  211. }
  212. BData = datass.Copy();
  213. //return datass;
  214. }
  215. /// <summary>
  216. /// 获取读取数据库并过滤颗粒
  217. /// </summary>
  218. /// <returns></returns>
  219. public DataTable GetDBData()
  220. {
  221. return BData;
  222. }
  223. public void SetAllClass()
  224. {
  225. AllClass = fielddata.GetAllClass();
  226. }
  227. /// <summary>
  228. /// 获取全部大类
  229. /// </summary>
  230. /// <returns></returns>
  231. public DataTable GetAllClass()
  232. {
  233. return AllClass;
  234. }
  235. /// <summary>
  236. /// 定义ParticleData类
  237. /// </summary>
  238. public void newParticleData(OTSReport_Export m_otsreport_export)
  239. {
  240. fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath);
  241. }
  242. public ParticleData getParticleData()
  243. {
  244. return fielddata;
  245. }
  246. public void SetAllElement()
  247. {
  248. AllElement = fielddata.GetAllElement();
  249. }
  250. /// <summary>
  251. /// 获取全部元素
  252. /// </summary>
  253. /// <returns></returns>
  254. public DataTable GetAllElement()
  255. {
  256. return AllElement;
  257. }
  258. /// <summary>
  259. /// 判断是否有大分类,有为true
  260. /// </summary>
  261. /// <param name="m_otsreport_export"></param>
  262. /// <returns></returns>
  263. public void IsThereAMajorClassification()
  264. {
  265. DataTable getClass_dt = fielddata.GetAllClass();
  266. List<string> ClassName = new List<string>();
  267. bool bl = false;
  268. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  269. {
  270. if (getClass_dt.Rows[i]["GroupName"].ToString() != "NOT_INCLUTION" && getClass_dt.Rows[i]["GroupName"].ToString() != "Invalid"
  271. && getClass_dt.Rows[i]["GroupName"].ToString() != "Not Identified")
  272. if (getClass_dt.Rows[i]["GroupName"].ToString() == "")
  273. {
  274. if (!bl)
  275. {
  276. ClassName.Add("Default");
  277. bl = true;
  278. }
  279. }
  280. else
  281. {
  282. if (getClass_dt.Rows[i]["GroupName"].ToString() != "Default")
  283. {
  284. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  285. }
  286. }
  287. }
  288. if (ClassName.Count < 2)
  289. {
  290. IsShereAClassificationGroup= false;
  291. }
  292. else
  293. {
  294. IsShereAClassificationGroup= true;
  295. }
  296. }
  297. public bool GetIsThereAMajorClassification()
  298. {
  299. return IsShereAClassificationGroup;
  300. }
  301. public void IsResultFilesList(OTSReport_Export m_otsreport_export)
  302. {
  303. resfile = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()];
  304. }
  305. /// <summary>
  306. /// 获取标准库名称
  307. /// </summary>
  308. /// <returns></returns>
  309. public string GetResfile()
  310. {
  311. return resfile.GetSTDName();
  312. }
  313. public void IsFilePath(OTSReport_Export m_otsreport_export)
  314. {
  315. FilePath= m_otsreport_export.m_ReportApp.m_rstDataMgr.CurResultFile.FilePath;
  316. }
  317. /// <summary>
  318. /// 得到文件路径
  319. /// </summary>
  320. /// <returns></returns>
  321. public string GetFilePath()
  322. {
  323. return FilePath;
  324. }
  325. #region 内部函数
  326. private string getWhere(string max, string min, string col, string partic)
  327. {
  328. return col + ">=" + min + " and " + col + "<" + max + " and TypeId=" + partic;
  329. }
  330. private DataTable InvalidRemoval(DataTable dt)
  331. {
  332. DataTable dataTable = dt.Copy();
  333. dataTable.Clear();
  334. for (int i = 0; i < dt.Rows.Count; i++)
  335. {
  336. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 10)
  337. {
  338. dataTable.Rows.Add(dt.Rows[i].ItemArray);
  339. }
  340. }
  341. return dataTable;
  342. }
  343. #endregion
  344. }
  345. }