瀏覽代碼

优化报告导出代码,优化速度

zhangjiaxin 1 周之前
父節點
當前提交
6c600767ae

+ 3 - 10
OTSIncAReportApp/1-UI/Control_Grids/CompositionDistributionGrid.cs

@@ -42,7 +42,6 @@ namespace OTSIncAReportGrids
         List<Point> list_table_size = new List<Point>();
         List<Point> list_table_Point = new List<Point>();
         List<string> list_fileName = new List<string>();
-        int DataNumber = 0; // current dataset index
 
         List<ComboBox> list_ComboBox = new List<ComboBox>();
         List<ChartControl> list_ChartControl = new List<ChartControl>();
@@ -430,7 +429,7 @@ namespace OTSIncAReportGrids
 
             for (int i = 0; i < list_table_data.Count; i++)
             {
-                DataNumber = i;
+              
 				Graphics(list_table_data[i], list_fileName[i], stdId_TYPE, list_table_size[i], list_table_Point[i], high);
             }
         }
@@ -513,7 +512,7 @@ namespace OTSIncAReportGrids
             list_table_size.Clear();
             list_table_Point.Clear();
             list_fileName.Clear();
-            int ii = 0;
+          
             string sou = m_condition.m_CurrentConditions[OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE].itemDisplayVal.ToString();
             if (sou.Contains("+"))
             {
@@ -522,10 +521,7 @@ namespace OTSIncAReportGrids
                     var resultFile = m_ReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == name);
                     if (resultFile != null)
                     {
-						DataNumber = ii;
 						BindDataGridView(resultFile.FilePath, list_fileName.Count, resultFile.anotherFileName);
-                        ii++;
-
 					}
                 }
             }
@@ -593,16 +589,13 @@ namespace OTSIncAReportGrids
             string sou = source.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
             if (sou.Contains("+"))
             {
-                int ii = 0;
+                
 				foreach (var name in sou.Split('+'))
                 {
                     var resultFile = m_ReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == name);
                     if (resultFile != null)
                     {
-						DataNumber = ii;
 						BindDataGridView(resultFile.FilePath, list_fileName.Count, resultFile.anotherFileName);
-                        ii++;
-
 					}
                 }
             }

+ 0 - 71
OTSIncAReportApp/1-UI/Control_Grids/ParticlesSizeGrid.cs

@@ -322,73 +322,6 @@ namespace OTSIncAReportGrids
         private Point SetDataGridViewStyle(OTSGridView gridView)
         {
 
-
-			//// user can't change header height
-			//gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
-
-			//// user can't change row height
-			//gridView.AllowUserToResizeRows = false;
-
-			//gridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
-
-			//var centeredStyle = new DataGridViewCellStyle
-			//{
-			//	Alignment = DataGridViewContentAlignment.MiddleCenter
-			//};
-			//gridView.DefaultCellStyle = centeredStyle;
-			//gridView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
-
-			//gridView.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
-
-			//gridView.Columns[0].Width = 40;
-			//gridView.Columns[1].Width = 200;
-
-			//gridView.Columns[0].Resizable = DataGridViewTriState.False;
-			//gridView.AllowUserToAddRows = false;
-			//gridView.AllowUserToDeleteRows = false;
-			//gridView.AllowUserToResizeRows = false;
-			//gridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
-			//gridView.RowHeadersVisible = false;
-			//gridView.RowHeadersWidth = 40;
-			//gridView.RowTemplate.Height = 30;
-
-			//int gridView_Width = 0;
-
-			//         for (int i = 0; i < gridView.ColumnCount; i++)
-			//         {
-			//             gridView_Width = gridView_Width + gridView.Columns[i].Width;
-
-			//         }
-
-			//         int gridViewHeight = 0;
-
-			//         for (int i = 0; i < gridView.Rows.Count; i++)
-			//         {
-			//             gridViewHeight = gridViewHeight + gridView.Rows[i].Height;
-
-			//         }
-
-			//         gridView.Size = new System.Drawing.Size(gridView_Width, gridViewHeight);
-
-			//         gridheight = gridheight + gridViewHeight;
-			//         gridwidth = gridwidth + gridView_Width+20;
-
-			//MessageBox.Show(((gridwidth - (gridView_Width + 20)).ToString())+":"+gridView_Width.ToString()+":"+gridViewHeight.ToString());
-
-			//gridView.TabIndex = 0;
-			//         //先设置一下头的高度,否则会太矮不好看
-			//         gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
-			//         gridView.ColumnHeadersHeight = 40;
-			//         gridView.Columns[4].Visible = false;
-			//list_table_size.Add(new Point(gridView_Width, (gridView.RowCount + 2) * 30));
-			//         int outpos = gridView.Location.X;
-			//         int a_height = gridheight - gridViewHeight;
-
-
-			//gridView.Location = new System.Drawing.Point(gridwidth- (gridView_Width + 20), 0);
-			//return new Point(gridwidth - (gridView_Width + 20), 0);
-
-
 			// user can't change header height
 			gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
 
@@ -558,10 +491,6 @@ namespace OTSIncAReportGrids
             chartControl1.Size = new Size(a_size.X, location_hig);
             chartControl1.Location = new Point(a_Location.X, location_hig + 20);
 
-			//MessageBox.Show(a_Location.X.ToString() + ":" + a_size.X.ToString() + ":" + location_hig.ToString());
-			//MessageBox.Show(chartControl1.Location.X.ToString() + ":" + chartControl1.Width.ToString() + ":" + chartControl1.Height.ToString());
-
-
 			DataTable dataTable = new DataTable();
 			dataTable.Columns.Add("name");
 			dataTable.Columns.Add("size");

文件差異過大導致無法顯示
+ 401 - 421
OTSIncAReportApp/1-UI/OTSReportExport/DataIntegration/BasicData.cs


+ 252 - 354
OTSIncAReportApp/1-UI/OTSReportExport/DataIntegration/ParticleList.cs

@@ -35,36 +35,44 @@ namespace OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration
     /// </summary>
     class ParticleList
     {
-        //string str_resultPath = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath;
+        
         ParticleData fielddata;
         FieldImage imgAcc;
 
 
-        //ResultFile result;
 		/// <summary>
 		/// DEV颗粒列表颗粒前20个谱图排序
 		/// </summary>
 		/// <param name="m_mbszclass"></param>
 		/// <returns></returns>
-		public List<DataTable> Get_dev_kllb_data(c_TemplateClass m_mbszclass, OTSReport_Export m_otsreport_export,BasicData basicData,out List<DataTable> a_FilteredData)
+		public List<DataTable> Get_dev_kllb_data(c_TemplateClass m_mbszclass, OTSReport_Export m_otsreport_export, BasicData basicData, out List<DataTable> a_FilteredData)
 		{
-			
-			//------------------加载模块,获取数据-------------------------------------------------
-			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<DataTable> OutDt = new List<DataTable>();
-            a_FilteredData = new List<DataTable>();
-
-			List<DataTable> datas = basicData.GetMeasurements();
-			DataTable SpliceMeasurements= basicData.GetSpliceMeasurements();
-
-			DataTable spliceAll = basicData.ObtainInformationOnSplicedParticles(m_otsreport_export);//拼接颗粒信息
+			// 优化要点:
+			// - 缓存频繁访问的属性到局部变量
+			// - 用 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<DataTable> OutDt = new List<DataTable>();
+			a_FilteredData = new List<DataTable>();
 
+			List<DataTable> datas = basicData.GetMeasurements() ?? new List<DataTable>();
+			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();
+			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!");
@@ -72,79 +80,107 @@ namespace OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration
 			}
 			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)];
+				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);
+			particlesGridDevide.fldImgAccess = new FieldImage(result.FilePath);
+			particlesGridDevide.Particledata = new ParticleData(result.FilePath);
 
+			// prepare maps for splice lookups to avoid repeated loops
+			HashSet<string> spliceSubSet = new HashSet<string>(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<string, List<DataRow>>(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<DataRow>();
+						spliceMeasurementsMap[key] = list;
+					}
+					list.Add(r);
+				}
+			}
+
+			// cache deletion set (serial)
+			var deleteSerialSet = new HashSet<string>(m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial ?? new List<string>(), StringComparer.OrdinalIgnoreCase);
+
+			ImageProcessor imageProcessor = new ImageProcessor();
 
 			for (int i = 0; i < datas.Count; i++)
-            {
+			{
 				int serialNumber = 1;
-				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*/)
+				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)
 				{
-					datas[i].Columns.Add("Hardness", typeof(double));
-					datas[i].Columns.Add("Hardness_detailed");
-					DataTable dt_stl = new DataTable();
-					if (GetSTL(basicData.GetResfile(), out dt_stl, m_otsreport_export))
+					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)
 					{
-						for (int a = 0; a < datas[a].Rows.Count; a++)
+						// 建立字典:TypeId(string) -> row for快速匹配
+						var stlDict = new Dictionary<string, DataRow>(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++)
 						{
-							for (int b = 0; b < dt_stl.Rows.Count; b++)
+							var typeName = current.Rows[r]["TypeName"]?.ToString();
+							if (!string.IsNullOrEmpty(typeName) && stlDict.TryGetValue(typeName, out var drStl))
 							{
-								if (datas[a].Rows[a]["TypeName"].ToString() == dt_stl.Rows[b]["TypeId"].ToString())
-								{
-									datas[a].Rows[a]["Hardness"] = Convert.ToDouble(dt_stl.Rows[b]["Hardness"]);
-									datas[a].Rows[a]["Hardness_detailed"] = dt_stl.Rows[b]["Hardness_detailed"];
-									break;
-								}
+								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 a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial.Count; a++)
-                {
-					for (int b = datas[i].Rows.Count - 1; b >= 0; b--)
+				#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))
 					{
-						if (m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial[a].ToString() == datas[i].Rows[b]["TypeId"].ToString())
-						{
-                            datas[i].Rows.RemoveAt(b);
-						}
+						current.Rows.RemoveAt(b);
 					}
 				}
+				#endregion
 
-
-                #endregion
-                #region 安装选择的类型大小排序
-                DataTable table = datas[i].Copy();
-      
-
-                DataView dvs = table.DefaultView;
-
-
-                dvs.Sort = m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1.ToString() + " DESC";
-				
-
-
-                    DataTable p1Data_b = dvs.ToTable();
+				#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_field_dt = new DataTable();
-				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");
@@ -173,274 +209,179 @@ namespace OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration
 				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();
 
-				DataTable p1Data = fielddata.AddElementColumn(p1Data_b, m_mbszclass, spliceAll);
+				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;
 
-				#region 插入颗粒部份
-				DataTable FilteredData = p1Data.Clone();
-				ImageProcessor imageProcessor = new ImageProcessor();
-                for (int i_row = 0; i_row < p1Data.Rows.Count; i_row++)
-                {
-                    if (p1Data.Rows[i_row]["Element"].ToString() != "")
-                    {
-						if (p1Data.Rows[i_row].ItemArray[24].ToString() != "Not Identified")
-						{
-							//获取颗粒的fieldid,和particleid
-							string str_fieldid = p1Data.Rows[i_row]["fieldid"].ToString();
-							string str_particleid = p1Data.Rows[i_row]["particleid"].ToString();
-							string str_typeid = p1Data.Rows[i_row]["TypeId"].ToString();
-							string str_typename = p1Data.Rows[i_row]["TypeName"].ToString();
-							string str_element = p1Data.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;
-                            DataTable table1=p1Data.Clone();
-                            table1.ImportRow(p1Data.Rows[i_row]);
-
-                            bool isSplice = false;
-							for (int b = 0; b < spliceAll.Rows.Count; b++)
-                            {
-                                if (spliceAll.Rows[b]["SubParticles"].ToString() == p1Data.Rows[i_row]["SubParticles"].ToString())
-                                {
-                                    isSplice = true;
-								}
-                            }
-
-                            //原图
-                            Bitmap bp_particle;
-							//二次放大图
-							Bitmap BP;
-							//获取该颗粒的xray能谱图像
-							Bitmap ls_xraybpnew;
-
-                            if (!isSplice)
-                            {
-                                //原图
-                                bp_particle = imgAcc.GetBitmapByParticleForUncombinedParticle(table1);
-                                bp_particle = imageProcessor.ResizeImageWithPadding(bp_particle, 120, 120, System.Drawing.Color.White);
-                                bp_particle.Tag = new List<string>() { p1Data.Rows[i_row]["FieldId"].ToString(), p1Data.Rows[i_row]["ParticleId"].ToString(), p1Data.Rows[i_row]["TypeId"].ToString() };
-                                MemoryStream newms_p1 = new MemoryStream();
-                                bp_particle.Save(newms_p1, System.Drawing.Imaging.ImageFormat.Bmp);
-
-
-                                //获取该颗粒的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);
-                                ls_xraybpnew = OTSIncAReportGraph.Class.DrawFunction.KiResizeImage(bp_xraybp, 700, 115);//能谱图处理																														   //能谱图
-                                MemoryStream newms_p3 = new MemoryStream();
-                                ls_xraybpnew.Save(newms_p3, System.Drawing.Imaging.ImageFormat.Bmp);
-
-
-
-                                DataTable SegmentData = fielddata.GetSegment();
-                                Bitmap BinaryParticles = ImageSplicer.ParticleBinaryDiagram(SegmentData, Convert.ToInt32(str_fieldid), Convert.ToInt32(str_particleid));
-                                BP = imageProcessor.ResizeImageWithPadding(BinaryParticles, 120, 120, System.Drawing.Color.White);
-                                //二次放大图
-                                MemoryStream newms_p2 = new MemoryStream();
-                                BP.Save(newms_p2, System.Drawing.Imaging.ImageFormat.Bmp);
-
-								newms_p1.Dispose();
-								newms_p2.Dispose();
-								newms_p3.Dispose();
-							}
-                            else 
-                            {
-                                List<string> strFieldId = new List<string>();
-								List<string> strXrayId = new List<string>();
-								string detailedLocation = p1Data.Rows[i_row]["SubParticles"].ToString();
-								string[] fruits = detailedLocation.Split(',');
-								for (int p2 = 0; p2 < fruits.Length; p2++)
-								{
-									string[] fruit = fruits[p2].Split(':');
-									strFieldId.Add(fruit[0]);
-									strXrayId.Add(fruit[1]);
-								}
-								DataTable SpliceData = p1Data.Clone();
-								for (int splice = 0; splice < SpliceMeasurements.Rows.Count; splice++)
-                                {
-                                    for (int splice2 = 0; splice2 < strFieldId.Count; splice2++)
-                                    {
-										if (SpliceMeasurements.Rows[splice]["FieldId"].ToString() == strFieldId[splice2] && SpliceMeasurements.Rows[splice]["XrayId"].ToString() == strXrayId[splice2])
-										{
-											SpliceData.Rows.Add(SpliceMeasurements.Rows[splice].ItemArray);
-										}
-									}
-
-                                    
-                                }
-
-								double pix = particlesGridDevide.result.GetPixelSize();
-								int bitHeight = particlesGridDevide.result.GetImageHeight();
-								int bitWidth = particlesGridDevide.result.GetImageWidth();
-
-
-								//原图
-								Bitmap original = particlesGridDevide.fldImgAccess.GetBitmapForParticleAll
-                                    (p1Data.Rows[i_row]["SubParticles"].ToString(), SpliceData, pix, bitHeight, bitWidth);
-								bp_particle= OTSIncAReportGraph.Class.DrawFunction.KiResizeImage(original, 120, 120);
-								//黑白图
-								Dictionary<string, List<Segment>> segsData = new Dictionary<string, List<Segment>>();
-								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.Add(key, listseg);
-								}
-								Bitmap black = particlesGridDevide.fldImgAccess.GetBitmapForParticleAllWithBlackAndWhite
-									(p1Data.Rows[i_row]["SubParticles"].ToString(), SpliceData, segsData, pix, bitHeight, bitWidth);
-								BP = OTSIncAReportGraph.Class.DrawFunction.KiResizeImage(black, 120, 120);
-
-								//谱图
-								Bitmap xraybpnew = splice_ExportXRayBitmap
-                                    (p1Data.Rows[i_row]["SubParticles"].ToString(), Convert.ToInt32(p1Data.Rows[i_row]["particleId"]), 
-                                    Convert.ToInt32(p1Data.Rows[i_row]["fieldid"]), particlesGridDevide.Particledata, p1Data.Rows[i_row]["TypeName"].ToString());
-								ls_xraybpnew = OTSIncAReportGraph.Class.DrawFunction.KiResizeImage(xraybpnew, 700, 115);//能谱图处理
-																														
+					// 超出要显示数量则跳出
+					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<string>() { 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<string> strFieldId = new List<string>();
+						List<string> strXrayId = new List<string>();
+						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]);
+							}
+						}
 
-                                //---------------------------------------------------------------------------------------                   
-                                DataRow dr = DT_Largest20.NewRow();
-							dr["p1"] = bp_particle;
-							dr["p2"] = BP;
-							dr["p3"] = ls_xraybpnew;
+						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();
 
-							
-							dr["pid"] = serialNumber++.ToString();
-							//颗粒列表列中第一个可选参数
-							dr["Size"] = datatable_data(p1Data, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p1);
-							//这个参数没有用
-							dr["Width"] = p1Data.Rows[i_row]["rectwidth"].ToString();
-							//颗粒列表列中第二个可选参数
-							dr["DMAX"] = datatable_data(p1Data, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p2);
-							//颗粒列表列中第三个可选参数
-							dr["DMIN"] = datatable_data(p1Data, i_row, m_mbszclass.M_KLLBXX.str_cb_kllb_sort_p3);
-							//颗粒列表列中显示分类不可以选择
-							dr["Class"] = p1Data.Rows[i_row]["typename"].ToString();
+						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); }
 
-							dr["GroupName"] = p1Data.Rows[i_row]["GroupName"].ToString();
-							GetMaxElementFromDataTable(p1Data, i_row, out List<string> list_max_elementname, out List<double> list_max_elementvale);
-							double colVal = 0;
-							for (int a = 0; a < list_max_elementvale.Count; a++)
+						// 黑白图
+						try
+						{
+							var segsData = new Dictionary<string, List<Segment>>();
+							foreach (DataRow dow in SpliceData.Rows)
 							{
-								colVal = colVal + Convert.ToDouble(list_max_elementvale[a]);
+								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;
 							}
-							//元素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);
-							FilteredData.Rows.Add(p1Data.Rows[i_row].ItemArray);
+							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<string> list_max_elementname, out List<double> 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);
 				}
-                #endregion
-                OutDt.Add(DT_Largest20);
-                a_FilteredData.Add(FilteredData);
+
+				OutDt.Add(DT_Largest20);
+				a_FilteredData.Add(FilteredData);
 			}
+
 			return OutDt;
 		}
 
-	
-		/// <summary>
-		/// 拼接颗粒
-		/// </summary>
-		public DataTable GetSplicingParticlesData(OTSReport_Export m_otsreport_export)
-        {
-            DataTable SplicingParticlesData = new DataTable();
-            SplicingParticlesData.Columns.Add("image",typeof(Bitmap));
-            SplicingParticlesData.Columns.Add("TypeName");
-			SplicingParticlesData.Columns.Add("Area");
-            SplicingParticlesData.Columns.Add("ECD");
-            SplicingParticlesData.Columns.Add("DiameterRatio");
-            SplicingParticlesData.Columns.Add("DPERP");
-
-            //根据sql条件,查询获取颗粒信息数据
-            ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath);
-			DataTable particles = fielddata.GetSplicingParticlesData();
-            if (particles.Rows.Count == 0)
-            {
-                return SplicingParticlesData;
-            }
-            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)];
-			}
-			ParticleData Particledata = new ParticleData(result.FilePath);
-			string filePath = result.FilePath + "\\FIELD_FILES\\";
-			for (int i = 0; i < particles.Rows.Count; i++)
-            {
-				DataTable table1 = particles.Clone();
-                table1.ImportRow(particles.Rows[i]);
-                Bitmap bmap = imgAcc.GetBitmapByParticleForUncombinedParticle(table1);
-				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() };
-                DataRow row = SplicingParticlesData.NewRow();
-                row["image"] = bmap;
-                row["TypeName"] = particles.Rows[i]["TypeName"];
-                row["Area"] = particles.Rows[i]["Area"];
-                row["ECD"] = (Convert.ToDouble(particles.Rows[i]["Area"]) / Math.PI) * 2;
-                row["DiameterRatio"] = Convert.ToDouble(particles.Rows[i]["DMAX"]) / Convert.ToDouble(particles.Rows[i]["DMIN"]);
-                row["DPERP"] = particles.Rows[i]["DPERP"];
-                SplicingParticlesData.Rows.Add(row);
-			}
-            return SplicingParticlesData;
 
-		}
 
 		/// <summary>
 		/// 颗粒列表帧图
@@ -507,27 +448,13 @@ namespace OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration
 							}
 						}
 
-                        //bool bl = false;
-                        //                  for (int j = 0; j < list_dt.Count; i++)
-                        //                  {
-                        //                      if (list_dt[j].TableName == dataTable.TableName)
-                        //                      {
-                        //                          bl = true;
-                        //                      }
-                        //                  }
-                        //                  if (!bl)
-                        //                  {
                         list_dt.Add(dataTable);
                         file_pic.Rows.Add(data.Rows[a].ItemArray);
-                        //}
-
+              
                     }
 				}
 			}
-            
-            
-
-
+           
 
 		}
 	
@@ -594,36 +521,7 @@ namespace OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration
             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;
-        }
+   
         /// <summary>
         /// 输入颗粒的所在帧图id,颗粒id,颗粒类型id,获取对应的XRay能谱数据图
         /// </summary>

部分文件因文件數量過多而無法顯示