markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DashBoardViewModel.cs @ 037ab674
이력 | 보기 | 이력해설 | 다운로드 (13.8 KB)
1 |
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 |
using System.Collections.ObjectModel; |
17 |
|
18 |
namespace Markus.Service.StationController.ViewModel |
19 |
{ |
20 |
class DashBoardViewModel : Mvvm.ToolKit.ViewModelBase |
21 |
{ |
22 |
#region Constructor |
23 |
|
24 |
|
25 |
public DashBoardViewModel() |
26 |
{ |
27 |
RemoveCreateTimeFilterCommand = new DelegateCommand(RemoveCreateTimeFilter); |
28 |
} |
29 |
|
30 |
#endregion |
31 |
|
32 |
#region Properties |
33 |
|
34 |
DataService.DataServiceClient WcfClient = new DataService.DataServiceClient(); |
35 |
|
36 |
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 |
private ObservableCollection<ConvertCOUNT> _ConvertCOUNTDashBoard; |
98 |
public ObservableCollection<ConvertCOUNT> ConvertCOUNTDashBoard |
99 |
{ |
100 |
get |
101 |
{ |
102 |
if (_ConvertCOUNTDashBoard == null) |
103 |
{ |
104 |
_ConvertCOUNTDashBoard = new ObservableCollection<ConvertCOUNT>(); |
105 |
} |
106 |
return _ConvertCOUNTDashBoard; |
107 |
} |
108 |
set |
109 |
{ |
110 |
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 |
} |
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 |
if (ConvertCOUNTDashBoard == null) |
247 |
{ |
248 |
ConvertCOUNTDashBoard = new ObservableCollection<ConvertCOUNT>(); |
249 |
} |
250 |
if(FinalPDFCOUNTDashBoard == null) |
251 |
{ |
252 |
FinalPDFCOUNTDashBoard = new ObservableCollection<FinalPDFCOUNT>(); |
253 |
} |
254 |
|
255 |
if (SelectedStatus != null) |
256 |
{ |
257 |
ConvertDataSelect(new[] { (ConvertPDF.StatusCodeType)(SelectedStatus.Value) }, ConvertCOUNTDashBoard); |
258 |
FinalPDFDataSelect(new[] { (ConvertPDF.StatusCodeType)(SelectedStatus.Value) }, FinalPDFCOUNTDashBoard); |
259 |
} |
260 |
} |
261 |
|
262 |
private async void ConvertDataSelect(IEnumerable<ConvertPDF.StatusCodeType> statusCodeTypeList, ObservableCollection<ConvertCOUNT> collection) |
263 |
{ |
264 |
try |
265 |
{ |
266 |
int _status = 0; |
267 |
if (SelectedStatus != null) |
268 |
{ |
269 |
_status = (int)SelectedStatus.Value; |
270 |
} |
271 |
|
272 |
//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 |
|
284 |
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 |
|
287 |
if (collection.Count() == 0) |
288 |
{ |
289 |
if (statusCodeTypeList.Count() == 1) |
290 |
{ |
291 |
foreach (var x in Listitems) |
292 |
{ |
293 |
collection.Add(x); |
294 |
} |
295 |
} |
296 |
} |
297 |
else |
298 |
{ |
299 |
|
300 |
//세미 업데이트 |
301 |
foreach (var newitem in Listitems) |
302 |
{ |
303 |
collection.UpdateWhere(changeitem => |
304 |
ConvertItemEx.ChangeValues(changeitem, newitem), x => x.Project_NO == newitem.Project_NO && x.Count == newitem.Count); |
305 |
} |
306 |
|
307 |
|
308 |
if (statusCodeTypeList.Count() == 1) |
309 |
{ |
310 |
|
311 |
//삭제 |
312 |
for (int i = collection.Count() - 1; i >= 0; --i) |
313 |
{ |
314 |
var item = collection[i]; |
315 |
|
316 |
if (Listitems.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0) |
317 |
{ |
318 |
collection.RemoveAt(i); |
319 |
} |
320 |
} |
321 |
} |
322 |
|
323 |
if (statusCodeTypeList.Count() == 1) |
324 |
{ |
325 |
//추가 convert 후 추가됨 |
326 |
foreach (var item in Listitems) |
327 |
{ |
328 |
if (collection.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0) |
329 |
{ |
330 |
for (int i = 0; i < 200; i++) |
331 |
{ |
332 |
collection.Add(item); |
333 |
break; |
334 |
} |
335 |
} |
336 |
} |
337 |
} |
338 |
} |
339 |
|
340 |
} |
341 |
catch (Exception ex) |
342 |
{ |
343 |
MessageBox.Show(ex.ToString()); |
344 |
} |
345 |
} |
346 |
|
347 |
private async void FinalPDFDataSelect(IEnumerable<ConvertPDF.StatusCodeType> statusCodeTypeList, ObservableCollection<FinalPDFCOUNT> collection) |
348 |
{ |
349 |
try |
350 |
{ |
351 |
|
352 |
int _status = 0; |
353 |
if (SelectedStatus != null) |
354 |
{ |
355 |
_status = (int)SelectedStatus.Value; |
356 |
} |
357 |
|
358 |
//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 |
|
370 |
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 |
|
373 |
if (collection.Count() == 0) |
374 |
{ |
375 |
if (statusCodeTypeList.Count() == 1) |
376 |
{ |
377 |
foreach (var x in Listitems) |
378 |
{ |
379 |
collection.Add(x); |
380 |
} |
381 |
} |
382 |
} |
383 |
else |
384 |
{ |
385 |
|
386 |
//세미 업데이트 |
387 |
foreach (var newitem in Listitems) |
388 |
{ |
389 |
collection.UpdateWhere(changeitem => |
390 |
ConvertItemEx.ChangeValues(changeitem, newitem), x => x.Project_NO == newitem.Project_NO && x.Count == newitem.Count); |
391 |
} |
392 |
|
393 |
|
394 |
if (statusCodeTypeList.Count() == 1) |
395 |
{ |
396 |
|
397 |
//삭제 |
398 |
for (int i = collection.Count() - 1; i >= 0; --i) |
399 |
{ |
400 |
var item = collection[i]; |
401 |
|
402 |
if (Listitems.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0) |
403 |
{ |
404 |
collection.RemoveAt(i); |
405 |
} |
406 |
} |
407 |
} |
408 |
|
409 |
if (statusCodeTypeList.Count() == 1) |
410 |
{ |
411 |
//추가 convert 후 추가됨 |
412 |
foreach (var item in Listitems) |
413 |
{ |
414 |
if (collection.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0) |
415 |
{ |
416 |
for (int i = 0; i < 200; i++) |
417 |
{ |
418 |
collection.Add(item); |
419 |
break; |
420 |
} |
421 |
} |
422 |
} |
423 |
} |
424 |
|
425 |
} |
426 |
} |
427 |
catch (Exception ex) |
428 |
{ |
429 |
MessageBox.Show(ex.ToString()); |
430 |
} |
431 |
} |
432 |
#endregion |
433 |
|
434 |
#endregion |
435 |
} |
436 |
} |