| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 | using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Controls;using System.Windows;using MECF.Framework.Common.DataCenter;using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;using FurnaceUI.Models;using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;using MECF.Framework.UI.Client.CenterViews.Parameter;using System.Collections.ObjectModel;using MECF.Framework.Common.ParameterCenter;using OpenSEMI.ClientBase;using MECF.Framework.UI.Client.ClientBase;using RecipeEditorLib.RecipeModel.Params;namespace FurnaceUI.Views.Editors{    public class TempOffsetTableViewModel : FurnaceUIViewModelBase    {        enum ShowPanel        {            Table,            AutoSelect        }        public TempOffsetTableViewModel()        {        }        public bool IsSave { get; set; }        public string TempOffsetTableSelected { get; set; }        private bool _isEnable;        public bool IsEnable        {            get { return _isEnable; }            set { _isEnable = value; this.NotifyOfPropertyChange(nameof(IsEnable)); }        }        private Step _selectedRecipeStep;        public Step SelectedRecipeStep        {            get => _selectedRecipeStep;            set            {                _selectedRecipeStep = value;                NotifyOfPropertyChange("SelectedRecipeStep");            }        }        private RecipeDataBase _CurrentRecipe;        public RecipeDataBase CurrentRecipe        {            get { return _CurrentRecipe; }            set { _CurrentRecipe = value; this.NotifyOfPropertyChange(nameof(CurrentRecipe)); }        }        private readonly ParameterProvider _parameterProvider = new ParameterProvider();        private Dictionary<string, ObservableCollection<ParameterTemplateColumnBase>> ParameterTemplate;        public TempPIDParameterData CurrentParameter { get; set; } = new TempPIDParameterData();        private ParameterFormatBuilder _columnBuilder = new ParameterFormatBuilder();        private TempPIDTable _selectedParameterStep;        private Visibility _tableVisibility = Visibility.Visible;        public Visibility TableVisibility        {            get => _tableVisibility;            set            {                _tableVisibility = value;                NotifyOfPropertyChange("TableVisibility");            }        }        private Visibility _autoSelectVisibility = Visibility.Hidden;        public Visibility AutoSelectVisibility        {            get => _autoSelectVisibility;            set            {                _autoSelectVisibility = value;                NotifyOfPropertyChange("AutoSelectVisibility");            }        }        private bool _autoSelectIsEnabled = true;        public bool AutoSelectIsEnabled        {            get => _autoSelectIsEnabled;            set            {                _autoSelectIsEnabled = value;                NotifyOfPropertyChange("AutoSelectIsEnabled");            }        }        public TempPIDTable SelectedParameterStep        {            get => _selectedParameterStep;            set            {                _selectedParameterStep = value;                NotifyOfPropertyChange("SelectedParameterStep");            }        }        public int SelectedStepNo { get; set; }        private string _selectedStepName;        public string SelectedStepName        {            get            {                return _selectedStepName;            }            set            {                _selectedStepName = value;                NotifyOfPropertyChange("SelectedStepName");            }        }        private bool _cboAutoSelectChecked;        public bool IsManualSet { get; set; }        public bool CboAutoSelectChecked        {            get => _cboAutoSelectChecked;            set            {                _cboAutoSelectChecked = value;                NotifyOfPropertyChange("CboAutoSelectChecked");            }        }        public string FullFileName { get; set; }        private bool _isEnabledControl = true;        public bool IsEnabledControl        {            get => _isEnabledControl;            set            {                _isEnabledControl = value;                NotifyOfPropertyChange("IsEnabledControl");            }        }        protected override void OnInitialize()        {            base.OnInitialize();        }        protected override void OnViewLoaded(object view)        {            base.OnViewLoaded(view);            LoadData();            LoadViewData();            IsEnable = IsManualSet == true ? IsManualSet : CGlobal.RecipeProcessEditViewEnable;        }        private void SetShowPanel(ShowPanel showPanel)        {            switch (showPanel)            {                case ShowPanel.Table:                    TableVisibility = Visibility.Visible;                    AutoSelectVisibility = Visibility.Hidden;                    break;                case ShowPanel.AutoSelect:                    TableVisibility = Visibility.Hidden;                    AutoSelectVisibility = Visibility.Visible;                    break;                default:                    break;            }        }        public void AutoSelectClick(object sender)        {            if (sender is CheckBox)            {                if (!(bool)((CheckBox)sender).IsChecked)                {                    ((CheckBox)sender).IsChecked = true;                    AutoSelectIsEnabled = false;                }            }        }        public void SelectTable(object step)        {            if (step != null && step is TempPIDTable 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 = (TempPIDTable)SelectedStep;                //SelectedParameterStep = new TempPIDTable(CurrentParameter, SelectedStepNo);                SetShowPanel(ShowPanel.Table);                AutoSelectIsEnabled = true;            }        }        private void LoadViewData()        {            if (CurrentParameter.Steps != null && CurrentParameter.Steps.Count > 0 && SelectedParameterStep == null)            {                SelectedStepName = CurrentParameter.Steps[0].Name;                SelectedStepNo = CurrentParameter.Steps[0].StepNo;                var step = CurrentParameter.Steps[0];                if (!string.IsNullOrEmpty(TempOffsetTableSelected))                {                    var strList = TempOffsetTableSelected.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))                        {                            SelectedStepName = selectedName;                        }                    }                                  }                step.IsChecked = true;                SelectTable(step);            }        }        private void LoadData()        {            CurrentParameter.PrefixPath = $"Parameter\\TempPID";            if (CurrentRecipe != null)            {                StringParam tempCorrection = CurrentRecipe.ConfigItems.FirstOrDefault(x => x.Name == "Combination.TempPID") as StringParam;                if (tempCorrection != null && !string.IsNullOrEmpty(tempCorrection.Value))                {                    CurrentParameter.Name = tempCorrection.Value;                    CurrentParameter.Permission = "";                }                else                {                    if (CurrentParameter.Steps != null && CurrentParameter.Steps.Count > 0)                    {                        foreach (var item in CurrentParameter.Steps)                        {                            if (((TempPIDTable)item).PIDDataList != null && ((TempPIDTable)item).PIDDataList.Count > 0)                            {                                foreach (var subitem in ((TempPIDTable)item).PIDDataList)                                {                                    subitem.P.Value = "0";                                    subitem.I.Value = "0";                                    subitem.D.Value = "0";                                }                            }                        }                    }                    DialogBox.ShowDialog(DialogButton.Cancel, DialogType.INFO, "Please set the Combination default Temp PID  file!");                    return;                }                //CurrentParameter.Name = SelectedRecipeStep.TemperaturePID;                FullFileName = $"{CurrentParameter.PrefixPath}\\{CurrentParameter.Name}";            }            else            {                var defaultTempPID = SystemConfigProvider.Instance.GetValueByName("PM1.TempPID");                if (string.IsNullOrEmpty(defaultTempPID))                {                    DialogBox.ShowDialog(DialogButton.Cancel, DialogType.INFO, "Please set the default file first");                    return;                }                int last = defaultTempPID.LastIndexOf('\\');                var pix = defaultTempPID.Substring(0, last);                var file = defaultTempPID.Substring(last + 1, defaultTempPID.Length - last - 1);                CurrentParameter.PrefixPath = pix;                CurrentParameter.Name = file;                CurrentParameter.Permission = "";                FullFileName = defaultTempPID;                TempOffsetTableSelected = "1: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, "");            if (!string.IsNullOrEmpty(TempOffsetTableSelected))            {                if (!TempOffsetTableSelected.Contains(":"))                {                    SetShowPanel(ShowPanel.AutoSelect);                    CboAutoSelectChecked = true;                    AutoSelectIsEnabled = false;                }                else                {                    SetShowPanel(ShowPanel.Table);                    CboAutoSelectChecked = false;                    AutoSelectIsEnabled = true;                    var no = Convert.ToInt32(TempOffsetTableSelected.Split(':')[0]);                    var selecttable = CurrentParameter.Steps.Where(x => x.StepNo == no).FirstOrDefault();                    selecttable.IsChecked = true;                    SelectTable(selecttable);                }            }            else            {                SetShowPanel(ShowPanel.AutoSelect);                CboAutoSelectChecked = true;                AutoSelectIsEnabled = false;            }        }        private ConfigNode FindNodeByName(ConfigNode parentNode, string strName)        {            string strCates = strName.Split('.')[0];            ConfigNode node = parentNode.SubNodes.Find((x) => x.Name == strCates);            if (node == null)                return parentNode;            else                return FindNodeByName(node, strName.Replace(strCates + ".", ""));        }        public void TempOffsetSelected(object sender)        {            if (sender.ToString() != "None")            {                //  InitTableData(sender.ToString());            }            TempOffsetTableSelected = sender.ToString();        }        public void ParameterSave()        {            var step = CurrentParameter.Steps.FirstOrDefault(x => x.IsChecked);            if (step != null)            {                TempOffsetTableSelected = $"{FullFileName},{step.StepNo},{step.Name}";            }            else            {                TempOffsetTableSelected = $"{FullFileName},{SelectedParameterStep.StepNo},{SelectedParameterStep.Name}";            }            IsSave = true;            ((Window)GetView()).DialogResult = true;        }        public void ParameterCancel()        {            IsSave = false;            ((Window)GetView()).DialogResult = false;        }    }}
 |