using FurnaceUI.Models; using MECF.Framework.UI.Client.CenterViews.Editors.Recipe; using OpenSEMI.ClientBase; using System.Windows; using System.Linq; using MECF.Framework.Common.Utilities; namespace FurnaceUI.Views.Recipes { public class RecipeTableSelectDialogViewModel : FurnaceUIViewModelBase { private RecipeTable _copyTable; public RecipeDataBase Recipe { get; set; } private int _SelectedIndex; public int SelectedIndex { get { return _SelectedIndex; } set { _SelectedIndex = value; this.NotifyOfPropertyChange(nameof(SelectedIndex)); this.NotifyOfPropertyChange(nameof(SelectedTable)); } } public RecipeTable SelectedTable => (Recipe.Tables.Count > SelectedIndex && SelectedIndex >= 0) ? Recipe.Tables[SelectedIndex] : null; public bool IsEditEnable { get; set; } = true; public bool IsAlarmRecipe { get; set; } protected override void OnInitialize() { 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 = Recipe.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) { item.StepNo = index; index++; } } } public void Clear() { if (!DialogBox.Confirm("Clear this table?")) return; // SelectedTable.Name = ""; SelectedTable.EndStatus = ""; if (SelectedTable.TableData.Steps.Count > 1) { while (SelectedTable.TableData.Steps.Count > 1) { SelectedTable.TableData.Steps.RemoveAt(1); } } else { SelectedTable.TableData = new RecipeDataBase(); } } public void NotSelect() { SelectedIndex = -1; } public void CancelCmd() { ((Window)GetView()).DialogResult = false; } public void SaveCmd() { if (SelectedIndex < 0) { Recipe.TableIndex = -1; Recipe.Steps = null; } else { Recipe.TableIndex = SelectedTable.Index; Recipe.Steps.Clear(); SelectedTable.TableData.Steps.ToList().ForEach(x => { var tempStep = (Step)CloneUtil.CloneObject(x); tempStep.StepNo = x.StepNo; Recipe.Steps.Add(tempStep); }); } ((Window)GetView()).DialogResult = true; } } }