using OTSIncAReportApp.Control_ECharts; using OTSIncAReportApp.DataOperation.DataAccess; using OTSIncAReportApp.DataOperation.Model; using OTSIncAReportGraph.Controls; using OTSIncAReportGrids; using OTSPeriodicTable; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; namespace OTSIncAReportApp.OTSTemplateDesigner { public class Export_ReportTemplate { #region 全局变量 public List m_list_dt; //导出的各模块数据,合集 public OTSReport_Export m_otsreport_export; List TemplateList; #endregion #region 构造函数 public Export_ReportTemplate(OTSReport_Export in_export) { m_otsreport_export = in_export; TemplateList = new List(); //加载三元相图各项 string pathtpf = in_export.m_ReportApp.m_RptConfigFile.FileFolderTrigTemp + "\\" + in_export.m_ReportApp.m_RptConfigFile.TriTempFile;// Application.StartupPath + "\\Config\\ProData\\DefaultTriTemplateFile.tpf"; TemplateList = new List(); DataSet ds = DataOperation.DataAccess.XMLoperate.GetXmlData(pathtpf, "XMLData"); DataTable dt = ds.Tables["Member"]; foreach (DataRow item in dt.Rows) { if (item["TemplateName"].ToString() != "") { TemplateList.Add(item["TemplateName"].ToString()); } } m_list_dt = new List(); } #endregion #region 插入测量结果Grid表格 /// /// 向 模板设计器 中插入测量结果Grid表格 /// /// public bool InsertReportTemplateTable_ResultGrid() { try { //------------------加载模块,获取数据------------------------------------------------- ResultGrid ls_resultgrid = new ResultGrid(m_otsreport_export.m_ReportApp); Dictionary keyValues_ResultGrid = ls_resultgrid.GetData_ResultGrid(); //------------------加载模块,获取数据结束---------------------------------------------- Dictionary.Enumerator en = keyValues_ResultGrid.GetEnumerator(); string str_CLJGMC = ""; string str_YXSJ = ""; string str_SCZS = ""; string str_FLFA = ""; string str_YJCTZ = ""; string str_SCMJ = ""; string str_CKBZ = "GB/130834-2014"; keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col1"].ToString(), out str_CLJGMC);//测量结果名称 keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col4"].ToString(), out str_YXSJ);//运行时间 keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col5"].ToString(), out str_SCZS);//视场总数 keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col6"].ToString(), out str_FLFA);//分类方案 keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col7"].ToString(), out str_YJCTZ);//已检测特征 keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col8"].ToString(), out str_SCMJ);//视场面积 //将获取到的数据转换成报告模板能接收的格式。 DataTable ls_new_dt = new DataTable(); ls_new_dt.TableName = "ResultGrid"; ls_new_dt.Columns.Add("CLJGMC"); //测量结果名称 ls_new_dt.Columns.Add("YXSJ"); //运行时间 ls_new_dt.Columns.Add("SCZS"); //视场总数 ls_new_dt.Columns.Add("FLFA"); //分类方案 ls_new_dt.Columns.Add("YJCTZ"); //已检测特征 ls_new_dt.Columns.Add("SCMJ"); //视场面积 ls_new_dt.Columns.Add("CKBZ"); //参考标准 //行转列,这里不会发生改变,所以这样写 DataRow dr = ls_new_dt.NewRow(); dr["CLJGMC"] = str_CLJGMC; dr["YXSJ"] = str_YXSJ; dr["SCZS"] = str_SCZS; dr["FLFA"] = str_FLFA; dr["YJCTZ"] = str_YJCTZ; dr["SCMJ"] = str_SCMJ; dr["CKBZ"] = str_CKBZ; ls_new_dt.Rows.Add(dr); m_list_dt.Add(ls_new_dt); return true; } catch (Exception ee) { string str = ee.ToString(); return false; } } #endregion #region 插入颗粒列表并带有帧图 /// /// 颗粒列表中插入帧图,并带上颗粒分组信息 /// /// public bool InsertReportTemplateTable_ParticlesGridDevidePage() { //------------------加载模块,获取数据------------------------------------------------- m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage = new ParticlesGridDevidePage(m_otsreport_export.m_ReportApp); //DataGridView gv_dt_ParticlesGridDevidePage_element = new DataGridView(); //DataTable dt_ParticlesGridDevidePage_element = new DataTable(); //m_otsreport_export.m_ReportApp.m_CTablesWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage); //m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage.GetDataTableAndGridView(out dt_ParticlesGridDevidePage_element, out gv_dt_ParticlesGridDevidePage_element); //根据sql条件,查询获取颗粒信息数据 DataTable dt_ParticlesGridDevidePage = new DataTable(); ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.resultFilesList[m_otsreport_export.m_ReportApp.WorkingResult].FilePath); dt_ParticlesGridDevidePage = fielddata.GetInfoForPartucleDevidePage(0, 200, "fieldid,particleid", ""); string str_resultPath = m_otsreport_export.m_ReportApp.resultFilesList[m_otsreport_export.m_ReportApp.WorkingResult].FilePath; //------------------加载模块,获取数据结束---------------------------------------------- #region 创建要插入数据库表结构 //插入模板需父子表,结构 //表名field_dt表:(父表) 帧图表 DataTable DT_field_dt = new DataTable(); DT_field_dt = new DataTable(); DT_field_dt.TableName = "field_dt"; DataColumn colpictid2 = new DataColumn("FieldId"); colpictid2.DataType = typeof(int); DT_field_dt.Columns.Add(colpictid2); //图像列 DataColumn colpict2 = new DataColumn("FieldImg"); colpict2.DataType = System.Type.GetType("System.Byte[]"); DT_field_dt.Columns.Add(colpict2); //表名Largest_frame表:(子表) 显示20条颗粒除外的部份颗粒信息 DataTable DT_Largest_frame = new DataTable(); DT_Largest_frame.TableName = "Largest_frame"; DT_Largest_frame.Columns.Add("pid"); DT_Largest_frame.Columns.Add("Size"); DT_Largest_frame.Columns.Add("Width"); DT_Largest_frame.Columns.Add("Class"); DT_Largest_frame.Columns.Add("ColName1"); DT_Largest_frame.Columns.Add("ColName2"); DT_Largest_frame.Columns.Add("ColName3"); DT_Largest_frame.Columns.Add("ColName4"); DT_Largest_frame.Columns.Add("ColName5"); DT_Largest_frame.Columns.Add("ColName6"); DT_Largest_frame.Columns.Add("ColVal1"); DT_Largest_frame.Columns.Add("ColVal2"); DT_Largest_frame.Columns.Add("ColVal3"); DT_Largest_frame.Columns.Add("ColVal4"); DT_Largest_frame.Columns.Add("ColVal5"); DT_Largest_frame.Columns.Add("ColVal6"); DataColumn colpictid = new DataColumn("FieldId"); colpictid.DataType = typeof(int); DT_Largest_frame.Columns.Add(colpictid); //图像列 DataColumn colpict = new DataColumn("p1"); colpict.DataType = System.Type.GetType("System.Byte[]"); DT_Largest_frame.Columns.Add(colpict); //largest20表:(无关系表) 需要显示前20条带有显示能谱图像的颗粒表 DataTable DT_Largest20 = new DataTable(); DT_Largest20.TableName = "Largest20"; DT_Largest20.Columns.Add("pid"); DT_Largest20.Columns.Add("Size"); DT_Largest20.Columns.Add("Width"); DT_Largest20.Columns.Add("Class"); DT_Largest20.Columns.Add("ColName1"); DT_Largest20.Columns.Add("ColName2"); DT_Largest20.Columns.Add("ColName3"); DT_Largest20.Columns.Add("ColName4"); DT_Largest20.Columns.Add("ColName5"); DT_Largest20.Columns.Add("ColName6"); DT_Largest20.Columns.Add("ColVal1"); DT_Largest20.Columns.Add("ColVal2"); DT_Largest20.Columns.Add("ColVal3"); DT_Largest20.Columns.Add("ColVal4"); DT_Largest20.Columns.Add("ColVal5"); DT_Largest20.Columns.Add("ColVal6"); // 图像列 DataColumn colpict_20ago = new DataColumn("p1"); colpict_20ago.DataType = System.Type.GetType("System.Byte[]"); DT_Largest20.Columns.Add(colpict_20ago); DataColumn colpict2_20ago = new DataColumn("p2"); colpict2_20ago.DataType = System.Type.GetType("System.Byte[]"); DT_Largest20.Columns.Add(colpict2_20ago); DataColumn colpict3_20ago = new DataColumn("p3"); colpict3_20ago.DataType = System.Type.GetType("System.Byte[]"); DT_Largest20.Columns.Add(colpict3_20ago); #endregion #region 插入-前20颗粒部份 for (int i_row = 0; i_row < 20; i_row++) { if (i_row < dt_ParticlesGridDevidePage.Rows.Count) { //获取颗粒的fieldid,和particleid string str_fieldid = dt_ParticlesGridDevidePage.Rows[i_row]["fieldid"].ToString(); string str_particleid = dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString(); string str_subparticles = dt_ParticlesGridDevidePage.Rows[i_row]["SubParticles"].ToString(); string str_typeid = dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString(); string str_typename = dt_ParticlesGridDevidePage.Rows[i_row]["TypeName"].ToString(); string str_element = dt_ParticlesGridDevidePage.Rows[i_row]["Element"].ToString(); //获取原始颗粒图像 Bitmap bp_particle = new Bitmap(1, 1); string str_path = str_resultPath + "\\FIELD_FILES\\"; string str_imagePath = str_path + "Field" + str_fieldid.ToString() + ".bmp"; if (str_fieldid == "-1") continue; if (str_subparticles != null && str_subparticles != "") { //合并大颗粒 double ScanFieldSize = 1142; Bitmap tempbit = fielddata.ReadImageFile(str_imagePath); int pixw = tempbit.Width; double xs = pixw / ScanFieldSize; bp_particle = fielddata.GetBitmapForBig(str_subparticles, xs, str_resultPath); } else { //正常颗粒 Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectLeft"]), Y = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectTop"]), Width = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectWidth"]), Height = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectHeight"]) }; Bitmap bp_field = fielddata.ReadImageFile(str_imagePath); bp_particle = fielddata.GetBitmapByParticle(bp_field, rectangle); bp_particle.Tag = new List() { dt_ParticlesGridDevidePage.Rows[i_row]["FieldId"].ToString(), dt_ParticlesGridDevidePage.Rows[i_row]["ParticleId"].ToString(), dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString() }; } //获取该颗粒的xray能谱图像 System.Drawing.Bitmap bp_xraybp = ExportXRayBitmap(str_fieldid, str_particleid, Convert.ToInt32(str_typeid), str_typename, fielddata); Bitmap ls_xraybpnew = new Bitmap(1, 1); ls_xraybpnew = OTSIncAReportGraph.Class.DrawFuncation.KiResizeImage(bp_xraybp, 700, 115);//能谱图处理 //获取该颗粒的二次放大处理图像 Bitmap ls_processbitmap = new Bitmap(1, 1); ls_processbitmap = OTSIncAReportGraph.Class.DrawFuncation.GetReZoomBitmap(bp_particle);// (Bitmap)bp_particle.Clone();//待完善 //再将图像转成二进制流------------------------------------------------------------------- //原图 MemoryStream newms_p1 = new MemoryStream(); bp_particle.Save(newms_p1, System.Drawing.Imaging.ImageFormat.Bmp); newms_p1.Seek(0, SeekOrigin.Begin); byte[] newarr_p1 = new byte[newms_p1.Length]; newms_p1.Read(newarr_p1, 0, newarr_p1.Length); //二次放大图 MemoryStream newms_p2 = new MemoryStream(); ls_processbitmap.Save(newms_p2, System.Drawing.Imaging.ImageFormat.Bmp); newms_p2.Seek(0, SeekOrigin.Begin); byte[] newarr_p2 = new byte[newms_p2.Length]; newms_p2.Read(newarr_p2, 0, newarr_p2.Length); //能谱图 MemoryStream newms_p3 = new MemoryStream(); ls_xraybpnew.Save(newms_p3, System.Drawing.Imaging.ImageFormat.Bmp); newms_p3.Seek(0, SeekOrigin.Begin); byte[] newarr_p3 = new byte[newms_p3.Length]; newms_p3.Read(newarr_p3, 0, newarr_p3.Length); //--------------------------------------------------------------------------------------- DataRow dr = DT_Largest20.NewRow(); dr["p1"] = newarr_p1; dr["p2"] = newarr_p2; dr["p3"] = newarr_p3; newms_p1.Dispose(); newms_p2.Dispose(); newms_p3.Dispose(); dr["pid"] = str_fieldid + dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString(); dr["Size"] = Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["area"]).ToString("#0.00"); //可以需要选择切换,计算方式 dr["Width"] = dt_ParticlesGridDevidePage.Rows[i_row]["rectwidth"].ToString(); dr["Class"] = dt_ParticlesGridDevidePage.Rows[i_row]["typename"].ToString(); List list_max_elementname = new List(); List list_max_elementvale = new List(); GetMaxElementFromDataTable(dt_ParticlesGridDevidePage, i_row, out list_max_elementname, out list_max_elementvale); //元素1 dr["ColName1"] = list_max_elementname[0]; dr["ColVal1"] = list_max_elementvale[0].ToString(); //元素2 dr["ColName2"] = list_max_elementname[1]; dr["ColVal2"] = list_max_elementvale[1].ToString(); //元素3 dr["ColName3"] = list_max_elementname[2]; dr["ColVal3"] = list_max_elementvale[2].ToString(); //元素4 dr["ColName4"] = list_max_elementname[3]; dr["ColVal4"] = list_max_elementvale[3].ToString(); //元素5 dr["ColName5"] = list_max_elementname[4]; dr["ColVal5"] = list_max_elementvale[4].ToString(); //元素6 dr["ColName6"] = list_max_elementname[5]; dr["ColVal6"] = list_max_elementvale[5].ToString(); DT_Largest20.Rows.Add(dr); } } #endregion #region 插入-帧图图像部份 //首先生成标记颗粒的帧图图像文件 m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage.SaveMarkParticleRectangleOnFieldFile(); string str_path_FIELD_FILES_MARK = str_resultPath + "\\FIELD_FILES_MARK\\"; DirectoryInfo theFolder = new DirectoryInfo(str_path_FIELD_FILES_MARK); if (theFolder.Exists) { foreach (FileInfo nextifile in theFolder.GetFiles()) { if (nextifile.Name.Contains(".bmp") == true || nextifile.Name.Contains(".BMP") == true) { //确认对应的帧图名 string str_fieldid = Path.GetFileNameWithoutExtension(nextifile.Name); //在数据表中有颗粒在该帧图中的话,则对该帧图标记图像进行读取存入数据库 DataRow[] datarowlist = dt_ParticlesGridDevidePage.Select(" fieldid = " + str_fieldid); if (datarowlist.Count() > 0) { Bitmap ls_bp_fieldmark = new Bitmap(nextifile.FullName); DataRow dr = DT_field_dt.NewRow(); MemoryStream newms_bp_fieldmark = new MemoryStream(); ls_bp_fieldmark.Save(newms_bp_fieldmark, System.Drawing.Imaging.ImageFormat.Bmp); newms_bp_fieldmark.Seek(0, SeekOrigin.Begin); byte[] newarr_fieldmark = new byte[newms_bp_fieldmark.Length]; newms_bp_fieldmark.Read(newarr_fieldmark, 0, newarr_fieldmark.Length); dr["FieldImg"] = newarr_fieldmark; dr["FieldId"] = str_fieldid; ls_bp_fieldmark.Dispose(); DT_field_dt.Rows.Add(dr); } } } } #endregion #region 插入-前20颗粒外的颗粒 for (int i_row = 20; i_row < dt_ParticlesGridDevidePage.Rows.Count; i_row++) { //获取颗粒的fieldid,和particleid string str_fieldid = dt_ParticlesGridDevidePage.Rows[i_row]["fieldid"].ToString(); string str_particleid = dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString(); string str_subparticles = dt_ParticlesGridDevidePage.Rows[i_row]["SubParticles"].ToString(); string str_typeid = dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString(); string str_typename = dt_ParticlesGridDevidePage.Rows[i_row]["TypeName"].ToString(); string str_element = dt_ParticlesGridDevidePage.Rows[i_row]["Element"].ToString(); //获取原始颗粒图像 Bitmap bp_particle = new Bitmap(1, 1); string str_path = str_resultPath + "\\FIELD_FILES\\"; string str_imagePath = str_path + "Field" + str_fieldid.ToString() + ".bmp"; if (str_subparticles != null && str_subparticles != "") { //合并大颗粒 double ScanFieldSize = 1142; Bitmap tempbit = fielddata.ReadImageFile(str_imagePath); int pixw = tempbit.Width; double xs = pixw / ScanFieldSize; bp_particle = fielddata.GetBitmapForBig(str_subparticles, xs, str_resultPath); } else { //正常颗粒 Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectLeft"]), Y = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectTop"]), Width = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectWidth"]), Height = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectHeight"]) }; Bitmap bp_field = fielddata.ReadImageFile(str_imagePath); bp_particle = fielddata.GetBitmapByParticle(bp_field, rectangle); bp_particle.Tag = new List() { dt_ParticlesGridDevidePage.Rows[i_row]["FieldId"].ToString(), dt_ParticlesGridDevidePage.Rows[i_row]["ParticleId"].ToString(), dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString() }; } //获取该颗粒的xray能谱图像 System.Drawing.Bitmap bp_xraybp = ExportXRayBitmap(str_fieldid, str_particleid, Convert.ToInt32(str_typeid), str_typename, fielddata); //获取该颗粒的二次放大处理图像 Bitmap ls_processbitmap = new Bitmap(1, 1); ls_processbitmap = (Bitmap)bp_particle.Clone();//待完善 //再将图像转成二进制流------------------------------------------------------------------- //原图 MemoryStream newms_p1 = new MemoryStream(); bp_particle.Save(newms_p1, System.Drawing.Imaging.ImageFormat.Bmp); newms_p1.Seek(0, SeekOrigin.Begin); byte[] newarr_p1 = new byte[newms_p1.Length]; newms_p1.Read(newarr_p1, 0, newarr_p1.Length); //--------------------------------------------------------------------------------------- DataRow dr = DT_Largest_frame.NewRow(); dr["p1"] = newarr_p1; newms_p1.Dispose(); dr["pid"] = str_fieldid + dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString(); dr["Size"] = Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["area"]).ToString("#0.00"); //可以需要选择切换,计算方式 dr["Width"] = dt_ParticlesGridDevidePage.Rows[i_row]["rectwidth"].ToString(); dr["Class"] = dt_ParticlesGridDevidePage.Rows[i_row]["typename"].ToString(); dr["fieldid"] = str_fieldid; List list_max_elementname = new List(); List list_max_elementvale = new List(); GetMaxElementFromDataTable(dt_ParticlesGridDevidePage, i_row, out list_max_elementname, out list_max_elementvale); //元素1 dr["ColName1"] = list_max_elementname[0]; dr["ColVal1"] = list_max_elementvale[0].ToString(); //元素2 dr["ColName2"] = list_max_elementname[1]; dr["ColVal2"] = list_max_elementvale[1].ToString(); //元素3 dr["ColName3"] = list_max_elementname[2]; dr["ColVal3"] = list_max_elementvale[2].ToString(); //元素4 dr["ColName4"] = list_max_elementname[3]; dr["ColVal4"] = list_max_elementvale[3].ToString(); //元素5 dr["ColName5"] = list_max_elementname[4]; dr["ColVal5"] = list_max_elementvale[4].ToString(); //元素6 dr["ColName6"] = list_max_elementname[5]; dr["ColVal6"] = list_max_elementvale[5].ToString(); DT_Largest_frame.Rows.Add(dr); } #endregion m_list_dt.Add(DT_field_dt); m_list_dt.Add(DT_Largest_frame); m_list_dt.Add(DT_Largest20); return true; } #endregion #region 插入颗粒尺寸表 /// /// 向 模板设计器 中插入 颗粒尺寸表 /// /// public bool InsertReportTemplateTable_ParticleSizeGrid() { try { //加载模块 ParticlesSizeGrid ls_particlesizegrid = new ParticlesSizeGrid(m_otsreport_export.m_ReportApp); List vs = new List() { "DMAX", "DMIN", "Area", "FERET" }; ls_particlesizegrid.condition = vs[m_otsreport_export.m_mbszclass.M_KLFXJG.index_cb_klcc_jsfs]; m_otsreport_export.panel_container.Controls.Clear(); m_otsreport_export.panel_container.Controls.Add(ls_particlesizegrid); DataGridView ls_gv = new DataGridView(); DataTable ls_dt = new DataTable(); ls_particlesizegrid.GetDataTableAndGridView(out ls_dt, out ls_gv); //------------------------------------------------ DataTable ls_partsize_dt = new DataTable(); ls_partsize_dt.TableName = "PartSize"; ls_partsize_dt.Columns.Add("c1"); ls_partsize_dt.Columns.Add("c2"); ls_partsize_dt.Columns.Add("c3"); ls_partsize_dt.Columns.Add("c4"); ls_partsize_dt.Columns.Add("c5"); ls_partsize_dt.Columns.Add("c6"); ls_partsize_dt.Columns.Add("c7"); ls_partsize_dt.Columns.Add("c8"); ls_partsize_dt.Columns.Add("c9"); DataRow dr = ls_partsize_dt.NewRow(); //从2开始,固定的 int col = 6; for (int i = 1; i < 11; i++) { if (ls_gv.Columns.Count > col) if (i<10) dr["c" + i.ToString()] = ls_gv.Columns[col++].Name; } ls_partsize_dt.Rows.Add(dr); DataTable ls_Particel_dt = new DataTable(); ls_Particel_dt.TableName = "Particel"; ls_Particel_dt.Columns.Add("c1"); ls_Particel_dt.Columns.Add("c2"); ls_Particel_dt.Columns.Add("c3"); ls_Particel_dt.Columns.Add("c4"); ls_Particel_dt.Columns.Add("c5"); ls_Particel_dt.Columns.Add("c6"); ls_Particel_dt.Columns.Add("c7"); ls_Particel_dt.Columns.Add("c8"); ls_Particel_dt.Columns.Add("c9"); ls_Particel_dt.Columns.Add("SName"); ls_Particel_dt.Columns.Add("total"); ls_Particel_dt.Columns.Add("Largest"); ls_Particel_dt.Columns.Add("Hardness"); ls_Particel_dt.Columns.Add("Density"); ls_Particel_dt.Columns.Add("Conductivity"); for (int i = 0; i < ls_gv.Rows.Count; i++) { DataRow dr2 = ls_Particel_dt.NewRow(); dr2["SName"] = ls_gv.Rows[i].Cells[1].Value.ToString(); dr2["Largest"] = ls_gv.Rows[i].Cells[4].Value.ToString(); dr2["Hardness"] = ls_gv.Rows[i].Cells[6].Value.ToString(); dr2["Density"] = ls_gv.Rows[i].Cells[7].Value.ToString(); dr2["Conductivity"] = ls_gv.Rows[i].Cells[8].Value.ToString(); int col2 = 6; for (int j = 1; j < 11; j++) { if (ls_gv.Columns.Count > col2) if(j<10) dr2["c" + j.ToString()] = ls_gv.Rows[i].Cells[col2++].Value.ToString(); } //total,不为空行,和不能是总计行 if (dr2["SName"].ToString() != "" && dr2["SName"].ToString().IndexOf("个数") < 0) { dr2["total"] = "0"; //求合 double d_total = 0; int col3 = 6; for (int j = 1; j < 11; j++) { if (ls_gv.Columns.Count > col3) d_total = d_total + Convert.ToInt64(ls_gv.Rows[i].Cells[col3++].Value.ToString()); } dr2["total"] = d_total.ToString(); } ls_Particel_dt.Rows.Add(dr2); } m_list_dt.Add(ls_partsize_dt); m_list_dt.Add(ls_Particel_dt); return true; } catch (Exception ee) { m_otsreport_export.WriteRictBox(ee.ToString()); return false; } } #endregion #region 插入平均元素含量表 /// /// 向 模板设计器 中插入 平均元素含量表 /// /// public bool InsertReportTemplateTable_ElementCompositionAvgGrid() { try { //加载模块 ElementCompositionAvgGrid ls_elementcompositionavggrid = new ElementCompositionAvgGrid(m_otsreport_export.m_ReportApp); //List vs = new List() { "DMAX", "DMIN", "Area", "FERET" }; //ls_elementcompositionavggrid.condition = vs[m_otsreport_export.m_mbszclass.M_YSFXJG.index_cb_yxfx_jsfs]; m_otsreport_export.panel_container.Controls.Clear(); m_otsreport_export.panel_container.Controls.Add(ls_elementcompositionavggrid); DataGridView ls_gv = new DataGridView(); DataTable ls_dt = new DataTable(); ls_elementcompositionavggrid.GetDataTableAndGridView(out ls_dt, out ls_gv); //------------------------------------------------ DataTable ls_elementname_dt = new DataTable(); ls_elementname_dt.TableName = "ElementName"; ls_elementname_dt.Columns.Add("e1"); ls_elementname_dt.Columns.Add("e2"); ls_elementname_dt.Columns.Add("e3"); ls_elementname_dt.Columns.Add("e4"); ls_elementname_dt.Columns.Add("e5"); ls_elementname_dt.Columns.Add("e6"); ls_elementname_dt.Columns.Add("e7"); ls_elementname_dt.Columns.Add("e8"); ls_elementname_dt.Columns.Add("e9"); DataRow dr = ls_elementname_dt.NewRow(); int col = 5; for (int i = 1; i < 10; i++) { if (ls_gv.Columns.Count > col) dr["e" + i.ToString()] = ls_gv.Columns[col++].Name; } ls_elementname_dt.Rows.Add(dr); DataTable ls_element_dt = new DataTable(); ls_element_dt.TableName = "ElementValue"; ls_element_dt.Columns.Add("e1"); ls_element_dt.Columns.Add("e2"); ls_element_dt.Columns.Add("e3"); ls_element_dt.Columns.Add("e4"); ls_element_dt.Columns.Add("e5"); ls_element_dt.Columns.Add("e6"); ls_element_dt.Columns.Add("e7"); ls_element_dt.Columns.Add("e8"); ls_element_dt.Columns.Add("e9"); ls_element_dt.Columns.Add("PName"); ls_element_dt.Columns.Add("Count"); for (int i = 0; i < ls_gv.Rows.Count; i++) { DataRow dr2 = ls_element_dt.NewRow(); dr2["PName"] = ls_gv.Rows[i].Cells[1].Value.ToString(); dr2["Count"] = ls_gv.Rows[i].Cells[2].Value.ToString(); int colq = 5; for (int j = 1; j < 10; j++) { if (ls_gv.Columns.Count > colq) dr2["e" + j.ToString()] = ls_gv.Rows[i].Cells[colq++].Tag.ToString(); } ls_element_dt.Rows.Add(dr2); } m_list_dt.Add(ls_elementname_dt); m_list_dt.Add(ls_element_dt); return true; } catch (Exception ee) { m_otsreport_export.WriteRictBox(ee.ToString()); return false; } } #endregion #region 插入颗粒图chart /// /// 用于颗粒图chart /// /// private DataTable GetPicDataTable_PicKL() { if (m_list_dt.Where(aa => aa.TableName.Contains("PicKL")).ToList().Count == 0) { //创建二进制列的数据表 DataTable ls_dt = new DataTable(); ls_dt.TableName = "PicKL"; DataColumn colpict = new DataColumn("pict"); colpict.DataType = System.Type.GetType("System.Byte[]"); ls_dt.Columns.Add(colpict); m_list_dt.Add(ls_dt); return ls_dt; } else { return m_list_dt.Where(aa => aa.TableName.Contains("PicKL")).ToList()[0]; } } #endregion #region 插入元素图chart /// /// 用于元素图chart /// /// private DataTable GetPicDataTable_PicYS() { if (m_list_dt.Where(aa => aa.TableName.Contains("PicYS")).ToList().Count == 0) { //创建二进制列的数据表 DataTable ls_dt = new DataTable(); ls_dt.TableName = "PicYS"; DataColumn colpict = new DataColumn("pict"); colpict.DataType = System.Type.GetType("System.Byte[]"); ls_dt.Columns.Add(colpict); m_list_dt.Add(ls_dt); return ls_dt; } else { return m_list_dt.Where(aa => aa.TableName.Contains("PicYS")).ToList()[0]; } } #endregion #region 插入颗粒成份图 /// /// 向 模板设计器 中插入 颗粒成份图 /// /// public bool InsertReportTemplateChart_ParticlesCompositionChart(string a_GraphicStyle) { try { //-----------------------------------颗粒成份图----------------------------------------------------------------------------------------------- //加载模块 m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition = new EChart_ParticlesComposition(m_otsreport_export.m_ReportApp, "PComponent"); m_otsreport_export.m_ReportApp.m_reportname = "InclusionClassification"; m_otsreport_export.m_ReportApp.type = a_GraphicStyle; m_otsreport_export.m_ReportApp.timerKG = true; m_otsreport_export.m_ReportApp.m_CChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition); //弹出加载图片窗体 OTSReport_GetEChartImage og = new OTSReport_GetEChartImage(); //将EChart委托事件注册给加载图片窗体的方法 m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition.butclic += og.get_ParticalesCompositionChart; og.ShowDialog(); //获取图片数据 string str = og.PicStr; //将Base64String转为图片并保存 byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1)); MemoryStream ms = new MemoryStream(arr); System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms); //再将图转成流,流再转二进制------------------------------------------- MemoryStream newms = new MemoryStream(); bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp); newms.Seek(0, SeekOrigin.Begin); byte[] newarr = new byte[newms.Length]; newms.Read(newarr, 0, newarr.Length); newms.Dispose(); //创建二进制列的数据表 DataTable ls_dt = GetPicDataTable_PicKL(); DataRow dr = ls_dt.NewRow(); dr["pict"] = newarr;//图像二进制 ls_dt.Rows.Add(dr); return true; } catch (Exception ee) { m_otsreport_export.WriteRictBox(ee.ToString()); return false; } } #endregion #region 插入元素成份图 /// /// 向 模板设计器 中插入 元素成份图 /// /// public bool InsertReportTemplateChart_ElementCompositionChart(string a_GraphicStyle) { try { //-----------------------------------元素成份图----------------------------------------------------------------------------------------------- //加载模块 m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition = new EChart_ParticlesComposition(m_otsreport_export.m_ReportApp, "EComponent"); m_otsreport_export.m_ReportApp.m_reportname = "ElementComposition"; m_otsreport_export.m_ReportApp.type = a_GraphicStyle; m_otsreport_export.m_ReportApp.timerKG = true; m_otsreport_export.m_ReportApp.m_CChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition); //弹出加载图片窗体 OTSReport_GetEChartImage og = new OTSReport_GetEChartImage(); //将EChart委托事件注册给加载图片窗体的方法 m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition.butclic += og.get_ParticalesCompositionChart; og.ShowDialog(); //获取图片数据 string str = og.PicStr; //将Base64String转为图片并保存 byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1)); MemoryStream ms = new MemoryStream(arr); System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms); //再将图转成流,流再转二进制------------------------------------------- MemoryStream newms = new MemoryStream(); bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp); newms.Seek(0, SeekOrigin.Begin); byte[] newarr = new byte[newms.Length]; newms.Read(newarr, 0, newarr.Length); newms.Dispose(); //创建二进制列的数据表 DataTable ls_dt = GetPicDataTable_PicYS(); DataRow dr = ls_dt.NewRow(); dr["pict"] = newarr;//图像二进制 ls_dt.Rows.Add(dr); return true; } catch (Exception ee) { m_otsreport_export.WriteRictBox(ee.ToString()); return false; } } #endregion #region 插入三元相图 /// /// 获取或创建pic表格,用于三元相图 /// /// private DataTable GetPicDataTable_PicSYXT2T() { if (m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT2T")).ToList().Count == 0) { //创建二进制列的数据表 DataTable ls_dt = new DataTable(); ls_dt.TableName = "PicSYXT2T"; DataColumn colpict = new DataColumn("pict"); colpict.DataType = System.Type.GetType("System.Byte[]"); ls_dt.Columns.Add(colpict); DataColumn colpict2 = new DataColumn("pict2"); colpict2.DataType = System.Type.GetType("System.Byte[]"); ls_dt.Columns.Add(colpict2); m_list_dt.Add(ls_dt); return ls_dt; } else { return m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT2T")).ToList()[0]; } } /// /// 获取或创建pic表格,用于三元相图,3个列的 /// /// private DataTable GetPicDataTable_PicSYXT3T() { if (m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT3T")).ToList().Count == 0) { //创建二进制列的数据表 DataTable ls_dt = new DataTable(); ls_dt.TableName = "PicSYXT3T"; DataColumn colpict = new DataColumn("pict"); colpict.DataType = System.Type.GetType("System.Byte[]"); ls_dt.Columns.Add(colpict); DataColumn colpict2 = new DataColumn("pict2"); colpict2.DataType = System.Type.GetType("System.Byte[]"); ls_dt.Columns.Add(colpict2); DataColumn colpict3 = new DataColumn("pict3"); colpict3.DataType = System.Type.GetType("System.Byte[]"); ls_dt.Columns.Add(colpict3); m_list_dt.Add(ls_dt); return ls_dt; } else { return m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT")).ToList()[0]; } } /// /// 获取三元相图二进制数据 /// /// /// private byte[] GetByte_InsertReportTemplateChart_Trianglediagram(int selectindex) { byte[] newarr = new byte[0]; //加载模块 m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram = new EChart_Trianglediagram(m_otsreport_export.m_ReportApp, TemplateList[selectindex]); m_otsreport_export.m_ReportApp.timerKG = true; m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram.condition = m_otsreport_export.m_mbszclass.M_SYXT.index_cb_syxt_jsfs; m_otsreport_export.m_ReportApp.m_CChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram); //ls_echart_trianglediagram. //弹出加载图片窗体 OTSReport_GetEChartImage og = new OTSReport_GetEChartImage(); //将EChart委托事件注册给加载图片窗体的方法 m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram.butclic += og.get_ParticalesCompositionChart; og.ShowDialog(); //获取图片数据 string str = og.PicStr; //将Base64String转为图片并保存 byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1)); MemoryStream ms = new MemoryStream(arr); System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms); //再将图转成流,流再转二进制------------------------------------------- MemoryStream newms = new MemoryStream(); bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp); newms.Seek(0, SeekOrigin.Begin); newarr = new byte[newms.Length]; newms.Read(newarr, 0, newarr.Length); newms.Dispose(); return newarr; } /// /// 向 模板设计器 中插入 三元相图 /// /// public bool InsertReportTemplateChart_Trianglediagram() { try { //创建二进制列的数据表,循环插入三元选择的模板 DataTable ls_dt = GetPicDataTable_PicSYXT2T(); DataTable ls_dt3t = GetPicDataTable_PicSYXT3T(); //这里要校验一下,总数必须要是2的整倍数,不可有余数 if (m_otsreport_export.m_mbszclass.M_SYXT.str_cb_syxt_mhxssl == "2" && m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index.Count % 2 == 0) { for (int i = 0; i < m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index.Count; i = i + 2) { byte[] newarr, newarr2; newarr = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i]); newarr2 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 1]); DataRow dr = ls_dt.NewRow(); dr["pict"] = newarr;//图像二进制 dr["pict2"] = newarr2;//图像二进制 ls_dt.Rows.Add(dr); } } else { DataRow dr = ls_dt.NewRow(); dr["pict"] = null;//图像二进制 dr["pict2"] = null;//图像二进制 ls_dt.Rows.Add(dr); } if (m_otsreport_export.m_mbszclass.M_SYXT.str_cb_syxt_mhxssl == "3" && m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index.Count % 3 == 0) { for (int i = 0; i < m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index.Count; i = i + 3) { byte[] newarr, newarr2, newarr3; newarr = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i]); newarr2 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 1]); newarr3 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 2]); DataRow dr = ls_dt3t.NewRow(); dr["pict"] = newarr;//图像二进制 dr["pict2"] = newarr2;//图像二进制 dr["pict3"] = newarr3;//图像二进制 ls_dt3t.Rows.Add(dr); } } else { DataRow dr = ls_dt3t.NewRow(); dr["pict"] = null;//图像二进制 dr["pict2"] = null;//图像二进制 dr["pict3"] = null;//图像二进制 ls_dt3t.Rows.Add(dr); } return true; } catch (Exception ee) { m_otsreport_export.WriteRictBox(ee.ToString()); return false; } } #endregion #region 其它部份 ///// ///// 获取夹杂物总数量,报告中暂时固定导出100数量,如果需要导出全部颗粒,到颗粒列表中导出Excel使用 ///// ///// //public int GetReportTemplateTable_ParticlesNumber() //{ // return 100; //} /// /// 输入颗粒的所在帧图id,颗粒id,颗粒类型id,获取对应的XRay能谱数据图 /// /// public Bitmap ExportXRayBitmap(string in_fieldid, string in_particleid, int in_stdtypeid, string TypeName, ParticleData particleData) { Bitmap ret_bp; //显示xray相关信息 uint[] Search_xray = new uint[2000]; uint[] Analysis_xray = new uint[2000]; // int i_xray_id = 0; List list_celementchemistryclr = new List(); //获取Xray数据 list_celementchemistryclr = new List(); Particle list = particleData.GetParticleByFidAndPid(in_fieldid, in_particleid); if (list == null) { return null; } Particle particle = list; if (particle.XrayId > -1) { for (int i = 0; i < 2000; i++) { Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4); } Search_xray = Analysis_xray; i_xray_id = particle.XrayId; list_celementchemistryclr = particle.ElementList; } //get CElementChemistryClr list List list_showelementinfo = new List(); for (int i = 0; i < list_celementchemistryclr.Count; i++) { ShowElementInfo ls_sei = new ShowElementInfo(); ls_sei.ElementName = list_celementchemistryclr[i].Name; ls_sei.Percentage = list_celementchemistryclr[i].Percentage; ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX1); list_showelementinfo.Add(ls_sei); } //获取使用标准库的名称 string str_stdname = ""; string str_IncALibName = ""; if (in_stdtypeid < 1000) { //小于1000,使用系统默认分类 str_IncALibName = TypeName; str_stdname = "Default standard library"; } else if (in_stdtypeid >= 1000 && in_stdtypeid < 10000) { //大于等于1000,并且小于10000时,使用系统数据库中夹杂物来分析 str_IncALibName = TypeName; str_stdname = "User defined standard library"; } else if (in_stdtypeid > 10000) { //大于10000时,使用用户标准库来分析夹杂物名称 str_IncALibName = TypeName; str_stdname = "System standard library"; } //获取数据后,需要对xraytable设置 OTSIncAReportGraph.Controls.Control_XRayTable control_XRayTable1 = new Control_XRayTable(); control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray, list_showelementinfo); //颗粒国标信息 //control_XRayTable1.GBInfoStr = in_dparticle.GBContent; control_XRayTable1.GoodName = str_IncALibName;//杂夹物 control_XRayTable1.STDName = str_stdname;//标准库 control_XRayTable1.List_ShowElementInfo = list_showelementinfo; control_XRayTable1.Visible = true; control_XRayTable1.Invalidate(); control_XRayTable1.Refresh(); ret_bp = control_XRayTable1.ExportXRayImage(); return ret_bp; } /// /// 导出二次放大图像 /// /// /// public void ParticleReZoom(string str_srcPathName, string str_outPathName) { //m_COTSReportProjFileMgrClr.ReZoom(str_srcPathName, str_outPathName); } /// /// 传入DataTable,和行号,返回该Row行中,返回6个靠前的元素,不足6个返回空 /// /// /// /// private void GetMaxElementFromDataTable(DataTable in_dt, int row_index, out List out_list_elementname, out List out_list_elementvalue) { out_list_elementname = new List(); out_list_elementvalue = new List(); //分别排出元素名,元素值列表 List list_elementname = new List(); List list_elementvalue = new List(); string str_element = in_dt.Rows[row_index]["Element"].ToString(); //防止取出的元素信息为空 if (str_element != "") { string[] strcbo = str_element.Split(';'); for (int i = 0; i < strcbo.Length; i++) { string[] str = strcbo[i].Split('-'); list_elementname.Add(str[0]); list_elementvalue.Add(Math.Round(Convert.ToDouble(str[1]), 2)); } } //循环6次,得到最大的6个元素信息 for (int geti = 0; geti < 6; geti++) { double max_elementvalue = -1; string max_elementname = ""; int max_index = -1; if (list_elementvalue.Count > 1) { for (int i = 0; i < list_elementvalue.Count; i++) { if (list_elementvalue[i] > max_elementvalue) { max_elementvalue = list_elementvalue[i]; max_elementname = list_elementname[i]; max_index = i; } } //移除掉最大的元素 list_elementname.RemoveAt(max_index); list_elementvalue.RemoveAt(max_index); //将最大的元素添加到list中 if (max_elementvalue > 0) { out_list_elementname.Add(max_elementname); out_list_elementvalue.Add(max_elementvalue); } else { out_list_elementname.Add(" "); out_list_elementvalue.Add(0); } } else { //如果元素数量已经不够,则添加空 out_list_elementname.Add(" "); out_list_elementvalue.Add(0); } } } /// /// 传入DataTable和想要找到的列名,返回对应列的索引 /// /// /// /// private int GetDataTableColumnsIndexByName(DataTable in_dt, string in_str) { int i_ret = -1; for (int i = 0; i < in_dt.Columns.Count; i++) { if (in_dt.Columns[i].ColumnName.IndexOf(in_str) > -1) { //找到 i_ret = i; break; } } return i_ret; } /// /// 传入DataTable和想要的元素第几个排列,返回对应的列的索引 /// /// /// /// private int GetDataTableColumnsIndexByElementNumber(DataTable in_dt, int in_elementorder) { int i_ret = -1; int i_findcount = 0;//第几次找到的记数 //首先遍历所有的datatable中的元素 for (int i = 0; i < in_dt.Columns.Count; i++) { //然后遍历该列是否是元素名,要显示的元素名 for (int k = 0; k < m_otsreport_export.m_mbszclass.M_KLLBXX.list_str_tb_lllb_sxys.Count; k++) { if (in_dt.Columns[i].ColumnName.ToString().ToUpper() == m_otsreport_export.m_mbszclass.M_KLLBXX.list_str_tb_lllb_sxys[k].ToUpper()) { //找到了 if (i_findcount == in_elementorder) { //并且达到了想找的第几个序列,返回对应的列的索引 i_ret = i; return i_ret; } else { //否则,找到的索引号增长 i_findcount++; } } } } return i_ret; } #endregion } }