123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368 |
- 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<DataTable> m_list_dt; //导出的各模块数据,合集
- public OTSReport_Export m_otsreport_export;
- List<string> TemplateList;
- #endregion
- #region 构造函数
- public Export_ReportTemplate(OTSReport_Export in_export)
- {
- m_otsreport_export = in_export;
- TemplateList = new List<string>();
- //加载三元相图各项
- string pathtpf = in_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.FileFolderTrigTemp + "\\" + in_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.TriTempFile;// Application.StartupPath + "\\Config\\ProData\\DefaultTriTemplateFile.tpf";
- TemplateList = new List<string>();
- 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<DataTable>();
- }
- #endregion
- #region 插入测量结果Grid表格
- /// <summary>
- /// 向 模板设计器 中插入测量结果Grid表格
- /// </summary>
- /// <returns></returns>
- public DataTable InsertReportTemplateTable_ResultGrid()
- {
-
- //------------------加载模块,获取数据-------------------------------------------------
- ResultGrid ls_resultgrid = new ResultGrid(m_otsreport_export.m_ReportApp);
- Dictionary<string, string> keyValues_ResultGrid = ls_resultgrid.GetData_ResultGrid();
- //------------------加载模块,获取数据结束----------------------------------------------
- Dictionary<string, string>.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/T30834-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 ls_new_dt;
-
- }
- #endregion
-
- #region 插入颗粒列表并带有帧图
- /// <summary>
- /// 颗粒列表中插入帧图,并带上颗粒分组信息
- /// </summary>
- /// <returns></returns>
- public bool InsertReportTemplateTable_ParticlesGridDevidePage()
- {
- int serialNumber = 1;
- //------------------加载模块,获取数据-------------------------------------------------
- m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage = new ParticlesGridDevidePage(m_otsreport_export.m_ReportApp);
- //根据sql条件,查询获取颗粒信息数据
- ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResult()].FilePath);
- DataTable dt = fielddata.GetIncaSurfaceData();
- //将颗粒大小排序(从大到小)
- DataView dv = dt.DefaultView;
- dv.Sort = "Area DESC";
- DataTable dt_ParticlesGridDevidePage = dv.ToTable();
- string str_resultPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResult()].FilePath;
- //------------------加载模块,获取数据结束----------------------------------------------
- #region 创建要插入数据库表结构
- //插入模板需父子表,结构
- //表名field_dt表:(父表) 帧图表
- 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 < dt_ParticlesGridDevidePage.Rows.Count; i_row++)
- {
- if (dt_ParticlesGridDevidePage.Rows[i_row].ItemArray[24].ToString()!= "Not Identified")
- {
- //获取颗粒的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 (serialNumber > 20)
- 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<string>() { 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.DrawFunction.KiResizeImage(bp_xraybp, 700, 115);//能谱图处理
- //获取该颗粒的二次放大处理图像
- Bitmap ls_processbitmap = new Bitmap(1, 1);
- ls_processbitmap = OTSIncAReportGraph.Class.DrawFunction.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"] = serialNumber++.ToString();
- //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<string> list_max_elementname = new List<string>();
- List<double> list_max_elementvale = new List<double>();
- 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(dt_ParticlesGridDevidePage);
- string str_path_FIELD_FILES_MARK = str_resultPath + "\\FIELD_FILES_MARK\\";
- DirectoryInfo theFolder = new DirectoryInfo(str_path_FIELD_FILES_MARK);
- if (theFolder.Exists)
- {
- for (int i = 0; i <= theFolder.GetFiles().Count(); i++)
- {
- //判断i.bmp图片是否存在,如果不存在跳出当前循环
- if (!DetermineWhetherTheFileExists(theFolder, i))
- continue;
- //在数据表中有颗粒在该帧图中的话,则对该帧图标记图像进行读取存入数据库
- DataRow[] datarowlist = dt_ParticlesGridDevidePage.Select(" fieldid = " + i);
- if (datarowlist.Count() > 0)
- {
- Bitmap ls_bp_fieldmark = new Bitmap(theFolder.GetFiles()[i].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"] = i;
- ls_bp_fieldmark.Dispose();
- DT_field_dt.Rows.Add(dr);
- }
- }
-
- }
- #endregion
- #region 插入-前20颗粒外的颗粒
- for (int i_row = 0; i_row < dt_ParticlesGridDevidePage.Rows.Count; i_row++)
- {
- if (dt_ParticlesGridDevidePage.Rows[i_row]["element"].ToString() == "")
- continue;
- //获取颗粒的fieldid,和particleid
- string str_fieldid = dt_ParticlesGridDevidePage.Rows[i_row]["fieldid"].ToString();
- if (Convert.ToInt32(str_fieldid) < 20)
- {
-
- 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);
- continue;
- }
- 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<string>() { 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<string> list_max_elementname = new List<string>();
- List<double> list_max_elementvale = new List<double>();
- 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;
- }
- private bool DetermineWhetherTheFileExists(DirectoryInfo theFolder ,int id)
- {
- foreach (FileInfo nextifile in theFolder.GetFiles())
- {
- if (nextifile.Name.Contains(id.ToString()+".bmp") == true || nextifile.Name.Contains(id.ToString()+".BMP") == true)
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region 插入颗粒尺寸表
- /// <summary>
- /// 向 模板设计器 中插入 颗粒尺寸表
- /// </summary>
- /// <returns></returns>
- public bool InsertReportTemplateTable_ParticleSizeGrid()
- {
- try
- {
- //加载模块
- ParticlesSizeGrid ls_particlesizegrid = new ParticlesSizeGrid(m_otsreport_export.m_ReportApp);
- List<string> vs = new List<string>() { "DMAX", "DMIN", "CIRCLE", "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("number") < 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 插入平均元素含量表
- /// <summary>
- /// 向 模板设计器 中插入 平均元素含量表
- /// </summary>
- /// <returns></returns>
- public bool InsertReportTemplateTable_ElementCompositionAvgGrid()
- {
- try
- {
- //加载模块
- ElementCompositionAvgGrid ls_elementcompositionavggrid = new ElementCompositionAvgGrid(m_otsreport_export.m_ReportApp);
- 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");
- ls_elementname_dt.Columns.Add("e10");
- ls_elementname_dt.Columns.Add("e11");
- ls_elementname_dt.Columns.Add("e12");
- ls_elementname_dt.Columns.Add("e13");
- ls_elementname_dt.Columns.Add("e14");
- DataRow dr = ls_elementname_dt.NewRow();
- int col = 4;
- for (int i = 1; i < 15; 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("e10");
- ls_element_dt.Columns.Add("e11");
- ls_element_dt.Columns.Add("e12");
- ls_element_dt.Columns.Add("e13");
- ls_element_dt.Columns.Add("e14");
- ls_element_dt.Columns.Add("PName");
- ls_element_dt.Columns.Add("Count");
- ls_element_dt.Columns.Add("AllElements");
- 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 = 4;
- for (int j = 1; j < 15; j++)
- {
- if (ls_gv.Columns.Count > colq)
- dr2["e" + j.ToString()] = ls_gv.Rows[i].Cells[colq++].Tag.ToString();
- }
- colq = 4;
- string AllElements=null;
- for (int j = 0; j < ls_gv.Rows[i].Cells.Count; j++)
- {
- if (ls_gv.Columns.Count > colq)
- {
- AllElements = AllElements+ ls_gv.Columns[colq].Name + "%="+ ls_gv.Rows[i].Cells[colq++].Tag.ToString()+"; ";
- }
- }
- dr2["AllElements"] = AllElements;
- ls_element_dt.Rows.Add(dr2);
- }
- InclusionAreaRatio(ls_gv);
- 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
- private void InclusionAreaRatio(DataGridView ls_gv)
- {
- DataTable AreaRatio = new DataTable();
- AreaRatio.TableName = "InclusionAreaRatio";
- AreaRatio.Columns.Add("e1");
- AreaRatio.Columns.Add("e2");
- AreaRatio.Columns.Add("e3");
- AreaRatio.Columns.Add("e4");
- AreaRatio.Columns.Add("e5");
- //获取夹杂物的总面积用于计算夹杂物类别的占比(gridview最后一个固定是未识别颗粒,要排除未识别颗粒所以for循环至grid view长度减一)
- double totalInclusionArea = 0;
- for (int i = 0; i < ls_gv.Rows.Count - 1; i++)
- {
- totalInclusionArea = totalInclusionArea + Convert.ToDouble(ls_gv.Rows[i].Cells[2].Value.ToString());
- }
- for (int i = 0; i < ls_gv.Rows.Count - 1; i++)
- {
- DataRow dr = AreaRatio.NewRow();
- dr["e1"] = (i + 1).ToString();
- dr["e2"] = ls_gv.Rows[i].Cells[1].Value.ToString();
- dr["e3"] = ls_gv.Rows[i].Cells[2].Value.ToString();
- dr["e4"] = Math.Round((Convert.ToDouble(ls_gv.Rows[i].Cells[2].Value)/ totalInclusionArea)*100,2);
- dr["e5"] = Math.Round((Convert.ToDouble(ls_gv.Rows[i].Cells[2].Value) / Convert.ToDouble( m_list_dt.Where(aa => aa.TableName.Contains("ResultGrid")).ToList()[0].Rows[0][5])) * 100, 4);
- AreaRatio.Rows.Add(dr);
- }
- m_list_dt.Add(AreaRatio);
- }
- #region 插入颗粒图chart
- /// <summary>
- /// 用于颗粒图chart
- /// </summary>
- /// <returns></returns>
- 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
- private DataTable GetPicDataTable_InclusionAreaRatio()
- {
- if (m_list_dt.Where(aa => aa.TableName.Contains("Pic_InclusionAreaRatio")).ToList().Count == 0)
- {
- //创建二进制列的数据表
- DataTable ls_dt = new DataTable();
- ls_dt.TableName = "Pic_InclusionAreaRatio";
- 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("Pic_InclusionAreaRatio")).ToList()[0];
- }
- }
- #region 插入元素图chart
- /// <summary>
- /// 用于元素图chart
- /// </summary>
- /// <returns></returns>
- 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_InclusionAreaRatio(string a_GraphicStyle)
- {
- //加载模块
- m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition = new EChart_ParticlesComposition(m_otsreport_export.m_ReportApp, "InclusionareaRatio");
- m_otsreport_export.m_ReportApp.m_reportname = "夹杂物面积比";
- m_otsreport_export.m_ReportApp.type = a_GraphicStyle;
- m_otsreport_export.m_ReportApp.timerKG = true;
- m_otsreport_export.m_ReportApp.m_ChartsWindow.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_InclusionAreaRatio();
- DataRow dr = ls_dt.NewRow();
- dr["pict"] = newarr;//图像二进制
- ls_dt.Rows.Add(dr);
- return true;
- }
- #endregion
- #region 插入颗粒成份图
- /// <summary>
- /// 向 模板设计器 中插入 颗粒成份图
- /// </summary>
- /// <returns></returns>
- 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_ChartsWindow.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 插入元素成份图
- /// <summary>
- /// 向 模板设计器 中插入 元素成份图
- /// </summary>
- /// <returns></returns>
- 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_ChartsWindow.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 插入三元相图
- /// <summary>
- /// 获取或创建pic表格,用于三元相图
- /// </summary>
- /// <returns></returns>
- 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];
- }
- }
- /// <summary>
- /// 获取或创建pic表格,用于三元相图,3个列的
- /// </summary>
- /// <returns></returns>
- 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];
- }
- }
- /// <summary>
- /// 获取三元相图二进制数据
- /// </summary>
- /// <param name="selectindex"></param>
- /// <returns></returns>
- 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_ChartsWindow.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;
- }
- /// <summary>
- /// 向 模板设计器 中插入 三元相图
- /// </summary>
- /// <returns></returns>
- 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 其它部份
-
- /// <summary>
- /// 输入颗粒的所在帧图id,颗粒id,颗粒类型id,获取对应的XRay能谱数据图
- /// </summary>
- /// <returns></returns>
- 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<Element> list_celementchemistryclr = new List<Element>();
- //获取Xray数据
- list_celementchemistryclr = new List<Element>();
- 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++)
- {
- if (particle.XRayData!=null)
- {
- 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<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
- 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.MaterialName = 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;
- }
- /// <summary>
- /// 导出二次放大图像
- /// </summary>
- /// <param name="str_srcPathName"></param>
- /// <param name="str_outPathName"></param>
- public void ParticleReZoom(string str_srcPathName, string str_outPathName)
- {
- //m_COTSReportProjFileMgrClr.ReZoom(str_srcPathName, str_outPathName);
- }
- /// <summary>
- /// 传入DataTable,和行号,返回该Row行中,返回6个靠前的元素,不足6个返回空
- /// </summary>
- /// <param name="in_dt"></param>
- /// <param name="row_index"></param>
- /// <returns></returns>
- private void GetMaxElementFromDataTable(DataTable in_dt, int row_index, out List<string> out_list_elementname, out List<double> out_list_elementvalue)
- {
- out_list_elementname = new List<string>();
- out_list_elementvalue = new List<double>();
- //分别排出元素名,元素值列表
- List<string> list_elementname = new List<string>();
- List<double> list_elementvalue = new List<double>();
- 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-1; 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 > 0)
- {
- 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);
- }
- }
- }
- #endregion
- /// <summary>
- /// 国标一
- /// </summary>
- /// <returns></returns>
- public List<DataTable> InsertReportTemplateTable_ChineseStandardABCDDS(OTSCLRINTERFACE.CPropParamClr cPropParamClr)
- {
- //得到国标一的DataTable表格
-
- cPropParamClr.SetDataSourceId(0);//
- cPropParamClr.SetType(1);//table
- cPropParamClr.SetCalTableType(6);//国标1
- List<OTSCLRINTERFACE.CGridDataClr> listGriddataclr = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr.GridDataTransfer(cPropParamClr);
- m_otsreport_export.m_ReportApp.im_ChineseStandardABCDDS = new OTSIncAReportGB.ChineseStandardABCDDS(m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr, listGriddataclr);
- m_otsreport_export.m_ReportApp.m_TablesWindow.Controls.Clear();
- //List<DataTable> GB_1 = m_otsreport_export.m_ReportApp.im_ChineseStandardABCDDS.ChineseStandardABCD_GetDataTable();
- //string s = GB_1[0].Rows[0][0].ToString();
- return m_otsreport_export.m_ReportApp.im_ChineseStandardABCDDS.ChineseStandardABCD_GetDataTable(); ;
- }
- /// <summary>
- /// 国标二
- /// </summary>
- /// <returns></returns>
- public List<DataTable> InsertReportTemplateTable_NationalStandardMethodTwo(OTSCLRINTERFACE.CPropParamClr cPropParamClr)
- {
- //得到国标二的DataTable表格
-
- cPropParamClr.SetDataSourceId(0);//
- cPropParamClr.SetType(1);//table
- cPropParamClr.SetCalTableType(7);//国标2
- List<OTSCLRINTERFACE.CGridDataClr> listGriddataclr2 = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr.GridDataTransfer(cPropParamClr);//
- m_otsreport_export.m_ReportApp.m_TablesWindow.Controls.Clear();
- m_otsreport_export.m_ReportApp.im_NationalStandardMethodTwo = new OTSIncAReportGB.NationalStandardMethodTwo(m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr, listGriddataclr2);
- return m_otsreport_export.m_ReportApp.im_NationalStandardMethodTwo.ChineseStandardABCD_GetDataTable();
- }
- }
- }
|