using Aitex.Core.RT.SCCore; using Caliburn.Micro; using Caliburn.Micro.Core; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.OperationCenter; using MECF.Framework.Common.RecipeCenter; using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig; using MECF.Framework.UI.Client.CenterViews.Dialogs; using MECF.Framework.UI.Client.CenterViews.Editors.Recipe; using MECF.Framework.UI.Client.ClientBase; using OpenSEMI.ClientBase; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Text; using System.Windows; //using System.Windows.Forms; using System.Windows.Controls; using FurnaceUI.Client; using FurnaceUI.Models; using FurnaceUI.Views.Editors; using Aitex.Core.Util; using Aitex.Core.Common.DeviceData; using MECF.Framework.UI.Client.CenterViews.Parameter; using MECF.Framework.Common.ParameterCenter; using RecipeEditorLib.RecipeModel.Params; using SciChart.Charting.Common.Extensions; namespace FurnaceUI.Views.Parameter { public class TempCorrectionEditViewModel : FurnaceUIViewModelBase { private UIElement _parent; enum ShowPanel { Table, AutoSelect } public void SetParent(UIElement parent) { _parent = parent; } private readonly ParameterProvider _parameterProvider = new ParameterProvider(); private Dictionary> ParameterTemplate; public TempCorrectionParameterData CurrentParameter { get; set; } = new TempCorrectionParameterData(); private ParameterFormatBuilder _columnBuilder = new ParameterFormatBuilder(); private TempCorrectionTable _selectedParameterStep; public TempCorrectionTable SelectedParameterStep { get => _selectedParameterStep; set { if (value != null) { _selectedParameterStep = value; NotifyOfPropertyChange("SelectedParameterStep"); } else { _selectedParameterStep = null; NotifyOfPropertyChange("SelectedParameterStep"); } } } private int _IndexNoDefault = -1; public int IndexNoDefault { get { return _IndexNoDefault; } set { _IndexNoDefault = value; NotifyOfPropertyChange("IndexNoDefault"); } } private bool _appendStepItemIsEnabled; public bool AppendStepItemIsEnabled { get => _appendStepItemIsEnabled; set { _appendStepItemIsEnabled = value; NotifyOfPropertyChange("AppendStepItemIsEnabled"); } } private bool _overWriteCopyIsEnabled; public bool OverWriteCopyIsEnabled { get => _overWriteCopyIsEnabled; set { _overWriteCopyIsEnabled = value; NotifyOfPropertyChange("OverWriteCopyIsEnabled"); } } private bool _insertCopyIsEnabled; public bool InsertCopyIsEnabled { get => _insertCopyIsEnabled; set { _insertCopyIsEnabled = value; NotifyOfPropertyChange("InsertCopyIsEnabled"); } } private bool _prevStepOverwriteIsEnabled; public bool PrevStepOverwriteIsEnabled { get => _prevStepOverwriteIsEnabled; set { _prevStepOverwriteIsEnabled = value; NotifyOfPropertyChange("PrevStepOverwriteIsEnabled"); } } private bool _prevStepInsertIsEnabled; public bool PrevStepInsertIsEnabled { get => _prevStepInsertIsEnabled; set { _prevStepInsertIsEnabled = value; NotifyOfPropertyChange("PrevStepInsertIsEnabled"); } } private bool _prevStepItemIsEnabled; public bool PrevStepItemIsEnabled { get => _prevStepItemIsEnabled; set { _prevStepItemIsEnabled = value; NotifyOfPropertyChange("PrevStepItemIsEnabled"); } } private bool _currStepDeleteIsEnabled; public bool CurrStepDeleteIsEnabled { get => _currStepDeleteIsEnabled; set { _currStepDeleteIsEnabled = value; NotifyOfPropertyChange("CurrStepDeleteIsEnabled"); } } private bool _multStepsDeleteIsEnabled; public bool MultStepsDeleteIsEnabled { get => _multStepsDeleteIsEnabled; set { _multStepsDeleteIsEnabled = value; NotifyOfPropertyChange("MultStepsDeleteIsEnabled"); } } private bool _settingButtonEnable; public bool SettingButtonEnable { get => _settingButtonEnable; set { _settingButtonEnable = value; NotifyOfPropertyChange("SettingButtonEnable"); } } private string _eventSetting; public string EventSetting { get => _eventSetting; set { _eventSetting = value; NotifyOfPropertyChange("EventSetting"); } } private bool _isEnable; public bool IsEnable { get { return _isEnable; } set { _isEnable = value; this.NotifyOfPropertyChange(nameof(IsEnable)); } } public string EditRecipeStepName { get; set; } private RecipeDataBase _CurrentRecipe; public RecipeDataBase CurrentRecipe { get { return _CurrentRecipe; } set { _CurrentRecipe = value; this.NotifyOfPropertyChange(nameof(CurrentRecipe)); } } private bool _autoSelectIsEnabled = true; public bool AutoSelectIsEnabled { get => _autoSelectIsEnabled; set { _autoSelectIsEnabled = value; NotifyOfPropertyChange("AutoSelectIsEnabled"); } } private bool _cboAutoSelectChecked; public bool CboAutoSelectChecked { get => _cboAutoSelectChecked; set { _cboAutoSelectChecked = value; NotifyOfPropertyChange("CboAutoSelectChecked"); } } public string FullFileName { get; set; } public void SetCmdIsEnabled() { if (CurrentParameter.Steps == null || CurrentParameter.Steps.Count == 0) { SelectedParameterStep = null; AppendStepItemIsEnabled = true; OverWriteCopyIsEnabled = false; InsertCopyIsEnabled = false; PrevStepOverwriteIsEnabled = false; PrevStepInsertIsEnabled = false; PrevStepItemIsEnabled = false; CurrStepDeleteIsEnabled = false; MultStepsDeleteIsEnabled = false; SettingButtonEnable = false; } } public int SelectedStepNo { get; set; } private List _ConfigNodes = new List(); public List ConfigNodes { get { return _ConfigNodes; } set { _ConfigNodes = value; NotifyOfPropertyChange("ConfigNodes"); } } public string ParameterType { get; set; } private Visibility _autoSelectVisibility = Visibility.Hidden; public Visibility AutoSelectVisibility { get => _autoSelectVisibility; set { _autoSelectVisibility = value; NotifyOfPropertyChange("AutoSelectVisibility"); } } private Visibility _tableVisibility = Visibility.Visible; public Visibility TableVisibility { get => _tableVisibility; set { _tableVisibility = value; NotifyOfPropertyChange("TableVisibility"); } } private bool _isEnabledControl = true; public bool IsEnabledControl { get => _isEnabledControl; set { _isEnabledControl = value; NotifyOfPropertyChange("IsEnabledControl"); } } public TempCorrectionEditViewModel(string strPrefixPath, string strRecipeName, string permission = "") { _parameterProvider.GetParameterFormatXml(strPrefixPath); ParameterTemplate = _parameterProvider.GetGroupParameterTemplate(); _columnBuilder.Build(strPrefixPath); CurrentParameter.PrefixPath = strPrefixPath; CurrentParameter.Name = strRecipeName; CurrentParameter.Permission = permission; } public TempCorrectionEditViewModel() { _parameterProvider.GetParameterFormatXml($"Parameter\\TempCorrection"); ParameterTemplate = _parameterProvider.GetGroupParameterTemplate(); _columnBuilder.Build($"Parameter\\TempCorrection"); CurrentParameter.PrefixPath = $"Parameter\\TempCorrection"; } protected override void OnViewLoaded(object view) { base.OnViewLoaded(view); } protected override void OnActivate() { base.OnActivate(); } protected override void OnDeactivate(bool close) { base.OnDeactivate(close); InvokeClient.Instance.Service.DoOperation($"PM1.SetSensorPROCManualOK", ""); } protected override void OnInitialize() { base.OnInitialize(); // GetHeaderConfig(); LoadData(); LoadViewData(); SetCmdIsEnabled(); IsEnable = IsManualSet == true ? IsManualSet : CGlobal.RecipeProcessEditViewEnable; } public void SetValue(object sender, string isFullKeyboard = "") { string value = ((TextBox)sender).Text; if (!string.IsNullOrEmpty(isFullKeyboard)) { FullKeyboard fullKeyboard1 = new FullKeyboard("", value); if ((bool)fullKeyboard1.ShowDialog()) { ((TextBox)sender).Text = fullKeyboard1.ValueString; } } else { NumberKeyboard fullKeyboard = new NumberKeyboard("", value); if ((bool)fullKeyboard.ShowDialog()) { ((TextBox)sender).Text = fullKeyboard.ValueString; } } } private void LoadData() { if (CurrentRecipe != null) { CurrentParameter.PrefixPath = $"Parameter\\TempCorrection"; StringParam tempCorrection = CurrentRecipe.ConfigItems.FirstOrDefault(x => x.Name == "Combination.TempCorrection") as StringParam; if (tempCorrection != null && !string.IsNullOrEmpty(tempCorrection.Value)) { CurrentParameter.Name = tempCorrection.Value; CurrentParameter.Permission = ""; FullFileName = $"{CurrentParameter.PrefixPath}\\{CurrentParameter.Name}"; } else { DialogBox.ShowDialog(DialogButton.Cancel, DialogType.INFO, "Please set the Combination default Temp Correction file!"); return; } } if (string.IsNullOrEmpty(CurrentParameter.Name) && CurrentRecipe == null) { var defaultTempCorrectionFile = (string)QueryDataClient.Instance.Service.GetConfig("PM1.TempCorrection"); if (!string.IsNullOrEmpty(defaultTempCorrectionFile)) { CurrentParameter.Name = defaultTempCorrectionFile.Split('\\').LastOrDefault(); } } var recipeContent = _parameterProvider.LoadParameter(CurrentParameter.PrefixPath, CurrentParameter.Name); if (string.IsNullOrEmpty(recipeContent)) { System.Windows.MessageBox.Show($"{CurrentParameter.PrefixPath}\\{CurrentParameter.Name} is empty, please confirm the file is valid."); return; } CurrentParameter.TableNumber = _columnBuilder.TableNumber; CurrentParameter.ChamberType = _columnBuilder.ChamberType; CurrentParameter.InitData(CurrentParameter.PrefixPath, CurrentParameter.Name, recipeContent, ""); if (!IsEnabledControl) { AutoSelectVisibility = Visibility.Visible; if (string.IsNullOrEmpty(ResultString) || !ResultString.Contains(":")) { SetShowPanel(ShowPanel.AutoSelect); CboAutoSelectChecked = true; AutoSelectIsEnabled = false; } else { SetShowPanel(ShowPanel.Table); CboAutoSelectChecked = false; AutoSelectIsEnabled = true; var no = Convert.ToInt32(ResultString.Split(':')[0]); var selecttable = CurrentParameter.Steps.Where(x => x.StepNo == no).FirstOrDefault(); selecttable.IsChecked = true; SelectTable(selecttable); } } else { AutoSelectVisibility = Visibility.Hidden; SetShowPanel(ShowPanel.AutoSelect); CboAutoSelectChecked = true; AutoSelectIsEnabled = false; } } private void SetShowPanel(ShowPanel showPanel) { switch (showPanel) { case ShowPanel.Table: TableVisibility = Visibility.Visible; break; case ShowPanel.AutoSelect: TableVisibility = Visibility.Hidden; break; default: break; } } private void LoadViewData() { if (CurrentParameter.Steps != null && CurrentParameter.Steps.Count > 0 && SelectedParameterStep == null) { SelectedStepNo = CurrentParameter.Steps[0].StepNo; var step = CurrentParameter.Steps[0]; if (!string.IsNullOrEmpty(ResultString)) { var strList = ResultString.Split(','); var selecteNo = strList.Skip(1).Take(1).FirstOrDefault(); // var selectedName = strList.LastOrDefault(); if (selecteNo != null) { SelectedStepNo = int.Parse(selecteNo); step = CurrentParameter.Steps.Where(a => a.StepNo.Equals(SelectedStepNo)).FirstOrDefault(); //if (!string.IsNullOrEmpty(selectedName)) //{ // step.Name = selectedName; //} } } SelectTable(step); } } private void RecipeGasPanelSettingViewModel_ChangedStepEvent(Step step) { SelectTable(step); IndexNoDefault = step.StepNo - 1; } public void SelectTable(object step) { if (step != null && step is TempCorrectionTable step1) { var SelectedStep = this.CurrentParameter.Steps.Where(x => x.StepNo == step1.StepNo).FirstOrDefault(); SelectedStep.IsChecked = true; SelectedStepNo = step1.StepNo; string strName = step1.Name.Trim(); SelectedParameterStep = (TempCorrectionTable)SelectedStep; } SetShowPanel(ShowPanel.Table); SetCmdIsEnabled(); AutoSelectIsEnabled = true; CboAutoSelectChecked = false; } private void OverWriteStep() { var windowManager = IoC.Get(); if (CurrentParameter == null) return; } public void InsertPrevStep() { } public void InsertCopyStep() { var windowManager = IoC.Get(); if (CurrentParameter == null) return; } //撤销修改 public void RecipeIsChangeClick(object cmdName, object value) { var windowManager = IoC.Get(); } public void TempSetClick(object sender) { string stSetValue = ShowNumberKeyboard(sender as Button, ""); } public void RampSetClick(object sender) { string strSetRamp = ShowNumberKeyboard(sender as Button, ""); } private string ShowNumberKeyboard(Control control, string defaultValue) { NumberKeyboard numberKeyboard = new NumberKeyboard("", defaultValue); var point = control.PointFromScreen(new Point(0, 0)); double wx = SystemParameters.WorkArea.Width; double hy = SystemParameters.WorkArea.Height; if (-point.Y + control.ActualHeight + 5 + numberKeyboard.Height < hy) { numberKeyboard.Top = -point.Y + control.ActualHeight + 5; } else { numberKeyboard.Top = -point.Y - numberKeyboard.Height - 5; } if (-point.X + numberKeyboard.Width < wx) { numberKeyboard.Left = -point.X; } else { numberKeyboard.Left = -point.X - (numberKeyboard.Width - control.ActualWidth); } if ((bool)numberKeyboard.ShowDialog()) return numberKeyboard.ValueString; else return "Cancel"; } public void TempTextClick(string type, object sender) { var windowManager = IoC.Get(); switch (type) { case "Mode": RecipeTempModeViewModel recipeTempModeViewModel = new RecipeTempModeViewModel(); var rtn = (windowManager as WindowManager)?.ShowDialogWithTitle(recipeTempModeViewModel, null, "Temp Mode"); break; case "Correct": TempOffsetTableViewModel tempOffsetTableViewModel = new TempOffsetTableViewModel(); break; case "PID": TempOffsetTableViewModel tempOffsetTableViewModel1 = new TempOffsetTableViewModel(); break; default: break; } } public void TempTextChanged(string type, object sender, object item) { if (!string.IsNullOrEmpty(type) && item != null && sender != null) { TempSetData tempData = (TempSetData)item; string value = ((TextBox)sender).Text; int stepNo = SelectedParameterStep.StepNo; var step = CurrentParameter.Steps.Where(x => x.StepNo == stepNo).FirstOrDefault(); } } public bool IsManualSet { get; set; } private string _resultString; public string ResultString { get => _resultString; set { _resultString = value; NotifyOfPropertyChange("ResultString"); } } public void ParameterDownload() { if (DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, " You are sure to set these parameters?") == DialogButton.No) return; var step = CurrentParameter.Steps.FirstOrDefault(x => x.IsChecked); InvokeClient.Instance.Service.DoOperation($"PM1.Heater.SetCorrect", $"{CurrentParameter.PrefixPath}\\{CurrentParameter.Name},{step.StepNo},{step.Name}"); } public void ParameterUnload() { } public void ParameterSave() { var SelectedStep = this.CurrentParameter.Steps.Where(x => x.StepNo == SelectedStepNo).FirstOrDefault(); if (IsEnabledControl) { List names = new List(); string filmFormula = string.Empty; ParameterTable step = CurrentParameter.Steps.Where(x => x.StepNo == SelectedParameterStep.StepNo).FirstOrDefault(); this.CurrentParameter.Revisor = BaseApp.Instance.UserContext.LoginName; this.CurrentParameter.ReviseTime = DateTime.Now; this.CurrentParameter.Level = this.LevelDisplay; var result = this._parameterProvider.SaveParameter(CurrentParameter.PrefixPath, CurrentParameter.Name, CurrentParameter.GetXmlString()); if (result) ((Window)GetView()).DialogResult = true; } else { if (!CboAutoSelectChecked) { var step = CurrentParameter.Steps.FirstOrDefault(x => x.IsChecked); if (step != null) { ResultString = $"{FullFileName},{step.StepNo},{step.Name}"; } else { ResultString = $"{FullFileName},{SelectedParameterStep.StepNo},{SelectedParameterStep.Name}"; } } ((Window)GetView()).DialogResult = true; } } public void ParameterCancel() { if (DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, " You confirm that you want to unsave the recipe and exit the interface?") == DialogButton.No) return; ((Window)GetView()).DialogResult = false; } protected override void InvokeAfterUpdateProperty(Dictionary data) { base.InvokeAfterUpdateProperty(data); if (CurrentParameter.Steps != null && CurrentParameter.Steps.Count > 0 && CheckValueChange(data)) { } oldresult = data; } Dictionary oldresult; private bool CheckValueChange(Dictionary result) { Dictionary temp = result; if (oldresult == null) { oldresult = result; return true; } else { List strkeys = new List(); foreach (var key in result.Keys) { if (_subscribedKeys.Contains(key) && oldresult.ContainsKey(key) && result.ContainsKey(key)) { if (result[key].GetType() == typeof(AITValveData) && ((AITValveData)oldresult[key]).VirtualFeedback != ((AITValveData)result[key]).VirtualFeedback) { return true; } else if (result[key].GetType() == typeof(AITMfcData) && ((AITMfcData)oldresult[key]).VirtualSetPoint != ((AITMfcData)result[key]).VirtualSetPoint) { return true; } else if (result[key].GetType() == typeof(bool) && (bool)oldresult[key] != (bool)result[key]) { return true; } } } } return false; } public void AutoSelectClick(object sender) { if (sender is CheckBox) { if ((bool)((CheckBox)sender).IsChecked) { AutoSelectIsEnabled = false; CurrentParameter.Steps.Select(step => step.IsChecked = false); SetShowPanel(ShowPanel.AutoSelect); ResultString = "Auto"; } } } } }