markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DashBoardViewModel.cs @ 9b2f01e1
이력 | 보기 | 이력해설 | 다운로드 (13.8 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(5000); |
||
205 | await Task.Delay(10000); |
||
206 | |||
207 | //System.Threading.Thread.Sleep(new TimeSpan(0,0,0,0,100)); |
||
208 | |||
209 | dispatcherTimer.Start(); |
||
210 | } |
||
211 | |||
212 | public override void Closed() |
||
213 | { |
||
214 | if (dispatcherTimer != null) |
||
215 | { |
||
216 | dispatcherTimer.Stop(); |
||
217 | } |
||
218 | |||
219 | base.Closed(); |
||
220 | } |
||
221 | |||
222 | |||
223 | #endregion |
||
224 | |||
225 | #region Function |
||
226 | |||
227 | #region RemoveCreateTimeFilter |
||
228 | |||
229 | public void RemoveCreateTimeFilter(object obj) |
||
230 | { |
||
231 | DefaultCreateTime = DateTime.Now; |
||
232 | SelectedCreateTimeBegin = DefaultCreateTime; |
||
233 | SelectedCreateTimeEnd = DefaultCreateTime; |
||
234 | } |
||
235 | |||
236 | #endregion |
||
237 | |||
238 | |||
239 | #region Data Select |
||
240 | |||
241 | /// <summary> |
||
242 | /// 상단 그리드 중앙 그리드 출력 데이터 |
||
243 | /// </summary> |
||
244 | private void DataSelect() |
||
245 | { |
||
246 | c7955b40 | semi | if (ConvertCOUNTDashBoard == null) |
247 | { |
||
248 | ConvertCOUNTDashBoard = new ObservableCollection<ConvertCOUNT>(); |
||
249 | } |
||
250 | if(FinalPDFCOUNTDashBoard == null) |
||
251 | 80391351 | semi | { |
252 | c7955b40 | semi | FinalPDFCOUNTDashBoard = new ObservableCollection<FinalPDFCOUNT>(); |
253 | 80391351 | semi | } |
254 | |||
255 | 2f07b70a | semi | if (SelectedStatus != null) |
256 | { |
||
257 | c7955b40 | semi | ConvertDataSelect(new[] { (ConvertPDF.StatusCodeType)(SelectedStatus.Value) }, ConvertCOUNTDashBoard); |
258 | FinalPDFDataSelect(new[] { (ConvertPDF.StatusCodeType)(SelectedStatus.Value) }, FinalPDFCOUNTDashBoard); |
||
259 | 2f07b70a | semi | } |
260 | } |
||
261 | |||
262 | 037ab674 | semi | private async void ConvertDataSelect(IEnumerable<ConvertPDF.StatusCodeType> statusCodeTypeList, ObservableCollection<ConvertCOUNT> collection) |
263 | 2f07b70a | semi | { |
264 | try |
||
265 | { |
||
266 | 037ab674 | semi | int _status = 0; |
267 | if (SelectedStatus != null) |
||
268 | 2f07b70a | semi | { |
269 | 037ab674 | semi | _status = (int)SelectedStatus.Value; |
270 | } |
||
271 | 2f07b70a | semi | |
272 | 037ab674 | semi | //DocumentID = unikey |
273 | DateTime? Start_CreateTime = null; |
||
274 | DateTime? Finish_CreateTime = null; |
||
275 | if (SelectedCreateTimeBegin != DefaultCreateTime) |
||
276 | { |
||
277 | Start_CreateTime = SelectedCreateTimeBegin; |
||
278 | } |
||
279 | if (SelectedCreateTimeEnd != DefaultCreateTime) |
||
280 | { |
||
281 | Finish_CreateTime = SelectedCreateTimeEnd; |
||
282 | } |
||
283 | 2f07b70a | semi | |
284 | 037ab674 | semi | var Listitems = from num in await WcfClient.GET_CONVERT_COUNTAsync(_status, Start_CreateTime, Finish_CreateTime) |
285 | select new ConvertCOUNT(num.PROJECT_NO, num.COUNT.Value, num.EXCEPTION_COUNT.Value); |
||
286 | 80391351 | semi | |
287 | 037ab674 | semi | if (collection.Count() == 0) |
288 | { |
||
289 | if (statusCodeTypeList.Count() == 1) |
||
290 | 80391351 | semi | { |
291 | 037ab674 | semi | foreach (var x in Listitems) |
292 | 80391351 | semi | { |
293 | 037ab674 | semi | collection.Add(x); |
294 | 80391351 | semi | } |
295 | } |
||
296 | 037ab674 | semi | } |
297 | else |
||
298 | { |
||
299 | |||
300 | //세미 업데이트 |
||
301 | foreach (var newitem in Listitems) |
||
302 | 80391351 | semi | { |
303 | 037ab674 | semi | collection.UpdateWhere(changeitem => |
304 | ConvertItemEx.ChangeValues(changeitem, newitem), x => x.Project_NO == newitem.Project_NO && x.Count == newitem.Count); |
||
305 | } |
||
306 | 80391351 | semi | |
307 | |||
308 | 037ab674 | semi | if (statusCodeTypeList.Count() == 1) |
309 | { |
||
310 | 80391351 | semi | |
311 | 037ab674 | semi | //삭제 |
312 | for (int i = collection.Count() - 1; i >= 0; --i) |
||
313 | 80391351 | semi | { |
314 | 037ab674 | semi | var item = collection[i]; |
315 | 80391351 | semi | |
316 | 037ab674 | semi | if (Listitems.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0) |
317 | 80391351 | semi | { |
318 | 037ab674 | semi | collection.RemoveAt(i); |
319 | 80391351 | semi | } |
320 | } |
||
321 | 037ab674 | semi | } |
322 | 80391351 | semi | |
323 | 037ab674 | semi | if (statusCodeTypeList.Count() == 1) |
324 | { |
||
325 | //추가 convert 후 추가됨 |
||
326 | foreach (var item in Listitems) |
||
327 | 2f07b70a | semi | { |
328 | 037ab674 | semi | if (collection.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0) |
329 | 80391351 | semi | { |
330 | 037ab674 | semi | for (int i = 0; i < 200; i++) |
331 | 80391351 | semi | { |
332 | 037ab674 | semi | collection.Add(item); |
333 | break; |
||
334 | 80391351 | semi | } |
335 | } |
||
336 | 2f07b70a | semi | } |
337 | } |
||
338 | } |
||
339 | 037ab674 | semi | |
340 | 2f07b70a | semi | } |
341 | catch (Exception ex) |
||
342 | { |
||
343 | MessageBox.Show(ex.ToString()); |
||
344 | } |
||
345 | } |
||
346 | |||
347 | 037ab674 | semi | private async void FinalPDFDataSelect(IEnumerable<ConvertPDF.StatusCodeType> statusCodeTypeList, ObservableCollection<FinalPDFCOUNT> collection) |
348 | c7955b40 | semi | { |
349 | try |
||
350 | { |
||
351 | |||
352 | 037ab674 | semi | int _status = 0; |
353 | if (SelectedStatus != null) |
||
354 | { |
||
355 | _status = (int)SelectedStatus.Value; |
||
356 | } |
||
357 | c7955b40 | semi | |
358 | 037ab674 | semi | //DocumentID = unikey |
359 | DateTime? Start_CreateTime = null; |
||
360 | DateTime? Finish_CreateTime = null; |
||
361 | if (SelectedCreateTimeBegin != DefaultCreateTime) |
||
362 | { |
||
363 | Start_CreateTime = SelectedCreateTimeBegin; |
||
364 | } |
||
365 | if (SelectedCreateTimeEnd != DefaultCreateTime) |
||
366 | { |
||
367 | Finish_CreateTime = SelectedCreateTimeEnd; |
||
368 | } |
||
369 | c7955b40 | semi | |
370 | 037ab674 | semi | var Listitems = from num in await WcfClient.GET_FINALPDF_COUNTAsync(_status, Start_CreateTime, Finish_CreateTime) |
371 | select new FinalPDFCOUNT(num.PROJECT_NO, num.COUNT.Value, num.EXCEPTION_COUNT.Value); |
||
372 | c7955b40 | semi | |
373 | 037ab674 | semi | if (collection.Count() == 0) |
374 | { |
||
375 | if (statusCodeTypeList.Count() == 1) |
||
376 | c7955b40 | semi | { |
377 | 037ab674 | semi | foreach (var x in Listitems) |
378 | c7955b40 | semi | { |
379 | 037ab674 | semi | collection.Add(x); |
380 | c7955b40 | semi | } |
381 | } |
||
382 | 037ab674 | semi | } |
383 | else |
||
384 | { |
||
385 | |||
386 | //세미 업데이트 |
||
387 | foreach (var newitem in Listitems) |
||
388 | c7955b40 | semi | { |
389 | 037ab674 | semi | collection.UpdateWhere(changeitem => |
390 | ConvertItemEx.ChangeValues(changeitem, newitem), x => x.Project_NO == newitem.Project_NO && x.Count == newitem.Count); |
||
391 | } |
||
392 | c7955b40 | semi | |
393 | |||
394 | 037ab674 | semi | if (statusCodeTypeList.Count() == 1) |
395 | { |
||
396 | c7955b40 | semi | |
397 | 037ab674 | semi | //삭제 |
398 | for (int i = collection.Count() - 1; i >= 0; --i) |
||
399 | c7955b40 | semi | { |
400 | 037ab674 | semi | var item = collection[i]; |
401 | c7955b40 | semi | |
402 | 037ab674 | semi | if (Listitems.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0) |
403 | c7955b40 | semi | { |
404 | 037ab674 | semi | collection.RemoveAt(i); |
405 | c7955b40 | semi | } |
406 | } |
||
407 | 037ab674 | semi | } |
408 | c7955b40 | semi | |
409 | 037ab674 | semi | if (statusCodeTypeList.Count() == 1) |
410 | { |
||
411 | //추가 convert 후 추가됨 |
||
412 | foreach (var item in Listitems) |
||
413 | c7955b40 | semi | { |
414 | 037ab674 | semi | if (collection.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0) |
415 | c7955b40 | semi | { |
416 | 037ab674 | semi | for (int i = 0; i < 200; i++) |
417 | c7955b40 | semi | { |
418 | 037ab674 | semi | collection.Add(item); |
419 | break; |
||
420 | c7955b40 | semi | } |
421 | } |
||
422 | } |
||
423 | } |
||
424 | 037ab674 | semi | |
425 | c7955b40 | semi | } |
426 | } |
||
427 | catch (Exception ex) |
||
428 | { |
||
429 | MessageBox.Show(ex.ToString()); |
||
430 | } |
||
431 | } |
||
432 | 2f07b70a | semi | #endregion |
433 | |||
434 | #endregion |
||
435 | } |
||
436 | } |