EChart_ParticlesComposition.cs 38 KB

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