Export_ReportTemplate.cs 56 KB

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