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 (SelectedIndex < 0) { DialogBox.ShowWarning("No table is selected"); return; } if (!DialogBox.Confirm("Clear this table?")) return; // SelectedTable.Name = ""; SelectedTable.EndStatus = ""; if (SelectedTable.TableData.Steps.Count > 0) { if (SelectedIndex == 0) { if (SelectedTable.TableData.Steps.Count < 2) { DialogBox.ShowInfo("Table1 have one step at least"); return; } var step = SelectedTable.TableData.Steps.First(); if (step != null) { SelectedTable.TableData.Steps.Clear(); SelectedTable.TableData.Steps.Add(step); } } else SelectedTable.TableData.Steps.Clear(); } } 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 { //table名不能重复 for (int i = 0; i < Recipe.Tables.Count; i++) { if (Recipe.Tables[i].TableData?.Steps?.Count > 0) { var tablename = Recipe.Tables[i].Name.Trim(); for (int j = i + 1; j < Recipe.Tables.Count; j++) { if (Recipe.Tables[j].TableData?.Steps?.Count > 0) { if (tablename == Recipe.Tables[j].Name.Trim()) { DialogBox.ShowError($"Table{i + 1} and Table{j + 1} couldn't have same table name [{tablename}]"); return; } } } } } 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; } } }