| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 | using FurnaceUI.Models;using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;using OpenSEMI.ClientBase;using System.Windows;using System.Linq;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    {        public List<TableEdit> Tables { get; set; } = new List<TableEdit>();        private TableEdit _copyTable;        public RecipeTable CopyTable { get; set; }        public RecipeDataBase Recipe { get; set; }        private int _SelectedIndex;        public int SelectedIndex        {            get { return _SelectedIndex; }            set            {                _SelectedIndex = value;                this.NotifyOfPropertyChange(nameof(SelectedIndex));            }        }        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;        }        public void Copy()        {            if (!DialogBox.Confirm("Copy this table?"))                return;            _copyTable = SelectedTable;        }        public void Paste()        {            if (!DialogBox.Confirm("Paste the copied table?"))                return;            if (_copyTable != null)            {                var table = Tables[SelectedIndex];                if (table == _copyTable) return;                table.Name = _copyTable.Name;                table.EndStatus = _copyTable.EndStatus;                table.Steps.Clear();                foreach (var step in _copyTable.Steps)                {                    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()        {            if (SelectedIndex < 0)            {                DialogBox.ShowWarning("No table is selected");                return;            }            if (!DialogBox.Confirm("Clear this table?"))                return;            // SelectedTable.Name = "";            SelectedTable.EndStatus = "";            if (SelectedTable.Steps.Count > 0)            {                if (SelectedIndex == 0)                {                    if (SelectedTable.Steps.Count < 2)                    {                        DialogBox.ShowInfo("Table1 have one step at least");                        return;                    }                    var step = SelectedTable.Steps.First();                    if (step != null)                    {                        SelectedTable.Steps.Clear();                        SelectedTable.Steps.Add(step);                    }                }                else SelectedTable.Steps.Clear();                SelectedTable.From = "clear";                SelectedTable.UpdateTime = DateTime.Now;            }        }        public void NotSelect()        {            SelectedIndex = -1;        }        public void CancelCmd()        {            ((Window)GetView()).DialogResult = false;        }        public void SaveCmd()        {            //判断名称是否重复            for (int i = 0; i < Tables.Count; i++)            {                if (Tables[i]?.Steps?.Count > 0)                {                    var tablename = Tables[i].Name.Trim();                    for (int j = i + 1; j < Tables.Count; j++)                    {                        if (Tables[j]?.Steps?.Count > 0)                        {                            if (tablename == Tables[j].Name.Trim())                            {                                DialogBox.ShowError($"Table{i + 1} and Table{j + 1} couldn't have same table name [{tablename}]");                                return;                            }                        }                    }                }            }            #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();                Recipe.Tables[SelectedIndex].TableData.Steps.ToList().ForEach(x =>                {                    var tempStep = Recipe.Tables[SelectedIndex].TableData.CreateStep(x);                    tempStep.StepNo = x.StepNo;                    Recipe.Steps.Add(tempStep);                });            }            ((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; }    }}
 |