Export_ReportTemplate.cs 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. using OTSIncAReportApp.Control_ECharts;
  2. using OTSIncAReportApp.DataOperation.DataAccess;
  3. using OTSIncAReportApp.DataOperation.Model;
  4. using OTSIncAReportGraph.Controls;
  5. using OTSIncAReportGrids;
  6. using OTSPeriodicTable;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Windows.Forms;
  14. namespace OTSIncAReportApp.OTSTemplateDesigner
  15. {
  16. public class Export_ReportTemplate
  17. {
  18. #region 全局变量
  19. public List<DataTable> m_list_dt; //导出的各模块数据,合集
  20. public OTSReport_Export m_otsreport_export;
  21. List<string> TemplateList;
  22. #endregion
  23. #region 构造函数
  24. public Export_ReportTemplate(OTSReport_Export in_export)
  25. {
  26. m_otsreport_export = in_export;
  27. TemplateList = new List<string>();
  28. //加载三元相图各项
  29. string pathtpf = in_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.FileFolderTrigTemp + "\\" + in_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.TriTempFile;// Application.StartupPath + "\\Config\\ProData\\DefaultTriTemplateFile.tpf";
  30. TemplateList = new List<string>();
  31. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXmlData(pathtpf, "XMLData");
  32. DataTable dt = ds.Tables["Member"];
  33. foreach (DataRow item in dt.Rows)
  34. {
  35. if (item["TemplateName"].ToString() != "")
  36. {
  37. TemplateList.Add(item["TemplateName"].ToString());
  38. }
  39. }
  40. m_list_dt = new List<DataTable>();
  41. }
  42. #endregion
  43. #region 插入测量结果Grid表格
  44. /// <summary>
  45. /// 向 模板设计器 中插入测量结果Grid表格
  46. /// </summary>
  47. /// <returns></returns>
  48. public DataTable InsertReportTemplateTable_ResultGrid()
  49. {
  50. //------------------加载模块,获取数据-------------------------------------------------
  51. ResultGrid ls_resultgrid = new ResultGrid(m_otsreport_export.m_ReportApp);
  52. Dictionary<string, string> keyValues_ResultGrid = ls_resultgrid.GetData_ResultGrid();
  53. //------------------加载模块,获取数据结束----------------------------------------------
  54. Dictionary<string, string>.Enumerator en = keyValues_ResultGrid.GetEnumerator();
  55. string str_CLJGMC = "";
  56. string str_YXSJ = "";
  57. string str_SCZS = "";
  58. string str_FLFA = "";
  59. string str_YJCTZ = "";
  60. string str_SCMJ = "";
  61. string str_CKBZ = "GB/T30834-2014";
  62. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col1"].ToString(), out str_CLJGMC);//测量结果名称
  63. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col4"].ToString(), out str_YXSJ);//运行时间
  64. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col5"].ToString(), out str_SCZS);//视场总数
  65. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col6"].ToString(), out str_FLFA);//分类方案
  66. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col7"].ToString(), out str_YJCTZ);//已检测特征
  67. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col8"].ToString(), out str_SCMJ);//视场面积
  68. //将获取到的数据转换成报告模板能接收的格式。
  69. DataTable ls_new_dt = new DataTable();
  70. ls_new_dt.TableName = "ResultGrid";
  71. ls_new_dt.Columns.Add("CLJGMC"); //测量结果名称
  72. ls_new_dt.Columns.Add("YXSJ"); //运行时间
  73. ls_new_dt.Columns.Add("SCZS"); //视场总数
  74. ls_new_dt.Columns.Add("FLFA"); //分类方案
  75. ls_new_dt.Columns.Add("YJCTZ"); //已检测特征
  76. ls_new_dt.Columns.Add("SCMJ"); //视场面积
  77. ls_new_dt.Columns.Add("CKBZ"); //参考标准
  78. //行转列,这里不会发生改变,所以这样写
  79. DataRow dr = ls_new_dt.NewRow();
  80. dr["CLJGMC"] = str_CLJGMC;
  81. dr["YXSJ"] = str_YXSJ;
  82. dr["SCZS"] = str_SCZS;
  83. dr["FLFA"] = str_FLFA;
  84. dr["YJCTZ"] = str_YJCTZ;
  85. dr["SCMJ"] = str_SCMJ;
  86. dr["CKBZ"] = str_CKBZ;
  87. ls_new_dt.Rows.Add(dr);
  88. m_list_dt.Add(ls_new_dt);
  89. return ls_new_dt;
  90. }
  91. #endregion
  92. #region 插入颗粒列表并带有帧图
  93. /// <summary>
  94. /// 颗粒列表中插入帧图,并带上颗粒分组信息
  95. /// </summary>
  96. /// <returns></returns>
  97. public bool InsertReportTemplateTable_ParticlesGridDevidePage()
  98. {
  99. int serialNumber = 1;
  100. //------------------加载模块,获取数据-------------------------------------------------
  101. //if (m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage!=null)
  102. m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage = new ParticlesGridDevidePage(m_otsreport_export.m_ReportApp);
  103. //根据sql条件,查询获取颗粒信息数据
  104. ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResult()].FilePath);
  105. //DataTable dt_ParticlesGridDevidePage = fielddata.GetInfoForPartucleDevidePage(0, 200, "fieldid,particleid", "");
  106. DataTable dt = fielddata.GetIncaSurfaceData();
  107. //将颗粒大小排序(从大到小)
  108. DataView dv = dt.DefaultView;
  109. dv.Sort = "Area DESC";
  110. DataTable dt_ParticlesGridDevidePage = dv.ToTable();
  111. string str_resultPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResult()].FilePath;
  112. //------------------加载模块,获取数据结束----------------------------------------------
  113. #region 创建要插入数据库表结构
  114. //插入模板需父子表,结构
  115. //表名field_dt表:(父表) 帧图表
  116. DataTable DT_field_dt = new DataTable();
  117. DT_field_dt.TableName = "field_dt";
  118. DataColumn colpictid2 = new DataColumn("FieldId");
  119. colpictid2.DataType = typeof(int);
  120. DT_field_dt.Columns.Add(colpictid2);
  121. //图像列
  122. DataColumn colpict2 = new DataColumn("FieldImg");
  123. colpict2.DataType = System.Type.GetType("System.Byte[]");
  124. DT_field_dt.Columns.Add(colpict2);
  125. //表名Largest_frame表:(子表) 显示20条颗粒除外的部份颗粒信息
  126. DataTable DT_Largest_frame = new DataTable();
  127. DT_Largest_frame.TableName = "Largest_frame";
  128. DT_Largest_frame.Columns.Add("pid");
  129. DT_Largest_frame.Columns.Add("Size");
  130. DT_Largest_frame.Columns.Add("Width");
  131. DT_Largest_frame.Columns.Add("Class");
  132. DT_Largest_frame.Columns.Add("ColName1");
  133. DT_Largest_frame.Columns.Add("ColName2");
  134. DT_Largest_frame.Columns.Add("ColName3");
  135. DT_Largest_frame.Columns.Add("ColName4");
  136. DT_Largest_frame.Columns.Add("ColName5");
  137. DT_Largest_frame.Columns.Add("ColName6");
  138. DT_Largest_frame.Columns.Add("ColVal1");
  139. DT_Largest_frame.Columns.Add("ColVal2");
  140. DT_Largest_frame.Columns.Add("ColVal3");
  141. DT_Largest_frame.Columns.Add("ColVal4");
  142. DT_Largest_frame.Columns.Add("ColVal5");
  143. DT_Largest_frame.Columns.Add("ColVal6");
  144. DataColumn colpictid = new DataColumn("FieldId");
  145. colpictid.DataType = typeof(int);
  146. DT_Largest_frame.Columns.Add(colpictid);
  147. //图像列
  148. DataColumn colpict = new DataColumn("p1");
  149. colpict.DataType = System.Type.GetType("System.Byte[]");
  150. DT_Largest_frame.Columns.Add(colpict);
  151. //largest20表:(无关系表) 需要显示前20条带有显示能谱图像的颗粒表
  152. DataTable DT_Largest20 = new DataTable();
  153. DT_Largest20.TableName = "Largest20";
  154. DT_Largest20.Columns.Add("pid");
  155. DT_Largest20.Columns.Add("Size");
  156. DT_Largest20.Columns.Add("Width");
  157. DT_Largest20.Columns.Add("Class");
  158. DT_Largest20.Columns.Add("ColName1");
  159. DT_Largest20.Columns.Add("ColName2");
  160. DT_Largest20.Columns.Add("ColName3");
  161. DT_Largest20.Columns.Add("ColName4");
  162. DT_Largest20.Columns.Add("ColName5");
  163. DT_Largest20.Columns.Add("ColName6");
  164. DT_Largest20.Columns.Add("ColVal1");
  165. DT_Largest20.Columns.Add("ColVal2");
  166. DT_Largest20.Columns.Add("ColVal3");
  167. DT_Largest20.Columns.Add("ColVal4");
  168. DT_Largest20.Columns.Add("ColVal5");
  169. DT_Largest20.Columns.Add("ColVal6");
  170. // 图像列
  171. DataColumn colpict_20ago = new DataColumn("p1");
  172. colpict_20ago.DataType = System.Type.GetType("System.Byte[]");
  173. DT_Largest20.Columns.Add(colpict_20ago);
  174. DataColumn colpict2_20ago = new DataColumn("p2");
  175. colpict2_20ago.DataType = System.Type.GetType("System.Byte[]");
  176. DT_Largest20.Columns.Add(colpict2_20ago);
  177. DataColumn colpict3_20ago = new DataColumn("p3");
  178. colpict3_20ago.DataType = System.Type.GetType("System.Byte[]");
  179. DT_Largest20.Columns.Add(colpict3_20ago);
  180. #endregion
  181. #region 插入-前20颗粒部份
  182. for (int i_row = 0; i_row < dt_ParticlesGridDevidePage.Rows.Count; i_row++)
  183. {
  184. if (dt_ParticlesGridDevidePage.Rows[i_row].ItemArray[24].ToString()!= "Not Identified")
  185. {
  186. //获取颗粒的fieldid,和particleid
  187. string str_fieldid = dt_ParticlesGridDevidePage.Rows[i_row]["fieldid"].ToString();
  188. string str_particleid = dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  189. string str_subparticles = dt_ParticlesGridDevidePage.Rows[i_row]["SubParticles"].ToString();
  190. string str_typeid = dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString();
  191. string str_typename = dt_ParticlesGridDevidePage.Rows[i_row]["TypeName"].ToString();
  192. string str_element = dt_ParticlesGridDevidePage.Rows[i_row]["Element"].ToString();
  193. //获取原始颗粒图像
  194. Bitmap bp_particle = new Bitmap(1, 1);
  195. string str_path = str_resultPath + "\\FIELD_FILES\\";
  196. string str_imagePath = str_path + "Field" + str_fieldid.ToString() + ".bmp";
  197. if (str_fieldid == "-1")
  198. continue;
  199. if (serialNumber > 20)
  200. continue;
  201. if (str_subparticles != null && str_subparticles != "")
  202. {
  203. //合并大颗粒
  204. double ScanFieldSize = 1142;
  205. Bitmap tempbit = fielddata.ReadImageFile(str_imagePath);
  206. int pixw = tempbit.Width;
  207. double xs = pixw / ScanFieldSize;
  208. bp_particle = fielddata.GetBitmapForBig(str_subparticles, xs, str_resultPath);
  209. }
  210. else
  211. {
  212. //正常颗粒
  213. Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectLeft"]), Y = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectTop"]), Width = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectWidth"]), Height = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectHeight"]) };
  214. Bitmap bp_field = fielddata.ReadImageFile(str_imagePath);
  215. bp_particle = fielddata.GetBitmapByParticle(bp_field, rectangle);
  216. bp_particle.Tag = new List<string>() { dt_ParticlesGridDevidePage.Rows[i_row]["FieldId"].ToString(), dt_ParticlesGridDevidePage.Rows[i_row]["ParticleId"].ToString(), dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString() };
  217. }
  218. //获取该颗粒的xray能谱图像
  219. System.Drawing.Bitmap bp_xraybp = ExportXRayBitmap(str_fieldid,
  220. str_particleid, Convert.ToInt32(str_typeid), str_typename, fielddata);
  221. Bitmap ls_xraybpnew = new Bitmap(1, 1);
  222. ls_xraybpnew = OTSIncAReportGraph.Class.DrawFunction.KiResizeImage(bp_xraybp, 700, 115);//能谱图处理
  223. //获取该颗粒的二次放大处理图像
  224. Bitmap ls_processbitmap = new Bitmap(1, 1);
  225. ls_processbitmap = OTSIncAReportGraph.Class.DrawFunction.GetReZoomBitmap(bp_particle);// (Bitmap)bp_particle.Clone();//待完善
  226. //再将图像转成二进制流-------------------------------------------------------------------
  227. //原图
  228. MemoryStream newms_p1 = new MemoryStream();
  229. bp_particle.Save(newms_p1, System.Drawing.Imaging.ImageFormat.Bmp);
  230. newms_p1.Seek(0, SeekOrigin.Begin);
  231. byte[] newarr_p1 = new byte[newms_p1.Length];
  232. newms_p1.Read(newarr_p1, 0, newarr_p1.Length);
  233. //二次放大图
  234. MemoryStream newms_p2 = new MemoryStream();
  235. ls_processbitmap.Save(newms_p2, System.Drawing.Imaging.ImageFormat.Bmp);
  236. newms_p2.Seek(0, SeekOrigin.Begin);
  237. byte[] newarr_p2 = new byte[newms_p2.Length];
  238. newms_p2.Read(newarr_p2, 0, newarr_p2.Length);
  239. //能谱图
  240. MemoryStream newms_p3 = new MemoryStream();
  241. ls_xraybpnew.Save(newms_p3, System.Drawing.Imaging.ImageFormat.Bmp);
  242. newms_p3.Seek(0, SeekOrigin.Begin);
  243. byte[] newarr_p3 = new byte[newms_p3.Length];
  244. newms_p3.Read(newarr_p3, 0, newarr_p3.Length);
  245. //---------------------------------------------------------------------------------------
  246. DataRow dr = DT_Largest20.NewRow();
  247. dr["p1"] = newarr_p1;
  248. dr["p2"] = newarr_p2;
  249. dr["p3"] = newarr_p3;
  250. newms_p1.Dispose();
  251. newms_p2.Dispose();
  252. newms_p3.Dispose();
  253. dr["pid"] = serialNumber++.ToString();
  254. //dr["pid"] = str_fieldid + dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  255. dr["Size"] = Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["area"]).ToString("#0.00"); //可以需要选择切换,计算方式
  256. dr["Width"] = dt_ParticlesGridDevidePage.Rows[i_row]["rectwidth"].ToString();
  257. dr["Class"] = dt_ParticlesGridDevidePage.Rows[i_row]["typename"].ToString();
  258. List<string> list_max_elementname = new List<string>();
  259. List<double> list_max_elementvale = new List<double>();
  260. GetMaxElementFromDataTable(dt_ParticlesGridDevidePage, i_row, out list_max_elementname, out list_max_elementvale);
  261. //元素1
  262. dr["ColName1"] = list_max_elementname[0];
  263. dr["ColVal1"] = list_max_elementvale[0].ToString();
  264. //元素2
  265. dr["ColName2"] = list_max_elementname[1];
  266. dr["ColVal2"] = list_max_elementvale[1].ToString();
  267. //元素3
  268. dr["ColName3"] = list_max_elementname[2];
  269. dr["ColVal3"] = list_max_elementvale[2].ToString();
  270. //元素4
  271. dr["ColName4"] = list_max_elementname[3];
  272. dr["ColVal4"] = list_max_elementvale[3].ToString();
  273. //元素5
  274. dr["ColName5"] = list_max_elementname[4];
  275. dr["ColVal5"] = list_max_elementvale[4].ToString();
  276. //元素6
  277. dr["ColName6"] = list_max_elementname[5];
  278. dr["ColVal6"] = list_max_elementvale[5].ToString();
  279. DT_Largest20.Rows.Add(dr);
  280. }
  281. }
  282. #endregion
  283. #region 插入-帧图图像部份
  284. //首先生成标记颗粒的帧图图像文件
  285. m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage.SaveMarkParticleRectangleOnFieldFile(dt_ParticlesGridDevidePage);
  286. string str_path_FIELD_FILES_MARK = str_resultPath + "\\FIELD_FILES_MARK\\";
  287. DirectoryInfo theFolder = new DirectoryInfo(str_path_FIELD_FILES_MARK);
  288. if (theFolder.Exists)
  289. {
  290. foreach (FileInfo nextifile in theFolder.GetFiles())
  291. {
  292. if (nextifile.Name.Contains(".bmp") == true || nextifile.Name.Contains(".BMP") == true)
  293. {
  294. //确认对应的帧图名
  295. string str_fieldid = Path.GetFileNameWithoutExtension(nextifile.Name);
  296. //在数据表中有颗粒在该帧图中的话,则对该帧图标记图像进行读取存入数据库
  297. DataRow[] datarowlist = dt_ParticlesGridDevidePage.Select(" fieldid = " + str_fieldid);
  298. if (datarowlist.Count() > 0)
  299. {
  300. Bitmap ls_bp_fieldmark = new Bitmap(nextifile.FullName);
  301. DataRow dr = DT_field_dt.NewRow();
  302. MemoryStream newms_bp_fieldmark = new MemoryStream();
  303. ls_bp_fieldmark.Save(newms_bp_fieldmark, System.Drawing.Imaging.ImageFormat.Bmp);
  304. newms_bp_fieldmark.Seek(0, SeekOrigin.Begin);
  305. byte[] newarr_fieldmark = new byte[newms_bp_fieldmark.Length];
  306. newms_bp_fieldmark.Read(newarr_fieldmark, 0, newarr_fieldmark.Length);
  307. dr["FieldImg"] = newarr_fieldmark;
  308. dr["FieldId"] = str_fieldid;
  309. ls_bp_fieldmark.Dispose();
  310. DT_field_dt.Rows.Add(dr);
  311. }
  312. }
  313. }
  314. }
  315. #endregion
  316. #region 插入-前20颗粒外的颗粒
  317. for (int i_row = 0; i_row < dt_ParticlesGridDevidePage.Rows.Count; i_row++)
  318. {
  319. //获取颗粒的fieldid,和particleid
  320. string str_fieldid = dt_ParticlesGridDevidePage.Rows[i_row]["fieldid"].ToString();
  321. if (Convert.ToInt32(str_fieldid) < 20)
  322. {
  323. string str_particleid = dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  324. string str_subparticles = dt_ParticlesGridDevidePage.Rows[i_row]["SubParticles"].ToString();
  325. string str_typeid = dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString();
  326. string str_typename = dt_ParticlesGridDevidePage.Rows[i_row]["TypeName"].ToString();
  327. string str_element = dt_ParticlesGridDevidePage.Rows[i_row]["Element"].ToString();
  328. //获取原始颗粒图像
  329. Bitmap bp_particle = new Bitmap(1, 1);
  330. string str_path = str_resultPath + "\\FIELD_FILES\\";
  331. string str_imagePath = str_path + "Field" + str_fieldid.ToString() + ".bmp";
  332. if (str_subparticles != null && str_subparticles != "")
  333. {
  334. //合并大颗粒
  335. double ScanFieldSize = 1142;
  336. Bitmap tempbit = fielddata.ReadImageFile(str_imagePath);
  337. int pixw = tempbit.Width;
  338. double xs = pixw / ScanFieldSize;
  339. bp_particle = fielddata.GetBitmapForBig(str_subparticles, xs, str_resultPath);
  340. }
  341. else
  342. {
  343. //正常颗粒
  344. Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectLeft"]), Y = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectTop"]), Width = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectWidth"]), Height = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectHeight"]) };
  345. Bitmap bp_field = fielddata.ReadImageFile(str_imagePath);
  346. bp_particle = fielddata.GetBitmapByParticle(bp_field, rectangle);
  347. bp_particle.Tag = new List<string>() { dt_ParticlesGridDevidePage.Rows[i_row]["FieldId"].ToString(), dt_ParticlesGridDevidePage.Rows[i_row]["ParticleId"].ToString(), dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString() };
  348. }
  349. //获取该颗粒的xray能谱图像
  350. System.Drawing.Bitmap bp_xraybp = ExportXRayBitmap(str_fieldid,
  351. str_particleid, Convert.ToInt32(str_typeid), str_typename, fielddata);
  352. //获取该颗粒的二次放大处理图像
  353. Bitmap ls_processbitmap = new Bitmap(1, 1);
  354. ls_processbitmap = (Bitmap)bp_particle.Clone();//待完善
  355. //再将图像转成二进制流-------------------------------------------------------------------
  356. //原图
  357. MemoryStream newms_p1 = new MemoryStream();
  358. bp_particle.Save(newms_p1, System.Drawing.Imaging.ImageFormat.Bmp);
  359. newms_p1.Seek(0, SeekOrigin.Begin);
  360. byte[] newarr_p1 = new byte[newms_p1.Length];
  361. newms_p1.Read(newarr_p1, 0, newarr_p1.Length);
  362. //---------------------------------------------------------------------------------------
  363. DataRow dr = DT_Largest_frame.NewRow();
  364. dr["p1"] = newarr_p1;
  365. newms_p1.Dispose();
  366. dr["pid"] = str_fieldid + dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  367. dr["Size"] = Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["area"]).ToString("#0.00"); //可以需要选择切换,计算方式
  368. dr["Width"] = dt_ParticlesGridDevidePage.Rows[i_row]["rectwidth"].ToString();
  369. dr["Class"] = dt_ParticlesGridDevidePage.Rows[i_row]["typename"].ToString();
  370. dr["fieldid"] = str_fieldid;
  371. List<string> list_max_elementname = new List<string>();
  372. List<double> list_max_elementvale = new List<double>();
  373. GetMaxElementFromDataTable(dt_ParticlesGridDevidePage, i_row, out list_max_elementname, out list_max_elementvale);
  374. //元素1
  375. dr["ColName1"] = list_max_elementname[0];
  376. dr["ColVal1"] = list_max_elementvale[0].ToString();
  377. //元素2
  378. dr["ColName2"] = list_max_elementname[1];
  379. dr["ColVal2"] = list_max_elementvale[1].ToString();
  380. //元素3
  381. dr["ColName3"] = list_max_elementname[2];
  382. dr["ColVal3"] = list_max_elementvale[2].ToString();
  383. //元素4
  384. dr["ColName4"] = list_max_elementname[3];
  385. dr["ColVal4"] = list_max_elementvale[3].ToString();
  386. //元素5
  387. dr["ColName5"] = list_max_elementname[4];
  388. dr["ColVal5"] = list_max_elementvale[4].ToString();
  389. //元素6
  390. dr["ColName6"] = list_max_elementname[5];
  391. dr["ColVal6"] = list_max_elementvale[5].ToString();
  392. DT_Largest_frame.Rows.Add(dr);
  393. }
  394. }
  395. #endregion
  396. m_list_dt.Add(DT_field_dt);
  397. m_list_dt.Add(DT_Largest_frame);
  398. m_list_dt.Add(DT_Largest20);
  399. return true;
  400. }
  401. #endregion
  402. #region 插入颗粒尺寸表
  403. /// <summary>
  404. /// 向 模板设计器 中插入 颗粒尺寸表
  405. /// </summary>
  406. /// <returns></returns>
  407. public bool InsertReportTemplateTable_ParticleSizeGrid()
  408. {
  409. try
  410. {
  411. //加载模块
  412. ParticlesSizeGrid ls_particlesizegrid = new ParticlesSizeGrid(m_otsreport_export.m_ReportApp);
  413. List<string> vs = new List<string>() { "DMAX", "DMIN", "CIRCLE", "FERET" };
  414. ls_particlesizegrid.condition = vs[m_otsreport_export.m_mbszclass.M_KLFXJG.index_cb_klcc_jsfs];
  415. m_otsreport_export.panel_container.Controls.Clear();
  416. m_otsreport_export.panel_container.Controls.Add(ls_particlesizegrid);
  417. DataGridView ls_gv = new DataGridView();
  418. DataTable ls_dt = new DataTable();
  419. ls_particlesizegrid.GetDataTableAndGridView(out ls_dt, out ls_gv);
  420. //------------------------------------------------
  421. DataTable ls_partsize_dt = new DataTable();
  422. ls_partsize_dt.TableName = "PartSize";
  423. ls_partsize_dt.Columns.Add("c1");
  424. ls_partsize_dt.Columns.Add("c2");
  425. ls_partsize_dt.Columns.Add("c3");
  426. ls_partsize_dt.Columns.Add("c4");
  427. ls_partsize_dt.Columns.Add("c5");
  428. ls_partsize_dt.Columns.Add("c6");
  429. ls_partsize_dt.Columns.Add("c7");
  430. ls_partsize_dt.Columns.Add("c8");
  431. ls_partsize_dt.Columns.Add("c9");
  432. DataRow dr = ls_partsize_dt.NewRow();
  433. //从2开始,固定的
  434. int col = 6;
  435. for (int i = 1; i < 11; i++)
  436. {
  437. if (ls_gv.Columns.Count > col)
  438. if (i<10)
  439. dr["c" + i.ToString()] = ls_gv.Columns[col++].Name;
  440. }
  441. ls_partsize_dt.Rows.Add(dr);
  442. DataTable ls_Particel_dt = new DataTable();
  443. ls_Particel_dt.TableName = "Particel";
  444. ls_Particel_dt.Columns.Add("c1");
  445. ls_Particel_dt.Columns.Add("c2");
  446. ls_Particel_dt.Columns.Add("c3");
  447. ls_Particel_dt.Columns.Add("c4");
  448. ls_Particel_dt.Columns.Add("c5");
  449. ls_Particel_dt.Columns.Add("c6");
  450. ls_Particel_dt.Columns.Add("c7");
  451. ls_Particel_dt.Columns.Add("c8");
  452. ls_Particel_dt.Columns.Add("c9");
  453. ls_Particel_dt.Columns.Add("SName");
  454. ls_Particel_dt.Columns.Add("total");
  455. ls_Particel_dt.Columns.Add("Largest");
  456. ls_Particel_dt.Columns.Add("Hardness");
  457. ls_Particel_dt.Columns.Add("Density");
  458. ls_Particel_dt.Columns.Add("Conductivity");
  459. for (int i = 0; i < ls_gv.Rows.Count; i++)
  460. {
  461. DataRow dr2 = ls_Particel_dt.NewRow();
  462. dr2["SName"] = ls_gv.Rows[i].Cells[1].Value.ToString();
  463. dr2["Largest"] = ls_gv.Rows[i].Cells[4].Value.ToString();
  464. dr2["Hardness"] = ls_gv.Rows[i].Cells[6].Value.ToString();
  465. dr2["Density"] = ls_gv.Rows[i].Cells[7].Value.ToString();
  466. dr2["Conductivity"] = ls_gv.Rows[i].Cells[8].Value.ToString();
  467. int col2 = 6;
  468. for (int j = 1; j < 11; j++)
  469. {
  470. if (ls_gv.Columns.Count > col2)
  471. if(j<10)
  472. dr2["c" + j.ToString()] = ls_gv.Rows[i].Cells[col2++].Value.ToString();
  473. }
  474. //total,不为空行,和不能是总计行
  475. if (dr2["SName"].ToString() != "" && dr2["SName"].ToString().IndexOf("number") < 0)
  476. {
  477. dr2["total"] = "0"; //求合
  478. double d_total = 0;
  479. int col3 = 6;
  480. for (int j = 1; j < 11; j++)
  481. {
  482. if (ls_gv.Columns.Count > col3)
  483. d_total = d_total + Convert.ToInt64(ls_gv.Rows[i].Cells[col3++].Value.ToString());
  484. }
  485. dr2["total"] = d_total.ToString();
  486. }
  487. ls_Particel_dt.Rows.Add(dr2);
  488. }
  489. m_list_dt.Add(ls_partsize_dt);
  490. m_list_dt.Add(ls_Particel_dt);
  491. return true;
  492. }
  493. catch (Exception ee)
  494. {
  495. m_otsreport_export.WriteRictBox(ee.ToString());
  496. return false;
  497. }
  498. }
  499. #endregion
  500. #region 插入平均元素含量表
  501. /// <summary>
  502. /// 向 模板设计器 中插入 平均元素含量表
  503. /// </summary>
  504. /// <returns></returns>
  505. public bool InsertReportTemplateTable_ElementCompositionAvgGrid()
  506. {
  507. try
  508. {
  509. //加载模块
  510. ElementCompositionAvgGrid ls_elementcompositionavggrid = new ElementCompositionAvgGrid(m_otsreport_export.m_ReportApp);
  511. m_otsreport_export.panel_container.Controls.Clear();
  512. m_otsreport_export.panel_container.Controls.Add(ls_elementcompositionavggrid);
  513. DataGridView ls_gv = new DataGridView();
  514. DataTable ls_dt = new DataTable();
  515. ls_elementcompositionavggrid.GetDataTableAndGridView(out ls_dt, out ls_gv);
  516. //------------------------------------------------
  517. DataTable ls_elementname_dt = new DataTable();
  518. ls_elementname_dt.TableName = "ElementName";
  519. ls_elementname_dt.Columns.Add("e1");
  520. ls_elementname_dt.Columns.Add("e2");
  521. ls_elementname_dt.Columns.Add("e3");
  522. ls_elementname_dt.Columns.Add("e4");
  523. ls_elementname_dt.Columns.Add("e5");
  524. ls_elementname_dt.Columns.Add("e6");
  525. ls_elementname_dt.Columns.Add("e7");
  526. ls_elementname_dt.Columns.Add("e8");
  527. ls_elementname_dt.Columns.Add("e9");
  528. ls_elementname_dt.Columns.Add("e10");
  529. ls_elementname_dt.Columns.Add("e11");
  530. ls_elementname_dt.Columns.Add("e12");
  531. ls_elementname_dt.Columns.Add("e13");
  532. ls_elementname_dt.Columns.Add("e14");
  533. DataRow dr = ls_elementname_dt.NewRow();
  534. int col = 4;
  535. for (int i = 1; i < 15; i++)
  536. {
  537. if (ls_gv.Columns.Count > col)
  538. dr["e" + i.ToString()] = ls_gv.Columns[col++].Name;
  539. }
  540. ls_elementname_dt.Rows.Add(dr);
  541. DataTable ls_element_dt = new DataTable();
  542. ls_element_dt.TableName = "ElementValue";
  543. ls_element_dt.Columns.Add("e1");
  544. ls_element_dt.Columns.Add("e2");
  545. ls_element_dt.Columns.Add("e3");
  546. ls_element_dt.Columns.Add("e4");
  547. ls_element_dt.Columns.Add("e5");
  548. ls_element_dt.Columns.Add("e6");
  549. ls_element_dt.Columns.Add("e7");
  550. ls_element_dt.Columns.Add("e8");
  551. ls_element_dt.Columns.Add("e9");
  552. ls_element_dt.Columns.Add("e10");
  553. ls_element_dt.Columns.Add("e11");
  554. ls_element_dt.Columns.Add("e12");
  555. ls_element_dt.Columns.Add("e13");
  556. ls_element_dt.Columns.Add("e14");
  557. ls_element_dt.Columns.Add("PName");
  558. ls_element_dt.Columns.Add("Count");
  559. ls_element_dt.Columns.Add("AllElements");
  560. for (int i = 0; i < ls_gv.Rows.Count; i++)
  561. {
  562. DataRow dr2 = ls_element_dt.NewRow();
  563. dr2["PName"] = ls_gv.Rows[i].Cells[1].Value.ToString();
  564. dr2["Count"] = ls_gv.Rows[i].Cells[2].Value.ToString();
  565. int colq = 4;
  566. for (int j = 1; j < 15; j++)
  567. {
  568. if (ls_gv.Columns.Count > colq)
  569. dr2["e" + j.ToString()] = ls_gv.Rows[i].Cells[colq++].Tag.ToString();
  570. }
  571. colq = 4;
  572. string AllElements=null;
  573. for (int j = 0; j < ls_gv.Rows[i].Cells.Count; j++)
  574. {
  575. if (ls_gv.Columns.Count > colq)
  576. {
  577. AllElements = AllElements+ ls_gv.Columns[colq].Name + "%="+ ls_gv.Rows[i].Cells[colq++].Tag.ToString()+"; ";
  578. }
  579. }
  580. dr2["AllElements"] = AllElements;
  581. ls_element_dt.Rows.Add(dr2);
  582. }
  583. //获取夹杂物的总面积用于计算夹杂物类别的占比(gridview最后一个固定是未识别颗粒,要排除未识别颗粒所以for循环至grid view长度减一)
  584. double totalInclusionArea = 0;
  585. for (int i = 0; i < ls_gv.Rows.Count - 1; i++)
  586. {
  587. totalInclusionArea = totalInclusionArea + Convert.ToDouble(ls_gv.Rows[i].Cells[2].Value.ToString());
  588. }
  589. m_list_dt.Add(ls_elementname_dt);
  590. m_list_dt.Add(ls_element_dt);
  591. return true;
  592. }
  593. catch (Exception ee)
  594. {
  595. m_otsreport_export.WriteRictBox(ee.ToString());
  596. return false;
  597. }
  598. }
  599. #endregion
  600. #region 插入颗粒图chart
  601. /// <summary>
  602. /// 用于颗粒图chart
  603. /// </summary>
  604. /// <returns></returns>
  605. private DataTable GetPicDataTable_PicKL()
  606. {
  607. if (m_list_dt.Where(aa => aa.TableName.Contains("PicKL")).ToList().Count == 0)
  608. {
  609. //创建二进制列的数据表
  610. DataTable ls_dt = new DataTable();
  611. ls_dt.TableName = "PicKL";
  612. DataColumn colpict = new DataColumn("pict");
  613. colpict.DataType = System.Type.GetType("System.Byte[]");
  614. ls_dt.Columns.Add(colpict);
  615. m_list_dt.Add(ls_dt);
  616. return ls_dt;
  617. }
  618. else
  619. {
  620. return m_list_dt.Where(aa => aa.TableName.Contains("PicKL")).ToList()[0];
  621. }
  622. }
  623. #endregion
  624. #region 插入元素图chart
  625. /// <summary>
  626. /// 用于元素图chart
  627. /// </summary>
  628. /// <returns></returns>
  629. private DataTable GetPicDataTable_PicYS()
  630. {
  631. if (m_list_dt.Where(aa => aa.TableName.Contains("PicYS")).ToList().Count == 0)
  632. {
  633. //创建二进制列的数据表
  634. DataTable ls_dt = new DataTable();
  635. ls_dt.TableName = "PicYS";
  636. DataColumn colpict = new DataColumn("pict");
  637. colpict.DataType = System.Type.GetType("System.Byte[]");
  638. ls_dt.Columns.Add(colpict);
  639. m_list_dt.Add(ls_dt);
  640. return ls_dt;
  641. }
  642. else
  643. {
  644. return m_list_dt.Where(aa => aa.TableName.Contains("PicYS")).ToList()[0];
  645. }
  646. }
  647. #endregion
  648. #region 插入颗粒成份图
  649. /// <summary>
  650. /// 向 模板设计器 中插入 颗粒成份图
  651. /// </summary>
  652. /// <returns></returns>
  653. public bool InsertReportTemplateChart_ParticlesCompositionChart(string a_GraphicStyle)
  654. {
  655. try
  656. {
  657. //-----------------------------------颗粒成份图-----------------------------------------------------------------------------------------------
  658. //加载模块
  659. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition = new EChart_ParticlesComposition(m_otsreport_export.m_ReportApp, "PComponent");
  660. m_otsreport_export.m_ReportApp.m_reportname = "InclusionClassification";
  661. m_otsreport_export.m_ReportApp.type = a_GraphicStyle;
  662. m_otsreport_export.m_ReportApp.timerKG = true;
  663. m_otsreport_export.m_ReportApp.m_ChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition);
  664. //弹出加载图片窗体
  665. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  666. //将EChart委托事件注册给加载图片窗体的方法
  667. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition.butclic += og.get_ParticalesCompositionChart;
  668. og.ShowDialog();
  669. //获取图片数据
  670. string str = og.PicStr;
  671. //将Base64String转为图片并保存
  672. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  673. MemoryStream ms = new MemoryStream(arr);
  674. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  675. //再将图转成流,流再转二进制-------------------------------------------
  676. MemoryStream newms = new MemoryStream();
  677. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  678. newms.Seek(0, SeekOrigin.Begin);
  679. byte[] newarr = new byte[newms.Length];
  680. newms.Read(newarr, 0, newarr.Length);
  681. newms.Dispose();
  682. //创建二进制列的数据表
  683. DataTable ls_dt = GetPicDataTable_PicKL();
  684. DataRow dr = ls_dt.NewRow();
  685. dr["pict"] = newarr;//图像二进制
  686. ls_dt.Rows.Add(dr);
  687. return true;
  688. }
  689. catch (Exception ee)
  690. {
  691. m_otsreport_export.WriteRictBox(ee.ToString());
  692. return false;
  693. }
  694. }
  695. #endregion
  696. #region 插入元素成份图
  697. /// <summary>
  698. /// 向 模板设计器 中插入 元素成份图
  699. /// </summary>
  700. /// <returns></returns>
  701. public bool InsertReportTemplateChart_ElementCompositionChart(string a_GraphicStyle)
  702. {
  703. try
  704. {
  705. //-----------------------------------元素成份图-----------------------------------------------------------------------------------------------
  706. //加载模块
  707. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition = new EChart_ParticlesComposition(m_otsreport_export.m_ReportApp, "EComponent");
  708. m_otsreport_export.m_ReportApp.m_reportname = "ElementComposition";
  709. m_otsreport_export.m_ReportApp.type = a_GraphicStyle;
  710. m_otsreport_export.m_ReportApp.timerKG = true;
  711. m_otsreport_export.m_ReportApp.m_ChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition);
  712. //弹出加载图片窗体
  713. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  714. //将EChart委托事件注册给加载图片窗体的方法
  715. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition.butclic += og.get_ParticalesCompositionChart;
  716. og.ShowDialog();
  717. //获取图片数据
  718. string str = og.PicStr;
  719. //将Base64String转为图片并保存
  720. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  721. MemoryStream ms = new MemoryStream(arr);
  722. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  723. //再将图转成流,流再转二进制-------------------------------------------
  724. MemoryStream newms = new MemoryStream();
  725. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  726. newms.Seek(0, SeekOrigin.Begin);
  727. byte[] newarr = new byte[newms.Length];
  728. newms.Read(newarr, 0, newarr.Length);
  729. newms.Dispose();
  730. //创建二进制列的数据表
  731. DataTable ls_dt = GetPicDataTable_PicYS();
  732. DataRow dr = ls_dt.NewRow();
  733. dr["pict"] = newarr;//图像二进制
  734. ls_dt.Rows.Add(dr);
  735. return true;
  736. }
  737. catch (Exception ee)
  738. {
  739. m_otsreport_export.WriteRictBox(ee.ToString());
  740. return false;
  741. }
  742. }
  743. #endregion
  744. #region 插入三元相图
  745. /// <summary>
  746. /// 获取或创建pic表格,用于三元相图
  747. /// </summary>
  748. /// <returns></returns>
  749. private DataTable GetPicDataTable_PicSYXT2T()
  750. {
  751. if (m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT2T")).ToList().Count == 0)
  752. {
  753. //创建二进制列的数据表
  754. DataTable ls_dt = new DataTable();
  755. ls_dt.TableName = "PicSYXT2T";
  756. DataColumn colpict = new DataColumn("pict");
  757. colpict.DataType = System.Type.GetType("System.Byte[]");
  758. ls_dt.Columns.Add(colpict);
  759. DataColumn colpict2 = new DataColumn("pict2");
  760. colpict2.DataType = System.Type.GetType("System.Byte[]");
  761. ls_dt.Columns.Add(colpict2);
  762. m_list_dt.Add(ls_dt);
  763. return ls_dt;
  764. }
  765. else
  766. {
  767. return m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT2T")).ToList()[0];
  768. }
  769. }
  770. /// <summary>
  771. /// 获取或创建pic表格,用于三元相图,3个列的
  772. /// </summary>
  773. /// <returns></returns>
  774. private DataTable GetPicDataTable_PicSYXT3T()
  775. {
  776. if (m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT3T")).ToList().Count == 0)
  777. {
  778. //创建二进制列的数据表
  779. DataTable ls_dt = new DataTable();
  780. ls_dt.TableName = "PicSYXT3T";
  781. DataColumn colpict = new DataColumn("pict");
  782. colpict.DataType = System.Type.GetType("System.Byte[]");
  783. ls_dt.Columns.Add(colpict);
  784. DataColumn colpict2 = new DataColumn("pict2");
  785. colpict2.DataType = System.Type.GetType("System.Byte[]");
  786. ls_dt.Columns.Add(colpict2);
  787. DataColumn colpict3 = new DataColumn("pict3");
  788. colpict3.DataType = System.Type.GetType("System.Byte[]");
  789. ls_dt.Columns.Add(colpict3);
  790. m_list_dt.Add(ls_dt);
  791. return ls_dt;
  792. }
  793. else
  794. {
  795. return m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT")).ToList()[0];
  796. }
  797. }
  798. /// <summary>
  799. /// 获取三元相图二进制数据
  800. /// </summary>
  801. /// <param name="selectindex"></param>
  802. /// <returns></returns>
  803. private byte[] GetByte_InsertReportTemplateChart_Trianglediagram(int selectindex)
  804. {
  805. byte[] newarr = new byte[0];
  806. //加载模块
  807. m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram = new EChart_Trianglediagram(m_otsreport_export.m_ReportApp, TemplateList[selectindex]);
  808. m_otsreport_export.m_ReportApp.timerKG = true;
  809. m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram.condition = m_otsreport_export.m_mbszclass.M_SYXT.index_cb_syxt_jsfs;
  810. m_otsreport_export.m_ReportApp.m_ChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram);
  811. //ls_echart_trianglediagram.
  812. //弹出加载图片窗体
  813. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  814. //将EChart委托事件注册给加载图片窗体的方法
  815. m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram.butclic += og.get_ParticalesCompositionChart;
  816. og.ShowDialog();
  817. //获取图片数据
  818. string str = og.PicStr;
  819. //将Base64String转为图片并保存
  820. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  821. MemoryStream ms = new MemoryStream(arr);
  822. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  823. //再将图转成流,流再转二进制-------------------------------------------
  824. MemoryStream newms = new MemoryStream();
  825. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  826. newms.Seek(0, SeekOrigin.Begin);
  827. newarr = new byte[newms.Length];
  828. newms.Read(newarr, 0, newarr.Length);
  829. newms.Dispose();
  830. return newarr;
  831. }
  832. /// <summary>
  833. /// 向 模板设计器 中插入 三元相图
  834. /// </summary>
  835. /// <returns></returns>
  836. public bool InsertReportTemplateChart_Trianglediagram()
  837. {
  838. try
  839. {
  840. //创建二进制列的数据表,循环插入三元选择的模板
  841. DataTable ls_dt = GetPicDataTable_PicSYXT2T();
  842. DataTable ls_dt3t = GetPicDataTable_PicSYXT3T();
  843. //这里要校验一下,总数必须要是2的整倍数,不可有余数
  844. if (m_otsreport_export.m_mbszclass.M_SYXT.str_cb_syxt_mhxssl == "2" && m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index.Count % 2 == 0)
  845. {
  846. for (int i = 0; i < m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index.Count; i = i + 2)
  847. {
  848. byte[] newarr, newarr2;
  849. newarr = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i]);
  850. newarr2 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 1]);
  851. DataRow dr = ls_dt.NewRow();
  852. dr["pict"] = newarr;//图像二进制
  853. dr["pict2"] = newarr2;//图像二进制
  854. ls_dt.Rows.Add(dr);
  855. }
  856. }
  857. else
  858. {
  859. DataRow dr = ls_dt.NewRow();
  860. dr["pict"] = null;//图像二进制
  861. dr["pict2"] = null;//图像二进制
  862. ls_dt.Rows.Add(dr);
  863. }
  864. if (m_otsreport_export.m_mbszclass.M_SYXT.str_cb_syxt_mhxssl == "3" && m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index.Count % 3 == 0)
  865. {
  866. for (int i = 0; i < m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index.Count; i = i + 3)
  867. {
  868. byte[] newarr, newarr2, newarr3;
  869. newarr = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i]);
  870. newarr2 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 1]);
  871. newarr3 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 2]);
  872. DataRow dr = ls_dt3t.NewRow();
  873. dr["pict"] = newarr;//图像二进制
  874. dr["pict2"] = newarr2;//图像二进制
  875. dr["pict3"] = newarr3;//图像二进制
  876. ls_dt3t.Rows.Add(dr);
  877. }
  878. }
  879. else
  880. {
  881. DataRow dr = ls_dt3t.NewRow();
  882. dr["pict"] = null;//图像二进制
  883. dr["pict2"] = null;//图像二进制
  884. dr["pict3"] = null;//图像二进制
  885. ls_dt3t.Rows.Add(dr);
  886. }
  887. return true;
  888. }
  889. catch (Exception ee)
  890. {
  891. m_otsreport_export.WriteRictBox(ee.ToString());
  892. return false;
  893. }
  894. }
  895. #endregion
  896. #region 其它部份
  897. /// <summary>
  898. /// 输入颗粒的所在帧图id,颗粒id,颗粒类型id,获取对应的XRay能谱数据图
  899. /// </summary>
  900. /// <returns></returns>
  901. public Bitmap ExportXRayBitmap(string in_fieldid, string in_particleid, int in_stdtypeid, string TypeName, ParticleData particleData)
  902. {
  903. Bitmap ret_bp;
  904. //显示xray相关信息
  905. uint[] Search_xray = new uint[2000];
  906. uint[] Analysis_xray = new uint[2000];
  907. //
  908. int i_xray_id = 0;
  909. List<Element> list_celementchemistryclr = new List<Element>();
  910. //获取Xray数据
  911. list_celementchemistryclr = new List<Element>();
  912. Particle list = particleData.GetParticleByFidAndPid(in_fieldid, in_particleid);
  913. if (list == null)
  914. {
  915. return null;
  916. }
  917. Particle particle = list;
  918. if (particle.XrayId > -1)
  919. {
  920. for (int i = 0; i < 2000; i++)
  921. {
  922. if (particle.XRayData!=null)
  923. {
  924. Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
  925. }
  926. }
  927. Search_xray = Analysis_xray;
  928. i_xray_id = particle.XrayId;
  929. list_celementchemistryclr = particle.ElementList;
  930. }
  931. //get CElementChemistryClr list
  932. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  933. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  934. {
  935. ShowElementInfo ls_sei = new ShowElementInfo();
  936. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  937. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  938. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX1);
  939. list_showelementinfo.Add(ls_sei);
  940. }
  941. //获取使用标准库的名称
  942. string str_stdname = "";
  943. string str_IncALibName = "";
  944. if (in_stdtypeid < 1000)
  945. {
  946. //小于1000,使用系统默认分类
  947. str_IncALibName = TypeName;
  948. str_stdname = "Default standard library";
  949. }
  950. else if (in_stdtypeid >= 1000 && in_stdtypeid < 10000)
  951. {
  952. //大于等于1000,并且小于10000时,使用系统数据库中夹杂物来分析
  953. str_IncALibName = TypeName;
  954. str_stdname = "User defined standard library";
  955. }
  956. else if (in_stdtypeid > 10000)
  957. {
  958. //大于10000时,使用用户标准库来分析夹杂物名称
  959. str_IncALibName = TypeName;
  960. str_stdname = "System standard library";
  961. }
  962. //获取数据后,需要对xraytable设置
  963. OTSIncAReportGraph.Controls.Control_XRayTable control_XRayTable1 = new Control_XRayTable();
  964. control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray, list_showelementinfo);
  965. //颗粒国标信息
  966. //control_XRayTable1.GBInfoStr = in_dparticle.GBContent;
  967. control_XRayTable1.MaterialName = str_IncALibName;//杂夹物
  968. control_XRayTable1.STDName = str_stdname;//标准库
  969. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  970. control_XRayTable1.Visible = true;
  971. control_XRayTable1.Invalidate();
  972. control_XRayTable1.Refresh();
  973. ret_bp = control_XRayTable1.ExportXRayImage();
  974. return ret_bp;
  975. }
  976. /// <summary>
  977. /// 导出二次放大图像
  978. /// </summary>
  979. /// <param name="str_srcPathName"></param>
  980. /// <param name="str_outPathName"></param>
  981. public void ParticleReZoom(string str_srcPathName, string str_outPathName)
  982. {
  983. //m_COTSReportProjFileMgrClr.ReZoom(str_srcPathName, str_outPathName);
  984. }
  985. /// <summary>
  986. /// 传入DataTable,和行号,返回该Row行中,返回6个靠前的元素,不足6个返回空
  987. /// </summary>
  988. /// <param name="in_dt"></param>
  989. /// <param name="row_index"></param>
  990. /// <returns></returns>
  991. private void GetMaxElementFromDataTable(DataTable in_dt, int row_index, out List<string> out_list_elementname, out List<double> out_list_elementvalue)
  992. {
  993. out_list_elementname = new List<string>();
  994. out_list_elementvalue = new List<double>();
  995. //分别排出元素名,元素值列表
  996. List<string> list_elementname = new List<string>();
  997. List<double> list_elementvalue = new List<double>();
  998. string str_element = in_dt.Rows[row_index]["Element"].ToString();
  999. //防止取出的元素信息为空
  1000. if (str_element != "")
  1001. {
  1002. string[] strcbo = str_element.Split(';');
  1003. for (int i = 0; i < strcbo.Length-1; i++)
  1004. {
  1005. string[] str = strcbo[i].Split('-');
  1006. list_elementname.Add(str[0]);
  1007. list_elementvalue.Add(Math.Round(Convert.ToDouble(str[1]), 2));
  1008. }
  1009. }
  1010. //循环6次,得到最大的6个元素信息
  1011. for (int geti = 0; geti < 6; geti++)
  1012. {
  1013. double max_elementvalue = -1;
  1014. string max_elementname = "";
  1015. int max_index = -1;
  1016. if (list_elementvalue.Count > 0)
  1017. {
  1018. for (int i = 0; i < list_elementvalue.Count; i++)
  1019. {
  1020. if (list_elementvalue[i] > max_elementvalue)
  1021. {
  1022. max_elementvalue = list_elementvalue[i];
  1023. max_elementname = list_elementname[i];
  1024. max_index = i;
  1025. }
  1026. }
  1027. //移除掉最大的元素
  1028. list_elementname.RemoveAt(max_index);
  1029. list_elementvalue.RemoveAt(max_index);
  1030. //将最大的元素添加到list中
  1031. if (max_elementvalue > 0)
  1032. {
  1033. out_list_elementname.Add(max_elementname);
  1034. out_list_elementvalue.Add(max_elementvalue);
  1035. }
  1036. else
  1037. {
  1038. out_list_elementname.Add(" ");
  1039. out_list_elementvalue.Add(0);
  1040. }
  1041. }
  1042. else
  1043. {
  1044. //如果元素数量已经不够,则添加空
  1045. out_list_elementname.Add(" ");
  1046. out_list_elementvalue.Add(0);
  1047. }
  1048. }
  1049. }
  1050. #endregion
  1051. /// <summary>
  1052. /// 国标一
  1053. /// </summary>
  1054. /// <returns></returns>
  1055. public List<DataTable> InsertReportTemplateTable_ChineseStandardABCDDS(OTSCLRINTERFACE.CPropParamClr cPropParamClr)
  1056. {
  1057. //得到国标一的DataTable表格
  1058. cPropParamClr.SetDataSourceId(0);//
  1059. cPropParamClr.SetType(1);//table
  1060. cPropParamClr.SetCalTableType(6);//国标1
  1061. List<OTSCLRINTERFACE.CGridDataClr> listGriddataclr = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr.GridDataTransfer(cPropParamClr);
  1062. m_otsreport_export.m_ReportApp.im_ChineseStandardABCDDS = new OTSIncAReportGB.ChineseStandardABCDDS(m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr, listGriddataclr);
  1063. m_otsreport_export.m_ReportApp.m_TablesWindow.Controls.Clear();
  1064. //List<DataTable> GB_1 = m_otsreport_export.m_ReportApp.im_ChineseStandardABCDDS.ChineseStandardABCD_GetDataTable();
  1065. //string s = GB_1[0].Rows[0][0].ToString();
  1066. return m_otsreport_export.m_ReportApp.im_ChineseStandardABCDDS.ChineseStandardABCD_GetDataTable(); ;
  1067. }
  1068. /// <summary>
  1069. /// 国标二
  1070. /// </summary>
  1071. /// <returns></returns>
  1072. public List<DataTable> InsertReportTemplateTable_NationalStandardMethodTwo(OTSCLRINTERFACE.CPropParamClr cPropParamClr)
  1073. {
  1074. //得到国标二的DataTable表格
  1075. cPropParamClr.SetDataSourceId(0);//
  1076. cPropParamClr.SetType(1);//table
  1077. cPropParamClr.SetCalTableType(7);//国标2
  1078. List<OTSCLRINTERFACE.CGridDataClr> listGriddataclr2 = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr.GridDataTransfer(cPropParamClr);//
  1079. m_otsreport_export.m_ReportApp.m_TablesWindow.Controls.Clear();
  1080. m_otsreport_export.m_ReportApp.im_NationalStandardMethodTwo = new OTSIncAReportGB.NationalStandardMethodTwo(m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr, listGriddataclr2);
  1081. return m_otsreport_export.m_ReportApp.im_NationalStandardMethodTwo.ChineseStandardABCD_GetDataTable();
  1082. }
  1083. }
  1084. }