using Caliburn.Micro.Core; using RecipeEditorLib.RecipeModel.Params; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MECF.Framework.UI.Client.CenterViews.Parameter { public class TempPIDTable : ParameterTable { private ObservableCollection _pIDDataList = new ObservableCollection(); public ObservableCollection PIDDataList { get => _pIDDataList; set { _pIDDataList = value; NotifyOfPropertyChange("PIDDataList"); } } public TempPIDTable() : base() { } public TempPIDTable(ParameterDataBase recipeData) { if (recipeData.Steps.Count <= 0) return; SetCurrentRecipeStep(recipeData, recipeData.Steps[0]); } public TempPIDTable(ParameterDataBase recipeData, int selectedStepNo) { ParameterTable step = recipeData.Steps.Where(x => x.StepNo == selectedStepNo).FirstOrDefault(); SetCurrentRecipeStep(recipeData, step); } public void SetTempPIDData(string value) { if (string.IsNullOrEmpty(value)) return; string[] strTempPID = value.Split('|'); foreach (var item in strTempPID) { if (string.IsNullOrEmpty(item)) continue; string[] subTempPID = item.Split(';'); Dictionary dictTempPID = new Dictionary(); foreach (var pid in subTempPID) { if (string.IsNullOrEmpty(item)) continue; var keyValue = pid.Split(':'); if (keyValue == null || keyValue.Length != 2) continue; dictTempPID[keyValue[0]] = keyValue[1]; } var selectPID = PIDDataList.Where(x => x.Name == dictTempPID["Name"]).FirstOrDefault(); if (selectPID != null) { selectPID.P.Value = dictTempPID["P"]; selectPID.I.Value = dictTempPID["I"]; selectPID.D.Value = dictTempPID["D"]; } } } } public class PIDData : PropertyChangedBase { private int _index = 1; public int Index { get => _index; set { _index = value; NotifyOfPropertyChange("Index"); } } private string _name = ""; public string Name { get => _name; set { _name = value; NotifyOfPropertyChange("Name"); } } private DoubleParam _p; public DoubleParam P { get => _p; set { _p = value; NotifyOfPropertyChange("P"); } } private DoubleParam _i; public DoubleParam I { get => _i; set { _i = value; NotifyOfPropertyChange("I"); } } private DoubleParam _d; public DoubleParam D { get => _d; set { _d = value; NotifyOfPropertyChange("D"); } } public override string ToString() { string[] rtnStrList = new string[5]; rtnStrList[0] = $"Index:{Index}"; rtnStrList[1] = $"Name:{Name}"; rtnStrList[2] = $"P:{P.Value}"; rtnStrList[3] = $"I:{I.Value}"; rtnStrList[4] = $"D:{D.Value}"; return string.Join(";", rtnStrList); } } }