Export_ReportTemplate.cs 104 KB

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