Export_ReportTemplate.cs 105 KB

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