Export_ReportTemplate.cs 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  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. if (i<10)
  440. dr["c" + i.ToString()] = ls_gv.Columns[col++].Name;
  441. }
  442. ls_partsize_dt.Rows.Add(dr);
  443. DataTable ls_Particel_dt = new DataTable();
  444. ls_Particel_dt.TableName = "Particel";
  445. ls_Particel_dt.Columns.Add("c1");
  446. ls_Particel_dt.Columns.Add("c2");
  447. ls_Particel_dt.Columns.Add("c3");
  448. ls_Particel_dt.Columns.Add("c4");
  449. ls_Particel_dt.Columns.Add("c5");
  450. ls_Particel_dt.Columns.Add("c6");
  451. ls_Particel_dt.Columns.Add("c7");
  452. ls_Particel_dt.Columns.Add("c8");
  453. ls_Particel_dt.Columns.Add("c9");
  454. ls_Particel_dt.Columns.Add("SName");
  455. ls_Particel_dt.Columns.Add("total");
  456. ls_Particel_dt.Columns.Add("Largest");
  457. ls_Particel_dt.Columns.Add("Hardness");
  458. ls_Particel_dt.Columns.Add("Density");
  459. ls_Particel_dt.Columns.Add("Conductivity");
  460. for (int i = 0; i < ls_gv.Rows.Count; i++)
  461. {
  462. DataRow dr2 = ls_Particel_dt.NewRow();
  463. dr2["SName"] = ls_gv.Rows[i].Cells[1].Value.ToString();
  464. dr2["Largest"] = ls_gv.Rows[i].Cells[4].Value.ToString();
  465. dr2["Hardness"] = ls_gv.Rows[i].Cells[6].Value.ToString();
  466. dr2["Density"] = ls_gv.Rows[i].Cells[7].Value.ToString();
  467. dr2["Conductivity"] = ls_gv.Rows[i].Cells[8].Value.ToString();
  468. int col2 = 6;
  469. for (int j = 1; j < 11; j++)
  470. {
  471. if (ls_gv.Columns.Count > col2)
  472. if(j<10)
  473. dr2["c" + j.ToString()] = ls_gv.Rows[i].Cells[col2++].Value.ToString();
  474. }
  475. //total,不为空行,和不能是总计行
  476. if (dr2["SName"].ToString() != "" && dr2["SName"].ToString().IndexOf("个数") < 0)
  477. {
  478. dr2["total"] = "0"; //求合
  479. double d_total = 0;
  480. int col3 = 6;
  481. for (int j = 1; j < 11; j++)
  482. {
  483. if (ls_gv.Columns.Count > col3)
  484. d_total = d_total + Convert.ToInt64(ls_gv.Rows[i].Cells[col3++].Value.ToString());
  485. }
  486. dr2["total"] = d_total.ToString();
  487. }
  488. ls_Particel_dt.Rows.Add(dr2);
  489. }
  490. m_list_dt.Add(ls_partsize_dt);
  491. m_list_dt.Add(ls_Particel_dt);
  492. return true;
  493. }
  494. catch (Exception ee)
  495. {
  496. m_otsreport_export.WriteRictBox(ee.ToString());
  497. return false;
  498. }
  499. }
  500. #endregion
  501. #region 插入平均元素含量表
  502. /// <summary>
  503. /// 向 模板设计器 中插入 平均元素含量表
  504. /// </summary>
  505. /// <returns></returns>
  506. public bool InsertReportTemplateTable_ElementCompositionAvgGrid()
  507. {
  508. try
  509. {
  510. //加载模块
  511. ElementCompositionAvgGrid ls_elementcompositionavggrid = new ElementCompositionAvgGrid(m_otsreport_export.m_ReportApp);
  512. //List<string> vs = new List<string>() { "DMAX", "DMIN", "Area", "FERET" };
  513. //ls_elementcompositionavggrid.condition = vs[m_otsreport_export.m_mbszclass.M_YSFXJG.index_cb_yxfx_jsfs];
  514. m_otsreport_export.panel_container.Controls.Clear();
  515. m_otsreport_export.panel_container.Controls.Add(ls_elementcompositionavggrid);
  516. DataGridView ls_gv = new DataGridView();
  517. DataTable ls_dt = new DataTable();
  518. ls_elementcompositionavggrid.GetDataTableAndGridView(out ls_dt, out ls_gv);
  519. //------------------------------------------------
  520. DataTable ls_elementname_dt = new DataTable();
  521. ls_elementname_dt.TableName = "ElementName";
  522. ls_elementname_dt.Columns.Add("e1");
  523. ls_elementname_dt.Columns.Add("e2");
  524. ls_elementname_dt.Columns.Add("e3");
  525. ls_elementname_dt.Columns.Add("e4");
  526. ls_elementname_dt.Columns.Add("e5");
  527. ls_elementname_dt.Columns.Add("e6");
  528. ls_elementname_dt.Columns.Add("e7");
  529. ls_elementname_dt.Columns.Add("e8");
  530. ls_elementname_dt.Columns.Add("e9");
  531. DataRow dr = ls_elementname_dt.NewRow();
  532. int col = 5;
  533. for (int i = 1; i < 10; i++)
  534. {
  535. if (ls_gv.Columns.Count > col)
  536. dr["e" + i.ToString()] = ls_gv.Columns[col++].Name;
  537. }
  538. ls_elementname_dt.Rows.Add(dr);
  539. DataTable ls_element_dt = new DataTable();
  540. ls_element_dt.TableName = "ElementValue";
  541. ls_element_dt.Columns.Add("e1");
  542. ls_element_dt.Columns.Add("e2");
  543. ls_element_dt.Columns.Add("e3");
  544. ls_element_dt.Columns.Add("e4");
  545. ls_element_dt.Columns.Add("e5");
  546. ls_element_dt.Columns.Add("e6");
  547. ls_element_dt.Columns.Add("e7");
  548. ls_element_dt.Columns.Add("e8");
  549. ls_element_dt.Columns.Add("e9");
  550. ls_element_dt.Columns.Add("PName");
  551. ls_element_dt.Columns.Add("Count");
  552. for (int i = 0; i < ls_gv.Rows.Count; i++)
  553. {
  554. DataRow dr2 = ls_element_dt.NewRow();
  555. dr2["PName"] = ls_gv.Rows[i].Cells[1].Value.ToString();
  556. dr2["Count"] = ls_gv.Rows[i].Cells[2].Value.ToString();
  557. int colq = 5;
  558. for (int j = 1; j < 10; j++)
  559. {
  560. if (ls_gv.Columns.Count > colq)
  561. dr2["e" + j.ToString()] = ls_gv.Rows[i].Cells[colq++].Tag.ToString();
  562. }
  563. ls_element_dt.Rows.Add(dr2);
  564. }
  565. m_list_dt.Add(ls_elementname_dt);
  566. m_list_dt.Add(ls_element_dt);
  567. return true;
  568. }
  569. catch (Exception ee)
  570. {
  571. m_otsreport_export.WriteRictBox(ee.ToString());
  572. return false;
  573. }
  574. }
  575. #endregion
  576. #region 插入颗粒图chart
  577. /// <summary>
  578. /// 用于颗粒图chart
  579. /// </summary>
  580. /// <returns></returns>
  581. private DataTable GetPicDataTable_PicKL()
  582. {
  583. if (m_list_dt.Where(aa => aa.TableName.Contains("PicKL")).ToList().Count == 0)
  584. {
  585. //创建二进制列的数据表
  586. DataTable ls_dt = new DataTable();
  587. ls_dt.TableName = "PicKL";
  588. DataColumn colpict = new DataColumn("pict");
  589. colpict.DataType = System.Type.GetType("System.Byte[]");
  590. ls_dt.Columns.Add(colpict);
  591. m_list_dt.Add(ls_dt);
  592. return ls_dt;
  593. }
  594. else
  595. {
  596. return m_list_dt.Where(aa => aa.TableName.Contains("PicKL")).ToList()[0];
  597. }
  598. }
  599. #endregion
  600. #region 插入元素图chart
  601. /// <summary>
  602. /// 用于元素图chart
  603. /// </summary>
  604. /// <returns></returns>
  605. private DataTable GetPicDataTable_PicYS()
  606. {
  607. if (m_list_dt.Where(aa => aa.TableName.Contains("PicYS")).ToList().Count == 0)
  608. {
  609. //创建二进制列的数据表
  610. DataTable ls_dt = new DataTable();
  611. ls_dt.TableName = "PicYS";
  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("PicYS")).ToList()[0];
  621. }
  622. }
  623. #endregion
  624. #region 插入颗粒成份图
  625. /// <summary>
  626. /// 向 模板设计器 中插入 颗粒成份图
  627. /// </summary>
  628. /// <returns></returns>
  629. public bool InsertReportTemplateChart_ParticlesCompositionChart(string a_GraphicStyle)
  630. {
  631. try
  632. {
  633. //-----------------------------------颗粒成份图-----------------------------------------------------------------------------------------------
  634. //加载模块
  635. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition = new EChart_ParticlesComposition(m_otsreport_export.m_ReportApp, "PComponent");
  636. m_otsreport_export.m_ReportApp.m_reportname = "InclusionClassification";
  637. m_otsreport_export.m_ReportApp.type = a_GraphicStyle;
  638. m_otsreport_export.m_ReportApp.timerKG = true;
  639. m_otsreport_export.m_ReportApp.m_CChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition);
  640. //弹出加载图片窗体
  641. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  642. //将EChart委托事件注册给加载图片窗体的方法
  643. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition.butclic += og.get_ParticalesCompositionChart;
  644. og.ShowDialog();
  645. //获取图片数据
  646. string str = og.PicStr;
  647. //将Base64String转为图片并保存
  648. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  649. MemoryStream ms = new MemoryStream(arr);
  650. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  651. //再将图转成流,流再转二进制-------------------------------------------
  652. MemoryStream newms = new MemoryStream();
  653. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  654. newms.Seek(0, SeekOrigin.Begin);
  655. byte[] newarr = new byte[newms.Length];
  656. newms.Read(newarr, 0, newarr.Length);
  657. newms.Dispose();
  658. //创建二进制列的数据表
  659. DataTable ls_dt = GetPicDataTable_PicKL();
  660. DataRow dr = ls_dt.NewRow();
  661. dr["pict"] = newarr;//图像二进制
  662. ls_dt.Rows.Add(dr);
  663. return true;
  664. }
  665. catch (Exception ee)
  666. {
  667. m_otsreport_export.WriteRictBox(ee.ToString());
  668. return false;
  669. }
  670. }
  671. #endregion
  672. #region 插入元素成份图
  673. /// <summary>
  674. /// 向 模板设计器 中插入 元素成份图
  675. /// </summary>
  676. /// <returns></returns>
  677. public bool InsertReportTemplateChart_ElementCompositionChart(string a_GraphicStyle)
  678. {
  679. try
  680. {
  681. //-----------------------------------元素成份图-----------------------------------------------------------------------------------------------
  682. //加载模块
  683. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition = new EChart_ParticlesComposition(m_otsreport_export.m_ReportApp, "EComponent");
  684. m_otsreport_export.m_ReportApp.m_reportname = "ElementComposition";
  685. m_otsreport_export.m_ReportApp.type = a_GraphicStyle;
  686. m_otsreport_export.m_ReportApp.timerKG = true;
  687. m_otsreport_export.m_ReportApp.m_CChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition);
  688. //弹出加载图片窗体
  689. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  690. //将EChart委托事件注册给加载图片窗体的方法
  691. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition.butclic += og.get_ParticalesCompositionChart;
  692. og.ShowDialog();
  693. //获取图片数据
  694. string str = og.PicStr;
  695. //将Base64String转为图片并保存
  696. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  697. MemoryStream ms = new MemoryStream(arr);
  698. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  699. //再将图转成流,流再转二进制-------------------------------------------
  700. MemoryStream newms = new MemoryStream();
  701. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  702. newms.Seek(0, SeekOrigin.Begin);
  703. byte[] newarr = new byte[newms.Length];
  704. newms.Read(newarr, 0, newarr.Length);
  705. newms.Dispose();
  706. //创建二进制列的数据表
  707. DataTable ls_dt = GetPicDataTable_PicYS();
  708. DataRow dr = ls_dt.NewRow();
  709. dr["pict"] = newarr;//图像二进制
  710. ls_dt.Rows.Add(dr);
  711. return true;
  712. }
  713. catch (Exception ee)
  714. {
  715. m_otsreport_export.WriteRictBox(ee.ToString());
  716. return false;
  717. }
  718. }
  719. #endregion
  720. #region 插入三元相图
  721. /// <summary>
  722. /// 获取或创建pic表格,用于三元相图
  723. /// </summary>
  724. /// <returns></returns>
  725. private DataTable GetPicDataTable_PicSYXT2T()
  726. {
  727. if (m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT2T")).ToList().Count == 0)
  728. {
  729. //创建二进制列的数据表
  730. DataTable ls_dt = new DataTable();
  731. ls_dt.TableName = "PicSYXT2T";
  732. DataColumn colpict = new DataColumn("pict");
  733. colpict.DataType = System.Type.GetType("System.Byte[]");
  734. ls_dt.Columns.Add(colpict);
  735. DataColumn colpict2 = new DataColumn("pict2");
  736. colpict2.DataType = System.Type.GetType("System.Byte[]");
  737. ls_dt.Columns.Add(colpict2);
  738. m_list_dt.Add(ls_dt);
  739. return ls_dt;
  740. }
  741. else
  742. {
  743. return m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT2T")).ToList()[0];
  744. }
  745. }
  746. /// <summary>
  747. /// 获取或创建pic表格,用于三元相图,3个列的
  748. /// </summary>
  749. /// <returns></returns>
  750. private DataTable GetPicDataTable_PicSYXT3T()
  751. {
  752. if (m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT3T")).ToList().Count == 0)
  753. {
  754. //创建二进制列的数据表
  755. DataTable ls_dt = new DataTable();
  756. ls_dt.TableName = "PicSYXT3T";
  757. DataColumn colpict = new DataColumn("pict");
  758. colpict.DataType = System.Type.GetType("System.Byte[]");
  759. ls_dt.Columns.Add(colpict);
  760. DataColumn colpict2 = new DataColumn("pict2");
  761. colpict2.DataType = System.Type.GetType("System.Byte[]");
  762. ls_dt.Columns.Add(colpict2);
  763. DataColumn colpict3 = new DataColumn("pict3");
  764. colpict3.DataType = System.Type.GetType("System.Byte[]");
  765. ls_dt.Columns.Add(colpict3);
  766. m_list_dt.Add(ls_dt);
  767. return ls_dt;
  768. }
  769. else
  770. {
  771. return m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT")).ToList()[0];
  772. }
  773. }
  774. /// <summary>
  775. /// 获取三元相图二进制数据
  776. /// </summary>
  777. /// <param name="selectindex"></param>
  778. /// <returns></returns>
  779. private byte[] GetByte_InsertReportTemplateChart_Trianglediagram(int selectindex)
  780. {
  781. byte[] newarr = new byte[0];
  782. //加载模块
  783. m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram = new EChart_Trianglediagram(m_otsreport_export.m_ReportApp, TemplateList[selectindex]);
  784. m_otsreport_export.m_ReportApp.timerKG = true;
  785. m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram.condition = m_otsreport_export.m_mbszclass.M_SYXT.index_cb_syxt_jsfs;
  786. m_otsreport_export.m_ReportApp.m_CChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram);
  787. //ls_echart_trianglediagram.
  788. //弹出加载图片窗体
  789. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  790. //将EChart委托事件注册给加载图片窗体的方法
  791. m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram.butclic += og.get_ParticalesCompositionChart;
  792. og.ShowDialog();
  793. //获取图片数据
  794. string str = og.PicStr;
  795. //将Base64String转为图片并保存
  796. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  797. MemoryStream ms = new MemoryStream(arr);
  798. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  799. //再将图转成流,流再转二进制-------------------------------------------
  800. MemoryStream newms = new MemoryStream();
  801. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  802. newms.Seek(0, SeekOrigin.Begin);
  803. newarr = new byte[newms.Length];
  804. newms.Read(newarr, 0, newarr.Length);
  805. newms.Dispose();
  806. return newarr;
  807. }
  808. /// <summary>
  809. /// 向 模板设计器 中插入 三元相图
  810. /// </summary>
  811. /// <returns></returns>
  812. public bool InsertReportTemplateChart_Trianglediagram()
  813. {
  814. try
  815. {
  816. //创建二进制列的数据表,循环插入三元选择的模板
  817. DataTable ls_dt = GetPicDataTable_PicSYXT2T();
  818. DataTable ls_dt3t = GetPicDataTable_PicSYXT3T();
  819. //这里要校验一下,总数必须要是2的整倍数,不可有余数
  820. 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)
  821. {
  822. for (int i = 0; i < m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index.Count; i = i + 2)
  823. {
  824. byte[] newarr, newarr2;
  825. newarr = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i]);
  826. newarr2 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 1]);
  827. DataRow dr = ls_dt.NewRow();
  828. dr["pict"] = newarr;//图像二进制
  829. dr["pict2"] = newarr2;//图像二进制
  830. ls_dt.Rows.Add(dr);
  831. }
  832. }
  833. else
  834. {
  835. DataRow dr = ls_dt.NewRow();
  836. dr["pict"] = null;//图像二进制
  837. dr["pict2"] = null;//图像二进制
  838. ls_dt.Rows.Add(dr);
  839. }
  840. 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)
  841. {
  842. for (int i = 0; i < m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index.Count; i = i + 3)
  843. {
  844. byte[] newarr, newarr2, newarr3;
  845. newarr = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i]);
  846. newarr2 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 1]);
  847. newarr3 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 2]);
  848. DataRow dr = ls_dt3t.NewRow();
  849. dr["pict"] = newarr;//图像二进制
  850. dr["pict2"] = newarr2;//图像二进制
  851. dr["pict3"] = newarr3;//图像二进制
  852. ls_dt3t.Rows.Add(dr);
  853. }
  854. }
  855. else
  856. {
  857. DataRow dr = ls_dt3t.NewRow();
  858. dr["pict"] = null;//图像二进制
  859. dr["pict2"] = null;//图像二进制
  860. dr["pict3"] = null;//图像二进制
  861. ls_dt3t.Rows.Add(dr);
  862. }
  863. return true;
  864. }
  865. catch (Exception ee)
  866. {
  867. m_otsreport_export.WriteRictBox(ee.ToString());
  868. return false;
  869. }
  870. }
  871. #endregion
  872. #region 其它部份
  873. ///// <summary>
  874. ///// 获取夹杂物总数量,报告中暂时固定导出100数量,如果需要导出全部颗粒,到颗粒列表中导出Excel使用
  875. ///// </summary>
  876. ///// <returns></returns>
  877. //public int GetReportTemplateTable_ParticlesNumber()
  878. //{
  879. // return 100;
  880. //}
  881. /// <summary>
  882. /// 输入颗粒的所在帧图id,颗粒id,颗粒类型id,获取对应的XRay能谱数据图
  883. /// </summary>
  884. /// <returns></returns>
  885. public Bitmap ExportXRayBitmap(string in_fieldid, string in_particleid, int in_stdtypeid, string TypeName, ParticleData particleData)
  886. {
  887. Bitmap ret_bp;
  888. //显示xray相关信息
  889. uint[] Search_xray = new uint[2000];
  890. uint[] Analysis_xray = new uint[2000];
  891. //
  892. int i_xray_id = 0;
  893. List<Element> list_celementchemistryclr = new List<Element>();
  894. //获取Xray数据
  895. list_celementchemistryclr = new List<Element>();
  896. Particle list = particleData.GetParticleByFidAndPid(in_fieldid, in_particleid);
  897. if (list == null)
  898. {
  899. return null;
  900. }
  901. Particle particle = list;
  902. if (particle.XrayId > -1)
  903. {
  904. for (int i = 0; i < 2000; i++)
  905. {
  906. Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
  907. }
  908. Search_xray = Analysis_xray;
  909. i_xray_id = particle.XrayId;
  910. list_celementchemistryclr = particle.ElementList;
  911. }
  912. //get CElementChemistryClr list
  913. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  914. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  915. {
  916. ShowElementInfo ls_sei = new ShowElementInfo();
  917. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  918. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  919. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX1);
  920. list_showelementinfo.Add(ls_sei);
  921. }
  922. //获取使用标准库的名称
  923. string str_stdname = "";
  924. string str_IncALibName = "";
  925. if (in_stdtypeid < 1000)
  926. {
  927. //小于1000,使用系统默认分类
  928. str_IncALibName = TypeName;
  929. str_stdname = "Default standard library";
  930. }
  931. else if (in_stdtypeid >= 1000 && in_stdtypeid < 10000)
  932. {
  933. //大于等于1000,并且小于10000时,使用系统数据库中夹杂物来分析
  934. str_IncALibName = TypeName;
  935. str_stdname = "User defined standard library";
  936. }
  937. else if (in_stdtypeid > 10000)
  938. {
  939. //大于10000时,使用用户标准库来分析夹杂物名称
  940. str_IncALibName = TypeName;
  941. str_stdname = "System standard library";
  942. }
  943. //获取数据后,需要对xraytable设置
  944. OTSIncAReportGraph.Controls.Control_XRayTable control_XRayTable1 = new Control_XRayTable();
  945. control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray, list_showelementinfo);
  946. //颗粒国标信息
  947. //control_XRayTable1.GBInfoStr = in_dparticle.GBContent;
  948. control_XRayTable1.GoodName = str_IncALibName;//杂夹物
  949. control_XRayTable1.STDName = str_stdname;//标准库
  950. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  951. control_XRayTable1.Visible = true;
  952. control_XRayTable1.Invalidate();
  953. control_XRayTable1.Refresh();
  954. ret_bp = control_XRayTable1.ExportXRayImage();
  955. return ret_bp;
  956. }
  957. /// <summary>
  958. /// 导出二次放大图像
  959. /// </summary>
  960. /// <param name="str_srcPathName"></param>
  961. /// <param name="str_outPathName"></param>
  962. public void ParticleReZoom(string str_srcPathName, string str_outPathName)
  963. {
  964. //m_COTSReportProjFileMgrClr.ReZoom(str_srcPathName, str_outPathName);
  965. }
  966. /// <summary>
  967. /// 传入DataTable,和行号,返回该Row行中,返回6个靠前的元素,不足6个返回空
  968. /// </summary>
  969. /// <param name="in_dt"></param>
  970. /// <param name="row_index"></param>
  971. /// <returns></returns>
  972. private void GetMaxElementFromDataTable(DataTable in_dt, int row_index, out List<string> out_list_elementname, out List<double> out_list_elementvalue)
  973. {
  974. out_list_elementname = new List<string>();
  975. out_list_elementvalue = new List<double>();
  976. //分别排出元素名,元素值列表
  977. List<string> list_elementname = new List<string>();
  978. List<double> list_elementvalue = new List<double>();
  979. string str_element = in_dt.Rows[row_index]["Element"].ToString();
  980. //防止取出的元素信息为空
  981. if (str_element != "")
  982. {
  983. string[] strcbo = str_element.Split(';');
  984. for (int i = 0; i < strcbo.Length; i++)
  985. {
  986. string[] str = strcbo[i].Split('-');
  987. list_elementname.Add(str[0]);
  988. list_elementvalue.Add(Math.Round(Convert.ToDouble(str[1]), 2));
  989. }
  990. }
  991. //循环6次,得到最大的6个元素信息
  992. for (int geti = 0; geti < 6; geti++)
  993. {
  994. double max_elementvalue = -1;
  995. string max_elementname = "";
  996. int max_index = -1;
  997. if (list_elementvalue.Count > 1)
  998. {
  999. for (int i = 0; i < list_elementvalue.Count; i++)
  1000. {
  1001. if (list_elementvalue[i] > max_elementvalue)
  1002. {
  1003. max_elementvalue = list_elementvalue[i];
  1004. max_elementname = list_elementname[i];
  1005. max_index = i;
  1006. }
  1007. }
  1008. //移除掉最大的元素
  1009. list_elementname.RemoveAt(max_index);
  1010. list_elementvalue.RemoveAt(max_index);
  1011. //将最大的元素添加到list中
  1012. if (max_elementvalue > 0)
  1013. {
  1014. out_list_elementname.Add(max_elementname);
  1015. out_list_elementvalue.Add(max_elementvalue);
  1016. }
  1017. else
  1018. {
  1019. out_list_elementname.Add(" ");
  1020. out_list_elementvalue.Add(0);
  1021. }
  1022. }
  1023. else
  1024. {
  1025. //如果元素数量已经不够,则添加空
  1026. out_list_elementname.Add(" ");
  1027. out_list_elementvalue.Add(0);
  1028. }
  1029. }
  1030. }
  1031. /// <summary>
  1032. /// 传入DataTable和想要找到的列名,返回对应列的索引
  1033. /// </summary>
  1034. /// <param name="in_dt"></param>
  1035. /// <param name="in_str"></param>
  1036. /// <returns></returns>
  1037. private int GetDataTableColumnsIndexByName(DataTable in_dt, string in_str)
  1038. {
  1039. int i_ret = -1;
  1040. for (int i = 0; i < in_dt.Columns.Count; i++)
  1041. {
  1042. if (in_dt.Columns[i].ColumnName.IndexOf(in_str) > -1)
  1043. {
  1044. //找到
  1045. i_ret = i;
  1046. break;
  1047. }
  1048. }
  1049. return i_ret;
  1050. }
  1051. /// <summary>
  1052. /// 传入DataTable和想要的元素第几个排列,返回对应的列的索引
  1053. /// </summary>
  1054. /// <param name="in_dt"></param>
  1055. /// <param name="in_str"></param>
  1056. /// <returns></returns>
  1057. private int GetDataTableColumnsIndexByElementNumber(DataTable in_dt, int in_elementorder)
  1058. {
  1059. int i_ret = -1;
  1060. int i_findcount = 0;//第几次找到的记数
  1061. //首先遍历所有的datatable中的元素
  1062. for (int i = 0; i < in_dt.Columns.Count; i++)
  1063. {
  1064. //然后遍历该列是否是元素名,要显示的元素名
  1065. for (int k = 0; k < m_otsreport_export.m_mbszclass.M_KLLBXX.list_str_tb_lllb_sxys.Count; k++)
  1066. {
  1067. if (in_dt.Columns[i].ColumnName.ToString().ToUpper() == m_otsreport_export.m_mbszclass.M_KLLBXX.list_str_tb_lllb_sxys[k].ToUpper())
  1068. {
  1069. //找到了
  1070. if (i_findcount == in_elementorder)
  1071. {
  1072. //并且达到了想找的第几个序列,返回对应的列的索引
  1073. i_ret = i;
  1074. return i_ret;
  1075. }
  1076. else
  1077. {
  1078. //否则,找到的索引号增长
  1079. i_findcount++;
  1080. }
  1081. }
  1082. }
  1083. }
  1084. return i_ret;
  1085. }
  1086. #endregion
  1087. }
  1088. }