YB6156ABCD.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. using DevExpress.LookAndFeel;
  2. using DevExpress.XtraGrid.Views.Base;
  3. using DevExpress.XtraGrid.Views.Grid;
  4. using DevExpress.XtraReports.UI;
  5. using DevExpress.XtraReports.UserDesigner;
  6. using NPOI.XWPF.UserModel;
  7. using OTSCLRINTERFACE;
  8. using OTSIncAReportApp._1_UI.OTSReportExport;
  9. using OTSIncAReportApp.SysMgrTools;
  10. using System;
  11. using System.Collections;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.Data;
  15. using System.Drawing;
  16. using System.Linq;
  17. using System.Security.Cryptography;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using System.Windows.Forms;
  21. using static DevExpress.Utils.Drawing.Helpers.NativeMethods;
  22. namespace OTSIncAReportGB
  23. {
  24. public partial class YB6156ABCD : UserControl
  25. {
  26. //设置数据表
  27. public DataTable m_dt = new DataTable();
  28. //底层相关,项目操作管理类
  29. CReportMgrClr m_ReportMgrClr = null;
  30. //获取从框架得到的底层计算结果,国标表A
  31. List<CGridDataClr> in_list_cgriddataclr = null;
  32. //接收底层数据
  33. public List<CGridDataClr> DataAll;
  34. Language lan;
  35. Hashtable table;
  36. public DataTable dt_yb6156 = new DataTable();
  37. Dictionary<int,double> Level_Coefficient=new Dictionary<int,double>();
  38. Dictionary<string, InclusionGradeInfo> SamplesInclusionGradeInfo;
  39. public struct InclusionGradeInfo
  40. {
  41. public int[] GradeACount;
  42. public int[] GradeBCount;
  43. public int[] GradeCCount;
  44. public int[] GradeDCount;
  45. public double S;
  46. public double O;
  47. public double Area;
  48. }
  49. public Dictionary<int,List<InclusionGradeInfo>> InclusionGradeInfos=new Dictionary<int, List<InclusionGradeInfo>>();
  50. public YB6156ABCD(CReportMgrClr in_Cotsreportprojfilemgrclr, List<CGridDataClr> in_list_CGridDataClrAll)
  51. {
  52. DataAll = in_list_CGridDataClrAll;
  53. m_ReportMgrClr = in_Cotsreportprojfilemgrclr;
  54. in_list_cgriddataclr = in_list_CGridDataClrAll.GetRange(0, in_list_CGridDataClrAll.Count);
  55. InitializeComponent();
  56. #region 国际化语言
  57. lan = new Language(this);
  58. table = lan.GetNameTable(this.Name);
  59. #endregion
  60. }
  61. private void YB6156ABCD_Load(object sender, EventArgs e)
  62. {
  63. Level_Coefficient.Clear();
  64. Level_Coefficient.Add(0,0.05);
  65. Level_Coefficient.Add(1, 0.1);
  66. Level_Coefficient.Add(2, 0.2);
  67. Level_Coefficient.Add(3, 0.5);
  68. Level_Coefficient.Add(4, 1);
  69. Level_Coefficient.Add(5, 2);
  70. Level_Coefficient.Add(6, 5);
  71. Level_Coefficient.Add(7, 10);
  72. Level_Coefficient.Add(8, 20);
  73. Level_Coefficient.Add(9, 50);
  74. comboBox_InitialRatingLevel.Items.Clear();
  75. comboBox_InitialRatingLevel.Items.Add("0");
  76. comboBox_InitialRatingLevel.Items.Add("1");
  77. comboBox_InitialRatingLevel.Items.Add("2");
  78. comboBox_InitialRatingLevel.Items.Add("3");
  79. comboBox_InitialRatingLevel.Items.Add("4");
  80. comboBox_InitialRatingLevel.Items.Add("5");
  81. comboBox_InitialRatingLevel.Items.Add("6");
  82. comboBox_InitialRatingLevel.Items.Add("7");
  83. comboBox_InitialRatingLevel.Items.Add("8");
  84. comboBox_InitialRatingLevel.Items.Add("9");
  85. comboBox_InitialRatingLevel.SelectedIndex = 0;
  86. this.comboBox_InitialRatingLevel.SelectedIndexChanged += new System.EventHandler(this.comboBox_InitialRatingLevel_SelectedIndexChanged);
  87. List<DataTable> dts = GetDataTable(in_list_cgriddataclr);
  88. SamplesInclusionGradeInfo=new Dictionary<string, InclusionGradeInfo>();
  89. int t = 1;
  90. foreach (DataTable dt in dts)
  91. {
  92. InclusionGradeInfo inclusionGradeInfo = CalInclusionGradeInfo(dt);
  93. SamplesInclusionGradeInfo.Add(t.ToString(),inclusionGradeInfo);
  94. t++;
  95. }
  96. dt_yb6156 = CreateTheDatatable(SamplesInclusionGradeInfo);
  97. FillTheDataToTheTable(dt_yb6156);
  98. }
  99. List<DataTable> GetDataTable(List<CGridDataClr> in_list_cgriddataclr)
  100. {
  101. List<DataTable> dataTables = new List<DataTable>();
  102. //判断传入的数据对象是否为空
  103. if (in_list_cgriddataclr == null)
  104. {
  105. string str1 = "传入分解表格数据的CGridDataClr对象为空!";
  106. str1 = table["str1"].ToString();
  107. //log.Error("(OTSIncAReportGridsFun.ChineseStandardABCD_GetDataTable_Total)" + str1);
  108. }
  109. #region 根据返回的结构创建DataTable的结构---------------------------------------------
  110. for (int i = 0; i < in_list_cgriddataclr.Count(); i++)
  111. {
  112. DataTable ret_dt = new DataTable(in_list_cgriddataclr[i].GetDataSourceList()[Convert.ToInt32(in_list_cgriddataclr[i].GetDataSourceId())].ToString());
  113. List<CGridColumnClr> list_cgridcolumnclrs = new List<CGridColumnClr>();
  114. list_cgridcolumnclrs = in_list_cgriddataclr[i].GetGridColumnList(); //获取各列
  115. foreach (CGridColumnClr ls_cgridcolumnclr in list_cgridcolumnclrs)
  116. {
  117. string ls_fl_strName = ls_cgridcolumnclr.GetName();
  118. ret_dt.Columns.Add(ls_fl_strName);
  119. }
  120. //取最大的rowlistcount,要不然,不知道这底层返回的数据居然还有2,2,3这样的行数据
  121. int maxrownumber = 0;
  122. //创建DT的行
  123. if (list_cgridcolumnclrs != null)
  124. {
  125. foreach (CGridColumnClr ls_cgridcolumnclr in list_cgridcolumnclrs)
  126. {
  127. if (maxrownumber < ls_cgridcolumnclr.GetRowList().Count())
  128. {
  129. maxrownumber = ls_cgridcolumnclr.GetRowList().Count();
  130. }
  131. }
  132. }
  133. for (int k = 0; k < maxrownumber; k++)
  134. {
  135. DataRow dr = ret_dt.NewRow();
  136. ret_dt.Rows.Add(dr);
  137. }
  138. for (int k = 0; k < list_cgridcolumnclrs.Count(); k++)
  139. {
  140. string ls_fl_strName = list_cgridcolumnclrs[k].GetName();
  141. List<CGridRowClr> ls_list_cgridrowclr = new List<CGridRowClr>();
  142. ls_list_cgridrowclr = list_cgridcolumnclrs[k].GetRowList();
  143. for (int j = 0; j < ls_list_cgridrowclr.Count(); j++)
  144. {
  145. //先判断该行该单元格的数据类型
  146. string str_value = "";//因为显示只需要对字符串进行操作就可以了,所以将底层获取到的数据,除了颗粒类型外的都转成string
  147. switch (ls_list_cgridrowclr[j].GetDataType())
  148. {
  149. case 0:
  150. //string
  151. str_value = ls_list_cgridrowclr[j].GetStringValue();
  152. ret_dt.Rows[j][k] = str_value;
  153. break;
  154. case 1:
  155. //该元素含量表没有需要显示的颗粒图像
  156. //ret_dt.Rows[j][k+i*oneresult_columncount] = GetBitmapByParticleList(ls_list_cgridrowclr[k].GetParticle());
  157. break;
  158. case 2:
  159. //int
  160. str_value = ls_list_cgridrowclr[j].GetIntValue().ToString();
  161. ret_dt.Rows[j][k] = str_value;
  162. break;
  163. case 3:
  164. //float
  165. str_value = ls_list_cgridrowclr[j].GetDoubleValue().ToString("0.00");
  166. ret_dt.Rows[j][k] = str_value;
  167. break;
  168. default:
  169. str_value = "";
  170. ret_dt.Rows[j][k] = str_value;
  171. break;
  172. }
  173. }
  174. }
  175. dataTables.Add(ret_dt);
  176. }
  177. #endregion
  178. return dataTables;
  179. }
  180. void FillTheDataToTheTable(DataTable dataTable)
  181. {
  182. gridControl_YB6156.DataSource = dataTable;
  183. //gridControl_YB6156.
  184. }
  185. DataTable CreateTheDatatable(Dictionary<string, InclusionGradeInfo> SamplesInclusionGradeInfo)
  186. {
  187. DataTable dt = new DataTable("yb6156");
  188. DataColumn SampleId = new DataColumn("SampleId", Type.GetType("System.String"));
  189. DataColumn Area = new DataColumn("Area", Type.GetType("System.String"));
  190. DataColumn InclusionType = new DataColumn("InclusionType", Type.GetType("System.String"));
  191. DataColumn TypeLevel = new DataColumn("TypeLevel", Type.GetType("System.String"));
  192. DataColumn Gride0Count = new DataColumn("Gride0Count", Type.GetType("System.String"));
  193. DataColumn Gride1Count = new DataColumn("Gride1Count", Type.GetType("System.String"));
  194. DataColumn Gride2Count = new DataColumn("Gride2Count", Type.GetType("System.String"));
  195. DataColumn Gride3Count = new DataColumn("Gride3Count", Type.GetType("System.String"));
  196. DataColumn Gride4Count = new DataColumn("Gride4Count", Type.GetType("System.String"));
  197. DataColumn Gride5Count = new DataColumn("Gride5Count", Type.GetType("System.String"));
  198. DataColumn Gride6Count = new DataColumn("Gride6Count", Type.GetType("System.String"));
  199. DataColumn Gride7Count = new DataColumn("Gride7Count", Type.GetType("System.String"));
  200. DataColumn Gride8Count = new DataColumn("Gride8Count", Type.GetType("System.String"));
  201. DataColumn Gride9Count = new DataColumn("Gride9Count", Type.GetType("System.String"));
  202. DataColumn TotalS = new DataColumn("TotalS", Type.GetType("System.String"));
  203. DataColumn TotalO = new DataColumn("TotalO", Type.GetType("System.String"));
  204. dt.Columns.Add(SampleId);
  205. dt.Columns.Add(Area);
  206. dt.Columns.Add(InclusionType);
  207. dt.Columns.Add(TypeLevel);
  208. dt.Columns.Add(Gride0Count);
  209. dt.Columns.Add(Gride1Count);
  210. dt.Columns.Add(Gride2Count);
  211. dt.Columns.Add(Gride3Count);
  212. dt.Columns.Add(Gride4Count);
  213. dt.Columns.Add(Gride5Count);
  214. dt.Columns.Add(Gride6Count);
  215. dt.Columns.Add(Gride7Count);
  216. dt.Columns.Add(Gride8Count);
  217. dt.Columns.Add(Gride9Count);
  218. dt.Columns.Add(TotalS);
  219. dt.Columns.Add(TotalO);
  220. double TotalArea = 0;
  221. double TotalS2 = 0;
  222. double TotalO2 = 0;
  223. foreach (KeyValuePair<string, InclusionGradeInfo> InclusionGradeInfo in SamplesInclusionGradeInfo)
  224. {
  225. TotalArea += Convert.ToDouble(InclusionGradeInfo.Value.Area);
  226. double ToO = 0;
  227. for (int i = Convert.ToInt32(comboBox_InitialRatingLevel.SelectedItem); i < 10; i++)
  228. {
  229. int GradeCount = Convert.ToInt32(InclusionGradeInfo.Value.GradeBCount[i]);
  230. ToO += GradeCount * Level_Coefficient[i];
  231. GradeCount = Convert.ToInt32(InclusionGradeInfo.Value.GradeCCount[i]);
  232. ToO += GradeCount * Level_Coefficient[i];
  233. GradeCount = Convert.ToInt32(InclusionGradeInfo.Value.GradeDCount[i]);
  234. ToO += GradeCount * Level_Coefficient[i];
  235. }
  236. TotalO2 += ToO;
  237. for (int k=0;k<4;k++)
  238. {
  239. DataRow dr = dt.NewRow();
  240. dr["SampleId"] = InclusionGradeInfo.Key;
  241. dr["Area"] = InclusionGradeInfo.Value.Area;
  242. switch (k)
  243. {
  244. case 0:
  245. double toS = 0;
  246. dr["InclusionType"] = "硫化物";
  247. dr["TypeLevel"] = "A";
  248. for (int i = 0; i < 10; i++)
  249. {
  250. if (i < Convert.ToInt32(comboBox_InitialRatingLevel.SelectedItem))
  251. {
  252. dr["Gride" + i + "Count"] = "-";
  253. }
  254. else
  255. {
  256. dr["Gride" + i + "Count"] = InclusionGradeInfo.Value.GradeACount[i];
  257. int GradeCount = Convert.ToInt32(InclusionGradeInfo.Value.GradeACount[i]);
  258. toS += GradeCount * Level_Coefficient[i];
  259. }
  260. }
  261. dr["TotalS"] = toS;
  262. dr["TotalO"] = "-";
  263. TotalS2 += toS;
  264. dt.Rows.Add(dr);
  265. break;
  266. case 1:
  267. dr["InclusionType"] = "氧化物";
  268. dr["TypeLevel"] = "B";
  269. for (int i = 0; i < 10; i++)
  270. {
  271. if (i < Convert.ToInt32(comboBox_InitialRatingLevel.SelectedItem))
  272. {
  273. dr["Gride" + i + "Count"] = "-";
  274. }
  275. else
  276. {
  277. dr["Gride" + i + "Count"] = InclusionGradeInfo.Value.GradeBCount[i];
  278. }
  279. }
  280. dr["TotalS"] = "-";
  281. dr["TotalO"] = ToO;
  282. dt.Rows.Add(dr);
  283. break;
  284. case 2:
  285. dr["InclusionType"] = "氧化物";
  286. dr["TypeLevel"] = "C";
  287. for (int i = 0; i < 10; i++)
  288. {
  289. if (i < Convert.ToInt32(comboBox_InitialRatingLevel.SelectedItem))
  290. {
  291. dr["Gride" + i + "Count"] = "-";
  292. }
  293. else
  294. {
  295. dr["Gride" + i + "Count"] = InclusionGradeInfo.Value.GradeCCount[i];
  296. }
  297. }
  298. dr["TotalS"] = "-";
  299. dr["TotalO"] = ToO;
  300. dt.Rows.Add(dr);
  301. break;
  302. case 3:
  303. dr["InclusionType"] = "氧化物";
  304. dr["TypeLevel"] = "D";
  305. for (int i = 0; i < 10; i++)
  306. {
  307. if (i < Convert.ToInt32(comboBox_InitialRatingLevel.SelectedItem))
  308. {
  309. dr["Gride" + i + "Count"] = "-";
  310. }
  311. else
  312. {
  313. dr["Gride" + i + "Count"] = InclusionGradeInfo.Value.GradeDCount[i];
  314. }
  315. }
  316. dr["TotalS"] = "-";
  317. dr["TotalO"] = ToO;
  318. dt.Rows.Add(dr);
  319. break;
  320. default:
  321. break;
  322. }
  323. }
  324. }
  325. DataRow dr1 = dt.NewRow();
  326. dr1["SampleId"] = "Total";
  327. dr1["Area"] = TotalArea.ToString();
  328. dr1["Gride9Count"] = "第二次求和值";
  329. dr1["TotalS"] = TotalS2;
  330. dr1["TotalO"] = TotalO2;
  331. dt.Rows.Add(dr1);
  332. DataRow dr2 = dt.NewRow();
  333. dr2["SampleId"] = "Total";
  334. dr2["Area"] = TotalArea.ToString();
  335. dr2["Gride9Count"] = "特征值";
  336. dr2["TotalS"] = (TotalS2 *1000/ TotalArea).ToString("F2");
  337. dr2["TotalO"] = (TotalO2 * 1000 / TotalArea).ToString("F2");
  338. dt.Rows.Add(dr2);
  339. DataRow dr3 = dt.NewRow();
  340. dr3["SampleId"] = "Total";
  341. dr3["Area"] = TotalArea;
  342. dr3["Gride9Count"] = "总特征值";
  343. dr3["TotalO"] = (TotalS2 * 1000 / TotalArea + TotalO2 * 1000 / TotalArea).ToString("F2");
  344. dt.Rows.Add(dr3);
  345. return dt;
  346. }
  347. InclusionGradeInfo CalInclusionGradeInfo(DataTable dt)
  348. {
  349. InclusionGradeInfo inclusionGradeInfo= new InclusionGradeInfo();
  350. inclusionGradeInfo.GradeACount = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  351. inclusionGradeInfo.GradeBCount = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  352. inclusionGradeInfo.GradeCCount = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  353. inclusionGradeInfo.GradeDCount = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  354. foreach (DataRow dr in dt.Rows) {
  355. int ret = CalInclusionGradeByArea(Convert.ToDouble(dr[0]));
  356. if (ret != -1)
  357. {
  358. inclusionGradeInfo.GradeACount[ret] += 1;
  359. }
  360. ret = CalInclusionGradeByArea(Convert.ToDouble(dr[1]));
  361. if (ret != -1)
  362. {
  363. inclusionGradeInfo.GradeBCount[ret] += 1;
  364. }
  365. ret = CalInclusionGradeByArea(Convert.ToDouble(dr[2]));
  366. if (ret != -1)
  367. {
  368. inclusionGradeInfo.GradeCCount[ret] += 1;
  369. }
  370. ret = CalInclusionGradeByArea(Convert.ToDouble(dr[3]));
  371. if (ret != -1)
  372. {
  373. inclusionGradeInfo.GradeDCount[ret] += 1;
  374. }
  375. }
  376. inclusionGradeInfo.Area= dt.Rows.Count*0.5;
  377. return inclusionGradeInfo;
  378. }
  379. int CalInclusionGradeByArea(double Area)
  380. {
  381. if (Area < 71)
  382. {
  383. return -1;
  384. }
  385. else if (Area < 141)
  386. {
  387. return 0;
  388. }
  389. else if (Area < 283)
  390. {
  391. return 1;
  392. }
  393. else if (Area < 566)
  394. { return 2; }
  395. else if (Area < 1131)
  396. { return 3; }
  397. else if (Area < 2263)
  398. { return 4; }
  399. else if (Area < 4525)
  400. { return 5; }
  401. else if (Area < 9051)
  402. { return 6; }
  403. else if (Area < 18102)
  404. { return 7; }
  405. else if (Area < 36204)
  406. { return 8; }
  407. else
  408. { return 9; }
  409. }
  410. private void gridView1_CellMerge(object sender, CellMergeEventArgs e)
  411. {
  412. GridView gridView1 = sender as GridView;
  413. if (e.Column != gridView1.Columns["gridColumn15"] && e.Column != gridView1.Columns["gridColumn16"]) return;
  414. DataRow dataRow = gridView1.GetDataRow(e.RowHandle1);
  415. if (dataRow["Gride0Count"].ToString() == "")
  416. {
  417. e.Merge = false;
  418. e.Handled = true;
  419. }
  420. dataRow = gridView1.GetDataRow(e.RowHandle2);
  421. if (dataRow["Gride0Count"].ToString() == "")
  422. {
  423. e.Merge = false;
  424. e.Handled = true;
  425. }
  426. }
  427. private void comboBox_InitialRatingLevel_SelectedIndexChanged(object sender, EventArgs e)
  428. {
  429. dt_yb6156 = CreateTheDatatable(SamplesInclusionGradeInfo);
  430. gridControl_YB6156.DataSource= dt_yb6156;
  431. this.Refresh();
  432. }
  433. private void button_export_Click(object sender, EventArgs e)
  434. {
  435. XtraReport_yb6156 Report_yb6156 = new XtraReport_yb6156(dt_yb6156);
  436. DevExpress.XtraReports.UI.ReportPrintTool tool = new DevExpress.XtraReports.UI.ReportPrintTool(Report_yb6156);
  437. tool.ShowPreview();
  438. //XRDesignForm designForm = new XRDesignForm();
  439. //designForm.OpenReport(Report_yb6156);
  440. //designForm.Show();
  441. }
  442. }
  443. }