using DevExpress.DataAccess.Sql;
using DevExpress.Office.Utils;
using DevExpress.PivotGrid.OLAP.SchemaEntities;
using DevExpress.XtraDiagram.Bars;
using DevExpress.XtraTreeList.Data;
using NPOI.Util;
using Org.BouncyCastle.Crypto;
using OTSCommon.DBOperate;
using OTSCommon.DBOperate.Model;
using OTSIncAReportApp._1_UI.Control_Graph.Controls;
using OTSIncAReportApp._3_ServiceCenter.DataOperation.DataAccess;
using OTSIncAReportApp.DataOperation.DataAccess;
using OTSIncAReportApp.OTSRstMgrFunction;
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 System.Windows.Forms;
using System.Windows.Media;
using static NPOI.HSSF.Util.HSSFColor;
using static OTSDataType.otsdataconst;
using static OTSIncAReportApp.OTSReport_Export;
namespace OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration
{
///
/// 颗粒列表
///
class ParticleList
{
ParticleData fielddata;
FieldImage imgAcc;
///
/// DEV颗粒列表颗粒前20个谱图排序
///
///
///
public List Get_dev_kllb_data(c_TemplateClass m_mbszclass, OTSReport_Export m_otsreport_export, BasicData basicData, out List a_FilteredData)
{
// 优化要点:
// - 缓存频繁访问的属性到局部变量
// - 用 HashSet/Dictionary 减少重复查找
// - 将重复创建的对象移出循环
// - 修复原有循环/索引错误
// - 保持原有输出结构与行为
// basic path & helpers
string str_resultPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[
m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()]
.FilePath;
fielddata = new ParticleData(str_resultPath);
imgAcc = new FieldImage(str_resultPath);
List OutDt = new List();
a_FilteredData = new List();
List datas = basicData.GetMeasurements() ?? new List();
DataTable SpliceMeasurements = basicData.GetSpliceMeasurements();
DataTable spliceAll = basicData.ObtainInformationOnSplicedParticles(m_otsreport_export);
// resolve result file (same logic as original)
ResultFile result;
string sou = m_otsreport_export.m_ReportApp.m_conditionChoose.m_CurrentConditions[
OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE]
.itemDisplayVal.ToString();
if (sou.Contains("+"))
{
MessageBox.Show("This function does not support multiple samples!");
result = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[0];
}
else
{
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)
];
}
ParticlesGridDevidePage particlesGridDevide = new ParticlesGridDevidePage(m_otsreport_export.m_ReportApp);
particlesGridDevide.fldImgAccess = new FieldImage(result.FilePath);
particlesGridDevide.Particledata = new ParticleData(result.FilePath);
// prepare maps for splice lookups to avoid repeated loops
HashSet spliceSubSet = new HashSet(StringComparer.OrdinalIgnoreCase);
if (spliceAll != null)
{
foreach (DataRow r in spliceAll.Rows)
{
var sub = r["SubParticles"]?.ToString();
if (!string.IsNullOrWhiteSpace(sub)) spliceSubSet.Add(sub);
}
}
// map splice measurements by key "FieldId_XrayId"
var spliceMeasurementsMap = new Dictionary>(StringComparer.OrdinalIgnoreCase);
if (SpliceMeasurements != null)
{
foreach (DataRow r in SpliceMeasurements.Rows)
{
var key = r["FieldId"] + "_" + r["XrayId"];
if (!spliceMeasurementsMap.TryGetValue(key, out var list))
{
list = new List();
spliceMeasurementsMap[key] = list;
}
list.Add(r);
}
}
// cache deletion set (serial)
var deleteSerialSet = new HashSet(m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial ?? new List(), StringComparer.OrdinalIgnoreCase);
ImageProcessor imageProcessor = new ImageProcessor();
for (int i = 0; i < datas.Count; i++)
{
int serialNumber = 1;
DataTable current = datas[i];
if (current == null) continue;
// 如果是 TCCleannessA,需要添加 Hardness 列并尝试从标准库读取硬度数据
bool needHardness = m_otsreport_export.m_ReportApp.m_RptConfigFile.Systype == OTS_SysType_ID.TCCleannessA;
if (needHardness)
{
if (!current.Columns.Contains("Hardness")) current.Columns.Add("Hardness", typeof(double));
if (!current.Columns.Contains("Hardness_detailed")) current.Columns.Add("Hardness_detailed");
// 将 STL 数据应用到表(若可用)
DataTable dt_stl;
if (GetSTL(basicData.GetResfile(), out dt_stl, m_otsreport_export) && dt_stl != null)
{
// 建立字典:TypeId(string) -> row for快速匹配
var stlDict = new Dictionary(StringComparer.OrdinalIgnoreCase);
foreach (DataRow r in dt_stl.Rows)
{
var key = r["TypeId"]?.ToString();
if (!string.IsNullOrEmpty(key)) stlDict[key] = r;
}
for (int r = 0; r < current.Rows.Count; r++)
{
var typeName = current.Rows[r]["TypeName"]?.ToString();
if (!string.IsNullOrEmpty(typeName) && stlDict.TryGetValue(typeName, out var drStl))
{
double hard = 0;
try { hard = Convert.ToDouble(drStl["Hardness"]); } catch { hard = 0; }
current.Rows[r]["Hardness"] = hard;
current.Rows[r]["Hardness_detailed"] = drStl["Hardness_detailed"];
}
}
}
}
#region 夹杂物筛选(按序号删除)
for (int b = current.Rows.Count - 1; b >= 0; b--)
{
var typeId = current.Rows[b]["TypeId"]?.ToString();
if (!string.IsNullOrEmpty(typeId) && deleteSerialSet.Contains(typeId))
{
current.Rows.RemoveAt(b);
}
}
#endregion
#region 排序并生成 p1Data_b
DataTable table = current.Copy();
DataView dvs = table.DefaultView;
dvs.Sort = m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1 + " DESC";
DataTable p1Data_b = dvs.ToTable();
#endregion
// 增加元素列,原逻辑使用 fielddata.AddElementColumn
DataTable p1Data = fielddata.AddElementColumn(p1Data_b, m_mbszclass, spliceAll);
#region 创建要插入数据库表结构
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));
DT_Largest20.Columns.Add("GroupName");
#endregion
// 插入颗粒部份
DataTable FilteredData = p1Data.Clone();
for (int i_row = 0; i_row < p1Data.Rows.Count; i_row++)
{
var row = p1Data.Rows[i_row];
// 快速判空和排除
var elementStr = row["Element"]?.ToString();
var typeName = row["TypeName"]?.ToString();
if (string.IsNullOrWhiteSpace(elementStr)) continue;
if (string.Equals(typeName, "Not Identified", StringComparison.OrdinalIgnoreCase)) continue;
var subParticles = row["SubParticles"]?.ToString() ?? "";
var fieldid = row["fieldid"]?.ToString();
if (string.IsNullOrWhiteSpace(fieldid) || fieldid == "-1") continue;
// 超出要显示数量则跳出
if (serialNumber > m_mbszclass.M_KLLBXX.list_int_kllb_number) break;
// 判断是否为拼接
bool isSplice = !string.IsNullOrEmpty(subParticles) && spliceSubSet.Contains(subParticles);
// 准备表行副本,用于取 Tag 等
DataTable table1 = p1Data.Clone();
table1.ImportRow(row);
Bitmap bp_particle = null;
Bitmap BP = null;
Bitmap ls_xraybpnew = null;
if (!isSplice)
{
// 原图 & 二值图 & 能谱
bp_particle = imgAcc.GetBitmapByParticleForUncombinedParticle(table1);
bp_particle = imageProcessor.ResizeImageWithPadding(bp_particle, 120, 120, System.Drawing.Color.White);
bp_particle.Tag = new List() { row["FieldId"].ToString(), row["ParticleId"].ToString(), row["TypeId"].ToString() };
// 能谱图
ls_xraybpnew = null;
try
{
System.Drawing.Bitmap bp_xraybp = ExportXRayBitmap(row["fieldid"].ToString(), row["particleid"].ToString(),
Convert.ToInt32(row["TypeId"]), row["TypeName"].ToString(), fielddata);
if (bp_xraybp != null) ls_xraybpnew = OTSIncAReportGraph.Class.DrawFunction.KiResizeImage(bp_xraybp, 700, 115);
}
catch { ls_xraybpnew = null; }
// 二次放大黑白图(Binary)
try
{
DataTable SegmentData = fielddata.GetSegment();
Bitmap BinaryParticles = ImageSplicer.ParticleBinaryDiagram(SegmentData, Convert.ToInt32(fieldid), Convert.ToInt32(row["particleid"]));
BP = imageProcessor.ResizeImageWithPadding(BinaryParticles, 120, 120, System.Drawing.Color.White);
}
catch { BP = new Bitmap(1, 1); }
}
else
{
// 组合拼接:收集子颗粒的 SpliceMeasurements 行
List strFieldId = new List();
List strXrayId = new List();
string[] fruits = subParticles.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var f in fruits)
{
var parts = f.Split(':');
if (parts.Length >= 2)
{
strFieldId.Add(parts[0]);
strXrayId.Add(parts[1]);
}
}
DataTable SpliceData = p1Data.Clone();
for (int splice = 0; splice < strFieldId.Count; splice++)
{
var key = strFieldId[splice] + "_" + strXrayId[splice];
if (spliceMeasurementsMap.TryGetValue(key, out var drs))
{
foreach (var dr in drs) SpliceData.ImportRow(dr);
}
}
// 原图(拼接)
double pix = particlesGridDevide.result.GetPixelSize();
int bitHeight = particlesGridDevide.result.GetImageHeight();
int bitWidth = particlesGridDevide.result.GetImageWidth();
try
{
Bitmap original = particlesGridDevide.fldImgAccess.GetBitmapForParticleAll(subParticles, SpliceData, pix, bitHeight, bitWidth);
bp_particle = OTSIncAReportGraph.Class.DrawFunction.KiResizeImage(original, 120, 120);
}
catch { bp_particle = new Bitmap(1, 1); }
// 黑白图
try
{
var segsData = new Dictionary>();
foreach (DataRow dow in SpliceData.Rows)
{
int fldid = Convert.ToInt32(dow["fieldid"]);
int partid = Convert.ToInt32(dow["particleId"]);
var listseg = particlesGridDevide.Particledata.GetSegmentData(fldid, partid);
string key = dow["fieldid"].ToString() + "_" + dow["particleid"].ToString();
segsData[key] = listseg;
}
Bitmap black = particlesGridDevide.fldImgAccess.GetBitmapForParticleAllWithBlackAndWhite(subParticles, SpliceData, segsData, pix, bitHeight, bitWidth);
BP = OTSIncAReportGraph.Class.DrawFunction.KiResizeImage(black, 120, 120);
}
catch { BP = new Bitmap(1, 1); }
// 谱图(拼接)
try
{
Bitmap xraybpnew = splice_ExportXRayBitmap(subParticles, Convert.ToInt32(row["particleId"]), Convert.ToInt32(row["fieldid"]), particlesGridDevide.Particledata, row["TypeName"].ToString());
ls_xraybpnew = OTSIncAReportGraph.Class.DrawFunction.KiResizeImage(xraybpnew, 700, 115);
}
catch { ls_xraybpnew = null; }
}
// 填充 DT_Largest20 行
DataRow drOut = DT_Largest20.NewRow();
drOut["p1"] = bp_particle;
drOut["p2"] = BP;
drOut["p3"] = ls_xraybpnew;
drOut["pid"] = serialNumber++.ToString();
drOut["Size"] = datatable_data(p1Data, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1);
drOut["Width"] = p1Data.Rows[i_row]["rectwidth"].ToString();
drOut["DMAX"] = datatable_data(p1Data, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p2);
drOut["DMIN"] = datatable_data(p1Data, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p3);
drOut["Class"] = p1Data.Rows[i_row]["typename"].ToString();
drOut["GroupName"] = p1Data.Rows[i_row]["GroupName"].ToString();
// 元素 top N
GetMaxElementFromDataTable(p1Data, i_row, out List list_max_elementname, out List list_max_elementvale);
double colVal = list_max_elementvale.Sum();
// 填充 10 个元素名和值(不足用空/0 补齐)
for (int e = 0; e < 10; e++)
{
string nameCol = "ColName" + (e + 1);
string valCol = "ColVal" + (e + 1);
if (e < list_max_elementname.Count)
{
drOut[nameCol] = list_max_elementname[e];
drOut[valCol] = ParameterNormalization(colVal, list_max_elementvale[e]);
}
else
{
drOut[nameCol] = " ";
drOut[valCol] = "";
}
}
DT_Largest20.Rows.Add(drOut);
FilteredData.Rows.Add(p1Data.Rows[i_row].ItemArray);
}
OutDt.Add(DT_Largest20);
a_FilteredData.Add(FilteredData);
}
return OutDt;
}
///
/// 颗粒列表帧图
///
///
///
///
///
public void Get_dev_kllb_data_frame_pic(c_TemplateClass m_mbszclass, out DataTable file_pic, out List list_dt, OTSReport_Export m_otsreport_export, List a_FrameData)
{
//去除拼接后的颗粒
List FrameData = new List();
for (int i = 0; i < a_FrameData.Count; i++)
{
DataTable DT = a_FrameData[i].Clone();
for (int a = 0; a < a_FrameData[i].Rows.Count; a++)
{
if (a_FrameData[i].Rows[a]["SubParticles"].ToString() == "")
{
DT.Rows.Add(a_FrameData[i].Rows[a].ItemArray);
}
}
FrameData.Add(DT);
}
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.GetWorkingResultId()].FilePath);
string str_resultPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath;
file_pic =new DataTable();
file_pic.Clear();
file_pic.Columns.Add("fieldid");
file_pic.Columns.Add("id");
file_pic.Columns.Add("fieldName");
file_pic.Columns.Add("cunt", typeof(int));
file_pic.Columns.Add("fieldFullName");
file_pic.Columns.Add("Field_pic", typeof(Bitmap));
list_dt = new List();
for (int i = 0; i < FrameData.Count; i++)
{
DataTable pic = new DataTable();
List picDt = new List();
m_otsreport_export.m_ReportApp.im_ParticlesGridDevidePage.Out_MarkParticleRectangleOnFieldFile(str_resultPath, FrameData[i], out List vs, out DataTable data);
DataTable data_A = FrameGraphParticleTableDatat(FrameData[i], fielddata, data, m_mbszclass, m_otsreport_export);
for (int a = 0; a < data.Rows.Count; a++)
{
DataTable dataTable = data_A.Clone();
//在数据表中有颗粒在该帧图中的话,则对该帧图标记图像进行读取存入数据库
DataRow[] datarowlist = data_A.Select(data.Rows[a]["fieldid"].ToString());
if (datarowlist.Count() > 0)
{
for (int b = 0; b < data_A.Rows.Count; b++)
{
if (data.Rows[a]["id"].ToString() == data_A.Rows[b]["FieldId"].ToString())
{
dataTable.Rows.Add(data_A.Rows[b].ItemArray);
dataTable.TableName = data_A.Rows[b]["FieldId"].ToString();
}
}
list_dt.Add(dataTable);
file_pic.Rows.Add(data.Rows[a].ItemArray);
}
}
}
}
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.DBOperate.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.DBOperate.SqLiteHelper("data source='" + fullPath + "'");
}
else if (System.IO.File.Exists(fullPath2))
{
sh = new OTSCommon.DBOperate.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() != "")
{
try
{
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]", ""));
}
}
catch
{
dr["Hardness"] = 0;
}
}
else
{
dr["Hardness"] = 0;
}
dt.Rows.Add(dr);
}
data = dt;
return true;
}
///
/// 输入颗粒的所在帧图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[] 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);
}
}
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(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;
}
///
/// 输入颗粒的所在帧图id,颗粒id,颗粒类型id,获取对应的XRay能谱数据图
///
///
private Bitmap splice_ExportXRayBitmap(string subParticleString,int a_particleId,int a_fieldid, ParticleData particleData,string a_TyoeName)
{
Bitmap ret_bp;
//显示xray相关信息
uint[] Analysis_xray = new uint[2000];
List list_celementchemistryclr = new List();
//获取Xray数据
Particle list = particleData.GetXrayByParticleIDAndFieldID(subParticleString, a_particleId, a_fieldid, out Analysis_xray);
List list_showelementinfo = particleData.GetShowElementInfos(list.ElementList);
//获取数据后,需要对xraytable设置
OTSIncAReportGraph.Controls.Control_XRayTable control_XRayTable1 = new Control_XRayTable();
control_XRayTable1.SetXRayShowLineValue(Analysis_xray, list_showelementinfo);
control_XRayTable1.MaterialName = a_TyoeName;
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
if (str == "ECD")
{
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)
{
DataTable dt;
string str_resultPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath;
imgAcc = new FieldImage(str_resultPath);
if (m_otsreport_export.m_ReportApp.m_RptConfigFile.Systype != OTS_SysType_ID.IncA)
{
if (dt_ParticlesGridDevidePage.Columns.Contains("Hardness"))
dt_ParticlesGridDevidePage.Columns.Remove("Hardness");
if (dt_ParticlesGridDevidePage.Columns.Contains("Hardness_detailed"))
dt_ParticlesGridDevidePage.Columns.Remove("Hardness_detailed");
//将颗粒大小排序(从大到小)
DataView dvs = dt_ParticlesGridDevidePage.DefaultView;
dvs.Sort = m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1.ToString() + " DESC";
dt = dvs.ToTable();
dt.Columns.Add("Hardness");
dt.Columns.Add("Hardness_detailed");
}
else
{
//将颗粒大小排序(从大到小)
DataView dvs = dt_ParticlesGridDevidePage.DefaultView;
dvs.Sort = m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1.ToString() + " DESC";
dt = dvs.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));
FrameGraphSubTable.Columns.Add("GroupName");
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);
DataTable table1 = dt.Clone();
table1.ImportRow(dt.Rows[i_row]);
bp_particle = imgAcc.GetBitmapByParticleForUncombinedParticle(table1);
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["GroupName"] = dt.Rows[i_row]["GroupName"].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;
}
}
}