EChart_ParticlesComposition.cs 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. using CefSharp;
  2. using CefSharp.WinForms;
  3. using Newtonsoft.Json;
  4. using OTSIncAReportApp.DataOperation.DataAccess;
  5. using OTSIncAReportApp.DataOperation.Model;
  6. using OTSIncAReportApp.OTSDataMgrFunction;
  7. using OTSIncAReportApp.OTSSampleReportInfo;
  8. using OTSIncAReportApp.OTSTemplateDesigner;
  9. using OTSIncAReportApp.SysMgrTools;
  10. using OTSIncAReportGrids;
  11. using System;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using System.Data;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Windows.Forms;
  18. namespace OTSIncAReportApp.Control_ECharts
  19. {
  20. /// <summary>
  21. /// 各图char相关模块
  22. /// </summary>
  23. public partial class EChart_ParticlesComposition : UserControl
  24. {
  25. Hashtable table;
  26. #region 图表相关变量
  27. //y轴名称
  28. public string m_str_AxisY { get; set; }
  29. //定义图片
  30. JsEvent js;
  31. //定义图片base64
  32. public string pic { get; set; }
  33. //定义图形类型
  34. public string type { get; set; }
  35. //图形数据
  36. public string data { get; set; }
  37. string url = "Resources/HTML/charts.html";
  38. //数据图类型:常用夹杂物分类CommonlyUsedClassify ,颗粒成分PComponent,元素成分EComponent,颗粒尺寸分布PSize
  39. string ComSel { get; set; }
  40. frmReportApp m_ReportApp;
  41. List<int> FLID = new List<int>() { 0, 1, 2, 4, 6, 7, 8, 9 };
  42. List<string> NameList = new List<string>() { "过小颗粒", "过大颗粒", "亮度不在分析范围内的颗粒", "低计数率颗粒", "不含分析元素的颗粒", "非夹杂物颗粒SiC", "非夹杂物颗粒FeO", "未识别颗粒" };
  43. private frmReportConditionChoose m_conditionChoose;
  44. private ResultDataMgr m_DataMgr;
  45. Export_ReportTemplate m_export_reporttemplate;
  46. #endregion
  47. #region 窗体加载及构造函数
  48. public EChart_ParticlesComposition(frmReportApp ReportApp, string comsel)
  49. {
  50. ComSel = comsel;
  51. m_ReportApp = ReportApp;
  52. m_conditionChoose = ReportApp.m_conditionChoose;
  53. m_DataMgr = ReportApp.m_rstDataMgr;
  54. InitializeComponent();
  55. //国际化
  56. Language lan = new Language();
  57. table = lan.GetNameTable("CompositionDistributionGrid");
  58. m_export_reporttemplate = new Export_ReportTemplate();
  59. }
  60. private void EChart_ParticlesComposition_Load(object sender, EventArgs e)
  61. {
  62. 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() };
  63. //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  64. //string sou = m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString();
  65. string sou = m_conditionChoose.m_SourceGridData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  66. if (sou.Contains("+"))
  67. {
  68. if (m_ReportApp.more)
  69. {
  70. m_ReportApp.trans = false;
  71. }
  72. else
  73. {
  74. m_ReportApp.trans = true;
  75. }
  76. m_ReportApp.more = true;
  77. //获取到List,json的字符串
  78. ChartdateMore list_json_str = GetListJsonStr();
  79. url = "Resources/HTML/chartsMore.html";
  80. m_ReportApp.data = JsonConvert.SerializeObject(list_json_str);
  81. }
  82. else
  83. {
  84. if (!m_ReportApp.more)
  85. {
  86. m_ReportApp.trans = false;
  87. }
  88. else
  89. {
  90. m_ReportApp.trans = true;
  91. }
  92. m_ReportApp.more = false;
  93. //获取到List,json的字符串
  94. List<Chartdate> list_json_str = GetListJsonStrByChartStruct();
  95. url = "Resources/HTML/charts.html";
  96. m_ReportApp.data = JsonConvert.SerializeObject(list_json_str[0]);
  97. }
  98. InitBrowser();
  99. }
  100. #endregion
  101. #region 获取单数据源
  102. private Chartdate GetCommonlyUsedClassifyData(string path)
  103. {
  104. string spinel = table["str20"].ToString();
  105. string oxide = table["str21"].ToString();
  106. string SulfurOxide = table["str22"].ToString();
  107. string nitrides = table["str23"].ToString();
  108. string sulfide = table["str24"].ToString();
  109. DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path);
  110. //创建新的图形数据源
  111. Chartdate chart = new Chartdate();
  112. chart.Title = m_ReportApp.m_reportname;
  113. chart.YName = m_str_AxisY;
  114. //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  115. //int sel = m_ReportApp.SourceGridData.ConditionItemList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString());
  116. //int sel = m_conditionChoose.m_SourceGridData.GetPropIndexByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  117. int sel = m_ReportApp.m_conditionChoose.m_SourceGridData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  118. DataTable dt = new DataTable();
  119. if (sel == 1)
  120. {
  121. List<Particle> particles = m_ReportApp.GetSelectedParticles();
  122. int SPINEL = 0;
  123. int OXIDE = 0;
  124. int SULFIDE_OXIDE = 0;
  125. int NITRIDE = 0;
  126. int SULFIDE = 0;
  127. for (int i = 0; i < m_ReportApp.GetSelectedParticles().Count; i++)
  128. {
  129. //SPINEL
  130. 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))
  131. {
  132. SPINEL = SPINEL + 1;
  133. }
  134. //OXIDE
  135. if (particles[i].TypeId >= 10000 || particles[i].TypeId <= 10999)
  136. {
  137. OXIDE = OXIDE + 1;
  138. }
  139. //SULFIDE_OXIDE
  140. 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))
  141. {
  142. SULFIDE_OXIDE = SULFIDE_OXIDE + 1;
  143. }
  144. //NITRIDE
  145. if (particles[i].TypeId >= 12000 || particles[i].TypeId <= 12999)
  146. {
  147. NITRIDE = NITRIDE + 1;
  148. }
  149. //SULFIDE
  150. if (particles[i].TypeId >= 11000 || particles[i].TypeId <= 11999)
  151. {
  152. SULFIDE = SULFIDE + 1;
  153. }
  154. }
  155. DataTable dataTable = new DataTable();
  156. dataTable.Columns.Add("SPINEL", typeof(String));
  157. dataTable.Columns.Add("OXIDE", typeof(String));
  158. dataTable.Columns.Add("SULFIDE_OXIDE", typeof(String));
  159. dataTable.Columns.Add("NITRIDE", typeof(String));
  160. dataTable.Columns.Add("SULFIDE", typeof(String));
  161. dataTable.Rows.Add();
  162. dataTable.Rows[0]["SPINEL"] = SPINEL.ToString();
  163. dataTable.Rows[0]["OXIDE"] = OXIDE.ToString();
  164. dataTable.Rows[0]["SULFIDE_OXIDE"] = SULFIDE_OXIDE.ToString();
  165. dataTable.Rows[0]["NITRIDE"] = NITRIDE.ToString();
  166. dataTable.Rows[0]["SULFIDE"] = SULFIDE.ToString();
  167. dt = dataTable;
  168. }
  169. else
  170. {
  171. dt = particledata.GetCommonlyUsedClassifyData();
  172. }
  173. //DataTable dt = dataTable;
  174. //设置标签名称
  175. List<string> listName = new List<string>();
  176. listName.Add(spinel);
  177. listName.Add(oxide);
  178. listName.Add(SulfurOxide);
  179. listName.Add(nitrides);
  180. listName.Add(sulfide);
  181. chart.ListName = listName;
  182. //设置数据
  183. List<Item> listData = new List<Item>();
  184. //ListData
  185. for (int k = 0; k < dt.Rows.Count; k++)
  186. {
  187. try
  188. {
  189. Item item_SPINEL = new Item()
  190. {
  191. value = decimal.Round(decimal.Parse(dt.Rows[k]["SPINEL"].ToString()), 2).ToString(),
  192. name = spinel
  193. };
  194. listData.Add(item_SPINEL);
  195. Item item_OXIDE = new Item()
  196. {
  197. value = decimal.Round(decimal.Parse(dt.Rows[k]["OXIDE"].ToString()), 2).ToString(),
  198. name = oxide
  199. };
  200. listData.Add(item_OXIDE);
  201. Item item_SULFIDE_OXIDE = new Item()
  202. {
  203. value = decimal.Round(decimal.Parse(dt.Rows[k]["SULFIDE_OXIDE"].ToString()), 2).ToString(),
  204. name = SulfurOxide
  205. };
  206. listData.Add(item_SULFIDE_OXIDE);
  207. Item item_NITRIDE = new Item()
  208. {
  209. value = decimal.Round(decimal.Parse(dt.Rows[k]["NITRIDE"].ToString()), 2).ToString(),
  210. name = nitrides
  211. };
  212. listData.Add(item_NITRIDE);
  213. Item item_SULFIDE = new Item()
  214. {
  215. value = decimal.Round(decimal.Parse(dt.Rows[k]["SULFIDE"].ToString()), 2).ToString(),
  216. name = sulfide
  217. };
  218. listData.Add(item_SULFIDE);
  219. }
  220. catch
  221. {
  222. Item item = new Item()
  223. {
  224. value = "",
  225. name = ""
  226. };
  227. listData.Add(item);
  228. }
  229. }
  230. chart.ListData = listData;
  231. return chart;
  232. }
  233. private Chartdate GetInclusionAreaRatioData(string path)
  234. {
  235. DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path);
  236. //创建新的图形数据源
  237. Chartdate chart = new Chartdate();
  238. chart.Title = m_ReportApp.m_reportname;
  239. chart.YName = m_str_AxisY;
  240. int sel = m_ReportApp.m_conditionChoose.m_SourceGridData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  241. DataTable dt = particledata.GetAreaByAllIncA("");
  242. //设置标签名称
  243. List<string> listName = new List<string>();
  244. //ListName
  245. for (int i = 0; i < dt.Rows.Count; i++)
  246. {
  247. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) < 100)
  248. {
  249. continue;
  250. }
  251. listName.Add(dt.Rows[i]["TypeName"].ToString());
  252. }
  253. //for (int i = 0; i < dt.Rows.Count; i++)
  254. //{
  255. // if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 100)
  256. // {
  257. // continue;
  258. // }
  259. // int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[i]["TypeId"]));
  260. // if (index == -1)
  261. // {
  262. // index = 7;
  263. // }
  264. // string name = NameList[index];
  265. // if (listName.IndexOf(name) == -1)
  266. // {
  267. // listName.Add(name);
  268. // }
  269. //}
  270. chart.ListName = listName;
  271. //设置数据
  272. List<Item> listData = new List<Item>();
  273. //ListData
  274. for (int k = 0; k < dt.Rows.Count; k++)
  275. {
  276. string str = dt.Rows[k]["ar"].ToString();
  277. string name = dt.Rows[k]["TypeName"].ToString();
  278. if (Convert.ToInt32(dt.Rows[k]["TypeId"]) < 100)
  279. {
  280. continue;
  281. }
  282. Item item = new Item()
  283. {
  284. value = decimal.Round(decimal.Parse(dt.Rows[k]["ar"].ToString()), 2).ToString(),
  285. name = name
  286. };
  287. listData.Add(item);
  288. }
  289. chart.ListData = listData;
  290. return chart;
  291. }
  292. private Chartdate GetInclusionAreaRatioClassData(string path)
  293. {
  294. //创建新的图形数据源
  295. Chartdate chart = new Chartdate();
  296. chart.Title = m_ReportApp.m_reportname;
  297. chart.YName = m_str_AxisY;
  298. //计算分类整个表的数据
  299. DataTable dt= ClassificationIntegration(path);
  300. List<string> listName = new List<string>();
  301. //ListName
  302. for (int i = 0; i < dt.Rows.Count; i++)
  303. {
  304. listName.Add(dt.Rows[i]["e1"].ToString());
  305. }
  306. chart.ListName = listName;
  307. //DataTable dt
  308. //设置数据
  309. List<Item> listData = new List<Item>();
  310. //ListData
  311. for (int k = 0; k < dt.Rows.Count; k++)
  312. {
  313. string str = dt.Rows[k]["e3"].ToString();
  314. string name = dt.Rows[k]["e1"].ToString();
  315. Item item = new Item()
  316. {
  317. value = decimal.Round(decimal.Parse(dt.Rows[k]["e3"].ToString()), 2).ToString(),
  318. name = name
  319. };
  320. listData.Add(item);
  321. }
  322. chart.ListData = listData;
  323. return chart;
  324. }
  325. private DataTable ClassificationIntegration(string path )
  326. {
  327. //------------------加载模块,获取数据-------------------------------------------------
  328. ResultGrid ls_resultgrid = new ResultGrid(m_ReportApp);
  329. Dictionary<string, string> keyValues_ResultGrid = ls_resultgrid.GetData_ResultGrid();
  330. //------------------加载模块,获取数据结束----------------------------------------------
  331. Dictionary<string, string>.Enumerator en = keyValues_ResultGrid.GetEnumerator();
  332. string str_SCZS = "";
  333. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col5"].ToString(), out str_SCZS);//视场总数
  334. DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path);
  335. DataTable AreaInformationOfAllElements = particledata.GetAreaByAllIncA("");//获取所有分类面积和数量信息
  336. DataTable AllAnalysisDetails = new DataTable();
  337. AllAnalysisDetails.Columns.Add("Name");
  338. AllAnalysisDetails.Columns.Add("TypeId");
  339. AllAnalysisDetails.Columns.Add("Area", typeof(double));
  340. AllAnalysisDetails.Columns.Add("Class");
  341. AllAnalysisDetails.Columns.Add("Cunt", typeof(double));
  342. for (int i = 0; i < AreaInformationOfAllElements.Rows.Count; i++)
  343. {
  344. DataRow dr2 = AllAnalysisDetails.NewRow();
  345. dr2["Name"] = AreaInformationOfAllElements.Rows[i]["TypeName"].ToString();
  346. dr2["Area"] = Convert.ToDouble(AreaInformationOfAllElements.Rows[i]["ar"]);
  347. dr2["TypeId"] = AreaInformationOfAllElements.Rows[i]["TypeId"].ToString();
  348. dr2["Cunt"] = Convert.ToDouble(AreaInformationOfAllElements.Rows[i]["con"]);
  349. dr2["Class"] = AreaInformationOfAllElements.Rows[i]["GroupName"].ToString();
  350. AllAnalysisDetails.Rows.Add(dr2);
  351. }
  352. //按照list列表进行物质类排序,物质类中的元素分类按照面积的大小进行排序
  353. List<string> ClassName = new List<string>();
  354. DataTable getClass_dt = particledata.GetAllClass();
  355. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  356. {
  357. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  358. }
  359. DataTable AreaRatio = new DataTable();
  360. AreaRatio.TableName = "InclusionAreaRatio";
  361. AreaRatio.Columns.Add("e1");
  362. AreaRatio.Columns.Add("e2");
  363. AreaRatio.Columns.Add("e3", typeof(double));
  364. AreaRatio.Columns.Add("e4");
  365. AreaRatio.Columns.Add("e5");
  366. //获取夹杂物的总面积用于计算夹杂物类别的占比(gridview最后一个固定是未识别颗粒,要排除未识别颗粒所以for循环至grid view长度减一)
  367. double totalInclusionArea = 0;
  368. totalInclusionArea = Convert.ToDouble(decimal.Parse(AllAnalysisDetails.Compute("sum(Area)", "").ToString()));
  369. for (int i = 0; i < AllAnalysisDetails.Rows.Count; i++)
  370. {
  371. DataRow dr2 = AreaRatio.NewRow();
  372. dr2["e1"] = AllAnalysisDetails.Rows[i]["Class"].ToString();
  373. dr2["e2"] = AllAnalysisDetails.Rows[i]["Name"].ToString();
  374. dr2["e3"] = Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]);
  375. dr2["e4"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / totalInclusionArea) * 100, 2);
  376. dr2["e5"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / Convert.ToDouble(str_SCZS)) * 100, 4);
  377. AreaRatio.Rows.Add(dr2);
  378. }
  379. DataTable AreaRatio_dt = AreaRatio.Copy();
  380. AreaRatio_dt.Clear();
  381. for (int i = 0; i < ClassName.Count(); i++)
  382. {
  383. DataTable dt = AreaRatio.Copy();
  384. dt.Clear();
  385. for (int a = 0; a < AreaRatio.Rows.Count; a++)
  386. {
  387. if (AreaRatio.Rows[a]["e1"].ToString() == ClassName[i].ToString())
  388. {
  389. dt.Rows.Add(AreaRatio.Rows[a].ItemArray);
  390. }
  391. }
  392. DataView dv = dt.DefaultView;
  393. dv.Sort = "e3 DESC";
  394. DataTable dt_Element = dv.ToTable();
  395. for (int a = 0; a < dt_Element.Rows.Count; a++)
  396. {
  397. AreaRatio_dt.Rows.Add(dt_Element.Rows[a].ItemArray);
  398. }
  399. }
  400. DataTable AllAnalysisDetails1 = AreaRatio_dt.Copy();
  401. AllAnalysisDetails1.Clear();
  402. for (int i = 0; i < ClassName.Count; i++)
  403. {
  404. DataTable dt = AreaRatio_dt.Copy();
  405. dt.Clear();
  406. for (int a = 0; a < AreaRatio_dt.Rows.Count; a++)
  407. {
  408. if (AreaRatio_dt.Rows[a]["e1"].ToString() == ClassName[i].ToString())
  409. {
  410. dt.Rows.Add(AreaRatio_dt.Rows[a].ItemArray);
  411. }
  412. }
  413. if (dt.Rows.Count > 0)
  414. {
  415. double totalInclusionArea2 = Convert.ToDouble(decimal.Parse(AreaRatio_dt.Compute("sum(e3)", "").ToString()));
  416. double Area = Convert.ToDouble(decimal.Parse(dt.Compute("sum(e3)", "").ToString()));
  417. DataRow dr3 = AllAnalysisDetails1.NewRow();
  418. dr3["e1"] = ClassName[i].ToString();
  419. dr3["e3"] = Math.Round(Area, 2);
  420. //Convert.ToDouble(decimal.Parse(dt.Compute("sum(e3)", "").ToString()));
  421. dr3["e4"] = Math.Round((Convert.ToDouble(dt.Rows[0]["e3"]) / totalInclusionArea2) * 100, 2);
  422. dr3["e5"] = Math.Round((Convert.ToDouble(dt.Rows[0]["e3"]) / Convert.ToDouble(str_SCZS)) * 100, 4);
  423. AllAnalysisDetails1.Rows.Add(dr3);
  424. }
  425. }
  426. return AllAnalysisDetails1;
  427. }
  428. /// <summary>
  429. /// 获取颗粒成分数据
  430. /// </summary>
  431. private Chartdate GetPComponentData(string path)
  432. {
  433. DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path);
  434. //创建新的图形数据源
  435. Chartdate chart = new Chartdate();
  436. chart.Title = m_ReportApp.m_reportname;
  437. chart.YName = m_str_AxisY;
  438. //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  439. //int sel = m_ReportApp.SourceGridData.ConditionItemList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString());
  440. //int sel = m_conditionChoose.m_SourceGridData.GetPropIndexByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  441. int sel = m_ReportApp.m_conditionChoose.m_SourceGridData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  442. string filedAndParticl = "";
  443. if (sel == 1)
  444. {
  445. List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.GetSelectedParticles();
  446. foreach (var item in selectParticles)
  447. {
  448. filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
  449. }
  450. if (filedAndParticl != "")
  451. {
  452. filedAndParticl = filedAndParticl + ",";
  453. }
  454. }
  455. DataTable dt = particledata.GetParticleListForParticlSize("area", filedAndParticl);
  456. //设置标签名称
  457. List<string> listName = new List<string>();
  458. //ListName
  459. for (int i = 0; i < dt.Rows.Count; i++)
  460. {
  461. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) < 100)
  462. {
  463. continue;
  464. }
  465. listName.Add(dt.Rows[i]["TypeName"].ToString());
  466. }
  467. for (int i = 0; i < dt.Rows.Count; i++)
  468. {
  469. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 100)
  470. {
  471. continue;
  472. }
  473. int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[i]["TypeId"]));
  474. if (index == -1)
  475. {
  476. index = 7;
  477. }
  478. string name = NameList[index];
  479. if (listName.IndexOf(name) == -1)
  480. {
  481. listName.Add(name);
  482. }
  483. }
  484. chart.ListName = listName;
  485. //设置数据
  486. List<Item> listData = new List<Item>();
  487. //ListData
  488. for (int k = 0; k < dt.Rows.Count; k++)
  489. {
  490. string str = dt.Rows[k]["con"].ToString();
  491. string name = dt.Rows[k]["TypeName"].ToString();
  492. if (Convert.ToInt32(dt.Rows[k]["TypeId"]) < 100)
  493. {
  494. int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[k]["TypeId"]));
  495. if (index == -1)
  496. {
  497. index = 7;
  498. }
  499. name = NameList[index];
  500. }
  501. Item item = new Item()
  502. {
  503. value = decimal.Round(decimal.Parse(str), 2).ToString(),
  504. name = name
  505. };
  506. listData.Add(item);
  507. }
  508. chart.ListData = listData;
  509. return chart;
  510. }
  511. /// <summary>
  512. /// 获取元素成分数据
  513. /// </summary>
  514. private Chartdate GetEComponentData(string path)
  515. {
  516. DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path);
  517. //创建新的图形数据源
  518. Chartdate chart = new Chartdate();
  519. chart.Title = m_ReportApp.m_reportname;
  520. chart.YName = m_str_AxisY;
  521. //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  522. //int sel = m_ReportApp.SourceGridData.ConditionItemList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString());
  523. //int sel = m_conditionChoose.m_SourceGridData.GetPropIndexByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  524. int sel = m_ReportApp.m_conditionChoose.m_SourceGridData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  525. string filedAndParticl = "";
  526. if (sel == 1)
  527. {
  528. List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.GetSelectedParticles();
  529. foreach (var item in selectParticles)
  530. {
  531. filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
  532. }
  533. if (filedAndParticl != "")
  534. {
  535. filedAndParticl = filedAndParticl + ",";
  536. }
  537. }
  538. DataTable dt = particledata.GetElementForArea(filedAndParticl);
  539. //设置标签名称
  540. List<string> listName = new List<string>();
  541. //ListName
  542. for (int i = 0; i < dt.Rows.Count; i++)
  543. {
  544. listName.Add(dt.Rows[i]["name"].ToString());
  545. }
  546. chart.ListName = listName;
  547. //设置数据
  548. List<Item> listData = new List<Item>();
  549. //ListData
  550. for (int k = 0; k < dt.Rows.Count; k++)
  551. {
  552. string str = dt.Rows[k]["earea"].ToString();
  553. try
  554. {
  555. Item item = new Item()
  556. {
  557. value = decimal.Round(decimal.Parse(str), 2).ToString(),
  558. name = dt.Rows[k]["name"].ToString()
  559. };
  560. listData.Add(item);
  561. }
  562. catch
  563. {
  564. Item item = new Item()
  565. {
  566. value = str,
  567. name = dt.Rows[k]["name"].ToString()
  568. };
  569. listData.Add(item);
  570. }
  571. }
  572. chart.ListData = listData;
  573. return chart;
  574. }
  575. /// <summary>
  576. /// 获取此尺寸分布图数据
  577. /// </summary>
  578. private Chartdate GetPSizeData(string path)
  579. {
  580. DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path);
  581. //创建新的图形数据源
  582. Chartdate chart = new Chartdate();
  583. chart.Title = m_ReportApp.m_reportname;
  584. chart.YName = m_str_AxisY;
  585. //设置标签名称
  586. List<string> listName = new List<string>();
  587. //获取粒级表
  588. string pathe = m_ReportApp.m_rstDataMgr.m_RptConfigFile.FileFolderSize + m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile;
  589. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(pathe);
  590. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  591. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  592. {
  593. if (sizestr.Split(',')[i].Length > 0)
  594. {
  595. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  596. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  597. listName.Add(d1.ToString() + "~" + d2.ToString());
  598. }
  599. }
  600. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  601. listName.Add(d.ToString() + "~MAX");
  602. chart.ListName = listName;
  603. //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  604. //int sel = m_ReportApp.SourceGridData.ConditionItemList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString());
  605. //int sel = m_conditionChoose.m_SourceGridData.GetPropIndexByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  606. int sel = m_ReportApp.m_conditionChoose.m_SourceGridData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  607. string filedAndParticl = "";
  608. if (sel == 1)
  609. {
  610. List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.GetSelectedParticles();
  611. foreach (var item in selectParticles)
  612. {
  613. filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
  614. }
  615. if (filedAndParticl != "")
  616. {
  617. filedAndParticl = filedAndParticl + ",";
  618. }
  619. }
  620. //idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE);
  621. //string con = m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString();
  622. string con = m_conditionChoose.m_SourceGridData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE).ToString();
  623. string po = "";
  624. switch (con)
  625. {
  626. case "DMAX":
  627. po = "DMAX";
  628. break;
  629. case "DMIN":
  630. po = "DMIN";
  631. break;
  632. case "CIRCLE":
  633. po = "Area";
  634. break;
  635. case "FERET":
  636. po = "DFERET";
  637. break;
  638. }
  639. DataTable dtp = particledata.GetParticleAll(filedAndParticl);
  640. //设置数据
  641. List<Item> listData = new List<Item>();
  642. //ListData
  643. for (int k = 0; k < listName.Count; k++)
  644. {
  645. string str = listName[k];
  646. string d1 = str.Split('~')[0];
  647. string d2 = str.Split('~')[1];
  648. if (d2 == "MAX")
  649. {
  650. d2 = "999";
  651. }
  652. DataRow[] datas = dtp.Select(getWhere(d2, d1, po));
  653. Item item = new Item()
  654. {
  655. value = datas.Count().ToString(),
  656. name = str
  657. };
  658. listData.Add(item);
  659. }
  660. chart.ListData = listData;
  661. return chart;
  662. }
  663. private string getWhere(string max, string min, string col)
  664. {
  665. return col + ">=" + min + " and " + col + "<=" + max;
  666. }
  667. #endregion
  668. #region echarts
  669. /// <summary>
  670. /// 通过m_list_chartstruct,组合json数据格式
  671. /// </summary>
  672. /// <returns></returns>
  673. private List<Chartdate> GetListJsonStrByChartStruct()
  674. {
  675. List<Chartdate> list = new List<Chartdate>();
  676. Chartdate chartdate = new Chartdate();
  677. switch (ComSel)
  678. {
  679. case "CommonlyUsedClassify":
  680. //chartdate = GetCommonlyUsedClassifyData(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath);
  681. chartdate = GetInclusionAreaRatioClassData(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath);
  682. break;
  683. case "PComponent":
  684. chartdate = GetPComponentData(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath);
  685. break;
  686. case "EComponent":
  687. chartdate = GetEComponentData(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath);
  688. break;
  689. case "PSize":
  690. chartdate = GetPSizeData(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath);
  691. break;
  692. case "InclusionareaRatio":
  693. chartdate = GetInclusionAreaRatioData(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath);
  694. break;
  695. case "InclusionareaClassRatio":
  696. chartdate=GetInclusionAreaRatioClassData(m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].FilePath);
  697. break;
  698. }
  699. list.Add(chartdate);
  700. return list;
  701. }
  702. /// <summary>
  703. /// 通过m_list_chartstruct,组合json数据格式
  704. /// </summary>
  705. /// <returns></returns>
  706. private ChartdateMore GetListJsonStr()
  707. {
  708. //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  709. //int sel = m_ReportApp.SourceGridData.ConditionItemList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString());
  710. int sel = m_conditionChoose.m_SourceGridData.GetPropIndexByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  711. string filedAndParticl = "";
  712. if (sel == 1)
  713. {
  714. List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.GetSelectedParticles();
  715. foreach (var item in selectParticles)
  716. {
  717. filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
  718. }
  719. if (filedAndParticl != "")
  720. {
  721. filedAndParticl = filedAndParticl + ",";
  722. }
  723. }
  724. DataOperation.DataAccess.ParticleData particledata = null;
  725. DataTable dt = new DataTable();
  726. ChartdateMore chart = new ChartdateMore();
  727. chart.Title = m_ReportApp.m_reportname;
  728. chart.YName = m_str_AxisY;
  729. List<string> listName = new List<string>();
  730. List<string> soursName = new List<string>();
  731. List<List<Item>> listDataMore = new List<List<Item>>();
  732. //idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  733. //string sou = m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString();
  734. string sou = m_conditionChoose.m_SourceGridData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  735. if (sou.Contains("+"))
  736. {
  737. for (int i = 0; i < sou.Split('+').Length; i++)
  738. {
  739. DataOperation.Model.ResultFile resultFile = m_DataMgr.ResultFilesList.Find(s => s.FileName == sou.Split('+')[i]);
  740. if (resultFile == null)
  741. {
  742. continue;
  743. }
  744. soursName.Add(resultFile.FileName);
  745. particledata = new DataOperation.DataAccess.ParticleData(resultFile.FilePath);
  746. switch (ComSel)
  747. {
  748. case "CommonlyUsedClassify":
  749. break;
  750. case "PComponent":
  751. //创建新的图形数据源
  752. dt = particledata.GetParticleListByIncA("area");
  753. //设置标签名称
  754. for (int j = 0; j < dt.Rows.Count; j++)
  755. {
  756. if (Convert.ToInt32(dt.Rows[j]["TypeId"]) < 100)
  757. {
  758. continue;
  759. }
  760. string name = dt.Rows[j]["TypeName"].ToString();
  761. if (!listName.Contains(name))
  762. {
  763. listName.Add(name);
  764. }
  765. }
  766. for (int j = 0; j < dt.Rows.Count; j++)
  767. {
  768. if (Convert.ToInt32(dt.Rows[j]["TypeId"]) > 100)
  769. {
  770. continue;
  771. }
  772. int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[j]["TypeId"]));
  773. if (index == -1)
  774. {
  775. index = 7;
  776. }
  777. string name = NameList[index];
  778. if (!listName.Contains(name))
  779. {
  780. listName.Add(name);
  781. }
  782. }
  783. //设置数据
  784. List<Item> listData = new List<Item>();
  785. //ListData
  786. for (int k = 0; k < dt.Rows.Count; k++)
  787. {
  788. string str = dt.Rows[k]["con"].ToString();
  789. string name = dt.Rows[k]["TypeName"].ToString();
  790. if (Convert.ToInt32(dt.Rows[k]["TypeId"]) < 100)
  791. {
  792. int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[k]["TypeId"]));
  793. name = NameList[index];
  794. }
  795. Item item = new Item()
  796. {
  797. value = decimal.Round(decimal.Parse(str), 2).ToString(),
  798. name = name
  799. };
  800. listData.Add(item);
  801. }
  802. listDataMore.Add(listData);
  803. break;
  804. case "EComponent":
  805. //创建新的图形数据源
  806. dt = particledata.GetElementForArea(filedAndParticl);
  807. //ListName
  808. for (int j = 0; j < dt.Rows.Count; j++)
  809. {
  810. string name = dt.Rows[j]["name"].ToString();
  811. if (!listName.Contains(name))
  812. {
  813. listName.Add(name);
  814. }
  815. }
  816. //设置数据
  817. List<Item> listData1 = new List<Item>();
  818. //ListData
  819. for (int k = 0; k < dt.Rows.Count; k++)
  820. {
  821. string str = dt.Rows[k]["earea"].ToString();
  822. try
  823. {
  824. Item item = new Item()
  825. {
  826. value = decimal.Round(decimal.Parse(str), 2).ToString(),
  827. name = dt.Rows[k]["name"].ToString()
  828. };
  829. listData1.Add(item);
  830. }
  831. catch
  832. {
  833. Item item = new Item()
  834. {
  835. value = str,
  836. name = dt.Rows[k]["name"].ToString()
  837. };
  838. listData1.Add(item);
  839. }
  840. }
  841. listDataMore.Add(listData1);
  842. break;
  843. case "PSize":
  844. //获取粒级表
  845. string pathe = m_DataMgr.m_RptConfigFile.FileFolderSize + m_DataMgr.m_RptConfigFile.PartSizeFile;
  846. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(pathe);
  847. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  848. List<string> temp = new List<string>();
  849. for (int j = 0; j < sizestr.Split(',').Length - 1; j++)
  850. {
  851. if (sizestr.Split(',')[j].Length > 0)
  852. {
  853. double d1 = Convert.ToDouble(sizestr.Split(',')[j]);
  854. double d2 = Convert.ToDouble(sizestr.Split(',')[j + 1]);
  855. string name = d1.ToString() + "~" + d2.ToString();
  856. temp.Add(name);
  857. if (!listName.Contains(name))
  858. {
  859. listName.Add(name);
  860. }
  861. }
  862. }
  863. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  864. string name1 = d.ToString() + "~MAX";
  865. temp.Add(name1);
  866. if (!listName.Contains(name1))
  867. {
  868. listName.Add(name1);
  869. }
  870. //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();
  871. string con = m_conditionChoose.m_SourceGridData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE).ToString();
  872. string po = "";
  873. switch (con)
  874. {
  875. case "DMAX":
  876. po = "DMAX";
  877. break;
  878. case "DMIN":
  879. po = "DMIN";
  880. break;
  881. case "Area":
  882. po = "Area";
  883. break;
  884. case "FERET":
  885. po = "DFERET";
  886. break;
  887. }
  888. DataTable dtp = particledata.GetParticleAll(filedAndParticl);
  889. //设置数据
  890. List<Item> listData2 = new List<Item>();
  891. //ListData
  892. for (int k = 0; k < temp.Count; k++)
  893. {
  894. string str = temp[k];
  895. string d1 = str.Split('~')[0];
  896. string d2 = str.Split('~')[1];
  897. if (d2 == "MAX")
  898. {
  899. d2 = "999";
  900. }
  901. DataRow[] datas = dtp.Select(getWhere(d2, d1, po));
  902. Item item = new Item()
  903. {
  904. value = datas.Count().ToString(),
  905. name = str
  906. };
  907. listData2.Add(item);
  908. }
  909. listDataMore.Add(listData2);
  910. break;
  911. }
  912. }
  913. }
  914. chart.ListName = listName;
  915. chart.SoursName = soursName;
  916. chart.ListData = listDataMore;
  917. return chart;
  918. }
  919. class Chartdate
  920. {
  921. public string Title { get; set; }
  922. public string YName { get; set; }
  923. public List<string> ListName { get; set; }
  924. public List<Item> ListData { get; set; }
  925. }
  926. class ChartdateMore
  927. {
  928. public string Title { get; set; }
  929. public string YName { get; set; }
  930. public List<string> ListName { get; set; }
  931. public List<string> SoursName { get; set; }
  932. public List<List<Item>> ListData { get; set; }
  933. }
  934. class Item
  935. {
  936. public string value { get; set; }
  937. public string name { get; set; }
  938. }
  939. //获取图片
  940. private void button1_Click(object sender, EventArgs e)
  941. {
  942. string str = GetPic();
  943. pic = str;
  944. //保存目录
  945. string dir = Path.Combine(Directory.GetCurrentDirectory(), "Resources/HTML/pic");
  946. //文件名称
  947. string fileName = "headdemo" + DateTime.Now.ToString("yyyyMMddHHmmssff");
  948. //保存文件所在站点位置
  949. string filePath = Path.Combine(dir, fileName);
  950. if (!System.IO.Directory.Exists(dir))
  951. System.IO.Directory.CreateDirectory(dir);
  952. //将Base64String转为图片并保存
  953. byte[] arr2 = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  954. using (MemoryStream ms2 = new MemoryStream(arr2))
  955. {
  956. System.Drawing.Bitmap bmp2 = new System.Drawing.Bitmap(ms2);
  957. bmp2.Save(filePath + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
  958. }
  959. }
  960. /// <summary>
  961. /// 加载浏览器
  962. /// </summary>
  963. public void InitBrowser()
  964. {
  965. //加载网页
  966. if (m_ReportApp.browser == null || m_ReportApp.trans)
  967. {
  968. // 获取生成路径下网页文件的绝对路径
  969. string fileName = Path.Combine(Directory.GetCurrentDirectory(), url);
  970. //加载网页
  971. m_ReportApp.browser = new ChromiumWebBrowser(fileName);
  972. //禁止网页
  973. m_ReportApp.browser.MenuHandler = new MenuHandler();
  974. m_ReportApp.browser.Dock = DockStyle.Fill;
  975. m_ReportApp.js.MessageText = "";
  976. //添加网页到当前自定义控件
  977. this.Controls.Add(m_ReportApp.browser);
  978. //供页面调用以传递数据
  979. m_ReportApp.browser.RegisterJsObject("jsObj", m_ReportApp.js, false);
  980. //升级cef版本后新方法
  981. //CefSharpSettings.LegacyJavascriptBindingEnabled = true;
  982. //CefSharpSettings.WcfEnabled = true;
  983. //m_ReportApp.browser.JavascriptObjectRepository.Register("jsObj", m_ReportApp.js, isAsync: false, options: BindingOptions.DefaultBinder);
  984. //网页加载结束后调用事件
  985. m_ReportApp.browser.FrameLoadEnd += WebBrowser_FrameLoadEnd;
  986. }
  987. else
  988. {
  989. m_ReportApp.browser.ResetText();
  990. m_ReportApp.browser.Reload();
  991. m_ReportApp.browser.Refresh();
  992. //供页面调用以传递数据
  993. this.Controls.Add(m_ReportApp.browser);
  994. }
  995. if (m_ReportApp.timerKG)
  996. {
  997. timer1.Enabled = true;
  998. }
  999. }
  1000. /// <summary>
  1001. /// 页面加载结束后事件
  1002. /// </summary>
  1003. /// <param name="sender"></param>
  1004. /// <param name="e"></param>
  1005. private void WebBrowser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
  1006. {
  1007. if (e.Frame.IsMain)
  1008. {
  1009. //为页面图形提供数据参数
  1010. string str = m_ReportApp.data;
  1011. //执行网页脚本事件
  1012. m_ReportApp.browser.ExecuteScriptAsync("showchart('" + str + "','" + m_ReportApp.type + "')");
  1013. }
  1014. }
  1015. public string GetPic()
  1016. {
  1017. return js.MessageText;
  1018. }
  1019. //禁止网页操作,右键点击等
  1020. class MenuHandler : CefSharp.IContextMenuHandler
  1021. {
  1022. void CefSharp.IContextMenuHandler.OnBeforeContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model)
  1023. {
  1024. model.Clear();
  1025. }
  1026. bool CefSharp.IContextMenuHandler.OnContextMenuCommand(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.CefMenuCommand commandId, CefSharp.CefEventFlags eventFlags)
  1027. {
  1028. //throw new NotImplementedException();
  1029. return false;
  1030. }
  1031. void CefSharp.IContextMenuHandler.OnContextMenuDismissed(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame)
  1032. {
  1033. //throw new NotImplementedException();
  1034. }
  1035. bool CefSharp.IContextMenuHandler.RunContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model, CefSharp.IRunContextMenuCallback callback)
  1036. {
  1037. return false;
  1038. }
  1039. }
  1040. class JsEvent
  1041. {
  1042. public string MessageText { set; get; }
  1043. public void ShowTest()
  1044. {
  1045. MessageBox.Show(MessageText);
  1046. }
  1047. }
  1048. #endregion
  1049. #region EChart导出图像委托调用部份
  1050. public delegate void MyDelgate(string va);
  1051. public event MyDelgate butclic;
  1052. private void timer1_Tick(object sender, EventArgs e)
  1053. {
  1054. if (butclic == null)
  1055. return;
  1056. if (m_ReportApp.js == null)
  1057. return;
  1058. if (m_ReportApp.js.MessageText == null)
  1059. return;
  1060. if (m_ReportApp.js.MessageText != "")
  1061. {
  1062. butclic(m_ReportApp.js.MessageText);
  1063. timer1.Enabled = false;
  1064. m_ReportApp.timerKG = false;
  1065. }
  1066. }
  1067. #endregion
  1068. }
  1069. }