ParticleList.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. using DevExpress.DataAccess.Sql;
  2. using DevExpress.Office.Utils;
  3. using DevExpress.PivotGrid.OLAP.SchemaEntities;
  4. using DevExpress.XtraDiagram.Bars;
  5. using DevExpress.XtraTreeList.Data;
  6. using NPOI.Util;
  7. using OTSCommon.DBOperate;
  8. using OTSCommon.DBOperate.Model;
  9. using OTSIncAReportApp._1_UI.Control_Graph.Controls;
  10. using OTSIncAReportApp.DataOperation.DataAccess;
  11. using OTSIncAReportApp.OTSRstMgrFunction;
  12. using OTSIncAReportGraph.Controls;
  13. using OTSIncAReportGrids;
  14. using OTSPeriodicTable;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Data;
  18. using System.Drawing;
  19. using System.IO;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. using System.Windows.Forms;
  24. using System.Windows.Media;
  25. using static OTSDataType.otsdataconst;
  26. using static OTSIncAReportApp.OTSReport_Export;
  27. namespace OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration
  28. {
  29. /// <summary>
  30. /// 颗粒列表
  31. /// </summary>
  32. class ParticleList
  33. {
  34. /// <summary>
  35. /// DEV颗粒列表颗粒前20个谱图排序
  36. /// </summary>
  37. /// <param name="m_mbszclass"></param>
  38. /// <returns></returns>
  39. public List<DataTable> Get_dev_kllb_data(c_TemplateClass m_mbszclass, OTSReport_Export m_otsreport_export,BasicData basicData,out List<DataTable> a_FilteredData)
  40. {
  41. //------------------加载模块,获取数据-------------------------------------------------
  42. string str_resultPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath;
  43. ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath);
  44. List<DataTable> OutDt = new List<DataTable>();
  45. a_FilteredData = new List<DataTable>();
  46. List<DataTable> datas = basicData.GetMeasurements();
  47. for (int i = 0; i < datas.Count; i++)
  48. {
  49. int serialNumber = 1;
  50. if (m_otsreport_export.m_ReportApp.m_RptConfigFile.Systype == OTS_SysType_ID.TCCleannessA/*|| m_otsreport_export.m_ReportApp.m_RptConfigFile.Systype == OTS_SysType_ID.BatteryCleannessA*/)
  51. {
  52. datas[i].Columns.Add("Hardness", typeof(double));
  53. datas[i].Columns.Add("Hardness_detailed");
  54. DataTable dt_stl = new DataTable();
  55. if (GetSTL(basicData.GetResfile(), out dt_stl, m_otsreport_export))
  56. {
  57. for (int a = 0; a < datas[a].Rows.Count; a++)
  58. {
  59. for (int b = 0; b < dt_stl.Rows.Count; b++)
  60. {
  61. if (datas[a].Rows[a]["TypeName"].ToString() == dt_stl.Rows[b]["TypeId"].ToString())
  62. {
  63. datas[a].Rows[a]["Hardness"] = Convert.ToDouble(dt_stl.Rows[b]["Hardness"]);
  64. datas[a].Rows[a]["Hardness_detailed"] = dt_stl.Rows[b]["Hardness_detailed"];
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. #region 夹杂物筛选
  72. for (int a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial.Count; a++)
  73. {
  74. for (int b = datas[i].Rows.Count - 1; b >= 0; b--)
  75. {
  76. if (m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial[a].ToString() == datas[i].Rows[b]["TypeId"].ToString())
  77. {
  78. datas[i].Rows.RemoveAt(b);
  79. }
  80. }
  81. }
  82. #endregion
  83. #region 安装选择的类型大小排序
  84. DataTable table = datas[i].Copy();
  85. //if (!table.Columns.Contains("Area"))
  86. // {
  87. // table.Columns.Add("Area");
  88. // DataColumn newColumn = new DataColumn("Area", typeof(double));
  89. // table.Columns.Add(1, newColumn);
  90. // for (int a = 0; a < table.Rows.Count; a++)
  91. // {
  92. // table.Rows[a]["Area"] = Convert.ToDouble(table.Rows[a]["ar"]);
  93. // }
  94. // table.Columns.Remove("ar");
  95. //}
  96. DataView dvs = table.DefaultView;
  97. //if (m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1.ToString() == "Area")
  98. //{
  99. // dvs.Sort = "ar DESC";
  100. //}
  101. //else
  102. //{
  103. dvs.Sort = m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1.ToString() + " DESC";
  104. //}
  105. DataTable p1Data_b = dvs.ToTable();
  106. #endregion
  107. #region 创建要插入数据库表结构
  108. //插入模板需父子表,结构
  109. // 帧图表
  110. DataTable DT_field_dt = new DataTable();
  111. DataColumn colpictid2 = new DataColumn("FieldId");
  112. colpictid2.DataType = typeof(int);
  113. DT_field_dt.Columns.Add(colpictid2);
  114. //图像列
  115. DataColumn colpict2 = new DataColumn("FieldImg");
  116. colpict2.DataType = System.Type.GetType("System.Byte[]");
  117. DT_field_dt.Columns.Add(colpict2);
  118. //largest20表:(无关系表) 需要显示前20条带有显示能谱图像的颗粒表
  119. DataTable DT_Largest20 = new DataTable();
  120. DT_Largest20.TableName = "Largest20";
  121. DT_Largest20.Columns.Add("pid");
  122. DT_Largest20.Columns.Add("Size");
  123. DT_Largest20.Columns.Add("Width");
  124. DT_Largest20.Columns.Add("DMAX");
  125. DT_Largest20.Columns.Add("DMIN");
  126. DT_Largest20.Columns.Add("Class");
  127. DT_Largest20.Columns.Add("ColName1");
  128. DT_Largest20.Columns.Add("ColName2");
  129. DT_Largest20.Columns.Add("ColName3");
  130. DT_Largest20.Columns.Add("ColName4");
  131. DT_Largest20.Columns.Add("ColName5");
  132. DT_Largest20.Columns.Add("ColName6");
  133. DT_Largest20.Columns.Add("ColName7");
  134. DT_Largest20.Columns.Add("ColName8");
  135. DT_Largest20.Columns.Add("ColName9");
  136. DT_Largest20.Columns.Add("ColName10");
  137. DT_Largest20.Columns.Add("ColVal1");
  138. DT_Largest20.Columns.Add("ColVal2");
  139. DT_Largest20.Columns.Add("ColVal3");
  140. DT_Largest20.Columns.Add("ColVal4");
  141. DT_Largest20.Columns.Add("ColVal5");
  142. DT_Largest20.Columns.Add("ColVal6");
  143. DT_Largest20.Columns.Add("ColVal7");
  144. DT_Largest20.Columns.Add("ColVal8");
  145. DT_Largest20.Columns.Add("ColVal9");
  146. DT_Largest20.Columns.Add("ColVal10");
  147. // 图像列
  148. DT_Largest20.Columns.Add("p1", typeof(Bitmap));
  149. DT_Largest20.Columns.Add("p2", typeof(Bitmap));
  150. DT_Largest20.Columns.Add("p3", typeof(Bitmap));
  151. DT_Largest20.Columns.Add("GroupName");
  152. #endregion
  153. DataTable p1Data = fielddata.AddElementColumn(p1Data_b);
  154. #region 插入颗粒部份
  155. DataTable FilteredData = p1Data.Clone();
  156. ImageProcessor imageProcessor = new ImageProcessor();
  157. for (int i_row = 0; i_row < p1Data.Rows.Count; i_row++)
  158. {
  159. if (p1Data.Rows[i_row].ItemArray[24].ToString() != "Not Identified")
  160. {
  161. //获取颗粒的fieldid,和particleid
  162. string str_fieldid = p1Data.Rows[i_row]["fieldid"].ToString();
  163. string str_particleid = p1Data.Rows[i_row]["particleid"].ToString();
  164. string str_typeid = p1Data.Rows[i_row]["TypeId"].ToString();
  165. string str_typename = p1Data.Rows[i_row]["TypeName"].ToString();
  166. string str_element = p1Data.Rows[i_row]["Element"].ToString();
  167. //获取原始颗粒图像
  168. //Bitmap bp_particle = new Bitmap(1, 1);
  169. string str_path = str_resultPath + "\\FIELD_FILES\\";
  170. string str_imagePath = str_path + "Field" + str_fieldid.ToString() + ".bmp";
  171. if (str_fieldid == "-1")
  172. continue;
  173. if (serialNumber > m_mbszclass.M_KLLBXX.list_int_kllb_number)
  174. continue;
  175. Rectangle rectangle = new Rectangle()
  176. { X = Convert.ToInt32(p1Data.Rows[i_row]["RectLeft"]), Y = Convert.ToInt32(p1Data.Rows[i_row]["RectTop"]), Width = Convert.ToInt32(p1Data.Rows[i_row]["RectWidth"]), Height = Convert.ToInt32(p1Data.Rows[i_row]["RectHeight"]) };
  177. Bitmap bp_field = fielddata.ReadImageFile(str_imagePath);
  178. Bitmap bp_particle = fielddata.GetBitmapByParticle(bp_field, rectangle);
  179. bp_particle = imageProcessor.ResizeImageWithPadding(bp_particle, 120, 120, System.Drawing.Color.White);
  180. bp_particle.Tag = new List<string>() { p1Data.Rows[i_row]["FieldId"].ToString(), p1Data.Rows[i_row]["ParticleId"].ToString(), p1Data.Rows[i_row]["TypeId"].ToString() };
  181. //获取该颗粒的xray能谱图像
  182. DataTable DT_XR = ExportXRay(str_fieldid, str_particleid, fielddata);
  183. //ElementIcons.Add(DT_XR);
  184. System.Drawing.Bitmap bp_xraybp = ExportXRayBitmap(str_fieldid,
  185. str_particleid, Convert.ToInt32(str_typeid), str_typename, fielddata);
  186. Bitmap ls_xraybpnew = OTSIncAReportGraph.Class.DrawFunction.KiResizeImage(bp_xraybp, 700, 115);//能谱图处理
  187. DataTable SegmentData = fielddata.GetSegment();
  188. Bitmap BinaryParticles = ImageSplicer.ParticleBinaryDiagram(SegmentData, Convert.ToInt32(str_fieldid), Convert.ToInt32(str_particleid));
  189. Bitmap BP = imageProcessor.ResizeImageWithPadding(BinaryParticles, 120, 120, System.Drawing.Color.White);
  190. //获取该颗粒的二次放大处理图像
  191. //Bitmap ls_processbitmap = OTSIncAReportGraph.Class.DrawFunction.GetReZoomBitmap(bp_particle);// (Bitmap)bp_particle.Clone();//待完善
  192. //再将图像转成二进制流-------------------------------------------------------------------
  193. //原图
  194. MemoryStream newms_p1 = new MemoryStream();
  195. bp_particle.Save(newms_p1, System.Drawing.Imaging.ImageFormat.Bmp);
  196. //二次放大图
  197. MemoryStream newms_p2 = new MemoryStream();
  198. BP.Save(newms_p2, System.Drawing.Imaging.ImageFormat.Bmp);
  199. //能谱图
  200. MemoryStream newms_p3 = new MemoryStream();
  201. ls_xraybpnew.Save(newms_p3, System.Drawing.Imaging.ImageFormat.Bmp);
  202. //---------------------------------------------------------------------------------------
  203. DataRow dr = DT_Largest20.NewRow();
  204. dr["p1"] = bp_particle;
  205. dr["p2"] = BP;
  206. dr["p3"] = ls_xraybpnew;
  207. newms_p1.Dispose();
  208. newms_p2.Dispose();
  209. newms_p3.Dispose();
  210. dr["pid"] = serialNumber++.ToString();
  211. //颗粒列表列中第一个可选参数
  212. dr["Size"] = datatable_data(p1Data, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1);
  213. //这个参数没有用
  214. dr["Width"] = p1Data.Rows[i_row]["rectwidth"].ToString();
  215. //颗粒列表列中第二个可选参数
  216. dr["DMAX"] = datatable_data(p1Data, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p2);
  217. //颗粒列表列中第三个可选参数
  218. dr["DMIN"] = datatable_data(p1Data, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p3);
  219. //颗粒列表列中显示分类不可以选择
  220. dr["Class"] = p1Data.Rows[i_row]["typename"].ToString();
  221. dr["GroupName"] = p1Data.Rows[i_row]["GroupName"].ToString();
  222. GetMaxElementFromDataTable(p1Data, i_row, out List<string> list_max_elementname, out List<double> list_max_elementvale);
  223. double colVal = 0;
  224. for (int a = 0; a < list_max_elementvale.Count; a++)
  225. {
  226. colVal = colVal + Convert.ToDouble(list_max_elementvale[a]);
  227. }
  228. //元素1
  229. dr["ColName1"] = list_max_elementname[0];
  230. dr["ColVal1"] = ParameterNormalization(colVal, list_max_elementvale[0]);
  231. //元素2
  232. dr["ColName2"] = list_max_elementname[1];
  233. dr["ColVal2"] = ParameterNormalization(colVal, list_max_elementvale[1]);
  234. //元素3
  235. dr["ColName3"] = list_max_elementname[2];
  236. dr["ColVal3"] = ParameterNormalization(colVal, list_max_elementvale[2]);
  237. //元素4
  238. dr["ColName4"] = list_max_elementname[3];
  239. dr["ColVal4"] = ParameterNormalization(colVal, list_max_elementvale[3]);
  240. //元素5
  241. dr["ColName5"] = list_max_elementname[4];
  242. dr["ColVal5"] = ParameterNormalization(colVal, list_max_elementvale[4]);
  243. //元素6
  244. dr["ColName6"] = list_max_elementname[5];
  245. dr["ColVal6"] = ParameterNormalization(colVal, list_max_elementvale[5]);
  246. //元素7
  247. dr["ColName7"] = list_max_elementname[6];
  248. dr["ColVal7"] = ParameterNormalization(colVal, list_max_elementvale[6]);
  249. //元素8
  250. dr["ColName8"] = list_max_elementname[7];
  251. dr["ColVal8"] = ParameterNormalization(colVal, list_max_elementvale[7]);
  252. //元素6
  253. dr["ColName9"] = list_max_elementname[8];
  254. dr["ColVal9"] = ParameterNormalization(colVal, list_max_elementvale[8]);
  255. //元素6
  256. dr["ColName9"] = list_max_elementname[9];
  257. dr["ColVal9"] = ParameterNormalization(colVal, list_max_elementvale[9]);
  258. DT_Largest20.Rows.Add(dr);
  259. FilteredData.Rows.Add(p1Data.Rows[i_row].ItemArray);
  260. }
  261. }
  262. #endregion
  263. OutDt.Add(DT_Largest20);
  264. a_FilteredData.Add(FilteredData);
  265. }
  266. return OutDt;
  267. }
  268. /// <summary>
  269. /// 拼接颗粒
  270. /// </summary>
  271. public DataTable GetSplicingParticlesData(OTSReport_Export m_otsreport_export)
  272. {
  273. DataTable SplicingParticlesData = new DataTable();
  274. SplicingParticlesData.Columns.Add("image",typeof(Bitmap));
  275. SplicingParticlesData.Columns.Add("TypeName");
  276. SplicingParticlesData.Columns.Add("Area");
  277. SplicingParticlesData.Columns.Add("ECD");
  278. SplicingParticlesData.Columns.Add("DiameterRatio");
  279. SplicingParticlesData.Columns.Add("DPERP");
  280. //根据sql条件,查询获取颗粒信息数据
  281. ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath);
  282. DataTable particles = fielddata.GetSplicingParticlesData();
  283. if (particles.Rows.Count == 0)
  284. {
  285. return SplicingParticlesData;
  286. }
  287. ResultFile result = null;
  288. string sou = m_otsreport_export.m_ReportApp.m_conditionChoose.m_CurrentConditions[OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE].itemDisplayVal.ToString();
  289. if (sou.Contains("+"))
  290. {
  291. MessageBox.Show("This function does not support multiple samples!");
  292. result = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[0];
  293. }
  294. else
  295. {
  296. result = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE)];
  297. }
  298. ParticleData Particledata = new ParticleData(result.FilePath);
  299. string filePath = result.FilePath + "\\FIELD_FILES\\";
  300. for (int i = 0; i < particles.Rows.Count; i++)
  301. {
  302. KeyValuePair<string, Bitmap> FieldImage = new KeyValuePair<string, Bitmap>();
  303. if (FieldImage.Key != particles.Rows[i]["fieldid"].ToString() || FieldImage.Value == null)
  304. {
  305. string imagePath = filePath + "Field" + particles.Rows[i]["fieldid"].ToString() + ".bmp";
  306. FieldImage = new KeyValuePair<string, Bitmap>(particles.Rows[i]["fieldid"].ToString(), Particledata.ReadImageFile(imagePath));
  307. }
  308. Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(particles.Rows[i]["RectLeft"]), Y = Convert.ToInt32(particles.Rows[i]["RectTop"]), Width = Convert.ToInt32(particles.Rows[i]["RectWidth"]), Height = Convert.ToInt32(particles.Rows[i]["RectHeight"]) };
  309. Bitmap bmap = Particledata.GetBitmapByParticle(FieldImage.Value, rectangle);
  310. bmap.Tag = new List<string>() { particles.Rows[i]["FieldId"].ToString(), particles.Rows[i]["ParticleId"].ToString(), particles.Rows[i]["TypeId"].ToString(), particles.Rows[i]["XrayId"].ToString() };
  311. DataRow row = SplicingParticlesData.NewRow();
  312. row["image"] = bmap;
  313. row["TypeName"] = particles.Rows[i]["TypeName"];
  314. row["Area"] = particles.Rows[i]["Area"];
  315. row["ECD"] = (Convert.ToDouble(particles.Rows[i]["Area"]) / Math.PI) * 2;
  316. row["DiameterRatio"] = Convert.ToDouble(particles.Rows[i]["DMAX"]) / Convert.ToDouble(particles.Rows[i]["DMIN"]);
  317. row["DPERP"] = particles.Rows[i]["DPERP"];
  318. SplicingParticlesData.Rows.Add(row);
  319. }
  320. return SplicingParticlesData;
  321. }
  322. /// <summary>
  323. /// 颗粒列表帧图
  324. /// </summary>
  325. /// <param name="m_mbszclass"></param>
  326. /// <param name="file_pic"></param>
  327. /// <param name="list_dt"></param>
  328. /// <param name="m_otsreport_export"></param>
  329. public void Get_dev_kllb_data_frame_pic(c_TemplateClass m_mbszclass, out DataTable file_pic, out List<DataTable> list_dt, OTSReport_Export m_otsreport_export, List<DataTable> FrameData)
  330. {
  331. m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage = new ParticlesGridDevidePage(m_otsreport_export.m_ReportApp);
  332. //根据sql条件,查询获取颗粒信息数据
  333. ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath);
  334. string str_resultPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath;
  335. file_pic =new DataTable();
  336. file_pic.Clear();
  337. file_pic.Columns.Add("fieldid");
  338. file_pic.Columns.Add("id");
  339. file_pic.Columns.Add("fieldName");
  340. file_pic.Columns.Add("cunt", typeof(int));
  341. file_pic.Columns.Add("fieldFullName");
  342. file_pic.Columns.Add("Field_pic", typeof(Bitmap));
  343. list_dt = new List<DataTable>();
  344. for (int i = 0; i < FrameData.Count; i++)
  345. {
  346. DataTable pic = new DataTable();
  347. List<DataTable> picDt = new List<DataTable>();
  348. m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage.Out_MarkParticleRectangleOnFieldFile(str_resultPath, FrameData[i], out List<string> vs, out DataTable data);
  349. DataTable data_A = FrameGraphParticleTableDatat(FrameData[i], fielddata, data, m_mbszclass, m_otsreport_export);
  350. for (int a = 0; a < data.Rows.Count; a++)
  351. {
  352. DataTable dataTable = data_A.Clone();
  353. //在数据表中有颗粒在该帧图中的话,则对该帧图标记图像进行读取存入数据库
  354. DataRow[] datarowlist = data_A.Select(data.Rows[a]["fieldid"].ToString());
  355. if (datarowlist.Count() > 0)
  356. {
  357. for (int b = 0; b < data_A.Rows.Count; b++)
  358. {
  359. if (data.Rows[a]["id"].ToString() == data_A.Rows[b]["FieldId"].ToString())
  360. {
  361. dataTable.Rows.Add(data_A.Rows[b].ItemArray);
  362. dataTable.TableName = data_A.Rows[b]["FieldId"].ToString();
  363. }
  364. }
  365. //bool bl = false;
  366. // for (int j = 0; j < list_dt.Count; i++)
  367. // {
  368. // if (list_dt[j].TableName == dataTable.TableName)
  369. // {
  370. // bl = true;
  371. // }
  372. // }
  373. // if (!bl)
  374. // {
  375. list_dt.Add(dataTable);
  376. file_pic.Rows.Add(data.Rows[a].ItemArray);
  377. //}
  378. }
  379. }
  380. }
  381. }
  382. private bool GetSTL(string str, out DataTable data,OTSReport_Export m_otsreport_export)
  383. {
  384. if (str.ToLower() == "nostddb")
  385. {
  386. data = null;
  387. return false;
  388. }
  389. DataTable dt = new DataTable();
  390. dt.Columns.Add("TypeId");
  391. dt.Columns.Add("Hardness", typeof(double));
  392. dt.Columns.Add("Hardness_detailed");
  393. OTSCommon.DBOperate.SqLiteHelper sh = null;
  394. string fullPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.CurResultFile.FilePath + "\\" + str + ".db";
  395. string fullPath2 = System.IO.Directory.GetCurrentDirectory() + "\\Config\\SysData\\" + str + ".db";
  396. if (System.IO.File.Exists(fullPath))
  397. {
  398. sh = new OTSCommon.DBOperate.SqLiteHelper("data source='" + fullPath + "'");
  399. }
  400. else if (System.IO.File.Exists(fullPath2))
  401. {
  402. sh = new OTSCommon.DBOperate.SqLiteHelper("data source='" + fullPath2 + "'");
  403. }
  404. else
  405. {
  406. sh = null;
  407. data = null;
  408. return false;
  409. }
  410. DataTable dt_stl = sh.ExecuteQuery("select * from ClassifySTD");
  411. for (int i = 0; i < dt_stl.Rows.Count; i++)
  412. {
  413. DataRow dr = dt.NewRow();
  414. dr["TypeId"] = dt_stl.Rows[i]["StrName"].ToString();
  415. dr["Hardness_detailed"] = dt_stl.Rows[i]["Hardness"].ToString();
  416. if (System.Text.RegularExpressions.Regex.Replace(dt_stl.Rows[i]["Hardness"].ToString(), @"[^\d.\d]", "").ToString() != "")
  417. {
  418. try
  419. {
  420. if (System.Text.RegularExpressions.Regex.Replace(dt_stl.Rows[i]["Hardness"].ToString(), @"[^\d.\d]", "") == "o. Def.")
  421. {
  422. dr["Hardness"] = 0;
  423. }
  424. else
  425. {
  426. dr["Hardness"] = Convert.ToDouble(System.Text.RegularExpressions.Regex.Replace(dt_stl.Rows[i]["Hardness"].ToString(), @"[^\d.\d]", ""));
  427. }
  428. }
  429. catch
  430. {
  431. dr["Hardness"] = 0;
  432. }
  433. }
  434. else
  435. {
  436. dr["Hardness"] = 0;
  437. }
  438. dt.Rows.Add(dr);
  439. }
  440. data = dt;
  441. return true;
  442. }
  443. private DataTable ExportXRay(string in_fieldid, string in_particleid, ParticleData particleData)
  444. {
  445. DataTable data = new DataTable();
  446. data.Columns.Add("XName", typeof(string));
  447. data.Columns.Add("Serial", typeof(double));
  448. data.Columns.Add("data", typeof(double));
  449. uint[] Analysis_xray = new uint[2000];
  450. //获取Xray数据
  451. Particle list = particleData.GetParticleByFidAndPid(in_fieldid, in_particleid);
  452. if (list == null)
  453. {
  454. return null;
  455. }
  456. Particle particle = list;
  457. if (particle.XrayId > -1)
  458. {
  459. for (int i = 0; i < 999; i++)
  460. {
  461. DataRow dr = data.NewRow();
  462. dr["XName"] = i + 1;
  463. dr["Serial"] = i + 1;
  464. dr["data"] = BitConverter.ToUInt32(particle.XRayData, i * 4);
  465. Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
  466. data.Rows.Add(dr);
  467. }
  468. }
  469. return data;
  470. }
  471. /// <summary>
  472. /// 输入颗粒的所在帧图id,颗粒id,颗粒类型id,获取对应的XRay能谱数据图
  473. /// </summary>
  474. /// <returns></returns>
  475. private Bitmap ExportXRayBitmap(string in_fieldid, string in_particleid, int in_stdtypeid, string TypeName, ParticleData particleData)
  476. {
  477. Bitmap ret_bp;
  478. //显示xray相关信息
  479. uint[] Search_xray = new uint[2000];
  480. uint[] Analysis_xray = new uint[2000];
  481. int i_xray_id = 0;
  482. List<Element> list_celementchemistryclr = new List<Element>();
  483. //获取Xray数据
  484. Particle list = particleData.GetParticleByFidAndPid(in_fieldid, in_particleid);
  485. if (list == null)
  486. {
  487. return null;
  488. }
  489. Particle particle = list;
  490. if (particle.XrayId > -1)
  491. {
  492. for (int i = 0; i < 2000; i++)
  493. {
  494. if (particle.XRayData != null)
  495. {
  496. Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
  497. }
  498. }
  499. Search_xray = Analysis_xray;
  500. i_xray_id = particle.XrayId;
  501. list_celementchemistryclr = particle.ElementList;
  502. }
  503. //get CElementChemistryClr list
  504. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  505. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  506. {
  507. ShowElementInfo ls_sei = new ShowElementInfo();
  508. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  509. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  510. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  511. list_showelementinfo.Add(ls_sei);
  512. }
  513. //获取使用标准库的名称
  514. string str_stdname = "";
  515. string str_IncALibName = "";
  516. if (in_stdtypeid < 1000)
  517. {
  518. //小于1000,使用系统默认分类
  519. str_IncALibName = TypeName;
  520. str_stdname = "Default standard library";
  521. }
  522. else if (in_stdtypeid >= 1000 && in_stdtypeid < 10000)
  523. {
  524. //大于等于1000,并且小于10000时,使用系统数据库中夹杂物来分析
  525. str_IncALibName = TypeName;
  526. str_stdname = "User defined standard library";
  527. }
  528. else if (in_stdtypeid > 10000)
  529. {
  530. //大于10000时,使用用户标准库来分析夹杂物名称
  531. str_IncALibName = TypeName;
  532. str_stdname = "System standard library";
  533. }
  534. //获取数据后,需要对xraytable设置
  535. OTSIncAReportGraph.Controls.Control_XRayTable control_XRayTable1 = new Control_XRayTable();
  536. control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray, list_showelementinfo);
  537. //颗粒国标信息
  538. //control_XRayTable1.GBInfoStr = in_dparticle.GBContent;
  539. control_XRayTable1.MaterialName = str_IncALibName;//杂夹物
  540. control_XRayTable1.STDName = str_stdname;//标准库
  541. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  542. control_XRayTable1.Visible = true;
  543. control_XRayTable1.Invalidate();
  544. control_XRayTable1.Refresh();
  545. ret_bp = control_XRayTable1.ExportXRayImage();
  546. return ret_bp;
  547. }
  548. private string datatable_data(DataTable dt, int it, string str)
  549. {
  550. if (str == "Hardness")
  551. {
  552. return dt.Rows[it]["Hardness_detailed"].ToString();
  553. }
  554. else
  555. if (str == "Area")
  556. {
  557. return Convert.ToDouble(dt.Rows[it][str]).ToString("#0.00");
  558. }
  559. else
  560. if (str == "DMAX")
  561. {
  562. return Math.Round(Convert.ToDouble(dt.Rows[it][str]), 2).ToString();
  563. }
  564. else
  565. {
  566. return dt.Rows[it][str].ToString();
  567. }
  568. }
  569. /// <summary>
  570. /// 传入DataTable,和行号,返回该Row行中,返回6个靠前的元素,不足6个返回空
  571. /// </summary>
  572. /// <param name="in_dt"></param>
  573. /// <param name="row_index"></param>
  574. /// <returns></returns>
  575. private void GetMaxElementFromDataTable(DataTable in_dt, int row_index, out List<string> out_list_elementname, out List<double> out_list_elementvalue)
  576. {
  577. out_list_elementname = new List<string>();
  578. out_list_elementvalue = new List<double>();
  579. //分别排出元素名,元素值列表
  580. List<string> list_elementname = new List<string>();
  581. List<double> list_elementvalue = new List<double>();
  582. string str_element = in_dt.Rows[row_index]["Element"].ToString();
  583. //防止取出的元素信息为空
  584. if (str_element != "")
  585. {
  586. string[] strcbo = str_element.Split(';');
  587. for (int i = 0; i < strcbo.Length - 1; i++)
  588. {
  589. string[] str = strcbo[i].Split('-');
  590. list_elementname.Add(str[0]);
  591. list_elementvalue.Add(Math.Round(Convert.ToDouble(str[1]), 2));
  592. }
  593. }
  594. //循环6次,得到最大的6个元素信息
  595. for (int geti = 0; geti < 11; geti++)
  596. {
  597. double max_elementvalue = -1;
  598. string max_elementname = " ";
  599. int max_index = -1;
  600. if (list_elementvalue.Count > 0)
  601. {
  602. for (int i = 0; i < list_elementvalue.Count; i++)
  603. {
  604. if (list_elementvalue[i] > max_elementvalue)
  605. {
  606. max_elementvalue = list_elementvalue[i];
  607. max_elementname = list_elementname[i];
  608. max_index = i;
  609. }
  610. }
  611. //移除掉最大的元素
  612. list_elementname.RemoveAt(max_index);
  613. list_elementvalue.RemoveAt(max_index);
  614. //将最大的元素添加到list中
  615. if (max_elementvalue > 0)
  616. {
  617. out_list_elementname.Add(max_elementname);
  618. out_list_elementvalue.Add(max_elementvalue);
  619. }
  620. else
  621. {
  622. out_list_elementname.Add(" ");
  623. out_list_elementvalue.Add(0);
  624. }
  625. }
  626. else
  627. {
  628. //如果元素数量已经不够,则添加空
  629. out_list_elementname.Add(" ");
  630. out_list_elementvalue.Add(0);
  631. }
  632. }
  633. }
  634. /// <summary>
  635. /// 参数归一化
  636. /// </summary>
  637. /// <param name="a_mi">总数</param>
  638. /// <param name="m">传参</param>
  639. /// <returns></returns>
  640. private string ParameterNormalization(double a_mi, double m)
  641. {
  642. double ColVal = Convert.ToDouble(m / a_mi * 100);
  643. if (ColVal == 0)
  644. {
  645. return "";
  646. }
  647. else
  648. {
  649. if (m == 0)
  650. return "0";
  651. else
  652. return Math.Round(ColVal, 2).ToString();
  653. }
  654. }
  655. private DataTable FrameGraphParticleTableDatat(DataTable dt_ParticlesGridDevidePage, ParticleData fielddata, DataTable DT_field_dt, c_TemplateClass m_mbszclass, OTSReport_Export m_otsreport_export)
  656. {
  657. DataTable dt;
  658. if (m_otsreport_export.m_ReportApp.m_RptConfigFile.Systype != OTS_SysType_ID.IncA)
  659. {
  660. if (dt_ParticlesGridDevidePage.Columns.Contains("Hardness"))
  661. dt_ParticlesGridDevidePage.Columns.Remove("Hardness");
  662. if (dt_ParticlesGridDevidePage.Columns.Contains("Hardness_detailed"))
  663. dt_ParticlesGridDevidePage.Columns.Remove("Hardness_detailed");
  664. //将颗粒大小排序(从大到小)
  665. DataView dvs = dt_ParticlesGridDevidePage.DefaultView;
  666. dvs.Sort = m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1.ToString() + " DESC";
  667. dt = dvs.ToTable();
  668. dt.Columns.Add("Hardness");
  669. dt.Columns.Add("Hardness_detailed");
  670. }
  671. else
  672. {
  673. //将颗粒大小排序(从大到小)
  674. DataView dvs = dt_ParticlesGridDevidePage.DefaultView;
  675. dvs.Sort = m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1.ToString() + " DESC";
  676. dt = dvs.ToTable();
  677. }
  678. //表名Largest_frame表:(子表) 显示20条颗粒除外的部份颗粒信息
  679. DataTable FrameGraphSubTable = new DataTable();
  680. FrameGraphSubTable.TableName = "FrameGraphSubTable";
  681. FrameGraphSubTable.Columns.Add("pid");
  682. FrameGraphSubTable.Columns.Add("Size");
  683. FrameGraphSubTable.Columns.Add("Width");
  684. FrameGraphSubTable.Columns.Add("DMAX");
  685. FrameGraphSubTable.Columns.Add("DMIN");
  686. FrameGraphSubTable.Columns.Add("Class");
  687. FrameGraphSubTable.Columns.Add("ColName1");
  688. FrameGraphSubTable.Columns.Add("ColName2");
  689. FrameGraphSubTable.Columns.Add("ColName3");
  690. FrameGraphSubTable.Columns.Add("ColName4");
  691. FrameGraphSubTable.Columns.Add("ColName5");
  692. FrameGraphSubTable.Columns.Add("ColName6");
  693. FrameGraphSubTable.Columns.Add("ColName7");
  694. FrameGraphSubTable.Columns.Add("ColName8");
  695. FrameGraphSubTable.Columns.Add("ColName9");
  696. FrameGraphSubTable.Columns.Add("ColName10");
  697. FrameGraphSubTable.Columns.Add("ColVal1");
  698. FrameGraphSubTable.Columns.Add("ColVal2");
  699. FrameGraphSubTable.Columns.Add("ColVal3");
  700. FrameGraphSubTable.Columns.Add("ColVal4");
  701. FrameGraphSubTable.Columns.Add("ColVal5");
  702. FrameGraphSubTable.Columns.Add("ColVal6");
  703. FrameGraphSubTable.Columns.Add("ColVal7");
  704. FrameGraphSubTable.Columns.Add("ColVal8");
  705. FrameGraphSubTable.Columns.Add("ColVal9");
  706. FrameGraphSubTable.Columns.Add("ColVal10");
  707. FrameGraphSubTable.Columns.Add("pic", typeof(Bitmap));
  708. FrameGraphSubTable.Columns.Add("FieldId", typeof(int));
  709. FrameGraphSubTable.Columns.Add("GroupName");
  710. for (int i_row = 0; i_row < dt.Rows.Count; i_row++)
  711. {
  712. if (dt.Rows[i_row]["element"].ToString() == "")
  713. continue;
  714. if (dt.Rows[i_row]["TypeName"].ToString() == "Not Identified")
  715. continue;
  716. string str_fieldid = dt.Rows[i_row]["fieldid"].ToString();
  717. if (JudgeWhetherItExists(Convert.ToInt32(str_fieldid), DT_field_dt, "id"))
  718. {
  719. //获取原始颗粒图像
  720. Bitmap bp_particle = new Bitmap(1, 1);
  721. Bitmap bp_field = new Bitmap(1, 1);
  722. Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(dt.Rows[i_row]["RectLeft"]), Y = Convert.ToInt32(dt.Rows[i_row]["RectTop"]), Width = Convert.ToInt32(dt.Rows[i_row]["RectWidth"]), Height = Convert.ToInt32(dt.Rows[i_row]["RectHeight"]) };
  723. for (int i = 0; i < DT_field_dt.Rows.Count; i++)
  724. {
  725. if (dt.Rows[i_row]["FieldId"].ToString() == DT_field_dt.Rows[i]["id"].ToString())
  726. {
  727. bp_field = new Bitmap(DT_field_dt.Rows[i]["fieldFullName"].ToString());
  728. }
  729. }
  730. bp_particle = fielddata.GetBitmapByParticle(bp_field, rectangle);
  731. bp_particle.Tag = new List<string>() { dt.Rows[i_row]["FieldId"].ToString(), dt.Rows[i_row]["ParticleId"].ToString(), dt.Rows[i_row]["TypeId"].ToString() };
  732. DataRow dr = FrameGraphSubTable.NewRow();
  733. dr["pic"] = bp_particle;
  734. //帧图列表列第一个字段的可选参数
  735. dr["pid"] = datatable_data(dt, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1);
  736. //帧图列表列第二个字段的可选参数
  737. dr["Size"] = datatable_data(dt, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p2);
  738. dr["Width"] = dt.Rows[i_row]["rectwidth"].ToString();
  739. dr["DMAX"] = Math.Round(Convert.ToDouble(dt.Rows[i_row]["dmax"]), 2).ToString();
  740. dr["DMIN"] = Math.Round(Convert.ToDouble(dt.Rows[i_row]["dmin"]), 2).ToString();
  741. dr["Class"] = dt.Rows[i_row]["typename"].ToString();
  742. dr["GroupName"] = dt.Rows[i_row]["GroupName"].ToString();
  743. dr["fieldid"] = str_fieldid;
  744. GetMaxElementFromDataTable(dt, i_row, out List<string> list_max_elementname, out List<double> list_max_elementvale);
  745. double colVal = 0;
  746. for (int i = 0; i < list_max_elementvale.Count; i++)
  747. {
  748. colVal = colVal + Convert.ToDouble(list_max_elementvale[i]);
  749. }
  750. //元素1
  751. dr["ColName1"] = list_max_elementname[0];
  752. dr["ColVal1"] = ParameterNormalization(colVal, list_max_elementvale[0]);
  753. //元素2
  754. dr["ColName2"] = list_max_elementname[1];
  755. dr["ColVal2"] = ParameterNormalization(colVal, list_max_elementvale[1]);
  756. //元素3
  757. dr["ColName3"] = list_max_elementname[2];
  758. dr["ColVal3"] = ParameterNormalization(colVal, list_max_elementvale[2]);
  759. //元素4
  760. dr["ColName4"] = list_max_elementname[3];
  761. dr["ColVal4"] = ParameterNormalization(colVal, list_max_elementvale[3]);
  762. //元素5
  763. dr["ColName5"] = list_max_elementname[4];
  764. dr["ColVal5"] = ParameterNormalization(colVal, list_max_elementvale[4]);
  765. //元素6
  766. dr["ColName6"] = list_max_elementname[5];
  767. dr["ColVal6"] = ParameterNormalization(colVal, list_max_elementvale[5]);
  768. //元素6
  769. dr["ColName7"] = list_max_elementname[6];
  770. dr["ColVal7"] = ParameterNormalization(colVal, list_max_elementvale[6]);
  771. //元素6
  772. dr["ColName8"] = list_max_elementname[7];
  773. dr["ColVal8"] = ParameterNormalization(colVal, list_max_elementvale[7]);
  774. //元素6
  775. dr["ColName9"] = list_max_elementname[8];
  776. dr["ColVal9"] = ParameterNormalization(colVal, list_max_elementvale[8]);
  777. //元素6
  778. dr["ColName10"] = list_max_elementname[9];
  779. dr["ColVal10"] = ParameterNormalization(colVal, list_max_elementvale[9]);
  780. FrameGraphSubTable.Rows.Add(dr);
  781. }
  782. }
  783. return FrameGraphSubTable;
  784. }
  785. private bool JudgeWhetherItExists(int id, DataTable dt, string column)
  786. {
  787. for (int i = 0; i < dt.Rows.Count; i++)
  788. {
  789. if (id == Convert.ToInt32(dt.Rows[i][column].ToString()))
  790. return true;
  791. }
  792. return false;
  793. }
  794. }
  795. }