EChart_ParticlesComposition.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. using CefSharp;
  2. using CefSharp.WinForms;
  3. using Newtonsoft.Json;
  4. using OTSIncAReportApp.SysMgrTools;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Windows.Forms;
  12. namespace OTSIncAReportApp.Control_ECharts
  13. {
  14. /// <summary>
  15. /// 各图char相关模块
  16. /// </summary>
  17. public partial class EChart_ParticlesComposition : UserControl
  18. {
  19. #region 图表相关变量
  20. //y轴名称
  21. public string m_str_AxisY { get; set; }
  22. //定义图片
  23. JsEvent js;
  24. //定义图片base64
  25. public string pic { get; set; }
  26. //定义图形类型
  27. public string type { get; set; }
  28. //图形数据
  29. public string data { get; set; }
  30. string url = "Resources/HTML/charts.html";
  31. //数据图类型:常用夹杂物分类CommonlyUsedClassify ,颗粒成分PComponent,元素成分EComponent,颗粒尺寸分布PSize
  32. string ComSel { get; set; }
  33. frmReportApp m_ReportApp;
  34. List<int> FLID = new List<int>() { 0, 1, 2, 4, 6, 7, 8, 9 };
  35. List<string> NameList = new List<string>() { "过小颗粒", "过大颗粒", "亮度不在分析范围内的颗粒", "低计数率颗粒", "不含分析元素的颗粒", "非夹杂物颗粒SiC", "非夹杂物颗粒FeO", "未识别颗粒" };
  36. #endregion
  37. #region 窗体加载及构造函数
  38. public EChart_ParticlesComposition(frmReportApp ReportApp, string comsel)
  39. {
  40. ComSel = comsel;
  41. m_ReportApp = ReportApp;
  42. InitializeComponent();
  43. }
  44. private void EChart_ParticlesComposition_Load(object sender, EventArgs e)
  45. {
  46. //国际化
  47. Language lan = new Language();
  48. Hashtable table = lan.GetNameTable("CompositionDistributionGrid");
  49. 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() };
  50. int idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  51. string sou = m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString();
  52. if (sou.Contains("+"))
  53. {
  54. if (m_ReportApp.more)
  55. {
  56. m_ReportApp.trans = false;
  57. }
  58. else
  59. {
  60. m_ReportApp.trans = true;
  61. }
  62. m_ReportApp.more = true;
  63. //获取到List,json的字符串
  64. ChartdateMore list_json_str = GetListJsonStr();
  65. url = "Resources/HTML/chartsMore.html";
  66. m_ReportApp.data = JsonConvert.SerializeObject(list_json_str);
  67. }
  68. else
  69. {
  70. if (!m_ReportApp.more)
  71. {
  72. m_ReportApp.trans = false;
  73. }
  74. else
  75. {
  76. m_ReportApp.trans = true;
  77. }
  78. m_ReportApp.more = false;
  79. //获取到List,json的字符串
  80. List<Chartdate> list_json_str = GetListJsonStrByChartStruct();
  81. url = "Resources/HTML/charts.html";
  82. m_ReportApp.data = JsonConvert.SerializeObject(list_json_str[0]);
  83. }
  84. InitBrowser();
  85. }
  86. #endregion
  87. #region 获取单数据源
  88. private Chartdate GetCommonlyUsedClassifyData(string path)
  89. {
  90. DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path);
  91. //创建新的图形数据源
  92. Chartdate chart = new Chartdate();
  93. chart.Title = m_ReportApp.m_reportname;
  94. chart.YName = m_str_AxisY;
  95. int idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  96. int sel = m_ReportApp.SourceGridData.SampleDataList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString());
  97. string filedAndParticl = "";
  98. if (sel == 1)
  99. {
  100. List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.SelectedParticles;
  101. foreach (var item in selectParticles)
  102. {
  103. filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
  104. }
  105. if (filedAndParticl != "")
  106. {
  107. filedAndParticl = filedAndParticl + ",";
  108. }
  109. }
  110. DataTable dt = particledata.GetCommonlyUsedClassifyData();
  111. //设置标签名称
  112. List<string> listName = new List<string>();
  113. listName.Add("尖晶石");
  114. listName.Add("氧化物");
  115. listName.Add("硫氧化物");
  116. listName.Add("氮化物");
  117. listName.Add("硫化物");
  118. chart.ListName = listName;
  119. //设置数据
  120. List<Item> listData = new List<Item>();
  121. //ListData
  122. for (int k = 0; k < dt.Rows.Count; k++)
  123. {
  124. try
  125. {
  126. Item item_SPINEL = new Item()
  127. {
  128. value = decimal.Round(decimal.Parse(dt.Rows[k]["SPINEL"].ToString()), 2).ToString(),
  129. name = "尖晶石"
  130. };
  131. listData.Add(item_SPINEL);
  132. Item item_OXIDE = new Item()
  133. {
  134. value = decimal.Round(decimal.Parse(dt.Rows[k]["OXIDE"].ToString()), 2).ToString(),
  135. name = "氧化物"
  136. };
  137. listData.Add(item_OXIDE);
  138. Item item_SULFIDE_OXIDE = new Item()
  139. {
  140. value = decimal.Round(decimal.Parse(dt.Rows[k]["SULFIDE_OXIDE"].ToString()), 2).ToString(),
  141. name = "硫氧化物"
  142. };
  143. listData.Add(item_SULFIDE_OXIDE);
  144. Item item_NITRIDE = new Item()
  145. {
  146. value = decimal.Round(decimal.Parse(dt.Rows[k]["NITRIDE"].ToString()), 2).ToString(),
  147. name = "氮化物"
  148. };
  149. listData.Add(item_NITRIDE);
  150. Item item_SULFIDE = new Item()
  151. {
  152. value = decimal.Round(decimal.Parse(dt.Rows[k]["SULFIDE"].ToString()), 2).ToString(),
  153. name = "硫化物"
  154. };
  155. listData.Add(item_SULFIDE);
  156. }
  157. catch
  158. {
  159. Item item = new Item()
  160. {
  161. value = "",
  162. name = ""
  163. };
  164. listData.Add(item);
  165. }
  166. }
  167. chart.ListData = listData;
  168. return chart;
  169. }
  170. /// <summary>
  171. /// 获取颗粒成分数据
  172. /// </summary>
  173. private Chartdate GetPComponentData(string path)
  174. {
  175. DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path);
  176. //创建新的图形数据源
  177. Chartdate chart = new Chartdate();
  178. chart.Title = m_ReportApp.m_reportname;
  179. chart.YName = m_str_AxisY;
  180. int idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  181. int sel = m_ReportApp.SourceGridData.SampleDataList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString());
  182. string filedAndParticl = "";
  183. if (sel == 1)
  184. {
  185. List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.SelectedParticles;
  186. foreach (var item in selectParticles)
  187. {
  188. filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
  189. }
  190. if (filedAndParticl != "")
  191. {
  192. filedAndParticl = filedAndParticl + ",";
  193. }
  194. }
  195. DataTable dt = particledata.GetParticleListByIncA("area", filedAndParticl);
  196. //设置标签名称
  197. List<string> listName = new List<string>();
  198. //ListName
  199. for (int i = 0; i < dt.Rows.Count; i++)
  200. {
  201. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) < 100)
  202. {
  203. continue;
  204. }
  205. listName.Add(dt.Rows[i]["TypeName"].ToString());
  206. }
  207. for (int i = 0; i < dt.Rows.Count; i++)
  208. {
  209. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 100)
  210. {
  211. continue;
  212. }
  213. int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[i]["TypeId"]));
  214. if (index == -1)
  215. {
  216. index = 7;
  217. }
  218. string name = NameList[index];
  219. if (listName.IndexOf(name) == -1)
  220. {
  221. listName.Add(name);
  222. }
  223. }
  224. chart.ListName = listName;
  225. //设置数据
  226. List<Item> listData = new List<Item>();
  227. //ListData
  228. for (int k = 0; k < dt.Rows.Count; k++)
  229. {
  230. string str = dt.Rows[k]["con"].ToString();
  231. string name = dt.Rows[k]["TypeName"].ToString();
  232. if (Convert.ToInt32(dt.Rows[k]["TypeId"]) < 100)
  233. {
  234. int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[k]["TypeId"]));
  235. if (index == -1)
  236. {
  237. index = 7;
  238. }
  239. name = NameList[index];
  240. }
  241. Item item = new Item()
  242. {
  243. value = decimal.Round(decimal.Parse(str), 2).ToString(),
  244. name = name
  245. };
  246. listData.Add(item);
  247. }
  248. chart.ListData = listData;
  249. return chart;
  250. }
  251. /// <summary>
  252. /// 获取元素成分数据
  253. /// </summary>
  254. private Chartdate GetEComponentData(string path)
  255. {
  256. DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path);
  257. //创建新的图形数据源
  258. Chartdate chart = new Chartdate();
  259. chart.Title = m_ReportApp.m_reportname;
  260. chart.YName = m_str_AxisY;
  261. int idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  262. int sel = m_ReportApp.SourceGridData.SampleDataList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString());
  263. string filedAndParticl = "";
  264. if (sel == 1)
  265. {
  266. List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.SelectedParticles;
  267. foreach (var item in selectParticles)
  268. {
  269. filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
  270. }
  271. if (filedAndParticl != "")
  272. {
  273. filedAndParticl = filedAndParticl + ",";
  274. }
  275. }
  276. DataTable dt = particledata.GetElementForArea(filedAndParticl);
  277. //设置标签名称
  278. List<string> listName = new List<string>();
  279. //ListName
  280. for (int i = 0; i < dt.Rows.Count; i++)
  281. {
  282. listName.Add(dt.Rows[i]["name"].ToString());
  283. }
  284. chart.ListName = listName;
  285. //设置数据
  286. List<Item> listData = new List<Item>();
  287. //ListData
  288. for (int k = 0; k < dt.Rows.Count; k++)
  289. {
  290. string str = dt.Rows[k]["earea"].ToString();
  291. try
  292. {
  293. Item item = new Item()
  294. {
  295. value = decimal.Round(decimal.Parse(str), 2).ToString(),
  296. name = dt.Rows[k]["name"].ToString()
  297. };
  298. listData.Add(item);
  299. }
  300. catch
  301. {
  302. Item item = new Item()
  303. {
  304. value = str,
  305. name = dt.Rows[k]["name"].ToString()
  306. };
  307. listData.Add(item);
  308. }
  309. }
  310. chart.ListData = listData;
  311. return chart;
  312. }
  313. /// <summary>
  314. /// 获取此尺寸分布图数据
  315. /// </summary>
  316. private Chartdate GetPSizeData(string path)
  317. {
  318. DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path);
  319. //创建新的图形数据源
  320. Chartdate chart = new Chartdate();
  321. chart.Title = m_ReportApp.m_reportname;
  322. chart.YName = m_str_AxisY;
  323. //设置标签名称
  324. List<string> listName = new List<string>();
  325. //获取粒级表
  326. string pathe = m_ReportApp.m_RptConfigFile.FileFolderSize + m_ReportApp.m_RptConfigFile.PartSizeFile;
  327. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(pathe);
  328. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  329. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  330. {
  331. if (sizestr.Split(',')[i].Length > 0)
  332. {
  333. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  334. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  335. listName.Add(d1.ToString() + "~" + d2.ToString());
  336. }
  337. }
  338. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  339. listName.Add(d.ToString() + "~MAX");
  340. chart.ListName = listName;
  341. int idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  342. int sel = m_ReportApp.SourceGridData.SampleDataList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString());
  343. string filedAndParticl = "";
  344. if (sel == 1)
  345. {
  346. List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.SelectedParticles;
  347. foreach (var item in selectParticles)
  348. {
  349. filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
  350. }
  351. if (filedAndParticl != "")
  352. {
  353. filedAndParticl = filedAndParticl + ",";
  354. }
  355. }
  356. idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE);
  357. string con = m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString();
  358. string po = "";
  359. switch (con)
  360. {
  361. case "DMAX":
  362. po = "DMAX";
  363. break;
  364. case "DMIN":
  365. po = "DMIN";
  366. break;
  367. case "Area":
  368. po = "Area";
  369. break;
  370. case "FERET":
  371. po = "DFERET";
  372. break;
  373. }
  374. DataTable dtp = particledata.GetParticleAll(filedAndParticl);
  375. //设置数据
  376. List<Item> listData = new List<Item>();
  377. //ListData
  378. for (int k = 0; k < listName.Count; k++)
  379. {
  380. string str = listName[k];
  381. string d1 = str.Split('~')[0];
  382. string d2 = str.Split('~')[1];
  383. if (d2 == "MAX")
  384. {
  385. d2 = "999";
  386. }
  387. DataRow[] datas = dtp.Select(getWhere(d2, d1, po));
  388. Item item = new Item()
  389. {
  390. value = datas.Count().ToString(),
  391. name = str
  392. };
  393. listData.Add(item);
  394. }
  395. chart.ListData = listData;
  396. return chart;
  397. }
  398. private string getWhere(string max, string min, string col)
  399. {
  400. return col + ">=" + min + " and " + col + "<=" + max;
  401. }
  402. #endregion
  403. #region echarts
  404. /// <summary>
  405. /// 通过m_list_chartstruct,组合json数据格式
  406. /// </summary>
  407. /// <returns></returns>
  408. private List<Chartdate> GetListJsonStrByChartStruct()
  409. {
  410. List<Chartdate> list = new List<Chartdate>();
  411. Chartdate chartdate = new Chartdate();
  412. switch (ComSel)
  413. {
  414. case "CommonlyUsedClassify":
  415. chartdate = GetCommonlyUsedClassifyData(m_ReportApp.resultFilesList[m_ReportApp.WorkingResult].FilePath);
  416. break;
  417. case "PComponent":
  418. chartdate = GetPComponentData(m_ReportApp.resultFilesList[m_ReportApp.WorkingResult].FilePath);
  419. break;
  420. case "EComponent":
  421. chartdate = GetEComponentData(m_ReportApp.resultFilesList[m_ReportApp.WorkingResult].FilePath);
  422. break;
  423. case "PSize":
  424. chartdate = GetPSizeData(m_ReportApp.resultFilesList[m_ReportApp.WorkingResult].FilePath);
  425. break;
  426. }
  427. list.Add(chartdate);
  428. return list;
  429. }
  430. /// <summary>
  431. /// 通过m_list_chartstruct,组合json数据格式
  432. /// </summary>
  433. /// <returns></returns>
  434. private ChartdateMore GetListJsonStr()
  435. {
  436. int idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  437. int sel = m_ReportApp.SourceGridData.SampleDataList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString());
  438. string filedAndParticl = "";
  439. if (sel == 1)
  440. {
  441. List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.SelectedParticles;
  442. foreach (var item in selectParticles)
  443. {
  444. filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
  445. }
  446. if (filedAndParticl != "")
  447. {
  448. filedAndParticl = filedAndParticl + ",";
  449. }
  450. }
  451. DataOperation.DataAccess.ParticleData particledata = null;
  452. DataTable dt = new DataTable();
  453. ChartdateMore chart = new ChartdateMore();
  454. chart.Title = m_ReportApp.m_reportname;
  455. chart.YName = m_str_AxisY;
  456. List<string> listName = new List<string>();
  457. List<string> soursName = new List<string>();
  458. List<List<Item>> listDataMore = new List<List<Item>>();
  459. idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  460. string sou = m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString();
  461. if (sou.Contains("+"))
  462. {
  463. for (int i = 0; i < sou.Split('+').Length; i++)
  464. {
  465. DataOperation.Model.ResultFile resultFile = m_ReportApp.resultFilesList.Find(s => s.FileName == sou.Split('+')[i]);
  466. if (resultFile == null)
  467. {
  468. continue;
  469. }
  470. soursName.Add(resultFile.FileName);
  471. particledata = new DataOperation.DataAccess.ParticleData(resultFile.FilePath);
  472. switch (ComSel)
  473. {
  474. case "CommonlyUsedClassify":
  475. break;
  476. case "PComponent":
  477. //创建新的图形数据源
  478. dt = particledata.GetParticleListByIncA("area", filedAndParticl);
  479. //设置标签名称
  480. for (int j = 0; j < dt.Rows.Count; j++)
  481. {
  482. if (Convert.ToInt32(dt.Rows[j]["TypeId"]) < 100)
  483. {
  484. continue;
  485. }
  486. string name = dt.Rows[j]["TypeName"].ToString();
  487. if (!listName.Contains(name))
  488. {
  489. listName.Add(name);
  490. }
  491. }
  492. for (int j = 0; j < dt.Rows.Count; j++)
  493. {
  494. if (Convert.ToInt32(dt.Rows[j]["TypeId"]) > 100)
  495. {
  496. continue;
  497. }
  498. int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[j]["TypeId"]));
  499. if (index == -1)
  500. {
  501. index = 7;
  502. }
  503. string name = NameList[index];
  504. if (!listName.Contains(name))
  505. {
  506. listName.Add(name);
  507. }
  508. }
  509. //设置数据
  510. List<Item> listData = new List<Item>();
  511. //ListData
  512. for (int k = 0; k < dt.Rows.Count; k++)
  513. {
  514. string str = dt.Rows[k]["con"].ToString();
  515. string name = dt.Rows[k]["TypeName"].ToString();
  516. if (Convert.ToInt32(dt.Rows[k]["TypeId"]) < 100)
  517. {
  518. int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[k]["TypeId"]));
  519. name = NameList[index];
  520. }
  521. Item item = new Item()
  522. {
  523. value = decimal.Round(decimal.Parse(str), 2).ToString(),
  524. name = name
  525. };
  526. listData.Add(item);
  527. }
  528. listDataMore.Add(listData);
  529. break;
  530. case "EComponent":
  531. //创建新的图形数据源
  532. dt = particledata.GetElementForArea(filedAndParticl);
  533. //ListName
  534. for (int j = 0; j < dt.Rows.Count; j++)
  535. {
  536. string name = dt.Rows[j]["name"].ToString();
  537. if (!listName.Contains(name))
  538. {
  539. listName.Add(name);
  540. }
  541. }
  542. //设置数据
  543. List<Item> listData1 = new List<Item>();
  544. //ListData
  545. for (int k = 0; k < dt.Rows.Count; k++)
  546. {
  547. string str = dt.Rows[k]["earea"].ToString();
  548. try
  549. {
  550. Item item = new Item()
  551. {
  552. value = decimal.Round(decimal.Parse(str), 2).ToString(),
  553. name = dt.Rows[k]["name"].ToString()
  554. };
  555. listData1.Add(item);
  556. }
  557. catch
  558. {
  559. Item item = new Item()
  560. {
  561. value = str,
  562. name = dt.Rows[k]["name"].ToString()
  563. };
  564. listData1.Add(item);
  565. }
  566. }
  567. listDataMore.Add(listData1);
  568. break;
  569. case "PSize":
  570. //获取粒级表
  571. string pathe = m_ReportApp.m_RptConfigFile.FileFolderSize + m_ReportApp.m_RptConfigFile.PartSizeFile;
  572. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(pathe);
  573. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  574. List<string> temp = new List<string>();
  575. for (int j = 0; j < sizestr.Split(',').Length - 1; j++)
  576. {
  577. if (sizestr.Split(',')[j].Length > 0)
  578. {
  579. double d1 = Convert.ToDouble(sizestr.Split(',')[j]);
  580. double d2 = Convert.ToDouble(sizestr.Split(',')[j + 1]);
  581. string name = d1.ToString() + "~" + d2.ToString();
  582. temp.Add(name);
  583. if (!listName.Contains(name))
  584. {
  585. listName.Add(name);
  586. }
  587. }
  588. }
  589. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  590. string name1 = d.ToString() + "~MAX";
  591. temp.Add(name1);
  592. if (!listName.Contains(name1))
  593. {
  594. listName.Add(name1);
  595. }
  596. 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();
  597. string po = "";
  598. switch (con)
  599. {
  600. case "DMAX":
  601. po = "DMAX";
  602. break;
  603. case "DMIN":
  604. po = "DMIN";
  605. break;
  606. case "Area":
  607. po = "Area";
  608. break;
  609. case "FERET":
  610. po = "DFERET";
  611. break;
  612. }
  613. DataTable dtp = particledata.GetParticleAll(filedAndParticl);
  614. //设置数据
  615. List<Item> listData2 = new List<Item>();
  616. //ListData
  617. for (int k = 0; k < temp.Count; k++)
  618. {
  619. string str = temp[k];
  620. string d1 = str.Split('~')[0];
  621. string d2 = str.Split('~')[1];
  622. if (d2 == "MAX")
  623. {
  624. d2 = "999";
  625. }
  626. DataRow[] datas = dtp.Select(getWhere(d2, d1, po));
  627. Item item = new Item()
  628. {
  629. value = datas.Count().ToString(),
  630. name = str
  631. };
  632. listData2.Add(item);
  633. }
  634. listDataMore.Add(listData2);
  635. break;
  636. }
  637. }
  638. }
  639. chart.ListName = listName;
  640. chart.SoursName = soursName;
  641. chart.ListData = listDataMore;
  642. return chart;
  643. }
  644. class Chartdate
  645. {
  646. public string Title { get; set; }
  647. public string YName { get; set; }
  648. public List<string> ListName { get; set; }
  649. public List<Item> ListData { get; set; }
  650. }
  651. class ChartdateMore
  652. {
  653. public string Title { get; set; }
  654. public string YName { get; set; }
  655. public List<string> ListName { get; set; }
  656. public List<string> SoursName { get; set; }
  657. public List<List<Item>> ListData { get; set; }
  658. }
  659. class Item
  660. {
  661. public string value { get; set; }
  662. public string name { get; set; }
  663. }
  664. //获取图片
  665. private void button1_Click(object sender, EventArgs e)
  666. {
  667. string str = GetPic();
  668. pic = str;
  669. //保存目录
  670. string dir = Path.Combine(Directory.GetCurrentDirectory(), "Resources/HTML/pic");
  671. //文件名称
  672. string fileName = "headdemo" + DateTime.Now.ToString("yyyyMMddHHmmssff");
  673. //保存文件所在站点位置
  674. string filePath = Path.Combine(dir, fileName);
  675. if (!System.IO.Directory.Exists(dir))
  676. System.IO.Directory.CreateDirectory(dir);
  677. //将Base64String转为图片并保存
  678. byte[] arr2 = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  679. using (MemoryStream ms2 = new MemoryStream(arr2))
  680. {
  681. System.Drawing.Bitmap bmp2 = new System.Drawing.Bitmap(ms2);
  682. bmp2.Save(filePath + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
  683. }
  684. }
  685. /// <summary>
  686. /// 加载浏览器
  687. /// </summary>
  688. public void InitBrowser()
  689. {
  690. //加载网页
  691. if (m_ReportApp.browser == null || m_ReportApp.trans)
  692. {
  693. // 获取生成路径下网页文件的绝对路径
  694. string fileName = Path.Combine(Directory.GetCurrentDirectory(), url);
  695. //加载网页
  696. m_ReportApp.browser = new ChromiumWebBrowser(fileName);
  697. //禁止网页
  698. m_ReportApp.browser.MenuHandler = new MenuHandler();
  699. m_ReportApp.browser.Dock = DockStyle.Fill;
  700. m_ReportApp.js.MessageText = "";
  701. //添加网页到当前自定义控件
  702. this.Controls.Add(m_ReportApp.browser);
  703. //供页面调用以传递数据
  704. m_ReportApp.browser.RegisterJsObject("jsObj", m_ReportApp.js, false);
  705. //升级cef版本后新方法
  706. //CefSharpSettings.LegacyJavascriptBindingEnabled = true;
  707. //CefSharpSettings.WcfEnabled = true;
  708. //m_ReportApp.browser.JavascriptObjectRepository.Register("jsObj", m_ReportApp.js, isAsync: false, options: BindingOptions.DefaultBinder);
  709. //网页加载结束后调用事件
  710. m_ReportApp.browser.FrameLoadEnd += WebBrowser_FrameLoadEnd;
  711. }
  712. else
  713. {
  714. m_ReportApp.browser.ResetText();
  715. m_ReportApp.browser.Reload();
  716. m_ReportApp.browser.Refresh();
  717. //供页面调用以传递数据
  718. this.Controls.Add(m_ReportApp.browser);
  719. }
  720. if (m_ReportApp.timerKG)
  721. {
  722. timer1.Enabled = true;
  723. }
  724. }
  725. /// <summary>
  726. /// 页面加载结束后事件
  727. /// </summary>
  728. /// <param name="sender"></param>
  729. /// <param name="e"></param>
  730. private void WebBrowser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
  731. {
  732. if (e.Frame.IsMain)
  733. {
  734. //为页面图形提供数据参数
  735. string str = m_ReportApp.data;
  736. //执行网页脚本事件
  737. m_ReportApp.browser.ExecuteScriptAsync("showchart('" + str + "','" + m_ReportApp.type + "')");
  738. }
  739. }
  740. public string GetPic()
  741. {
  742. return js.MessageText;
  743. }
  744. //禁止网页操作,右键点击等
  745. class MenuHandler : CefSharp.IContextMenuHandler
  746. {
  747. void CefSharp.IContextMenuHandler.OnBeforeContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model)
  748. {
  749. model.Clear();
  750. }
  751. bool CefSharp.IContextMenuHandler.OnContextMenuCommand(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.CefMenuCommand commandId, CefSharp.CefEventFlags eventFlags)
  752. {
  753. //throw new NotImplementedException();
  754. return false;
  755. }
  756. void CefSharp.IContextMenuHandler.OnContextMenuDismissed(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame)
  757. {
  758. //throw new NotImplementedException();
  759. }
  760. bool CefSharp.IContextMenuHandler.RunContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model, CefSharp.IRunContextMenuCallback callback)
  761. {
  762. return false;
  763. }
  764. }
  765. class JsEvent
  766. {
  767. public string MessageText { set; get; }
  768. public void ShowTest()
  769. {
  770. MessageBox.Show(MessageText);
  771. }
  772. }
  773. #endregion
  774. #region EChart导出图像委托调用部份
  775. public delegate void MyDelgate(string va);
  776. public event MyDelgate butclic;
  777. private void timer1_Tick(object sender, EventArgs e)
  778. {
  779. if (butclic == null)
  780. return;
  781. if (m_ReportApp.js == null)
  782. return;
  783. if (m_ReportApp.js.MessageText == null)
  784. return;
  785. if (m_ReportApp.js.MessageText != "")
  786. {
  787. butclic(m_ReportApp.js.MessageText);
  788. timer1.Enabled = false;
  789. m_ReportApp.timerKG = false;
  790. }
  791. }
  792. #endregion
  793. }
  794. }