EChart_ParticlesComposition.cs 43 KB

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