markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DashBoardViewModel.cs @ cb806a91
이력 | 보기 | 이력해설 | 다운로드 (13.3 KB)
1 | 2f07b70a | semi | using Markus.Service.Extensions; |
---|---|---|---|
2 | using Markus.Service.StationController.Data; |
||
3 | using Markus.Service.StationController.Extensions; |
||
4 | using Newtonsoft.Json; |
||
5 | using Telerik.Charting; |
||
6 | using Telerik.Windows.Controls; |
||
7 | using Telerik.Windows.Controls.ChartView; |
||
8 | using System; |
||
9 | using System.Collections.Generic; |
||
10 | using System.Linq; |
||
11 | using System.Text; |
||
12 | using System.Threading.Tasks; |
||
13 | using System.Windows; |
||
14 | using System.Windows.Threading; |
||
15 | using ConverCOUNT = Markus.Service.StationController.Data.ConvertCOUNT; |
||
16 | c7955b40 | semi | using System.Collections.ObjectModel; |
17 | 2f07b70a | semi | |
18 | namespace Markus.Service.StationController.ViewModel |
||
19 | { |
||
20 | 80391351 | semi | class DashBoardViewModel : Mvvm.ToolKit.ViewModelBase |
21 | 2f07b70a | semi | { |
22 | #region Constructor |
||
23 | |||
24 | |||
25 | public DashBoardViewModel() |
||
26 | { |
||
27 | RemoveCreateTimeFilterCommand = new DelegateCommand(RemoveCreateTimeFilter); |
||
28 | } |
||
29 | |||
30 | #endregion |
||
31 | |||
32 | #region Properties |
||
33 | |||
34 | 037ab674 | semi | DataService.DataServiceClient WcfClient = new DataService.DataServiceClient(); |
35 | |||
36 | 2f07b70a | semi | static DateTime DefaultCreateTime = DateTime.Now; |
37 | private DateTime _SelectedCreateTimeBegin = DefaultCreateTime; |
||
38 | public DateTime SelectedCreateTimeBegin |
||
39 | { |
||
40 | |||
41 | get { return _SelectedCreateTimeBegin; } |
||
42 | set |
||
43 | { |
||
44 | if (_SelectedCreateTimeBegin == value) |
||
45 | return; |
||
46 | _SelectedCreateTimeBegin = value; |
||
47 | OnPropertyChanged(() => SelectedCreateTimeBegin); |
||
48 | |||
49 | } |
||
50 | } |
||
51 | |||
52 | private DateTime _SelectedCreateTimeEnd = DefaultCreateTime; |
||
53 | public DateTime SelectedCreateTimeEnd |
||
54 | { |
||
55 | |||
56 | get { return _SelectedCreateTimeEnd; } |
||
57 | set |
||
58 | { |
||
59 | if (_SelectedCreateTimeEnd == value) |
||
60 | return; |
||
61 | _SelectedCreateTimeEnd = value; |
||
62 | OnPropertyChanged(() => SelectedCreateTimeEnd); |
||
63 | } |
||
64 | } |
||
65 | |||
66 | private SelectedCountItem _SelectedCount; |
||
67 | public SelectedCountItem SelectedCount |
||
68 | { |
||
69 | get => _SelectedCount; |
||
70 | set |
||
71 | { |
||
72 | _SelectedCount = value; |
||
73 | OnPropertyChanged(() => SelectedCount); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | List<SelectedCountItem> _SelectedCountList; |
||
78 | public List<SelectedCountItem> SelectedCountList |
||
79 | { |
||
80 | get |
||
81 | { |
||
82 | if (_SelectedCountList == null) |
||
83 | { |
||
84 | _SelectedCountList = new List<SelectedCountItem> |
||
85 | { |
||
86 | new SelectedCountItem{DisplayMember = "50",ValueMember = 50}, |
||
87 | new SelectedCountItem{DisplayMember = "100",ValueMember = 100}, |
||
88 | new SelectedCountItem{DisplayMember = "150",ValueMember = 150}, |
||
89 | new SelectedCountItem{DisplayMember = "200",ValueMember = 200} |
||
90 | }; |
||
91 | } |
||
92 | |||
93 | return _SelectedCountList; |
||
94 | } |
||
95 | } |
||
96 | |||
97 | c7955b40 | semi | private ObservableCollection<ConvertCOUNT> _ConvertCOUNTDashBoard; |
98 | public ObservableCollection<ConvertCOUNT> ConvertCOUNTDashBoard |
||
99 | 2f07b70a | semi | { |
100 | get |
||
101 | { |
||
102 | c7955b40 | semi | if (_ConvertCOUNTDashBoard == null) |
103 | 2f07b70a | semi | { |
104 | c7955b40 | semi | _ConvertCOUNTDashBoard = new ObservableCollection<ConvertCOUNT>(); |
105 | 2f07b70a | semi | } |
106 | c7955b40 | semi | return _ConvertCOUNTDashBoard; |
107 | 2f07b70a | semi | } |
108 | set |
||
109 | { |
||
110 | c7955b40 | semi | if (_ConvertCOUNTDashBoard != value) |
111 | { |
||
112 | _ConvertCOUNTDashBoard = value; |
||
113 | OnPropertyChanged(() => ConvertCOUNTDashBoard); |
||
114 | } |
||
115 | } |
||
116 | } |
||
117 | |||
118 | private ObservableCollection<FinalPDFCOUNT> _FinalPDFCOUNTDashBoard; |
||
119 | public ObservableCollection<FinalPDFCOUNT> FinalPDFCOUNTDashBoard |
||
120 | { |
||
121 | get |
||
122 | { |
||
123 | if (_FinalPDFCOUNTDashBoard == null) |
||
124 | { |
||
125 | _FinalPDFCOUNTDashBoard = new ObservableCollection<FinalPDFCOUNT>(); |
||
126 | } |
||
127 | return _FinalPDFCOUNTDashBoard; |
||
128 | } |
||
129 | set |
||
130 | { |
||
131 | if (_FinalPDFCOUNTDashBoard != value) |
||
132 | { |
||
133 | _FinalPDFCOUNTDashBoard = value; |
||
134 | OnPropertyChanged(() => FinalPDFCOUNTDashBoard); |
||
135 | } |
||
136 | 2f07b70a | semi | } |
137 | } |
||
138 | |||
139 | private Telerik.Windows.Data.EnumMemberViewModel _SelectedStatus; |
||
140 | public Telerik.Windows.Data.EnumMemberViewModel SelectedStatus |
||
141 | { |
||
142 | get => _SelectedStatus; |
||
143 | set |
||
144 | { |
||
145 | _SelectedStatus = value; |
||
146 | OnPropertyChanged(() => SelectedStatus); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> _StatusCodeList; |
||
151 | public IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> StatusCodeList |
||
152 | { |
||
153 | get |
||
154 | { |
||
155 | if (_StatusCodeList == null) |
||
156 | { |
||
157 | _StatusCodeList = Telerik.Windows.Data.EnumDataSource.FromType<ConvertPDF.StatusCodeType>(); |
||
158 | } |
||
159 | |||
160 | return _StatusCodeList; |
||
161 | } |
||
162 | } |
||
163 | |||
164 | #endregion |
||
165 | |||
166 | #region Command |
||
167 | |||
168 | public DelegateCommand RemoveCreateTimeFilterCommand { get; private set; } |
||
169 | |||
170 | #endregion |
||
171 | |||
172 | #region Main Logic |
||
173 | |||
174 | /// <summary> |
||
175 | /// 각각의 Grid row 객체들 업데이트 |
||
176 | /// </summary> |
||
177 | |||
178 | private DispatcherTimer dispatcherTimer; |
||
179 | public override void Loaded() |
||
180 | { |
||
181 | base.Loaded(); |
||
182 | |||
183 | if (!App.IsDesignMode) |
||
184 | { |
||
185 | dispatcherTimer = new DispatcherTimer(); |
||
186 | dispatcherTimer.Tick += new EventHandler(Timer_Tick); |
||
187 | dispatcherTimer.Interval = new TimeSpan(0, 0, 1); |
||
188 | dispatcherTimer.Start(); |
||
189 | } |
||
190 | } |
||
191 | |||
192 | private async void Timer_Tick(object sender, EventArgs e) |
||
193 | { |
||
194 | dispatcherTimer.Stop(); |
||
195 | |||
196 | if (IsAcitve) |
||
197 | { |
||
198 | await App.Current.Dispatcher.InvokeAsync(() => |
||
199 | { |
||
200 | DataSelect(); |
||
201 | }); |
||
202 | } |
||
203 | |||
204 | await Task.Delay(10000); |
||
205 | |||
206 | dispatcherTimer.Start(); |
||
207 | } |
||
208 | |||
209 | public override void Closed() |
||
210 | { |
||
211 | if (dispatcherTimer != null) |
||
212 | { |
||
213 | dispatcherTimer.Stop(); |
||
214 | } |
||
215 | |||
216 | base.Closed(); |
||
217 | } |
||
218 | |||
219 | |||
220 | #endregion |
||
221 | |||
222 | #region Function |
||
223 | |||
224 | #region RemoveCreateTimeFilter |
||
225 | |||
226 | public void RemoveCreateTimeFilter(object obj) |
||
227 | { |
||
228 | DefaultCreateTime = DateTime.Now; |
||
229 | SelectedCreateTimeBegin = DefaultCreateTime; |
||
230 | SelectedCreateTimeEnd = DefaultCreateTime; |
||
231 | } |
||
232 | |||
233 | #endregion |
||
234 | |||
235 | |||
236 | #region Data Select |
||
237 | |||
238 | /// <summary> |
||
239 | /// 상단 그리드 중앙 그리드 출력 데이터 |
||
240 | /// </summary> |
||
241 | private void DataSelect() |
||
242 | { |
||
243 | c7955b40 | semi | if (ConvertCOUNTDashBoard == null) |
244 | { |
||
245 | ConvertCOUNTDashBoard = new ObservableCollection<ConvertCOUNT>(); |
||
246 | } |
||
247 | if(FinalPDFCOUNTDashBoard == null) |
||
248 | 80391351 | semi | { |
249 | c7955b40 | semi | FinalPDFCOUNTDashBoard = new ObservableCollection<FinalPDFCOUNT>(); |
250 | 80391351 | semi | } |
251 | |||
252 | 2f07b70a | semi | if (SelectedStatus != null) |
253 | { |
||
254 | c7955b40 | semi | ConvertDataSelect(new[] { (ConvertPDF.StatusCodeType)(SelectedStatus.Value) }, ConvertCOUNTDashBoard); |
255 | FinalPDFDataSelect(new[] { (ConvertPDF.StatusCodeType)(SelectedStatus.Value) }, FinalPDFCOUNTDashBoard); |
||
256 | 2f07b70a | semi | } |
257 | } |
||
258 | |||
259 | 037ab674 | semi | private async void ConvertDataSelect(IEnumerable<ConvertPDF.StatusCodeType> statusCodeTypeList, ObservableCollection<ConvertCOUNT> collection) |
260 | 2f07b70a | semi | { |
261 | try |
||
262 | { |
||
263 | 037ab674 | semi | int _status = 0; |
264 | if (SelectedStatus != null) |
||
265 | 2f07b70a | semi | { |
266 | 037ab674 | semi | _status = (int)SelectedStatus.Value; |
267 | } |
||
268 | 2f07b70a | semi | |
269 | 037ab674 | semi | DateTime? Start_CreateTime = null; |
270 | DateTime? Finish_CreateTime = null; |
||
271 | if (SelectedCreateTimeBegin != DefaultCreateTime) |
||
272 | { |
||
273 | Start_CreateTime = SelectedCreateTimeBegin; |
||
274 | } |
||
275 | if (SelectedCreateTimeEnd != DefaultCreateTime) |
||
276 | { |
||
277 | Finish_CreateTime = SelectedCreateTimeEnd; |
||
278 | } |
||
279 | 2f07b70a | semi | |
280 | 037ab674 | semi | var Listitems = from num in await WcfClient.GET_CONVERT_COUNTAsync(_status, Start_CreateTime, Finish_CreateTime) |
281 | select new ConvertCOUNT(num.PROJECT_NO, num.COUNT.Value, num.EXCEPTION_COUNT.Value); |
||
282 | 80391351 | semi | |
283 | 037ab674 | semi | if (collection.Count() == 0) |
284 | { |
||
285 | if (statusCodeTypeList.Count() == 1) |
||
286 | 80391351 | semi | { |
287 | 037ab674 | semi | foreach (var x in Listitems) |
288 | 80391351 | semi | { |
289 | 037ab674 | semi | collection.Add(x); |
290 | 80391351 | semi | } |
291 | } |
||
292 | 037ab674 | semi | } |
293 | else |
||
294 | { |
||
295 | foreach (var newitem in Listitems) |
||
296 | 80391351 | semi | { |
297 | 037ab674 | semi | collection.UpdateWhere(changeitem => |
298 | ConvertItemEx.ChangeValues(changeitem, newitem), x => x.Project_NO == newitem.Project_NO && x.Count == newitem.Count); |
||
299 | } |
||
300 | 80391351 | semi | |
301 | |||
302 | 037ab674 | semi | if (statusCodeTypeList.Count() == 1) |
303 | { |
||
304 | 80391351 | semi | |
305 | 037ab674 | semi | for (int i = collection.Count() - 1; i >= 0; --i) |
306 | 80391351 | semi | { |
307 | 037ab674 | semi | var item = collection[i]; |
308 | 80391351 | semi | |
309 | 037ab674 | semi | if (Listitems.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0) |
310 | 80391351 | semi | { |
311 | 037ab674 | semi | collection.RemoveAt(i); |
312 | 80391351 | semi | } |
313 | } |
||
314 | 037ab674 | semi | } |
315 | 80391351 | semi | |
316 | 037ab674 | semi | if (statusCodeTypeList.Count() == 1) |
317 | { |
||
318 | foreach (var item in Listitems) |
||
319 | 2f07b70a | semi | { |
320 | 037ab674 | semi | if (collection.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0) |
321 | 80391351 | semi | { |
322 | 037ab674 | semi | for (int i = 0; i < 200; i++) |
323 | 80391351 | semi | { |
324 | 037ab674 | semi | collection.Add(item); |
325 | break; |
||
326 | 80391351 | semi | } |
327 | } |
||
328 | 2f07b70a | semi | } |
329 | } |
||
330 | } |
||
331 | 037ab674 | semi | |
332 | 2f07b70a | semi | } |
333 | catch (Exception ex) |
||
334 | { |
||
335 | MessageBox.Show(ex.ToString()); |
||
336 | } |
||
337 | } |
||
338 | |||
339 | 037ab674 | semi | private async void FinalPDFDataSelect(IEnumerable<ConvertPDF.StatusCodeType> statusCodeTypeList, ObservableCollection<FinalPDFCOUNT> collection) |
340 | c7955b40 | semi | { |
341 | try |
||
342 | { |
||
343 | |||
344 | 037ab674 | semi | int _status = 0; |
345 | if (SelectedStatus != null) |
||
346 | { |
||
347 | _status = (int)SelectedStatus.Value; |
||
348 | } |
||
349 | c7955b40 | semi | |
350 | 037ab674 | semi | DateTime? Start_CreateTime = null; |
351 | DateTime? Finish_CreateTime = null; |
||
352 | if (SelectedCreateTimeBegin != DefaultCreateTime) |
||
353 | { |
||
354 | Start_CreateTime = SelectedCreateTimeBegin; |
||
355 | } |
||
356 | if (SelectedCreateTimeEnd != DefaultCreateTime) |
||
357 | { |
||
358 | Finish_CreateTime = SelectedCreateTimeEnd; |
||
359 | } |
||
360 | c7955b40 | semi | |
361 | 037ab674 | semi | var Listitems = from num in await WcfClient.GET_FINALPDF_COUNTAsync(_status, Start_CreateTime, Finish_CreateTime) |
362 | select new FinalPDFCOUNT(num.PROJECT_NO, num.COUNT.Value, num.EXCEPTION_COUNT.Value); |
||
363 | c7955b40 | semi | |
364 | 037ab674 | semi | if (collection.Count() == 0) |
365 | { |
||
366 | if (statusCodeTypeList.Count() == 1) |
||
367 | c7955b40 | semi | { |
368 | 037ab674 | semi | foreach (var x in Listitems) |
369 | c7955b40 | semi | { |
370 | 037ab674 | semi | collection.Add(x); |
371 | c7955b40 | semi | } |
372 | } |
||
373 | 037ab674 | semi | } |
374 | else |
||
375 | { |
||
376 | foreach (var newitem in Listitems) |
||
377 | c7955b40 | semi | { |
378 | 037ab674 | semi | collection.UpdateWhere(changeitem => |
379 | ConvertItemEx.ChangeValues(changeitem, newitem), x => x.Project_NO == newitem.Project_NO && x.Count == newitem.Count); |
||
380 | } |
||
381 | c7955b40 | semi | |
382 | |||
383 | 037ab674 | semi | if (statusCodeTypeList.Count() == 1) |
384 | { |
||
385 | for (int i = collection.Count() - 1; i >= 0; --i) |
||
386 | c7955b40 | semi | { |
387 | 037ab674 | semi | var item = collection[i]; |
388 | c7955b40 | semi | |
389 | 037ab674 | semi | if (Listitems.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0) |
390 | c7955b40 | semi | { |
391 | 037ab674 | semi | collection.RemoveAt(i); |
392 | c7955b40 | semi | } |
393 | } |
||
394 | 037ab674 | semi | } |
395 | c7955b40 | semi | |
396 | 037ab674 | semi | if (statusCodeTypeList.Count() == 1) |
397 | { |
||
398 | foreach (var item in Listitems) |
||
399 | c7955b40 | semi | { |
400 | 037ab674 | semi | if (collection.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0) |
401 | c7955b40 | semi | { |
402 | 037ab674 | semi | for (int i = 0; i < 200; i++) |
403 | c7955b40 | semi | { |
404 | 037ab674 | semi | collection.Add(item); |
405 | break; |
||
406 | c7955b40 | semi | } |
407 | } |
||
408 | } |
||
409 | } |
||
410 | 037ab674 | semi | |
411 | c7955b40 | semi | } |
412 | } |
||
413 | catch (Exception ex) |
||
414 | { |
||
415 | MessageBox.Show(ex.ToString()); |
||
416 | } |
||
417 | } |
||
418 | 2f07b70a | semi | #endregion |
419 | |||
420 | #endregion |
||
421 | } |
||
422 | } |