Browse Source

同步TIN copy/past 功能

jiangjy 1 month ago
parent
commit
2400acee7b

+ 8 - 1
Furnace/FurnaceUI/Common/RecipeTableSelect.cs

@@ -7,8 +7,11 @@ namespace FurnaceUI.Common
 {
     public static class RecipeTableSelect
     {
+        public static RecipeTable CopyTable = null;
+
         public static bool ShowDialog(RecipeDataBase recipeData,string recipeType)
         {
+
             var windowManager = IoC.Get<IWindowManager>();
             RecipeTableSelectDialogViewModel recipeTableSelectDialogView = new RecipeTableSelectDialogViewModel();
             recipeTableSelectDialogView.Recipe = recipeData;
@@ -21,9 +24,11 @@ namespace FurnaceUI.Common
             var windowManager = IoC.Get<IWindowManager>();
             RecipeTableSelectDialogViewModel recipeTableSelectDialogView = new RecipeTableSelectDialogViewModel();
             recipeTableSelectDialogView.Recipe = recipeData;
+            recipeTableSelectDialogView.CopyTable = CopyTable;
             recipeTableSelectDialogView.IsAlarmRecipe = recipeType.ToLower() == "alarm";
             if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipeTableSelectDialogView, null, "Select Table"))
             {
+                CopyTable = recipeTableSelectDialogView.CopyTable;
                 return recipeTableSelectDialogView.SelectedIndex;
             }
             return -1;
@@ -42,8 +47,10 @@ namespace FurnaceUI.Common
             RecipeTableSelectDialogViewModel recipeTableSelectDialogView = new RecipeTableSelectDialogViewModel();
             recipeTableSelectDialogView.Recipe = recipeData;
             recipeTableSelectDialogView.IsEditEnable = isEditEnable;
-            if((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipeTableSelectDialogView, null, "Select Table"))
+            recipeTableSelectDialogView.CopyTable = CopyTable;
+            if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipeTableSelectDialogView, null, "Select Table"))
             {
+                CopyTable = recipeTableSelectDialogView.CopyTable;
                 return $"{recipeData.TableIndex}:{recipeData.TableName}";
             }
             return null;

+ 173 - 37
Furnace/FurnaceUI/Views/Recipes/RecipeTableSelectDialogViewModel.cs

@@ -3,13 +3,19 @@ using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
 using OpenSEMI.ClientBase;
 using System.Windows;
 using System.Linq;
-using MECF.Framework.Common.Utilities;
+using MECF.Framework.Common.CommonData;
+using System.Collections.ObjectModel;
+using System;
+using System.Collections.Generic;
+using Mapster;
 
 namespace FurnaceUI.Views.Recipes
 {
     public class RecipeTableSelectDialogViewModel : FurnaceUIViewModelBase
     {
-        private RecipeTable _copyTable;
+        public List<TableEdit> Tables { get; set; } = new List<TableEdit>();
+        private TableEdit _copyTable;
+        public RecipeTable CopyTable { get; set; }
 
         public RecipeDataBase Recipe { get; set; }
 
@@ -21,17 +27,33 @@ namespace FurnaceUI.Views.Recipes
             {
                 _SelectedIndex = value;
                 this.NotifyOfPropertyChange(nameof(SelectedIndex));
-                this.NotifyOfPropertyChange(nameof(SelectedTable));
             }
         }
 
-        public RecipeTable SelectedTable => (Recipe.Tables.Count > SelectedIndex && SelectedIndex >= 0) ? Recipe.Tables[SelectedIndex] : null;
+        public TableEdit SelectedTable => (Tables.Count > SelectedIndex && SelectedIndex >= 0) ? Tables[SelectedIndex] : null;
 
         public bool IsEditEnable { get; set; } = true;
         public bool IsAlarmRecipe { get; set; }
 
         protected override void OnInitialize()
         {
+            for (int i = 0; i < Recipe.Tables.Count; i++)
+            {
+                var table = Recipe.Tables[i];
+                if (table != null)
+                {
+                    Tables.Add(new TableEdit
+                    {
+                        TableIndex = table.Index,//从1开始
+                        Name = table.Name,
+                        Steps = new ObservableCollection<Tuple<int, string>>(table.TableData.Steps.Select(r => Tuple.Create(r.StepNo, r.Name))),
+                        EndStatus = table.EndStatus,
+                        From = "origin",
+                        UpdateTime = DateTime.MinValue
+                    });
+                }
+                else Tables.Add(new TableEdit { TableIndex = i + 1 });
+            }
             base.OnInitialize();
             SelectedIndex = Recipe.TableIndex - 1;
         }
@@ -48,18 +70,29 @@ namespace FurnaceUI.Views.Recipes
                 return;
             if (_copyTable != null)
             {
-                var table = Recipe.Tables[SelectedIndex];
+                var table = Tables[SelectedIndex];
                 table.Name = _copyTable.Name;
                 table.EndStatus = _copyTable.EndStatus;
-                table.TableData = (RecipeDataBase)CloneUtil.CloneObject(_copyTable.TableData);
-                int index = 1;
-                foreach (var item in table.TableData.Steps)
+                table.Steps.Clear();
+                foreach (var step in _copyTable.Steps)
                 {
-                    item.StepNo = index;
-                    index++;
+                    table.Steps.Add(step);
+                }
+                table.From = _copyTable.From == "origin" ? _copyTable.TableIndex.ToString() : _copyTable.From;
+                table.UpdateTime = DateTime.Now;
+            }
+            else
+            {
+                if (CopyTable != null)
+                {
+                    var table = Tables[SelectedIndex];
+                    table.Name = CopyTable.Name;
+                    table.EndStatus = CopyTable.EndStatus;
+                    table.Steps = new ObservableCollection<Tuple<int, string>>(CopyTable.TableData.Steps.Select(r => Tuple.Create(r.StepNo, r.Name)));
+                    table.From = "copy";
+                    table.UpdateTime = DateTime.Now;
                 }
             }
-
         }
         public void Clear()
         {
@@ -72,23 +105,28 @@ namespace FurnaceUI.Views.Recipes
                 return;
             // SelectedTable.Name = "";
             SelectedTable.EndStatus = "";
-            if (SelectedTable.TableData.Steps.Count > 0)
+
+            if (SelectedTable.Steps.Count > 0)
             {
                 if (SelectedIndex == 0)
                 {
-                    if (SelectedTable.TableData.Steps.Count < 2)
+                    if (SelectedTable.Steps.Count < 2)
+
                     {
                         DialogBox.ShowInfo("Table1 have one step at least");
                         return;
                     }
-                    var step = SelectedTable.TableData.Steps.First();
+
+                    var step = SelectedTable.Steps.First();
                     if (step != null)
                     {
-                        SelectedTable.TableData.Steps.Clear();
-                        SelectedTable.TableData.Steps.Add(step);
+                        SelectedTable.Steps.Clear();
+                        SelectedTable.Steps.Add(step);
                     }
                 }
-                else SelectedTable.TableData.Steps.Clear();
+                else SelectedTable.Steps.Clear();
+                SelectedTable.From = "clear";
+                SelectedTable.UpdateTime = DateTime.Now;
             }
         }
 
@@ -104,37 +142,94 @@ namespace FurnaceUI.Views.Recipes
 
         public void SaveCmd()
         {
-            if (SelectedIndex < 0)
-            {
-                Recipe.TableIndex = -1;
-                Recipe.Steps = null;
-            }
-            else
+            //判断名称是否重复
+            for (int i = 0; i < Tables.Count; i++)
             {
-                //table名不能重复
-                for (int i = 0; i < Recipe.Tables.Count; i++)
+                if (Tables[i]?.Steps?.Count > 0)
                 {
-                    if (Recipe.Tables[i].TableData?.Steps?.Count > 0)
+                    var tablename = Tables[i].Name.Trim();
+                    for (int j = i + 1; j < Tables.Count; j++)
                     {
-                        var tablename = Recipe.Tables[i].Name.Trim();
-                        for (int j = i + 1; j < Recipe.Tables.Count; j++)
+                        if (Tables[j]?.Steps?.Count > 0)
                         {
-                            if (Recipe.Tables[j].TableData?.Steps?.Count > 0)
+                            if (tablename == Tables[j].Name.Trim())
                             {
-                                if (tablename == Recipe.Tables[j].Name.Trim())
-                                {
-                                    DialogBox.ShowError($"Table{i + 1} and Table{j + 1} couldn't have same table name [{tablename}]");
-                                    return;
-                                }
+                                DialogBox.ShowError($"Table{i + 1} and Table{j + 1} couldn't have same table name [{tablename}]");
+                                return;
                             }
                         }
                     }
                 }
-                Recipe.TableIndex = SelectedTable.Index;
+            }
+
+            #region 实际处理recipe
+            var copytables = Tables.OrderBy(r => r.UpdateTime);
+            foreach (var table in copytables)
+            {
+                Recipe.Tables[table.TableIndex - 1].Name = table.Name;
+                Recipe.Tables[table.TableIndex - 1].EndStatus = table.EndStatus;
+                if (table.From == "origin") continue;
+                if (table.From == "clear")
+                {
+                    if (table.Steps?.Count > 0)//复制第一步可能是1步
+                    {
+                        var step = Recipe.Tables[0].TableData.Steps.FirstOrDefault();
+                        Recipe.Tables[table.TableIndex - 1].TableData.Steps?.Clear();
+                        if (step != null)
+                        {
+                            if (Recipe.Tables[table.TableIndex - 1].TableData.Steps == null)
+                                Recipe.Tables[table.TableIndex - 1].TableData.Steps = new ObservableCollection<Step> { step };
+                            else Recipe.Tables[table.TableIndex - 1].TableData.Steps.Add(step);
+                        }
+                    }
+                    else
+                    {
+                        Recipe.Tables[table.TableIndex - 1].TableData.Steps.Clear();
+                    }
+                }
+                else if (table.From == "copy")
+                {
+                    if (CopyTable != null)
+                    {
+                        Recipe.Tables[table.TableIndex - 1].TableData.Steps.Clear();
+                        foreach (var item in CopyTable.TableData.Steps)
+                        {
+                            Recipe.Tables[table.TableIndex - 1].TableData.Steps.Add(item.Adapt<Step>());
+                        }
+                    }
+                }
+                else if (int.TryParse(table.From, out int no))
+                {
+                    if (no > 0)
+                    {
+                        Recipe.Tables[table.TableIndex - 1].TableData.Steps.Clear();
+                        foreach (var item in Recipe.Tables[no - 1].TableData.Steps)
+                        {
+                            Recipe.Tables[table.TableIndex - 1].TableData.Steps.Add(item.Adapt<Step>());
+                        }
+                    }
+                }
+            }
+            #endregion
+
+            #region 2025.8.30 工艺要求实现不同recipe的table 复制
+            if (_copyTable != null && _copyTable.TableIndex > 0)
+            {
+                CopyTable = Recipe.Tables[_copyTable.TableIndex - 1].Adapt<RecipeTable>();
+            }
+            #endregion
+            if (SelectedIndex < 0)
+            {
+                Recipe.TableIndex = -1;
+                Recipe.Steps = null;
+            }
+            else
+            {
+                Recipe.TableIndex = SelectedTable.TableIndex;
                 Recipe.Steps.Clear();
-                SelectedTable.TableData.Steps.ToList().ForEach(x =>
+                Recipe.Tables[SelectedIndex].TableData.Steps.ToList().ForEach(x =>
                 {
-                    var tempStep = (Step)CloneUtil.CloneObject(x);
+                    var tempStep = Recipe.Tables[SelectedIndex].TableData.CreateStep(x);
                     tempStep.StepNo = x.StepNo;
                     Recipe.Steps.Add(tempStep);
                 });
@@ -142,4 +237,45 @@ namespace FurnaceUI.Views.Recipes
             ((Window)GetView()).DialogResult = true;
         }
     }
+    public class TableEdit : NotifyPropertyBase
+    {
+        public int TableIndex { get; set; }
+
+        private string _name;
+
+        public string Name
+        {
+            get { return _name; }
+            set
+            {
+                if (_name != value)
+                {
+                    _name = value;
+                    RaisePropertyChanged();
+                }
+            }
+        }
+
+        public ObservableCollection<Tuple<int, string>> Steps { get; set; }
+
+        private string _endStatus;
+
+        public string EndStatus
+        {
+            get { return _endStatus; }
+            set
+            {
+                if (_endStatus != value)
+                {
+                    _endStatus = value;
+                    RaisePropertyChanged();
+                }
+            }
+        }
+        /// <summary>
+        /// 来自哪里
+        /// </summary>
+        public string From { get; set; }
+        public DateTime UpdateTime { get; set; }
+    }
 }