Export_ReportTemplate.cs 127 KB

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