프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (8.82 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
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> _ExceptionCount;
96
        public ObservableCollection<ConvertCOUNT> ExceptionCount
97
        {
98
            get
99
            {
100
                if (_ExceptionCount == null)
101
                {
102
                    _ExceptionCount = new ObservableCollection<ConvertCOUNT>();
103
                }
104
                return _ExceptionCount;
105
            }
106
            set
107
            {
108
                _ExceptionCount = value;
109
                OnPropertyChanged(() => ExceptionCount);
110
            }
111
        }
112
113
114
        private ObservableCollection<ConvertCOUNT> _ConvertCount;
115
        public ObservableCollection<ConvertCOUNT> ConvertCount
116
        {
117
            get
118
            {
119
                if (_ConvertCount == null)
120
                {
121
                    _ConvertCount = new ObservableCollection<ConvertCOUNT>();
122
                }
123
                return _ConvertCount;
124
            }
125
            set
126
            {
127
                _ConvertCount = value;
128
                OnPropertyChanged(() => ConvertCount);
129
            }
130
        }
131
132
        private Telerik.Windows.Data.EnumMemberViewModel _SelectedStatus;
133
        public Telerik.Windows.Data.EnumMemberViewModel SelectedStatus
134
        {
135
            get => _SelectedStatus;
136
            set
137
            {
138
                _SelectedStatus = value;
139
                OnPropertyChanged(() => SelectedStatus);
140
            }
141
        }
142
143
        IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> _StatusCodeList;
144
        public IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> StatusCodeList
145
        {
146
            get
147
            {
148
                if (_StatusCodeList == null)
149
                {
150
                    _StatusCodeList = Telerik.Windows.Data.EnumDataSource.FromType<ConvertPDF.StatusCodeType>();
151
                }
152
153
                return _StatusCodeList;
154
            }
155
        }
156
157
        #endregion
158
159
        #region Command
160
161
        public DelegateCommand RemoveCreateTimeFilterCommand { get; private set; }
162
163
        #endregion
164
165
        #region Main Logic
166
167
        /// <summary>
168
        /// 각각의 Grid row 객체들 업데이트
169
        /// </summary>
170
171
        private DispatcherTimer dispatcherTimer;
172
        public override void Loaded()
173
        {
174
            base.Loaded();
175
176
            if (!App.IsDesignMode)
177
            {
178
                dispatcherTimer = new DispatcherTimer();
179
                dispatcherTimer.Tick += new EventHandler(Timer_Tick);
180
                dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
181
                dispatcherTimer.Start();
182
            }
183
        }
184
185
        private async void Timer_Tick(object sender, EventArgs e)
186
        {
187
            dispatcherTimer.Stop();
188
189
            if (IsAcitve)
190
            {
191
                await App.Current.Dispatcher.InvokeAsync(() =>
192
                {
193
                    DataSelect();
194
                });
195
            }
196
197
            //await Task.Delay(5000);
198
            await Task.Delay(10000);
199
200
            //System.Threading.Thread.Sleep(new TimeSpan(0,0,0,0,100));
201
202
            dispatcherTimer.Start();
203
        }
204
205
        public override void Closed()
206
        {
207
            if (dispatcherTimer != null)
208
            {
209
                dispatcherTimer.Stop();
210
            }
211
212
            base.Closed();
213
        }
214
215
216
        #endregion
217
218
        #region Function
219
220
        #region RemoveCreateTimeFilter
221
222
        public void RemoveCreateTimeFilter(object obj)
223
        {
224
            DefaultCreateTime = DateTime.Now;
225
            SelectedCreateTimeBegin = DefaultCreateTime;
226
            SelectedCreateTimeEnd = DefaultCreateTime;
227
        }
228
229
        #endregion
230
231
232
        #region Data Select
233
234
        /// <summary>
235
        /// 상단 그리드 중앙 그리드 출력 데이터
236
        /// </summary>
237
        private void DataSelect()
238
        {
239
            /// combobox 에서 선택된 items
240
            if (SelectedStatus != null)
241
            {
242
                DataSelect(new[] { (ConvertPDF.StatusCodeType)(SelectedStatus.Value) } );
243
            }
244
245
        }
246
247
        private void DataSelect(IEnumerable<ConvertPDF.StatusCodeType> statusCodeTypeList)
248
        {
249
            try
250
            {
251
                using (markusEntities entities = new markusEntities(App.MarkusDataBaseConnecitonString))
252
                {
253
                    int _status = 0;
254
                    if (SelectedStatus != null)
255
                    {
256
                        _status = (int)SelectedStatus.Value;
257
                    }
258
259
                    //DocumentID = unikey
260
                    DateTime? Start_CreateTime = null;
261
                    DateTime? Finish_CreateTime = null;
262
                    if (SelectedCreateTimeBegin != DefaultCreateTime)
263
                    {
264
                        Start_CreateTime = SelectedCreateTimeBegin;
265
                    }
266
                    if (SelectedCreateTimeEnd != DefaultCreateTime)
267
                    {
268
                        Finish_CreateTime = SelectedCreateTimeEnd;
269
                    }
270
271
                    var items = entities.SELECT_CONVERT_COUNT(_status, Start_CreateTime, Finish_CreateTime).ToList();
272
273
                    ObservableCollection<ConverCOUNT> Listitems = new ObservableCollection<ConverCOUNT>();
274
275
                    ExceptionCount.Clear();
276
                    ConvertCount.Clear();
277
                    for (int i=0; i<items.Count; i++)
278
                    {
279
                        if (i < items.Count / 2)
280
                        {
281
                            ConverCOUNT AddItem = new ConverCOUNT(items[i].PROJECT_NO, items[i].COUNT);
282
                            ExceptionCount.Add(AddItem);
283
                        }
284
                        else
285
                        {
286
                            ConverCOUNT AddItem = new ConverCOUNT(items[i].PROJECT_NO, items[i].COUNT);
287
                            ConvertCount.Add(AddItem);
288
                        }
289
                    }
290
                }
291
               
292
            }
293
            catch (Exception ex)
294
            {
295
                MessageBox.Show(ex.ToString());
296
                //System.Diagnostics.Debug.WriteLine(ex.ToString());
297
            }
298
        }
299
300
        #endregion
301
302
        #endregion
303
    }
304
}
클립보드 이미지 추가 (최대 크기: 500 MB)