Export_ReportTemplate.cs 128 KB

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