Export_ReportTemplate.cs 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242
  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. DataTable m_bt_DBData = new DataTable();
  22. List<string> TemplateList;
  23. #endregion
  24. #region 构造函数
  25. public Export_ReportTemplate(OTSReport_Export in_export)
  26. {
  27. m_otsreport_export = in_export;
  28. TemplateList = new List<string>();
  29. //加载三元相图各项
  30. 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";
  31. TemplateList = new List<string>();
  32. DataSet ds = DataOperation.DataAccess.XMLoperate.GetXmlData(pathtpf, "XMLData");
  33. DataTable dt = ds.Tables["Member"];
  34. foreach (DataRow item in dt.Rows)
  35. {
  36. if (item["TemplateName"].ToString() != "")
  37. {
  38. TemplateList.Add(item["TemplateName"].ToString());
  39. }
  40. }
  41. m_list_dt = new List<DataTable>();
  42. }
  43. public Export_ReportTemplate()
  44. {
  45. m_list_dt = new List<DataTable>();
  46. }
  47. #endregion
  48. #region 插入测量结果Grid表格
  49. /// <summary>
  50. /// 向 模板设计器 中插入测量结果Grid表格
  51. /// </summary>
  52. /// <returns></returns>
  53. public DataTable InsertReportTemplateTable_ResultGrid()
  54. {
  55. //------------------加载模块,获取数据-------------------------------------------------
  56. ResultGrid ls_resultgrid = new ResultGrid(m_otsreport_export.m_ReportApp);
  57. Dictionary<string, string> keyValues_ResultGrid = ls_resultgrid.GetData_ResultGrid();
  58. //------------------加载模块,获取数据结束----------------------------------------------
  59. Dictionary<string, string>.Enumerator en = keyValues_ResultGrid.GetEnumerator();
  60. string str_CLJGMC = "";
  61. string str_YXSJ = "";
  62. string str_SCZS = "";
  63. string str_FLFA = "";
  64. string str_YJCTZ = "";
  65. string str_SCMJ = "";
  66. string str_CKBZ = "GB/T30834-2014";
  67. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col1"].ToString(), out str_CLJGMC);//测量结果名称
  68. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col4"].ToString(), out str_YXSJ);//运行时间
  69. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col5"].ToString(), out str_SCZS);//视场总数
  70. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col6"].ToString(), out str_FLFA);//分类方案
  71. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col7"].ToString(), out str_YJCTZ);//已检测特征
  72. keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col8"].ToString(), out str_SCMJ);//视场面积
  73. //将获取到的数据转换成报告模板能接收的格式。
  74. DataTable ls_new_dt = new DataTable();
  75. ls_new_dt.TableName = "ResultGrid";
  76. ls_new_dt.Columns.Add("CLJGMC"); //测量结果名称
  77. ls_new_dt.Columns.Add("YXSJ"); //运行时间
  78. ls_new_dt.Columns.Add("SCZS"); //视场总数
  79. ls_new_dt.Columns.Add("FLFA"); //分类方案
  80. ls_new_dt.Columns.Add("YJCTZ"); //已检测特征
  81. ls_new_dt.Columns.Add("SCMJ"); //视场面积
  82. ls_new_dt.Columns.Add("CKBZ"); //参考标准
  83. //行转列,这里不会发生改变,所以这样写
  84. DataRow dr = ls_new_dt.NewRow();
  85. dr["CLJGMC"] = str_CLJGMC;
  86. dr["YXSJ"] = str_YXSJ;
  87. dr["SCZS"] = str_SCZS;
  88. dr["FLFA"] = str_FLFA;
  89. dr["YJCTZ"] = str_YJCTZ;
  90. dr["SCMJ"] = str_SCMJ;
  91. dr["CKBZ"] = str_CKBZ;
  92. ls_new_dt.Rows.Add(dr);
  93. m_list_dt.Add(ls_new_dt);
  94. return ls_new_dt;
  95. }
  96. #endregion
  97. #region 一次性读取数据所需要的数据
  98. public bool GetDBData()
  99. {
  100. m_bt_DBData.Clear();
  101. m_bt_DBData.Columns.Clear();
  102. ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResult()].FilePath);
  103. List<string> colid = new List<string>() { "TypeName", "ar", "TypeId", "Largest", "Class", "con" };
  104. //获取粒级表
  105. string path1 = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.FileFolderSize + m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile;
  106. DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXml(path1);
  107. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  108. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  109. {
  110. if (sizestr.Split(',')[i].Length > 0)
  111. {
  112. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  113. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  114. colid.Add(d1.ToString() + "~" + d2.ToString());
  115. }
  116. }
  117. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  118. colid.Add(d.ToString() + "~MAX");
  119. for (int i=0;i< colid.Count;i++)
  120. {
  121. m_bt_DBData.Columns.Add(colid[i].ToString());
  122. }
  123. DataTable dt = fielddata.GetParticleListForParticlSize("area", "");
  124. DataTable AreaInformationOfAllElements = fielddata.GetAreaByAllIncA("");//获取所有分类面积和数量信息
  125. DataTable dtp = fielddata.GetParticleAll("");
  126. List<string> vs = new List<string>() { "DMAX", "DMIN", "Area", "FERET" };
  127. string po = vs[m_otsreport_export.m_mbszclass.M_KLFXJG.index_cb_klcc_jsfs];
  128. for (int i=0;i< dt.Rows.Count;i++)
  129. {
  130. DataRow dr = m_bt_DBData.NewRow();
  131. dr["TypeName"] = dt.Rows[i]["TypeName"].ToString();
  132. dr["TypeId"] = dt.Rows[i]["TypeId"].ToString();
  133. dr["con"]= dt.Rows[i]["con"].ToString();
  134. dr["Class"] = dt.Rows[i]["GroupName"].ToString();
  135. dr["Largest"] = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  136. for (int a=6;a< colid.Count;a++)
  137. {
  138. string d1 = colid[a].Split('~')[0];
  139. string d2 = colid[a].Split('~')[1];
  140. if (d2 == "MAX")
  141. {
  142. d2 = "999";
  143. }
  144. DataRow[] datas = dtp.Select(getWhere(d2, d1, po, dt.Rows[i]["TypeId"].ToString()));
  145. dr[colid[a]] = datas.Count();
  146. }
  147. for (int a=0;a< AreaInformationOfAllElements.Rows.Count;a++)
  148. {
  149. if (dt.Rows[i]["TypeId"].ToString()== AreaInformationOfAllElements.Rows[a]["TypeId"].ToString())
  150. {
  151. dr["ar"] = AreaInformationOfAllElements.Rows[a]["ar"];
  152. }
  153. }
  154. m_bt_DBData.Rows.Add(dr);
  155. }
  156. return true;
  157. }
  158. private string getWhere(string max, string min, string col, string partic)
  159. {
  160. return col + ">=" + min + " and " + col + "<" + max + " and TypeId=" + partic;
  161. }
  162. #endregion
  163. #region 插入颗粒列表并带有帧图
  164. /// <summary>
  165. /// 颗粒列表中插入帧图,并带上颗粒分组信息
  166. /// </summary>
  167. /// <returns></returns>
  168. public bool InsertReportTemplateTable_ParticlesGridDevidePage()
  169. {
  170. int serialNumber = 1;
  171. //------------------加载模块,获取数据-------------------------------------------------
  172. m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage = new ParticlesGridDevidePage(m_otsreport_export.m_ReportApp);
  173. //根据sql条件,查询获取颗粒信息数据
  174. ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResult()].FilePath);
  175. DataTable dt = fielddata.GetIncaSurfaceData();
  176. //将颗粒大小排序(从大到小)
  177. DataView dv = dt.DefaultView;
  178. dv.Sort = "Area DESC";
  179. DataTable dt_ParticlesGridDevidePage = dv.ToTable();
  180. string str_resultPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResult()].FilePath;
  181. //------------------加载模块,获取数据结束----------------------------------------------
  182. #region 创建要插入数据库表结构
  183. //插入模板需父子表,结构
  184. //表名field_dt表:(父表) 帧图表
  185. DataTable DT_field_dt = new DataTable();
  186. DT_field_dt.TableName = "field_dt";
  187. DataColumn colpictid2 = new DataColumn("FieldId");
  188. colpictid2.DataType = typeof(int);
  189. DT_field_dt.Columns.Add(colpictid2);
  190. //图像列
  191. DataColumn colpict2 = new DataColumn("FieldImg");
  192. colpict2.DataType = System.Type.GetType("System.Byte[]");
  193. DT_field_dt.Columns.Add(colpict2);
  194. //表名Largest_frame表:(子表) 显示20条颗粒除外的部份颗粒信息
  195. DataTable DT_field_dt_copy = new DataTable();
  196. DataTable DT_Largest_frame = new DataTable();
  197. DT_Largest_frame.TableName = "Largest_frame";
  198. DT_Largest_frame.Columns.Add("pid");
  199. DT_Largest_frame.Columns.Add("Size");
  200. DT_Largest_frame.Columns.Add("Width");
  201. DT_Largest_frame.Columns.Add("DMAX");
  202. DT_Largest_frame.Columns.Add("DMIN");
  203. DT_Largest_frame.Columns.Add("Class");
  204. DT_Largest_frame.Columns.Add("ColName1");
  205. DT_Largest_frame.Columns.Add("ColName2");
  206. DT_Largest_frame.Columns.Add("ColName3");
  207. DT_Largest_frame.Columns.Add("ColName4");
  208. DT_Largest_frame.Columns.Add("ColName5");
  209. DT_Largest_frame.Columns.Add("ColName6");
  210. DT_Largest_frame.Columns.Add("ColVal1");
  211. DT_Largest_frame.Columns.Add("ColVal2");
  212. DT_Largest_frame.Columns.Add("ColVal3");
  213. DT_Largest_frame.Columns.Add("ColVal4");
  214. DT_Largest_frame.Columns.Add("ColVal5");
  215. DT_Largest_frame.Columns.Add("ColVal6");
  216. DataColumn colpictid = new DataColumn("FieldId");
  217. colpictid.DataType = typeof(int);
  218. DT_Largest_frame.Columns.Add(colpictid);
  219. //图像列
  220. DataColumn colpict = new DataColumn("p1");
  221. colpict.DataType = System.Type.GetType("System.Byte[]");
  222. DT_Largest_frame.Columns.Add(colpict);
  223. //largest20表:(无关系表) 需要显示前20条带有显示能谱图像的颗粒表
  224. DataTable DT_Largest20 = new DataTable();
  225. DT_Largest20.TableName = "Largest20";
  226. DT_Largest20.Columns.Add("pid");
  227. DT_Largest20.Columns.Add("Size");
  228. DT_Largest20.Columns.Add("Width");
  229. DT_Largest20.Columns.Add("DMAX");
  230. DT_Largest20.Columns.Add("DMIN");
  231. DT_Largest20.Columns.Add("Class");
  232. DT_Largest20.Columns.Add("ColName1");
  233. DT_Largest20.Columns.Add("ColName2");
  234. DT_Largest20.Columns.Add("ColName3");
  235. DT_Largest20.Columns.Add("ColName4");
  236. DT_Largest20.Columns.Add("ColName5");
  237. DT_Largest20.Columns.Add("ColName6");
  238. DT_Largest20.Columns.Add("ColVal1");
  239. DT_Largest20.Columns.Add("ColVal2");
  240. DT_Largest20.Columns.Add("ColVal3");
  241. DT_Largest20.Columns.Add("ColVal4");
  242. DT_Largest20.Columns.Add("ColVal5");
  243. DT_Largest20.Columns.Add("ColVal6");
  244. // 图像列
  245. DataColumn colpict_20ago = new DataColumn("p1");
  246. colpict_20ago.DataType = System.Type.GetType("System.Byte[]");
  247. DT_Largest20.Columns.Add(colpict_20ago);
  248. DataColumn colpict2_20ago = new DataColumn("p2");
  249. colpict2_20ago.DataType = System.Type.GetType("System.Byte[]");
  250. DT_Largest20.Columns.Add(colpict2_20ago);
  251. DataColumn colpict3_20ago = new DataColumn("p3");
  252. colpict3_20ago.DataType = System.Type.GetType("System.Byte[]");
  253. DT_Largest20.Columns.Add(colpict3_20ago);
  254. #endregion
  255. #region 插入-前20颗粒部份
  256. for (int i_row = 0; i_row < dt_ParticlesGridDevidePage.Rows.Count; i_row++)
  257. {
  258. if (dt_ParticlesGridDevidePage.Rows[i_row].ItemArray[24].ToString()!= "Not Identified")
  259. {
  260. //获取颗粒的fieldid,和particleid
  261. string str_fieldid = dt_ParticlesGridDevidePage.Rows[i_row]["fieldid"].ToString();
  262. string str_particleid = dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  263. string str_subparticles = dt_ParticlesGridDevidePage.Rows[i_row]["SubParticles"].ToString();
  264. string str_typeid = dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString();
  265. string str_typename = dt_ParticlesGridDevidePage.Rows[i_row]["TypeName"].ToString();
  266. string str_element = dt_ParticlesGridDevidePage.Rows[i_row]["Element"].ToString();
  267. //获取原始颗粒图像
  268. Bitmap bp_particle = new Bitmap(1, 1);
  269. string str_path = str_resultPath + "\\FIELD_FILES\\";
  270. string str_imagePath = str_path + "Field" + str_fieldid.ToString() + ".bmp";
  271. if (str_fieldid == "-1")
  272. continue;
  273. if (serialNumber > 20)
  274. continue;
  275. if (str_subparticles != null && str_subparticles != "")
  276. {
  277. //合并大颗粒
  278. double ScanFieldSize = 1142;
  279. Bitmap tempbit = fielddata.ReadImageFile(str_imagePath);
  280. int pixw = tempbit.Width;
  281. double xs = pixw / ScanFieldSize;
  282. bp_particle = fielddata.GetBitmapForBig(str_subparticles, xs, str_resultPath);
  283. }
  284. else
  285. {
  286. //正常颗粒
  287. 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"]) };
  288. Bitmap bp_field = fielddata.ReadImageFile(str_imagePath);
  289. bp_particle = fielddata.GetBitmapByParticle(bp_field, rectangle);
  290. 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() };
  291. }
  292. //获取该颗粒的xray能谱图像
  293. System.Drawing.Bitmap bp_xraybp = ExportXRayBitmap(str_fieldid,
  294. str_particleid, Convert.ToInt32(str_typeid), str_typename, fielddata);
  295. Bitmap ls_xraybpnew = new Bitmap(1, 1);
  296. ls_xraybpnew = OTSIncAReportGraph.Class.DrawFunction.KiResizeImage(bp_xraybp, 700, 115);//能谱图处理
  297. //获取该颗粒的二次放大处理图像
  298. Bitmap ls_processbitmap = new Bitmap(1, 1);
  299. ls_processbitmap = OTSIncAReportGraph.Class.DrawFunction.GetReZoomBitmap(bp_particle);// (Bitmap)bp_particle.Clone();//待完善
  300. //再将图像转成二进制流-------------------------------------------------------------------
  301. //原图
  302. MemoryStream newms_p1 = new MemoryStream();
  303. bp_particle.Save(newms_p1, System.Drawing.Imaging.ImageFormat.Bmp);
  304. newms_p1.Seek(0, SeekOrigin.Begin);
  305. byte[] newarr_p1 = new byte[newms_p1.Length];
  306. newms_p1.Read(newarr_p1, 0, newarr_p1.Length);
  307. //二次放大图
  308. MemoryStream newms_p2 = new MemoryStream();
  309. ls_processbitmap.Save(newms_p2, System.Drawing.Imaging.ImageFormat.Bmp);
  310. newms_p2.Seek(0, SeekOrigin.Begin);
  311. byte[] newarr_p2 = new byte[newms_p2.Length];
  312. newms_p2.Read(newarr_p2, 0, newarr_p2.Length);
  313. //能谱图
  314. MemoryStream newms_p3 = new MemoryStream();
  315. ls_xraybpnew.Save(newms_p3, System.Drawing.Imaging.ImageFormat.Bmp);
  316. newms_p3.Seek(0, SeekOrigin.Begin);
  317. byte[] newarr_p3 = new byte[newms_p3.Length];
  318. newms_p3.Read(newarr_p3, 0, newarr_p3.Length);
  319. //---------------------------------------------------------------------------------------
  320. DataRow dr = DT_Largest20.NewRow();
  321. dr["p1"] = newarr_p1;
  322. dr["p2"] = newarr_p2;
  323. dr["p3"] = newarr_p3;
  324. newms_p1.Dispose();
  325. newms_p2.Dispose();
  326. newms_p3.Dispose();
  327. dr["pid"] = serialNumber++.ToString();
  328. //dr["pid"] = str_fieldid + dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  329. dr["Size"] = Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["area"]).ToString("#0.00"); //可以需要选择切换,计算方式
  330. dr["Width"] = dt_ParticlesGridDevidePage.Rows[i_row]["rectwidth"].ToString();
  331. dr["DMAX"] = Math.Round(Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["dmax"]), 2).ToString();
  332. dr["DMIN"] = Math.Round(Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["dmin"]), 2).ToString();
  333. dr["Class"] = dt_ParticlesGridDevidePage.Rows[i_row]["typename"].ToString();
  334. List<string> list_max_elementname = new List<string>();
  335. List<double> list_max_elementvale = new List<double>();
  336. GetMaxElementFromDataTable(dt_ParticlesGridDevidePage, i_row, out list_max_elementname, out list_max_elementvale);
  337. //元素1
  338. dr["ColName1"] = list_max_elementname[0];
  339. dr["ColVal1"] = list_max_elementvale[0].ToString();
  340. //元素2
  341. dr["ColName2"] = list_max_elementname[1];
  342. dr["ColVal2"] = list_max_elementvale[1].ToString();
  343. //元素3
  344. dr["ColName3"] = list_max_elementname[2];
  345. dr["ColVal3"] = list_max_elementvale[2].ToString();
  346. //元素4
  347. dr["ColName4"] = list_max_elementname[3];
  348. dr["ColVal4"] = list_max_elementvale[3].ToString();
  349. //元素5
  350. dr["ColName5"] = list_max_elementname[4];
  351. dr["ColVal5"] = list_max_elementvale[4].ToString();
  352. //元素6
  353. dr["ColName6"] = list_max_elementname[5];
  354. dr["ColVal6"] = list_max_elementvale[5].ToString();
  355. DT_Largest20.Rows.Add(dr);
  356. }
  357. }
  358. #endregion
  359. #region 插入-帧图图像部份
  360. //首先生成标记颗粒的帧图图像文件
  361. m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage.SaveMarkParticleRectangleOnFieldFile(dt_ParticlesGridDevidePage);
  362. string str_path_FIELD_FILES_MARK = str_resultPath + "\\FIELD_FILES_MARK\\";
  363. DirectoryInfo theFolder = new DirectoryInfo(str_path_FIELD_FILES_MARK);
  364. if (theFolder.Exists)
  365. {
  366. //for (int i = 0; i <= theFolder.GetFiles().Count(); i++)
  367. //{
  368. // //判断i.bmp图片是否存在,如果不存在跳出当前循环
  369. // if (!DetermineWhetherTheFileExists(theFolder, i))
  370. // continue;
  371. // //在数据表中有颗粒在该帧图中的话,则对该帧图标记图像进行读取存入数据库
  372. // DataRow[] datarowlist = dt_ParticlesGridDevidePage.Select(" fieldid = " + i);
  373. // if (datarowlist.Count() > 0)
  374. // {
  375. // Bitmap ls_bp_fieldmark = new Bitmap(theFolder.GetFiles()[i].FullName);
  376. // DataRow dr = DT_field_dt.NewRow();
  377. // MemoryStream newms_bp_fieldmark = new MemoryStream();
  378. // ls_bp_fieldmark.Save(newms_bp_fieldmark, System.Drawing.Imaging.ImageFormat.Bmp);
  379. // newms_bp_fieldmark.Seek(0, SeekOrigin.Begin);
  380. // byte[] newarr_fieldmark = new byte[newms_bp_fieldmark.Length];
  381. // newms_bp_fieldmark.Read(newarr_fieldmark, 0, newarr_fieldmark.Length);
  382. // dr["FieldImg"] = newarr_fieldmark;
  383. // dr["FieldId"] = i;
  384. // ls_bp_fieldmark.Dispose();
  385. // DT_field_dt.Rows.Add(dr);
  386. // }
  387. //}
  388. foreach (FileInfo nextifile in theFolder.GetFiles())
  389. {
  390. if (nextifile.Name.Contains(".bmp") == true || nextifile.Name.Contains(".BMP") == true)
  391. {
  392. //确认对应的帧图名
  393. string str_fieldid = Path.GetFileNameWithoutExtension(nextifile.Name);
  394. //在数据表中有颗粒在该帧图中的话,则对该帧图标记图像进行读取存入数据库
  395. DataRow[] datarowlist = dt_ParticlesGridDevidePage.Select(" fieldid = " + str_fieldid);
  396. if (datarowlist.Count() > 0)
  397. {
  398. Bitmap ls_bp_fieldmark = new Bitmap(nextifile.FullName);
  399. DataRow dr = DT_field_dt.NewRow();
  400. MemoryStream newms_bp_fieldmark = new MemoryStream();
  401. ls_bp_fieldmark.Save(newms_bp_fieldmark, System.Drawing.Imaging.ImageFormat.Bmp);
  402. newms_bp_fieldmark.Seek(0, SeekOrigin.Begin);
  403. byte[] newarr_fieldmark = new byte[newms_bp_fieldmark.Length];
  404. newms_bp_fieldmark.Read(newarr_fieldmark, 0, newarr_fieldmark.Length);
  405. dr["FieldImg"] = newarr_fieldmark;
  406. dr["FieldId"] = str_fieldid;
  407. ls_bp_fieldmark.Dispose();
  408. DT_field_dt.Rows.Add(dr);
  409. }
  410. }
  411. }
  412. DataView vw = DT_field_dt.DefaultView;
  413. vw.Sort = "FieldId ASC";
  414. DT_field_dt_copy = vw.ToTable();
  415. }
  416. #endregion
  417. #region 插入-前20颗粒外的颗粒
  418. for (int i_row = 0; i_row < dt_ParticlesGridDevidePage.Rows.Count; i_row++)
  419. {
  420. if (dt_ParticlesGridDevidePage.Rows[i_row]["element"].ToString() == "")
  421. continue;
  422. //获取颗粒的fieldid,和particleid
  423. string str_fieldid = dt_ParticlesGridDevidePage.Rows[i_row]["fieldid"].ToString();
  424. if (Convert.ToInt32(str_fieldid) < 20)
  425. {
  426. string str_particleid = dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  427. string str_subparticles = dt_ParticlesGridDevidePage.Rows[i_row]["SubParticles"].ToString();
  428. string str_typeid = dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString();
  429. string str_typename = dt_ParticlesGridDevidePage.Rows[i_row]["TypeName"].ToString();
  430. string str_element = dt_ParticlesGridDevidePage.Rows[i_row]["Element"].ToString();
  431. //获取原始颗粒图像
  432. Bitmap bp_particle = new Bitmap(1, 1);
  433. string str_path = str_resultPath + "\\FIELD_FILES\\";
  434. string str_imagePath = str_path + "Field" + str_fieldid.ToString() + ".bmp";
  435. if (str_subparticles != null && str_subparticles != "")
  436. {
  437. //合并大颗粒
  438. //double ScanFieldSize = 1142;
  439. //Bitmap tempbit = fielddata.ReadImageFile(str_imagePath);
  440. //int pixw = tempbit.Width;
  441. //double xs = pixw / ScanFieldSize;
  442. //bp_particle = fielddata.GetBitmapForBig(str_subparticles, xs, str_resultPath);
  443. continue;
  444. }
  445. else
  446. {
  447. //正常颗粒
  448. 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"]) };
  449. Bitmap bp_field = fielddata.ReadImageFile(str_imagePath);
  450. bp_particle = fielddata.GetBitmapByParticle(bp_field, rectangle);
  451. 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() };
  452. }
  453. //获取该颗粒的xray能谱图像
  454. System.Drawing.Bitmap bp_xraybp = ExportXRayBitmap(str_fieldid,
  455. str_particleid, Convert.ToInt32(str_typeid), str_typename, fielddata);
  456. //获取该颗粒的二次放大处理图像
  457. Bitmap ls_processbitmap = new Bitmap(1, 1);
  458. ls_processbitmap = (Bitmap)bp_particle.Clone();//待完善
  459. //再将图像转成二进制流-------------------------------------------------------------------
  460. //原图
  461. MemoryStream newms_p1 = new MemoryStream();
  462. bp_particle.Save(newms_p1, System.Drawing.Imaging.ImageFormat.Bmp);
  463. newms_p1.Seek(0, SeekOrigin.Begin);
  464. byte[] newarr_p1 = new byte[newms_p1.Length];
  465. newms_p1.Read(newarr_p1, 0, newarr_p1.Length);
  466. //---------------------------------------------------------------------------------------
  467. DataRow dr = DT_Largest_frame.NewRow();
  468. dr["p1"] = newarr_p1;
  469. newms_p1.Dispose();
  470. dr["pid"] = str_fieldid + dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  471. dr["Size"] = Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["area"]).ToString("#0.00"); //可以需要选择切换,计算方式
  472. dr["Width"] = dt_ParticlesGridDevidePage.Rows[i_row]["rectwidth"].ToString();
  473. dr["DMAX"] = Math.Round(Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["dmax"]),2).ToString();
  474. dr["DMIN"] = Math.Round(Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["dmin"]),2).ToString();
  475. dr["Class"] = dt_ParticlesGridDevidePage.Rows[i_row]["typename"].ToString();
  476. dr["fieldid"] = str_fieldid;
  477. List<string> list_max_elementname = new List<string>();
  478. List<double> list_max_elementvale = new List<double>();
  479. GetMaxElementFromDataTable(dt_ParticlesGridDevidePage, i_row, out list_max_elementname, out list_max_elementvale);
  480. //元素1
  481. dr["ColName1"] = list_max_elementname[0];
  482. dr["ColVal1"] = list_max_elementvale[0].ToString();
  483. //元素2
  484. dr["ColName2"] = list_max_elementname[1];
  485. dr["ColVal2"] = list_max_elementvale[1].ToString();
  486. //元素3
  487. dr["ColName3"] = list_max_elementname[2];
  488. dr["ColVal3"] = list_max_elementvale[2].ToString();
  489. //元素4
  490. dr["ColName4"] = list_max_elementname[3];
  491. dr["ColVal4"] = list_max_elementvale[3].ToString();
  492. //元素5
  493. dr["ColName5"] = list_max_elementname[4];
  494. dr["ColVal5"] = list_max_elementvale[4].ToString();
  495. //元素6
  496. dr["ColName6"] = list_max_elementname[5];
  497. dr["ColVal6"] = list_max_elementvale[5].ToString();
  498. DT_Largest_frame.Rows.Add(dr);
  499. }
  500. }
  501. #endregion
  502. FrameGraphParticleTable(dt_ParticlesGridDevidePage, str_resultPath, fielddata, DT_field_dt);
  503. m_list_dt.Add(DT_field_dt_copy);
  504. m_list_dt.Add(DT_Largest_frame);
  505. m_list_dt.Add(DT_Largest20);
  506. return true;
  507. }
  508. private bool JudgeWhetherItExists(int id, DataTable dt,string column)
  509. {
  510. for (int i=0;i<dt.Rows.Count;i++)
  511. {
  512. if (id == Convert.ToInt32(dt.Rows[i][column].ToString()))
  513. return true;
  514. }
  515. return false;
  516. }
  517. /// <param name="dt_ParticlesGridDevidePage">数据源</param>
  518. /// <param name="str_resultPath">地址</param>
  519. /// <param name="fielddata"></param>
  520. /// <param name="DT_field_dt">主表</param>
  521. private void FrameGraphParticleTable(DataTable dt_ParticlesGridDevidePage,string str_resultPath, ParticleData fielddata,DataTable DT_field_dt)
  522. {
  523. //表名Largest_frame表:(子表) 显示20条颗粒除外的部份颗粒信息
  524. DataTable FrameGraphSubTable = new DataTable();
  525. FrameGraphSubTable.TableName = "FrameGraphSubTable";
  526. FrameGraphSubTable.Columns.Add("pid");
  527. FrameGraphSubTable.Columns.Add("Size");
  528. FrameGraphSubTable.Columns.Add("Width");
  529. FrameGraphSubTable.Columns.Add("DMAX");
  530. FrameGraphSubTable.Columns.Add("DMIN");
  531. FrameGraphSubTable.Columns.Add("Class");
  532. FrameGraphSubTable.Columns.Add("ColName1");
  533. FrameGraphSubTable.Columns.Add("ColName2");
  534. FrameGraphSubTable.Columns.Add("ColName3");
  535. FrameGraphSubTable.Columns.Add("ColName4");
  536. FrameGraphSubTable.Columns.Add("ColName5");
  537. FrameGraphSubTable.Columns.Add("ColName6");
  538. FrameGraphSubTable.Columns.Add("ColVal1");
  539. FrameGraphSubTable.Columns.Add("ColVal2");
  540. FrameGraphSubTable.Columns.Add("ColVal3");
  541. FrameGraphSubTable.Columns.Add("ColVal4");
  542. FrameGraphSubTable.Columns.Add("ColVal5");
  543. FrameGraphSubTable.Columns.Add("ColVal6");
  544. DataColumn colpictid = new DataColumn("FieldId");
  545. colpictid.DataType = typeof(int);
  546. FrameGraphSubTable.Columns.Add(colpictid);
  547. //图像列
  548. DataColumn colpict = new DataColumn("p1");
  549. colpict.DataType = System.Type.GetType("System.Byte[]");
  550. FrameGraphSubTable.Columns.Add(colpict);
  551. for (int i_row = 0; i_row < dt_ParticlesGridDevidePage.Rows.Count; i_row++)
  552. {
  553. if (dt_ParticlesGridDevidePage.Rows[i_row]["element"].ToString() == "")
  554. continue;
  555. //获取颗粒的fieldid,和particleid
  556. string str_fieldid = dt_ParticlesGridDevidePage.Rows[i_row]["fieldid"].ToString();
  557. //if (Convert.ToInt32(str_fieldid) < 20)
  558. if (JudgeWhetherItExists(Convert.ToInt32(str_fieldid), DT_field_dt, "FieldId"))
  559. {
  560. string str_particleid = dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  561. string str_subparticles = dt_ParticlesGridDevidePage.Rows[i_row]["SubParticles"].ToString();
  562. string str_typeid = dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString();
  563. string str_typename = dt_ParticlesGridDevidePage.Rows[i_row]["TypeName"].ToString();
  564. string str_element = dt_ParticlesGridDevidePage.Rows[i_row]["Element"].ToString();
  565. //获取原始颗粒图像
  566. Bitmap bp_particle = new Bitmap(1, 1);
  567. string str_path = str_resultPath + "\\FIELD_FILES\\";
  568. string str_imagePath = str_path + "Field" + str_fieldid.ToString() + ".bmp";
  569. if (str_subparticles != null && str_subparticles != "")
  570. {
  571. continue;
  572. }
  573. else
  574. {
  575. //正常颗粒
  576. 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"]) };
  577. Bitmap bp_field = fielddata.ReadImageFile(str_imagePath);
  578. bp_particle = fielddata.GetBitmapByParticle(bp_field, rectangle);
  579. 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() };
  580. }
  581. //获取该颗粒的xray能谱图像
  582. System.Drawing.Bitmap bp_xraybp = ExportXRayBitmap(str_fieldid,
  583. str_particleid, Convert.ToInt32(str_typeid), str_typename, fielddata);
  584. //获取该颗粒的二次放大处理图像
  585. Bitmap ls_processbitmap = new Bitmap(1, 1);
  586. ls_processbitmap = (Bitmap)bp_particle.Clone();//待完善
  587. //再将图像转成二进制流-------------------------------------------------------------------
  588. //原图
  589. MemoryStream newms_p1 = new MemoryStream();
  590. bp_particle.Save(newms_p1, System.Drawing.Imaging.ImageFormat.Bmp);
  591. newms_p1.Seek(0, SeekOrigin.Begin);
  592. byte[] newarr_p1 = new byte[newms_p1.Length];
  593. newms_p1.Read(newarr_p1, 0, newarr_p1.Length);
  594. //---------------------------------------------------------------------------------------
  595. DataRow dr = FrameGraphSubTable.NewRow();
  596. dr["p1"] = newarr_p1;
  597. newms_p1.Dispose();
  598. dr["pid"] = str_fieldid + dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
  599. dr["Size"] = Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["area"]).ToString("#0.00"); //可以需要选择切换,计算方式
  600. dr["Width"] = dt_ParticlesGridDevidePage.Rows[i_row]["rectwidth"].ToString();
  601. dr["DMAX"] = Math.Round(Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["dmax"]),2).ToString();
  602. dr["DMIN"] = Math.Round(Convert.ToDouble(dt_ParticlesGridDevidePage.Rows[i_row]["dmin"]),2).ToString();
  603. dr["Class"] = dt_ParticlesGridDevidePage.Rows[i_row]["typename"].ToString();
  604. dr["fieldid"] = str_fieldid;
  605. List<string> list_max_elementname = new List<string>();
  606. List<double> list_max_elementvale = new List<double>();
  607. GetMaxElementFromDataTable(dt_ParticlesGridDevidePage, i_row, out list_max_elementname, out list_max_elementvale);
  608. //元素1
  609. dr["ColName1"] = list_max_elementname[0];
  610. dr["ColVal1"] = list_max_elementvale[0].ToString();
  611. //元素2
  612. dr["ColName2"] = list_max_elementname[1];
  613. dr["ColVal2"] = list_max_elementvale[1].ToString();
  614. //元素3
  615. dr["ColName3"] = list_max_elementname[2];
  616. dr["ColVal3"] = list_max_elementvale[2].ToString();
  617. //元素4
  618. dr["ColName4"] = list_max_elementname[3];
  619. dr["ColVal4"] = list_max_elementvale[3].ToString();
  620. //元素5
  621. dr["ColName5"] = list_max_elementname[4];
  622. dr["ColVal5"] = list_max_elementvale[4].ToString();
  623. //元素6
  624. dr["ColName6"] = list_max_elementname[5];
  625. dr["ColVal6"] = list_max_elementvale[5].ToString();
  626. FrameGraphSubTable.Rows.Add(dr);
  627. }
  628. }
  629. m_list_dt.Add(FrameGraphSubTable);
  630. }
  631. #endregion
  632. #region 插入颗粒尺寸表
  633. /// <summary>
  634. /// 向 模板设计器 中插入 颗粒尺寸表
  635. /// </summary>
  636. /// <returns></returns>
  637. public bool InsertReportTemplateTable_ParticleSizeGrid()
  638. {
  639. try
  640. {
  641. if (m_bt_DBData.Columns.Count==0)
  642. {
  643. GetDBData();
  644. }
  645. List<string> colid = new List<string>();
  646. //获取粒级表
  647. string path1 = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.FileFolderSize + m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile;
  648. DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXml(path1);
  649. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  650. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  651. {
  652. if (sizestr.Split(',')[i].Length > 0)
  653. {
  654. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  655. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  656. colid.Add(d1.ToString() + "~" + d2.ToString());
  657. }
  658. }
  659. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  660. colid.Add(d.ToString() + "~MAX");
  661. ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResult()].FilePath);
  662. //------------------------------------------------
  663. DataTable ls_partsize_dt = new DataTable();
  664. ls_partsize_dt.TableName = "PartSize";
  665. ls_partsize_dt.Columns.Add("c1");
  666. ls_partsize_dt.Columns.Add("c2");
  667. ls_partsize_dt.Columns.Add("c3");
  668. ls_partsize_dt.Columns.Add("c4");
  669. ls_partsize_dt.Columns.Add("c5");
  670. ls_partsize_dt.Columns.Add("c6");
  671. ls_partsize_dt.Columns.Add("c7");
  672. ls_partsize_dt.Columns.Add("c8");
  673. ls_partsize_dt.Columns.Add("c9");
  674. DataRow dr = ls_partsize_dt.NewRow();
  675. for (int i=1;i<10;i++)
  676. {
  677. if (colid.Count<i)
  678. {
  679. dr["c" + i.ToString()] = "";
  680. }
  681. else
  682. {
  683. dr["c" + i.ToString()] = colid[i - 1];
  684. }
  685. }
  686. ls_partsize_dt.Rows.Add(dr);
  687. DataTable ls_Particel_dt = new DataTable();
  688. ls_Particel_dt.TableName = "Particel";
  689. ls_Particel_dt.Columns.Add("c1", typeof(double));
  690. ls_Particel_dt.Columns.Add("c2", typeof(double));
  691. ls_Particel_dt.Columns.Add("c3", typeof(double));
  692. ls_Particel_dt.Columns.Add("c4", typeof(double));
  693. ls_Particel_dt.Columns.Add("c5", typeof(double));
  694. ls_Particel_dt.Columns.Add("c6", typeof(double));
  695. ls_Particel_dt.Columns.Add("c7", typeof(double));
  696. ls_Particel_dt.Columns.Add("c8", typeof(double));
  697. ls_Particel_dt.Columns.Add("c9", typeof(double));
  698. ls_Particel_dt.Columns.Add("Name");
  699. ls_Particel_dt.Columns.Add("total", typeof(double));
  700. ls_Particel_dt.Columns.Add("TypeId");
  701. ls_Particel_dt.Columns.Add("Class");
  702. for (int i = 0; i < m_bt_DBData.Rows.Count; i++)
  703. {
  704. DataRow dr2 = ls_Particel_dt.NewRow();
  705. dr2["Name"] = m_bt_DBData.Rows[i]["TypeName"].ToString();
  706. dr2["Class"] = m_bt_DBData.Rows[i]["Class"].ToString();
  707. dr2["TypeId"] = m_bt_DBData.Rows[i]["TypeId"].ToString();//获取分类编号
  708. for (int j=1;j< 10;j++)
  709. {
  710. if (colid.Count >= j)
  711. {
  712. dr2["c" + j.ToString()] = Convert.ToDouble(m_bt_DBData.Rows[i][colid[j-1]]);
  713. }
  714. }
  715. if (dr2["Name"].ToString() != "" && dr2["Name"].ToString().IndexOf("number") < 0)
  716. {
  717. dr2["total"] = "0"; //求合
  718. double d_total = 0;
  719. for (int j = 1; j < 10; j++)
  720. {
  721. if (colid.Count >= j)
  722. {
  723. d_total = d_total + Convert.ToInt64(m_bt_DBData.Rows[i][colid[j - 1]]);
  724. }
  725. }
  726. dr2["total"] = d_total.ToString();
  727. }
  728. ls_Particel_dt.Rows.Add(dr2);
  729. }
  730. //按照list列表进行物质类排序,物质类中的元素分类按照面积的大小进行排序
  731. List<string> ClassName = new List<string>();
  732. DataTable getClass_dt = fielddata.GetAllClass();
  733. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  734. {
  735. if (getClass_dt.Rows[i]["GroupName"].ToString() != "NOT_INCLUTION")
  736. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  737. }
  738. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  739. {
  740. if (getClass_dt.Rows[i]["GroupName"].ToString() == "NOT_INCLUTION")
  741. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  742. }
  743. //获取大分类信息
  744. DataTable dt = QuantityOfIntegratedSubstances(ls_Particel_dt, ClassName);
  745. ClassificationSort(ls_Particel_dt,ClassName, dt);
  746. m_list_dt.Add(ls_partsize_dt);
  747. return true;
  748. }
  749. catch (Exception ee)
  750. {
  751. m_otsreport_export.WriteRictBox(ee.ToString());
  752. return false;
  753. }
  754. }
  755. private DataTable QuantityOfIntegratedSubstances(DataTable dataTable, List<string> ClassName )
  756. {
  757. DataTable dt_Class = dataTable.Copy();
  758. dt_Class.Clear();
  759. dt_Class.TableName = "Particel";
  760. dt_Class.Columns.Remove("Name");
  761. dt_Class.Columns.Remove("TypeId");
  762. for (int i = 0; i < ClassName.Count; i++)
  763. {
  764. //保留当前循环中大类物质,去除其他物质
  765. DataTable dt = dataTable.Copy();
  766. dt.Clear();
  767. for (int a = 0; a < dataTable.Rows.Count; a++)
  768. {
  769. if (dataTable.Rows[a]["Class"].ToString() == ClassName[i].ToString())
  770. {
  771. dt.Rows.Add(dataTable.Rows[a].ItemArray);
  772. }
  773. }
  774. if (dt.Rows.Count == 0)
  775. continue;
  776. DataTable dt_2 = new DataTable();
  777. dt_2 = dataTable.Copy();
  778. dt_2.Clear();
  779. DataRow row = dt_2.NewRow();
  780. dt_2.Rows.Add(row);
  781. for (int a=0;a< dt.Columns.Count;a++)
  782. {
  783. if (dt.Columns[a].ToString() != "Name" && dt.Columns[a].ToString() != "Class"&&dt.Columns[a].ToString()!= "TypeId")
  784. {
  785. bool bl = false;
  786. for (int b = 0; b < dt.Rows.Count; b++)
  787. {
  788. if (!dt.Rows[b].IsNull(dt.Columns[a].ToString()))
  789. {
  790. bl = true;
  791. }
  792. }
  793. if (bl)
  794. {
  795. dt_2.Rows[0][dt.Columns[a].ToString()] = decimal.Parse(dt.Compute("sum(" + dt.Columns[a].ToString() + ")", "").ToString());
  796. }
  797. }
  798. }
  799. dt_2.Columns.Remove("Name");
  800. dt_2.Columns.Remove("TypeId");
  801. dt_2.Rows[0]["Class"] = ClassName[i];
  802. //dt_2.Rows[0]["TypeId"] = dt.Rows[0]["TypeId"].ToString();
  803. dt_Class.Rows.Add(dt_2.Rows[0].ItemArray);
  804. }
  805. m_list_dt.Add(dt_Class);
  806. return dt_Class;
  807. }
  808. private void ClassificationSort(DataTable dataTable,List<string> ClassName,DataTable data)
  809. {
  810. DataTable dt = new DataTable();
  811. dt = dataTable.Copy();
  812. dt.Clear();
  813. dt.TableName = "Particel_subdivision";
  814. //循环list中每个类型
  815. for (int i=0;i< ClassName.Count();i++)
  816. {
  817. DataTable data1 = dt.Copy();
  818. data1.Clear();
  819. data1.Rows.Add();
  820. for (int a=0;a< data.Rows.Count;a++)
  821. {
  822. if (data.Rows[a]["Class"].ToString()== ClassName[i].ToString())
  823. {
  824. for (int b=1;b<10;b++)
  825. {
  826. data1.Rows[0]["c"+b.ToString()] = data.Rows[a]["c"+b.ToString()];
  827. }
  828. data1.Rows[0]["total"] = data.Rows[a]["total"];
  829. data1.Rows[0]["Class"] = data.Rows[a]["Class"];
  830. dt.Rows.Add(data1.Rows[0].ItemArray);
  831. }
  832. }
  833. DataTable dt_1 = new DataTable();
  834. dt_1 = dt.Copy();
  835. dt_1.Clear();
  836. //循环DataTable中每个分类的数据
  837. for (int a=0;a< dataTable.Rows.Count;a++)
  838. {
  839. if (dataTable.Rows[a]["Class"].ToString()== ClassName[i])
  840. {
  841. dataTable.Rows[a]["Class"] = "";
  842. dt_1.Rows.Add(dataTable.Rows[a].ItemArray);
  843. }
  844. }
  845. //将颗粒数量排序(从大到小)
  846. DataView dv = dt_1.DefaultView;
  847. dv.Sort = "total DESC";
  848. DataTable dt_1_sort = dv.ToTable();
  849. for (int a = 0; a < dt_1_sort.Rows.Count; a++)
  850. {
  851. dt.Rows.Add(dt_1_sort.Rows[a].ItemArray);
  852. }
  853. }
  854. dt.Columns.Remove("TypeId");
  855. m_list_dt.Add(dt);
  856. }
  857. #endregion
  858. #region 插入平均元素含量表
  859. /// <summary>
  860. /// 向 模板设计器 中插入 平均元素含量表
  861. /// </summary>
  862. /// <returns></returns>
  863. public bool InsertReportTemplateTable_ElementCompositionAvgGrid()
  864. {
  865. try
  866. {
  867. //加载模块
  868. ElementCompositionAvgGrid ls_elementcompositionavggrid = new ElementCompositionAvgGrid(m_otsreport_export.m_ReportApp);
  869. m_otsreport_export.panel_container.Controls.Clear();
  870. m_otsreport_export.panel_container.Controls.Add(ls_elementcompositionavggrid);
  871. DataGridView ls_gv = new DataGridView();
  872. DataTable ls_dt = new DataTable();
  873. ls_elementcompositionavggrid.GetDataTableAndGridView(out ls_dt, out ls_gv);
  874. //------------------------------------------------
  875. DataTable ls_elementname_dt = new DataTable();
  876. ls_elementname_dt.TableName = "ElementName";
  877. ls_elementname_dt.Columns.Add("e1");
  878. ls_elementname_dt.Columns.Add("e2");
  879. ls_elementname_dt.Columns.Add("e3");
  880. ls_elementname_dt.Columns.Add("e4");
  881. ls_elementname_dt.Columns.Add("e5");
  882. ls_elementname_dt.Columns.Add("e6");
  883. ls_elementname_dt.Columns.Add("e7");
  884. ls_elementname_dt.Columns.Add("e8");
  885. ls_elementname_dt.Columns.Add("e9");
  886. ls_elementname_dt.Columns.Add("e10");
  887. ls_elementname_dt.Columns.Add("e11");
  888. ls_elementname_dt.Columns.Add("e12");
  889. ls_elementname_dt.Columns.Add("e13");
  890. ls_elementname_dt.Columns.Add("e14");
  891. DataRow dr = ls_elementname_dt.NewRow();
  892. int col = 4;
  893. for (int i = 1; i < 15; i++)
  894. {
  895. if (ls_gv.Columns.Count > col)
  896. dr["e" + i.ToString()] = ls_gv.Columns[col++].Name;
  897. }
  898. ls_elementname_dt.Rows.Add(dr);
  899. DataTable ls_element_dt = new DataTable();
  900. ls_element_dt.TableName = "ElementValue";
  901. ls_element_dt.Columns.Add("e1");
  902. ls_element_dt.Columns.Add("e2");
  903. ls_element_dt.Columns.Add("e3");
  904. ls_element_dt.Columns.Add("e4");
  905. ls_element_dt.Columns.Add("e5");
  906. ls_element_dt.Columns.Add("e6");
  907. ls_element_dt.Columns.Add("e7");
  908. ls_element_dt.Columns.Add("e8");
  909. ls_element_dt.Columns.Add("e9");
  910. ls_element_dt.Columns.Add("e10");
  911. ls_element_dt.Columns.Add("e11");
  912. ls_element_dt.Columns.Add("e12");
  913. ls_element_dt.Columns.Add("e13");
  914. ls_element_dt.Columns.Add("e14");
  915. ls_element_dt.Columns.Add("PName");
  916. ls_element_dt.Columns.Add("Count");
  917. ls_element_dt.Columns.Add("AllElements");
  918. for (int i = 0; i < ls_gv.Rows.Count; i++)
  919. {
  920. DataRow dr2 = ls_element_dt.NewRow();
  921. dr2["PName"] = ls_gv.Rows[i].Cells[1].Value.ToString();
  922. dr2["Count"] = ls_gv.Rows[i].Cells[2].Value.ToString();
  923. int colq = 4;
  924. for (int j = 1; j < 15; j++)
  925. {
  926. if (ls_gv.Columns.Count > colq)
  927. dr2["e" + j.ToString()] = ls_gv.Rows[i].Cells[colq++].Tag.ToString();
  928. }
  929. colq = 4;
  930. string AllElements=null;
  931. for (int j = 0; j < ls_gv.Rows[i].Cells.Count; j++)
  932. {
  933. if (ls_gv.Columns.Count > colq)
  934. {
  935. AllElements = AllElements+ ls_gv.Columns[colq].Name + "%="+ ls_gv.Rows[i].Cells[colq++].Tag.ToString()+"; ";
  936. }
  937. }
  938. dr2["AllElements"] = AllElements;
  939. ls_element_dt.Rows.Add(dr2);
  940. }
  941. //把用户设置感兴趣的元素显示在前边
  942. for (int i=0;i< m_otsreport_export.m_mbszclass.M_YSFXJG.list_str_tb_ysfx_xsys.Count(); i++)
  943. {
  944. if (i > 13)
  945. continue;
  946. for (int a=0;a< ls_elementname_dt.Rows[0].ItemArray.Count(); a++)
  947. {
  948. if (m_otsreport_export.m_mbszclass.M_YSFXJG.list_str_tb_ysfx_xsys[i]== ls_elementname_dt.Rows[0][a].ToString())
  949. {
  950. string str_elementname = "";
  951. str_elementname = ls_elementname_dt.Rows[0][i].ToString();
  952. ls_elementname_dt.Rows[0][i] = ls_elementname_dt.Rows[0][a];
  953. ls_elementname_dt.Rows[0][a] = str_elementname;
  954. for (int j=0;j< ls_element_dt.Rows.Count;j++)
  955. {
  956. string str_element = "0";
  957. str_element = ls_element_dt.Rows[j][i].ToString();
  958. ls_element_dt.Rows[j][i] = ls_element_dt.Rows[j][a];
  959. ls_element_dt.Rows[j][a] = str_element;
  960. }
  961. }
  962. }
  963. }
  964. m_list_dt.Add(ls_elementname_dt);
  965. m_list_dt.Add(ls_element_dt);
  966. List<string> elementColumn= m_otsreport_export.m_mbszclass.M_YSFXJG.list_str_tb_ysfx_xsys;
  967. return true;
  968. }
  969. catch (Exception ee)
  970. {
  971. m_otsreport_export.WriteRictBox(ee.ToString());
  972. return false;
  973. }
  974. }
  975. public bool InsertReportTemplateTable_ElementAvgGrid()
  976. {
  977. if (m_bt_DBData.Columns.Count == 0)
  978. {
  979. GetDBData();
  980. }
  981. //根据sql条件,查询获取颗粒信息数据
  982. ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResult()].FilePath);
  983. DataTable AllAnalysisDetails = new DataTable();
  984. AllAnalysisDetails.TableName = "ElementValue";
  985. AllAnalysisDetails.Columns.Add("Name");
  986. AllAnalysisDetails.Columns.Add("TypeId");
  987. AllAnalysisDetails.Columns.Add("Area",typeof(double));
  988. AllAnalysisDetails.Columns.Add("Class");
  989. for (int i = 0; i < m_bt_DBData.Rows.Count; i++)
  990. {
  991. DataRow dr2 = AllAnalysisDetails.NewRow();
  992. dr2["Name"] = m_bt_DBData.Rows[i]["TypeName"].ToString();
  993. dr2["Area"] = Convert.ToDouble(m_bt_DBData.Rows[i]["ar"]);
  994. dr2["TypeId"] = m_bt_DBData.Rows[i]["TypeId"].ToString();
  995. dr2["Class"]= m_bt_DBData.Rows[i]["Class"].ToString();
  996. AllAnalysisDetails.Rows.Add(dr2);
  997. }
  998. //按照list列表进行物质类排序,物质类中的元素分类按照面积的大小进行排序
  999. List<string> ClassName = new List<string>();
  1000. DataTable getClass_dt= fielddata.GetAllClass();
  1001. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  1002. {
  1003. if (getClass_dt.Rows[i]["GroupName"].ToString() != "NOT_INCLUTION")
  1004. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  1005. }
  1006. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  1007. {
  1008. if (getClass_dt.Rows[i]["GroupName"].ToString() == "NOT_INCLUTION")
  1009. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  1010. }
  1011. //统计元素物质大类的元素信息和面积占比
  1012. DataTable dt_ElementalSubstance= ElementalSubstance(AllAnalysisDetails, ClassName, fielddata);
  1013. //统计元素并按照Class Name自定义列表进行排序,大类中的小类元素信息按照面积从大到小排序
  1014. DataTable dt_ElementSorting= ElementSorting( AllAnalysisDetails, ClassName, fielddata);
  1015. //生成最后导出时物质元素成分表
  1016. DataTable dt= MaterialElementComposition(dt_ElementalSubstance,13);//导出14个元素成分信息
  1017. //生成最后导出时物质元素细分表
  1018. SubdivisionOfMaterialElements(dt_ElementSorting, 13, ClassName, dt);
  1019. //夹杂物面积比添加大类
  1020. DataTable RawParticleData = InclusionAreaRatio();
  1021. //夹杂物面积比计算大类占比
  1022. ProportionOfParticleArea(RawParticleData, ClassName);
  1023. return true;
  1024. }
  1025. private bool ProportionOfParticleArea(DataTable dataTable, List<string> ClassName)
  1026. {
  1027. DataTable AllAnalysisDetails = dataTable.Copy();
  1028. AllAnalysisDetails.Clear();
  1029. AllAnalysisDetails.TableName = "InclusionAreaRatio";
  1030. for (int i=0;i< ClassName.Count;i++)
  1031. {
  1032. DataTable dt = dataTable.Copy();
  1033. dt.Clear();
  1034. for (int a=0;a< dataTable.Rows.Count;a++)
  1035. {
  1036. if (dataTable.Rows[a]["e1"].ToString()== ClassName[i].ToString())
  1037. {
  1038. dt.Rows.Add(dataTable.Rows[a].ItemArray);
  1039. }
  1040. }
  1041. if (dt.Rows.Count>0)
  1042. {
  1043. double totalInclusionArea = Convert.ToDouble(decimal.Parse(dataTable.Compute("sum(e3)", "").ToString()));
  1044. double Area= Convert.ToDouble(decimal.Parse(dt.Compute("sum(e3)", "").ToString()));
  1045. DataRow dr = AllAnalysisDetails.NewRow();
  1046. dr["e1"] = ClassName[i].ToString();
  1047. dr["e3"] = Math.Round(Area, 2);
  1048. //Convert.ToDouble(decimal.Parse(dt.Compute("sum(e3)", "").ToString()));
  1049. dr["e4"] = Math.Round((Convert.ToDouble(dt.Rows[0]["e3"]) / totalInclusionArea) * 100, 2);
  1050. dr["e5"] = Math.Round((Convert.ToDouble(dt.Rows[0]["e3"]) / Convert.ToDouble(m_list_dt.Where(aa => aa.TableName.Contains("ResultGrid")).ToList()[0].Rows[0][5])) * 100, 4);
  1051. AllAnalysisDetails.Rows.Add(dr);
  1052. DataView dv = dt.DefaultView;
  1053. dv.Sort = "e3 DESC";
  1054. DataTable dt_Area = dv.ToTable();
  1055. for (int a=0;a< dt_Area.Rows.Count;a++)
  1056. {
  1057. dt_Area.Rows[a]["e1"] = "";
  1058. dt_Area.Rows[a]["e3"] = Math.Round(Convert.ToDouble(dt_Area.Rows[a]["e3"]), 2);
  1059. AllAnalysisDetails.Rows.Add(dt_Area.Rows[a].ItemArray);
  1060. }
  1061. }
  1062. }
  1063. m_list_dt.Add(AllAnalysisDetails);
  1064. return true;
  1065. }
  1066. private DataTable ElementSorting( DataTable AllAnalysisDetails, List<string> ClassName , ParticleData fielddata)
  1067. {
  1068. DataTable dte = fielddata.GetAllElement();
  1069. DataTable ElementSorting_dt = AllAnalysisDetails.Copy();
  1070. ElementSorting_dt.Clear();
  1071. for (int i=0; i< ClassName.Count;i++)
  1072. {
  1073. DataTable dt = AllAnalysisDetails.Copy();
  1074. dt.Clear();
  1075. for (int a=0;a< AllAnalysisDetails.Rows.Count;a++)
  1076. {
  1077. if (AllAnalysisDetails.Rows[a]["Class"].ToString()== ClassName[i].ToString())
  1078. {
  1079. dt.Rows.Add(AllAnalysisDetails.Rows[a].ItemArray);
  1080. }
  1081. }
  1082. //将颗粒大小排序(从大到小)
  1083. DataView dv = dt.DefaultView;
  1084. dv.Sort = "Area DESC";
  1085. DataTable dt_Element = dv.ToTable();
  1086. for (int a=0;a< dt_Element.Rows.Count;a++)
  1087. {
  1088. ElementSorting_dt.Rows.Add(dt_Element.Rows[a].ItemArray);
  1089. }
  1090. }
  1091. //循环创建元素列(类型定义为double,为以后计算做准备)
  1092. for (int a = 0; a < dte.Rows.Count; a++)
  1093. {
  1094. ElementSorting_dt.Columns.Add(dte.Rows[a]["Name"].ToString(), typeof(double));
  1095. }
  1096. for (int a = 0; a < ElementSorting_dt.Rows.Count; a++)
  1097. {
  1098. DataTable ClassificationDetails = fielddata.GetAreaByIncA(ElementSorting_dt.Rows[a]["TypeId"].ToString(), "");//获取单个分类的元素信息
  1099. //DataRow dr2 = ElementSorting_dt.NewRow();
  1100. foreach (DataRow dr in ClassificationDetails.Rows)
  1101. {
  1102. double doe = Convert.ToDouble(dr["pc"]);
  1103. ElementSorting_dt.Rows[a][dr["Name"].ToString()] = Math.Round( doe/Convert.ToDouble(ElementSorting_dt.Rows[a]["Area"]),2);
  1104. }
  1105. }
  1106. return ElementSorting_dt;
  1107. }
  1108. private DataTable ElementalSubstance(DataTable AllAnalysisDetails, List<string> ClassName, ParticleData fielddata)
  1109. {
  1110. //当前元素物质类面积的总和
  1111. double ElementalSubstance = 0;
  1112. DataTable dte = fielddata.GetAllElement();
  1113. DataTable dt_Class = new DataTable();
  1114. dt_Class.Columns.Add("Name");
  1115. dt_Class.Columns.Add("Area");
  1116. //循环创建元素列(类型定义为double,为以后计算做准备)
  1117. for (int a = 0; a < dte.Rows.Count; a++)
  1118. {
  1119. dt_Class.Columns.Add(dte.Rows[a]["Name"].ToString(), typeof(double));
  1120. }
  1121. //循环大类物质列表
  1122. for (int i = 0; i < ClassName.Count; i++)
  1123. {
  1124. //保留当前循环中大类物质,去除其他物质
  1125. DataTable dt = AllAnalysisDetails.Copy();
  1126. dt.Clear();
  1127. for (int a = 0; a < AllAnalysisDetails.Rows.Count; a++)
  1128. {
  1129. if (AllAnalysisDetails.Rows[a]["Class"].ToString() == ClassName[i].ToString())
  1130. {
  1131. dt.Rows.Add(AllAnalysisDetails.Rows[a].ItemArray);
  1132. }
  1133. }
  1134. if (dt.Rows.Count == 0)
  1135. continue;
  1136. //计算出当前循环中大类物质的面积
  1137. ElementalSubstance=Convert.ToDouble(decimal.Parse(dt.Compute("sum(Area)", "").ToString()));
  1138. DataTable ta = new DataTable();
  1139. ta = dt_Class.Copy();
  1140. ta.Clear();
  1141. for (int a = 0; a < dt.Rows.Count; a++)
  1142. {
  1143. DataTable ClassificationDetails = fielddata.GetAreaByIncA(dt.Rows[a]["TypeId"].ToString(), "");//获取单个分类的元素信息
  1144. DataRow dr2 = ta.NewRow();
  1145. foreach (DataRow dr in ClassificationDetails.Rows)
  1146. {
  1147. double doe = Convert.ToDouble(dr["pc"]);
  1148. dr2[dr["Name"].ToString()] = doe;
  1149. }
  1150. ta.Rows.Add(dr2);
  1151. }
  1152. DataTable dataTable = ta.Copy();
  1153. dataTable.Clear();
  1154. DataRow row = dataTable.NewRow();
  1155. dataTable.Rows.Add(row);
  1156. for (int a=0;a< ta.Columns.Count;a++)
  1157. {
  1158. if (ta.Columns[a].ToString()!="Name"&& ta.Columns[a].ToString() !="Class")
  1159. {
  1160. bool bl = false;
  1161. for (int b=0;b<ta.Rows.Count;b++)
  1162. {
  1163. if (!ta.Rows[b].IsNull(ta.Columns[a].ToString()))
  1164. {
  1165. bl = true;
  1166. }
  1167. }
  1168. if (bl)
  1169. dataTable.Rows[0][ta.Columns[a].ToString()] = Math.Round( Convert.ToDouble(decimal.Parse(ta.Compute("sum(" + ta.Columns[a].ToString() + ")", "").ToString()))/ ElementalSubstance,2);
  1170. }
  1171. }
  1172. dataTable.Rows[0]["Name"] = ClassName[i].ToString();
  1173. dataTable.Rows[0]["Area"] = ElementalSubstance;
  1174. dt_Class.Rows.Add(dataTable.Rows[0].ItemArray);
  1175. }
  1176. return dt_Class;
  1177. }
  1178. private DataTable MaterialElementComposition(DataTable a_ElementalSubstance,int NumberOfColumns)
  1179. {
  1180. DataTable dt_ElementalSubstance = new DataTable();
  1181. dt_ElementalSubstance.TableName = "ElementalSubstance_Value";
  1182. dt_ElementalSubstance.Columns.Add("Name");
  1183. dt_ElementalSubstance.Columns.Add("Area");
  1184. for (int i=0;i< a_ElementalSubstance.Rows.Count;i++)
  1185. {
  1186. dt_ElementalSubstance.Rows.Add(a_ElementalSubstance.Rows[i]["Name"]);
  1187. dt_ElementalSubstance.Rows[i]["Area"]=Math.Round(Convert.ToDouble(a_ElementalSubstance.Rows[i]["Area"]),2) ;
  1188. }
  1189. int cunt = 1;
  1190. for (int i=0;i< NumberOfColumns; i++)
  1191. {
  1192. if (i< m_otsreport_export.m_mbszclass.M_YSFXJG.list_str_tb_ysfx_xsys.Count())
  1193. {
  1194. dt_ElementalSubstance.Columns.Add(m_otsreport_export.m_mbszclass.M_YSFXJG.list_str_tb_ysfx_xsys[i]);
  1195. for (int a=0;a< a_ElementalSubstance.Rows.Count;a++)
  1196. {
  1197. if (a_ElementalSubstance.Columns.Contains(m_otsreport_export.m_mbszclass.M_YSFXJG.list_str_tb_ysfx_xsys[i]))
  1198. {
  1199. if (a_ElementalSubstance.Rows[a][m_otsreport_export.m_mbszclass.M_YSFXJG.list_str_tb_ysfx_xsys[i]].ToString() == "")
  1200. {
  1201. dt_ElementalSubstance.Rows[a][m_otsreport_export.m_mbszclass.M_YSFXJG.list_str_tb_ysfx_xsys[i]] = 0;
  1202. }
  1203. else
  1204. {
  1205. dt_ElementalSubstance.Rows[a][m_otsreport_export.m_mbszclass.M_YSFXJG.list_str_tb_ysfx_xsys[i]] = a_ElementalSubstance.Rows[a][m_otsreport_export.m_mbszclass.M_YSFXJG.list_str_tb_ysfx_xsys[i]];
  1206. }
  1207. }
  1208. else
  1209. {
  1210. dt_ElementalSubstance.Rows[a][m_otsreport_export.m_mbszclass.M_YSFXJG.list_str_tb_ysfx_xsys[i]] = 0;
  1211. }
  1212. }
  1213. }
  1214. else
  1215. {
  1216. dt_ElementalSubstance.Columns.Add("Null"+ cunt.ToString());
  1217. cunt = cunt + 1;
  1218. for (int a = 0; a < a_ElementalSubstance.Rows.Count; a++)
  1219. {
  1220. dt_ElementalSubstance.Rows[a][i+2] = "-";
  1221. }
  1222. }
  1223. }
  1224. DataTable dataTable = new DataTable();
  1225. dataTable = dt_ElementalSubstance.Copy();
  1226. dataTable.Clear();
  1227. DataRow row = dataTable.NewRow();
  1228. dataTable.Rows.Add(row);
  1229. dataTable.TableName = "ElementalSubstance_Name";
  1230. for (int i=0;i< dataTable.Columns.Count;i++)
  1231. {
  1232. dataTable.Rows[0][dataTable.Columns[i].ToString()] = dataTable.Columns[i].ToString();
  1233. }
  1234. m_list_dt.Add(dataTable);
  1235. m_list_dt.Add(dt_ElementalSubstance);
  1236. return dt_ElementalSubstance;
  1237. }
  1238. private bool SubdivisionOfMaterialElements(DataTable a_ElementalSubstance, int NumberOfColumns, List<string> ClassName,DataTable data)
  1239. {
  1240. DataTable dt_ElementalSubstance = new DataTable();
  1241. dt_ElementalSubstance= data.Copy();
  1242. dt_ElementalSubstance.Clear();
  1243. dt_ElementalSubstance.TableName = "ElementSubdivision_Value";
  1244. dt_ElementalSubstance.Columns["Name"].ColumnName = "Class";
  1245. dt_ElementalSubstance.Columns.Add("Name");
  1246. //处理元素面积保留小数点后两位
  1247. for (int i=0;i< a_ElementalSubstance.Rows.Count;i++)
  1248. {
  1249. a_ElementalSubstance.Rows[i]["Area"] = Math.Round(Convert.ToDouble(a_ElementalSubstance.Rows[i]["Area"].ToString()), 2);
  1250. }
  1251. //循环元素物质大类
  1252. for (int i = 0; i < ClassName.Count; i++)
  1253. {
  1254. DataTable dt_1 = new DataTable();
  1255. dt_1 = data.Copy();
  1256. dt_1.Clear();
  1257. for (int a = 0; a < data.Rows.Count; a++)
  1258. {
  1259. if (data.Rows[a]["Name"].ToString() == ClassName[i].ToString())
  1260. {
  1261. dt_1.Rows.Add(data.Rows[a].ItemArray);
  1262. }
  1263. }
  1264. dt_1.Columns["Name"].ColumnName = "Class";
  1265. dt_1.Columns.Add("Name");
  1266. DataTable dt_2 = new DataTable();
  1267. dt_2 = dt_1.Copy();
  1268. dt_2.Clear();
  1269. dt_2.Rows.Add();
  1270. //循环整个表筛选出当前的物质
  1271. for (int a = 0; a < a_ElementalSubstance.Rows.Count; a++)
  1272. {
  1273. if (ClassName[i].ToString() == a_ElementalSubstance.Rows[a]["Class"].ToString())
  1274. {
  1275. for (int b=0;b< dt_1.Columns.Count;b++)
  1276. {
  1277. if (dt_2.Columns[b].ToString()!="Class")
  1278. {
  1279. if (a_ElementalSubstance.Columns.Contains(dt_2.Columns[b].ToString()))
  1280. {
  1281. if (a_ElementalSubstance.Rows[a][dt_2.Columns[b].ToString()].ToString() == "")
  1282. {
  1283. dt_2.Rows[0][dt_2.Columns[b].ToString()] = 0;
  1284. }
  1285. else
  1286. {
  1287. dt_2.Rows[0][dt_2.Columns[b].ToString()] = a_ElementalSubstance.Rows[a][dt_2.Columns[b].ToString()];
  1288. }
  1289. }
  1290. else
  1291. {
  1292. dt_2.Rows[0][dt_2.Columns[b].ToString()] = 0;
  1293. }
  1294. }
  1295. }
  1296. dt_1.Rows.Add(dt_2.Rows[0].ItemArray);
  1297. }
  1298. }
  1299. for (int a=0;a< dt_1.Rows.Count;a++)
  1300. {
  1301. dt_ElementalSubstance.Rows.Add(dt_1.Rows[a].ItemArray);
  1302. }
  1303. }
  1304. DataTable dataTable = new DataTable();
  1305. dataTable = dt_ElementalSubstance.Copy();
  1306. dataTable.Clear();
  1307. DataRow row = dataTable.NewRow();
  1308. dataTable.Rows.Add(row);
  1309. dataTable.TableName = "ElementSubdivision_Name";
  1310. for (int i = 0; i < dataTable.Columns.Count; i++)
  1311. {
  1312. dataTable.Rows[0][dataTable.Columns[i].ToString()] = dataTable.Columns[i].ToString();
  1313. }
  1314. m_list_dt.Add(dataTable);
  1315. m_list_dt.Add(dt_ElementalSubstance);
  1316. return true;
  1317. }
  1318. #endregion
  1319. private DataTable InclusionAreaRatio()
  1320. {
  1321. //根据sql条件,查询获取颗粒信息数据
  1322. ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResult()].FilePath);
  1323. DataTable AreaInformationOfAllElements = fielddata.GetAreaByAllIncA("");//获取所有分类面积和数量信息
  1324. DataTable AllAnalysisDetails = new DataTable();
  1325. //AllAnalysisDetails.TableName = "ElementValue";
  1326. AllAnalysisDetails.Columns.Add("Name");
  1327. AllAnalysisDetails.Columns.Add("TypeId");
  1328. AllAnalysisDetails.Columns.Add("Area", typeof(double));
  1329. AllAnalysisDetails.Columns.Add("Class");
  1330. AllAnalysisDetails.Columns.Add("Cunt",typeof(double));
  1331. for (int i = 0; i < AreaInformationOfAllElements.Rows.Count; i++)
  1332. {
  1333. //if (Convert.ToInt32(AreaInformationOfAllElements.Rows[i]["TypeId"]) < 100)
  1334. // continue;
  1335. DataRow dr2 = AllAnalysisDetails.NewRow();
  1336. dr2["Name"] = AreaInformationOfAllElements.Rows[i]["TypeName"].ToString();
  1337. dr2["Area"] = Convert.ToDouble(AreaInformationOfAllElements.Rows[i]["ar"]);
  1338. dr2["TypeId"] = AreaInformationOfAllElements.Rows[i]["TypeId"].ToString();
  1339. dr2["Cunt"] = Convert.ToDouble(AreaInformationOfAllElements.Rows[i]["con"]);
  1340. dr2["Class"] = AreaInformationOfAllElements.Rows[i]["GroupName"].ToString();
  1341. AllAnalysisDetails.Rows.Add(dr2);
  1342. }
  1343. List<string> ClassName = new List<string>();
  1344. DataTable getClass_dt = fielddata.GetAllClass();
  1345. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  1346. {
  1347. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  1348. }
  1349. DataTable AreaRatio = new DataTable();
  1350. AreaRatio.TableName = "InclusionAreaRatio";
  1351. AreaRatio.Columns.Add("e1");
  1352. AreaRatio.Columns.Add("e2");
  1353. AreaRatio.Columns.Add("e3", typeof(double));
  1354. AreaRatio.Columns.Add("e4");
  1355. AreaRatio.Columns.Add("e5");
  1356. //获取夹杂物的总面积用于计算夹杂物类别的占比(gridview最后一个固定是未识别颗粒,要排除未识别颗粒所以for循环至grid view长度减一)
  1357. double totalInclusionArea = 0;
  1358. //for (int i = 0; i < ls_gv.Rows.Count - 1; i++)
  1359. //{
  1360. // totalInclusionArea = totalInclusionArea + Convert.ToDouble(ls_gv.Rows[i].Cells[2].Value.ToString());
  1361. //}
  1362. totalInclusionArea= Convert.ToDouble(decimal.Parse(AllAnalysisDetails.Compute("sum(Area)", "").ToString()));
  1363. for (int i=0;i< AllAnalysisDetails.Rows.Count;i++)
  1364. {
  1365. DataRow dr = AreaRatio.NewRow();
  1366. dr["e1"] = AllAnalysisDetails.Rows[i]["Class"].ToString();
  1367. dr["e2"] = AllAnalysisDetails.Rows[i]["Name"].ToString();
  1368. dr["e3"] = Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]);
  1369. dr["e4"]= Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / totalInclusionArea) * 100, 2);
  1370. dr["e5"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / Convert.ToDouble(m_list_dt.Where(aa => aa.TableName.Contains("ResultGrid")).ToList()[0].Rows[0][5])) * 100, 4);
  1371. AreaRatio.Rows.Add(dr);
  1372. }
  1373. DataTable AreaRatio_dt = AreaRatio.Copy();
  1374. AreaRatio_dt.Clear();
  1375. for (int i=0;i< ClassName.Count();i++)
  1376. {
  1377. DataTable dt = AreaRatio.Copy();
  1378. dt.Clear();
  1379. for (int a=0; a< AreaRatio.Rows.Count;a++)
  1380. {
  1381. if (AreaRatio.Rows[a]["e1"].ToString()== ClassName[i].ToString())
  1382. {
  1383. dt.Rows.Add(AreaRatio.Rows[a].ItemArray);
  1384. }
  1385. }
  1386. DataView dv = dt.DefaultView;
  1387. dv.Sort = "e3 DESC";
  1388. DataTable dt_Element = dv.ToTable();
  1389. for (int a = 0; a < dt_Element.Rows.Count;a++)
  1390. {
  1391. AreaRatio_dt.Rows.Add(dt_Element.Rows[a].ItemArray);
  1392. }
  1393. }
  1394. return AreaRatio_dt;
  1395. //m_list_dt.Add(AreaRatio_dt);
  1396. }
  1397. #region 插入颗粒图chart
  1398. /// <summary>
  1399. /// 用于颗粒图chart
  1400. /// </summary>
  1401. /// <returns></returns>
  1402. private DataTable GetPicDataTable_PicKL()
  1403. {
  1404. if (m_list_dt.Where(aa => aa.TableName.Contains("PicKL")).ToList().Count == 0)
  1405. {
  1406. //创建二进制列的数据表
  1407. DataTable ls_dt = new DataTable();
  1408. ls_dt.TableName = "PicKL";
  1409. DataColumn colpict = new DataColumn("pict");
  1410. colpict.DataType = System.Type.GetType("System.Byte[]");
  1411. ls_dt.Columns.Add(colpict);
  1412. m_list_dt.Add(ls_dt);
  1413. return ls_dt;
  1414. }
  1415. else
  1416. {
  1417. return m_list_dt.Where(aa => aa.TableName.Contains("PicKL")).ToList()[0];
  1418. }
  1419. }
  1420. #endregion
  1421. private DataTable GetPicDataTable_InclusionAreaRatio(string str)
  1422. {
  1423. if (m_list_dt.Where(aa => aa.TableName.Contains(str)).ToList().Count == 0)
  1424. {
  1425. //创建二进制列的数据表
  1426. DataTable ls_dt = new DataTable();
  1427. ls_dt.TableName = str;
  1428. DataColumn colpict = new DataColumn("pict");
  1429. colpict.DataType = System.Type.GetType("System.Byte[]");
  1430. ls_dt.Columns.Add(colpict);
  1431. m_list_dt.Add(ls_dt);
  1432. return ls_dt;
  1433. }
  1434. else
  1435. {
  1436. return m_list_dt.Where(aa => aa.TableName.Contains(str)).ToList()[0];
  1437. }
  1438. }
  1439. #region 插入元素图chart
  1440. /// <summary>
  1441. /// 用于元素图chart
  1442. /// </summary>
  1443. /// <returns></returns>
  1444. private DataTable GetPicDataTable_PicYS()
  1445. {
  1446. if (m_list_dt.Where(aa => aa.TableName.Contains("PicYS")).ToList().Count == 0)
  1447. {
  1448. //创建二进制列的数据表
  1449. DataTable ls_dt = new DataTable();
  1450. ls_dt.TableName = "PicYS";
  1451. DataColumn colpict = new DataColumn("pict");
  1452. colpict.DataType = System.Type.GetType("System.Byte[]");
  1453. ls_dt.Columns.Add(colpict);
  1454. m_list_dt.Add(ls_dt);
  1455. return ls_dt;
  1456. }
  1457. else
  1458. {
  1459. return m_list_dt.Where(aa => aa.TableName.Contains("PicYS")).ToList()[0];
  1460. }
  1461. }
  1462. #endregion
  1463. #region 插入大分类夹杂物面积比图
  1464. public bool InsertReportTemplateChart_InclusionAreaClassRatio(string a_GraphicStyle)
  1465. {
  1466. //加载模块
  1467. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition = new EChart_ParticlesComposition(m_otsreport_export.m_ReportApp, "InclusionareaClassRatio");
  1468. m_otsreport_export.m_ReportApp.m_reportname = "";
  1469. m_otsreport_export.m_ReportApp.type = a_GraphicStyle;
  1470. m_otsreport_export.m_ReportApp.timerKG = true;
  1471. m_otsreport_export.m_ReportApp.m_ChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition);
  1472. //弹出加载图片窗体
  1473. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  1474. //将EChart委托事件注册给加载图片窗体的方法
  1475. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition.butclic += og.get_ParticalesCompositionChart;
  1476. og.ShowDialog();
  1477. //获取图片数据
  1478. string str = og.PicStr;
  1479. //将Base64String转为图片并保存
  1480. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  1481. MemoryStream ms = new MemoryStream(arr);
  1482. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  1483. //再将图转成流,流再转二进制-------------------------------------------
  1484. MemoryStream newms = new MemoryStream();
  1485. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  1486. newms.Seek(0, SeekOrigin.Begin);
  1487. byte[] newarr = new byte[newms.Length];
  1488. newms.Read(newarr, 0, newarr.Length);
  1489. newms.Dispose();
  1490. DataTable ls_dt = GetPicDataTable_InclusionAreaRatio("Pic_InclusionareaClassRatio");
  1491. DataRow dr = ls_dt.NewRow();
  1492. dr["pict"] = newarr;//图像二进制
  1493. ls_dt.Rows.Add(dr);
  1494. return true;
  1495. }
  1496. #endregion
  1497. #region 插入夹杂物面积比图
  1498. public bool InsertReportTemplateChart_InclusionAreaRatio(string a_GraphicStyle)
  1499. {
  1500. //加载模块
  1501. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition = new EChart_ParticlesComposition(m_otsreport_export.m_ReportApp, "InclusionareaRatio");
  1502. m_otsreport_export.m_ReportApp.m_reportname = "";
  1503. m_otsreport_export.m_ReportApp.type = a_GraphicStyle;
  1504. m_otsreport_export.m_ReportApp.timerKG = true;
  1505. m_otsreport_export.m_ReportApp.m_ChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition);
  1506. //弹出加载图片窗体
  1507. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  1508. //将EChart委托事件注册给加载图片窗体的方法
  1509. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition.butclic += og.get_ParticalesCompositionChart;
  1510. og.ShowDialog();
  1511. //获取图片数据
  1512. string str = og.PicStr;
  1513. //将Base64String转为图片并保存
  1514. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  1515. MemoryStream ms = new MemoryStream(arr);
  1516. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  1517. //再将图转成流,流再转二进制-------------------------------------------
  1518. MemoryStream newms = new MemoryStream();
  1519. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  1520. newms.Seek(0, SeekOrigin.Begin);
  1521. byte[] newarr = new byte[newms.Length];
  1522. newms.Read(newarr, 0, newarr.Length);
  1523. newms.Dispose();
  1524. DataTable ls_dt = GetPicDataTable_InclusionAreaRatio("Pic_InclusionAreaRatio");
  1525. DataRow dr = ls_dt.NewRow();
  1526. dr["pict"] = newarr;//图像二进制
  1527. ls_dt.Rows.Add(dr);
  1528. return true;
  1529. }
  1530. #endregion
  1531. #region 插入颗粒成份图
  1532. /// <summary>
  1533. /// 向 模板设计器 中插入 颗粒成份图
  1534. /// </summary>
  1535. /// <returns></returns>
  1536. public bool InsertReportTemplateChart_ParticlesCompositionChart(string a_GraphicStyle)
  1537. {
  1538. try
  1539. {
  1540. //-----------------------------------颗粒成份图-----------------------------------------------------------------------------------------------
  1541. //加载模块
  1542. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition = new EChart_ParticlesComposition(m_otsreport_export.m_ReportApp, "PComponent");
  1543. m_otsreport_export.m_ReportApp.m_reportname = "InclusionClassification";
  1544. m_otsreport_export.m_ReportApp.type = a_GraphicStyle;
  1545. m_otsreport_export.m_ReportApp.timerKG = true;
  1546. m_otsreport_export.m_ReportApp.m_ChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition);
  1547. //弹出加载图片窗体
  1548. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  1549. //将EChart委托事件注册给加载图片窗体的方法
  1550. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition.butclic += og.get_ParticalesCompositionChart;
  1551. og.ShowDialog();
  1552. //获取图片数据
  1553. string str = og.PicStr;
  1554. //将Base64String转为图片并保存
  1555. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  1556. MemoryStream ms = new MemoryStream(arr);
  1557. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  1558. //再将图转成流,流再转二进制-------------------------------------------
  1559. MemoryStream newms = new MemoryStream();
  1560. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  1561. newms.Seek(0, SeekOrigin.Begin);
  1562. byte[] newarr = new byte[newms.Length];
  1563. newms.Read(newarr, 0, newarr.Length);
  1564. newms.Dispose();
  1565. //创建二进制列的数据表
  1566. DataTable ls_dt = GetPicDataTable_PicKL();
  1567. DataRow dr = ls_dt.NewRow();
  1568. dr["pict"] = newarr;//图像二进制
  1569. ls_dt.Rows.Add(dr);
  1570. return true;
  1571. }
  1572. catch (Exception ee)
  1573. {
  1574. m_otsreport_export.WriteRictBox(ee.ToString());
  1575. return false;
  1576. }
  1577. }
  1578. #endregion
  1579. #region 插入元素成份图
  1580. /// <summary>
  1581. /// 向 模板设计器 中插入 元素成份图
  1582. /// </summary>
  1583. /// <returns></returns>
  1584. public bool InsertReportTemplateChart_ElementCompositionChart(string a_GraphicStyle)
  1585. {
  1586. try
  1587. {
  1588. //-----------------------------------元素成份图-----------------------------------------------------------------------------------------------
  1589. //加载模块
  1590. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition = new EChart_ParticlesComposition(m_otsreport_export.m_ReportApp, "EComponent");
  1591. m_otsreport_export.m_ReportApp.m_reportname = "ElementComposition";
  1592. m_otsreport_export.m_ReportApp.type = a_GraphicStyle;
  1593. m_otsreport_export.m_ReportApp.timerKG = true;
  1594. m_otsreport_export.m_ReportApp.m_ChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition);
  1595. //弹出加载图片窗体
  1596. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  1597. //将EChart委托事件注册给加载图片窗体的方法
  1598. m_otsreport_export.m_ReportApp.im_EChart_ParticlesComposition.butclic += og.get_ParticalesCompositionChart;
  1599. og.ShowDialog();
  1600. //获取图片数据
  1601. string str = og.PicStr;
  1602. //将Base64String转为图片并保存
  1603. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  1604. MemoryStream ms = new MemoryStream(arr);
  1605. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  1606. //再将图转成流,流再转二进制-------------------------------------------
  1607. MemoryStream newms = new MemoryStream();
  1608. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  1609. newms.Seek(0, SeekOrigin.Begin);
  1610. byte[] newarr = new byte[newms.Length];
  1611. newms.Read(newarr, 0, newarr.Length);
  1612. newms.Dispose();
  1613. //创建二进制列的数据表
  1614. DataTable ls_dt = GetPicDataTable_PicYS();
  1615. DataRow dr = ls_dt.NewRow();
  1616. dr["pict"] = newarr;//图像二进制
  1617. ls_dt.Rows.Add(dr);
  1618. return true;
  1619. }
  1620. catch (Exception ee)
  1621. {
  1622. m_otsreport_export.WriteRictBox(ee.ToString());
  1623. return false;
  1624. }
  1625. }
  1626. #endregion
  1627. #region 插入三元相图
  1628. /// <summary>
  1629. /// 获取或创建pic表格,用于三元相图
  1630. /// </summary>
  1631. /// <returns></returns>
  1632. private DataTable GetPicDataTable_PicSYXT2T()
  1633. {
  1634. if (m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT2T")).ToList().Count == 0)
  1635. {
  1636. //创建二进制列的数据表
  1637. DataTable ls_dt = new DataTable();
  1638. ls_dt.TableName = "PicSYXT2T";
  1639. DataColumn colpict = new DataColumn("pict");
  1640. colpict.DataType = System.Type.GetType("System.Byte[]");
  1641. ls_dt.Columns.Add(colpict);
  1642. DataColumn colpict2 = new DataColumn("pict2");
  1643. colpict2.DataType = System.Type.GetType("System.Byte[]");
  1644. ls_dt.Columns.Add(colpict2);
  1645. m_list_dt.Add(ls_dt);
  1646. return ls_dt;
  1647. }
  1648. else
  1649. {
  1650. return m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT2T")).ToList()[0];
  1651. }
  1652. }
  1653. /// <summary>
  1654. /// 获取或创建pic表格,用于三元相图,3个列的
  1655. /// </summary>
  1656. /// <returns></returns>
  1657. private DataTable GetPicDataTable_PicSYXT3T()
  1658. {
  1659. if (m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT3T")).ToList().Count == 0)
  1660. {
  1661. //创建二进制列的数据表
  1662. DataTable ls_dt = new DataTable();
  1663. ls_dt.TableName = "PicSYXT3T";
  1664. DataColumn colpict = new DataColumn("pict");
  1665. colpict.DataType = System.Type.GetType("System.Byte[]");
  1666. ls_dt.Columns.Add(colpict);
  1667. DataColumn colpict2 = new DataColumn("pict2");
  1668. colpict2.DataType = System.Type.GetType("System.Byte[]");
  1669. ls_dt.Columns.Add(colpict2);
  1670. DataColumn colpict3 = new DataColumn("pict3");
  1671. colpict3.DataType = System.Type.GetType("System.Byte[]");
  1672. ls_dt.Columns.Add(colpict3);
  1673. m_list_dt.Add(ls_dt);
  1674. return ls_dt;
  1675. }
  1676. else
  1677. {
  1678. return m_list_dt.Where(aa => aa.TableName.Contains("PicSYXT")).ToList()[0];
  1679. }
  1680. }
  1681. /// <summary>
  1682. /// 获取三元相图二进制数据
  1683. /// </summary>
  1684. /// <param name="selectindex"></param>
  1685. /// <returns></returns>
  1686. private byte[] GetByte_InsertReportTemplateChart_Trianglediagram(int selectindex)
  1687. {
  1688. byte[] newarr = new byte[0];
  1689. //加载模块
  1690. m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram = new EChart_Trianglediagram(m_otsreport_export.m_ReportApp, TemplateList[selectindex]);
  1691. m_otsreport_export.m_ReportApp.timerKG = true;
  1692. m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram.condition = m_otsreport_export.m_mbszclass.M_SYXT.index_cb_syxt_jsfs;
  1693. m_otsreport_export.m_ReportApp.m_ChartsWindow.Controls.Add(m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram);
  1694. //ls_echart_trianglediagram.
  1695. //弹出加载图片窗体
  1696. OTSReport_GetEChartImage og = new OTSReport_GetEChartImage();
  1697. //将EChart委托事件注册给加载图片窗体的方法
  1698. m_otsreport_export.m_ReportApp.im_EChart_Trianglediagram.butclic += og.get_ParticalesCompositionChart;
  1699. og.ShowDialog();
  1700. //获取图片数据
  1701. string str = og.PicStr;
  1702. //将Base64String转为图片并保存
  1703. byte[] arr = Convert.FromBase64String(str.Substring(str.IndexOf(',') + 1));
  1704. MemoryStream ms = new MemoryStream(arr);
  1705. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
  1706. //再将图转成流,流再转二进制-------------------------------------------
  1707. MemoryStream newms = new MemoryStream();
  1708. bmp.Save(newms, System.Drawing.Imaging.ImageFormat.Bmp);
  1709. newms.Seek(0, SeekOrigin.Begin);
  1710. newarr = new byte[newms.Length];
  1711. newms.Read(newarr, 0, newarr.Length);
  1712. newms.Dispose();
  1713. return newarr;
  1714. }
  1715. /// <summary>
  1716. /// 向 模板设计器 中插入 三元相图
  1717. /// </summary>
  1718. /// <returns></returns>
  1719. public bool InsertReportTemplateChart_Trianglediagram()
  1720. {
  1721. try
  1722. {
  1723. //创建二进制列的数据表,循环插入三元选择的模板
  1724. DataTable ls_dt = GetPicDataTable_PicSYXT2T();
  1725. DataTable ls_dt3t = GetPicDataTable_PicSYXT3T();
  1726. //这里要校验一下,总数必须要是2的整倍数,不可有余数
  1727. 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)
  1728. {
  1729. for (int i = 0; i < m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index.Count; i = i + 2)
  1730. {
  1731. byte[] newarr, newarr2;
  1732. newarr = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i]);
  1733. newarr2 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 1]);
  1734. DataRow dr = ls_dt.NewRow();
  1735. dr["pict"] = newarr;//图像二进制
  1736. dr["pict2"] = newarr2;//图像二进制
  1737. ls_dt.Rows.Add(dr);
  1738. }
  1739. }
  1740. else
  1741. {
  1742. DataRow dr = ls_dt.NewRow();
  1743. dr["pict"] = null;//图像二进制
  1744. dr["pict2"] = null;//图像二进制
  1745. ls_dt.Rows.Add(dr);
  1746. }
  1747. 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)
  1748. {
  1749. for (int i = 0; i < m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index.Count; i = i + 3)
  1750. {
  1751. byte[] newarr, newarr2, newarr3;
  1752. newarr = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i]);
  1753. newarr2 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 1]);
  1754. newarr3 = GetByte_InsertReportTemplateChart_Trianglediagram(m_otsreport_export.m_mbszclass.M_SYXT.list_lbv_syxt_mblb_index[i + 2]);
  1755. DataRow dr = ls_dt3t.NewRow();
  1756. dr["pict"] = newarr;//图像二进制
  1757. dr["pict2"] = newarr2;//图像二进制
  1758. dr["pict3"] = newarr3;//图像二进制
  1759. ls_dt3t.Rows.Add(dr);
  1760. }
  1761. }
  1762. else
  1763. {
  1764. DataRow dr = ls_dt3t.NewRow();
  1765. dr["pict"] = null;//图像二进制
  1766. dr["pict2"] = null;//图像二进制
  1767. dr["pict3"] = null;//图像二进制
  1768. ls_dt3t.Rows.Add(dr);
  1769. }
  1770. return true;
  1771. }
  1772. catch (Exception ee)
  1773. {
  1774. m_otsreport_export.WriteRictBox(ee.ToString());
  1775. return false;
  1776. }
  1777. }
  1778. #endregion
  1779. #region 其它部份
  1780. /// <summary>
  1781. /// 输入颗粒的所在帧图id,颗粒id,颗粒类型id,获取对应的XRay能谱数据图
  1782. /// </summary>
  1783. /// <returns></returns>
  1784. public Bitmap ExportXRayBitmap(string in_fieldid, string in_particleid, int in_stdtypeid, string TypeName, ParticleData particleData)
  1785. {
  1786. Bitmap ret_bp;
  1787. //显示xray相关信息
  1788. uint[] Search_xray = new uint[2000];
  1789. uint[] Analysis_xray = new uint[2000];
  1790. //
  1791. int i_xray_id = 0;
  1792. List<Element> list_celementchemistryclr = new List<Element>();
  1793. //获取Xray数据
  1794. list_celementchemistryclr = new List<Element>();
  1795. Particle list = particleData.GetParticleByFidAndPid(in_fieldid, in_particleid);
  1796. if (list == null)
  1797. {
  1798. return null;
  1799. }
  1800. Particle particle = list;
  1801. if (particle.XrayId > -1)
  1802. {
  1803. for (int i = 0; i < 2000; i++)
  1804. {
  1805. if (particle.XRayData!=null)
  1806. {
  1807. Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
  1808. }
  1809. }
  1810. Search_xray = Analysis_xray;
  1811. i_xray_id = particle.XrayId;
  1812. list_celementchemistryclr = particle.ElementList;
  1813. }
  1814. //get CElementChemistryClr list
  1815. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  1816. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  1817. {
  1818. ShowElementInfo ls_sei = new ShowElementInfo();
  1819. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  1820. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  1821. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX1);
  1822. list_showelementinfo.Add(ls_sei);
  1823. }
  1824. //获取使用标准库的名称
  1825. string str_stdname = "";
  1826. string str_IncALibName = "";
  1827. if (in_stdtypeid < 1000)
  1828. {
  1829. //小于1000,使用系统默认分类
  1830. str_IncALibName = TypeName;
  1831. str_stdname = "Default standard library";
  1832. }
  1833. else if (in_stdtypeid >= 1000 && in_stdtypeid < 10000)
  1834. {
  1835. //大于等于1000,并且小于10000时,使用系统数据库中夹杂物来分析
  1836. str_IncALibName = TypeName;
  1837. str_stdname = "User defined standard library";
  1838. }
  1839. else if (in_stdtypeid > 10000)
  1840. {
  1841. //大于10000时,使用用户标准库来分析夹杂物名称
  1842. str_IncALibName = TypeName;
  1843. str_stdname = "System standard library";
  1844. }
  1845. //获取数据后,需要对xraytable设置
  1846. OTSIncAReportGraph.Controls.Control_XRayTable control_XRayTable1 = new Control_XRayTable();
  1847. control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray, list_showelementinfo);
  1848. //颗粒国标信息
  1849. //control_XRayTable1.GBInfoStr = in_dparticle.GBContent;
  1850. control_XRayTable1.MaterialName = str_IncALibName;//杂夹物
  1851. control_XRayTable1.STDName = str_stdname;//标准库
  1852. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  1853. control_XRayTable1.Visible = true;
  1854. control_XRayTable1.Invalidate();
  1855. control_XRayTable1.Refresh();
  1856. ret_bp = control_XRayTable1.ExportXRayImage();
  1857. return ret_bp;
  1858. }
  1859. /// <summary>
  1860. /// 传入DataTable,和行号,返回该Row行中,返回6个靠前的元素,不足6个返回空
  1861. /// </summary>
  1862. /// <param name="in_dt"></param>
  1863. /// <param name="row_index"></param>
  1864. /// <returns></returns>
  1865. private void GetMaxElementFromDataTable(DataTable in_dt, int row_index, out List<string> out_list_elementname, out List<double> out_list_elementvalue)
  1866. {
  1867. out_list_elementname = new List<string>();
  1868. out_list_elementvalue = new List<double>();
  1869. //分别排出元素名,元素值列表
  1870. List<string> list_elementname = new List<string>();
  1871. List<double> list_elementvalue = new List<double>();
  1872. string str_element = in_dt.Rows[row_index]["Element"].ToString();
  1873. //防止取出的元素信息为空
  1874. if (str_element != "")
  1875. {
  1876. string[] strcbo = str_element.Split(';');
  1877. for (int i = 0; i < strcbo.Length-1; i++)
  1878. {
  1879. string[] str = strcbo[i].Split('-');
  1880. list_elementname.Add(str[0]);
  1881. list_elementvalue.Add(Math.Round(Convert.ToDouble(str[1]), 2));
  1882. }
  1883. }
  1884. //循环6次,得到最大的6个元素信息
  1885. for (int geti = 0; geti < 6; geti++)
  1886. {
  1887. double max_elementvalue = -1;
  1888. string max_elementname = "";
  1889. int max_index = -1;
  1890. if (list_elementvalue.Count > 0)
  1891. {
  1892. for (int i = 0; i < list_elementvalue.Count; i++)
  1893. {
  1894. if (list_elementvalue[i] > max_elementvalue)
  1895. {
  1896. max_elementvalue = list_elementvalue[i];
  1897. max_elementname = list_elementname[i];
  1898. max_index = i;
  1899. }
  1900. }
  1901. //移除掉最大的元素
  1902. list_elementname.RemoveAt(max_index);
  1903. list_elementvalue.RemoveAt(max_index);
  1904. //将最大的元素添加到list中
  1905. if (max_elementvalue > 0)
  1906. {
  1907. out_list_elementname.Add(max_elementname);
  1908. out_list_elementvalue.Add(max_elementvalue);
  1909. }
  1910. else
  1911. {
  1912. out_list_elementname.Add(" ");
  1913. out_list_elementvalue.Add(0);
  1914. }
  1915. }
  1916. else
  1917. {
  1918. //如果元素数量已经不够,则添加空
  1919. out_list_elementname.Add(" ");
  1920. out_list_elementvalue.Add(0);
  1921. }
  1922. }
  1923. }
  1924. #endregion
  1925. /// <summary>
  1926. /// 国标一
  1927. /// </summary>
  1928. /// <returns></returns>
  1929. public List<DataTable> InsertReportTemplateTable_ChineseStandardABCDDS(OTSCLRINTERFACE.CPropParamClr cPropParamClr)
  1930. {
  1931. //得到国标一的DataTable表格
  1932. cPropParamClr.SetDataSourceId(0);//
  1933. cPropParamClr.SetType(1);//table
  1934. cPropParamClr.SetCalTableType(6);//国标1
  1935. List<OTSCLRINTERFACE.CGridDataClr> listGriddataclr = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr.GridDataTransfer(cPropParamClr);
  1936. m_otsreport_export.m_ReportApp.im_ChineseStandardABCDDS = new OTSIncAReportGB.ChineseStandardABCDDS(m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr, listGriddataclr);
  1937. m_otsreport_export.m_ReportApp.m_TablesWindow.Controls.Clear();
  1938. //List<DataTable> GB_1 = m_otsreport_export.m_ReportApp.im_ChineseStandardABCDDS.ChineseStandardABCD_GetDataTable();
  1939. //string s = GB_1[0].Rows[0][0].ToString();
  1940. return m_otsreport_export.m_ReportApp.im_ChineseStandardABCDDS.ChineseStandardABCD_GetDataTable(); ;
  1941. }
  1942. /// <summary>
  1943. /// 国标二
  1944. /// </summary>
  1945. /// <returns></returns>
  1946. public List<DataTable> InsertReportTemplateTable_NationalStandardMethodTwo(OTSCLRINTERFACE.CPropParamClr cPropParamClr)
  1947. {
  1948. //得到国标二的DataTable表格
  1949. cPropParamClr.SetDataSourceId(0);//
  1950. cPropParamClr.SetType(1);//table
  1951. cPropParamClr.SetCalTableType(7);//国标2
  1952. List<OTSCLRINTERFACE.CGridDataClr> listGriddataclr2 = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr.GridDataTransfer(cPropParamClr);//
  1953. m_otsreport_export.m_ReportApp.m_TablesWindow.Controls.Clear();
  1954. m_otsreport_export.m_ReportApp.im_NationalStandardMethodTwo = new OTSIncAReportGB.NationalStandardMethodTwo(m_otsreport_export.m_ReportApp.m_rstDataMgr.m_ReportMgr, listGriddataclr2);
  1955. return m_otsreport_export.m_ReportApp.im_NationalStandardMethodTwo.ChineseStandardABCD_GetDataTable();
  1956. }
  1957. }
  1958. }