ParticleList.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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 Org.BouncyCastle.Crypto;
  8. using OTSCommon.DBOperate;
  9. using OTSCommon.DBOperate.Model;
  10. using OTSIncAReportApp._1_UI.Control_Graph.Controls;
  11. using OTSIncAReportApp._3_ServiceCenter.DataOperation.DataAccess;
  12. using OTSIncAReportApp.DataOperation.DataAccess;
  13. using OTSIncAReportApp.OTSRstMgrFunction;
  14. using OTSIncAReportGraph.Controls;
  15. using OTSIncAReportGrids;
  16. using OTSPeriodicTable;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Data;
  20. using System.Drawing;
  21. using System.IO;
  22. using System.Linq;
  23. using System.Text;
  24. using System.Threading.Tasks;
  25. using System.Windows.Forms;
  26. using System.Windows.Media;
  27. using static OTSDataType.otsdataconst;
  28. using static OTSIncAReportApp.OTSReport_Export;
  29. namespace OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration
  30. {
  31. /// <summary>
  32. /// 颗粒列表
  33. /// </summary>
  34. class ParticleList
  35. {
  36. //string str_resultPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath;
  37. ParticleData fielddata;
  38. FieldImage imgAcc;
  39. /// <summary>
  40. /// DEV颗粒列表颗粒前20个谱图排序
  41. /// </summary>
  42. /// <param name="m_mbszclass"></param>
  43. /// <returns></returns>
  44. public List<DataTable> Get_dev_kllb_data(c_TemplateClass m_mbszclass, OTSReport_Export m_otsreport_export,BasicData basicData,out List<DataTable> a_FilteredData)
  45. {
  46. //------------------加载模块,获取数据-------------------------------------------------
  47. string str_resultPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath;
  48. fielddata = new ParticleData(str_resultPath);
  49. imgAcc = new FieldImage(str_resultPath );
  50. List<DataTable> OutDt = new List<DataTable>();
  51. a_FilteredData = new List<DataTable>();
  52. List<DataTable> datas = basicData.GetMeasurements();
  53. for (int i = 0; i < datas.Count; i++)
  54. {
  55. int serialNumber = 1;
  56. 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*/)
  57. {
  58. datas[i].Columns.Add("Hardness", typeof(double));
  59. datas[i].Columns.Add("Hardness_detailed");
  60. DataTable dt_stl = new DataTable();
  61. if (GetSTL(basicData.GetResfile(), out dt_stl, m_otsreport_export))
  62. {
  63. for (int a = 0; a < datas[a].Rows.Count; a++)
  64. {
  65. for (int b = 0; b < dt_stl.Rows.Count; b++)
  66. {
  67. if (datas[a].Rows[a]["TypeName"].ToString() == dt_stl.Rows[b]["TypeId"].ToString())
  68. {
  69. datas[a].Rows[a]["Hardness"] = Convert.ToDouble(dt_stl.Rows[b]["Hardness"]);
  70. datas[a].Rows[a]["Hardness_detailed"] = dt_stl.Rows[b]["Hardness_detailed"];
  71. break;
  72. }
  73. }
  74. }
  75. }
  76. }
  77. #region 夹杂物筛选
  78. for (int a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial.Count; a++)
  79. {
  80. for (int b = datas[i].Rows.Count - 1; b >= 0; b--)
  81. {
  82. if (m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial[a].ToString() == datas[i].Rows[b]["TypeId"].ToString())
  83. {
  84. datas[i].Rows.RemoveAt(b);
  85. }
  86. }
  87. }
  88. #endregion
  89. #region 安装选择的类型大小排序
  90. DataTable table = datas[i].Copy();
  91. DataView dvs = table.DefaultView;
  92. dvs.Sort = m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1.ToString() + " DESC";
  93. DataTable p1Data_b = dvs.ToTable();
  94. #endregion
  95. #region 创建要插入数据库表结构
  96. //插入模板需父子表,结构
  97. // 帧图表
  98. DataTable DT_field_dt = new DataTable();
  99. DataColumn colpictid2 = new DataColumn("FieldId");
  100. colpictid2.DataType = typeof(int);
  101. DT_field_dt.Columns.Add(colpictid2);
  102. //图像列
  103. DataColumn colpict2 = new DataColumn("FieldImg");
  104. colpict2.DataType = System.Type.GetType("System.Byte[]");
  105. DT_field_dt.Columns.Add(colpict2);
  106. //largest20表:(无关系表) 需要显示前20条带有显示能谱图像的颗粒表
  107. DataTable DT_Largest20 = new DataTable();
  108. DT_Largest20.TableName = "Largest20";
  109. DT_Largest20.Columns.Add("pid");
  110. DT_Largest20.Columns.Add("Size");
  111. DT_Largest20.Columns.Add("Width");
  112. DT_Largest20.Columns.Add("DMAX");
  113. DT_Largest20.Columns.Add("DMIN");
  114. DT_Largest20.Columns.Add("Class");
  115. DT_Largest20.Columns.Add("ColName1");
  116. DT_Largest20.Columns.Add("ColName2");
  117. DT_Largest20.Columns.Add("ColName3");
  118. DT_Largest20.Columns.Add("ColName4");
  119. DT_Largest20.Columns.Add("ColName5");
  120. DT_Largest20.Columns.Add("ColName6");
  121. DT_Largest20.Columns.Add("ColName7");
  122. DT_Largest20.Columns.Add("ColName8");
  123. DT_Largest20.Columns.Add("ColName9");
  124. DT_Largest20.Columns.Add("ColName10");
  125. DT_Largest20.Columns.Add("ColVal1");
  126. DT_Largest20.Columns.Add("ColVal2");
  127. DT_Largest20.Columns.Add("ColVal3");
  128. DT_Largest20.Columns.Add("ColVal4");
  129. DT_Largest20.Columns.Add("ColVal5");
  130. DT_Largest20.Columns.Add("ColVal6");
  131. DT_Largest20.Columns.Add("ColVal7");
  132. DT_Largest20.Columns.Add("ColVal8");
  133. DT_Largest20.Columns.Add("ColVal9");
  134. DT_Largest20.Columns.Add("ColVal10");
  135. // 图像列
  136. DT_Largest20.Columns.Add("p1", typeof(Bitmap));
  137. DT_Largest20.Columns.Add("p2", typeof(Bitmap));
  138. DT_Largest20.Columns.Add("p3", typeof(Bitmap));
  139. DT_Largest20.Columns.Add("GroupName");
  140. #endregion
  141. DataTable p1Data = fielddata.AddElementColumn(p1Data_b, m_mbszclass);
  142. #region 插入颗粒部份
  143. DataTable FilteredData = p1Data.Clone();
  144. ImageProcessor imageProcessor = new ImageProcessor();
  145. for (int i_row = 0; i_row < p1Data.Rows.Count; i_row++)
  146. {
  147. if (p1Data.Rows[i_row]["Element"].ToString() != "")
  148. {
  149. if (p1Data.Rows[i_row].ItemArray[24].ToString() != "Not Identified")
  150. {
  151. //获取颗粒的fieldid,和particleid
  152. string str_fieldid = p1Data.Rows[i_row]["fieldid"].ToString();
  153. string str_particleid = p1Data.Rows[i_row]["particleid"].ToString();
  154. string str_typeid = p1Data.Rows[i_row]["TypeId"].ToString();
  155. string str_typename = p1Data.Rows[i_row]["TypeName"].ToString();
  156. string str_element = p1Data.Rows[i_row]["Element"].ToString();
  157. //获取原始颗粒图像
  158. //Bitmap bp_particle = new Bitmap(1, 1);
  159. string str_path = str_resultPath + "\\FIELD_FILES\\";
  160. string str_imagePath = str_path + "Field" + str_fieldid.ToString() + ".bmp";
  161. if (str_fieldid == "-1")
  162. continue;
  163. if (serialNumber > m_mbszclass.M_KLLBXX.list_int_kllb_number)
  164. continue;
  165. DataTable table1=p1Data.Clone();
  166. table1.ImportRow(p1Data.Rows[i_row]);
  167. Bitmap bp_particle = imgAcc.GetBitmapByParticle(table1);
  168. bp_particle = imageProcessor.ResizeImageWithPadding(bp_particle, 120, 120, System.Drawing.Color.White);
  169. bp_particle.Tag = new List<string>() { p1Data.Rows[i_row]["FieldId"].ToString(), p1Data.Rows[i_row]["ParticleId"].ToString(), p1Data.Rows[i_row]["TypeId"].ToString() };
  170. //获取该颗粒的xray能谱图像
  171. DataTable DT_XR = ExportXRay(str_fieldid, str_particleid, fielddata);
  172. //ElementIcons.Add(DT_XR);
  173. System.Drawing.Bitmap bp_xraybp = ExportXRayBitmap(str_fieldid,
  174. str_particleid, Convert.ToInt32(str_typeid), str_typename, fielddata);
  175. Bitmap ls_xraybpnew = OTSIncAReportGraph.Class.DrawFunction.KiResizeImage(bp_xraybp, 700, 115);//能谱图处理
  176. DataTable SegmentData = fielddata.GetSegment();
  177. Bitmap BinaryParticles = ImageSplicer.ParticleBinaryDiagram(SegmentData, Convert.ToInt32(str_fieldid), Convert.ToInt32(str_particleid));
  178. Bitmap BP = imageProcessor.ResizeImageWithPadding(BinaryParticles, 120, 120, System.Drawing.Color.White);
  179. //获取该颗粒的二次放大处理图像
  180. //Bitmap ls_processbitmap = OTSIncAReportGraph.Class.DrawFunction.GetReZoomBitmap(bp_particle);// (Bitmap)bp_particle.Clone();//待完善
  181. //再将图像转成二进制流-------------------------------------------------------------------
  182. //原图
  183. MemoryStream newms_p1 = new MemoryStream();
  184. bp_particle.Save(newms_p1, System.Drawing.Imaging.ImageFormat.Bmp);
  185. //二次放大图
  186. MemoryStream newms_p2 = new MemoryStream();
  187. BP.Save(newms_p2, System.Drawing.Imaging.ImageFormat.Bmp);
  188. //能谱图
  189. MemoryStream newms_p3 = new MemoryStream();
  190. ls_xraybpnew.Save(newms_p3, System.Drawing.Imaging.ImageFormat.Bmp);
  191. //---------------------------------------------------------------------------------------
  192. DataRow dr = DT_Largest20.NewRow();
  193. dr["p1"] = bp_particle;
  194. dr["p2"] = BP;
  195. dr["p3"] = ls_xraybpnew;
  196. newms_p1.Dispose();
  197. newms_p2.Dispose();
  198. newms_p3.Dispose();
  199. dr["pid"] = serialNumber++.ToString();
  200. //颗粒列表列中第一个可选参数
  201. dr["Size"] = datatable_data(p1Data, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1);
  202. //这个参数没有用
  203. dr["Width"] = p1Data.Rows[i_row]["rectwidth"].ToString();
  204. //颗粒列表列中第二个可选参数
  205. dr["DMAX"] = datatable_data(p1Data, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p2);
  206. //颗粒列表列中第三个可选参数
  207. dr["DMIN"] = datatable_data(p1Data, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p3);
  208. //颗粒列表列中显示分类不可以选择
  209. dr["Class"] = p1Data.Rows[i_row]["typename"].ToString();
  210. dr["GroupName"] = p1Data.Rows[i_row]["GroupName"].ToString();
  211. GetMaxElementFromDataTable(p1Data, i_row, out List<string> list_max_elementname, out List<double> list_max_elementvale);
  212. double colVal = 0;
  213. for (int a = 0; a < list_max_elementvale.Count; a++)
  214. {
  215. colVal = colVal + Convert.ToDouble(list_max_elementvale[a]);
  216. }
  217. //元素1
  218. dr["ColName1"] = list_max_elementname[0];
  219. dr["ColVal1"] = ParameterNormalization(colVal, list_max_elementvale[0]);
  220. //元素2
  221. dr["ColName2"] = list_max_elementname[1];
  222. dr["ColVal2"] = ParameterNormalization(colVal, list_max_elementvale[1]);
  223. //元素3
  224. dr["ColName3"] = list_max_elementname[2];
  225. dr["ColVal3"] = ParameterNormalization(colVal, list_max_elementvale[2]);
  226. //元素4
  227. dr["ColName4"] = list_max_elementname[3];
  228. dr["ColVal4"] = ParameterNormalization(colVal, list_max_elementvale[3]);
  229. //元素5
  230. dr["ColName5"] = list_max_elementname[4];
  231. dr["ColVal5"] = ParameterNormalization(colVal, list_max_elementvale[4]);
  232. //元素6
  233. dr["ColName6"] = list_max_elementname[5];
  234. dr["ColVal6"] = ParameterNormalization(colVal, list_max_elementvale[5]);
  235. //元素7
  236. dr["ColName7"] = list_max_elementname[6];
  237. dr["ColVal7"] = ParameterNormalization(colVal, list_max_elementvale[6]);
  238. //元素8
  239. dr["ColName8"] = list_max_elementname[7];
  240. dr["ColVal8"] = ParameterNormalization(colVal, list_max_elementvale[7]);
  241. //元素6
  242. dr["ColName9"] = list_max_elementname[8];
  243. dr["ColVal9"] = ParameterNormalization(colVal, list_max_elementvale[8]);
  244. //元素6
  245. dr["ColName9"] = list_max_elementname[9];
  246. dr["ColVal9"] = ParameterNormalization(colVal, list_max_elementvale[9]);
  247. DT_Largest20.Rows.Add(dr);
  248. FilteredData.Rows.Add(p1Data.Rows[i_row].ItemArray);
  249. }
  250. }
  251. }
  252. #endregion
  253. OutDt.Add(DT_Largest20);
  254. a_FilteredData.Add(FilteredData);
  255. }
  256. return OutDt;
  257. }
  258. /// <summary>
  259. /// 拼接颗粒
  260. /// </summary>
  261. public DataTable GetSplicingParticlesData(OTSReport_Export m_otsreport_export)
  262. {
  263. DataTable SplicingParticlesData = new DataTable();
  264. SplicingParticlesData.Columns.Add("image",typeof(Bitmap));
  265. SplicingParticlesData.Columns.Add("TypeName");
  266. SplicingParticlesData.Columns.Add("Area");
  267. SplicingParticlesData.Columns.Add("ECD");
  268. SplicingParticlesData.Columns.Add("DiameterRatio");
  269. SplicingParticlesData.Columns.Add("DPERP");
  270. //根据sql条件,查询获取颗粒信息数据
  271. ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath);
  272. DataTable particles = fielddata.GetSplicingParticlesData();
  273. if (particles.Rows.Count == 0)
  274. {
  275. return SplicingParticlesData;
  276. }
  277. ResultFile result = null;
  278. string sou = m_otsreport_export.m_ReportApp.m_conditionChoose.m_CurrentConditions[OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE].itemDisplayVal.ToString();
  279. if (sou.Contains("+"))
  280. {
  281. MessageBox.Show("This function does not support multiple samples!");
  282. result = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[0];
  283. }
  284. else
  285. {
  286. 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)];
  287. }
  288. ParticleData Particledata = new ParticleData(result.FilePath);
  289. string filePath = result.FilePath + "\\FIELD_FILES\\";
  290. for (int i = 0; i < particles.Rows.Count; i++)
  291. {
  292. DataTable table1 = particles.Clone();
  293. table1.ImportRow(particles.Rows[i]);
  294. Bitmap bmap = imgAcc.GetBitmapByParticle(table1);
  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. DataTable table1 = dt.Clone();
  712. table1.ImportRow(dt.Rows[i_row]);
  713. bp_particle = imgAcc.GetBitmapByParticle(table1);
  714. bp_particle.Tag = new List<string>() { dt.Rows[i_row]["FieldId"].ToString(), dt.Rows[i_row]["ParticleId"].ToString(), dt.Rows[i_row]["TypeId"].ToString() };
  715. DataRow dr = FrameGraphSubTable.NewRow();
  716. dr["pic"] = bp_particle;
  717. //帧图列表列第一个字段的可选参数
  718. dr["pid"] = datatable_data(dt, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1);
  719. //帧图列表列第二个字段的可选参数
  720. dr["Size"] = datatable_data(dt, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p2);
  721. dr["Width"] = dt.Rows[i_row]["rectwidth"].ToString();
  722. dr["DMAX"] = Math.Round(Convert.ToDouble(dt.Rows[i_row]["dmax"]), 2).ToString();
  723. dr["DMIN"] = Math.Round(Convert.ToDouble(dt.Rows[i_row]["dmin"]), 2).ToString();
  724. dr["Class"] = dt.Rows[i_row]["typename"].ToString();
  725. dr["GroupName"] = dt.Rows[i_row]["GroupName"].ToString();
  726. dr["fieldid"] = str_fieldid;
  727. GetMaxElementFromDataTable(dt, i_row, out List<string> list_max_elementname, out List<double> list_max_elementvale);
  728. double colVal = 0;
  729. for (int i = 0; i < list_max_elementvale.Count; i++)
  730. {
  731. colVal = colVal + Convert.ToDouble(list_max_elementvale[i]);
  732. }
  733. //元素1
  734. dr["ColName1"] = list_max_elementname[0];
  735. dr["ColVal1"] = ParameterNormalization(colVal, list_max_elementvale[0]);
  736. //元素2
  737. dr["ColName2"] = list_max_elementname[1];
  738. dr["ColVal2"] = ParameterNormalization(colVal, list_max_elementvale[1]);
  739. //元素3
  740. dr["ColName3"] = list_max_elementname[2];
  741. dr["ColVal3"] = ParameterNormalization(colVal, list_max_elementvale[2]);
  742. //元素4
  743. dr["ColName4"] = list_max_elementname[3];
  744. dr["ColVal4"] = ParameterNormalization(colVal, list_max_elementvale[3]);
  745. //元素5
  746. dr["ColName5"] = list_max_elementname[4];
  747. dr["ColVal5"] = ParameterNormalization(colVal, list_max_elementvale[4]);
  748. //元素6
  749. dr["ColName6"] = list_max_elementname[5];
  750. dr["ColVal6"] = ParameterNormalization(colVal, list_max_elementvale[5]);
  751. //元素6
  752. dr["ColName7"] = list_max_elementname[6];
  753. dr["ColVal7"] = ParameterNormalization(colVal, list_max_elementvale[6]);
  754. //元素6
  755. dr["ColName8"] = list_max_elementname[7];
  756. dr["ColVal8"] = ParameterNormalization(colVal, list_max_elementvale[7]);
  757. //元素6
  758. dr["ColName9"] = list_max_elementname[8];
  759. dr["ColVal9"] = ParameterNormalization(colVal, list_max_elementvale[8]);
  760. //元素6
  761. dr["ColName10"] = list_max_elementname[9];
  762. dr["ColVal10"] = ParameterNormalization(colVal, list_max_elementvale[9]);
  763. FrameGraphSubTable.Rows.Add(dr);
  764. }
  765. }
  766. return FrameGraphSubTable;
  767. }
  768. private bool JudgeWhetherItExists(int id, DataTable dt, string column)
  769. {
  770. for (int i = 0; i < dt.Rows.Count; i++)
  771. {
  772. if (id == Convert.ToInt32(dt.Rows[i][column].ToString()))
  773. return true;
  774. }
  775. return false;
  776. }
  777. }
  778. }