using OTSCommon.Model;
using OTSIncAReportApp.DataOperation.DataAccess;
using OTSIncAReportGraph.Controls;
using OTSIncAReportGrids;
using OTSPeriodicTable;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static OTSIncAReportApp.OTSReport_Export;
namespace OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration
{
///
/// 颗粒列表
///
class ParticleList
{
///
/// DEV颗粒列表颗粒前20个谱图排序
///
///
///
public DataTable Get_dev_kllb_data(c_TemplateClass m_mbszclass, OTSReport_Export m_otsreport_export,out DataTable FilteredData,out List ElementIcons)
{
int serialNumber = 1;
//------------------加载模块,获取数据-------------------------------------------------
m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage = new ParticlesGridDevidePage(m_otsreport_export.m_ReportApp);
//根据sql条件,查询获取颗粒信息数据
ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.getSelectedIndex()].FilePath);
DataTable btb = InvalidRemoval(fielddata.GetIncaSurfaceData(m_mbszclass.M_KLLBXX.list_str_kllb_qcys));
DataTable dt;
if (m_mbszclass.list_str_MainPriority.Count == 0)
{
dt = btb.Copy();
}
else
{
dt = btb.Clone();
for (int i = 0; i < btb.Rows.Count; i++)
{
for (int a = 0; a < m_mbszclass.list_str_MainPriority.Count; a++)
{
if (btb.Rows[i]["TypeName"].ToString() == m_mbszclass.list_str_MainPriority[a])
{
dt.Rows.Add(btb.Rows[i].ItemArray);
continue;
}
}
}
}
ResultFile resfile = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.getSelectedIndex()];
string str_libraryName = resfile.GetSTDName();
if (m_otsreport_export.m_ReportApp.m_RptConfigFile.Systype == OTS_SysType_ID.CleannessA)
{
dt.Columns.Add("Hardness", typeof(double));
dt.Columns.Add("Hardness_detailed");
DataTable dt_stl = new DataTable();
if (GetSTL(str_libraryName, out dt_stl,m_otsreport_export))
{
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int a = 0; a < dt_stl.Rows.Count; a++)
{
if (dt.Rows[i]["TypeName"].ToString() == dt_stl.Rows[a]["TypeId"].ToString())
{
dt.Rows[i]["Hardness"] = Convert.ToDouble(dt_stl.Rows[a]["Hardness"]);
dt.Rows[i]["Hardness_detailed"] = dt_stl.Rows[a]["Hardness_detailed"];
break;
}
}
}
}
}
//去除物质分类(非夹杂物分类)
for (int a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass.Count; a++)
{
for (int i = dt.Rows.Count - 1; i >= 0; i--)
{
if (dt.Rows[i]["TypeName"].ToString() == m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass[a].ToString())
{
dt.Rows.RemoveAt(i);
}
}
}
DataTable PriorityOne = dt.Clone();
for (int i=0;i< dt.Rows.Count;i++)
{
for (int a=0;a< m_mbszclass.list_str_MainPriority.Count;a++)
{
if (m_mbszclass.list_str_MainPriority[a].ToString()== dt.Rows[i]["TypeName"].ToString())
{
PriorityOne.Rows.Add(dt.Rows[i].ItemArray);
}
}
}
DataTable dt_ParticlesGridDevidePage;
if (m_mbszclass.list_str_MainPriority.Count!=0)
{
dt_ParticlesGridDevidePage = dt.Clone();
DataView dvs = PriorityOne.DefaultView;
dvs.Sort = m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1.ToString() + " DESC";
var da = dvs.ToTable();
for (int i = 0; i < da.Rows.Count; i++)
{
dt_ParticlesGridDevidePage.Rows.Add(da.Rows[i].ItemArray);
}
}
else
{
DataView dvs = dt.DefaultView;
dvs.Sort = m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1.ToString() + " DESC";
dt_ParticlesGridDevidePage = dvs.ToTable();
//dt_ParticlesGridDevidePage = dt.Copy();
}
string str_resultPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.getSelectedIndex()].FilePath;
//------------------加载模块,获取数据结束----------------------------------------------
#region 创建要插入数据库表结构
//插入模板需父子表,结构
//表名field_dt表:(父表) 帧图表
DataTable DT_field_dt = new DataTable();
DT_field_dt.TableName = "field_dt";
DataColumn colpictid2 = new DataColumn("FieldId");
colpictid2.DataType = typeof(int);
DT_field_dt.Columns.Add(colpictid2);
//图像列
DataColumn colpict2 = new DataColumn("FieldImg");
colpict2.DataType = System.Type.GetType("System.Byte[]");
DT_field_dt.Columns.Add(colpict2);
//largest20表:(无关系表) 需要显示前20条带有显示能谱图像的颗粒表
DataTable DT_Largest20 = new DataTable();
DT_Largest20.TableName = "Largest20";
DT_Largest20.Columns.Add("pid");
DT_Largest20.Columns.Add("Size");
DT_Largest20.Columns.Add("Width");
DT_Largest20.Columns.Add("DMAX");
DT_Largest20.Columns.Add("DMIN");
DT_Largest20.Columns.Add("Class");
DT_Largest20.Columns.Add("ColName1");
DT_Largest20.Columns.Add("ColName2");
DT_Largest20.Columns.Add("ColName3");
DT_Largest20.Columns.Add("ColName4");
DT_Largest20.Columns.Add("ColName5");
DT_Largest20.Columns.Add("ColName6");
DT_Largest20.Columns.Add("ColName7");
DT_Largest20.Columns.Add("ColName8");
DT_Largest20.Columns.Add("ColName9");
DT_Largest20.Columns.Add("ColName10");
DT_Largest20.Columns.Add("ColVal1");
DT_Largest20.Columns.Add("ColVal2");
DT_Largest20.Columns.Add("ColVal3");
DT_Largest20.Columns.Add("ColVal4");
DT_Largest20.Columns.Add("ColVal5");
DT_Largest20.Columns.Add("ColVal6");
DT_Largest20.Columns.Add("ColVal7");
DT_Largest20.Columns.Add("ColVal8");
DT_Largest20.Columns.Add("ColVal9");
DT_Largest20.Columns.Add("ColVal10");
// 图像列
DT_Largest20.Columns.Add("p1", typeof(Bitmap));
DT_Largest20.Columns.Add("p2", typeof(Bitmap));
DT_Largest20.Columns.Add("p3", typeof(Bitmap));
#endregion
DataTable Filtered = dt_ParticlesGridDevidePage.Clone();
ElementIcons = new List();
#region 插入-前20颗粒部份
for (int i_row = 0; i_row < dt_ParticlesGridDevidePage.Rows.Count; i_row++)
{
if (dt_ParticlesGridDevidePage.Rows[i_row].ItemArray[24].ToString() != "Not Identified")
{
//获取颗粒的fieldid,和particleid
string str_fieldid = dt_ParticlesGridDevidePage.Rows[i_row]["fieldid"].ToString();
string str_particleid = dt_ParticlesGridDevidePage.Rows[i_row]["particleid"].ToString();
string str_typeid = dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString();
string str_typename = dt_ParticlesGridDevidePage.Rows[i_row]["TypeName"].ToString();
string str_element = dt_ParticlesGridDevidePage.Rows[i_row]["Element"].ToString();
//获取原始颗粒图像
Bitmap bp_particle = new Bitmap(1, 1);
string str_path = str_resultPath + "\\FIELD_FILES\\";
string str_imagePath = str_path + "Field" + str_fieldid.ToString() + ".bmp";
if (str_fieldid == "-1")
continue;
if (serialNumber > m_mbszclass.M_KLLBXX.list_int_kllb_number)
continue;
Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectLeft"]), Y = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectTop"]), Width = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectWidth"]), Height = Convert.ToInt32(dt_ParticlesGridDevidePage.Rows[i_row]["RectHeight"]) };
Bitmap bp_field = fielddata.ReadImageFile(str_imagePath);
bp_particle = fielddata.GetBitmapByParticle(bp_field, rectangle);
bp_particle.Tag = new List() { dt_ParticlesGridDevidePage.Rows[i_row]["FieldId"].ToString(), dt_ParticlesGridDevidePage.Rows[i_row]["ParticleId"].ToString(), dt_ParticlesGridDevidePage.Rows[i_row]["TypeId"].ToString() };
//获取该颗粒的xray能谱图像
DataTable DT_XR= ExportXRay(str_fieldid, str_particleid, fielddata);
ElementIcons.Add(DT_XR);
System.Drawing.Bitmap bp_xraybp = ExportXRayBitmap(str_fieldid,
str_particleid, Convert.ToInt32(str_typeid), str_typename, fielddata);
Bitmap ls_xraybpnew = OTSIncAReportGraph.Class.DrawFunction.KiResizeImage(bp_xraybp, 700, 115);//能谱图处理
//获取该颗粒的二次放大处理图像
Bitmap ls_processbitmap = OTSIncAReportGraph.Class.DrawFunction.GetReZoomBitmap(bp_particle);// (Bitmap)bp_particle.Clone();//待完善
//再将图像转成二进制流-------------------------------------------------------------------
//原图
MemoryStream newms_p1 = new MemoryStream();
bp_particle.Save(newms_p1, System.Drawing.Imaging.ImageFormat.Bmp);
//二次放大图
MemoryStream newms_p2 = new MemoryStream();
ls_processbitmap.Save(newms_p2, System.Drawing.Imaging.ImageFormat.Bmp);
//能谱图
MemoryStream newms_p3 = new MemoryStream();
ls_xraybpnew.Save(newms_p3, System.Drawing.Imaging.ImageFormat.Bmp);
//---------------------------------------------------------------------------------------
DataRow dr = DT_Largest20.NewRow();
dr["p1"] = bp_particle;
dr["p2"] = ls_processbitmap;
dr["p3"] = ls_xraybpnew;
newms_p1.Dispose();
newms_p2.Dispose();
newms_p3.Dispose();
dr["pid"] = serialNumber++.ToString();
//颗粒列表列中第一个可选参数
dr["Size"] = datatable_data(dt_ParticlesGridDevidePage, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1);
//这个参数没有用
dr["Width"] = dt_ParticlesGridDevidePage.Rows[i_row]["rectwidth"].ToString();
//颗粒列表列中第二个可选参数
dr["DMAX"] = datatable_data(dt_ParticlesGridDevidePage, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p2);
//颗粒列表列中第三个可选参数
dr["DMIN"] = datatable_data(dt_ParticlesGridDevidePage, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p3);
//颗粒列表列中显示分类不可以选择
dr["Class"] = dt_ParticlesGridDevidePage.Rows[i_row]["typename"].ToString();
GetMaxElementFromDataTable(dt_ParticlesGridDevidePage, i_row, out List list_max_elementname, out List list_max_elementvale);
double colVal = 0;
for (int i = 0; i < list_max_elementvale.Count; i++)
{
colVal = colVal + Convert.ToDouble(list_max_elementvale[i]);
}
//元素1
dr["ColName1"] = list_max_elementname[0];
dr["ColVal1"] = ParameterNormalization(colVal, list_max_elementvale[0]);
//元素2
dr["ColName2"] = list_max_elementname[1];
dr["ColVal2"] = ParameterNormalization(colVal, list_max_elementvale[1]);
//元素3
dr["ColName3"] = list_max_elementname[2];
dr["ColVal3"] = ParameterNormalization(colVal, list_max_elementvale[2]);
//元素4
dr["ColName4"] = list_max_elementname[3];
dr["ColVal4"] = ParameterNormalization(colVal, list_max_elementvale[3]);
//元素5
dr["ColName5"] = list_max_elementname[4];
dr["ColVal5"] = ParameterNormalization(colVal, list_max_elementvale[4]);
//元素6
dr["ColName6"] = list_max_elementname[5];
dr["ColVal6"] = ParameterNormalization(colVal, list_max_elementvale[5]);
//元素7
dr["ColName7"] = list_max_elementname[6];
dr["ColVal7"] = ParameterNormalization(colVal, list_max_elementvale[6]);
//元素8
dr["ColName8"] = list_max_elementname[7];
dr["ColVal8"] = ParameterNormalization(colVal, list_max_elementvale[7]);
//元素6
dr["ColName9"] = list_max_elementname[8];
dr["ColVal9"] = ParameterNormalization(colVal, list_max_elementvale[8]);
//元素6
dr["ColName9"] = list_max_elementname[9];
dr["ColVal9"] = ParameterNormalization(colVal, list_max_elementvale[9]);
DT_Largest20.Rows.Add(dr);
Filtered.Rows.Add(dt_ParticlesGridDevidePage.Rows[i_row].ItemArray);
}
}
FilteredData = Filtered.Copy();
#endregion
return DT_Largest20;
}
///
/// 颗粒列表帧图
///
///
///
///
///
public void Get_dev_kllb_data_frame(c_TemplateClass m_mbszclass, out DataTable file_pic, out List list_dt, OTSReport_Export m_otsreport_export,DataTable FrameData)
{
m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage = new ParticlesGridDevidePage(m_otsreport_export.m_ReportApp);
//根据sql条件,查询获取颗粒信息数据
ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.getSelectedIndex()].FilePath);
DataTable btb = InvalidRemoval(fielddata.GetIncaSurfaceData(m_mbszclass.M_KLLBXX.list_str_kllb_qcys));
DataTable dt;
if (m_mbszclass.list_str_MainPriority.Count == 0)
{
dt = btb.Copy();
}
else
{
dt = btb.Clone();
for (int i = 0; i < btb.Rows.Count; i++)
{
for (int a = 0; a < m_mbszclass.list_str_MainPriority.Count; a++)
{
if (btb.Rows[i]["TypeName"].ToString() == m_mbszclass.list_str_MainPriority[a])
{
dt.Rows.Add(btb.Rows[i].ItemArray);
continue;
}
}
}
}
ResultFile resfile = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.getSelectedIndex()];
string str_libraryName = resfile.GetSTDName();
if (m_otsreport_export.m_ReportApp.m_RptConfigFile.Systype == OTS_SysType_ID.CleannessA)
{
dt.Columns.Add("Hardness", typeof(double));
dt.Columns.Add("Hardness_detailed");
DataTable dt_stl = new DataTable();
if (GetSTL(str_libraryName, out dt_stl, m_otsreport_export))
{
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int a = 0; a < dt_stl.Rows.Count; a++)
{
if (dt.Rows[i]["TypeName"].ToString() == dt_stl.Rows[a]["TypeId"].ToString())
{
dt.Rows[i]["Hardness"] = Convert.ToDouble(dt_stl.Rows[a]["Hardness"]);
dt.Rows[i]["Hardness_detailed"] = dt_stl.Rows[a]["Hardness_detailed"];
break;
}
}
}
}
}
//去除物质分类(非夹杂物分类)
for (int a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass.Count; a++)
{
for (int i = dt.Rows.Count - 1; i >= 0; i--)
{
if (dt.Rows[i]["TypeName"].ToString() == m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass[a].ToString())
{
dt.Rows.RemoveAt(i);
}
}
}
//将颗粒大小排序(从大到小)
DataView dv = dt.DefaultView;
dv.Sort = m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1.ToString() + " DESC";
DataTable dt_ParticlesGridDevidePage = dv.ToTable();
string str_resultPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.getSelectedIndex()].FilePath;
DataTable dt_GridDevidePage = FrameData.Copy();
m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage.Out_MarkParticleRectangleOnFieldFile(str_resultPath, dt_GridDevidePage, out List vs, out DataTable data);
DataTable data_A= FrameGraphParticleTableDatat(dt_ParticlesGridDevidePage, fielddata, data, m_mbszclass, m_otsreport_export);
List listData = new List();
for (int i = 0; i < data.Rows.Count; i++)
{
DataTable dataTable = data_A.Clone();
//在数据表中有颗粒在该帧图中的话,则对该帧图标记图像进行读取存入数据库
DataRow[] datarowlist = data_A.Select(data.Rows[i]["fieldid"].ToString());
if (datarowlist.Count() > 0)
{
for (int a = 0; a < data_A.Rows.Count; a++)
{
if (data.Rows[i]["id"].ToString() == data_A.Rows[a]["FieldId"].ToString())
{
dataTable.Rows.Add(data_A.Rows[a].ItemArray);
}
}
listData.Add(dataTable);
}
}
file_pic = data.Copy();
list_dt = listData;
}
private DataTable InvalidRemoval(DataTable dt)
{
DataTable dataTable = dt.Copy();
dataTable.Clear();
for (int i = 0; i < dt.Rows.Count; i++)
{
if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 10)
{
dataTable.Rows.Add(dt.Rows[i].ItemArray);
}
}
return dataTable;
}
private bool GetSTL(string str, out DataTable data,OTSReport_Export m_otsreport_export)
{
if (str.ToLower() == "nostddb")
{
data = null;
return false;
}
DataTable dt = new DataTable();
dt.Columns.Add("TypeId");
dt.Columns.Add("Hardness", typeof(double));
dt.Columns.Add("Hardness_detailed");
OTSCommon.SqLiteHelper sh = null;
string fullPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.CurResultFile.FilePath + "\\" + str + ".db";
string fullPath2 = System.IO.Directory.GetCurrentDirectory() + "\\Config\\SysData\\" + str + ".db";
if (System.IO.File.Exists(fullPath))
{
sh = new OTSCommon.SqLiteHelper("data source='" + fullPath + "'");
}
else if (System.IO.File.Exists(fullPath2))
{
sh = new OTSCommon.SqLiteHelper("data source='" + fullPath2 + "'");
}
else
{
sh = null;
data = null;
return false;
}
DataTable dt_stl = sh.ExecuteQuery("select * from ClassifySTD");
for (int i = 0; i < dt_stl.Rows.Count; i++)
{
DataRow dr = dt.NewRow();
dr["TypeId"] = dt_stl.Rows[i]["StrName"].ToString();
dr["Hardness_detailed"] = dt_stl.Rows[i]["Hardness"].ToString();
if (System.Text.RegularExpressions.Regex.Replace(dt_stl.Rows[i]["Hardness"].ToString(), @"[^\d.\d]", "").ToString() != "")
{
if (System.Text.RegularExpressions.Regex.Replace(dt_stl.Rows[i]["Hardness"].ToString(), @"[^\d.\d]", "") == "o. Def.")
{
dr["Hardness"] = 0;
}
else
{
dr["Hardness"] = Convert.ToDouble(System.Text.RegularExpressions.Regex.Replace(dt_stl.Rows[i]["Hardness"].ToString(), @"[^\d.\d]", ""));
}
}
else
{
dr["Hardness"] = 0;
}
dt.Rows.Add(dr);
}
data = dt;
return true;
}
private DataTable ExportXRay(string in_fieldid, string in_particleid, ParticleData particleData)
{
DataTable data = new DataTable();
data.Columns.Add("XName", typeof(string));
data.Columns.Add("Serial", typeof(double));
data.Columns.Add("data", typeof(double));
uint[] Analysis_xray = new uint[2000];
//获取Xray数据
Particle list = particleData.GetParticleByFidAndPid(in_fieldid, in_particleid);
if (list == null)
{
return null;
}
Particle particle = list;
if (particle.XrayId > -1)
{
for (int i = 0; i < 999; i++)
{
DataRow dr = data.NewRow();
dr["XName"] = i + 1;
dr["Serial"] = i + 1;
dr["data"] = BitConverter.ToUInt32(particle.XRayData, i * 4);
Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
data.Rows.Add(dr);
}
}
return data;
}
///
/// 输入颗粒的所在帧图id,颗粒id,颗粒类型id,获取对应的XRay能谱数据图
///
///
private Bitmap ExportXRayBitmap(string in_fieldid, string in_particleid, int in_stdtypeid, string TypeName, ParticleData particleData)
{
Bitmap ret_bp;
//显示xray相关信息
uint[] Search_xray = new uint[2000];
uint[] Analysis_xray = new uint[2000];
int i_xray_id = 0;
List list_celementchemistryclr = new List();
//获取Xray数据
Particle list = particleData.GetParticleByFidAndPid(in_fieldid, in_particleid);
if (list == null)
{
return null;
}
Particle particle = list;
if (particle.XrayId > -1)
{
for (int i = 0; i < 2000; i++)
{
if (particle.XRayData != null)
{
Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
}
}
Search_xray = Analysis_xray;
i_xray_id = particle.XrayId;
list_celementchemistryclr = particle.ElementList;
}
//get CElementChemistryClr list
List list_showelementinfo = new List();
for (int i = 0; i < list_celementchemistryclr.Count; i++)
{
ShowElementInfo ls_sei = new ShowElementInfo();
ls_sei.ElementName = list_celementchemistryclr[i].Name;
ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
list_showelementinfo.Add(ls_sei);
}
//获取使用标准库的名称
string str_stdname = "";
string str_IncALibName = "";
if (in_stdtypeid < 1000)
{
//小于1000,使用系统默认分类
str_IncALibName = TypeName;
str_stdname = "Default standard library";
}
else if (in_stdtypeid >= 1000 && in_stdtypeid < 10000)
{
//大于等于1000,并且小于10000时,使用系统数据库中夹杂物来分析
str_IncALibName = TypeName;
str_stdname = "User defined standard library";
}
else if (in_stdtypeid > 10000)
{
//大于10000时,使用用户标准库来分析夹杂物名称
str_IncALibName = TypeName;
str_stdname = "System standard library";
}
//获取数据后,需要对xraytable设置
OTSIncAReportGraph.Controls.Control_XRayTable control_XRayTable1 = new Control_XRayTable();
control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray, list_showelementinfo);
//颗粒国标信息
//control_XRayTable1.GBInfoStr = in_dparticle.GBContent;
control_XRayTable1.MaterialName = str_IncALibName;//杂夹物
control_XRayTable1.STDName = str_stdname;//标准库
control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
control_XRayTable1.Visible = true;
control_XRayTable1.Invalidate();
control_XRayTable1.Refresh();
ret_bp = control_XRayTable1.ExportXRayImage();
return ret_bp;
}
private string datatable_data(DataTable dt, int it, string str)
{
if (str == "Hardness")
{
return dt.Rows[it]["Hardness_detailed"].ToString();
}
else
if (str == "Area")
{
return Convert.ToDouble(dt.Rows[it][str]).ToString("#0.00");
}
else
if (str == "DMAX")
{
return Math.Round(Convert.ToDouble(dt.Rows[it][str]), 2).ToString();
}
else
{
return dt.Rows[it][str].ToString();
}
}
///
/// 传入DataTable,和行号,返回该Row行中,返回6个靠前的元素,不足6个返回空
///
///
///
///
private void GetMaxElementFromDataTable(DataTable in_dt, int row_index, out List out_list_elementname, out List out_list_elementvalue)
{
out_list_elementname = new List();
out_list_elementvalue = new List();
//分别排出元素名,元素值列表
List list_elementname = new List();
List list_elementvalue = new List();
string str_element = in_dt.Rows[row_index]["Element"].ToString();
//防止取出的元素信息为空
if (str_element != "")
{
string[] strcbo = str_element.Split(';');
for (int i = 0; i < strcbo.Length - 1; i++)
{
string[] str = strcbo[i].Split('-');
list_elementname.Add(str[0]);
list_elementvalue.Add(Math.Round(Convert.ToDouble(str[1]), 2));
}
}
//循环6次,得到最大的6个元素信息
for (int geti = 0; geti < 11; geti++)
{
double max_elementvalue = -1;
string max_elementname = " ";
int max_index = -1;
if (list_elementvalue.Count > 0)
{
for (int i = 0; i < list_elementvalue.Count; i++)
{
if (list_elementvalue[i] > max_elementvalue)
{
max_elementvalue = list_elementvalue[i];
max_elementname = list_elementname[i];
max_index = i;
}
}
//移除掉最大的元素
list_elementname.RemoveAt(max_index);
list_elementvalue.RemoveAt(max_index);
//将最大的元素添加到list中
if (max_elementvalue > 0)
{
out_list_elementname.Add(max_elementname);
out_list_elementvalue.Add(max_elementvalue);
}
else
{
out_list_elementname.Add(" ");
out_list_elementvalue.Add(0);
}
}
else
{
//如果元素数量已经不够,则添加空
out_list_elementname.Add(" ");
out_list_elementvalue.Add(0);
}
}
}
///
/// 参数归一化
///
/// 总数
/// 传参
///
private string ParameterNormalization(double a_mi, double m)
{
double ColVal = Convert.ToDouble(m / a_mi * 100);
if (ColVal == 0)
{
return "";
}
else
{
if (m == 0)
return "0";
else
return Math.Round(ColVal, 2).ToString();
}
}
private DataTable FrameGraphParticleTableDatat(DataTable dt_ParticlesGridDevidePage, ParticleData fielddata, DataTable DT_field_dt, c_TemplateClass m_mbszclass, OTSReport_Export m_otsreport_export)
{
//将颗粒大小排序(从大到小)
DataView dv = dt_ParticlesGridDevidePage.DefaultView;
dv.Sort = m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1.ToString() + " DESC";
DataTable dt = dv.ToTable();
//表名Largest_frame表:(子表) 显示20条颗粒除外的部份颗粒信息
DataTable FrameGraphSubTable = new DataTable();
FrameGraphSubTable.TableName = "FrameGraphSubTable";
FrameGraphSubTable.Columns.Add("pid");
FrameGraphSubTable.Columns.Add("Size");
FrameGraphSubTable.Columns.Add("Width");
FrameGraphSubTable.Columns.Add("DMAX");
FrameGraphSubTable.Columns.Add("DMIN");
FrameGraphSubTable.Columns.Add("Class");
FrameGraphSubTable.Columns.Add("ColName1");
FrameGraphSubTable.Columns.Add("ColName2");
FrameGraphSubTable.Columns.Add("ColName3");
FrameGraphSubTable.Columns.Add("ColName4");
FrameGraphSubTable.Columns.Add("ColName5");
FrameGraphSubTable.Columns.Add("ColName6");
FrameGraphSubTable.Columns.Add("ColName7");
FrameGraphSubTable.Columns.Add("ColName8");
FrameGraphSubTable.Columns.Add("ColName9");
FrameGraphSubTable.Columns.Add("ColName10");
FrameGraphSubTable.Columns.Add("ColVal1");
FrameGraphSubTable.Columns.Add("ColVal2");
FrameGraphSubTable.Columns.Add("ColVal3");
FrameGraphSubTable.Columns.Add("ColVal4");
FrameGraphSubTable.Columns.Add("ColVal5");
FrameGraphSubTable.Columns.Add("ColVal6");
FrameGraphSubTable.Columns.Add("ColVal7");
FrameGraphSubTable.Columns.Add("ColVal8");
FrameGraphSubTable.Columns.Add("ColVal9");
FrameGraphSubTable.Columns.Add("ColVal10");
FrameGraphSubTable.Columns.Add("pic", typeof(Bitmap));
FrameGraphSubTable.Columns.Add("FieldId", typeof(int));
for (int i_row = 0; i_row < dt.Rows.Count; i_row++)
{
if (dt.Rows[i_row]["element"].ToString() == "")
continue;
if (dt.Rows[i_row]["TypeName"].ToString() == "Not Identified")
continue;
string str_fieldid = dt.Rows[i_row]["fieldid"].ToString();
if (JudgeWhetherItExists(Convert.ToInt32(str_fieldid), DT_field_dt, "id"))
{
//获取原始颗粒图像
Bitmap bp_particle = new Bitmap(1, 1);
Bitmap bp_field = new Bitmap(1, 1);
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"]) };
for (int i = 0; i < DT_field_dt.Rows.Count; i++)
{
if (dt.Rows[i_row]["FieldId"].ToString() == DT_field_dt.Rows[i]["id"].ToString())
{
bp_field = new Bitmap(DT_field_dt.Rows[i]["fieldFullName"].ToString());
}
}
bp_particle = fielddata.GetBitmapByParticle(bp_field, rectangle);
bp_particle.Tag = new List() { dt.Rows[i_row]["FieldId"].ToString(), dt.Rows[i_row]["ParticleId"].ToString(), dt.Rows[i_row]["TypeId"].ToString() };
DataRow dr = FrameGraphSubTable.NewRow();
dr["pic"] = bp_particle;
//帧图列表列第一个字段的可选参数
dr["pid"] = datatable_data(dt, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1);
//帧图列表列第二个字段的可选参数
dr["Size"] = datatable_data(dt, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p2);
dr["Width"] = dt.Rows[i_row]["rectwidth"].ToString();
dr["DMAX"] = Math.Round(Convert.ToDouble(dt.Rows[i_row]["dmax"]), 2).ToString();
dr["DMIN"] = Math.Round(Convert.ToDouble(dt.Rows[i_row]["dmin"]), 2).ToString();
dr["Class"] = dt.Rows[i_row]["typename"].ToString();
dr["fieldid"] = str_fieldid;
GetMaxElementFromDataTable(dt, i_row, out List list_max_elementname, out List list_max_elementvale);
double colVal = 0;
for (int i = 0; i < list_max_elementvale.Count; i++)
{
colVal = colVal + Convert.ToDouble(list_max_elementvale[i]);
}
//元素1
dr["ColName1"] = list_max_elementname[0];
dr["ColVal1"] = ParameterNormalization(colVal, list_max_elementvale[0]);
//元素2
dr["ColName2"] = list_max_elementname[1];
dr["ColVal2"] = ParameterNormalization(colVal, list_max_elementvale[1]);
//元素3
dr["ColName3"] = list_max_elementname[2];
dr["ColVal3"] = ParameterNormalization(colVal, list_max_elementvale[2]);
//元素4
dr["ColName4"] = list_max_elementname[3];
dr["ColVal4"] = ParameterNormalization(colVal, list_max_elementvale[3]);
//元素5
dr["ColName5"] = list_max_elementname[4];
dr["ColVal5"] = ParameterNormalization(colVal, list_max_elementvale[4]);
//元素6
dr["ColName6"] = list_max_elementname[5];
dr["ColVal6"] = ParameterNormalization(colVal, list_max_elementvale[5]);
//元素6
dr["ColName7"] = list_max_elementname[6];
dr["ColVal7"] = ParameterNormalization(colVal, list_max_elementvale[6]);
//元素6
dr["ColName8"] = list_max_elementname[7];
dr["ColVal8"] = ParameterNormalization(colVal, list_max_elementvale[7]);
//元素6
dr["ColName9"] = list_max_elementname[8];
dr["ColVal9"] = ParameterNormalization(colVal, list_max_elementvale[8]);
//元素6
dr["ColName10"] = list_max_elementname[9];
dr["ColVal10"] = ParameterNormalization(colVal, list_max_elementvale[9]);
FrameGraphSubTable.Rows.Add(dr);
}
}
return FrameGraphSubTable;
}
private bool JudgeWhetherItExists(int id, DataTable dt, string column)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (id == Convert.ToInt32(dt.Rows[i][column].ToString()))
return true;
}
return false;
}
}
}