EChart_ParticlesComposition.cs 40 KB

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