Export_ReportTemplate.cs 62 KB

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