ParticleList.cs 37 KB

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