Export_ReportTemplate.cs 104 KB

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