using Caliburn.Micro; using Caliburn.Micro.Core; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.RecipeCenter; using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig; using MECF.Framework.UI.Client.CenterViews.Editors.Recipe; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using FurnaceUI.Models; using FurnaceUI.Views.Recipes; using RecipeEditorLib.RecipeModel.Params; namespace FurnaceUI.Views.Editors { public class RecipeStandbySettingViewModel : FurnaceUIViewModelBase { private Step _standbyStep = new Step(); public Step StandbyStep { get => _standbyStep; set { _standbyStep = value; NotifyOfPropertyChange(nameof(StandbyStep)); } } private string _selectedStepName = "Standby"; public string SelectedStepName { get { return _selectedStepName; } set { _selectedStepName = value; NotifyOfPropertyChange("SelectedStepName"); } } private string _selectedTempSetting1; public string SelectedTempSetting1 { get { return _selectedTempSetting1; } set { _selectedTempSetting1 = value; NotifyOfPropertyChange("SelectedTempSetting1"); } } private string _selectedTempSetting2; public string SelectedTempSetting2 { get { return _selectedTempSetting2; } set { _selectedTempSetting2 = value; NotifyOfPropertyChange("SelectedTempSetting2"); } } private string _selectedTempSetting3; public string SelectedTempSetting3 { get { return _selectedTempSetting3; } set { _selectedTempSetting3 = value; NotifyOfPropertyChange("SelectedTempSetting3"); } } private string _selectedTempSetting4; public string SelectedTempSetting4 { get { return _selectedTempSetting4; } set { _selectedTempSetting4 = value; NotifyOfPropertyChange("SelectedTempSetting4"); } } private string _selectedTempSetting5; public string SelectedTempSetting5 { get { return _selectedTempSetting5; } set { _selectedTempSetting5 = value; NotifyOfPropertyChange("SelectedTempSetting5"); } } private string _selectedTempSettingValue1; public string SelectedTempSettingValue1 { get { return _selectedTempSettingValue1; } set { _selectedTempSettingValue1 = value; NotifyOfPropertyChange("SelectedTempSettingValue1"); } } private string _selectedTempSettingValue2; public string SelectedTempSettingValue2 { get { return _selectedTempSettingValue2; } set { _selectedTempSettingValue2 = value; NotifyOfPropertyChange("SelectedTempSettingValue2"); } } private string _selectedTempSettingValue3; public string SelectedTempSettingValue3 { get { return _selectedTempSettingValue3; } set { _selectedTempSettingValue3 = value; NotifyOfPropertyChange("SelectedTempSettingValue3"); } } private string _selectedTempSettingValue4; public string SelectedTempSettingValue4 { get { return _selectedTempSettingValue4; } set { _selectedTempSettingValue4 = value; NotifyOfPropertyChange("SelectedTempSettingValue4"); } } private string _selectedTempSettingValue5; public string SelectedTempSettingValue5 { get { return _selectedTempSettingValue5; } set { _selectedTempSettingValue5 = value; NotifyOfPropertyChange("SelectedTempSettingValue5"); } } private string _selectedGasSetting1; public string SelectedGasSetting1 { get { return _selectedGasSetting1; } set { _selectedGasSetting1 = value; NotifyOfPropertyChange("SelectedGasSetting1"); } } private string _selectedGasSetting2; public string SelectedGasSetting2 { get { return _selectedGasSetting2; } set { _selectedGasSetting2 = value; NotifyOfPropertyChange("SelectedGasSetting2"); } } private string _selectedGasSetting3; public string SelectedGasSetting3 { get { return _selectedGasSetting3; } set { _selectedGasSetting3 = value; NotifyOfPropertyChange("SelectedGasSetting3"); } } private string _selectedGasSetting4; public string SelectedGasSetting4 { get { return _selectedGasSetting4; } set { _selectedGasSetting4 = value; NotifyOfPropertyChange("SelectedGasSetting4"); } } private string _selectedGasSetting5; public string SelectedGasSetting5 { get { return _selectedGasSetting5; } set { _selectedGasSetting5 = value; NotifyOfPropertyChange("SelectedGasSetting5"); } } private string _selectedGasSetting6; public string SelectedGasSetting6 { get { return _selectedGasSetting6; } set { _selectedGasSetting6 = value; NotifyOfPropertyChange("SelectedGasSetting6"); } } public Dictionary TemperatureValues { get; set; } public ObservableCollection HeadLst { get; set; } public Dictionary> RecipeTemplate { get; set; } public RecipeDataBase CurrentRecipe { get; set; } private Step _selectedRecipeStep; public Step SelectedRecipeStep { get => _selectedRecipeStep; set { if (value != null) { _selectedRecipeStep = value; NotifyOfPropertyChange("SelectedRecipeStep"); } else { _selectedRecipeStep = null; NotifyOfPropertyChange("SelectedRecipeStep"); } } } //private ObservableCollection _mFCDatas = new ObservableCollection(); //public ObservableCollection MFCDataList //{ // get => _mFCDatas; // set // { // _mFCDatas = value; // NotifyOfPropertyChange("MFCDataList"); // } //} public List ConfigNodes { get; private set; } RecipeTempSetViewModel recipeTempSetViewModel = null; public string RecipeType { get; set; } public RecipeStandbySettingViewModel() { } protected override void OnInitialize() { base.OnInitialize(); LoadData(); } private void LoadData() { Step step = StandbyStep; if (step.MFCSets != null && step.MFCSets.Count > 0) { //int index2 = 0; StringBuilder stringBuilder = new StringBuilder(); var MfcItems = this.GetMfcItem(); int mfcIndex = 0; foreach (var item in MfcItems) { var isInstalled = QueryDataClient.Instance.Service.GetConfig($"PM1.MFC.{item.Name}.IsMFCInstalled"); //var key = step.MFCSets.Keys.ToList()[mfcIndex]; mfcIndex++; if (!(bool)isInstalled) continue; //MFCDataList.Add(new MFCData() //{ // SetValueParam = step.MFCSets[key.ToString()].SetValueParam, // Name = SystemConfigProvider.Instance.GetValueByName($"PM1.MFC.{item.Name}.GasName"), // // Unit = SystemConfigProvider.Instance.GetValueByName($"PM1.MFC.{item.Name}.FlowUnit"), //}); } } } public void RecipeEdit(object cmdName, object value) { var windowManager = IoC.Get(); switch ((string)cmdName) { case "StepTime": RecipeStepTimeViewModel recipeStepTimeViewModel = new RecipeStepTimeViewModel("StepTime"); recipeStepTimeViewModel.SelectTime = StandbyStep.Time; (windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepTimeViewModel, null, "Standby Time Setting"); if (recipeStepTimeViewModel.IsSave) { StandbyStep.Time = recipeStepTimeViewModel.SelectTime; if (recipeStepTimeViewModel.SelectTime == "Value") { SelectedRecipeStep.Time = recipeStepTimeViewModel.SelectTime + ":" + recipeStepTimeViewModel.SelectValueTime; StandbyStep.Time = recipeStepTimeViewModel.SelectValueTime; } else { SelectedRecipeStep.Time = recipeStepTimeViewModel.SelectTime + ":" + recipeStepTimeViewModel.RecipeStepTime[recipeStepTimeViewModel.SelectTime]; } } break; case "AlarmAction": RecipeAlarmActionViewModel recipeAlarmActionViewModel = new RecipeAlarmActionViewModel { CurrentRecipe = CurrentRecipe, CurrentStepName = SelectedRecipeStep.Name, TableIndex = StandbyStep.AlarmConditionTable.Value, AlarmActions = StandbyStep.AlarmActionSets }; if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipeAlarmActionViewModel, null, "Standby Alarm Action")) { StandbyStep.AlarmConditionTable.Value = recipeAlarmActionViewModel.TableIndex; StandbyStep.AlarmActionSets = recipeAlarmActionViewModel.AlarmActions; } break; case "TempSetting": if (recipeTempSetViewModel is null) { recipeTempSetViewModel = new RecipeTempSetViewModel { RecipeTemplate = RecipeTemplate }; } var tempSets = StandbyStep; recipeTempSetViewModel.TemperatureValues = tempSets.TemperatureSets; recipeTempSetViewModel.StepType = SelectedStepName; recipeTempSetViewModel.RecipeType = RecipeType; if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipeTempSetViewModel, null, "Standby Temperature Setting")) { if (recipeTempSetViewModel.TemperatureValues != null && recipeTempSetViewModel.TemperatureValues.Count > 0 && recipeTempSetViewModel.IsSave) { StringBuilder tempStr = new StringBuilder(); List temperatureValue = new List(); List tempLis = new List(); string strTemperatureValue = "", strTemperatureName = ""; int index = 0; } } break; case "GASSetting": RecipeGASSettingViewModel recipeGASSettingViewModel = new RecipeGASSettingViewModel(); var tempValveSets = StandbyStep.ValveSets; if (tempValveSets != null && tempValveSets.Count > 0) { recipeGASSettingViewModel.ValveSets= StandbyStep.ValveSets; } recipeGASSettingViewModel.MFCSets = StandbyStep.MFCSets; var tempMFMSets = StandbyStep.MFMSets; if (tempMFMSets != null && tempMFMSets.Count > 0) { foreach (var item in tempMFMSets.Keys) { if (recipeGASSettingViewModel.MFMSets.ContainsKey(item)) { recipeGASSettingViewModel.MFMSets[item] = tempMFMSets[item]; } else { recipeGASSettingViewModel.MFMSets.Add(item, tempMFMSets[item]); } } } var tempEXOU = StandbyStep.EXOUSets; if (tempEXOU != null && tempEXOU.Count > 0) { foreach (var item in tempEXOU.Keys) { var keyName = $"EXOU{item.Substring(12)}"; if (recipeGASSettingViewModel.ExternalOutSets.ContainsKey(keyName)) { recipeGASSettingViewModel.ExternalOutSets[keyName] = tempEXOU[item]; } else { recipeGASSettingViewModel.ExternalOutSets.Add(keyName, tempEXOU[item]); } } } recipeGASSettingViewModel.RecipeTemplate = RecipeTemplate; recipeGASSettingViewModel.RecipeType = RecipeType; if (!(bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipeGASSettingViewModel, null, "Standby Gas Setting")) return; if (StandbyStep.MFMSets != null) { if (recipeGASSettingViewModel.MFMSets != null) { StandbyStep.MFMSets = recipeGASSettingViewModel.MFMSets; } } if (StandbyStep.ValveSets != null) { if (recipeGASSettingViewModel.ValveSets != null && recipeGASSettingViewModel.ValveSets.Count > 0) { var step = StandbyStep; step.ValveSets = recipeGASSettingViewModel.ValveSets; } } if (StandbyStep.MFCSets != null) { if (recipeGASSettingViewModel.MFCSets != null && recipeGASSettingViewModel.MFCSets.Count > 0) { var step = StandbyStep; var MfcItems = this.GetMfcItem(); int mfcIndex = 0; foreach (var item in MfcItems) { var isInstalled = QueryDataClient.Instance.Service.GetConfig($"PM1.MFC.{item.Name}.IsMFCInstalled"); //var key = StandbyStep.MFCSets.Keys.ToList()[mfcIndex]; mfcIndex++; if (!(bool)isInstalled) continue; //MFCDataList.Add(new MFCData() //{ // SetValueParam =StandbyStep.MFCSets[key.ToString()].SetValueParam, // Name = SystemConfigProvider.Instance.GetValueByName($"PM1.MFC.{item.Name}.GasName"), // Unit = SystemConfigProvider.Instance.GetValueByName($"PM1.MFC.{item.Name}.FlowUnit"), //}); } } } if (StandbyStep.EXOUSets != null) { if (recipeGASSettingViewModel.ExternalOutSets != null && recipeGASSettingViewModel.ExternalOutSets.Count > 0) { var step = StandbyStep; foreach (var item in recipeGASSettingViewModel.ExternalOutSets.Keys) { var key = $"External.Out{ item.Substring(4)}"; if (step.EXOUSets.ContainsKey(key)) { step.EXOUSets[key] = recipeGASSettingViewModel.ExternalOutSets[item]; } else { step.EXOUSets.Add(key, recipeGASSettingViewModel.ExternalOutSets[item]); } } } } break; case "PressureSetting": RecipePressureSettingViewModel recipePressureSettingViewModel = new RecipePressureSettingViewModel(); var tempStep = StandbyStep; //recipePressureSettingViewModel.PressureSonsorValue = tempStep.PressureSonserValue; //recipePressureSettingViewModel.PressureValveAngleValue = tempStep.PressureValveAngle; //if (!string.IsNullOrEmpty(tempStep.PressureAlarmTableNo)) //{ // if (tempStep.PressureAlarmTableNo.ToLower() == "none") // recipePressureSettingViewModel.PressureAlarmWatchTable = "None"; // else // recipePressureSettingViewModel.PressureAlarmWatchTable = tempStep.PressureAlarmTableNo; //} //if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipePressureSettingViewModel, null, "Standby Pressure Setting")) //{ // if (StandbyStep != null) // { // StandbyStep.PressureSonserValue = recipePressureSettingViewModel.PressureSonsorValue; // StandbyStep.PressureValveAngle = recipePressureSettingViewModel.PressureValveAngleValue; // StandbyStep.PressureAlarmTableNo = recipePressureSettingViewModel.PressureAlarmWatchTable; // SelectedRecipeStep.PressureSonserValue = $"{recipePressureSettingViewModel.PressureSonsorValue}"; // } //} break; } } public List GetMfcItem() { this.SystemName = "System"; ConfigNodes = SystemConfigProvider.Instance.GetConfigTree(SystemName).SubNodes; var MfcItems = ConfigNodes.Where(x => x.Display == "Parameter").FirstOrDefault().SubNodes.Where(y => y.Name == "MFC").FirstOrDefault().SubNodes; return MfcItems; } public void RecipeSave() { ((Window)GetView()).DialogResult = true; } public void RecipeCancel() { ((Window)GetView()).DialogResult = false; } } }