using CefSharp; using CefSharp.WinForms; using Newtonsoft.Json; using OTSIncAReportApp.DataOperation.DataAccess; using OTSCommon.Model; using OTSIncAReportApp.OTSDataMgrFunction; using OTSIncAReportApp.OTSSampleReportInfo; using OTSIncAReportApp.OTSTemplateDesigner; using OTSIncAReportApp.SysMgrTools; using OTSIncAReportGrids; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Windows.Forms; namespace OTSIncAReportApp.Control_ECharts { /// /// 各图char相关模块 /// public partial class EChart_ParticlesComposition : UserControl { Hashtable table; #region 图表相关变量 //y轴名称 public string m_str_AxisY { get; set; } //定义图片 //JsEvent js; //定义图片base64 public string pic { get; set; } //定义图形类型 public string type { get; set; } //图形数据 public string data { get; set; } string url = "Resources/HTML/charts.html"; //数据图类型:常用夹杂物分类CommonlyUsedClassify ,颗粒成分PComponent,元素成分EComponent,颗粒尺寸分布PSize string ComSel { get; set; } public bool Report { get; set; } /// /// 选择颗粒范围(true为全部颗粒false为选择颗粒) /// public bool ParticleRange { set; get; } frmReportApp m_ReportApp; List FLID = new List() { 0, 1, 2, 4, 6, 7, 8, 9 }; List NameList = new List() { "过小颗粒", "过大颗粒", "亮度不在分析范围内的颗粒", "低计数率颗粒", "不含分析元素的颗粒", "非夹杂物颗粒SiC", "非夹杂物颗粒FeO", "未识别颗粒" }; private frmReportConditionChoose m_conditionChoose; private ResultDataMgr m_DataMgr; Export_ReportTemplate m_export_reporttemplate; #endregion #region 窗体加载及构造函数 public EChart_ParticlesComposition(frmReportApp ReportApp, string comsel) { ComSel = comsel; m_ReportApp = ReportApp; m_conditionChoose = ReportApp.m_conditionChoose; m_DataMgr = ReportApp.m_rstDataMgr; InitializeComponent(); //国际化 Language lan = new Language(); table = lan.GetNameTable("CompositionDistributionGrid"); m_export_reporttemplate = new Export_ReportTemplate(); } private void EChart_ParticlesComposition_Load(object sender, EventArgs e) { string sou = ""; int sel = 0;//选择颗粒范围(0为全部颗粒1为选择颗粒) NameList = new List() { table["partcletype0"].ToString(), table["partcletype1"].ToString(), table["partcletype2"].ToString(), table["partcletype4"].ToString(), table["partcletype6"].ToString(), table["partcletype7"].ToString(), table["partcletype8"].ToString(), table["partcletype9"].ToString() }; //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE); //string sou = m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString(); if (Report) { sou = m_DataMgr.ResultFilesList[m_DataMgr.getSelectedIndex()].anotherFileName.ToString(); if(ParticleRange) { sel = 0; }else { sel = 1; } } else { sou = m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString(); sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); } Report = false; if (sou.Contains("+")) { if (m_ReportApp.more) { m_ReportApp.trans = false; } else { m_ReportApp.trans = true; } m_ReportApp.more = true; //获取到List,json的字符串 ChartdateMore list_json_str = GetListJsonStr(); url = "Resources/HTML/chartsMore.html"; m_ReportApp.data = JsonConvert.SerializeObject(list_json_str); } else { if (!m_ReportApp.more) { m_ReportApp.trans = false; } else { m_ReportApp.trans = true; } m_ReportApp.more = false; //获取到List,json的字符串 for (int i=0;i< m_conditionChoose.m_conditionData.ConditionItemList.Count;i++) { if (m_conditionChoose.m_conditionData.ConditionItemList[i].itemDisplayVal.ToString()== sou) { m_DataMgr.SetWorkingResult((int)m_conditionChoose.m_conditionData.ConditionItemList[i].itemVal); } } List list_json_str = GetListJsonStrByChartStruct(sel); url = "Resources/HTML/charts.html"; m_ReportApp.data = JsonConvert.SerializeObject(list_json_str[0]); if (ComSel == "PSize") { ComSel = "PSizeCombin"; m_ReportApp.dataCombin = JsonConvert.SerializeObject(GetListJsonStrByChartStruct(sel)[0]); } else { m_ReportApp.dataCombin = ""; } } InitBrowser(); } #endregion #region 获取单数据源 private Chartdate GetCommonlyUsedClassifyData(string path) { string spinel = table["str20"].ToString(); string oxide = table["str21"].ToString(); string SulfurOxide = table["str22"].ToString(); string nitrides = table["str23"].ToString(); string sulfide = table["str24"].ToString(); DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path); //创建新的图形数据源 Chartdate chart = new Chartdate(); chart.Title = m_ReportApp.m_reportname; chart.YName = m_str_AxisY; //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); //int sel = m_ReportApp.SourceGridData.ConditionItemList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString()); //int sel = m_conditionChoose.m_SourceGridData.GetPropIndexByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); DataTable dt = new DataTable(); if (sel == 1) { List particles = m_ReportApp.GetSelectedParticles(); int SPINEL = 0; int OXIDE = 0; int SULFIDE_OXIDE = 0; int NITRIDE = 0; int SULFIDE = 0; for (int i = 0; i < m_ReportApp.GetSelectedParticles().Count; i++) { //SPINEL if ((particles[i].TypeId >= 10100 || particles[i].TypeId <= 10199) || (particles[i].TypeId >= 12200 || particles[i].TypeId <= 12299) || (particles[i].TypeId >= 11300 || particles[i].TypeId <= 11299)) { SPINEL = SPINEL + 1; } //OXIDE if (particles[i].TypeId >= 10000 || particles[i].TypeId <= 10999) { OXIDE = OXIDE + 1; } //SULFIDE_OXIDE if ((particles[i].TypeId >= 11200 || particles[i].TypeId <= 11299) || (particles[i].TypeId >= 11400 || particles[i].TypeId <= 11499) || (particles[i].TypeId >= 11200 || particles[i].TypeId <= 11599)) { SULFIDE_OXIDE = SULFIDE_OXIDE + 1; } //NITRIDE if (particles[i].TypeId >= 12000 || particles[i].TypeId <= 12999) { NITRIDE = NITRIDE + 1; } //SULFIDE if (particles[i].TypeId >= 11000 || particles[i].TypeId <= 11999) { SULFIDE = SULFIDE + 1; } } DataTable dataTable = new DataTable(); dataTable.Columns.Add("SPINEL", typeof(String)); dataTable.Columns.Add("OXIDE", typeof(String)); dataTable.Columns.Add("SULFIDE_OXIDE", typeof(String)); dataTable.Columns.Add("NITRIDE", typeof(String)); dataTable.Columns.Add("SULFIDE", typeof(String)); dataTable.Rows.Add(); dataTable.Rows[0]["SPINEL"] = SPINEL.ToString(); dataTable.Rows[0]["OXIDE"] = OXIDE.ToString(); dataTable.Rows[0]["SULFIDE_OXIDE"] = SULFIDE_OXIDE.ToString(); dataTable.Rows[0]["NITRIDE"] = NITRIDE.ToString(); dataTable.Rows[0]["SULFIDE"] = SULFIDE.ToString(); dt = dataTable; } else { dt = particledata.GetCommonlyUsedClassifyData(); } //DataTable dt = dataTable; //设置标签名称 List listName = new List(); listName.Add(spinel); listName.Add(oxide); listName.Add(SulfurOxide); listName.Add(nitrides); listName.Add(sulfide); chart.ListName = listName; //设置数据 List listData = new List(); //ListData for (int k = 0; k < dt.Rows.Count; k++) { try { Item item_SPINEL = new Item() { value = decimal.Round(decimal.Parse(dt.Rows[k]["SPINEL"].ToString()), 2).ToString(), name = spinel }; listData.Add(item_SPINEL); Item item_OXIDE = new Item() { value = decimal.Round(decimal.Parse(dt.Rows[k]["OXIDE"].ToString()), 2).ToString(), name = oxide }; listData.Add(item_OXIDE); Item item_SULFIDE_OXIDE = new Item() { value = decimal.Round(decimal.Parse(dt.Rows[k]["SULFIDE_OXIDE"].ToString()), 2).ToString(), name = SulfurOxide }; listData.Add(item_SULFIDE_OXIDE); Item item_NITRIDE = new Item() { value = decimal.Round(decimal.Parse(dt.Rows[k]["NITRIDE"].ToString()), 2).ToString(), name = nitrides }; listData.Add(item_NITRIDE); Item item_SULFIDE = new Item() { value = decimal.Round(decimal.Parse(dt.Rows[k]["SULFIDE"].ToString()), 2).ToString(), name = sulfide }; listData.Add(item_SULFIDE); } catch { Item item = new Item() { value = "", name = "" }; listData.Add(item); } } chart.ListData = listData; return chart; } private Chartdate GetInclusionAreaRatioData(string path,int sel) { DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path); //创建新的图形数据源 Chartdate chart = new Chartdate(); chart.Title = m_ReportApp.m_reportname; chart.YName = m_str_AxisY; //int sel = m_ReportApp.m_conditionChoose.m_SourceGridData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); DataTable data = new DataTable(); if (sel == 0) { data = particledata.GetAreaByAllIncA("");//获取所有分类面积和数量信息 } else { DataTable AllInca = particledata.GetAreaByAllIncA(""); DataTable SelectParticl = SelectParticleData(); data = GetParticleListForParticlSize(SelectParticl, AllInca); } //DataTable data = particledata.GetAreaByAllIncA(""); DataTable dt = ConSolidateInvalid(data); //设置标签名称 List listName = new List(); //ListName for (int i = 0; i < dt.Rows.Count; i++) { if (Convert.ToInt32(dt.Rows[i]["TypeId"]) < 100) { continue; } listName.Add(dt.Rows[i]["TypeName"].ToString()); } chart.ListName = listName; //设置数据 List listData = new List(); //ListData for (int k = 0; k < dt.Rows.Count; k++) { string str = dt.Rows[k]["ar"].ToString(); string name = dt.Rows[k]["TypeName"].ToString(); if (Convert.ToInt32(dt.Rows[k]["TypeId"]) < 100) { continue; } Item item = new Item() { value =Convert.ToInt32(dt.Rows[k]["ar"]).ToString(), name = name }; listData.Add(item); } chart.ListData = listData; return chart; } private Chartdate GetInclusionAreaRatioClassData(string path,int sel) { //创建新的图形数据源 Chartdate chart = new Chartdate(); chart.Title = m_ReportApp.m_reportname; chart.YName = m_str_AxisY; //计算分类整个表的数据 DataTable dt= ClassificationIntegration(path,sel); List listName = new List(); //ListName for (int i = 0; i < dt.Rows.Count; i++) { listName.Add(dt.Rows[i]["e1"].ToString()); } chart.ListName = listName; //DataTable dt //设置数据 List listData = new List(); //ListData for (int k = 0; k < dt.Rows.Count; k++) { string str = dt.Rows[k]["Cunt"].ToString(); string name = dt.Rows[k]["e1"].ToString(); Item item = new Item() { value = decimal.Round(decimal.Parse(dt.Rows[k]["Cunt"].ToString()), 2).ToString(), name = name }; listData.Add(item); } chart.ListData = listData; return chart; } private DataTable ClassificationIntegration(string path ,int sel) { //------------------加载模块,获取数据------------------------------------------------- ResultGrid ls_resultgrid = new ResultGrid(m_ReportApp); Dictionary keyValues_ResultGrid = ls_resultgrid.GetData_ResultGrid_Report(); //------------------加载模块,获取数据结束---------------------------------------------- Dictionary.Enumerator en = keyValues_ResultGrid.GetEnumerator(); string str_SCZS = ""; keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col5"].ToString(), out str_SCZS);//视场总数 DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path); DataTable data = new DataTable(); if (sel==0) { data = particledata.GetAreaByAllIncA("");//获取所有分类面积和数量信息 } else { DataTable AllInca = particledata.GetAreaByAllIncA(""); DataTable SelectParticl = SelectParticleData(); data = GetParticleListForParticlSize(SelectParticl, AllInca); } DataTable AreaInformationOfAllElements = ConSolidateInvalid(data); DataTable AllAnalysisDetails = new DataTable(); AllAnalysisDetails.Columns.Add("Name"); AllAnalysisDetails.Columns.Add("TypeId"); AllAnalysisDetails.Columns.Add("Area", typeof(double)); AllAnalysisDetails.Columns.Add("Class"); AllAnalysisDetails.Columns.Add("Cunt", typeof(double)); for (int i = 0; i < AreaInformationOfAllElements.Rows.Count; i++) { DataRow dr2 = AllAnalysisDetails.NewRow(); dr2["Name"] = AreaInformationOfAllElements.Rows[i]["TypeName"].ToString(); dr2["Area"] = Convert.ToDouble(AreaInformationOfAllElements.Rows[i]["ar"]); dr2["TypeId"] = AreaInformationOfAllElements.Rows[i]["TypeId"].ToString(); dr2["Cunt"] = Convert.ToDouble(AreaInformationOfAllElements.Rows[i]["con"]); dr2["Class"] = AreaInformationOfAllElements.Rows[i]["GroupName"].ToString(); AllAnalysisDetails.Rows.Add(dr2); } //按照list列表进行物质类排序,物质类中的元素分类按照面积的大小进行排序 List ClassName = new List(); DataTable getClass_dt = particledata.GetAllClass(); for (int i = 0; i < getClass_dt.Rows.Count; i++) { ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString()); } DataTable AreaRatio = new DataTable(); AreaRatio.TableName = "InclusionAreaRatio"; AreaRatio.Columns.Add("e1"); AreaRatio.Columns.Add("e2"); AreaRatio.Columns.Add("e3", typeof(double)); AreaRatio.Columns.Add("e4"); AreaRatio.Columns.Add("e5"); AreaRatio.Columns.Add("Cunt", typeof(int)); //获取夹杂物的总面积用于计算夹杂物类别的占比(gridview最后一个固定是未识别颗粒,要排除未识别颗粒所以for循环至grid view长度减一) double totalInclusionArea = 0; totalInclusionArea = Convert.ToDouble(decimal.Parse(AllAnalysisDetails.Compute("sum(Area)", "").ToString())); for (int i = 0; i < AllAnalysisDetails.Rows.Count; i++) { DataRow dr2 = AreaRatio.NewRow(); dr2["e1"] = AllAnalysisDetails.Rows[i]["Class"].ToString(); dr2["e2"] = AllAnalysisDetails.Rows[i]["Name"].ToString(); dr2["e3"] = Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]); dr2["e4"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / totalInclusionArea) * 100, 2); dr2["e5"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / Convert.ToDouble(str_SCZS)) * 100, 4); dr2["Cunt"]= AllAnalysisDetails.Rows[i]["Cunt"].ToString(); AreaRatio.Rows.Add(dr2); } DataTable AreaRatio_dt = AreaRatio.Copy(); AreaRatio_dt.Clear(); for (int i = 0; i < ClassName.Count(); i++) { DataTable dt = AreaRatio.Copy(); dt.Clear(); for (int a = 0; a < AreaRatio.Rows.Count; a++) { if (AreaRatio.Rows[a]["e1"].ToString() == ClassName[i].ToString()) { dt.Rows.Add(AreaRatio.Rows[a].ItemArray); } } DataView dv = dt.DefaultView; dv.Sort = "e3 DESC"; DataTable dt_Element = dv.ToTable(); for (int a = 0; a < dt_Element.Rows.Count; a++) { AreaRatio_dt.Rows.Add(dt_Element.Rows[a].ItemArray); } } DataTable AllAnalysisDetails1 = AreaRatio_dt.Copy(); AllAnalysisDetails1.Clear(); for (int i = 0; i < ClassName.Count; i++) { DataTable dt = AreaRatio_dt.Copy(); dt.Clear(); for (int a = 0; a < AreaRatio_dt.Rows.Count; a++) { if (AreaRatio_dt.Rows[a]["e1"].ToString() == ClassName[i].ToString()) { dt.Rows.Add(AreaRatio_dt.Rows[a].ItemArray); } } if (dt.Rows.Count > 0) { double totalInclusionArea2 = Convert.ToDouble(decimal.Parse(AreaRatio_dt.Compute("sum(e3)", "").ToString())); double Area = Convert.ToDouble(decimal.Parse(dt.Compute("sum(e3)", "").ToString())); int cunt= Convert.ToInt32(decimal.Parse(dt.Compute("sum(Cunt)", "").ToString())); DataRow dr3 = AllAnalysisDetails1.NewRow(); dr3["e1"] = ClassName[i].ToString(); dr3["e3"] = Math.Round(Area, 2); //Convert.ToDouble(decimal.Parse(dt.Compute("sum(e3)", "").ToString())); dr3["e4"] = Math.Round((Convert.ToDouble(dt.Rows[0]["e3"]) / totalInclusionArea2) * 100, 2); dr3["e5"] = Math.Round((Convert.ToDouble(dt.Rows[0]["e3"]) / Convert.ToDouble(str_SCZS)) * 100, 4); dr3["Cunt"] = cunt; AllAnalysisDetails1.Rows.Add(dr3); } } return AllAnalysisDetails1; } private DataTable GetParticleListForParticlSize(DataTable data, DataTable table) { DataTable dt_Partick = new DataTable(); dt_Partick.Columns.Add("TypeId"); dt_Partick.Columns.Add("TypeName"); dt_Partick.Columns.Add("TypeColor"); dt_Partick.Columns.Add("con"); dt_Partick.Columns.Add("av"); dt_Partick.Columns.Add("max"); dt_Partick.Columns.Add("ar", typeof(double)); dt_Partick.Columns.Add("GroupName"); List typeName = new List(); for (int i = 0; i < data.Rows.Count; i++) { typeName.Add(data.Rows[i]["TypeId"].ToString()); } typeName = typeName.Distinct().ToList(); for (int i = 0; i < typeName.Count; i++) { DataTable dt = dt_Partick.Clone(); for (int j = 0; j < data.Rows.Count; j++) { if (typeName[i].ToString() == data.Rows[j]["TypeId"].ToString()) { DataRow row = dt.NewRow(); row["TypeId"] = data.Rows[j]["TypeId"]; row["TypeName"] = data.Rows[j]["TypeName"]; row["TypeColor"] = data.Rows[j]["TypeColor"]; row["ar"] = data.Rows[j]["Area"]; dt.Rows.Add(row); } } DataRow dr = dt_Partick.NewRow(); dr["TypeId"] = dt.Rows[0]["TypeId"].ToString(); dr["TypeName"] = dt.Rows[0]["TypeName"].ToString(); dr["TypeColor"] = dt.Rows[0]["TypeColor"].ToString(); dr["con"] = dt.Rows.Count; dr["av"] = dt.Compute("min(ar)", ""); dr["max"] = dt.Compute("Max(ar)", ""); dr["ar"] = dt.Compute("SUM(ar)", ""); dt_Partick.Rows.Add(dr); } for (int i = 0; i < dt_Partick.Rows.Count; i++) { for (int j = 0; j < table.Rows.Count; j++) { if (dt_Partick.Rows[i]["TypeId"].ToString() == table.Rows[j]["TypeId"].ToString()) { dt_Partick.Rows[i]["GroupName"] = table.Rows[j]["GroupName"]; break; } } } return dt_Partick; } #region 读取选择颗粒数据 private DataTable SelectParticleData() { List selectParticles = m_ReportApp.GetSelectedParticles(); #region Datatable数据表格式 DataTable dtUelect = new DataTable(); dtUelect.Columns.Add("fieldid"); dtUelect.Columns.Add("particleid"); dtUelect.Columns.Add("AveGray"); dtUelect.Columns.Add("RectLeft"); dtUelect.Columns.Add("RectTop"); dtUelect.Columns.Add("RectWidth"); dtUelect.Columns.Add("RectHeight"); dtUelect.Columns.Add("Area"); dtUelect.Columns.Add("PosX"); dtUelect.Columns.Add("PosY"); dtUelect.Columns.Add("TypeId"); dtUelect.Columns.Add("SegmentNum"); dtUelect.Columns.Add("SEMPosX"); dtUelect.Columns.Add("SEMPosY"); dtUelect.Columns.Add("XrayId"); dtUelect.Columns.Add("DMAX"); dtUelect.Columns.Add("DMIN"); dtUelect.Columns.Add("DPERP"); dtUelect.Columns.Add("PERIMETER"); dtUelect.Columns.Add("ORIENTATION"); dtUelect.Columns.Add("DINSCR"); dtUelect.Columns.Add("DMEAN"); dtUelect.Columns.Add("DELONG"); dtUelect.Columns.Add("DFERET"); dtUelect.Columns.Add("TypeName"); dtUelect.Columns.Add("TypeColor"); #endregion for (int i = 0; i < selectParticles.Count; i++) { dtUelect.Rows.Add(selectParticles[i].FieldId, selectParticles[i].ParticleId, selectParticles[i].AveGray, selectParticles[i].RectLeft, selectParticles[i].RectTop, selectParticles[i].RectWidth, selectParticles[i].RectHeight, selectParticles[i].Area, selectParticles[i].PosX, selectParticles[i].PosX, selectParticles[i].TypeId, /*selectParticles[i].ElementNum,*/ selectParticles[i].SegmentNum, selectParticles[i].SEMPosX, selectParticles[i].SEMPosY, selectParticles[i].ParticleId, selectParticles[i].DMAX, selectParticles[i].DMIN, selectParticles[i].DPERP, selectParticles[i].PERIMETER, selectParticles[i].ORIENTATION, selectParticles[i].DINSCR, selectParticles[i].DMEAN, selectParticles[i].DELONG, selectParticles[i].DFERET, selectParticles[i].TypeName, selectParticles[i].TypeColor); } return dtUelect; } #endregion private DataTable ConSolidateInvalid(DataTable dt) { DataTable dt_invalid = dt.Clone(); DataTable dt_no_invalid = dt.Clone(); for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i]["TypeName"].ToString()=="Invalid") { dt_invalid.Rows.Add(dt.Rows[i].ItemArray); } else { dt_no_invalid.Rows.Add(dt.Rows[i].ItemArray); } } return dt_no_invalid; } /// /// 获取颗粒成分数据 /// private Chartdate GetPComponentData(string path) { DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path); //创建新的图形数据源 Chartdate chart = new Chartdate(); chart.Title = m_ReportApp.m_reportname; chart.YName = m_str_AxisY; //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); //int sel = m_ReportApp.SourceGridData.ConditionItemList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString()); //int sel = m_conditionChoose.m_SourceGridData.GetPropIndexByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); string filedAndParticl = ""; if (sel == 1) { List selectParticles = m_ReportApp.GetSelectedParticles(); foreach (var item in selectParticles) { filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString()); } if (filedAndParticl != "") { filedAndParticl = filedAndParticl + ","; } } DataTable dt = particledata.GetParticleListForParticlSize("area", filedAndParticl); //设置标签名称 List listName = new List(); //ListName for (int i = 0; i < dt.Rows.Count; i++) { if (Convert.ToInt32(dt.Rows[i]["TypeId"]) < 100) { continue; } listName.Add(dt.Rows[i]["TypeName"].ToString()); } for (int i = 0; i < dt.Rows.Count; i++) { if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 100) { continue; } int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[i]["TypeId"])); if (index == -1) { index = 7; } string name = NameList[index]; if (listName.IndexOf(name) == -1) { listName.Add(name); } } chart.ListName = listName; //设置数据 List listData = new List(); //ListData for (int k = 0; k < dt.Rows.Count; k++) { string str = dt.Rows[k]["con"].ToString(); string name = dt.Rows[k]["TypeName"].ToString(); if (Convert.ToInt32(dt.Rows[k]["TypeId"]) < 100) { int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[k]["TypeId"])); if (index == -1) { index = 7; } name = NameList[index]; } Item item = new Item() { value = decimal.Round(decimal.Parse(str), 2).ToString(), name = name }; listData.Add(item); } chart.ListData = listData; return chart; } /// /// 获取元素成分数据 /// private Chartdate GetEComponentData(string path) { DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path); //创建新的图形数据源 Chartdate chart = new Chartdate(); chart.Title = m_ReportApp.m_reportname; chart.YName = m_str_AxisY; //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); //int sel = m_ReportApp.SourceGridData.ConditionItemList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString()); //int sel = m_conditionChoose.m_SourceGridData.GetPropIndexByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); string filedAndParticl = ""; if (sel == 1) { List selectParticles = m_ReportApp.GetSelectedParticles(); foreach (var item in selectParticles) { filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString()); } if (filedAndParticl != "") { filedAndParticl = filedAndParticl + ","; } } DataTable dt = particledata.GetElementForArea(filedAndParticl); //设置标签名称 List listName = new List(); //ListName for (int i = 0; i < dt.Rows.Count; i++) { listName.Add(dt.Rows[i]["name"].ToString()); } chart.ListName = listName; //设置数据 List listData = new List(); //ListData for (int k = 0; k < dt.Rows.Count; k++) { string str = dt.Rows[k]["earea"].ToString(); try { Item item = new Item() { value = decimal.Round(decimal.Parse(str), 2).ToString(), name = dt.Rows[k]["name"].ToString() }; listData.Add(item); } catch { Item item = new Item() { value = str, name = dt.Rows[k]["name"].ToString() }; listData.Add(item); } } chart.ListData = listData; return chart; } /// /// 获取此尺寸分布图数据 /// private Chartdate GetPSizeData(string path) { DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path); //创建新的图形数据源 Chartdate chart = new Chartdate(); chart.Title = m_ReportApp.m_reportname; chart.YName = m_str_AxisY; //设置标签名称 List listName = new List(); //获取粒级表 string pathe = m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFileFolder + m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile; DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(pathe); string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString(); for (int i = 0; i < sizestr.Split(',').Length - 1; i++) { if (sizestr.Split(',')[i].Length > 0) { double d1 = Convert.ToDouble(sizestr.Split(',')[i]); double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]); listName.Add(d1.ToString() + "~" + d2.ToString()); } } double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]); listName.Add(d.ToString() + "~MAX"); chart.ListName = listName; //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); //int sel = m_ReportApp.SourceGridData.ConditionItemList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString()); //int sel = m_conditionChoose.m_SourceGridData.GetPropIndexByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); string filedAndParticl = ""; if (sel == 1) { List selectParticles = m_ReportApp.GetSelectedParticles(); foreach (var item in selectParticles) { filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString()); } if (filedAndParticl != "") { filedAndParticl = filedAndParticl + ","; } } //idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE); //string con = m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString(); string con = m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE).ToString(); string po = ""; switch (con) { case "DMAX": po = "DMAX"; break; case "DMIN": po = "DMIN"; break; case "CIRCLE": po = "Area"; break; case "FERET": po = "DFERET"; break; } DataTable dtp = particledata.GetParticleAll(filedAndParticl); //设置数据 List listData = new List(); //ListData for (int k = 0; k < listName.Count; k++) { string str = listName[k]; string d1 = str.Split('~')[0]; string d2 = str.Split('~')[1]; if (d2 == "MAX") { d2 = "999"; } DataRow[] datas = dtp.Select(getWhere(d2, d1, po)); Item item = new Item() { value = datas.Count().ToString(), name = str }; listData.Add(item); } chart.ListData = listData; return chart; } private Chartdate GetPSizeDataCombin(string path) { DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path); //创建新的图形数据源 Chartdate chart = new Chartdate(); chart.Title = m_ReportApp.m_reportname; chart.YName = m_str_AxisY; //设置标签名称 List listName = new List(); //获取粒级表 string pathe = m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFileFolder + m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile; DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(pathe); string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString(); for (int i = 0; i < sizestr.Split(',').Length - 1; i++) { if (sizestr.Split(',')[i].Length > 0) { double d1 = Convert.ToDouble(sizestr.Split(',')[i]); double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]); listName.Add(d1.ToString() + "~" + d2.ToString()); } } double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]); listName.Add(d.ToString() + "~MAX"); //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); //int sel = m_ReportApp.SourceGridData.ConditionItemList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString()); //int sel = m_conditionChoose.m_SourceGridData.GetPropIndexByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); string filedAndParticl = ""; if (sel == 1) { List selectParticles = m_ReportApp.GetSelectedParticles(); foreach (var item in selectParticles) { filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString()); } if (filedAndParticl != "") { filedAndParticl = filedAndParticl + ","; } } //idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE); //string con = m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString(); string con = m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE).ToString(); string po = ""; switch (con) { case "DMAX": po = "DMAX"; break; case "DMIN": po = "DMIN"; break; case "CIRCLE": po = "Area"; break; case "FERET": po = "DFERET"; break; } DataTable dtp = particledata.GetParticleAll(filedAndParticl); //计算分类整个表的数据 DataTable dt = ClassificationIntegration(path, sel); List listClassificationName = new List(); //ListName for (int i = 0; i < dt.Rows.Count; i++) { listClassificationName.Add(dt.Rows[i]["e1"].ToString()); } chart.ListName = listClassificationName; //设置数据 List listData = new List(); //ListData string strNameGroup = ""; for (int j = 0; j < listClassificationName.Count; j++) { string strGroup = ""; for (int k = 0; k < listName.Count; k++) { string str = listName[k]; string d1 = str.Split('~')[0]; string d2 = str.Split('~')[1]; if (d2 == "MAX") { d2 = "999"; } DataRow[] datas = dtp.Select(getWhere(d2, d1, po) + " and GroupName = '" + listClassificationName[j] + "'"); strGroup += datas.Count(); if (k != listName.Count - 1) { strGroup += ","; } } Item item = new Item() { value = strGroup, name = listClassificationName[j] }; listData.Add(item); strNameGroup += listClassificationName[j]; if (j != listClassificationName.Count - 1) { strNameGroup += ","; } } chart.Title = "[" + strNameGroup + "]"; chart.ListData = listData; return chart; } private string getWhere(string max, string min, string col) { return col + ">=" + min + " and " + col + "<" + max; } #endregion #region echarts /// /// 通过m_list_chartstruct,组合json数据格式 /// /// private List GetListJsonStrByChartStruct(int sel) { List list = new List(); Chartdate chartdate = new Chartdate(); switch (ComSel) { case "CommonlyUsedClassify": //chartdate = GetCommonlyUsedClassifyData(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath); chartdate = GetInclusionAreaRatioClassData(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath, sel); break; case "PComponent": chartdate = GetPComponentData(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath); break; case "EComponent": chartdate = GetEComponentData(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath); break; case "PSize": chartdate = GetPSizeData(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath); break; case "PSizeCombin": chartdate = GetPSizeDataCombin(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath); break; case "InclusionareaRatio": chartdate = GetInclusionAreaRatioData(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath, sel); break; case "InclusionareaClassRatio": chartdate=GetInclusionAreaRatioClassData(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath, sel); break; } list.Add(chartdate); return list; } /// /// 通过m_list_chartstruct,组合json数据格式 /// /// private ChartdateMore GetListJsonStr() { //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); //int sel = m_ReportApp.SourceGridData.ConditionItemList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString()); //int sel = m_conditionChoose.m_SourceGridData.GetPropIndexByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE); int sel = m_conditionChoose.m_conditionData.ProItemProIndex(); string filedAndParticl = ""; if (sel == 1) { List selectParticles = m_ReportApp.GetSelectedParticles(); foreach (var item in selectParticles) { filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString()); } if (filedAndParticl != "") { filedAndParticl = filedAndParticl + ","; } } DataOperation.DataAccess.ParticleData particledata = null; DataTable dt = new DataTable(); ChartdateMore chart = new ChartdateMore(); chart.Title = m_ReportApp.m_reportname; chart.YName = m_str_AxisY; List listName = new List(); List soursName = new List(); List> listDataMore = new List>(); //idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE); //string sou = m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString(); string sou = m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString(); if (sou.Contains("+")) { for (int i = 0; i < sou.Split('+').Length; i++) { ResultFile resultFile = m_DataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]); if (resultFile == null) { continue; } soursName.Add(resultFile.anotherFileName); particledata = new DataOperation.DataAccess.ParticleData(resultFile.FilePath); switch (ComSel) { case "InclusionareaRatio": dt = particledata.GetAreaByAllIncA(""); //设置标签名称 for (int a = 0; a < dt.Rows.Count; a++) { if (Convert.ToInt32(dt.Rows[a]["TypeId"]) < 100) { continue; } listName.Add(dt.Rows[a]["TypeName"].ToString()); } //设置数据 List listData3 = new List(); for (int k = 0; k < dt.Rows.Count; k++) { string str = dt.Rows[k]["ar"].ToString(); string name = dt.Rows[k]["TypeName"].ToString(); if (Convert.ToInt32(dt.Rows[k]["TypeId"]) < 100) { continue; } Item item = new Item() { value = decimal.Round(decimal.Parse(dt.Rows[k]["ar"].ToString()), 2).ToString(), name = name }; listData3.Add(item); } listDataMore.Add(listData3); break; case "CommonlyUsedClassify": //计算分类整个表的数据 dt = ClassificationIntegration(resultFile.FilePath,sel); ////List listName = new List(); ////ListName for (int a = 0; a < dt.Rows.Count; a++) { listName.Add(dt.Rows[a]["e1"].ToString()); } //chart.ListName = listName; ////DataTable dt //设置数据 List listData2 = new List(); ////ListData for (int k = 0; k < dt.Rows.Count; k++) { string str = dt.Rows[k]["Cunt"].ToString(); string name = dt.Rows[k]["e1"].ToString(); Item item = new Item() { value = decimal.Round(decimal.Parse(str), 2).ToString(), name = name }; listData2.Add(item); //listData2.Add(item); } listDataMore.Add(listData2); break; case "PComponent": //创建新的图形数据源 dt = particledata.GetParticleListByIncA("area"); //设置标签名称 for (int j = 0; j < dt.Rows.Count; j++) { if (Convert.ToInt32(dt.Rows[j]["TypeId"]) < 100) { continue; } string name = dt.Rows[j]["TypeName"].ToString(); if (!listName.Contains(name)) { listName.Add(name); } } for (int j = 0; j < dt.Rows.Count; j++) { if (Convert.ToInt32(dt.Rows[j]["TypeId"]) > 100) { continue; } int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[j]["TypeId"])); if (index == -1) { index = 7; } string name = NameList[index]; if (!listName.Contains(name)) { listName.Add(name); } } //设置数据 List listData = new List(); //ListData for (int k = 0; k < dt.Rows.Count; k++) { string str = dt.Rows[k]["con"].ToString(); string name = dt.Rows[k]["TypeName"].ToString(); if (Convert.ToInt32(dt.Rows[k]["TypeId"]) < 100) { if (Convert.ToInt32(dt.Rows[k]["TypeId"])==-1) { name = NameList[7]; } else { int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[k]["TypeId"])); name = NameList[index]; } } Item item = new Item() { value = decimal.Round(decimal.Parse(str), 2).ToString(), name = name }; listData.Add(item); } listDataMore.Add(listData); break; case "EComponent": //创建新的图形数据源 dt = particledata.GetElementForArea(filedAndParticl); //ListName for (int j = 0; j < dt.Rows.Count; j++) { string name = dt.Rows[j]["name"].ToString(); if (!listName.Contains(name)) { listName.Add(name); } } //设置数据 List listData1 = new List(); //ListData for (int k = 0; k < dt.Rows.Count; k++) { string str = dt.Rows[k]["earea"].ToString(); try { Item item = new Item() { value = decimal.Round(decimal.Parse(str), 2).ToString(), name = dt.Rows[k]["name"].ToString() }; listData1.Add(item); } catch { Item item = new Item() { value = str, name = dt.Rows[k]["name"].ToString() }; listData1.Add(item); } } listDataMore.Add(listData1); break; case "PSize": //获取粒级表 string pathe = m_DataMgr.m_RptConfigFile.PartSizeFileFolder + m_DataMgr.m_RptConfigFile.PartSizeFile; DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(pathe); string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString(); List temp = new List(); for (int j = 0; j < sizestr.Split(',').Length - 1; j++) { if (sizestr.Split(',')[j].Length > 0) { double d1 = Convert.ToDouble(sizestr.Split(',')[j]); double d2 = Convert.ToDouble(sizestr.Split(',')[j + 1]); string name = d1.ToString() + "~" + d2.ToString(); temp.Add(name); if (!listName.Contains(name)) { listName.Add(name); } } } double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]); string name1 = d.ToString() + "~MAX"; temp.Add(name1); if (!listName.Contains(name1)) { listName.Add(name1); } //string con = m_ReportApp.SourceGridData.ConditionItemList[m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE)].itemVal.ToString(); string con = m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE).ToString(); string po = ""; switch (con) { case "DMAX": po = "DMAX"; break; case "DMIN": po = "DMIN"; break; case "CIRCLE": po = "Area"; break; case "FERET": po = "DFERET"; break; } DataTable dtp = particledata.GetParticleAll(filedAndParticl); //设置数据 List listData4 = new List(); //ListData for (int k = 0; k < temp.Count; k++) { string str = temp[k]; string d1 = str.Split('~')[0]; string d2 = str.Split('~')[1]; if (d2 == "MAX") { d2 = "999"; } DataRow[] datas = dtp.Select(getWhere(d2, d1, po)); Item item = new Item() { value = datas.Count().ToString(), name = str }; listData4.Add(item); } listDataMore.Add(listData4); break; } } } chart.ListName = listName; chart.SoursName = soursName; chart.ListData = listDataMore; return chart; } class Chartdate { public string Title { get; set; } public string YName { get; set; } public List ListName { get; set; } public List ListData { get; set; } } class ChartdateMore { public string Title { get; set; } public string YName { get; set; } public List ListName { get; set; } public List SoursName { get; set; } public List> ListData { get; set; } } class Item { public string value { get; set; } public string name { get; set; } } //获取图片 private void button1_Click(object sender, EventArgs e) { //string str = GetPic(); //pic = str; ////保存目录 //string dir = Path.Combine(Directory.GetCurrentDirectory(), "Resources/HTML/pic"); ////文件名称 //string fileName = "headdemo" + DateTime.Now.ToString("yyyyMMddHHmmssff"); ////保存文件所在站点位置 //string filePath = Path.Combine(dir, fileName); //if (!System.IO.Directory.Exists(dir)) // System.IO.Directory.CreateDirectory(dir); ////将Base64String转为图片并保存 //byte[] arr2 = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1)); //using (MemoryStream ms2 = new MemoryStream(arr2)) //{ // System.Drawing.Bitmap bmp2 = new System.Drawing.Bitmap(ms2); // bmp2.Save(filePath + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); //} } /// /// 加载浏览器 /// public void InitBrowser() { //加载网页 if (m_ReportApp.browser == null || m_ReportApp.trans) { // 获取生成路径下网页文件的绝对路径 string fileName = Path.Combine(Directory.GetCurrentDirectory(), url); //加载网页 m_ReportApp.browser = new ChromiumWebBrowser(fileName); //禁止网页 m_ReportApp.browser.MenuHandler = new MenuHandler(); m_ReportApp.browser.Dock = DockStyle.Fill; m_ReportApp.js.MessageText = ""; //添加网页到当前自定义控件 this.Controls.Add(m_ReportApp.browser); //供页面调用以传递数据 m_ReportApp.browser.RegisterJsObject("jsObj", m_ReportApp.js, false); //升级cef版本后新方法 //CefSharpSettings.LegacyJavascriptBindingEnabled = true; //CefSharpSettings.WcfEnabled = true; //m_ReportApp.browser.JavascriptObjectRepository.Register("jsObj", m_ReportApp.js, isAsync: false, options: BindingOptions.DefaultBinder); //网页加载结束后调用事件 m_ReportApp.browser.FrameLoadEnd += WebBrowser_FrameLoadEnd; } else { m_ReportApp.browser.ResetText(); m_ReportApp.browser.Reload(); m_ReportApp.browser.Refresh(); //供页面调用以传递数据 this.Controls.Add(m_ReportApp.browser); } if (m_ReportApp.timerKG) { timer1.Enabled = true; } } /// /// 页面加载结束后事件 /// /// /// private void WebBrowser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e) { if (e.Frame.IsMain) { //为页面图形提供数据参数 string str = m_ReportApp.data; string strCombin = m_ReportApp.dataCombin; //执行网页脚本事件 m_ReportApp.browser.ExecuteScriptAsync("showchart('" + str + "','" + strCombin + "','" + m_ReportApp.type + "')"); } } //public string GetPic() //{ // return js.MessageText; //} //禁止网页操作,右键点击等 class MenuHandler : CefSharp.IContextMenuHandler { void CefSharp.IContextMenuHandler.OnBeforeContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model) { model.Clear(); } bool CefSharp.IContextMenuHandler.OnContextMenuCommand(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.CefMenuCommand commandId, CefSharp.CefEventFlags eventFlags) { //throw new NotImplementedException(); return false; } void CefSharp.IContextMenuHandler.OnContextMenuDismissed(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame) { //throw new NotImplementedException(); } bool CefSharp.IContextMenuHandler.RunContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model, CefSharp.IRunContextMenuCallback callback) { return false; } } class JsEvent { public string MessageText { set; get; } public void ShowTest() { MessageBox.Show(MessageText); } } #endregion #region EChart导出图像委托调用部份 public delegate void MyDelgate(string va); public event MyDelgate butclic; private void timer1_Tick(object sender, EventArgs e) { if (butclic == null) return; if (m_ReportApp.js == null) return; if (m_ReportApp.js.MessageText == null) return; if (m_ReportApp.js.MessageText != "") { butclic(m_ReportApp.js.MessageText); timer1.Enabled = false; m_ReportApp.timerKG = false; } } #endregion } }