From ff69308edbb6cd4de2cafed3ae49b624ce785c0f Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Tue, 21 Jul 2026 12:36:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B1=80=E9=83=A8=E5=9B=BE=E5=83=8F=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E5=AF=BC=E5=85=A5=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PLCSharpWpf/Models/GlobalModel.Recipes.cs | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/PLCSharpWpf/Models/GlobalModel.Recipes.cs b/PLCSharpWpf/Models/GlobalModel.Recipes.cs index 39d73fb..2a69ef0 100644 --- a/PLCSharpWpf/Models/GlobalModel.Recipes.cs +++ b/PLCSharpWpf/Models/GlobalModel.Recipes.cs @@ -256,10 +256,23 @@ namespace PLCSharp.Models RecipeID = v.RecipeID.ToString(), v.Name, v.Comment, + v.ControlName, v.SerializedVisionParams, v.SerializedVisionFlows }).ToList(); + // 局部图像(不含图像内容) + var visionFuncIds = _DatasContext.VisionFunctions.Where(v => v.RecipeID == recipeId).Select(v => v.ID).ToList(); + sheets["局部图像"] = _DatasContext.LocalImageDatas + .Where(l => visionFuncIds.Contains(l.FuncID)) + .Select(l => new + { + ID = l.ID.ToString(), + FuncID = l.FuncID.ToString(), + l.Name, + l.Comment + }).ToList(); + // 全局图像 sheets["全局图像"] = _DatasContext.ImageDatas .Where(i => i.RecipeID == recipeId) @@ -501,11 +514,35 @@ namespace PLCSharp.Models RecipeID = recipeId, Name = name, Comment = (string)row.Comment, + ControlName = (string)row.ControlName, SerializedVisionParams = (string)row.SerializedVisionParams, SerializedVisionFlows = (string)row.SerializedVisionFlows }); } + // 局部图像 + foreach (var row in MiniExcel.Query(dialog.FileName, sheetName: "局部图像")) + { + var idStr = (string)row.ID; + if (string.IsNullOrWhiteSpace(idStr)) continue; + if (!Guid.TryParse(idStr, out var id)) continue; + if (_DatasContext.LocalImageDatas.Any(l => l.ID == id)) continue; + + var funcIdStr = (string)row.FuncID; + if (string.IsNullOrWhiteSpace(funcIdStr)) continue; + if (!Guid.TryParse(funcIdStr, out var funcId)) continue; + // 对应的 VisionFunction 不存在时跳过,避免孤儿数据 + if (!_DatasContext.VisionFunctions.Any(v => v.ID == funcId)) continue; + + _DatasContext.LocalImageDatas.Add(new LocalImageData + { + ID = id, + FuncID = funcId, + Name = (string)row.Name, + Comment = (string)row.Comment + }); + } + // 全局图像 foreach (var row in MiniExcel.Query(dialog.FileName, sheetName: "全局图像")) {