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