using PdmSwPlugin.Common.Util; using PdmSwPlugin.PropertySetting.Entity; using PdmSwPlugin.PropertySetting.Panel.Attr; using System.Collections.Generic; using System.Collections.ObjectModel; namespace PdmSwPlugin.PropertySetting.Panel.Model { public class JgjBasePanelModel : BasePanelModel { private Dictionary datas; private Dictionary> stuffItemCache; private Dictionary> surfaceItemCache; private Dictionary> heatItemCache; #region 下拉框数据源 private ObservableCollection _jgjTypeItems; public ObservableCollection jgjTypeItems { get => _jgjTypeItems; set => RaiseAndSetIfChanged(ref _jgjTypeItems, value); } private ObservableCollection _stuffItems; public ObservableCollection stuffItems { get => _stuffItems; set => RaiseAndSetIfChanged(ref _stuffItems, value); } private ObservableCollection _surfaceItems; public ObservableCollection surfaceItems { get => _surfaceItems; set => RaiseAndSetIfChanged(ref _surfaceItems, value); } private ObservableCollection _heatItems; public ObservableCollection heatItems { get => _heatItems; set => RaiseAndSetIfChanged(ref _heatItems, value); } private ObservableCollection _materialTypeItems = new ObservableCollection { "普通件", "机罩","机架","大板" };// "易损件","备件", public ObservableCollection materialTypeItems { get => _materialTypeItems; set => RaiseAndSetIfChanged(ref _materialTypeItems, value); } private ObservableCollection _docTypeItems = new ObservableCollection { "加工件" }; public ObservableCollection docTypeItems { get => _docTypeItems; set => RaiseAndSetIfChanged(ref _docTypeItems, value); } #endregion #region 加工件属性 private string _jgjType = ""; [PropertySettingAttr(Name = NameConstant.jgjType)] public string jgjType { get => _jgjType; set { if (_jgjType == value) { return; } RaiseAndSetIfChanged(ref _jgjType, value); RefreshItem(); } } private string _stuff = ""; [PropertySettingAttr(Name = NameConstant.stuff)] public string stuff { get => _stuff; set { if (_stuff == value) { return; } RaiseAndSetIfChanged(ref _stuff, value); RefreshItem(); } } private string _surface = ""; [PropertySettingAttr(Name = NameConstant.surface)] public string surface { get => _surface; set { if (_surface == value) { return; } RaiseAndSetIfChanged(ref _surface, value); } } private string _heat = ""; [PropertySettingAttr(Name = NameConstant.heat)] public string heat { get => _heat; set { if (_heat == value) { return; } RaiseAndSetIfChanged(ref _heat, value); } } #endregion private void RefreshItem() { if (datas == null) { return; } var finalStuffs = stuffItemCache.Get(jgjType, new ObservableCollection { "无" }); string key = $"{jgjType}_{stuff}"; var finalSurfaces = surfaceItemCache.Get(key, new ObservableCollection { "无" }); var finalHeats = heatItemCache.Get(key, new ObservableCollection { "无" }); stuffItems = finalStuffs; surfaceItems = finalSurfaces; heatItems = finalHeats; } public override bool SetSettings(object settings) { Dictionary datas = settings as Dictionary; this.datas = datas; stuffItemCache = new Dictionary>(); surfaceItemCache = new Dictionary>(); heatItemCache = new Dictionary>(); ObservableCollection jgjTypes = new ObservableCollection { }; foreach (string key in datas.Keys) { jgjTypes.Add(key); JgjType type = datas[key]; ObservableCollection stuffs = new ObservableCollection { "无" }; Dictionary stuffDatas = type.stuffMap; foreach (string stuff in stuffDatas.Keys) { if (stuff != "无") { stuffs.Add(stuff); } StuffType stuffType = stuffDatas[stuff]; string key2 = key + "_" + stuff; ObservableCollection surfaces = new ObservableCollection { "无" }; ObservableCollection heats = new ObservableCollection { "无" }; foreach (string surface in stuffType.surfaceParam) { if (surface != "无") surfaces.Add(surface); } foreach (string heat in stuffType.heatParam) { if (heat != "无") heats.Add(heat); } surfaceItemCache.Add(key2, surfaces); heatItemCache.Add(key2, heats); } stuffItemCache.Add(key, stuffs); if (!stuffItemCache.ContainsKey("无")) { stuffItemCache.Add("无", new ObservableCollection { "无" }); } } jgjTypeItems = jgjTypes; RefreshItem(); return true; } } }