BasicData.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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; 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; 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('≥')[1];
  113. string d2;
  114. if (a== colid.Count-1)
  115. {
  116. d2 = "999";
  117. }
  118. else
  119. {
  120. d2 = colid[a+1].Split('≥')[1];
  121. }
  122. //if (d2 == "MAX")
  123. //{
  124. // d2 = "999";
  125. //}
  126. DataRow[] datas = dtp.Select(getWhere(d2, d1, po, dt.Rows[i]["TypeId"].ToString()));
  127. dr[colid[a]] = datas.Count();
  128. }
  129. for (int a = 0; a < AreaInformationOfAllElements.Rows.Count; a++)
  130. {
  131. if (dt.Rows[i]["TypeId"].ToString() == AreaInformationOfAllElements.Rows[a]["TypeId"].ToString())
  132. {
  133. dr["ar"] = AreaInformationOfAllElements.Rows[a]["ar"];
  134. }
  135. }
  136. m_bt_DBData.Rows.Add(dr);
  137. }
  138. //去除物质分类(非夹杂物分类)
  139. for (int a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial.Count; a++)
  140. {
  141. for (int i = m_bt_DBData.Rows.Count - 1; i >= 0; i--)
  142. {
  143. if (m_bt_DBData.Rows[i]["TypeId"].ToString() == m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial[a].ToString())
  144. {
  145. m_bt_DBData.Rows.RemoveAt(i);
  146. }
  147. }
  148. }
  149. if (m_mbszclass.list_str_MainPriority_Serial.Count == 0)
  150. {
  151. BData = m_bt_DBData.Copy();
  152. return;
  153. }
  154. DataTable datass = m_bt_DBData.Clone();
  155. string str = m_otsreport_export.m_mbszclass.M_SY.StandardLibraryName;
  156. OTSCommon.DBOperate.SqLiteHelper sh;
  157. string fullPath = GetFilePath() + "\\" + str;
  158. string fullPath2 = System.IO.Directory.GetCurrentDirectory() + "\\Config\\SysData\\" + str;
  159. if (System.IO.File.Exists(fullPath))
  160. {
  161. sh = new OTSCommon.DBOperate.SqLiteHelper("data source='" + fullPath + "'");
  162. }
  163. else if (System.IO.File.Exists(fullPath2))
  164. {
  165. sh = new OTSCommon.DBOperate.SqLiteHelper("data source='" + fullPath2 + "'");
  166. }
  167. else
  168. {
  169. sh = null;
  170. }
  171. DataTable dt_stl = sh.ExecuteQuery("select * from ClassifySTD");
  172. DataTable LargeClassificationTable = sh.ExecuteQuery("select * from STDGroups");
  173. for (int i = 0; i < m_mbszclass.list_str_MainPriority_Serial.Count; i++)
  174. {
  175. bool bl = false;
  176. for (int a = 0; a < m_bt_DBData.Rows.Count; a++)
  177. {
  178. if (m_bt_DBData.Rows[a]["TypeId"].ToString() == m_mbszclass.list_str_MainPriority_Serial[i])
  179. {
  180. datass.Rows.Add(m_bt_DBData.Rows[a].ItemArray);
  181. bl = true;
  182. continue;
  183. }
  184. }
  185. if (!bl)
  186. {
  187. DataTable dta = m_bt_DBData.Clone();
  188. // 添加一个空行
  189. DataRow newRow = dta.NewRow();
  190. dta.Rows.Add(newRow);
  191. for (int b = 0; b < dta.Columns.Count; b++)
  192. {
  193. if (dta.Columns[b].ColumnName == "TypeName")
  194. {
  195. dta.Rows[0][b] = m_mbszclass.list_str_MainPriority[i];
  196. }
  197. else if (dta.Columns[b].ColumnName == "Class")
  198. {
  199. for (int c = 0; c < LargeClassificationTable.Rows.Count; c++)
  200. {
  201. if (LargeClassificationTable.Rows[c]["id"].ToString() == dt_stl.Rows[i]["GroupId"].ToString())
  202. {
  203. dta.Rows[0][b] = LargeClassificationTable.Rows[c]["name"].ToString();
  204. }
  205. }
  206. }
  207. else
  208. if (dta.Columns[b].ColumnName == "TypeId")
  209. {
  210. dta.Rows[0][b] = m_mbszclass.list_str_MainPriority_Serial[i];
  211. }
  212. else
  213. {
  214. dta.Rows[0][b] = 0;
  215. }
  216. }
  217. datass.Rows.Add(dta.Rows[0].ItemArray);
  218. }
  219. }
  220. BData = datass.Copy();
  221. //return datass;
  222. }
  223. /// <summary>
  224. /// 获取读取数据库并过滤颗粒
  225. /// </summary>
  226. /// <returns></returns>
  227. public DataTable GetDBData()
  228. {
  229. return BData;
  230. }
  231. public void SetAllClass()
  232. {
  233. AllClass = fielddata.GetAllClass();
  234. }
  235. /// <summary>
  236. /// 获取全部大类
  237. /// </summary>
  238. /// <returns></returns>
  239. public DataTable GetAllClass()
  240. {
  241. return AllClass;
  242. }
  243. /// <summary>
  244. /// 定义ParticleData类
  245. /// </summary>
  246. public void newParticleData(OTSReport_Export m_otsreport_export)
  247. {
  248. fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath);
  249. }
  250. public ParticleData getParticleData()
  251. {
  252. return fielddata;
  253. }
  254. public void SetAllElement()
  255. {
  256. AllElement = fielddata.GetAllElement();
  257. }
  258. /// <summary>
  259. /// 获取全部元素
  260. /// </summary>
  261. /// <returns></returns>
  262. public DataTable GetAllElement()
  263. {
  264. return AllElement;
  265. }
  266. /// <summary>
  267. /// 判断是否有大分类,有为true
  268. /// </summary>
  269. /// <param name="m_otsreport_export"></param>
  270. /// <returns></returns>
  271. public void IsThereAMajorClassification()
  272. {
  273. DataTable getClass_dt = fielddata.GetAllClass();
  274. List<string> ClassName = new List<string>();
  275. bool bl = false;
  276. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  277. {
  278. if (getClass_dt.Rows[i]["GroupName"].ToString() != "NOT_INCLUTION" && getClass_dt.Rows[i]["GroupName"].ToString() != "Invalid"
  279. && getClass_dt.Rows[i]["GroupName"].ToString() != "Not Identified")
  280. if (getClass_dt.Rows[i]["GroupName"].ToString() == "")
  281. {
  282. if (!bl)
  283. {
  284. ClassName.Add("Default");
  285. bl = true;
  286. }
  287. }
  288. else
  289. {
  290. if (getClass_dt.Rows[i]["GroupName"].ToString() != "Default")
  291. {
  292. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  293. }
  294. }
  295. }
  296. if (ClassName.Count < 2)
  297. {
  298. IsShereAClassificationGroup= false;
  299. }
  300. else
  301. {
  302. IsShereAClassificationGroup= true;
  303. }
  304. }
  305. public bool GetIsThereAMajorClassification()
  306. {
  307. return IsShereAClassificationGroup;
  308. }
  309. public void IsResultFilesList(OTSReport_Export m_otsreport_export)
  310. {
  311. resfile = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()];
  312. }
  313. /// <summary>
  314. /// 获取标准库名称
  315. /// </summary>
  316. /// <returns></returns>
  317. public string GetResfile()
  318. {
  319. return resfile.GetSTDName();
  320. }
  321. public void IsFilePath(OTSReport_Export m_otsreport_export)
  322. {
  323. FilePath= m_otsreport_export.m_ReportApp.m_rstDataMgr.CurResultFile.FilePath;
  324. }
  325. /// <summary>
  326. /// 得到文件路径
  327. /// </summary>
  328. /// <returns></returns>
  329. public string GetFilePath()
  330. {
  331. return FilePath;
  332. }
  333. #region 内部函数
  334. private string getWhere(string max, string min, string col, string partic)
  335. {
  336. return col + ">=" + min + " and " + col + "<" + max + " and TypeId=" + partic;
  337. }
  338. private DataTable InvalidRemoval(DataTable dt)
  339. {
  340. DataTable dataTable = dt.Copy();
  341. dataTable.Clear();
  342. for (int i = 0; i < dt.Rows.Count; i++)
  343. {
  344. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 10)
  345. {
  346. dataTable.Rows.Add(dt.Rows[i].ItemArray);
  347. }
  348. }
  349. return dataTable;
  350. }
  351. #endregion
  352. }
  353. }