DEVChart_ParticlesComposition.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. using DevExpress.Charts.Model;
  2. using DevExpress.Utils;
  3. using DevExpress.XtraCharts;
  4. using NPOI.Util;
  5. using OTSIncAReportApp._1_UI.Control_DEVCharts;
  6. using OTSIncAReportApp.OTSRstMgrFunction;
  7. using OTSIncAReportApp.OTSSampleReportInfo;
  8. using OTSIncAReportApp.SysMgrTools;
  9. using OTSIncAReportGrids;
  10. using System;
  11. using System.Collections;
  12. using System.Collections.Generic;
  13. using System.Data;
  14. using System.Linq;
  15. using System.Windows.Forms;
  16. namespace OTSIncAReportApp.Control_ECharts
  17. {
  18. /// <summary>
  19. /// 各图char相关模块
  20. /// </summary>
  21. public partial class DEVChart_ParticlesComposition : UserControl
  22. {
  23. Hashtable table;
  24. #region 图表相关变量
  25. //y轴名称
  26. public string m_str_AxisY { get; set; }
  27. //数据图类型:常用夹杂物分类CommonlyUsedClassify ,颗粒成分PComponent,元素成分EComponent,颗粒尺寸分布PSize
  28. string ComSel { get; set; }
  29. public bool Report { get; set; }
  30. frmReportApp m_ReportApp;
  31. private frmReportConditionChoose m_conditionChoose;
  32. private ResultDataMgr m_DataMgr;
  33. private List<DataTable> prListData = new List<DataTable>();
  34. private List<string> prListString = new List<string>();
  35. #endregion
  36. #region 窗体加载及构造函数
  37. public DEVChart_ParticlesComposition(frmReportApp ReportApp, string comsel)
  38. {
  39. ComSel = comsel;
  40. m_ReportApp = ReportApp;
  41. m_conditionChoose = ReportApp.m_conditionChoose;
  42. m_DataMgr = ReportApp.m_rstDataMgr;
  43. InitializeComponent();
  44. //国际化
  45. Language lan = new Language();
  46. table = lan.GetNameTable("CompositionDistributionGrid");
  47. comboBox1.SelectedIndex = 0;
  48. }
  49. private void EChart_ParticlesComposition_Load(object sender, EventArgs e)
  50. {
  51. string sou = "";
  52. int sel = 0;//选择颗粒范围(0为全部颗粒1为选择颗粒)
  53. if (Report)
  54. {
  55. sou = m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResultId()].anotherFileName.ToString();
  56. sel = 0;
  57. }
  58. else
  59. {
  60. sou = m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  61. sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  62. }
  63. Report = false;
  64. if (m_ReportApp.more)
  65. {
  66. m_ReportApp.trans = false;
  67. }
  68. else
  69. {
  70. m_ReportApp.trans = true;
  71. }
  72. m_ReportApp.more = true;
  73. List<DataTable> list_dt = GetListJsonStr();
  74. bool bl = false;
  75. for (int i=0;i< list_dt.Count;i++)
  76. {
  77. if (list_dt[i].Rows.Count>0)
  78. {
  79. bl = true;
  80. }
  81. }
  82. List<DataTable> listDt = new List<DataTable>();
  83. for (int i=0;i< list_dt.Count;i++)
  84. {
  85. DataTable dt = list_dt[i].Clone();
  86. for (int a=0;a< list_dt[i].Rows.Count;a++)
  87. {
  88. if (list_dt[i].Rows[a]["name"].ToString() != "")
  89. {
  90. dt.Rows.Add(list_dt[i].Rows[a].ItemArray);
  91. }
  92. }
  93. listDt.Add(dt);
  94. }
  95. prListData = listDt.Copy();
  96. prListString.Clear();
  97. for (int i = 0; i < list_dt.Count; i++)
  98. {
  99. ResultFile resultFile = m_DataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
  100. string str = resultFile.anotherFileName;
  101. prListString.Add(str);
  102. }
  103. panel1.Dock = DockStyle.Fill;
  104. chartControl1.Dock = DockStyle.Fill;
  105. Graphics();
  106. }
  107. #endregion
  108. #region 获取单数据源
  109. private DataTable ClassificationIntegration(string path, int sel)
  110. {
  111. //------------------加载模块,获取数据-------------------------------------------------
  112. ResultGrid ls_resultgrid = new ResultGrid(m_ReportApp);
  113. Dictionary<string, string> keyValues_ResultGrid = ls_resultgrid.GetData_ResultGrid_Report();
  114. //------------------加载模块,获取数据结束----------------------------------------------
  115. Dictionary<string, string>.Enumerator en = keyValues_ResultGrid.GetEnumerator();
  116. string str_SCZS = "";
  117. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col5"].ToString(), out str_SCZS);//视场总数
  118. DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path);
  119. DataTable data = new DataTable();
  120. data = particledata.GetAreaByAllIncA("");//获取所有分类面积和数量信息
  121. if (data.Rows.Count == 0)
  122. {
  123. return data;
  124. }
  125. DataTable AreaInformationOfAllElements = ConSolidateInvalid(data);
  126. DataTable AllAnalysisDetails = new DataTable();
  127. AllAnalysisDetails.Columns.Add("Name");
  128. AllAnalysisDetails.Columns.Add("TypeId");
  129. AllAnalysisDetails.Columns.Add("Area", typeof(double));
  130. AllAnalysisDetails.Columns.Add("Class");
  131. AllAnalysisDetails.Columns.Add("Cunt", typeof(double));
  132. for (int i = 0; i < AreaInformationOfAllElements.Rows.Count; i++)
  133. {
  134. DataRow dr2 = AllAnalysisDetails.NewRow();
  135. dr2["Name"] = AreaInformationOfAllElements.Rows[i]["TypeName"].ToString();
  136. dr2["Area"] = Convert.ToDouble(AreaInformationOfAllElements.Rows[i]["ar"]);
  137. dr2["TypeId"] = AreaInformationOfAllElements.Rows[i]["TypeId"].ToString();
  138. dr2["Cunt"] = Convert.ToDouble(AreaInformationOfAllElements.Rows[i]["con"]);
  139. dr2["Class"] = AreaInformationOfAllElements.Rows[i]["GroupName"].ToString();
  140. AllAnalysisDetails.Rows.Add(dr2);
  141. }
  142. //按照list列表进行物质类排序,物质类中的元素分类按照面积的大小进行排序
  143. List<string> ClassName = new List<string>();
  144. DataTable getClass_dt = particledata.GetAllClass();
  145. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  146. {
  147. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  148. }
  149. DataTable AreaRatio = new DataTable();
  150. AreaRatio.TableName = "InclusionAreaRatio";
  151. AreaRatio.Columns.Add("e1");
  152. AreaRatio.Columns.Add("e2");
  153. AreaRatio.Columns.Add("e3", typeof(double));
  154. AreaRatio.Columns.Add("e4");
  155. AreaRatio.Columns.Add("e5");
  156. AreaRatio.Columns.Add("Cunt", typeof(int));
  157. //获取夹杂物的总面积用于计算夹杂物类别的占比(gridview最后一个固定是未识别颗粒,要排除未识别颗粒所以for循环至grid view长度减一)
  158. double totalInclusionArea = 0;
  159. totalInclusionArea = Convert.ToDouble(decimal.Parse(AllAnalysisDetails.Compute("sum(Area)", "").ToString()));
  160. for (int i = 0; i < AllAnalysisDetails.Rows.Count; i++)
  161. {
  162. DataRow dr2 = AreaRatio.NewRow();
  163. dr2["e1"] = AllAnalysisDetails.Rows[i]["Class"].ToString();
  164. dr2["e2"] = AllAnalysisDetails.Rows[i]["Name"].ToString();
  165. dr2["e3"] = Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]);
  166. dr2["e4"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / totalInclusionArea) * 100, 2);
  167. dr2["e5"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / Convert.ToDouble(str_SCZS)) * 100, 4);
  168. dr2["Cunt"] = AllAnalysisDetails.Rows[i]["Cunt"].ToString();
  169. AreaRatio.Rows.Add(dr2);
  170. }
  171. DataTable AreaRatio_dt = AreaRatio.Copy();
  172. AreaRatio_dt.Clear();
  173. for (int i = 0; i < ClassName.Count(); i++)
  174. {
  175. DataTable dt = AreaRatio.Copy();
  176. dt.Clear();
  177. for (int a = 0; a < AreaRatio.Rows.Count; a++)
  178. {
  179. if (AreaRatio.Rows[a]["e1"].ToString() == ClassName[i].ToString())
  180. {
  181. dt.Rows.Add(AreaRatio.Rows[a].ItemArray);
  182. }
  183. }
  184. DataView dv = dt.DefaultView;
  185. dv.Sort = "e3 DESC";
  186. DataTable dt_Element = dv.ToTable();
  187. for (int a = 0; a < dt_Element.Rows.Count; a++)
  188. {
  189. AreaRatio_dt.Rows.Add(dt_Element.Rows[a].ItemArray);
  190. }
  191. }
  192. DataTable AllAnalysisDetails1 = AreaRatio_dt.Copy();
  193. AllAnalysisDetails1.Clear();
  194. for (int i = 0; i < ClassName.Count; i++)
  195. {
  196. DataTable dt = AreaRatio_dt.Copy();
  197. dt.Clear();
  198. for (int a = 0; a < AreaRatio_dt.Rows.Count; a++)
  199. {
  200. if (AreaRatio_dt.Rows[a]["e1"].ToString() == ClassName[i].ToString())
  201. {
  202. dt.Rows.Add(AreaRatio_dt.Rows[a].ItemArray);
  203. }
  204. }
  205. if (dt.Rows.Count > 0)
  206. {
  207. double totalInclusionArea2 = Convert.ToDouble(decimal.Parse(AreaRatio_dt.Compute("sum(e3)", "").ToString()));
  208. double Area = Convert.ToDouble(decimal.Parse(dt.Compute("sum(e3)", "").ToString()));
  209. int cunt = Convert.ToInt32(decimal.Parse(dt.Compute("sum(Cunt)", "").ToString()));
  210. DataRow dr3 = AllAnalysisDetails1.NewRow();
  211. dr3["e1"] = ClassName[i].ToString();
  212. dr3["e3"] = Math.Round(Area, 2);
  213. dr3["e4"] = Math.Round((Convert.ToDouble(dt.Rows[0]["e3"]) / totalInclusionArea2) * 100, 2);
  214. dr3["e5"] = Math.Round((Convert.ToDouble(dt.Rows[0]["e3"]) / Convert.ToDouble(str_SCZS)) * 100, 4);
  215. dr3["Cunt"] = cunt;
  216. AllAnalysisDetails1.Rows.Add(dr3);
  217. }
  218. }
  219. return AllAnalysisDetails1;
  220. }
  221. private DataTable ConSolidateInvalid(DataTable dt)
  222. {
  223. DataTable dt_invalid = dt.Clone();
  224. DataTable dt_no_invalid = dt.Clone();
  225. for (int i = 0; i < dt.Rows.Count; i++)
  226. {
  227. if (dt.Rows[i]["TypeName"].ToString() == "Invalid")
  228. {
  229. dt_invalid.Rows.Add(dt.Rows[i].ItemArray);
  230. }
  231. else
  232. {
  233. dt_no_invalid.Rows.Add(dt.Rows[i].ItemArray);
  234. }
  235. }
  236. return dt_no_invalid;
  237. }
  238. private string getWhere(string max, string min, string col)
  239. {
  240. if (col == "Area")
  241. {
  242. return col + ">=" + ((Convert.ToDouble(min) / 2) * (Convert.ToDouble(min) / 2) * Math.PI).ToString() + " and " + col + "<" + ((Convert.ToDouble(max) / 2) * (Convert.ToDouble(max) / 2) * Math.PI).ToString();
  243. }
  244. else
  245. {
  246. return col + ">=" + min + " and " + col + "<" + max;
  247. }
  248. }
  249. #endregion
  250. #region echarts
  251. /// <summary>
  252. /// 通过m_list_chartstruct,组合json数据格式
  253. /// </summary>
  254. /// <returns></returns>
  255. private List<DataTable> GetListJsonStr()
  256. {
  257. int sel = m_conditionChoose.m_conditionData.ProItemProIndex();
  258. string filedAndParticl = "";
  259. DataOperation.DataAccess.ParticleData particledata = null;
  260. DataTable dt = new DataTable();
  261. List<DataTable> ListData = new List<DataTable>();
  262. string sou = m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  263. for (int i = 0; i < sou.Split('+').Length; i++)
  264. {
  265. ResultFile resultFile = m_DataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
  266. if (resultFile == null)
  267. {
  268. continue;
  269. }
  270. particledata = new DataOperation.DataAccess.ParticleData(resultFile.FilePath);
  271. switch (ComSel)
  272. {
  273. case "InclusionareaRatio":
  274. dt = particledata.GetAreaByAllIncA("");
  275. DataTable dtInclusionareaRatio = new DataTable();
  276. dtInclusionareaRatio.Columns.Add("name");
  277. dtInclusionareaRatio.Columns.Add("Cunt");
  278. for (int k = 0; k < dt.Rows.Count; k++)
  279. {
  280. string str = dt.Rows[k]["ar"].ToString();
  281. string name = dt.Rows[k]["TypeName"].ToString();
  282. if (Convert.ToInt32(dt.Rows[k]["TypeId"]) < 100)
  283. {
  284. continue;
  285. }
  286. DataRow dr = dtInclusionareaRatio.NewRow();
  287. dr["name"] = name;
  288. dr["Cunt"] = decimal.Round(decimal.Parse(dt.Rows[k]["ar"].ToString()), 2).ToString();
  289. dtInclusionareaRatio.Rows.Add(dr);
  290. }
  291. ListData.Add(dtInclusionareaRatio);
  292. break;
  293. case "CommonlyUsedClassify":
  294. //计算分类整个表的数据
  295. dt = ClassificationIntegration(resultFile.FilePath, sel);
  296. DataTable data = new DataTable();
  297. data.Columns.Add("name");
  298. data.Columns.Add("Cunt");
  299. for (int a = 0; a < dt.Rows.Count; a++)
  300. {
  301. DataRow dr = data.NewRow();
  302. dr["name"] = dt.Rows[a]["e1"].ToString();
  303. dr["Cunt"] = dt.Rows[a]["Cunt"].ToString();
  304. data.Rows.Add(dr);
  305. }
  306. ListData.Add(data);
  307. break;
  308. case "PComponent":
  309. //创建新的图形数据源
  310. dt = particledata.GetParticleListByIncA("area");
  311. DataTable dtPComponent = new DataTable();
  312. dtPComponent.Columns.Add("name");
  313. dtPComponent.Columns.Add("Cunt");
  314. for (int a = 0; a < dt.Rows.Count; a++)
  315. {
  316. if (Convert.ToInt32(dt.Rows[a]["TypeId"]) < 100)
  317. {
  318. continue;
  319. }
  320. DataRow dr = dtPComponent.NewRow();
  321. dr["name"] = dt.Rows[a]["TypeName"].ToString();
  322. dr["Cunt"] = dt.Rows[a]["con"].ToString();
  323. dtPComponent.Rows.Add(dr);
  324. }
  325. ListData.Add(dtPComponent);
  326. break;
  327. case "EComponent":
  328. //创建新的图形数据源
  329. dt = particledata.GetElementForArea(filedAndParticl);
  330. DataTable dtEComponent = new DataTable();
  331. dtEComponent.Columns.Add("name");
  332. dtEComponent.Columns.Add("Cunt");
  333. for (int k = 0; k < dt.Rows.Count; k++)
  334. {
  335. string str = dt.Rows[k]["earea"].ToString();
  336. try
  337. {
  338. DataRow dr = dtEComponent.NewRow();
  339. dr["name"] = dt.Rows[k]["name"].ToString();
  340. dr["Cunt"] = decimal.Round(decimal.Parse(str), 2).ToString();
  341. dtEComponent.Rows.Add(dr);
  342. }
  343. catch
  344. {
  345. DataRow dr = dtEComponent.NewRow();
  346. dr["name"] = dt.Rows[k]["name"].ToString();
  347. dr["Cunt"] = str;
  348. dtEComponent.Rows.Add(dr);
  349. }
  350. }
  351. ListData.Add(dtEComponent);
  352. break;
  353. case "PSize":
  354. //获取粒级表
  355. string pathe = m_DataMgr.m_RptConfigFile.PartSizeFileFolder + m_DataMgr.m_RptConfigFile.PartSizeFile;
  356. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(pathe);
  357. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  358. List<string> temp = new List<string>();
  359. for (int j = 0; j < sizestr.Split(',').Length - 1; j++)
  360. {
  361. if (sizestr.Split(',')[j].Length > 0)
  362. {
  363. double d1 = Convert.ToDouble(sizestr.Split(',')[j]);
  364. double d2 = Convert.ToDouble(sizestr.Split(',')[j + 1]);
  365. string name = d1.ToString() + "~" + d2.ToString();
  366. temp.Add(name);
  367. }
  368. }
  369. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  370. string name1 = d.ToString() + "~MAX";
  371. temp.Add(name1);
  372. string con = m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE).ToString();
  373. string po = "";
  374. switch (con)
  375. {
  376. case "DMAX":
  377. po = "DMAX";
  378. break;
  379. case "DMIN":
  380. po = "DMIN";
  381. break;
  382. case "ECD":
  383. po = "Area";
  384. break;
  385. case "FERET":
  386. po = "DFERET";
  387. break;
  388. }
  389. DataTable dtp = particledata.GetParticleAll(filedAndParticl);
  390. DataTable dtPSize = new DataTable();
  391. dtPSize.Columns.Add("name");
  392. dtPSize.Columns.Add("Cunt");
  393. for (int k = 0; k < temp.Count; k++)
  394. {
  395. string str = temp[k];
  396. string d1 = str.Split('~')[0];
  397. string d2 = str.Split('~')[1];
  398. if (d2 == "MAX")
  399. {
  400. d2 = "999";
  401. }
  402. DataRow[] datas = dtp.Select(getWhere(d2, d1, po));
  403. DataRow dr = dtPSize.NewRow();
  404. dr["name"] = str;
  405. dr["Cunt"] = datas.Count().ToString();
  406. dtPSize.Rows.Add(dr);
  407. }
  408. ListData.Add(dtPSize);
  409. break;
  410. }
  411. }
  412. return ListData;
  413. }
  414. #endregion
  415. private void Graphics()
  416. {
  417. chartControl1.Series.Clear();
  418. for (int i = 0; i < prListData.Count; i++)
  419. {
  420. string str = prListString[i];
  421. // 假设你已经有一个 ChartControl 实例,并且已经添加了一个饼图 Series
  422. Series series = new Series(str, ViewType.Bar);
  423. for (int a = 0; a < prListData[i].Rows.Count; a++)
  424. {
  425. string name = prListData[i].Rows[a]["name"].ToString();
  426. double Cunt = Convert.ToDouble(prListData[i].Rows[a]["Cunt"]);
  427. series.Points.Add(new SeriesPoint(name, Cunt));
  428. }
  429. series.LabelsVisibility = DefaultBoolean.True;
  430. chartControl1.Series.Add(series);
  431. }
  432. //图例的位置定义
  433. chartControl1.Legend.AlignmentVertical = LegendAlignmentVertical.Top;
  434. chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.RightOutside;
  435. chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
  436. chartControl1.Legend.Direction = LegendDirection.TopToBottom;
  437. //十字准线光标
  438. chartControl1.CrosshairEnabled = DefaultBoolean.True;
  439. chartControl1.CrosshairOptions.ShowValueLine = true;
  440. chartControl1.CrosshairOptions.ShowArgumentLabels = true;
  441. DevFunctions.ChangeView2(chartControl1, comboBox1.Text);
  442. }
  443. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  444. {
  445. Graphics();
  446. }
  447. }
  448. }