Export_ReportTemplate.cs 128 KB

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