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; namespace FurnaceUI.Views.Parameter { public class TempProfileEditViewModel : FurnaceUIViewModelBase { private UIElement _parent; public void SetParent(UIElement parent) { _parent = parent; } public bool Table1CheckinRecipe { get; set; } = false; public bool Table2CheckinRecipe { get; set; } = false; public bool Table3CheckinRecipe { get; set; } = false; private readonly ParameterProvider _parameterProvider = new ParameterProvider(); private Dictionary> ParameterTemplate; public TempProfileParameterData CurrentParameter { get; set; } = new TempProfileParameterData(); private ParameterFormatBuilder _columnBuilder = new ParameterFormatBuilder(); private TempProfileTable _selectedParameterStep; public TempProfileTable 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"); } } public bool IsEnable => CGlobal.ParameterEditViewEnable;//是否是View模式 private bool _isEidtEnable = true; public bool IsEditEnabled { get => _isEidtEnable; set { _isEidtEnable = value; NotifyOfPropertyChange(nameof(IsEditEnabled)); } } public string EditRecipeStepName { get; set; } private string _resultString; public string ResultString { get => _resultString; set { _resultString = value; NotifyOfPropertyChange(nameof(ResultString)); } } private RecipeDataBase _CurrentRecipe; public RecipeDataBase CurrentRecipe { get { return _CurrentRecipe; } set { _CurrentRecipe = value; this.NotifyOfPropertyChange(nameof(CurrentRecipe)); } } public string FullFileName { get; set; } public void SetCmdIsEnabled() { if (CurrentParameter.Steps == null || CurrentParameter.Steps.Count == 0) { SelectedStepName = ""; 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 string _selectedStepName; public string SelectedStepName { get { return _selectedStepName; } set { _selectedStepName = value; NotifyOfPropertyChange("SelectedStepName"); } } private List _ConfigNodes = new List(); public List ConfigNodes { get { return _ConfigNodes; } set { _ConfigNodes = value; NotifyOfPropertyChange("ConfigNodes"); } } private TempProfileTable profileTable1 = new TempProfileTable(); public TempProfileTable ProfileTable1 { get => profileTable1; set { profileTable1 = value; NotifyOfPropertyChange(nameof(ProfileTable1)); } } private TempProfileTable profileTable2 = new TempProfileTable(); public TempProfileTable ProfileTable2 { get => profileTable2; set { profileTable2 = value; NotifyOfPropertyChange(nameof(ProfileTable2)); } } private TempProfileTable profileTable3 = new TempProfileTable(); public TempProfileTable ProfileTable3 { get => profileTable3; set { profileTable3 = value; NotifyOfPropertyChange(nameof(ProfileTable3)); } } public string ParameterType { get; set; } 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; } } } public TempProfileEditViewModel() { _parameterProvider.GetParameterFormatXml($"Parameter\\TempProfile"); ParameterTemplate = _parameterProvider.GetGroupParameterTemplate(); _columnBuilder.Build($"Parameter\\TempProfile"); CurrentParameter.PrefixPath = $"Parameter\\TempProfile"; } public TempProfileEditViewModel(string strPrefixPath, string strRecipeName, string permission = "") { _parameterProvider.GetParameterFormatXml(strPrefixPath); ParameterTemplate = _parameterProvider.GetGroupParameterTemplate(); _columnBuilder.Build(strPrefixPath); CurrentParameter.PrefixPath = strPrefixPath; CurrentParameter.Name = strRecipeName; CurrentParameter.Permission = permission; } 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(); ProfileTable1.IsChecked = Table1CheckinRecipe; ProfileTable2.IsChecked = Table2CheckinRecipe; ProfileTable3.IsChecked = Table3CheckinRecipe; if (!ProfileTable1.IsChecked&& !ProfileTable2.IsChecked&& !ProfileTable3.IsChecked) { ProfileTable1.IsChecked = true; } } //private void LoadData() //{ // if (!string.IsNullOrEmpty(CurrentParameter.Name)) // { // 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, ""); // } //} private void LoadData() { if (CurrentRecipe != null) { CurrentParameter.PrefixPath = $"Parameter\\TempProfile"; StringParam pressAPC = CurrentRecipe.ConfigItems.FirstOrDefault(x => x.Name == "Combination.ProfileCondition") as StringParam; if (pressAPC != null && !string.IsNullOrEmpty(pressAPC.Value)) { CurrentParameter.Permission = ""; CurrentParameter.Name = pressAPC.Value; } else { if (CurrentParameter.Steps != null && CurrentParameter.Steps.Count > 0) { foreach (var item in CurrentParameter.Steps) { var profileTable = (TempProfileTable)item; profileTable.PreheatTime = "0"; profileTable.CheckTime = "0"; DoubleParam param = new DoubleParam() { Name = "", Value = "0", DisplayName = "", Minimun = 0, Maximun = 0, Resolution = 0 }; profileTable.LimitU = param; profileTable.LimitCU = param; profileTable.LimitC = param; profileTable.LimitCL = param; profileTable.LimitL = param; profileTable.AlarmLimit = param; profileTable.TotalTime = "0"; profileTable.PreheatTime = "0"; profileTable.CheckTime = "0"; } } CurrentParameter.Name = ""; FullFileName = ""; DialogBox.ShowDialog(DialogButton.Cancel, DialogType.INFO, "Please set the Combination default profile file!"); return; } FullFileName = $"{CurrentParameter.PrefixPath}\\{CurrentParameter.Name}"; } else { CurrentParameter.TableNumber = _columnBuilder.TableNumber; CurrentParameter.ChamberType = _columnBuilder.ChamberType; FullFileName = $"{CurrentParameter.PrefixPath}\\{CurrentParameter.Name}"; } 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.InitData(CurrentParameter.PrefixPath, CurrentParameter.Name, recipeContent, ""); } private void LoadViewData() { if (CurrentParameter.Steps != null && CurrentParameter.Steps.Count > 2) { SelectedStepName = CurrentParameter.Steps[0].Name; SelectedStepNo = CurrentParameter.Steps[0].StepNo; ProfileTable1 = (TempProfileTable)CurrentParameter.Steps[0]; ProfileTable2 = (TempProfileTable)CurrentParameter.Steps[1]; ProfileTable3 = (TempProfileTable)CurrentParameter.Steps[2]; } } public void SelectTable(object step) { if (step != null && step is TempProfileTable step1) { var SelectedStep = this.CurrentParameter.Steps.Where(x => x.StepNo == step1.StepNo).FirstOrDefault(); SelectedStep.IsChecked = true; SelectedStepNo = step1.StepNo; string strName = step1.Name.Trim(); SelectedStepName = strName; SelectedParameterStep = (TempProfileTable)SelectedStep; //SelectedParameterStep = new TempPIDTable(CurrentParameter, SelectedStepNo); } SetCmdIsEnabled(); } public void StepEdit(string stepEditCmd) { var windowManager = IoC.Get(); switch (stepEditCmd) { case "Append": CurrentParameter.Steps.Add(CurrentParameter.CreateStep()); int TempSelectIndex = 0; IndexNoDefault = TempSelectIndex; SelectTable(CurrentParameter.Steps[TempSelectIndex]); break; case "InsertCopy": InsertCopyStep(); break; case "OverWrite"://任何步骤的内容都可以覆盖到选定的步骤中 OverWriteStep(); break; case "PrevStepOverwrite"://用上一步的内容覆盖所选步骤 PrevStepOverwriteStep(); break; case "PrevStepInsert"://在选定步骤之前,插入带有前一步内容的新步骤。 InsertPrevStep(); break; case "PrevStepItem": break; case "MultStepsDelete": break; default: break; } } private void OverWriteStep() { var windowManager = IoC.Get(); if (CurrentParameter == null) return; } private void PrevStepOverwriteStep() { int index = -1; index = SelectedParameterStep.StepNo; if (index > 1) { CurrentParameter.CloneStep(CurrentParameter.Steps.Where(x => x.StepNo == SelectedParameterStep.StepNo).FirstOrDefault(), CurrentParameter.Steps.Where(x => x.StepNo == SelectedParameterStep.StepNo - 1).FirstOrDefault()); } } 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 void ParameterEdit(object cmdName, object value) { var windowManager = IoC.Get(); } public void ParameterSave() { var SelectedStep = this.CurrentParameter.Steps.Where(x => x.IsChecked).FirstOrDefault(); //RecipePermissionSelectViewModel dialog = new RecipePermissionSelectViewModel("Save recipe and permission", CurrentRecipe.RecipePermission); //WindowManager wm = new WindowManager(); //bool? dialogReturn = wm.ShowDialog(dialog); //if (!dialogReturn.HasValue || !dialogReturn.Value) // return; if (IsEditEnabled) { 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; //this.CurrentRecipe.RecipePermission = dialog.RecipePermission; var result = _parameterProvider.SaveParameter(CurrentParameter.PrefixPath, CurrentParameter.Name, CurrentParameter.GetXmlString()); if (result) ((Window)GetView()).Close(); } else { ResultString = $"{FullFileName},{SelectedStep.StepNo},{SelectedStep.Name}"; ((Window)GetView()).DialogResult = true; } } public void ParameterDownload() { var sss = ""; } public void ParameterUnload() { } 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()).Close(); } protected override void InvokeAfterUpdateProperty(Dictionary data) { base.InvokeAfterUpdateProperty(data); if (CurrentParameter.Steps != null && CurrentParameter.Steps.Count > 0 && CheckValueChange(data)) { //SelectStep(CurrentRecipe.Steps[EditRecipeStepNo]); } 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; } } }