Export_ReportTemplate.cs 104 KB

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