Export_ReportTemplate.cs 106 KB

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