using DocumentFormat.OpenXml.Bibliography; using FurnaceUI.Models; using MECF.Framework.UI.Client.CenterViews.Editors.Recipe; using MECF.Framework.UI.Client.CenterViews.Editors.Sequence; using MECF.Framework.UI.Client.CenterViews.Parameter; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace FurnaceUI.Views.Editors { public class AlarmErrorCallRecipeViewModel : FurnaceUIViewModelBase { private ObservableCollection _steps = new ObservableCollection(); public ObservableCollection Steps { get { return _steps; } set { _steps = value; this.NotifyOfPropertyChange(nameof(Steps)); } } private ObservableCollection _selectItemTable = new ObservableCollection(); public ObservableCollection SelectItemTable { get { return _selectItemTable; } set { _selectItemTable = value; this.NotifyOfPropertyChange(nameof(SelectItemTable)); } } private string _selectItemName; public string SelectItemName { get { return _selectItemName; } set { _selectItemName = value; this.NotifyOfPropertyChange(nameof(SelectItemName)); } } private string _selectItemEndStatus; public string SelectItemEndStatus { get { return _selectItemEndStatus; } set { _selectItemEndStatus = value; this.NotifyOfPropertyChange(nameof(SelectItemEndStatus)); } } private Visibility _isAlarmVisibility; public Visibility IsAlarmVisibility { get { return _isAlarmVisibility; } set { _isAlarmVisibility = value; this.NotifyOfPropertyChange(nameof(IsAlarmVisibility)); } } private RecipeProvider _recipeProvider = new RecipeProvider(); public string ResultParameterStr { get; set; } private RecipeDataBase _CurrentRecipe = new RecipeDataBase(); public RecipeDataBase CurrentRecipe { get { return _CurrentRecipe; } set { _CurrentRecipe = value; this.NotifyOfPropertyChange(nameof(CurrentRecipe)); } } protected override void OnInitialize() { base.OnInitialize(); LoadData(); } private void LoadData() { CurrentRecipe.Clear(); var prefixPath = "Furnace\\alarm"; var recipes = _recipeProvider.GetXmlRecipeList(prefixPath); var firstFile = RecipeSequenceTreeBuilder.BuildFileNode(prefixPath, "", false, recipes)[0].Files.FirstOrDefault(); if (firstFile != null) { var recipeContent = _recipeProvider.LoadRecipe(prefixPath, firstFile.Name); CurrentRecipe.InitData(prefixPath, firstFile.Name, recipeContent, "PM1"); foreach (var item in CurrentRecipe.Tables) { var stepItem = new ParameterTable() { StepNo = item.Index, Name = item.Name, IsChecked = false, }; Steps.Add(stepItem); } if (ResultParameterStr != null) { var stepNo = ResultParameterStr.Split(':')[0]; var one = Steps.Where(a => a.StepNo.Equals(int.Parse(stepNo))).FirstOrDefault(); one.IsChecked = true; SelectItemName = one.Name; } else { var first = Steps.FirstOrDefault(); if (first != null) { first.IsChecked = true; SelectItemName = first.Name; ResultParameterStr = $"{first.StepNo}:{first.Name}"; } } } } public void SelectTable(object step) { if (step != null) { var step1 = step as ParameterTable; var SelectedStep = this.Steps.Where(x => x.StepNo == step1.StepNo).FirstOrDefault(); SelectedStep.IsChecked = true; SelectItemName = step1.Name; SelectItemTable = new ObservableCollection(); ResultParameterStr = $"{step1.StepNo}:{step1.Name}"; } } public void AlarmTableSelected(object step) { if (step != null) { var step1 = step as ParameterTable; var SelectedStep = this.Steps.Where(x => x.StepNo == step1.StepNo).FirstOrDefault(); SelectedStep.IsChecked = true; SelectItemName = step1.Name; SelectItemTable = new ObservableCollection(); ResultParameterStr = $"{step1.StepNo}:{step1.Name}"; } } public void CloseCommand() { ((Window)GetView()).DialogResult = false; } public void OKCommand() { ((Window)GetView()).DialogResult = true; } } }