123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866 |
- using CefSharp;
- using CefSharp.WinForms;
- using Newtonsoft.Json;
- using OTSIncAReportApp.SysMgrTools;
- 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
- {
- /// <summary>
- /// 各图char相关模块
- /// </summary>
- public partial class EChart_ParticlesComposition : UserControl
- {
- #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; }
- frmReportApp m_ReportApp;
- List<int> FLID = new List<int>() { 0, 1, 2, 4, 6, 7, 8, 9 };
- List<string> NameList = new List<string>() { "过小颗粒", "过大颗粒", "亮度不在分析范围内的颗粒", "低计数率颗粒", "不含分析元素的颗粒", "非夹杂物颗粒SiC", "非夹杂物颗粒FeO", "未识别颗粒" };
- #endregion
- #region 窗体加载及构造函数
- public EChart_ParticlesComposition(frmReportApp ReportApp, string comsel)
- {
- ComSel = comsel;
- m_ReportApp = ReportApp;
- InitializeComponent();
- }
- private void EChart_ParticlesComposition_Load(object sender, EventArgs e)
- {
- //国际化
- Language lan = new Language();
- Hashtable table = lan.GetNameTable("CompositionDistributionGrid");
- NameList = new List<string>() { 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.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
- string sou = m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString();
- 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的字符串
- List<Chartdate> list_json_str = GetListJsonStrByChartStruct();
- url = "Resources/HTML/charts.html";
- m_ReportApp.data = JsonConvert.SerializeObject(list_json_str[0]);
- }
- InitBrowser();
- }
- #endregion
- #region 获取单数据源
- private Chartdate GetCommonlyUsedClassifyData(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.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
- int sel = m_ReportApp.SourceGridData.SampleDataList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString());
- string filedAndParticl = "";
- if (sel == 1)
- {
- List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.SelectedParticles;
- foreach (var item in selectParticles)
- {
- filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
- }
- if (filedAndParticl != "")
- {
- filedAndParticl = filedAndParticl + ",";
- }
- }
- DataTable dt = particledata.GetCommonlyUsedClassifyData();
- //设置标签名称
- List<string> listName = new List<string>();
- listName.Add("尖晶石");
- listName.Add("氧化物");
- listName.Add("硫氧化物");
- listName.Add("氮化物");
- listName.Add("硫化物");
- chart.ListName = listName;
- //设置数据
- List<Item> listData = new List<Item>();
- //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 = "尖晶石"
- };
- listData.Add(item_SPINEL);
- Item item_OXIDE = new Item()
- {
- value = decimal.Round(decimal.Parse(dt.Rows[k]["OXIDE"].ToString()), 2).ToString(),
- name = "氧化物"
- };
- listData.Add(item_OXIDE);
- Item item_SULFIDE_OXIDE = new Item()
- {
- value = decimal.Round(decimal.Parse(dt.Rows[k]["SULFIDE_OXIDE"].ToString()), 2).ToString(),
- name = "硫氧化物"
- };
- listData.Add(item_SULFIDE_OXIDE);
- Item item_NITRIDE = new Item()
- {
- value = decimal.Round(decimal.Parse(dt.Rows[k]["NITRIDE"].ToString()), 2).ToString(),
- name = "氮化物"
- };
- listData.Add(item_NITRIDE);
- Item item_SULFIDE = new Item()
- {
- value = decimal.Round(decimal.Parse(dt.Rows[k]["SULFIDE"].ToString()), 2).ToString(),
- name = "硫化物"
- };
- listData.Add(item_SULFIDE);
- }
- catch
- {
- Item item = new Item()
- {
- value = "",
- name = ""
- };
- listData.Add(item);
- }
- }
- chart.ListData = listData;
- return chart;
- }
- /// <summary>
- /// 获取颗粒成分数据
- /// </summary>
- 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.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
- int sel = m_ReportApp.SourceGridData.SampleDataList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString());
- string filedAndParticl = "";
- if (sel == 1)
- {
- List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.SelectedParticles;
- foreach (var item in selectParticles)
- {
- filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
- }
- if (filedAndParticl != "")
- {
- filedAndParticl = filedAndParticl + ",";
- }
- }
- DataTable dt = particledata.GetParticleListByIncA("area", filedAndParticl);
- //设置标签名称
- List<string> listName = new List<string>();
- //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<Item> listData = new List<Item>();
- //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;
- }
- /// <summary>
- /// 获取元素成分数据
- /// </summary>
- 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.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
- int sel = m_ReportApp.SourceGridData.SampleDataList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString());
- string filedAndParticl = "";
- if (sel == 1)
- {
- List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.SelectedParticles;
- foreach (var item in selectParticles)
- {
- filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
- }
- if (filedAndParticl != "")
- {
- filedAndParticl = filedAndParticl + ",";
- }
- }
- DataTable dt = particledata.GetElementForArea(filedAndParticl);
- //设置标签名称
- List<string> listName = new List<string>();
- //ListName
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- listName.Add(dt.Rows[i]["name"].ToString());
- }
- chart.ListName = listName;
- //设置数据
- List<Item> listData = new List<Item>();
- //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;
- }
- /// <summary>
- /// 获取此尺寸分布图数据
- /// </summary>
- 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<string> listName = new List<string>();
- //获取粒级表
- string pathe = m_ReportApp.m_RptConfigFile.FileFolderSize + m_ReportApp.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.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
- int sel = m_ReportApp.SourceGridData.SampleDataList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString());
- string filedAndParticl = "";
- if (sel == 1)
- {
- List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.SelectedParticles;
- foreach (var item in selectParticles)
- {
- filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
- }
- if (filedAndParticl != "")
- {
- filedAndParticl = filedAndParticl + ",";
- }
- }
- idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE);
- string con = m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString();
- string po = "";
- switch (con)
- {
- case "DMAX":
- po = "DMAX";
- break;
- case "DMIN":
- po = "DMIN";
- break;
- case "Area":
- po = "Area";
- break;
- case "FERET":
- po = "DFERET";
- break;
- }
- DataTable dtp = particledata.GetParticleAll(filedAndParticl);
- //设置数据
- List<Item> listData = new List<Item>();
- //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 string getWhere(string max, string min, string col)
- {
- return col + ">=" + min + " and " + col + "<=" + max;
- }
- #endregion
- #region echarts
- /// <summary>
- /// 通过m_list_chartstruct,组合json数据格式
- /// </summary>
- /// <returns></returns>
- private List<Chartdate> GetListJsonStrByChartStruct()
- {
- List<Chartdate> list = new List<Chartdate>();
- Chartdate chartdate = new Chartdate();
- switch (ComSel)
- {
- case "CommonlyUsedClassify":
- chartdate = GetCommonlyUsedClassifyData(m_ReportApp.resultFilesList[m_ReportApp.WorkingResult].FilePath);
- break;
- case "PComponent":
- chartdate = GetPComponentData(m_ReportApp.resultFilesList[m_ReportApp.WorkingResult].FilePath);
- break;
- case "EComponent":
- chartdate = GetEComponentData(m_ReportApp.resultFilesList[m_ReportApp.WorkingResult].FilePath);
- break;
- case "PSize":
- chartdate = GetPSizeData(m_ReportApp.resultFilesList[m_ReportApp.WorkingResult].FilePath);
- break;
- }
- list.Add(chartdate);
- return list;
- }
- /// <summary>
- /// 通过m_list_chartstruct,组合json数据格式
- /// </summary>
- /// <returns></returns>
- private ChartdateMore GetListJsonStr()
- {
- int idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
- int sel = m_ReportApp.SourceGridData.SampleDataList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString());
- string filedAndParticl = "";
- if (sel == 1)
- {
- List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.SelectedParticles;
- 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<string> listName = new List<string>();
- List<string> soursName = new List<string>();
- List<List<Item>> listDataMore = new List<List<Item>>();
- idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
- string sou = m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString();
- if (sou.Contains("+"))
- {
- for (int i = 0; i < sou.Split('+').Length; i++)
- {
- DataOperation.Model.ResultFile resultFile = m_ReportApp.resultFilesList.Find(s => s.FileName == sou.Split('+')[i]);
- if (resultFile == null)
- {
- continue;
- }
- soursName.Add(resultFile.FileName);
- particledata = new DataOperation.DataAccess.ParticleData(resultFile.FilePath);
- switch (ComSel)
- {
- case "CommonlyUsedClassify":
- break;
- case "PComponent":
- //创建新的图形数据源
- dt = particledata.GetParticleListByIncA("area", filedAndParticl);
- //设置标签名称
- 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<Item> listData = new List<Item>();
- //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"]));
- 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<Item> listData1 = new List<Item>();
- //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_ReportApp.m_RptConfigFile.FileFolderSize + m_ReportApp.m_RptConfigFile.PartSizeFile;
- DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(pathe);
- string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
- List<string> temp = new List<string>();
- 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.SampleDataList[m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE)].itemVal.ToString();
- string po = "";
- switch (con)
- {
- case "DMAX":
- po = "DMAX";
- break;
- case "DMIN":
- po = "DMIN";
- break;
- case "Area":
- po = "Area";
- break;
- case "FERET":
- po = "DFERET";
- break;
- }
- DataTable dtp = particledata.GetParticleAll(filedAndParticl);
- //设置数据
- List<Item> listData2 = new List<Item>();
- //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
- };
- listData2.Add(item);
- }
- listDataMore.Add(listData2);
- 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<string> ListName { get; set; }
- public List<Item> ListData { get; set; }
- }
- class ChartdateMore
- {
- public string Title { get; set; }
- public string YName { get; set; }
- public List<string> ListName { get; set; }
- public List<string> SoursName { get; set; }
- public List<List<Item>> 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);
- }
- }
- /// <summary>
- /// 加载浏览器
- /// </summary>
- 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;
- }
- }
- /// <summary>
- /// 页面加载结束后事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void WebBrowser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
- {
- if (e.Frame.IsMain)
- {
- //为页面图形提供数据参数
- string str = m_ReportApp.data;
- //执行网页脚本事件
- m_ReportApp.browser.ExecuteScriptAsync("showchart('" + str + "','" + 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
- }
- }
|