프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (14.9 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
        static DateTime DefaultCreateTime = DateTime.Now;
35
        private DateTime _SelectedCreateTimeBegin = DefaultCreateTime;
36
        public DateTime SelectedCreateTimeBegin
37
        {
38

    
39
            get { return _SelectedCreateTimeBegin; }
40
            set
41
            {
42
                if (_SelectedCreateTimeBegin == value)
43
                    return;
44
                _SelectedCreateTimeBegin = value;
45
                OnPropertyChanged(() => SelectedCreateTimeBegin);
46

    
47
            }
48
        }
49

    
50
        private DateTime _SelectedCreateTimeEnd = DefaultCreateTime;
51
        public DateTime SelectedCreateTimeEnd
52
        {
53

    
54
            get { return _SelectedCreateTimeEnd; }
55
            set
56
            {
57
                if (_SelectedCreateTimeEnd == value)
58
                    return;
59
                _SelectedCreateTimeEnd = value;
60
                OnPropertyChanged(() => SelectedCreateTimeEnd);
61
            }
62
        }
63

    
64
        private SelectedCountItem _SelectedCount;
65
        public SelectedCountItem SelectedCount
66
        {
67
            get => _SelectedCount;
68
            set
69
            {
70
                _SelectedCount = value;
71
                OnPropertyChanged(() => SelectedCount);
72
            }
73
        }
74

    
75
        List<SelectedCountItem> _SelectedCountList;
76
        public List<SelectedCountItem> SelectedCountList
77
        {
78
            get
79
            {
80
                if (_SelectedCountList == null)
81
                {
82
                    _SelectedCountList = new List<SelectedCountItem>
83
                    {
84
                        new SelectedCountItem{DisplayMember = "50",ValueMember = 50},
85
                        new SelectedCountItem{DisplayMember = "100",ValueMember = 100},
86
                        new SelectedCountItem{DisplayMember = "150",ValueMember = 150},
87
                        new SelectedCountItem{DisplayMember = "200",ValueMember = 200}
88
                    };
89
                }
90

    
91
                return _SelectedCountList;
92
            }
93
        }
94

    
95
        private ObservableCollection<ConvertCOUNT> _ConvertCOUNTDashBoard;
96
        public ObservableCollection<ConvertCOUNT> ConvertCOUNTDashBoard
97
        {
98
            get
99
            {
100
                if (_ConvertCOUNTDashBoard == null)
101
                {
102
                    _ConvertCOUNTDashBoard = new ObservableCollection<ConvertCOUNT>();
103
                }
104
                return _ConvertCOUNTDashBoard;
105
            }
106
            set
107
            {
108
                if (_ConvertCOUNTDashBoard != value)
109
                {
110
                    _ConvertCOUNTDashBoard = value;
111
                    OnPropertyChanged(() => ConvertCOUNTDashBoard);
112
                }
113
            }
114
        }
115

    
116
        private ObservableCollection<FinalPDFCOUNT> _FinalPDFCOUNTDashBoard;
117
        public ObservableCollection<FinalPDFCOUNT> FinalPDFCOUNTDashBoard
118
        {
119
            get
120
            {
121
                if (_FinalPDFCOUNTDashBoard == null)
122
                {
123
                    _FinalPDFCOUNTDashBoard = new ObservableCollection<FinalPDFCOUNT>();
124
                }
125
                return _FinalPDFCOUNTDashBoard;
126
            }
127
            set
128
            {
129
                if (_FinalPDFCOUNTDashBoard != value)
130
                {
131
                    _FinalPDFCOUNTDashBoard = value;
132
                    OnPropertyChanged(() => FinalPDFCOUNTDashBoard);
133
                }
134
            }
135
        }
136

    
137
        private Telerik.Windows.Data.EnumMemberViewModel _SelectedStatus;
138
        public Telerik.Windows.Data.EnumMemberViewModel SelectedStatus
139
        {
140
            get => _SelectedStatus;
141
            set
142
            {
143
                _SelectedStatus = value;
144
                OnPropertyChanged(() => SelectedStatus);
145
            }
146
        }
147

    
148
        IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> _StatusCodeList;
149
        public IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> StatusCodeList
150
        {
151
            get
152
            {
153
                if (_StatusCodeList == null)
154
                {
155
                    _StatusCodeList = Telerik.Windows.Data.EnumDataSource.FromType<ConvertPDF.StatusCodeType>();
156
                }
157

    
158
                return _StatusCodeList;
159
            }
160
        }
161

    
162
        #endregion
163

    
164
        #region Command
165

    
166
        public DelegateCommand RemoveCreateTimeFilterCommand { get; private set; }
167

    
168
        #endregion
169

    
170
        #region Main Logic
171

    
172
        /// <summary>
173
        /// 각각의 Grid row 객체들 업데이트
174
        /// </summary>
175

    
176
        private DispatcherTimer dispatcherTimer;
177
        public override void Loaded()
178
        {
179
            base.Loaded();
180

    
181
            if (!App.IsDesignMode)
182
            {
183
                dispatcherTimer = new DispatcherTimer();
184
                dispatcherTimer.Tick += new EventHandler(Timer_Tick);
185
                dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
186
                dispatcherTimer.Start();
187
            }
188
        }
189

    
190
        private async void Timer_Tick(object sender, EventArgs e)
191
        {
192
            dispatcherTimer.Stop();
193

    
194
            if (IsAcitve)
195
            {
196
                await App.Current.Dispatcher.InvokeAsync(() =>
197
                {
198
                    DataSelect();
199
                });
200
            }
201

    
202
            //await Task.Delay(5000);
203
            await Task.Delay(10000);
204

    
205
            //System.Threading.Thread.Sleep(new TimeSpan(0,0,0,0,100));
206

    
207
            dispatcherTimer.Start();
208
        }
209

    
210
        public override void Closed()
211
        {
212
            if (dispatcherTimer != null)
213
            {
214
                dispatcherTimer.Stop();
215
            }
216

    
217
            base.Closed();
218
        }
219

    
220

    
221
        #endregion
222

    
223
        #region Function
224

    
225
        #region RemoveCreateTimeFilter
226

    
227
        public void RemoveCreateTimeFilter(object obj)
228
        {
229
            DefaultCreateTime = DateTime.Now;
230
            SelectedCreateTimeBegin = DefaultCreateTime;
231
            SelectedCreateTimeEnd = DefaultCreateTime;
232
        }
233

    
234
        #endregion
235

    
236

    
237
        #region Data Select
238

    
239
        /// <summary>
240
        /// 상단 그리드 중앙 그리드 출력 데이터
241
        /// </summary>
242
        private void DataSelect()
243
        {
244
            if (ConvertCOUNTDashBoard == null)
245
            {
246
                ConvertCOUNTDashBoard = new ObservableCollection<ConvertCOUNT>();
247
            }
248
            if(FinalPDFCOUNTDashBoard == null)
249
            {
250
                FinalPDFCOUNTDashBoard = new ObservableCollection<FinalPDFCOUNT>();
251
            }
252

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

    
260
        private void ConvertDataSelect(IEnumerable<ConvertPDF.StatusCodeType> statusCodeTypeList, ObservableCollection<ConvertCOUNT> collection)
261
        {
262
            try
263
            {
264
                using (markusEntities entities = new markusEntities(App.MarkusDataBaseConnecitonString))
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 items = entities.SELECT_CONVERT_COUNT(_status, Start_CreateTime, Finish_CreateTime).ToList();
285

    
286
                    List<ConvertCOUNT> Listitems = new List<ConvertCOUNT>();
287

    
288
                    for (int i = 0; i < items.Count; i++)
289
                    {
290
                        ConvertCOUNT AddItem = new ConvertCOUNT(items[i].PROJECT_NO, items[i].COUNT, items[i].EXCEPTION_COUNT);
291
                        Listitems.Add(AddItem);
292
                    }
293

    
294
                    if (collection.Count() == 0)
295
                    {
296
                        if (statusCodeTypeList.Count() == 1)
297
                        {
298
                            foreach (var x in Listitems)
299
                            {
300
                                collection.Add(x); 
301
                            }
302
                        }
303
                    }
304
                    else
305
                    {
306

    
307
                        //세미 업데이트
308
                        foreach (var newitem in Listitems)
309
                        {
310
                            collection.UpdateWhere(changeitem =>
311
                            ConvertItemEx.ChangeValues(changeitem, newitem), x => x.Project_NO == newitem.Project_NO && x.Count == newitem.Count);
312
                        }
313

    
314

    
315
                        if (statusCodeTypeList.Count() == 1)
316
                        {
317

    
318
                            //삭제
319
                            for (int i = collection.Count() - 1; i >= 0; --i)
320
                            {
321
                                var item = collection[i];
322

    
323
                                if (Listitems.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0)
324
                                {
325
                                    collection.RemoveAt(i);
326
                                }
327
                            }
328
                        }
329

    
330
                        if (statusCodeTypeList.Count() == 1)
331
                        {
332
                            //추가 convert 후 추가됨
333
                            foreach (var item in Listitems)
334
                            {
335
                                if (collection.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0)
336
                                {
337
                                    for (int i = 0; i < 200; i++)
338
                                    {
339
                                        collection.Add(item);
340
                                        break;
341
                                    }
342
                                }
343
                            }
344
                        }
345
                    }
346
                }
347
            }
348
            catch (Exception ex)
349
            {
350
                MessageBox.Show(ex.ToString());
351
            }
352
        }
353

    
354
        private void FinalPDFDataSelect(IEnumerable<ConvertPDF.StatusCodeType> statusCodeTypeList, ObservableCollection<FinalPDFCOUNT> collection)
355
        {
356
            try
357
            {
358
                using (markusEntities entities = new markusEntities(App.MarkusDataBaseConnecitonString))
359
                {
360
                    int _status = 0;
361
                    if (SelectedStatus != null)
362
                    {
363
                        _status = (int)SelectedStatus.Value;
364
                    }
365

    
366
                    //DocumentID = unikey
367
                    DateTime? Start_CreateTime = null;
368
                    DateTime? Finish_CreateTime = null;
369
                    if (SelectedCreateTimeBegin != DefaultCreateTime)
370
                    {
371
                        Start_CreateTime = SelectedCreateTimeBegin;
372
                    }
373
                    if (SelectedCreateTimeEnd != DefaultCreateTime)
374
                    {
375
                        Finish_CreateTime = SelectedCreateTimeEnd;
376
                    }
377

    
378
                    var items = entities.SELECT_FINALPDF_COUNT(_status, Start_CreateTime, Finish_CreateTime).ToList();
379

    
380
                    List<FinalPDFCOUNT> Listitems = new List<FinalPDFCOUNT>();
381

    
382
                    for (int i = 0; i < items.Count; i++)
383
                    {
384
                        FinalPDFCOUNT AddItem = new FinalPDFCOUNT(items[i].PROJECT_NO, items[i].COUNT, items[i].EXCEPTION_COUNT);
385
                        Listitems.Add(AddItem);
386
                    }
387

    
388
                    if (collection.Count() == 0)
389
                    {
390
                        if (statusCodeTypeList.Count() == 1)
391
                        {
392
                            foreach (var x in Listitems)
393
                            {
394
                                collection.Add(x);
395
                            }
396
                        }
397
                    }
398
                    else
399
                    {
400

    
401
                        //세미 업데이트
402
                        foreach (var newitem in Listitems)
403
                        {
404
                            collection.UpdateWhere(changeitem =>
405
                            ConvertItemEx.ChangeValues(changeitem, newitem), x => x.Project_NO == newitem.Project_NO && x.Count == newitem.Count);
406
                        }
407

    
408

    
409
                        if (statusCodeTypeList.Count() == 1)
410
                        {
411

    
412
                            //삭제
413
                            for (int i = collection.Count() - 1; i >= 0; --i)
414
                            {
415
                                var item = collection[i];
416

    
417
                                if (Listitems.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0)
418
                                {
419
                                    collection.RemoveAt(i);
420
                                }
421
                            }
422
                        }
423

    
424
                        if (statusCodeTypeList.Count() == 1)
425
                        {
426
                            //추가 convert 후 추가됨
427
                            foreach (var item in Listitems)
428
                            {
429
                                if (collection.Count(x => x.Project_NO == item.Project_NO && x.Count == item.Count) == 0)
430
                                {
431
                                    for (int i = 0; i < 200; i++)
432
                                    {
433
                                        collection.Add(item);
434
                                        break;
435
                                    }
436
                                }
437
                            }
438
                        }
439
                    }
440
                }
441
            }
442
            catch (Exception ex)
443
            {
444
                MessageBox.Show(ex.ToString());
445
            }
446
        }
447
        #endregion
448

    
449
        #endregion
450
    }
451
}
클립보드 이미지 추가 (최대 크기: 500 MB)