chr
2024-11-02 b5234c5ab1e9e6826b8d8fc1e95fa752aaa40b74
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
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<string, JgjType> datas;
        private Dictionary<string, ObservableCollection<string>> stuffItemCache;
 
        private Dictionary<string, ObservableCollection<string>> surfaceItemCache;
 
        private Dictionary<string, ObservableCollection<string>> heatItemCache;
 
        #region 下拉框数据源
        private ObservableCollection<string> _jgjTypeItems;
        public ObservableCollection<string> jgjTypeItems
        {
            get => _jgjTypeItems;
            set => RaiseAndSetIfChanged(ref _jgjTypeItems, value);
        }
 
        private ObservableCollection<string> _stuffItems;
        public ObservableCollection<string> stuffItems
        {
            get => _stuffItems;
            set => RaiseAndSetIfChanged(ref _stuffItems, value);
        }
 
        private ObservableCollection<string> _surfaceItems;
        public ObservableCollection<string> surfaceItems
        {
            get => _surfaceItems;
            set => RaiseAndSetIfChanged(ref _surfaceItems, value);
        }
 
        private ObservableCollection<string> _heatItems;
        public ObservableCollection<string> heatItems
        {
            get => _heatItems;
            set => RaiseAndSetIfChanged(ref _heatItems, value);
        }
 
        private ObservableCollection<string> _materialTypeItems = new ObservableCollection<string> { "普通件",
       "机罩","机架","大板"
        };// "易损件","备件",
        public ObservableCollection<string> materialTypeItems
        {
            get => _materialTypeItems;
            set => RaiseAndSetIfChanged(ref _materialTypeItems, value);
        }
 
        private ObservableCollection<string> _docTypeItems = new ObservableCollection<string> { "加工件" };
        public ObservableCollection<string> 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> { "无" });
            string key = $"{jgjType}_{stuff}";
            var finalSurfaces = surfaceItemCache.Get(key, new ObservableCollection<string> { "无" });
            var finalHeats = heatItemCache.Get(key, new ObservableCollection<string> { "无" });
 
            stuffItems = finalStuffs;
            surfaceItems = finalSurfaces;
            heatItems = finalHeats;
        }
 
        public override bool SetSettings(object settings)
        {
            Dictionary<string, JgjType> datas = settings as Dictionary<string, JgjType>;
            this.datas = datas;
 
            stuffItemCache = new Dictionary<string, ObservableCollection<string>>();
 
            surfaceItemCache = new Dictionary<string, ObservableCollection<string>>();
 
            heatItemCache = new Dictionary<string, ObservableCollection<string>>();
 
            ObservableCollection<string> jgjTypes = new ObservableCollection<string> { };
 
            foreach (string key in datas.Keys)
            {
                jgjTypes.Add(key);
                JgjType type = datas[key];
                ObservableCollection<string> stuffs = new ObservableCollection<string> { "无" };
 
                Dictionary<string, StuffType> stuffDatas = type.stuffMap;
                foreach (string stuff in stuffDatas.Keys)
                {
                    if (stuff != "无")
                    {
                        stuffs.Add(stuff);
                    }
                    StuffType stuffType = stuffDatas[stuff];
                    string key2 = key + "_" + stuff;
 
                    ObservableCollection<string> surfaces = new ObservableCollection<string> { "无" };
                    ObservableCollection<string> heats = new ObservableCollection<string> { "无" };
                    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<string> { "无" });
                }
            }
 
            jgjTypeItems = jgjTypes;
            RefreshItem();
            return true;
        }
    }
}