Export_ReportTemplate.cs 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578
  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_field_dt_copy = new DataTable();
  125. DataTable DT_Largest_frame = new DataTable();
  126. DT_Largest_frame.TableName = "Largest_frame";
  127. DT_Largest_frame.Columns.Add("pid");
  128. DT_Largest_frame.Columns.Add("Size");
  129. DT_Largest_frame.Columns.Add("Width");
  130. DT_Largest_frame.Columns.Add("DMAX");
  131. DT_Largest_frame.Columns.Add("DMIN");
  132. DT_Largest_frame.Columns.Add("Class");
  133. DT_Largest_frame.Columns.Add("ColName1");
  134. DT_Largest_frame.Columns.Add("ColName2");
  135. DT_Largest_frame.Columns.Add("ColName3");
  136. DT_Largest_frame.Columns.Add("ColName4");
  137. DT_Largest_frame.Columns.Add("ColName5");
  138. DT_Largest_frame.Columns.Add("ColName6");
  139. DT_Largest_frame.Columns.Add("ColVal1");
  140. DT_Largest_frame.Columns.Add("ColVal2");
  141. DT_Largest_frame.Columns.Add("ColVal3");
  142. DT_Largest_frame.Columns.Add("ColVal4");
  143. DT_Largest_frame.Columns.Add("ColVal5");
  144. DT_Largest_frame.Columns.Add("ColVal6");
  145. DataColumn colpictid = new DataColumn("FieldId");
  146. colpictid.DataType = typeof(int);
  147. DT_Largest_frame.Columns.Add(colpictid);
  148. //图像列
  149. DataColumn colpict = new DataColumn("p1");
  150. colpict.DataType = System.Type.GetType("System.Byte[]");
  151. DT_Largest_frame.Columns.Add(colpict);
  152. //largest20表:(无关系表) 需要显示前20条带有显示能谱图像的颗粒表
  153. DataTable DT_Largest20 = new DataTable();
  154. DT_Largest20.TableName = "Largest20";
  155. DT_Largest20.Columns.Add("pid");
  156. DT_Largest20.Columns.Add("Size");
  157. DT_Largest20.Columns.Add("Width");
  158. DT_Largest20.Columns.Add("DMAX");
  159. DT_Largest20.Columns.Add("DMIN");
  160. DT_Largest20.Columns.Add("Class");
  161. DT_Largest20.Columns.Add("ColName1");
  162. DT_Largest20.Columns.Add("ColName2");
  163. DT_Largest20.Columns.Add("ColName3");
  164. DT_Largest20.Columns.Add("ColName4");
  165. DT_Largest20.Columns.Add("ColName5");
  166. DT_Largest20.Columns.Add("ColName6");
  167. DT_Largest20.Columns.Add("ColVal1");
  168. DT_Largest20.Columns.Add("ColVal2");
  169. DT_Largest20.Columns.Add("ColVal3");
  170. DT_Largest20.Columns.Add("ColVal4");
  171. DT_Largest20.Columns.Add("ColVal5");
  172. DT_Largest20.Columns.Add("ColVal6");
  173. // 图像列
  174. DataColumn colpict_20ago = new DataColumn("p1");
  175. colpict_20ago.DataType = System.Type.GetType("System.Byte[]");
  176. DT_Largest20.Columns.Add(colpict_20ago);
  177. DataColumn colpict2_20ago = new DataColumn("p2");
  178. colpict2_20ago.DataType = System.Type.GetType("System.Byte[]");
  179. DT_Largest20.Columns.Add(colpict2_20ago);
  180. DataColumn colpict3_20ago = new DataColumn("p3");
  181. colpict3_20ago.DataType = System.Type.GetType("System.Byte[]");
  182. DT_Largest20.Columns.Add(colpict3_20ago);
  183. #endregion
  184. #region 插入-前20颗粒部份
  185. for (int i_row = 0; i_row < dt_ParticlesGridDevidePage.Rows.Count; i_row++)
  186. {
  187. if (dt_ParticlesGridDevidePage.Rows[i_row].ItemArray[24].ToString()!= "Not Identified")
  188. {
  189. //获取颗粒的fieldid,和particleid
  190. string str_fieldid = dt_ParticlesGridDevidePage.Rows[i_row]["fieldid"].ToString();
  191. string str_particleid = dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  192. string str_subparticles = dt_ParticlesGridDevidePage.Rows[i_row]["SubParticles"].ToString();
  193. string str_typeid = dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString();
  194. string str_typename = dt_ParticlesGridDevidePage.Rows[i_row]["TypeName"].ToString();
  195. string str_element = dt_ParticlesGridDevidePage.Rows[i_row]["Element"].ToString();
  196. //获取原始颗粒图像
  197. Bitmap bp_particle = new Bitmap(1, 1);
  198. string str_path = str_resultPath + "\\FIELD_FILES\\";
  199. string str_imagePath = str_path + "Field" + str_fieldid.ToString() + ".bmp";
  200. if (str_fieldid == "-1")
  201. continue;
  202. if (serialNumber > 20)
  203. continue;
  204. if (str_subparticles != null && str_subparticles != "")
  205. {
  206. //合并大颗粒
  207. double ScanFieldSize = 1142;
  208. Bitmap tempbit = fielddata.ReadImageFile(str_imagePath);
  209. int pixw = tempbit.Width;
  210. double xs = pixw / ScanFieldSize;
  211. bp_particle = fielddata.GetBitmapForBig(str_subparticles, xs, str_resultPath);
  212. }
  213. else
  214. {
  215. //正常颗粒
  216. 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"]) };
  217. Bitmap bp_field = fielddata.ReadImageFile(str_imagePath);
  218. bp_particle = fielddata.GetBitmapByParticle(bp_field, rectangle);
  219. 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() };
  220. }
  221. //获取该颗粒的xray能谱图像
  222. System.Drawing.Bitmap bp_xraybp = ExportXRayBitmap(str_fieldid,
  223. str_particleid, Convert.ToInt32(str_typeid), str_typename, fielddata);
  224. Bitmap ls_xraybpnew = new Bitmap(1, 1);
  225. ls_xraybpnew = OTSIncAReportGraph.Class.DrawFunction.KiResizeImage(bp_xraybp, 700, 115);//能谱图处理
  226. //获取该颗粒的二次放大处理图像
  227. Bitmap ls_processbitmap = new Bitmap(1, 1);
  228. ls_processbitmap = OTSIncAReportGraph.Class.DrawFunction.GetReZoomBitmap(bp_particle);// (Bitmap)bp_particle.Clone();//待完善
  229. //再将图像转成二进制流-------------------------------------------------------------------
  230. //原图
  231. MemoryStream newms_p1 = new MemoryStream();
  232. bp_particle.Save(newms_p1, System.Drawing.Imaging.ImageFormat.Bmp);
  233. newms_p1.Seek(0, SeekOrigin.Begin);
  234. byte[] newarr_p1 = new byte[newms_p1.Length];
  235. newms_p1.Read(newarr_p1, 0, newarr_p1.Length);
  236. //二次放大图
  237. MemoryStream newms_p2 = new MemoryStream();
  238. ls_processbitmap.Save(newms_p2, System.Drawing.Imaging.ImageFormat.Bmp);
  239. newms_p2.Seek(0, SeekOrigin.Begin);
  240. byte[] newarr_p2 = new byte[newms_p2.Length];
  241. newms_p2.Read(newarr_p2, 0, newarr_p2.Length);
  242. //能谱图
  243. MemoryStream newms_p3 = new MemoryStream();
  244. ls_xraybpnew.Save(newms_p3, System.Drawing.Imaging.ImageFormat.Bmp);
  245. newms_p3.Seek(0, SeekOrigin.Begin);
  246. byte[] newarr_p3 = new byte[newms_p3.Length];
  247. newms_p3.Read(newarr_p3, 0, newarr_p3.Length);
  248. //---------------------------------------------------------------------------------------
  249. DataRow dr = DT_Largest20.NewRow();
  250. dr["p1"] = newarr_p1;
  251. dr["p2"] = newarr_p2;
  252. dr["p3"] = newarr_p3;
  253. newms_p1.Dispose();
  254. newms_p2.Dispose();
  255. newms_p3.Dispose();
  256. dr["pid"] = serialNumber++.ToString();
  257. //dr["pid"] = str_fieldid + dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  258. dr["Size"] = Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["area"]).ToString("#0.00"); //可以需要选择切换,计算方式
  259. dr["Width"] = dt_ParticlesGridDevidePage.Rows[i_row]["rectwidth"].ToString();
  260. dr["DMAX"] = Math.Round(Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["dmax"]), 2).ToString();
  261. dr["DMIN"] = Math.Round(Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["dmin"]), 2).ToString();
  262. dr["Class"] = dt_ParticlesGridDevidePage.Rows[i_row]["typename"].ToString();
  263. List<string> list_max_elementname = new List<string>();
  264. List<double> list_max_elementvale = new List<double>();
  265. GetMaxElementFromDataTable(dt_ParticlesGridDevidePage, i_row, out list_max_elementname, out list_max_elementvale);
  266. //元素1
  267. dr["ColName1"] = list_max_elementname[0];
  268. dr["ColVal1"] = list_max_elementvale[0].ToString();
  269. //元素2
  270. dr["ColName2"] = list_max_elementname[1];
  271. dr["ColVal2"] = list_max_elementvale[1].ToString();
  272. //元素3
  273. dr["ColName3"] = list_max_elementname[2];
  274. dr["ColVal3"] = list_max_elementvale[2].ToString();
  275. //元素4
  276. dr["ColName4"] = list_max_elementname[3];
  277. dr["ColVal4"] = list_max_elementvale[3].ToString();
  278. //元素5
  279. dr["ColName5"] = list_max_elementname[4];
  280. dr["ColVal5"] = list_max_elementvale[4].ToString();
  281. //元素6
  282. dr["ColName6"] = list_max_elementname[5];
  283. dr["ColVal6"] = list_max_elementvale[5].ToString();
  284. DT_Largest20.Rows.Add(dr);
  285. }
  286. }
  287. #endregion
  288. #region 插入-帧图图像部份
  289. //首先生成标记颗粒的帧图图像文件
  290. m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage.SaveMarkParticleRectangleOnFieldFile(dt_ParticlesGridDevidePage);
  291. string str_path_FIELD_FILES_MARK = str_resultPath + "\\FIELD_FILES_MARK\\";
  292. DirectoryInfo theFolder = new DirectoryInfo(str_path_FIELD_FILES_MARK);
  293. if (theFolder.Exists)
  294. {
  295. //for (int i = 0; i <= theFolder.GetFiles().Count(); i++)
  296. //{
  297. // //判断i.bmp图片是否存在,如果不存在跳出当前循环
  298. // if (!DetermineWhetherTheFileExists(theFolder, i))
  299. // continue;
  300. // //在数据表中有颗粒在该帧图中的话,则对该帧图标记图像进行读取存入数据库
  301. // DataRow[] datarowlist = dt_ParticlesGridDevidePage.Select(" fieldid = " + i);
  302. // if (datarowlist.Count() > 0)
  303. // {
  304. // Bitmap ls_bp_fieldmark = new Bitmap(theFolder.GetFiles()[i].FullName);
  305. // DataRow dr = DT_field_dt.NewRow();
  306. // MemoryStream newms_bp_fieldmark = new MemoryStream();
  307. // ls_bp_fieldmark.Save(newms_bp_fieldmark, System.Drawing.Imaging.ImageFormat.Bmp);
  308. // newms_bp_fieldmark.Seek(0, SeekOrigin.Begin);
  309. // byte[] newarr_fieldmark = new byte[newms_bp_fieldmark.Length];
  310. // newms_bp_fieldmark.Read(newarr_fieldmark, 0, newarr_fieldmark.Length);
  311. // dr["FieldImg"] = newarr_fieldmark;
  312. // dr["FieldId"] = i;
  313. // ls_bp_fieldmark.Dispose();
  314. // DT_field_dt.Rows.Add(dr);
  315. // }
  316. //}
  317. foreach (FileInfo nextifile in theFolder.GetFiles())
  318. {
  319. if (nextifile.Name.Contains(".bmp") == true || nextifile.Name.Contains(".BMP") == true)
  320. {
  321. //确认对应的帧图名
  322. string str_fieldid = Path.GetFileNameWithoutExtension(nextifile.Name);
  323. //在数据表中有颗粒在该帧图中的话,则对该帧图标记图像进行读取存入数据库
  324. DataRow[] datarowlist = dt_ParticlesGridDevidePage.Select(" fieldid = " + str_fieldid);
  325. if (datarowlist.Count() > 0)
  326. {
  327. Bitmap ls_bp_fieldmark = new Bitmap(nextifile.FullName);
  328. DataRow dr = DT_field_dt.NewRow();
  329. MemoryStream newms_bp_fieldmark = new MemoryStream();
  330. ls_bp_fieldmark.Save(newms_bp_fieldmark, System.Drawing.Imaging.ImageFormat.Bmp);
  331. newms_bp_fieldmark.Seek(0, SeekOrigin.Begin);
  332. byte[] newarr_fieldmark = new byte[newms_bp_fieldmark.Length];
  333. newms_bp_fieldmark.Read(newarr_fieldmark, 0, newarr_fieldmark.Length);
  334. dr["FieldImg"] = newarr_fieldmark;
  335. dr["FieldId"] = str_fieldid;
  336. ls_bp_fieldmark.Dispose();
  337. DT_field_dt.Rows.Add(dr);
  338. }
  339. }
  340. }
  341. DataView vw = DT_field_dt.DefaultView;
  342. vw.Sort = "FieldId ASC";
  343. DT_field_dt_copy = vw.ToTable();
  344. }
  345. #endregion
  346. #region 插入-前20颗粒外的颗粒
  347. for (int i_row = 0; i_row < dt_ParticlesGridDevidePage.Rows.Count; i_row++)
  348. {
  349. if (dt_ParticlesGridDevidePage.Rows[i_row]["element"].ToString() == "")
  350. continue;
  351. //获取颗粒的fieldid,和particleid
  352. string str_fieldid = dt_ParticlesGridDevidePage.Rows[i_row]["fieldid"].ToString();
  353. if (Convert.ToInt32(str_fieldid) < 20)
  354. {
  355. string str_particleid = dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  356. string str_subparticles = dt_ParticlesGridDevidePage.Rows[i_row]["SubParticles"].ToString();
  357. string str_typeid = dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString();
  358. string str_typename = dt_ParticlesGridDevidePage.Rows[i_row]["TypeName"].ToString();
  359. string str_element = dt_ParticlesGridDevidePage.Rows[i_row]["Element"].ToString();
  360. //获取原始颗粒图像
  361. Bitmap bp_particle = new Bitmap(1, 1);
  362. string str_path = str_resultPath + "\\FIELD_FILES\\";
  363. string str_imagePath = str_path + "Field" + str_fieldid.ToString() + ".bmp";
  364. if (str_subparticles != null && str_subparticles != "")
  365. {
  366. //合并大颗粒
  367. //double ScanFieldSize = 1142;
  368. //Bitmap tempbit = fielddata.ReadImageFile(str_imagePath);
  369. //int pixw = tempbit.Width;
  370. //double xs = pixw / ScanFieldSize;
  371. //bp_particle = fielddata.GetBitmapForBig(str_subparticles, xs, str_resultPath);
  372. continue;
  373. }
  374. else
  375. {
  376. //正常颗粒
  377. 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"]) };
  378. Bitmap bp_field = fielddata.ReadImageFile(str_imagePath);
  379. bp_particle = fielddata.GetBitmapByParticle(bp_field, rectangle);
  380. 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() };
  381. }
  382. //获取该颗粒的xray能谱图像
  383. System.Drawing.Bitmap bp_xraybp = ExportXRayBitmap(str_fieldid,
  384. str_particleid, Convert.ToInt32(str_typeid), str_typename, fielddata);
  385. //获取该颗粒的二次放大处理图像
  386. Bitmap ls_processbitmap = new Bitmap(1, 1);
  387. ls_processbitmap = (Bitmap)bp_particle.Clone();//待完善
  388. //再将图像转成二进制流-------------------------------------------------------------------
  389. //原图
  390. MemoryStream newms_p1 = new MemoryStream();
  391. bp_particle.Save(newms_p1, System.Drawing.Imaging.ImageFormat.Bmp);
  392. newms_p1.Seek(0, SeekOrigin.Begin);
  393. byte[] newarr_p1 = new byte[newms_p1.Length];
  394. newms_p1.Read(newarr_p1, 0, newarr_p1.Length);
  395. //---------------------------------------------------------------------------------------
  396. DataRow dr = DT_Largest_frame.NewRow();
  397. dr["p1"] = newarr_p1;
  398. newms_p1.Dispose();
  399. dr["pid"] = str_fieldid + dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  400. dr["Size"] = Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["area"]).ToString("#0.00"); //可以需要选择切换,计算方式
  401. dr["Width"] = dt_ParticlesGridDevidePage.Rows[i_row]["rectwidth"].ToString();
  402. dr["DMAX"] = Math.Round(Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["dmax"]),2).ToString();
  403. dr["DMIN"] = Math.Round(Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["dmin"]),2).ToString();
  404. dr["Class"] = dt_ParticlesGridDevidePage.Rows[i_row]["typename"].ToString();
  405. dr["fieldid"] = str_fieldid;
  406. List<string> list_max_elementname = new List<string>();
  407. List<double> list_max_elementvale = new List<double>();
  408. GetMaxElementFromDataTable(dt_ParticlesGridDevidePage, i_row, out list_max_elementname, out list_max_elementvale);
  409. //元素1
  410. dr["ColName1"] = list_max_elementname[0];
  411. dr["ColVal1"] = list_max_elementvale[0].ToString();
  412. //元素2
  413. dr["ColName2"] = list_max_elementname[1];
  414. dr["ColVal2"] = list_max_elementvale[1].ToString();
  415. //元素3
  416. dr["ColName3"] = list_max_elementname[2];
  417. dr["ColVal3"] = list_max_elementvale[2].ToString();
  418. //元素4
  419. dr["ColName4"] = list_max_elementname[3];
  420. dr["ColVal4"] = list_max_elementvale[3].ToString();
  421. //元素5
  422. dr["ColName5"] = list_max_elementname[4];
  423. dr["ColVal5"] = list_max_elementvale[4].ToString();
  424. //元素6
  425. dr["ColName6"] = list_max_elementname[5];
  426. dr["ColVal6"] = list_max_elementvale[5].ToString();
  427. DT_Largest_frame.Rows.Add(dr);
  428. }
  429. }
  430. #endregion
  431. FrameGraphParticleTable(dt_ParticlesGridDevidePage, str_resultPath, fielddata, DT_field_dt);
  432. m_list_dt.Add(DT_field_dt_copy);
  433. m_list_dt.Add(DT_Largest_frame);
  434. m_list_dt.Add(DT_Largest20);
  435. return true;
  436. }
  437. private bool JudgeWhetherItExists(int id, DataTable dt,string column)
  438. {
  439. for (int i=0;i<dt.Rows.Count;i++)
  440. {
  441. if (id == Convert.ToInt32(dt.Rows[i][column].ToString()))
  442. return true;
  443. }
  444. return false;
  445. }
  446. /// <summary>
  447. ///
  448. /// </summary>
  449. /// <param name="dt_ParticlesGridDevidePage">数据源</param>
  450. /// <param name="str_resultPath">地址</param>
  451. /// <param name="fielddata"></param>
  452. /// <param name="DT_field_dt">主表</param>
  453. private void FrameGraphParticleTable(DataTable dt_ParticlesGridDevidePage,string str_resultPath, ParticleData fielddata,DataTable DT_field_dt)
  454. {
  455. //表名Largest_frame表:(子表) 显示20条颗粒除外的部份颗粒信息
  456. DataTable FrameGraphSubTable = new DataTable();
  457. FrameGraphSubTable.TableName = "FrameGraphSubTable";
  458. FrameGraphSubTable.Columns.Add("pid");
  459. FrameGraphSubTable.Columns.Add("Size");
  460. FrameGraphSubTable.Columns.Add("Width");
  461. FrameGraphSubTable.Columns.Add("DMAX");
  462. FrameGraphSubTable.Columns.Add("DMIN");
  463. FrameGraphSubTable.Columns.Add("Class");
  464. FrameGraphSubTable.Columns.Add("ColName1");
  465. FrameGraphSubTable.Columns.Add("ColName2");
  466. FrameGraphSubTable.Columns.Add("ColName3");
  467. FrameGraphSubTable.Columns.Add("ColName4");
  468. FrameGraphSubTable.Columns.Add("ColName5");
  469. FrameGraphSubTable.Columns.Add("ColName6");
  470. FrameGraphSubTable.Columns.Add("ColVal1");
  471. FrameGraphSubTable.Columns.Add("ColVal2");
  472. FrameGraphSubTable.Columns.Add("ColVal3");
  473. FrameGraphSubTable.Columns.Add("ColVal4");
  474. FrameGraphSubTable.Columns.Add("ColVal5");
  475. FrameGraphSubTable.Columns.Add("ColVal6");
  476. DataColumn colpictid = new DataColumn("FieldId");
  477. colpictid.DataType = typeof(int);
  478. FrameGraphSubTable.Columns.Add(colpictid);
  479. //图像列
  480. DataColumn colpict = new DataColumn("p1");
  481. colpict.DataType = System.Type.GetType("System.Byte[]");
  482. FrameGraphSubTable.Columns.Add(colpict);
  483. for (int i_row = 0; i_row < dt_ParticlesGridDevidePage.Rows.Count; i_row++)
  484. {
  485. if (dt_ParticlesGridDevidePage.Rows[i_row]["element"].ToString() == "")
  486. continue;
  487. //获取颗粒的fieldid,和particleid
  488. string str_fieldid = dt_ParticlesGridDevidePage.Rows[i_row]["fieldid"].ToString();
  489. //if (Convert.ToInt32(str_fieldid) < 20)
  490. if (JudgeWhetherItExists(Convert.ToInt32(str_fieldid), DT_field_dt, "FieldId"))
  491. {
  492. string str_particleid = dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  493. string str_subparticles = dt_ParticlesGridDevidePage.Rows[i_row]["SubParticles"].ToString();
  494. string str_typeid = dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString();
  495. string str_typename = dt_ParticlesGridDevidePage.Rows[i_row]["TypeName"].ToString();
  496. string str_element = dt_ParticlesGridDevidePage.Rows[i_row]["Element"].ToString();
  497. //获取原始颗粒图像
  498. Bitmap bp_particle = new Bitmap(1, 1);
  499. string str_path = str_resultPath + "\\FIELD_FILES\\";
  500. string str_imagePath = str_path + "Field" + str_fieldid.ToString() + ".bmp";
  501. if (str_subparticles != null && str_subparticles != "")
  502. {
  503. continue;
  504. }
  505. else
  506. {
  507. //正常颗粒
  508. 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"]) };
  509. Bitmap bp_field = fielddata.ReadImageFile(str_imagePath);
  510. bp_particle = fielddata.GetBitmapByParticle(bp_field, rectangle);
  511. 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() };
  512. }
  513. //获取该颗粒的xray能谱图像
  514. System.Drawing.Bitmap bp_xraybp = ExportXRayBitmap(str_fieldid,
  515. str_particleid, Convert.ToInt32(str_typeid), str_typename, fielddata);
  516. //获取该颗粒的二次放大处理图像
  517. Bitmap ls_processbitmap = new Bitmap(1, 1);
  518. ls_processbitmap = (Bitmap)bp_particle.Clone();//待完善
  519. //再将图像转成二进制流-------------------------------------------------------------------
  520. //原图
  521. MemoryStream newms_p1 = new MemoryStream();
  522. bp_particle.Save(newms_p1, System.Drawing.Imaging.ImageFormat.Bmp);
  523. newms_p1.Seek(0, SeekOrigin.Begin);
  524. byte[] newarr_p1 = new byte[newms_p1.Length];
  525. newms_p1.Read(newarr_p1, 0, newarr_p1.Length);
  526. //---------------------------------------------------------------------------------------
  527. DataRow dr = FrameGraphSubTable.NewRow();
  528. dr["p1"] = newarr_p1;
  529. newms_p1.Dispose();
  530. dr["pid"] = str_fieldid + dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  531. dr["Size"] = Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["area"]).ToString("#0.00"); //可以需要选择切换,计算方式
  532. dr["Width"] = dt_ParticlesGridDevidePage.Rows[i_row]["rectwidth"].ToString();
  533. dr["DMAX"] = Math.Round(Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["dmax"]),2).ToString();
  534. dr["DMIN"] = Math.Round(Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["dmin"]),2).ToString();
  535. dr["Class"] = dt_ParticlesGridDevidePage.Rows[i_row]["typename"].ToString();
  536. dr["fieldid"] = str_fieldid;
  537. List<string> list_max_elementname = new List<string>();
  538. List<double> list_max_elementvale = new List<double>();
  539. GetMaxElementFromDataTable(dt_ParticlesGridDevidePage, i_row, out list_max_elementname, out list_max_elementvale);
  540. //元素1
  541. dr["ColName1"] = list_max_elementname[0];
  542. dr["ColVal1"] = list_max_elementvale[0].ToString();
  543. //元素2
  544. dr["ColName2"] = list_max_elementname[1];
  545. dr["ColVal2"] = list_max_elementvale[1].ToString();
  546. //元素3
  547. dr["ColName3"] = list_max_elementname[2];
  548. dr["ColVal3"] = list_max_elementvale[2].ToString();
  549. //元素4
  550. dr["ColName4"] = list_max_elementname[3];
  551. dr["ColVal4"] = list_max_elementvale[3].ToString();
  552. //元素5
  553. dr["ColName5"] = list_max_elementname[4];
  554. dr["ColVal5"] = list_max_elementvale[4].ToString();
  555. //元素6
  556. dr["ColName6"] = list_max_elementname[5];
  557. dr["ColVal6"] = list_max_elementvale[5].ToString();
  558. FrameGraphSubTable.Rows.Add(dr);
  559. }
  560. }
  561. m_list_dt.Add(FrameGraphSubTable);
  562. }
  563. private bool DetermineWhetherTheFileExists(DirectoryInfo theFolder ,int id)
  564. {
  565. foreach (FileInfo nextifile in theFolder.GetFiles())
  566. {
  567. if (nextifile.Name.Contains(id.ToString()+".bmp") == true || nextifile.Name.Contains(id.ToString()+".BMP") == true)
  568. {
  569. return true;
  570. }
  571. }
  572. return false;
  573. }
  574. #endregion
  575. #region 插入颗粒尺寸表
  576. /// <summary>
  577. /// 向 模板设计器 中插入 颗粒尺寸表
  578. /// </summary>
  579. /// <returns></returns>
  580. public bool InsertReportTemplateTable_ParticleSizeGrid()
  581. {
  582. try
  583. {
  584. //加载模块
  585. ParticlesSizeGrid ls_particlesizegrid = new ParticlesSizeGrid(m_otsreport_export.m_ReportApp);
  586. List<string> vs = new List<string>() { "DMAX", "DMIN", "CIRCLE", "FERET" };
  587. ls_particlesizegrid.condition = vs[m_otsreport_export.m_mbszclass.M_KLFXJG.index_cb_klcc_jsfs];
  588. m_otsreport_export.panel_container.Controls.Clear();
  589. m_otsreport_export.panel_container.Controls.Add(ls_particlesizegrid);
  590. DataGridView ls_gv = new DataGridView();
  591. DataTable ls_dt = new DataTable();
  592. ls_particlesizegrid.GetDataTableAndGridView(out ls_dt, out ls_gv);
  593. //------------------------------------------------
  594. DataTable ls_partsize_dt = new DataTable();
  595. ls_partsize_dt.TableName = "PartSize";
  596. ls_partsize_dt.Columns.Add("c1");
  597. ls_partsize_dt.Columns.Add("c2");
  598. ls_partsize_dt.Columns.Add("c3");
  599. ls_partsize_dt.Columns.Add("c4");
  600. ls_partsize_dt.Columns.Add("c5");
  601. ls_partsize_dt.Columns.Add("c6");
  602. ls_partsize_dt.Columns.Add("c7");
  603. ls_partsize_dt.Columns.Add("c8");
  604. ls_partsize_dt.Columns.Add("c9");
  605. DataRow dr = ls_partsize_dt.NewRow();
  606. //从2开始,固定的
  607. int col = 6;
  608. for (int i = 1; i < 11; i++)
  609. {
  610. if (ls_gv.Columns.Count > col)
  611. if (i<10)
  612. dr["c" + i.ToString()] = ls_gv.Columns[col++].Name;
  613. }
  614. ls_partsize_dt.Rows.Add(dr);
  615. DataTable ls_Particel_dt = new DataTable();
  616. ls_Particel_dt.TableName = "Particel";
  617. ls_Particel_dt.Columns.Add("c1");
  618. ls_Particel_dt.Columns.Add("c2");
  619. ls_Particel_dt.Columns.Add("c3");
  620. ls_Particel_dt.Columns.Add("c4");
  621. ls_Particel_dt.Columns.Add("c5");
  622. ls_Particel_dt.Columns.Add("c6");
  623. ls_Particel_dt.Columns.Add("c7");
  624. ls_Particel_dt.Columns.Add("c8");
  625. ls_Particel_dt.Columns.Add("c9");
  626. ls_Particel_dt.Columns.Add("SName");
  627. ls_Particel_dt.Columns.Add("total");
  628. ls_Particel_dt.Columns.Add("Largest");
  629. ls_Particel_dt.Columns.Add("Hardness");
  630. ls_Particel_dt.Columns.Add("Density");
  631. ls_Particel_dt.Columns.Add("Conductivity");
  632. for (int i = 0; i < ls_gv.Rows.Count; i++)
  633. {
  634. DataRow dr2 = ls_Particel_dt.NewRow();
  635. dr2["SName"] = ls_gv.Rows[i].Cells[1].Value.ToString();
  636. dr2["Largest"] = ls_gv.Rows[i].Cells[4].Value.ToString();
  637. dr2["Hardness"] = ls_gv.Rows[i].Cells[6].Value.ToString();
  638. dr2["Density"] = ls_gv.Rows[i].Cells[7].Value.ToString();
  639. dr2["Conductivity"] = ls_gv.Rows[i].Cells[8].Value.ToString();
  640. int col2 = 6;
  641. for (int j = 1; j < 11; j++)
  642. {
  643. if (ls_gv.Columns.Count > col2)
  644. if(j<10)
  645. dr2["c" + j.ToString()] = ls_gv.Rows[i].Cells[col2++].Value.ToString();
  646. }
  647. //total,不为空行,和不能是总计行
  648. if (dr2["SName"].ToString() != "" && dr2["SName"].ToString().IndexOf("number") < 0)
  649. {
  650. dr2["total"] = "0"; //求合
  651. double d_total = 0;
  652. int col3 = 6;
  653. for (int j = 1; j < 11; j++)
  654. {
  655. if (ls_gv.Columns.Count > col3)
  656. d_total = d_total + Convert.ToInt64(ls_gv.Rows[i].Cells[col3++].Value.ToString());
  657. }
  658. dr2["total"] = d_total.ToString();
  659. }
  660. ls_Particel_dt.Rows.Add(dr2);
  661. }
  662. m_list_dt.Add(ls_partsize_dt);
  663. m_list_dt.Add(ls_Particel_dt);
  664. return true;
  665. }
  666. catch (Exception ee)
  667. {
  668. m_otsreport_export.WriteRictBox(ee.ToString());
  669. return false;
  670. }
  671. }
  672. #endregion
  673. #region 插入平均元素含量表
  674. /// <summary>
  675. /// 向 模板设计器 中插入 平均元素含量表
  676. /// </summary>
  677. /// <returns></returns>
  678. public bool InsertReportTemplateTable_ElementCompositionAvgGrid()
  679. {
  680. try
  681. {
  682. //加载模块
  683. ElementCompositionAvgGrid ls_elementcompositionavggrid = new ElementCompositionAvgGrid(m_otsreport_export.m_ReportApp);
  684. m_otsreport_export.panel_container.Controls.Clear();
  685. m_otsreport_export.panel_container.Controls.Add(ls_elementcompositionavggrid);
  686. DataGridView ls_gv = new DataGridView();
  687. DataTable ls_dt = new DataTable();
  688. ls_elementcompositionavggrid.GetDataTableAndGridView(out ls_dt, out ls_gv);
  689. //------------------------------------------------
  690. DataTable ls_elementname_dt = new DataTable();
  691. ls_elementname_dt.TableName = "ElementName";
  692. ls_elementname_dt.Columns.Add("e1");
  693. ls_elementname_dt.Columns.Add("e2");
  694. ls_elementname_dt.Columns.Add("e3");
  695. ls_elementname_dt.Columns.Add("e4");
  696. ls_elementname_dt.Columns.Add("e5");
  697. ls_elementname_dt.Columns.Add("e6");
  698. ls_elementname_dt.Columns.Add("e7");
  699. ls_elementname_dt.Columns.Add("e8");
  700. ls_elementname_dt.Columns.Add("e9");
  701. ls_elementname_dt.Columns.Add("e10");
  702. ls_elementname_dt.Columns.Add("e11");
  703. ls_elementname_dt.Columns.Add("e12");
  704. ls_elementname_dt.Columns.Add("e13");
  705. ls_elementname_dt.Columns.Add("e14");
  706. DataRow dr = ls_elementname_dt.NewRow();
  707. int col = 4;
  708. for (int i = 1; i < 15; i++)
  709. {
  710. if (ls_gv.Columns.Count > col)
  711. dr["e" + i.ToString()] = ls_gv.Columns[col++].Name;
  712. }
  713. ls_elementname_dt.Rows.Add(dr);
  714. DataTable ls_element_dt = new DataTable();
  715. ls_element_dt.TableName = "ElementValue";
  716. ls_element_dt.Columns.Add("e1");
  717. ls_element_dt.Columns.Add("e2");
  718. ls_element_dt.Columns.Add("e3");
  719. ls_element_dt.Columns.Add("e4");
  720. ls_element_dt.Columns.Add("e5");
  721. ls_element_dt.Columns.Add("e6");
  722. ls_element_dt.Columns.Add("e7");
  723. ls_element_dt.Columns.Add("e8");
  724. ls_element_dt.Columns.Add("e9");
  725. ls_element_dt.Columns.Add("e10");
  726. ls_element_dt.Columns.Add("e11");
  727. ls_element_dt.Columns.Add("e12");
  728. ls_element_dt.Columns.Add("e13");
  729. ls_element_dt.Columns.Add("e14");
  730. ls_element_dt.Columns.Add("PName");
  731. ls_element_dt.Columns.Add("Count");
  732. ls_element_dt.Columns.Add("AllElements");
  733. for (int i = 0; i < ls_gv.Rows.Count; i++)
  734. {
  735. DataRow dr2 = ls_element_dt.NewRow();
  736. dr2["PName"] = ls_gv.Rows[i].Cells[1].Value.ToString();
  737. dr2["Count"] = ls_gv.Rows[i].Cells[2].Value.ToString();
  738. int colq = 4;
  739. for (int j = 1; j < 15; j++)
  740. {
  741. if (ls_gv.Columns.Count > colq)
  742. dr2["e" + j.ToString()] = ls_gv.Rows[i].Cells[colq++].Tag.ToString();
  743. }
  744. colq = 4;
  745. string AllElements=null;
  746. for (int j = 0; j < ls_gv.Rows[i].Cells.Count; j++)
  747. {
  748. if (ls_gv.Columns.Count > colq)
  749. {
  750. AllElements = AllElements+ ls_gv.Columns[colq].Name + "%="+ ls_gv.Rows[i].Cells[colq++].Tag.ToString()+"; ";
  751. }
  752. }
  753. dr2["AllElements"] = AllElements;
  754. ls_element_dt.Rows.Add(dr2);
  755. }
  756. InclusionAreaRatio(ls_gv);
  757. //把用户设置感兴趣的元素显示在前边
  758. for (int i=0;i< m_otsreport_export.m_mbszclass.M_YSFXJG.list_str_tb_ysfx_xsys.Count(); i++)
  759. {
  760. if (i > 13)
  761. continue;
  762. for (int a=0;a< ls_elementname_dt.Rows[0].ItemArray.Count(); a++)
  763. {
  764. if (m_otsreport_export.m_mbszclass.M_YSFXJG.list_str_tb_ysfx_xsys[i]== ls_elementname_dt.Rows[0][a].ToString())
  765. {
  766. string str_elementname = "";
  767. str_elementname = ls_elementname_dt.Rows[0][i].ToString();
  768. ls_elementname_dt.Rows[0][i] = ls_elementname_dt.Rows[0][a];
  769. ls_elementname_dt.Rows[0][a] = str_elementname;
  770. for (int j=0;j< ls_element_dt.Rows.Count;j++)
  771. {
  772. string str_element = "0";
  773. str_element = ls_element_dt.Rows[j][i].ToString();
  774. ls_element_dt.Rows[j][i] = ls_element_dt.Rows[j][a];
  775. ls_element_dt.Rows[j][a] = str_element;
  776. }
  777. }
  778. }
  779. }
  780. m_list_dt.Add(ls_elementname_dt);
  781. m_list_dt.Add(ls_element_dt);
  782. List<string> elementColumn= m_otsreport_export.m_mbszclass.M_YSFXJG.list_str_tb_ysfx_xsys;
  783. return true;
  784. }
  785. catch (Exception ee)
  786. {
  787. m_otsreport_export.WriteRictBox(ee.ToString());
  788. return false;
  789. }
  790. }
  791. #endregion
  792. private void InclusionAreaRatio(DataGridView ls_gv)
  793. {
  794. DataTable AreaRatio = new DataTable();
  795. AreaRatio.TableName = "InclusionAreaRatio";
  796. AreaRatio.Columns.Add("e1");
  797. AreaRatio.Columns.Add("e2");
  798. AreaRatio.Columns.Add("e3");
  799. AreaRatio.Columns.Add("e4");
  800. AreaRatio.Columns.Add("e5");
  801. //获取夹杂物的总面积用于计算夹杂物类别的占比(gridview最后一个固定是未识别颗粒,要排除未识别颗粒所以for循环至grid view长度减一)
  802. double totalInclusionArea = 0;
  803. for (int i = 0; i < ls_gv.Rows.Count - 1; i++)
  804. {
  805. totalInclusionArea = totalInclusionArea + Convert.ToDouble(ls_gv.Rows[i].Cells[2].Value.ToString());
  806. }
  807. for (int i = 0; i < ls_gv.Rows.Count - 1; i++)
  808. {
  809. DataRow dr = AreaRatio.NewRow();
  810. dr["e1"] = (i + 1).ToString();
  811. dr["e2"] = ls_gv.Rows[i].Cells[1].Value.ToString();
  812. dr["e3"] = ls_gv.Rows[i].Cells[2].Value.ToString();
  813. dr["e4"] = Math.Round((Convert.ToDouble(ls_gv.Rows[i].Cells[2].Value)/ totalInclusionArea)*100,2);
  814. 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);
  815. AreaRatio.Rows.Add(dr);
  816. }
  817. m_list_dt.Add(AreaRatio);
  818. }
  819. #region 插入颗粒图chart
  820. /// <summary>
  821. /// 用于颗粒图chart
  822. /// </summary>
  823. /// <returns></returns>
  824. private DataTable GetPicDataTable_PicKL()
  825. {
  826. if (m_list_dt.Where(aa => aa.TableName.Contains("PicKL")).ToList().Count == 0)
  827. {
  828. //创建二进制列的数据表
  829. DataTable ls_dt = new DataTable();
  830. ls_dt.TableName = "PicKL";
  831. DataColumn colpict = new DataColumn("pict");
  832. colpict.DataType = System.Type.GetType("System.Byte[]");
  833. ls_dt.Columns.Add(colpict);
  834. m_list_dt.Add(ls_dt);
  835. return ls_dt;
  836. }
  837. else
  838. {
  839. return m_list_dt.Where(aa => aa.TableName.Contains("PicKL")).ToList()[0];
  840. }
  841. }
  842. #endregion
  843. private DataTable GetPicDataTable_InclusionAreaRatio()
  844. {
  845. if (m_list_dt.Where(aa => aa.TableName.Contains("Pic_InclusionAreaRatio")).ToList().Count == 0)
  846. {
  847. //创建二进制列的数据表
  848. DataTable ls_dt = new DataTable();
  849. ls_dt.TableName = "Pic_InclusionAreaRatio";
  850. DataColumn colpict = new DataColumn("pict");
  851. colpict.DataType = System.Type.GetType("System.Byte[]");
  852. ls_dt.Columns.Add(colpict);
  853. m_list_dt.Add(ls_dt);
  854. return ls_dt;
  855. }
  856. else
  857. {
  858. return m_list_dt.Where(aa => aa.TableName.Contains("Pic_InclusionAreaRatio")).ToList()[0];
  859. }
  860. }
  861. #region 插入元素图chart
  862. /// <summary>
  863. /// 用于元素图chart
  864. /// </summary>
  865. /// <returns></returns>
  866. private DataTable GetPicDataTable_PicYS()
  867. {
  868. if (m_list_dt.Where(aa => aa.TableName.Contains("PicYS")).ToList().Count == 0)
  869. {
  870. //创建二进制列的数据表
  871. DataTable ls_dt = new DataTable();
  872. ls_dt.TableName = "PicYS";
  873. DataColumn colpict = new DataColumn("pict");
  874. colpict.DataType = System.Type.GetType("System.Byte[]");
  875. ls_dt.Columns.Add(colpict);
  876. m_list_dt.Add(ls_dt);
  877. return ls_dt;
  878. }
  879. else
  880. {
  881. return m_list_dt.Where(aa => aa.TableName.Contains("PicYS")).ToList()[0];
  882. }
  883. }
  884. #endregion
  885. #region 插入夹杂物面积比图
  886. public bool InsertReportTemplateChart_InclusionAreaRatio(string a_GraphicStyle)
  887. {
  888. //加载模块
  889. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition = new EChart_ParticlesComposition(m_otsreport_export.m_ReportApp, "InclusionareaRatio");
  890. m_otsreport_export.m_ReportApp.m_reportname = "夹杂物面积比";
  891. m_otsreport_export.m_ReportApp.type = a_GraphicStyle;
  892. m_otsreport_export.m_ReportApp.timerKG = true;
  893. m_otsreport_export.m_ReportApp.m_ChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition);
  894. //弹出加载图片窗体
  895. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  896. //将EChart委托事件注册给加载图片窗体的方法
  897. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition.butclic += og.get_ParticalesCompositionChart;
  898. og.ShowDialog();
  899. //获取图片数据
  900. string str = og.PicStr;
  901. //将Base64String转为图片并保存
  902. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  903. MemoryStream ms = new MemoryStream(arr);
  904. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  905. //再将图转成流,流再转二进制-------------------------------------------
  906. MemoryStream newms = new MemoryStream();
  907. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  908. newms.Seek(0, SeekOrigin.Begin);
  909. byte[] newarr = new byte[newms.Length];
  910. newms.Read(newarr, 0, newarr.Length);
  911. newms.Dispose();
  912. DataTable ls_dt = GetPicDataTable_InclusionAreaRatio();
  913. DataRow dr = ls_dt.NewRow();
  914. dr["pict"] = newarr;//图像二进制
  915. ls_dt.Rows.Add(dr);
  916. return true;
  917. }
  918. #endregion
  919. #region 插入颗粒成份图
  920. /// <summary>
  921. /// 向 模板设计器 中插入 颗粒成份图
  922. /// </summary>
  923. /// <returns></returns>
  924. public bool InsertReportTemplateChart_ParticlesCompositionChart(string a_GraphicStyle)
  925. {
  926. try
  927. {
  928. //-----------------------------------颗粒成份图-----------------------------------------------------------------------------------------------
  929. //加载模块
  930. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition = new EChart_ParticlesComposition(m_otsreport_export.m_ReportApp, "PComponent");
  931. m_otsreport_export.m_ReportApp.m_reportname = "InclusionClassification";
  932. m_otsreport_export.m_ReportApp.type = a_GraphicStyle;
  933. m_otsreport_export.m_ReportApp.timerKG = true;
  934. m_otsreport_export.m_ReportApp.m_ChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition);
  935. //弹出加载图片窗体
  936. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  937. //将EChart委托事件注册给加载图片窗体的方法
  938. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition.butclic += og.get_ParticalesCompositionChart;
  939. og.ShowDialog();
  940. //获取图片数据
  941. string str = og.PicStr;
  942. //将Base64String转为图片并保存
  943. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  944. MemoryStream ms = new MemoryStream(arr);
  945. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  946. //再将图转成流,流再转二进制-------------------------------------------
  947. MemoryStream newms = new MemoryStream();
  948. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  949. newms.Seek(0, SeekOrigin.Begin);
  950. byte[] newarr = new byte[newms.Length];
  951. newms.Read(newarr, 0, newarr.Length);
  952. newms.Dispose();
  953. //创建二进制列的数据表
  954. DataTable ls_dt = GetPicDataTable_PicKL();
  955. DataRow dr = ls_dt.NewRow();
  956. dr["pict"] = newarr;//图像二进制
  957. ls_dt.Rows.Add(dr);
  958. return true;
  959. }
  960. catch (Exception ee)
  961. {
  962. m_otsreport_export.WriteRictBox(ee.ToString());
  963. return false;
  964. }
  965. }
  966. #endregion
  967. #region 插入元素成份图
  968. /// <summary>
  969. /// 向 模板设计器 中插入 元素成份图
  970. /// </summary>
  971. /// <returns></returns>
  972. public bool InsertReportTemplateChart_ElementCompositionChart(string a_GraphicStyle)
  973. {
  974. try
  975. {
  976. //-----------------------------------元素成份图-----------------------------------------------------------------------------------------------
  977. //加载模块
  978. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition = new EChart_ParticlesComposition(m_otsreport_export.m_ReportApp, "EComponent");
  979. m_otsreport_export.m_ReportApp.m_reportname = "ElementComposition";
  980. m_otsreport_export.m_ReportApp.type = a_GraphicStyle;
  981. m_otsreport_export.m_ReportApp.timerKG = true;
  982. m_otsreport_export.m_ReportApp.m_ChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition);
  983. //弹出加载图片窗体
  984. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  985. //将EChart委托事件注册给加载图片窗体的方法
  986. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition.butclic += og.get_ParticalesCompositionChart;
  987. og.ShowDialog();
  988. //获取图片数据
  989. string str = og.PicStr;
  990. //将Base64String转为图片并保存
  991. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  992. MemoryStream ms = new MemoryStream(arr);
  993. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  994. //再将图转成流,流再转二进制-------------------------------------------
  995. MemoryStream newms = new MemoryStream();
  996. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  997. newms.Seek(0, SeekOrigin.Begin);
  998. byte[] newarr = new byte[newms.Length];
  999. newms.Read(newarr, 0, newarr.Length);
  1000. newms.Dispose();
  1001. //创建二进制列的数据表
  1002. DataTable ls_dt = GetPicDataTable_PicYS();
  1003. DataRow dr = ls_dt.NewRow();
  1004. dr["pict"] = newarr;//图像二进制
  1005. ls_dt.Rows.Add(dr);
  1006. return true;
  1007. }
  1008. catch (Exception ee)
  1009. {
  1010. m_otsreport_export.WriteRictBox(ee.ToString());
  1011. return false;
  1012. }
  1013. }
  1014. #endregion
  1015. #region 插入三元相图
  1016. /// <summary>
  1017. /// 获取或创建pic表格,用于三元相图
  1018. /// </summary>
  1019. /// <returns></returns>
  1020. private DataTable GetPicDataTable_PicSYXT2T()
  1021. {
  1022. if (m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT2T")).ToList().Count == 0)
  1023. {
  1024. //创建二进制列的数据表
  1025. DataTable ls_dt = new DataTable();
  1026. ls_dt.TableName = "PicSYXT2T";
  1027. DataColumn colpict = new DataColumn("pict");
  1028. colpict.DataType = System.Type.GetType("System.Byte[]");
  1029. ls_dt.Columns.Add(colpict);
  1030. DataColumn colpict2 = new DataColumn("pict2");
  1031. colpict2.DataType = System.Type.GetType("System.Byte[]");
  1032. ls_dt.Columns.Add(colpict2);
  1033. m_list_dt.Add(ls_dt);
  1034. return ls_dt;
  1035. }
  1036. else
  1037. {
  1038. return m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT2T")).ToList()[0];
  1039. }
  1040. }
  1041. /// <summary>
  1042. /// 获取或创建pic表格,用于三元相图,3个列的
  1043. /// </summary>
  1044. /// <returns></returns>
  1045. private DataTable GetPicDataTable_PicSYXT3T()
  1046. {
  1047. if (m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT3T")).ToList().Count == 0)
  1048. {
  1049. //创建二进制列的数据表
  1050. DataTable ls_dt = new DataTable();
  1051. ls_dt.TableName = "PicSYXT3T";
  1052. DataColumn colpict = new DataColumn("pict");
  1053. colpict.DataType = System.Type.GetType("System.Byte[]");
  1054. ls_dt.Columns.Add(colpict);
  1055. DataColumn colpict2 = new DataColumn("pict2");
  1056. colpict2.DataType = System.Type.GetType("System.Byte[]");
  1057. ls_dt.Columns.Add(colpict2);
  1058. DataColumn colpict3 = new DataColumn("pict3");
  1059. colpict3.DataType = System.Type.GetType("System.Byte[]");
  1060. ls_dt.Columns.Add(colpict3);
  1061. m_list_dt.Add(ls_dt);
  1062. return ls_dt;
  1063. }
  1064. else
  1065. {
  1066. return m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT")).ToList()[0];
  1067. }
  1068. }
  1069. /// <summary>
  1070. /// 获取三元相图二进制数据
  1071. /// </summary>
  1072. /// <param name="selectindex"></param>
  1073. /// <returns></returns>
  1074. private byte[] GetByte_InsertReportTemplateChart_Trianglediagram(int selectindex)
  1075. {
  1076. byte[] newarr = new byte[0];
  1077. //加载模块
  1078. m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram = new EChart_Trianglediagram(m_otsreport_export.m_ReportApp, TemplateList[selectindex]);
  1079. m_otsreport_export.m_ReportApp.timerKG = true;
  1080. m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram.condition = m_otsreport_export.m_mbszclass.M_SYXT.index_cb_syxt_jsfs;
  1081. m_otsreport_export.m_ReportApp.m_ChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram);
  1082. //ls_echart_trianglediagram.
  1083. //弹出加载图片窗体
  1084. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  1085. //将EChart委托事件注册给加载图片窗体的方法
  1086. m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram.butclic += og.get_ParticalesCompositionChart;
  1087. og.ShowDialog();
  1088. //获取图片数据
  1089. string str = og.PicStr;
  1090. //将Base64String转为图片并保存
  1091. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  1092. MemoryStream ms = new MemoryStream(arr);
  1093. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  1094. //再将图转成流,流再转二进制-------------------------------------------
  1095. MemoryStream newms = new MemoryStream();
  1096. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  1097. newms.Seek(0, SeekOrigin.Begin);
  1098. newarr = new byte[newms.Length];
  1099. newms.Read(newarr, 0, newarr.Length);
  1100. newms.Dispose();
  1101. return newarr;
  1102. }
  1103. /// <summary>
  1104. /// 向 模板设计器 中插入 三元相图
  1105. /// </summary>
  1106. /// <returns></returns>
  1107. public bool InsertReportTemplateChart_Trianglediagram()
  1108. {
  1109. try
  1110. {
  1111. //创建二进制列的数据表,循环插入三元选择的模板
  1112. DataTable ls_dt = GetPicDataTable_PicSYXT2T();
  1113. DataTable ls_dt3t = GetPicDataTable_PicSYXT3T();
  1114. //这里要校验一下,总数必须要是2的整倍数,不可有余数
  1115. 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)
  1116. {
  1117. for (int i = 0; i < m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index.Count; i = i + 2)
  1118. {
  1119. byte[] newarr, newarr2;
  1120. newarr = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i]);
  1121. newarr2 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 1]);
  1122. DataRow dr = ls_dt.NewRow();
  1123. dr["pict"] = newarr;//图像二进制
  1124. dr["pict2"] = newarr2;//图像二进制
  1125. ls_dt.Rows.Add(dr);
  1126. }
  1127. }
  1128. else
  1129. {
  1130. DataRow dr = ls_dt.NewRow();
  1131. dr["pict"] = null;//图像二进制
  1132. dr["pict2"] = null;//图像二进制
  1133. ls_dt.Rows.Add(dr);
  1134. }
  1135. 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)
  1136. {
  1137. for (int i = 0; i < m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index.Count; i = i + 3)
  1138. {
  1139. byte[] newarr, newarr2, newarr3;
  1140. newarr = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i]);
  1141. newarr2 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 1]);
  1142. newarr3 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 2]);
  1143. DataRow dr = ls_dt3t.NewRow();
  1144. dr["pict"] = newarr;//图像二进制
  1145. dr["pict2"] = newarr2;//图像二进制
  1146. dr["pict3"] = newarr3;//图像二进制
  1147. ls_dt3t.Rows.Add(dr);
  1148. }
  1149. }
  1150. else
  1151. {
  1152. DataRow dr = ls_dt3t.NewRow();
  1153. dr["pict"] = null;//图像二进制
  1154. dr["pict2"] = null;//图像二进制
  1155. dr["pict3"] = null;//图像二进制
  1156. ls_dt3t.Rows.Add(dr);
  1157. }
  1158. return true;
  1159. }
  1160. catch (Exception ee)
  1161. {
  1162. m_otsreport_export.WriteRictBox(ee.ToString());
  1163. return false;
  1164. }
  1165. }
  1166. #endregion
  1167. #region 其它部份
  1168. /// <summary>
  1169. /// 输入颗粒的所在帧图id,颗粒id,颗粒类型id,获取对应的XRay能谱数据图
  1170. /// </summary>
  1171. /// <returns></returns>
  1172. public Bitmap ExportXRayBitmap(string in_fieldid, string in_particleid, int in_stdtypeid, string TypeName, ParticleData particleData)
  1173. {
  1174. Bitmap ret_bp;
  1175. //显示xray相关信息
  1176. uint[] Search_xray = new uint[2000];
  1177. uint[] Analysis_xray = new uint[2000];
  1178. //
  1179. int i_xray_id = 0;
  1180. List<Element> list_celementchemistryclr = new List<Element>();
  1181. //获取Xray数据
  1182. list_celementchemistryclr = new List<Element>();
  1183. Particle list = particleData.GetParticleByFidAndPid(in_fieldid, in_particleid);
  1184. if (list == null)
  1185. {
  1186. return null;
  1187. }
  1188. Particle particle = list;
  1189. if (particle.XrayId > -1)
  1190. {
  1191. for (int i = 0; i < 2000; i++)
  1192. {
  1193. if (particle.XRayData!=null)
  1194. {
  1195. Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
  1196. }
  1197. }
  1198. Search_xray = Analysis_xray;
  1199. i_xray_id = particle.XrayId;
  1200. list_celementchemistryclr = particle.ElementList;
  1201. }
  1202. //get CElementChemistryClr list
  1203. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  1204. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  1205. {
  1206. ShowElementInfo ls_sei = new ShowElementInfo();
  1207. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  1208. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  1209. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX1);
  1210. list_showelementinfo.Add(ls_sei);
  1211. }
  1212. //获取使用标准库的名称
  1213. string str_stdname = "";
  1214. string str_IncALibName = "";
  1215. if (in_stdtypeid < 1000)
  1216. {
  1217. //小于1000,使用系统默认分类
  1218. str_IncALibName = TypeName;
  1219. str_stdname = "Default standard library";
  1220. }
  1221. else if (in_stdtypeid >= 1000 && in_stdtypeid < 10000)
  1222. {
  1223. //大于等于1000,并且小于10000时,使用系统数据库中夹杂物来分析
  1224. str_IncALibName = TypeName;
  1225. str_stdname = "User defined standard library";
  1226. }
  1227. else if (in_stdtypeid > 10000)
  1228. {
  1229. //大于10000时,使用用户标准库来分析夹杂物名称
  1230. str_IncALibName = TypeName;
  1231. str_stdname = "System standard library";
  1232. }
  1233. //获取数据后,需要对xraytable设置
  1234. OTSIncAReportGraph.Controls.Control_XRayTable control_XRayTable1 = new Control_XRayTable();
  1235. control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray, list_showelementinfo);
  1236. //颗粒国标信息
  1237. //control_XRayTable1.GBInfoStr = in_dparticle.GBContent;
  1238. control_XRayTable1.MaterialName = str_IncALibName;//杂夹物
  1239. control_XRayTable1.STDName = str_stdname;//标准库
  1240. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  1241. control_XRayTable1.Visible = true;
  1242. control_XRayTable1.Invalidate();
  1243. control_XRayTable1.Refresh();
  1244. ret_bp = control_XRayTable1.ExportXRayImage();
  1245. return ret_bp;
  1246. }
  1247. /// <summary>
  1248. /// 导出二次放大图像
  1249. /// </summary>
  1250. /// <param name="str_srcPathName"></param>
  1251. /// <param name="str_outPathName"></param>
  1252. public void ParticleReZoom(string str_srcPathName, string str_outPathName)
  1253. {
  1254. //m_COTSReportProjFileMgrClr.ReZoom(str_srcPathName, str_outPathName);
  1255. }
  1256. /// <summary>
  1257. /// 传入DataTable,和行号,返回该Row行中,返回6个靠前的元素,不足6个返回空
  1258. /// </summary>
  1259. /// <param name="in_dt"></param>
  1260. /// <param name="row_index"></param>
  1261. /// <returns></returns>
  1262. private void GetMaxElementFromDataTable(DataTable in_dt, int row_index, out List<string> out_list_elementname, out List<double> out_list_elementvalue)
  1263. {
  1264. out_list_elementname = new List<string>();
  1265. out_list_elementvalue = new List<double>();
  1266. //分别排出元素名,元素值列表
  1267. List<string> list_elementname = new List<string>();
  1268. List<double> list_elementvalue = new List<double>();
  1269. string str_element = in_dt.Rows[row_index]["Element"].ToString();
  1270. //防止取出的元素信息为空
  1271. if (str_element != "")
  1272. {
  1273. string[] strcbo = str_element.Split(';');
  1274. for (int i = 0; i < strcbo.Length-1; i++)
  1275. {
  1276. string[] str = strcbo[i].Split('-');
  1277. list_elementname.Add(str[0]);
  1278. list_elementvalue.Add(Math.Round(Convert.ToDouble(str[1]), 2));
  1279. }
  1280. }
  1281. //循环6次,得到最大的6个元素信息
  1282. for (int geti = 0; geti < 6; geti++)
  1283. {
  1284. double max_elementvalue = -1;
  1285. string max_elementname = "";
  1286. int max_index = -1;
  1287. if (list_elementvalue.Count > 0)
  1288. {
  1289. for (int i = 0; i < list_elementvalue.Count; i++)
  1290. {
  1291. if (list_elementvalue[i] > max_elementvalue)
  1292. {
  1293. max_elementvalue = list_elementvalue[i];
  1294. max_elementname = list_elementname[i];
  1295. max_index = i;
  1296. }
  1297. }
  1298. //移除掉最大的元素
  1299. list_elementname.RemoveAt(max_index);
  1300. list_elementvalue.RemoveAt(max_index);
  1301. //将最大的元素添加到list中
  1302. if (max_elementvalue > 0)
  1303. {
  1304. out_list_elementname.Add(max_elementname);
  1305. out_list_elementvalue.Add(max_elementvalue);
  1306. }
  1307. else
  1308. {
  1309. out_list_elementname.Add(" ");
  1310. out_list_elementvalue.Add(0);
  1311. }
  1312. }
  1313. else
  1314. {
  1315. //如果元素数量已经不够,则添加空
  1316. out_list_elementname.Add(" ");
  1317. out_list_elementvalue.Add(0);
  1318. }
  1319. }
  1320. }
  1321. #endregion
  1322. /// <summary>
  1323. /// 国标一
  1324. /// </summary>
  1325. /// <returns></returns>
  1326. public List<DataTable> InsertReportTemplateTable_ChineseStandardABCDDS(OTSCLRINTERFACE.CPropParamClr cPropParamClr)
  1327. {
  1328. //得到国标一的DataTable表格
  1329. cPropParamClr.SetDataSourceId(0);//
  1330. cPropParamClr.SetType(1);//table
  1331. cPropParamClr.SetCalTableType(6);//国标1
  1332. List<OTSCLRINTERFACE.CGridDataClr> listGriddataclr = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr.GridDataTransfer(cPropParamClr);
  1333. m_otsreport_export.m_ReportApp.im_ChineseStandardABCDDS = new OTSIncAReportGB.ChineseStandardABCDDS(m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr, listGriddataclr);
  1334. m_otsreport_export.m_ReportApp.m_TablesWindow.Controls.Clear();
  1335. //List<DataTable> GB_1 = m_otsreport_export.m_ReportApp.im_ChineseStandardABCDDS.ChineseStandardABCD_GetDataTable();
  1336. //string s = GB_1[0].Rows[0][0].ToString();
  1337. return m_otsreport_export.m_ReportApp.im_ChineseStandardABCDDS.ChineseStandardABCD_GetDataTable(); ;
  1338. }
  1339. /// <summary>
  1340. /// 国标二
  1341. /// </summary>
  1342. /// <returns></returns>
  1343. public List<DataTable> InsertReportTemplateTable_NationalStandardMethodTwo(OTSCLRINTERFACE.CPropParamClr cPropParamClr)
  1344. {
  1345. //得到国标二的DataTable表格
  1346. cPropParamClr.SetDataSourceId(0);//
  1347. cPropParamClr.SetType(1);//table
  1348. cPropParamClr.SetCalTableType(7);//国标2
  1349. List<OTSCLRINTERFACE.CGridDataClr> listGriddataclr2 = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr.GridDataTransfer(cPropParamClr);//
  1350. m_otsreport_export.m_ReportApp.m_TablesWindow.Controls.Clear();
  1351. m_otsreport_export.m_ReportApp.im_NationalStandardMethodTwo = new OTSIncAReportGB.NationalStandardMethodTwo(m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr, listGriddataclr2);
  1352. return m_otsreport_export.m_ReportApp.im_NationalStandardMethodTwo.ChineseStandardABCD_GetDataTable();
  1353. }
  1354. }
  1355. }