Export_ReportTemplate.cs 130 KB

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