| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734 | 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<string, ObservableCollection<ParameterTemplateColumnBase>> 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<ConfigNode> _ConfigNodes = new List<ConfigNode>();        public List<ConfigNode> 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<IWindowManager>();            if (CurrentParameter == null) return;        }        public void InsertPrevStep()        {        }        public void InsertCopyStep()        {            var windowManager = IoC.Get<IWindowManager>();            if (CurrentParameter == null) return;        }        //撤销修改        public void RecipeIsChangeClick(object cmdName, object value)        {            var windowManager = IoC.Get<IWindowManager>();        }        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<IWindowManager>();            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<string> names = new List<string>();                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<string, object> data)        {            base.InvokeAfterUpdateProperty(data);            if (CurrentParameter.Steps != null && CurrentParameter.Steps.Count > 0 && CheckValueChange(data))            {                          }            oldresult = data;        }        Dictionary<string, object> oldresult;        private bool CheckValueChange(Dictionary<string, object> result)        {            Dictionary<string, object> temp = result;            if (oldresult == null)            {                oldresult = result;                return true;            }            else            {                List<string> strkeys = new List<string>();                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";                }            }        }    }}
 |