ParticleAnalysis.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. 
  2. using OTSCommon.DBOperate;
  3. using OTSIncAReportApp.DataOperation.DataAccess;
  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 OTSDataType.otsdataconst;
  11. using static OTSIncAReportApp.OTSReport_Export;
  12. namespace OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration
  13. {
  14. /// <summary>
  15. /// 颗粒分析
  16. /// </summary>
  17. class ParticleAnalysis
  18. {
  19. /// <summary>
  20. /// 大分类
  21. /// </summary>
  22. /// <returns></returns>
  23. public DataTable GetLargeClassification(OTSReport_Export m_otsreport_export,BasicData basicData)
  24. {
  25. List<DataTable> DBData = basicData.GetDBData();
  26. DataTable Out_data = new DataTable();
  27. Out_data.Columns.Add("Name");
  28. Out_data.Columns.Add("total");
  29. Out_data.Columns.Add("TypeId");
  30. Out_data.Columns.Add("Class");
  31. int it = 1;
  32. for (int i = 7; i < DBData[0].Columns.Count; i++)
  33. {
  34. Out_data.Columns.Add("c" + it);
  35. it++;
  36. }
  37. List<string> ClassName = ObtainParticleCategory(m_otsreport_export, basicData);
  38. for (int i = 0; i < DBData.Count; i++)
  39. {
  40. if (DBData[i].Rows.Count == 0)
  41. {
  42. continue;
  43. }
  44. DataRow row1 = Out_data.NewRow();
  45. row1["Class"] = ClassName[i];
  46. List<double> ints = new List<double>();
  47. for (int a = 7; a < DBData[i].Columns.Count; a++)
  48. {
  49. double ias = CalculationTableColumn(DBData[i], DBData[i].Columns[a].ColumnName);
  50. ints.Add(ias);
  51. }
  52. int zur = 0;
  53. for (int a = 0; a < ints.Count; a++)
  54. {
  55. zur = zur + Convert.ToInt32(ints[a]);
  56. }
  57. row1["total"] = zur;
  58. Out_data.Rows.Add(row1);
  59. }
  60. return Out_data;
  61. }
  62. /// <summary>
  63. /// 小分类
  64. /// </summary>
  65. /// <returns></returns>
  66. public DataTable GetSubClassification(BasicData basicData)
  67. {
  68. List<DataTable> DBData = basicData.GetDBData();
  69. DataTable Out_data = new DataTable();
  70. Out_data.Columns.Add("Name");
  71. Out_data.Columns.Add("total");
  72. Out_data.Columns.Add("TypeId");
  73. Out_data.Columns.Add("Class");
  74. int it = 1;
  75. for (int i = 7; i < DBData[0].Columns.Count; i++)
  76. {
  77. Out_data.Columns.Add("c" + it);
  78. it++;
  79. }
  80. for (int i = 0; i < DBData.Count; i++)
  81. {
  82. if (DBData[i].Rows.Count == 0)
  83. {
  84. continue;
  85. }
  86. for (int a = 0; a < DBData[i].Rows.Count; a++)
  87. {
  88. DataRow row1 = Out_data.NewRow();
  89. row1["Name"] = DBData[i].Rows[a]["TypeName"];
  90. row1["total"] = DBData[i].Rows[a]["con"];
  91. row1["TypeId"] = DBData[i].Rows[a]["TypeId"];
  92. row1["Class"] = "";
  93. int ii = 4;
  94. for (int j = 7; j < DBData[i].Columns.Count; j++)
  95. {
  96. row1[ii] = DBData[i].Rows[a][j];
  97. ii++;
  98. }
  99. Out_data.Rows.Add(row1);
  100. }
  101. }
  102. return Out_data;
  103. }
  104. /// <summary>
  105. /// 分类整合大小分类都有
  106. /// </summary>
  107. /// <returns></returns>
  108. public List<DataTable> GetClassificationConsolidationTable(OTSReport_Export m_otsreport_export, BasicData basicData ,out DataTable dataTable)
  109. {
  110. List<DataTable> datas = new List<DataTable>();
  111. List<DataTable> DBData = basicData.GetDBData();
  112. DataTable DtName = new DataTable();
  113. DataTable table = new DataTable();
  114. table.Columns.Add("Name");
  115. table.Columns.Add("total");
  116. table.Columns.Add("TypeId");
  117. table.Columns.Add("Class");
  118. int it = 1;
  119. List<string> strings = new List<string>();
  120. for (int i = 7; i < DBData[0].Columns.Count; i++)
  121. {
  122. table.Columns.Add("c" + it);
  123. DtName.Columns.Add("c" + it);
  124. strings.Add(DBData[0].Columns[i].ColumnName);
  125. it++;
  126. }
  127. DataRow dataRow = DtName.NewRow();
  128. for (int i = 0; i < strings.Count; i++)
  129. {
  130. dataRow[i] = strings[i];
  131. }
  132. DtName.Rows.Add(dataRow);
  133. datas.Add(DtName);
  134. //数据
  135. List<string> ClassName = ObtainParticleCategory(m_otsreport_export, basicData);
  136. DataTable Dt = table.Clone();
  137. DataTable statisticalQuantity = Dt.Clone();
  138. for (int i = 0; i < DBData.Count; i++)
  139. {
  140. if (DBData[i].Rows.Count == 0)
  141. {
  142. continue;
  143. }
  144. DataRow row = Dt.NewRow();
  145. row["Name"] = "";
  146. row["total"] = CalculationTableColumn(DBData[i], "con");
  147. row["TypeId"] = "";
  148. row["Class"] = ClassName[i];
  149. int ie = 0;
  150. for (int a = 4; a < Dt.Columns.Count; a++)
  151. {
  152. row[a] = CalculationTableColumn(DBData[i], DtName.Rows[0][ie].ToString());
  153. ie++;
  154. }
  155. Dt.Rows.Add(row);
  156. for (int a = 0; a < DBData[i].Rows.Count; a++)
  157. {
  158. DataRow dataRow1 = statisticalQuantity.NewRow();
  159. dataRow1["Name"] = DBData[i].Rows[a]["TypeName"];
  160. dataRow1["total"] = DBData[i].Rows[a]["con"];
  161. dataRow1["TypeId"] = DBData[i].Rows[a]["TypeId"];
  162. //dataRow1["Class"] = DBData[i].Rows[a]["Class"];
  163. dataRow1["Class"] = "";
  164. DataRow row1= Dt.NewRow();
  165. row1["Name"] = DBData[i].Rows[a]["TypeName"];
  166. row1["total"] = DBData[i].Rows[a]["con"];
  167. row1["TypeId"] = DBData[i].Rows[a]["TypeId"];
  168. //row1["Class"] = DBData[i].Rows[a]["Class"];
  169. row1["Class"] = "";
  170. int ii = 4;
  171. for (int j = 7; j < DBData[i].Columns.Count; j++)
  172. {
  173. row1[ii]= DBData[i].Rows[a][j];
  174. dataRow1[ii] = DBData[i].Rows[a][j];
  175. ii++;
  176. }
  177. Dt.Rows.Add(row1);
  178. statisticalQuantity.Rows.Add(dataRow1);
  179. }
  180. }
  181. datas.Add(Dt);
  182. DataTable OutStatisticalQuantity = statisticalQuantity.Clone();
  183. DataRow row2 = OutStatisticalQuantity.NewRow();
  184. for (int i = 4; i < statisticalQuantity.Columns.Count; i++)
  185. {
  186. row2[i]= CalculationTableColumn(statisticalQuantity, statisticalQuantity.Columns[i].ColumnName);
  187. }
  188. OutStatisticalQuantity.Rows.Add(row2);
  189. dataTable = OutStatisticalQuantity.Copy();
  190. return datas;
  191. }
  192. /// <summary>
  193. /// 获得颗粒类别
  194. /// </summary>
  195. /// <returns></returns>
  196. private List<string> ObtainParticleCategory(OTSReport_Export m_otsreport_export, BasicData basicData)
  197. {
  198. List<string> ClassName = new List<string>();
  199. if (m_otsreport_export.m_ReportApp.m_RptConfigFile.Systype != OTS_SysType_ID.IncA)
  200. {
  201. DataTable get_dt = ReadClassification(basicData);
  202. DataTable getClass_dt = get_dt.Clone();
  203. DataRow[] dataRow = get_dt.Select("", "iorder ASC");
  204. foreach (DataRow row in dataRow)
  205. {
  206. if (row.ItemArray[1].ToString() != "Default")
  207. {
  208. getClass_dt.ImportRow(row);
  209. }
  210. }
  211. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  212. {
  213. ClassName.Add(getClass_dt.Rows[i][1].ToString());
  214. }
  215. ClassName.Add("Default");
  216. }
  217. else
  218. {
  219. ClassName = basicData.GetGroupInformation();
  220. }
  221. return ClassName;
  222. }
  223. private DataTable ReadClassification(BasicData basicData )
  224. {
  225. DataTable dt_stl = new DataTable();
  226. SqLiteHelper sh = new SqLiteHelper("data source='" + basicData.GetFilePath()+ "\\"+basicData.GetResfile() + "'");
  227. dt_stl = sh.ExecuteQuery("select * from STDGroups");
  228. return dt_stl;
  229. }
  230. /// <summary>
  231. /// 大分类chart数据
  232. /// </summary>
  233. /// <param name="m_mbszclass"></param>
  234. /// <param name="m_otsreport_export"></param>
  235. /// <returns></returns>
  236. public DataTable GetChartDataCalss(BasicData basicData)
  237. {
  238. //DataTable data =basicData.GetDBData();
  239. DataTable data = new DataTable();
  240. //获取粒级表
  241. List<string> colid = basicData.GetParticlesizeTable();
  242. //------------------------------------------------
  243. DataTable ls_partsize_dt = new DataTable();
  244. ls_partsize_dt.TableName = "PartSize";
  245. for (int i = 0; i < colid.Count; i++)
  246. {
  247. ls_partsize_dt.Columns.Add("c"+(i+1).ToString());
  248. }
  249. DataTable ls_Particel_dt = new DataTable();
  250. ls_Particel_dt.TableName = "Particel";
  251. DataRow dr = ls_partsize_dt.NewRow();
  252. int colidCount = 1;
  253. for (int i = 0; i < colid.Count; i++)
  254. {
  255. if (colid.Count < i)
  256. {
  257. dr["c" + (i + 1).ToString()] = "";
  258. }
  259. else
  260. {
  261. dr["c" + (i + 1).ToString()] = colid[i];
  262. ls_Particel_dt.Columns.Add("c" + (i + 1).ToString(), typeof(double));
  263. colidCount++;
  264. }
  265. }
  266. ls_partsize_dt.Rows.Add(dr);
  267. ls_Particel_dt.Columns.Add("Name");
  268. ls_Particel_dt.Columns.Add("total", typeof(double));
  269. ls_Particel_dt.Columns.Add("TypeId");
  270. ls_Particel_dt.Columns.Add("Class");
  271. for (int i = 0; i < data.Rows.Count; i++)
  272. {
  273. DataRow dr2 = ls_Particel_dt.NewRow();
  274. dr2["Name"] = data.Rows[i]["TypeName"].ToString();
  275. dr2["Class"] = data.Rows[i]["Class"].ToString();
  276. dr2["TypeId"] = data.Rows[i]["TypeId"].ToString();//获取分类编号
  277. for (int j = 1; j < colidCount; j++)
  278. {
  279. if (colid.Count >= j)
  280. {
  281. dr2["c" + j.ToString()] = Convert.ToDouble(data.Rows[i][colid[j - 1]]);
  282. }
  283. }
  284. if (dr2["Name"].ToString() != "" && dr2["Name"].ToString().IndexOf("number") < 0)
  285. {
  286. dr2["total"] = "0"; //求合
  287. double d_total = 0;
  288. for (int j = 1; j < colidCount; j++)
  289. {
  290. if (colid.Count >= j)
  291. {
  292. d_total = d_total + Convert.ToInt64(data.Rows[i][colid[j - 1]]);
  293. }
  294. }
  295. dr2["total"] = d_total.ToString();
  296. }
  297. ls_Particel_dt.Rows.Add(dr2);
  298. }
  299. //按照list列表进行物质类排序,物质类中的元素分类按照面积的大小进行排序
  300. List<string> ClassName = new List<string>();
  301. DataTable getClass_dt = basicData.GetAllClass();
  302. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  303. {
  304. if (getClass_dt.Rows[i]["GroupName"].ToString() != "NOT_INCLUTION" && getClass_dt.Rows[i]["GroupName"].ToString() != "Invalid")
  305. if (getClass_dt.Rows[i]["GroupName"].ToString() == "")
  306. ClassName.Add("NULL");
  307. else
  308. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  309. }
  310. //颗粒尺寸数据(例 1.5有多少,2.0有多少)
  311. DataTable colid_data = new DataTable();
  312. colid_data.Columns.Add("name");
  313. colid_data.Columns.Add("quantity", typeof(double));
  314. for (int i = 0; i < ls_Particel_dt.Columns.Count; i++)
  315. {
  316. if (ls_Particel_dt.Columns[i].ColumnName == "c" + (i + 1).ToString())
  317. {
  318. if (i < colid.Count)
  319. {
  320. DataRow dr1 = colid_data.NewRow();
  321. dr1["name"] = colid[i].ToString();
  322. int quantity = 0;
  323. for (int a = 0; a < ls_Particel_dt.Rows.Count; a++)
  324. {
  325. quantity = quantity + Convert.ToInt32(ls_Particel_dt.Rows[a][i].ToString());
  326. }
  327. dr1["quantity"] = quantity.ToString();
  328. colid_data.Rows.Add(dr1);
  329. }
  330. }
  331. }
  332. return colid_data;
  333. }
  334. public DataTable ParticleResults(c_TemplateClass m_mbszclass, OTSReport_Export m_otsreport_export, string ComputeMode)
  335. {
  336. DataTable data = GetDBData(m_mbszclass, m_otsreport_export, ComputeMode);
  337. List<string> colid = new List<string>();
  338. //获取粒级表
  339. string path1 = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFileFolder +
  340. m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile;
  341. DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXml(path1);
  342. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  343. for (int i = 0; i < sizestr.Split(',').Length; i++)
  344. {
  345. if (sizestr.Split(',')[i].Length > 0)
  346. {
  347. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  348. colid.Add("≥" + d1.ToString() );
  349. }
  350. }
  351. ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath);
  352. //------------------------------------------------
  353. DataTable ls_partsize_dt = new DataTable();
  354. ls_partsize_dt.TableName = "PartSize";
  355. for(int i=0;i< colid.Count;i++)
  356. {
  357. ls_partsize_dt.Columns.Add("c"+(i+1).ToString());
  358. }
  359. DataRow dr = ls_partsize_dt.NewRow();
  360. DataTable ls_Particel_dt = new DataTable();
  361. ls_Particel_dt.TableName = "Particel";
  362. int colidCount = 1;
  363. for (int i = 0; i < colid.Count; i++)
  364. {
  365. dr["c" + (i+1).ToString()] = colid[i];
  366. ls_Particel_dt.Columns.Add("c"+ (i + 1).ToString());
  367. colidCount++;
  368. }
  369. ls_partsize_dt.Rows.Add(dr);
  370. ls_Particel_dt.Columns.Add("Name");
  371. ls_Particel_dt.Columns.Add("total");
  372. ls_Particel_dt.Columns.Add("TypeId");
  373. for (int i = 0; i < data.Rows.Count; i++)
  374. {
  375. DataRow dr2 = ls_Particel_dt.NewRow();
  376. dr2["Name"] = data.Rows[i]["TypeName"].ToString();
  377. dr2["TypeId"] = data.Rows[i]["TypeId"].ToString();//获取分类编号
  378. for (int j = 1; j < colidCount; j++)
  379. {
  380. if (colid.Count >= j)
  381. {
  382. double de = Convert.ToDouble(data.Rows[i][colid[j - 1]]);
  383. if (de == 0)
  384. dr2["c" + j.ToString()] = " ";
  385. else
  386. dr2["c" + j.ToString()] = de.ToString();
  387. }
  388. }
  389. if (dr2["Name"].ToString() != "" && dr2["Name"].ToString().IndexOf("number") < 0)
  390. {
  391. dr2["total"] = " "; //求合
  392. double d_total = 0;
  393. for (int j = 1; j < colidCount; j++)
  394. {
  395. if (colid.Count >= j)
  396. {
  397. d_total = d_total + Convert.ToInt64(data.Rows[i][colid[j - 1]]);
  398. }
  399. }
  400. if (d_total == 0)
  401. {
  402. continue;
  403. dr2["total"] = " ";
  404. }
  405. else
  406. dr2["total"] = d_total.ToString();
  407. }
  408. ls_Particel_dt.Rows.Add(dr2);
  409. }
  410. return ls_Particel_dt;
  411. }
  412. public DataTable TypeRange(c_TemplateClass m_mbszclass, OTSReport_Export m_otsreport_export)
  413. {
  414. List<string> colid = new List<string>();
  415. //获取粒级表
  416. string path1 = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFileFolder +
  417. m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile;
  418. DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXml(path1);
  419. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  420. for (int i = 0; i < sizestr.Split(',').Length; i++)
  421. {
  422. if (sizestr.Split(',')[i].Length > 0)
  423. {
  424. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  425. colid.Add("≥" + d1.ToString());
  426. }
  427. }
  428. DataTable ls_partsize_dt = new DataTable();
  429. ls_partsize_dt.TableName = "PartSize";
  430. for (int i=0;i< colid.Count;i++)
  431. {
  432. ls_partsize_dt.Columns.Add("c"+(i+1).ToString());
  433. }
  434. DataRow dr = ls_partsize_dt.NewRow();
  435. for (int i = 0; i < colid.Count; i++)
  436. {
  437. dr["c" + (i+1).ToString()] = colid[i];
  438. }
  439. ls_partsize_dt.Rows.Add(dr);
  440. return ls_partsize_dt;
  441. }
  442. private DataTable QuantityOfIntegratedSubstances(DataTable dataTable, List<string> ClassName)
  443. {
  444. DataTable dt_Class = dataTable.Copy();
  445. dt_Class.Clear();
  446. dt_Class.TableName = "Particel";
  447. dt_Class.Columns.Remove("Name");
  448. for (int i = 0; i < ClassName.Count; i++)
  449. {
  450. //保留当前循环中大类物质,去除其他物质
  451. DataTable dt = dataTable.Copy();
  452. dt.Clear();
  453. for (int a = 0; a < dataTable.Rows.Count; a++)
  454. {
  455. if (dataTable.Rows[a]["Class"].ToString() == ClassName[i].ToString())
  456. {
  457. dt.Rows.Add(dataTable.Rows[a].ItemArray);
  458. }
  459. }
  460. //if (dt.Rows.Count == 0)
  461. // continue;
  462. DataTable dt_2 = new DataTable();
  463. dt_2 = dataTable.Copy();
  464. dt_2.Clear();
  465. DataRow row = dt_2.NewRow();
  466. dt_2.Rows.Add(row);
  467. for (int a = 0; a < dt.Columns.Count; a++)
  468. {
  469. if (dt.Columns[a].ToString() != "Name" && dt.Columns[a].ToString() != "Class" && dt.Columns[a].ToString() != "TypeId")
  470. {
  471. bool bl = false;
  472. for (int b = 0; b < dt.Rows.Count; b++)
  473. {
  474. if (!dt.Rows[b].IsNull(dt.Columns[a].ToString()))
  475. {
  476. bl = true;
  477. }
  478. }
  479. if (bl)
  480. {
  481. dt_2.Rows[0][dt.Columns[a].ToString()] = decimal.Parse(dt.Compute("sum(" + dt.Columns[a].ToString() + ")", "").ToString());
  482. }
  483. else
  484. {
  485. dt_2.Rows[0][dt.Columns[a].ToString()] = 0;
  486. }
  487. }
  488. }
  489. dt_2.Columns.Remove("Name");
  490. dt_2.Rows[0]["Class"] = ClassName[i];
  491. dt_Class.Rows.Add(dt_2.Rows[0].ItemArray);
  492. }
  493. return dt_Class;
  494. }
  495. private DataTable classIfIcationSort(DataTable dataTable, List<string> ClassName, DataTable data,int colidCount)
  496. {
  497. DataTable dt = new DataTable();
  498. dt = dataTable.Copy();
  499. dt.Clear();
  500. dt.TableName = "Particel_subdivision";
  501. //循环list中每个类型
  502. for (int i = 0; i < ClassName.Count(); i++)
  503. {
  504. DataTable data1 = dt.Copy();
  505. data1.Clear();
  506. data1.Rows.Add();
  507. for (int a = 0; a < data.Rows.Count; a++)
  508. {
  509. if (data.Rows[a]["Class"].ToString() == ClassName[i].ToString())
  510. {
  511. for (int b = 1; b < colidCount; b++)
  512. {
  513. data1.Rows[0]["c" + b.ToString()] = data.Rows[a]["c" + b.ToString()];
  514. }
  515. data1.Rows[0]["total"] = data.Rows[a]["total"];
  516. data1.Rows[0]["Class"] = data.Rows[a]["Class"];
  517. dt.Rows.Add(data1.Rows[0].ItemArray);
  518. }
  519. }
  520. DataTable dt_1 = new DataTable();
  521. dt_1 = dt.Copy();
  522. dt_1.Clear();
  523. //循环DataTable中每个分类的数据
  524. for (int a = 0; a < dataTable.Rows.Count; a++)
  525. {
  526. if (!string.IsNullOrWhiteSpace(ClassName[i].ToString()))
  527. if (dataTable.Rows[a]["Class"].ToString() == ClassName[i].ToString())
  528. {
  529. dataTable.Rows[a]["Class"] = "";
  530. dt_1.Rows.Add(dataTable.Rows[a].ItemArray);
  531. }
  532. }
  533. //将颗粒数量排序(从大到小)
  534. DataView dv = dt_1.DefaultView;
  535. dv.Sort = "total DESC";
  536. DataTable dt_1_sort = dv.ToTable();
  537. for (int a = 0; a < dt_1_sort.Rows.Count; a++)
  538. {
  539. dt.Rows.Add(dt_1_sort.Rows[a].ItemArray);
  540. }
  541. }
  542. return dt;
  543. }
  544. private DataTable InvalidRemoval(DataTable dt)
  545. {
  546. DataTable dataTable = dt.Copy();
  547. dataTable.Clear();
  548. for (int i = 0; i < dt.Rows.Count; i++)
  549. {
  550. if (Convert.ToInt32(dt.Rows[i]["TypeId"])>10 )
  551. {
  552. dataTable.Rows.Add(dt.Rows[i].ItemArray);
  553. }
  554. }
  555. return dataTable;
  556. }
  557. private string getWhere(string max, string min, string col, string partic)
  558. {
  559. return col + ">=" + min + " and " + col + "<" + max + " and TypeId=" + partic;
  560. }
  561. private DataTable GetDBData(c_TemplateClass m_mbszclass , OTSReport_Export m_otsreport_export,string ComputeMode)
  562. {
  563. DataTable m_bt_DBData = new DataTable();
  564. ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath);
  565. List<string> colid = new List<string>() { "TypeName", "ar", "TypeId", "Largest", "Class", "con" };
  566. //获取粒级表
  567. string path1 = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFileFolder +
  568. m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile;
  569. DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXml(path1);
  570. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  571. for (int i = 0; i < sizestr.Split(',').Length ; i++)
  572. {
  573. if (sizestr.Split(',')[i].Length > 0)
  574. {
  575. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  576. colid.Add("≥" + d1.ToString() );
  577. }
  578. }
  579. for (int i = 0; i < colid.Count; i++)
  580. {
  581. m_bt_DBData.Columns.Add(colid[i].ToString());
  582. }
  583. DataTable dt = InvalidRemoval(fielddata.GetParticleListForParticlSize("area", ""));
  584. DataTable AreaInformationOfAllElements = InvalidRemoval(fielddata.GetAreaByAllIncA(""));
  585. DataTable dtp = InvalidRemoval(fielddata.GetParticleAll(""));
  586. string po = ComputeMode;
  587. switch (po)
  588. {
  589. case "DMAX":
  590. po = "DMAX";
  591. break;
  592. case "DMIN":
  593. po = "DMIN";
  594. break;
  595. case "ECD":
  596. po = "Area";
  597. break;
  598. case "FERET":
  599. po = "DFERET";
  600. break;
  601. }
  602. for (int i = 0; i < dt.Rows.Count; i++)
  603. {
  604. DataRow dr = m_bt_DBData.NewRow();
  605. dr["TypeName"] = dt.Rows[i]["TypeName"].ToString();
  606. dr["TypeId"] = dt.Rows[i]["TypeId"].ToString();
  607. dr["con"] = dt.Rows[i]["con"].ToString();
  608. if (dt.Rows[i]["GroupName"].ToString() == "")
  609. dr["Class"] = "Default";
  610. else
  611. dr["Class"] = dt.Rows[i]["GroupName"].ToString();
  612. //continue;
  613. dr["Largest"] = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  614. for (int a = 6; a < colid.Count; a++)
  615. {
  616. string d2;
  617. if (a== colid.Count-1)
  618. {
  619. d2 = "999";
  620. }
  621. else
  622. {
  623. d2 = colid[a+1].Split('≥')[1];
  624. }
  625. string d1 = colid[a].Split('≥')[1];
  626. DataRow[] datas = dtp.Select(getWhere(d2, d1, po, dt.Rows[i]["TypeId"].ToString()));
  627. dr[colid[a]] = datas.Count();
  628. }
  629. for (int a = 0; a < AreaInformationOfAllElements.Rows.Count; a++)
  630. {
  631. if (dt.Rows[i]["TypeId"].ToString() == AreaInformationOfAllElements.Rows[a]["TypeId"].ToString())
  632. {
  633. dr["ar"] = AreaInformationOfAllElements.Rows[a]["ar"];
  634. }
  635. }
  636. m_bt_DBData.Rows.Add(dr);
  637. }
  638. //去除物质分类(非夹杂物分类)
  639. for (int a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial.Count; a++)
  640. {
  641. for (int i = m_bt_DBData.Rows.Count - 1; i >= 0; i--)
  642. {
  643. if (m_bt_DBData.Rows[i]["TypeId"].ToString() == m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial[a].ToString())
  644. {
  645. m_bt_DBData.Rows.RemoveAt(i);
  646. }
  647. }
  648. }
  649. if (m_mbszclass.list_str_MainPriority_Serial.Count==0)
  650. {
  651. return m_bt_DBData;
  652. }
  653. DataTable datass = m_bt_DBData.Clone();
  654. for (int i=0;i< m_mbszclass.list_str_MainPriority_Serial.Count;i++)
  655. {
  656. bool bl = false;
  657. for (int a = 0; a < m_bt_DBData.Rows.Count; a++)
  658. {
  659. if (m_bt_DBData.Rows[a]["TypeId"].ToString() == m_mbszclass.list_str_MainPriority_Serial[i])
  660. {
  661. datass.Rows.Add(m_bt_DBData.Rows[a].ItemArray);
  662. bl = true;
  663. continue;
  664. }
  665. }
  666. if(!bl)
  667. {
  668. DataTable dta= m_bt_DBData.Clone();
  669. if (m_bt_DBData.Rows.Count != 0)
  670. {
  671. dta.Rows.Add(m_bt_DBData.Rows[0].ItemArray);
  672. for (int b = 0; b < dta.Columns.Count; b++)
  673. {
  674. if (dta.Columns[b].ColumnName == "TypeName")
  675. {
  676. dta.Rows[0][b] = m_mbszclass.list_str_MainPriority[i];
  677. }
  678. else if (dta.Columns[b].ColumnName == "Class")
  679. {
  680. dta.Rows[0][b] = "Default";
  681. }
  682. else
  683. {
  684. dta.Rows[0][b] = 0;
  685. }
  686. }
  687. datass.Rows.Add(dta.Rows[0].ItemArray);
  688. }
  689. }
  690. }
  691. return datass;
  692. }
  693. private double CalculationTableColumn(DataTable a_data, string a_str)
  694. {
  695. double dl = 0;
  696. if (a_data.Columns.Contains(a_str))
  697. {
  698. for (int i = 0; i < a_data.Rows.Count; i++)
  699. {
  700. if (a_data.Rows[i][a_str].ToString() != "")
  701. {
  702. dl = dl + Convert.ToDouble(a_data.Rows[i][a_str]);
  703. }
  704. }
  705. }
  706. return dl;
  707. }
  708. }
  709. }