123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485 |
- using DevExpress.LookAndFeel;
- using DevExpress.XtraGrid.Views.Base;
- using DevExpress.XtraGrid.Views.Grid;
- using DevExpress.XtraReports.UI;
- using DevExpress.XtraReports.UserDesigner;
- using NPOI.XWPF.UserModel;
- using OTSCLRINTERFACE;
- using OTSIncAReportApp._1_UI.OTSReportExport;
- using OTSIncAReportApp.SysMgrTools;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using static DevExpress.Utils.Drawing.Helpers.NativeMethods;
- namespace OTSIncAReportGB
- {
- public partial class YB6156ABCD : UserControl
- {
- //设置数据表
- public DataTable m_dt = new DataTable();
- //底层相关,项目操作管理类
- CReportMgrClr m_ReportMgrClr = null;
- //获取从框架得到的底层计算结果,国标表A
- List<CGridDataClr> in_list_cgriddataclr = null;
- //接收底层数据
- public List<CGridDataClr> DataAll;
- Language lan;
- Hashtable table;
- public DataTable dt_yb6156 = new DataTable();
- Dictionary<int,double> Level_Coefficient=new Dictionary<int,double>();
- Dictionary<string, InclusionGradeInfo> SamplesInclusionGradeInfo;
- public struct InclusionGradeInfo
- {
- public int[] GradeACount;
- public int[] GradeBCount;
- public int[] GradeCCount;
- public int[] GradeDCount;
- public double S;
- public double O;
- public double Area;
- }
- public Dictionary<int,List<InclusionGradeInfo>> InclusionGradeInfos=new Dictionary<int, List<InclusionGradeInfo>>();
- public YB6156ABCD(CReportMgrClr in_Cotsreportprojfilemgrclr, List<CGridDataClr> in_list_CGridDataClrAll)
- {
- DataAll = in_list_CGridDataClrAll;
- m_ReportMgrClr = in_Cotsreportprojfilemgrclr;
- in_list_cgriddataclr = in_list_CGridDataClrAll.GetRange(0, in_list_CGridDataClrAll.Count);
- InitializeComponent();
- #region 国际化语言
- lan = new Language(this);
- table = lan.GetNameTable(this.Name);
- #endregion
- }
- private void YB6156ABCD_Load(object sender, EventArgs e)
- {
- Level_Coefficient.Clear();
- Level_Coefficient.Add(0,0.05);
- Level_Coefficient.Add(1, 0.1);
- Level_Coefficient.Add(2, 0.2);
- Level_Coefficient.Add(3, 0.5);
- Level_Coefficient.Add(4, 1);
- Level_Coefficient.Add(5, 2);
- Level_Coefficient.Add(6, 5);
- Level_Coefficient.Add(7, 10);
- Level_Coefficient.Add(8, 20);
- Level_Coefficient.Add(9, 50);
- comboBox_InitialRatingLevel.Items.Clear();
- comboBox_InitialRatingLevel.Items.Add("0");
- comboBox_InitialRatingLevel.Items.Add("1");
- comboBox_InitialRatingLevel.Items.Add("2");
- comboBox_InitialRatingLevel.Items.Add("3");
- comboBox_InitialRatingLevel.Items.Add("4");
- comboBox_InitialRatingLevel.Items.Add("5");
- comboBox_InitialRatingLevel.Items.Add("6");
- comboBox_InitialRatingLevel.Items.Add("7");
- comboBox_InitialRatingLevel.Items.Add("8");
- comboBox_InitialRatingLevel.Items.Add("9");
- comboBox_InitialRatingLevel.SelectedIndex = 0;
- this.comboBox_InitialRatingLevel.SelectedIndexChanged += new System.EventHandler(this.comboBox_InitialRatingLevel_SelectedIndexChanged);
- List<DataTable> dts = GetDataTable(in_list_cgriddataclr);
- SamplesInclusionGradeInfo=new Dictionary<string, InclusionGradeInfo>();
- int t = 1;
- foreach (DataTable dt in dts)
- {
- InclusionGradeInfo inclusionGradeInfo = CalInclusionGradeInfo(dt);
- SamplesInclusionGradeInfo.Add(t.ToString(),inclusionGradeInfo);
- t++;
- }
- dt_yb6156 = CreateTheDatatable(SamplesInclusionGradeInfo);
- FillTheDataToTheTable(dt_yb6156);
- }
- List<DataTable> GetDataTable(List<CGridDataClr> in_list_cgriddataclr)
- {
- List<DataTable> dataTables = new List<DataTable>();
- //判断传入的数据对象是否为空
- if (in_list_cgriddataclr == null)
- {
- string str1 = "传入分解表格数据的CGridDataClr对象为空!";
- str1 = table["str1"].ToString();
- //log.Error("(OTSIncAReportGridsFun.ChineseStandardABCD_GetDataTable_Total)" + str1);
- }
- #region 根据返回的结构创建DataTable的结构---------------------------------------------
- for (int i = 0; i < in_list_cgriddataclr.Count(); i++)
- {
- DataTable ret_dt = new DataTable(in_list_cgriddataclr[i].GetDataSourceList()[Convert.ToInt32(in_list_cgriddataclr[i].GetDataSourceId())].ToString());
- List<CGridColumnClr> list_cgridcolumnclrs = new List<CGridColumnClr>();
- list_cgridcolumnclrs = in_list_cgriddataclr[i].GetGridColumnList(); //获取各列
- foreach (CGridColumnClr ls_cgridcolumnclr in list_cgridcolumnclrs)
- {
- string ls_fl_strName = ls_cgridcolumnclr.GetName();
- ret_dt.Columns.Add(ls_fl_strName);
- }
- //取最大的rowlistcount,要不然,不知道这底层返回的数据居然还有2,2,3这样的行数据
- int maxrownumber = 0;
- //创建DT的行
- if (list_cgridcolumnclrs != null)
- {
- foreach (CGridColumnClr ls_cgridcolumnclr in list_cgridcolumnclrs)
- {
- if (maxrownumber < ls_cgridcolumnclr.GetRowList().Count())
- {
- maxrownumber = ls_cgridcolumnclr.GetRowList().Count();
- }
- }
- }
- for (int k = 0; k < maxrownumber; k++)
- {
- DataRow dr = ret_dt.NewRow();
- ret_dt.Rows.Add(dr);
- }
- for (int k = 0; k < list_cgridcolumnclrs.Count(); k++)
- {
- string ls_fl_strName = list_cgridcolumnclrs[k].GetName();
- List<CGridRowClr> ls_list_cgridrowclr = new List<CGridRowClr>();
- ls_list_cgridrowclr = list_cgridcolumnclrs[k].GetRowList();
- for (int j = 0; j < ls_list_cgridrowclr.Count(); j++)
- {
- //先判断该行该单元格的数据类型
- string str_value = "";//因为显示只需要对字符串进行操作就可以了,所以将底层获取到的数据,除了颗粒类型外的都转成string
- switch (ls_list_cgridrowclr[j].GetDataType())
- {
- case 0:
- //string
- str_value = ls_list_cgridrowclr[j].GetStringValue();
- ret_dt.Rows[j][k] = str_value;
- break;
- case 1:
- //该元素含量表没有需要显示的颗粒图像
- //ret_dt.Rows[j][k+i*oneresult_columncount] = GetBitmapByParticleList(ls_list_cgridrowclr[k].GetParticle());
- break;
- case 2:
- //int
- str_value = ls_list_cgridrowclr[j].GetIntValue().ToString();
- ret_dt.Rows[j][k] = str_value;
- break;
- case 3:
- //float
- str_value = ls_list_cgridrowclr[j].GetDoubleValue().ToString("0.00");
- ret_dt.Rows[j][k] = str_value;
- break;
- default:
- str_value = "";
- ret_dt.Rows[j][k] = str_value;
- break;
- }
- }
- }
- dataTables.Add(ret_dt);
- }
- #endregion
- return dataTables;
- }
- void FillTheDataToTheTable(DataTable dataTable)
- {
- gridControl_YB6156.DataSource = dataTable;
- //gridControl_YB6156.
- }
- DataTable CreateTheDatatable(Dictionary<string, InclusionGradeInfo> SamplesInclusionGradeInfo)
- {
- DataTable dt = new DataTable("yb6156");
- DataColumn SampleId = new DataColumn("SampleId", Type.GetType("System.String"));
- DataColumn Area = new DataColumn("Area", Type.GetType("System.String"));
- DataColumn InclusionType = new DataColumn("InclusionType", Type.GetType("System.String"));
- DataColumn TypeLevel = new DataColumn("TypeLevel", Type.GetType("System.String"));
- DataColumn Gride0Count = new DataColumn("Gride0Count", Type.GetType("System.String"));
- DataColumn Gride1Count = new DataColumn("Gride1Count", Type.GetType("System.String"));
- DataColumn Gride2Count = new DataColumn("Gride2Count", Type.GetType("System.String"));
- DataColumn Gride3Count = new DataColumn("Gride3Count", Type.GetType("System.String"));
- DataColumn Gride4Count = new DataColumn("Gride4Count", Type.GetType("System.String"));
- DataColumn Gride5Count = new DataColumn("Gride5Count", Type.GetType("System.String"));
- DataColumn Gride6Count = new DataColumn("Gride6Count", Type.GetType("System.String"));
- DataColumn Gride7Count = new DataColumn("Gride7Count", Type.GetType("System.String"));
- DataColumn Gride8Count = new DataColumn("Gride8Count", Type.GetType("System.String"));
- DataColumn Gride9Count = new DataColumn("Gride9Count", Type.GetType("System.String"));
- DataColumn TotalS = new DataColumn("TotalS", Type.GetType("System.String"));
- DataColumn TotalO = new DataColumn("TotalO", Type.GetType("System.String"));
- dt.Columns.Add(SampleId);
- dt.Columns.Add(Area);
- dt.Columns.Add(InclusionType);
- dt.Columns.Add(TypeLevel);
- dt.Columns.Add(Gride0Count);
- dt.Columns.Add(Gride1Count);
- dt.Columns.Add(Gride2Count);
- dt.Columns.Add(Gride3Count);
- dt.Columns.Add(Gride4Count);
- dt.Columns.Add(Gride5Count);
- dt.Columns.Add(Gride6Count);
- dt.Columns.Add(Gride7Count);
- dt.Columns.Add(Gride8Count);
- dt.Columns.Add(Gride9Count);
- dt.Columns.Add(TotalS);
- dt.Columns.Add(TotalO);
- double TotalArea = 0;
- double TotalS2 = 0;
- double TotalO2 = 0;
- foreach (KeyValuePair<string, InclusionGradeInfo> InclusionGradeInfo in SamplesInclusionGradeInfo)
- {
- TotalArea += Convert.ToDouble(InclusionGradeInfo.Value.Area);
- double ToO = 0;
- for (int i = Convert.ToInt32(comboBox_InitialRatingLevel.SelectedItem); i < 10; i++)
- {
- int GradeCount = Convert.ToInt32(InclusionGradeInfo.Value.GradeBCount[i]);
- ToO += GradeCount * Level_Coefficient[i];
- GradeCount = Convert.ToInt32(InclusionGradeInfo.Value.GradeCCount[i]);
- ToO += GradeCount * Level_Coefficient[i];
- GradeCount = Convert.ToInt32(InclusionGradeInfo.Value.GradeDCount[i]);
- ToO += GradeCount * Level_Coefficient[i];
- }
- TotalO2 += ToO;
- for (int k=0;k<4;k++)
- {
- DataRow dr = dt.NewRow();
- dr["SampleId"] = InclusionGradeInfo.Key;
- dr["Area"] = InclusionGradeInfo.Value.Area;
- switch (k)
- {
- case 0:
- double toS = 0;
- dr["InclusionType"] = "硫化物";
- dr["TypeLevel"] = "A";
- for (int i = 0; i < 10; i++)
- {
- if (i < Convert.ToInt32(comboBox_InitialRatingLevel.SelectedItem))
- {
- dr["Gride" + i + "Count"] = "-";
- }
- else
- {
- dr["Gride" + i + "Count"] = InclusionGradeInfo.Value.GradeACount[i];
- int GradeCount = Convert.ToInt32(InclusionGradeInfo.Value.GradeACount[i]);
- toS += GradeCount * Level_Coefficient[i];
- }
- }
- dr["TotalS"] = toS;
- dr["TotalO"] = "-";
- TotalS2 += toS;
- dt.Rows.Add(dr);
- break;
- case 1:
- dr["InclusionType"] = "氧化物";
- dr["TypeLevel"] = "B";
- for (int i = 0; i < 10; i++)
- {
- if (i < Convert.ToInt32(comboBox_InitialRatingLevel.SelectedItem))
- {
- dr["Gride" + i + "Count"] = "-";
- }
- else
- {
- dr["Gride" + i + "Count"] = InclusionGradeInfo.Value.GradeBCount[i];
- }
- }
- dr["TotalS"] = "-";
- dr["TotalO"] = ToO;
- dt.Rows.Add(dr);
- break;
- case 2:
- dr["InclusionType"] = "氧化物";
- dr["TypeLevel"] = "C";
- for (int i = 0; i < 10; i++)
- {
- if (i < Convert.ToInt32(comboBox_InitialRatingLevel.SelectedItem))
- {
- dr["Gride" + i + "Count"] = "-";
- }
- else
- {
- dr["Gride" + i + "Count"] = InclusionGradeInfo.Value.GradeCCount[i];
- }
- }
- dr["TotalS"] = "-";
- dr["TotalO"] = ToO;
- dt.Rows.Add(dr);
- break;
- case 3:
- dr["InclusionType"] = "氧化物";
- dr["TypeLevel"] = "D";
- for (int i = 0; i < 10; i++)
- {
- if (i < Convert.ToInt32(comboBox_InitialRatingLevel.SelectedItem))
- {
- dr["Gride" + i + "Count"] = "-";
- }
- else
- {
- dr["Gride" + i + "Count"] = InclusionGradeInfo.Value.GradeDCount[i];
- }
- }
- dr["TotalS"] = "-";
- dr["TotalO"] = ToO;
- dt.Rows.Add(dr);
- break;
- default:
- break;
- }
- }
- }
- DataRow dr1 = dt.NewRow();
- dr1["SampleId"] = "Total";
- dr1["Area"] = TotalArea.ToString();
- dr1["Gride9Count"] = "第二次求和值";
- dr1["TotalS"] = TotalS2;
- dr1["TotalO"] = TotalO2;
- dt.Rows.Add(dr1);
- DataRow dr2 = dt.NewRow();
- dr2["SampleId"] = "Total";
- dr2["Area"] = TotalArea.ToString();
- dr2["Gride9Count"] = "特征值";
- dr2["TotalS"] = (TotalS2 *1000/ TotalArea).ToString("F2");
- dr2["TotalO"] = (TotalO2 * 1000 / TotalArea).ToString("F2");
- dt.Rows.Add(dr2);
- DataRow dr3 = dt.NewRow();
- dr3["SampleId"] = "Total";
- dr3["Area"] = TotalArea;
- dr3["Gride9Count"] = "总特征值";
- dr3["TotalO"] = (TotalS2 * 1000 / TotalArea + TotalO2 * 1000 / TotalArea).ToString("F2");
- dt.Rows.Add(dr3);
- return dt;
- }
- InclusionGradeInfo CalInclusionGradeInfo(DataTable dt)
- {
- InclusionGradeInfo inclusionGradeInfo= new InclusionGradeInfo();
- inclusionGradeInfo.GradeACount = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- inclusionGradeInfo.GradeBCount = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- inclusionGradeInfo.GradeCCount = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- inclusionGradeInfo.GradeDCount = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- foreach (DataRow dr in dt.Rows) {
- int ret = CalInclusionGradeByArea(Convert.ToDouble(dr[0]));
- if (ret != -1)
- {
- inclusionGradeInfo.GradeACount[ret] += 1;
- }
- ret = CalInclusionGradeByArea(Convert.ToDouble(dr[1]));
- if (ret != -1)
- {
- inclusionGradeInfo.GradeBCount[ret] += 1;
- }
- ret = CalInclusionGradeByArea(Convert.ToDouble(dr[2]));
- if (ret != -1)
- {
- inclusionGradeInfo.GradeCCount[ret] += 1;
- }
- ret = CalInclusionGradeByArea(Convert.ToDouble(dr[3]));
- if (ret != -1)
- {
- inclusionGradeInfo.GradeDCount[ret] += 1;
- }
- }
- inclusionGradeInfo.Area= dt.Rows.Count*0.5;
- return inclusionGradeInfo;
- }
- int CalInclusionGradeByArea(double Area)
- {
- if (Area < 71)
- {
- return -1;
- }
- else if (Area < 141)
- {
- return 0;
- }
- else if (Area < 283)
- {
- return 1;
- }
- else if (Area < 566)
- { return 2; }
- else if (Area < 1131)
- { return 3; }
- else if (Area < 2263)
- { return 4; }
- else if (Area < 4525)
- { return 5; }
- else if (Area < 9051)
- { return 6; }
- else if (Area < 18102)
- { return 7; }
- else if (Area < 36204)
- { return 8; }
- else
- { return 9; }
- }
- private void gridView1_CellMerge(object sender, CellMergeEventArgs e)
- {
- GridView gridView1 = sender as GridView;
- if (e.Column != gridView1.Columns["gridColumn15"] && e.Column != gridView1.Columns["gridColumn16"]) return;
- DataRow dataRow = gridView1.GetDataRow(e.RowHandle1);
- if (dataRow["Gride0Count"].ToString() == "")
- {
- e.Merge = false;
- e.Handled = true;
- }
- dataRow = gridView1.GetDataRow(e.RowHandle2);
- if (dataRow["Gride0Count"].ToString() == "")
- {
- e.Merge = false;
- e.Handled = true;
- }
- }
- private void comboBox_InitialRatingLevel_SelectedIndexChanged(object sender, EventArgs e)
- {
- dt_yb6156 = CreateTheDatatable(SamplesInclusionGradeInfo);
- gridControl_YB6156.DataSource= dt_yb6156;
- this.Refresh();
- }
- private void button_export_Click(object sender, EventArgs e)
- {
- XtraReport_yb6156 Report_yb6156 = new XtraReport_yb6156(dt_yb6156);
- DevExpress.XtraReports.UI.ReportPrintTool tool = new DevExpress.XtraReports.UI.ReportPrintTool(Report_yb6156);
- tool.ShowPreview();
- //XRDesignForm designForm = new XRDesignForm();
- //designForm.OpenReport(Report_yb6156);
- //designForm.Show();
- }
- }
- }
-
|