ParticleList.cs 38 KB

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