Export_ReportTemplate.cs 56 KB

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