프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DashBoardViewModel.cs @ cb806a91

이력 | 보기 | 이력해설 | 다운로드 (13.3 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(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
            if (ConvertCOUNTDashBoard == null)
244
            {
245
                ConvertCOUNTDashBoard = new ObservableCollection<ConvertCOUNT>();
246
            }
247
            if(FinalPDFCOUNTDashBoard == null)
248
            {
249
                FinalPDFCOUNTDashBoard = new ObservableCollection<FinalPDFCOUNT>();
250
            }
251

    
252
            if (SelectedStatus != null)
253
            {
254
                ConvertDataSelect(new[] { (ConvertPDF.StatusCodeType)(SelectedStatus.Value) }, ConvertCOUNTDashBoard);
255
                FinalPDFDataSelect(new[] { (ConvertPDF.StatusCodeType)(SelectedStatus.Value) }, FinalPDFCOUNTDashBoard);
256
            }
257
        }
258

    
259
        private async void ConvertDataSelect(IEnumerable<ConvertPDF.StatusCodeType> statusCodeTypeList, ObservableCollection<ConvertCOUNT> collection)
260
        {
261
            try
262
            {
263
                int _status = 0;
264
                if (SelectedStatus != null)
265
                {
266
                    _status = (int)SelectedStatus.Value;
267
                }
268

    
269
                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

    
280
                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

    
283
                if (collection.Count() == 0)
284
                {
285
                    if (statusCodeTypeList.Count() == 1)
286
                    {
287
                        foreach (var x in Listitems)
288
                        {
289
                            collection.Add(x);
290
                        }
291
                    }
292
                }
293
                else
294
                {
295
                    foreach (var newitem in Listitems)
296
                    {
297
                        collection.UpdateWhere(changeitem =>
298
                        ConvertItemEx.ChangeValues(changeitem, newitem), x => x.Project_NO == newitem.Project_NO && x.Count == newitem.Count);
299
                    }
300

    
301

    
302
                    if (statusCodeTypeList.Count() == 1)
303
                    {
304

    
305
                        for (int i = collection.Count() - 1; i >= 0; --i)
306
                        {
307
                            var item = collection[i];
308

    
309
                            if (Listitems.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0)
310
                            {
311
                                collection.RemoveAt(i);
312
                            }
313
                        }
314
                    }
315

    
316
                    if (statusCodeTypeList.Count() == 1)
317
                    {
318
                        foreach (var item in Listitems)
319
                        {
320
                            if (collection.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0)
321
                            {
322
                                for (int i = 0; i < 200; i++)
323
                                {
324
                                    collection.Add(item);
325
                                    break;
326
                                }
327
                            }
328
                        }
329
                    }
330
                }
331

    
332
            }
333
            catch (Exception ex)
334
            {
335
                MessageBox.Show(ex.ToString());
336
            }
337
        }
338

    
339
        private async void FinalPDFDataSelect(IEnumerable<ConvertPDF.StatusCodeType> statusCodeTypeList, ObservableCollection<FinalPDFCOUNT> collection)
340
        {
341
            try
342
            {
343

    
344
                int _status = 0;
345
                if (SelectedStatus != null)
346
                {
347
                    _status = (int)SelectedStatus.Value;
348
                }
349

    
350
                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

    
361
                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

    
364
                if (collection.Count() == 0)
365
                {
366
                    if (statusCodeTypeList.Count() == 1)
367
                    {
368
                        foreach (var x in Listitems)
369
                        {
370
                            collection.Add(x);
371
                        }
372
                    }
373
                }
374
                else
375
                {
376
                    foreach (var newitem in Listitems)
377
                    {
378
                        collection.UpdateWhere(changeitem =>
379
                        ConvertItemEx.ChangeValues(changeitem, newitem), x => x.Project_NO == newitem.Project_NO && x.Count == newitem.Count);
380
                    }
381

    
382

    
383
                    if (statusCodeTypeList.Count() == 1)
384
                    {
385
                        for (int i = collection.Count() - 1; i >= 0; --i)
386
                        {
387
                            var item = collection[i];
388

    
389
                            if (Listitems.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0)
390
                            {
391
                                collection.RemoveAt(i);
392
                            }
393
                        }
394
                    }
395

    
396
                    if (statusCodeTypeList.Count() == 1)
397
                    {
398
                        foreach (var item in Listitems)
399
                        {
400
                            if (collection.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0)
401
                            {
402
                                for (int i = 0; i < 200; i++)
403
                                {
404
                                    collection.Add(item);
405
                                    break;
406
                                }
407
                            }
408
                        }
409
                    }
410

    
411
                }
412
            }
413
            catch (Exception ex)
414
            {
415
                MessageBox.Show(ex.ToString());
416
            }
417
        }
418
        #endregion
419

    
420
        #endregion
421
    }
422
}
클립보드 이미지 추가 (최대 크기: 500 MB)