markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseItemsModel.cs @ b63dcfbb
이력 | 보기 | 이력해설 | 다운로드 (43.3 KB)
1 |
using Markus.Message; |
---|---|
2 |
using Markus.Service.DataBase; |
3 |
using Markus.Service.Extensions; |
4 |
using Markus.Service.StationController.Data; |
5 |
using Markus.Service.StationController.Behaviors; |
6 |
using Markus.Service.StationController.Extensions; |
7 |
using Markus.Service.StationController.Controls; |
8 |
using Microsoft.Win32; |
9 |
using System; |
10 |
using System.Collections.Generic; |
11 |
using System.ComponentModel; |
12 |
using System.Linq; |
13 |
using System.Threading.Tasks; |
14 |
using System.Web; |
15 |
using System.Windows; |
16 |
using Telerik.Windows.Controls; |
17 |
using Telerik.Windows.Data; |
18 |
using ConvertItem = Markus.Service.Interface.ConvertItem; |
19 |
using System.Net; |
20 |
using System.Windows.Threading; |
21 |
using System.Diagnostics; |
22 |
using System.Windows.Input; |
23 |
using Markus.Mvvm.ToolKit; |
24 |
using System.Windows.Data; |
25 |
|
26 |
namespace Markus.Service.StationController.ViewModel |
27 |
{ |
28 |
//세미 |
29 |
public class DataBaseItemsModel : Mvvm.ToolKit.ViewModelBase |
30 |
{ |
31 |
#region Constructor |
32 |
|
33 |
/// <summary> |
34 |
/// 실행하면 처음 들어가는 부분 |
35 |
/// </summary> |
36 |
public DataBaseItemsModel() |
37 |
{ |
38 |
DataFilterCommand = new DelegateCommand(DataFilter); |
39 |
DataSaveFileGemBoxCommand = new DelegateCommand(DataExportData); |
40 |
ConvertCommand = new DelegateCommand(DataConvert); |
41 |
DeleteCommand = new DelegateCommand(DataDelete); |
42 |
ValidateCommand = new DelegateCommand(DataValidate); |
43 |
MarkusLinkCommand = new DelegateCommand(MarkusLink); |
44 |
RemoveCreateTimeFilterCommand = new DelegateCommand(RemoveCreateTimeFilter); |
45 |
FilterConvertSourceView.Filter = new Predicate<object>(o => DetailFilter(o as ConvertItem)); |
46 |
ResetCommand = new DelegateCommand(Reset); |
47 |
} |
48 |
|
49 |
#endregion |
50 |
|
51 |
#region Properties |
52 |
|
53 |
private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _FilterSearch; |
54 |
public System.Collections.ObjectModel.ObservableCollection<ConvertItem> FilterSearch |
55 |
{ |
56 |
get |
57 |
{ |
58 |
if (_FilterSearch == null) |
59 |
{ |
60 |
_FilterSearch = new System.Collections.ObjectModel.ObservableCollection<ConvertItem> |
61 |
{ |
62 |
new ConvertItem{ProjectNumber = "Filter Search"} |
63 |
}; |
64 |
} |
65 |
|
66 |
return _FilterSearch; |
67 |
} |
68 |
} |
69 |
|
70 |
private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _AliveItems; |
71 |
public System.Collections.ObjectModel.ObservableCollection<ConvertItem> AliveItems |
72 |
{ |
73 |
get => _AliveItems; |
74 |
set |
75 |
{ |
76 |
_AliveItems = value; |
77 |
OnPropertyChanged(() => AliveItems); |
78 |
} |
79 |
} |
80 |
|
81 |
public ICollectionView FilterConvertSourceView |
82 |
{ |
83 |
get |
84 |
{ |
85 |
var view = CollectionViewSource.GetDefaultView(FilterConvertSource); |
86 |
//if (view.CanFilter) |
87 |
//{ |
88 |
// view.Filter = DetailFilter; |
89 |
// view.Filter = o => String.IsNullOrEmpty(ProjectNumberFilter) ? true : ((string)o).Contains(ProjectNumberFilter); |
90 |
// view.Filter = o => String.IsNullOrEmpty(UniqueKeyFilter) ? true : ((string)o).Contains(UniqueKeyFilter); |
91 |
//} |
92 |
return view; |
93 |
} |
94 |
} |
95 |
|
96 |
private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _FilterConvertSource; |
97 |
public System.Collections.ObjectModel.ObservableCollection<ConvertItem> FilterConvertSource |
98 |
{ |
99 |
//get => _FilterConvertSource; |
100 |
get |
101 |
{ |
102 |
if (_FilterConvertSource == null) |
103 |
{ |
104 |
_FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
105 |
} |
106 |
//if (_FilterConvertSource != null) |
107 |
//{ |
108 |
// var view = CollectionViewSource.GetDefaultView(FilterConvertSource); |
109 |
// if (view.CanFilter) |
110 |
// { |
111 |
// view.Filter = DetailFilter; |
112 |
// } |
113 |
//} |
114 |
return _FilterConvertSource; |
115 |
} |
116 |
set |
117 |
{ |
118 |
_FilterConvertSource = value; |
119 |
OnPropertyChanged(() => FilterConvertSource); |
120 |
} |
121 |
} |
122 |
|
123 |
|
124 |
private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _RealConvertSource; |
125 |
public System.Collections.ObjectModel.ObservableCollection<ConvertItem> RealConvertSource |
126 |
{ |
127 |
get => _RealConvertSource; |
128 |
set |
129 |
{ |
130 |
_RealConvertSource = value; |
131 |
OnPropertyChanged(() => RealConvertSource); |
132 |
} |
133 |
} |
134 |
|
135 |
|
136 |
private System.Windows.Documents.FlowDocument connectionLog; |
137 |
public System.Windows.Documents.FlowDocument ConnectionLog |
138 |
{ |
139 |
get => connectionLog; |
140 |
set |
141 |
{ |
142 |
if (connectionLog != value) |
143 |
{ |
144 |
connectionLog = value; |
145 |
OnPropertyChanged(() => ConnectionLog); |
146 |
} |
147 |
} |
148 |
} |
149 |
|
150 |
|
151 |
private Telerik.Windows.Data.EnumMemberViewModel _SelectedStatus; |
152 |
public Telerik.Windows.Data.EnumMemberViewModel SelectedStatus |
153 |
{ |
154 |
get => _SelectedStatus; |
155 |
set |
156 |
{ |
157 |
_SelectedStatus = value; |
158 |
OnPropertyChanged(() => SelectedStatus); |
159 |
} |
160 |
} |
161 |
|
162 |
|
163 |
private SelectedCountItem _SelectedCount; |
164 |
public SelectedCountItem SelectedCount |
165 |
{ |
166 |
get => _SelectedCount; |
167 |
set |
168 |
{ |
169 |
_SelectedCount = value; |
170 |
OnPropertyChanged(() => SelectedCount); |
171 |
} |
172 |
} |
173 |
|
174 |
List<SelectedCountItem> _SelectedCountList; |
175 |
public List<SelectedCountItem> SelectedCountList |
176 |
{ |
177 |
get |
178 |
{ |
179 |
if (_SelectedCountList == null) |
180 |
{ |
181 |
_SelectedCountList = new List<SelectedCountItem> |
182 |
{ |
183 |
new SelectedCountItem{DisplayMember = "50",ValueMember = 50}, |
184 |
new SelectedCountItem{DisplayMember = "100",ValueMember = 100}, |
185 |
new SelectedCountItem{DisplayMember = "150",ValueMember = 150}, |
186 |
new SelectedCountItem{DisplayMember = "200",ValueMember = 200} |
187 |
}; |
188 |
} |
189 |
|
190 |
return _SelectedCountList; |
191 |
} |
192 |
} |
193 |
|
194 |
private ConvertItem _SelectFilterConvert; |
195 |
public ConvertItem SelectFilterConvert |
196 |
{ |
197 |
get => _SelectFilterConvert; |
198 |
set |
199 |
{ |
200 |
_SelectFilterConvert = value; |
201 |
OnPropertyChanged(() => SelectFilterConvert); |
202 |
} |
203 |
} |
204 |
|
205 |
private ConvertItem _SelectRealConvert; |
206 |
public ConvertItem SelectRealConvert |
207 |
{ |
208 |
get => _SelectRealConvert; |
209 |
set |
210 |
{ |
211 |
_SelectRealConvert = value; |
212 |
OnPropertyChanged(() => SelectRealConvert); |
213 |
} |
214 |
} |
215 |
|
216 |
|
217 |
private StatusTypeList _StatusType; |
218 |
public StatusTypeList StatusType |
219 |
{ |
220 |
get => _StatusType; |
221 |
set |
222 |
{ |
223 |
_StatusType = value; |
224 |
OnPropertyChanged(() => StatusType); |
225 |
} |
226 |
} |
227 |
|
228 |
private bool _IsLoading; |
229 |
public bool IsLoading |
230 |
{ |
231 |
get => _IsLoading; |
232 |
set |
233 |
{ |
234 |
if (_IsLoading != value) |
235 |
{ |
236 |
_IsLoading = value; |
237 |
OnPropertyChanged(() => IsLoading); |
238 |
} |
239 |
} |
240 |
} |
241 |
|
242 |
IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> _StatusCodeList; |
243 |
public IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> StatusCodeList |
244 |
{ |
245 |
get |
246 |
{ |
247 |
if (_StatusCodeList == null) |
248 |
{ |
249 |
_StatusCodeList = Telerik.Windows.Data.EnumDataSource.FromType<StatusCodeType>(); |
250 |
} |
251 |
|
252 |
return _StatusCodeList; |
253 |
} |
254 |
} |
255 |
|
256 |
public bool _ConvertShow; |
257 |
public bool ConvertShow |
258 |
{ |
259 |
get => _ConvertShow; |
260 |
set |
261 |
{ |
262 |
if (_ConvertShow = !value) |
263 |
{ |
264 |
_ConvertShow = false; |
265 |
} |
266 |
_ConvertShow = value; |
267 |
OnPropertyChanged(() => ConvertShow); |
268 |
} |
269 |
} |
270 |
|
271 |
public string _ProjectNumberFilter; |
272 |
public string ProjectNumberFilter |
273 |
{ |
274 |
get { return _ProjectNumberFilter; } |
275 |
set |
276 |
{ |
277 |
if(_ProjectNumberFilter == "") |
278 |
{ |
279 |
_ProjectNumberFilter = null; |
280 |
} |
281 |
else if (_ProjectNumberFilter != value) |
282 |
{ |
283 |
_ProjectNumberFilter = value; |
284 |
OnPropertyChanged(() => ProjectNumberFilter); |
285 |
//CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
286 |
FilterConvertSourceView.Refresh(); |
287 |
} |
288 |
} |
289 |
} |
290 |
|
291 |
public string _UniqueKeyFilter; |
292 |
public string UniqueKeyFilter |
293 |
{ |
294 |
get |
295 |
{ |
296 |
return _UniqueKeyFilter; |
297 |
} |
298 |
set |
299 |
{ |
300 |
if (_UniqueKeyFilter == "") |
301 |
{ |
302 |
_UniqueKeyFilter = null; |
303 |
} |
304 |
else if (_UniqueKeyFilter != value) |
305 |
{ |
306 |
_UniqueKeyFilter = value; |
307 |
OnPropertyChanged(() => UniqueKeyFilter); |
308 |
//CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
309 |
FilterConvertSourceView.Refresh(); |
310 |
} |
311 |
} |
312 |
} |
313 |
|
314 |
public StatusCodeType _ConvertStateFilter; |
315 |
public StatusCodeType ConvertStateFilter |
316 |
{ |
317 |
get { return _ConvertStateFilter; } |
318 |
set |
319 |
{ |
320 |
if (_ConvertStateFilter != value) |
321 |
{ |
322 |
_ConvertStateFilter = value; |
323 |
OnPropertyChanged(() => ConvertStateFilter); |
324 |
//CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
325 |
FilterConvertSourceView.Refresh(); |
326 |
} |
327 |
} |
328 |
} |
329 |
|
330 |
public string _Docuemnt_NOFilter; |
331 |
public string Docuemnt_NOFilter |
332 |
{ |
333 |
get { return _Docuemnt_NOFilter; } |
334 |
set |
335 |
{ |
336 |
if (_Docuemnt_NOFilter == "") |
337 |
{ |
338 |
_Docuemnt_NOFilter = null; |
339 |
} |
340 |
else if (_Docuemnt_NOFilter != value) |
341 |
{ |
342 |
_Docuemnt_NOFilter = value; |
343 |
OnPropertyChanged(() => Docuemnt_NOFilter); |
344 |
//CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
345 |
FilterConvertSourceView.Refresh(); |
346 |
} |
347 |
} |
348 |
} |
349 |
|
350 |
public string _Docuemnt_NameFilter; |
351 |
public string Docuemnt_NameFilter |
352 |
{ |
353 |
get { return _Docuemnt_NameFilter; } |
354 |
set |
355 |
{ |
356 |
if (_Docuemnt_NameFilter == "") |
357 |
{ |
358 |
_Docuemnt_NameFilter = null; |
359 |
} |
360 |
else if (_Docuemnt_NameFilter != value) |
361 |
{ |
362 |
_Docuemnt_NameFilter = value; |
363 |
OnPropertyChanged(() => Docuemnt_NameFilter); |
364 |
//CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
365 |
FilterConvertSourceView.Refresh(); |
366 |
} |
367 |
} |
368 |
} |
369 |
|
370 |
public int? _ReconverterFilter = 0; |
371 |
public int? ReconverterFilter |
372 |
{ |
373 |
get { return _ReconverterFilter; } |
374 |
set |
375 |
{ |
376 |
if (_ReconverterFilter == null) |
377 |
{ |
378 |
_ReconverterFilter = 0; |
379 |
} |
380 |
else if (_ReconverterFilter != value) |
381 |
{ |
382 |
_ReconverterFilter = value; |
383 |
OnPropertyChanged(() => ReconverterFilter); |
384 |
//CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
385 |
FilterConvertSourceView.Refresh(); |
386 |
|
387 |
} |
388 |
} |
389 |
} |
390 |
|
391 |
public string _Service_IDFilter; |
392 |
public string Service_IDFilter |
393 |
{ |
394 |
get { return _Service_IDFilter; } |
395 |
set |
396 |
{ |
397 |
if (_Service_IDFilter == "") |
398 |
{ |
399 |
_Service_IDFilter = null; |
400 |
} |
401 |
else if (_Service_IDFilter != value) |
402 |
{ |
403 |
_Service_IDFilter = value; |
404 |
OnPropertyChanged(() => Service_IDFilter); |
405 |
//CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
406 |
FilterConvertSourceView.Refresh(); |
407 |
} |
408 |
} |
409 |
} |
410 |
|
411 |
public string _RevisionFilter; |
412 |
public string RevisionFilter |
413 |
{ |
414 |
get { return _RevisionFilter; } |
415 |
set |
416 |
{ |
417 |
if (_RevisionFilter == "") |
418 |
{ |
419 |
_RevisionFilter = null ; |
420 |
} |
421 |
else if (_RevisionFilter != value) |
422 |
{ |
423 |
_RevisionFilter = value; |
424 |
OnPropertyChanged(() => RevisionFilter); |
425 |
//CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
426 |
FilterConvertSourceView.Refresh(); |
427 |
} |
428 |
} |
429 |
} |
430 |
|
431 |
static DateTime DefaultCreateTime = DateTime.Now; |
432 |
private DateTime _SelectedCreateTimeBegin = DefaultCreateTime; |
433 |
public DateTime SelectedCreateTimeBegin |
434 |
{ |
435 |
|
436 |
get { return _SelectedCreateTimeBegin; } |
437 |
set |
438 |
{ |
439 |
if (_SelectedCreateTimeBegin == value) |
440 |
return; |
441 |
_SelectedCreateTimeBegin = value; |
442 |
OnPropertyChanged(() => SelectedCreateTimeBegin); |
443 |
//CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
444 |
FilterConvertSourceView.Refresh(); |
445 |
//AddGeneratorBeginFilter(); |
446 |
|
447 |
} |
448 |
} |
449 |
|
450 |
private DateTime _SelectedCreateTimeEnd = DefaultCreateTime; |
451 |
public DateTime SelectedCreateTimeEnd |
452 |
{ |
453 |
|
454 |
get { return _SelectedCreateTimeEnd; } |
455 |
set |
456 |
{ |
457 |
if (_SelectedCreateTimeEnd == value) |
458 |
return; |
459 |
_SelectedCreateTimeEnd = value; |
460 |
OnPropertyChanged(() => SelectedCreateTimeEnd); |
461 |
//CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
462 |
FilterConvertSourceView.Refresh(); |
463 |
//AddGeneratorBeginFilter(); |
464 |
|
465 |
} |
466 |
} |
467 |
|
468 |
private string _Click = "Click"; |
469 |
public string Click |
470 |
{ |
471 |
|
472 |
get { return _Click; } |
473 |
} |
474 |
#endregion |
475 |
|
476 |
#region Command |
477 |
|
478 |
public DelegateCommand ConvertCommand { get; private set; } |
479 |
public DelegateCommand DeleteCommand { get; private set; } |
480 |
public DelegateCommand ValidateCommand { get; private set; } |
481 |
public DelegateCommand DataSaveFileGemBoxCommand { get; private set; } |
482 |
public DelegateCommand MarkusLinkCommand { get; private set; } |
483 |
public DelegateCommand RemoveCreateTimeFilterCommand { get; private set; } |
484 |
|
485 |
public DelegateCommand DataFilterCommand { get; private set; } |
486 |
public DelegateCommand ResetCommand { get; private set; } |
487 |
|
488 |
#endregion |
489 |
|
490 |
#region Main Logic |
491 |
|
492 |
/// <summary> |
493 |
/// 각각의 Grid row 객체들 업데이트 |
494 |
/// </summary> |
495 |
|
496 |
private DispatcherTimer dispatcherTimer; |
497 |
public override void Loaded() |
498 |
{ |
499 |
base.Loaded(); |
500 |
|
501 |
if (!App.IsDesignMode) |
502 |
{ |
503 |
dispatcherTimer = new DispatcherTimer(); |
504 |
dispatcherTimer.Tick += new EventHandler(Timer_Tick); |
505 |
dispatcherTimer.Interval = new TimeSpan(0, 0, 1); |
506 |
dispatcherTimer.Start(); |
507 |
} |
508 |
} |
509 |
|
510 |
private async void Timer_Tick(object sender, EventArgs e) |
511 |
{ |
512 |
dispatcherTimer.Stop(); |
513 |
|
514 |
if (IsAcitve) |
515 |
{ |
516 |
await App.Current.Dispatcher.InvokeAsync(() => |
517 |
{ |
518 |
DataSelect(); |
519 |
|
520 |
AliveDataSelect(); |
521 |
}); |
522 |
} |
523 |
|
524 |
await Task.Delay(5000); |
525 |
|
526 |
//System.Threading.Thread.Sleep(new TimeSpan(0,0,0,0,100)); |
527 |
|
528 |
dispatcherTimer.Start(); |
529 |
} |
530 |
|
531 |
public override void Closed() |
532 |
{ |
533 |
if (dispatcherTimer != null) |
534 |
{ |
535 |
dispatcherTimer.Stop(); |
536 |
} |
537 |
|
538 |
base.Closed(); |
539 |
} |
540 |
|
541 |
|
542 |
#endregion |
543 |
|
544 |
#region Function |
545 |
|
546 |
#region Data Select |
547 |
|
548 |
/// <summary> |
549 |
/// 상단 그리드 중앙 그리드 출력 데이터 |
550 |
/// </summary> |
551 |
private void DataSelect() |
552 |
{ |
553 |
|
554 |
if (FilterConvertSource == null) |
555 |
{ |
556 |
FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
557 |
} |
558 |
|
559 |
if (RealConvertSource == null) |
560 |
{ |
561 |
RealConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
562 |
} |
563 |
|
564 |
/// combobox 에서 선택된 items |
565 |
if (SelectedStatus != null) |
566 |
{ |
567 |
DataSelect(new[] { (StatusCodeType)(SelectedStatus.Value) }, FilterConvertSource); |
568 |
} |
569 |
|
570 |
/// 컨버터중인 items |
571 |
RealDataSelect(new[] { StatusCodeType.None, StatusCodeType.Wait, StatusCodeType.PageLoading, StatusCodeType.Saving }, RealConvertSource); |
572 |
|
573 |
} |
574 |
|
575 |
private void RealDataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection) |
576 |
{ |
577 |
try |
578 |
{ |
579 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
580 |
{ |
581 |
var items = database.GetConvertProjects(collection)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
582 |
.Take(SelectedCount.ValueMember).ToList();// |
583 |
|
584 |
items.ForEach(newitem => |
585 |
{ |
586 |
collection.UpdateWhere(changeitem => |
587 |
ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ConvertID == newitem.ConvertID && x.ProjectNumber == newitem.ProjectNumber); |
588 |
}); |
589 |
} |
590 |
} |
591 |
catch (Exception ex) |
592 |
{ |
593 |
MessageBox.Show(ex.ToString()); |
594 |
} |
595 |
} |
596 |
|
597 |
private void DataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection) |
598 |
{ |
599 |
try |
600 |
{ |
601 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
602 |
{ |
603 |
|
604 |
int _status = 0; |
605 |
if (SelectedStatus != null) |
606 |
{ |
607 |
_status = (int)SelectedStatus.Value; |
608 |
} |
609 |
|
610 |
var items = database.GetConvertProjects(_status, ProjectNumberFilter, UniqueKeyFilter, Docuemnt_NameFilter, Service_IDFilter, Docuemnt_NOFilter |
611 |
, ReconverterFilter, RevisionFilter)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
612 |
.Take(SelectedCount.ValueMember).ToList(); |
613 |
|
614 |
if (collection.Count() == 0) |
615 |
{ |
616 |
if (statusCodeTypeList.Count() == 1) |
617 |
{ |
618 |
items.ForEach(x => collection.Add(x)); |
619 |
} |
620 |
} |
621 |
else |
622 |
{ |
623 |
|
624 |
////세미 업데이트 |
625 |
items.ForEach(newitem => |
626 |
{ |
627 |
collection.UpdateWhere(changeitem => |
628 |
ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
629 |
}); |
630 |
|
631 |
if (statusCodeTypeList.Count() == 1) |
632 |
{ |
633 |
//삭제 |
634 |
for (int i = collection.Count() - 1; i >= 0; --i) |
635 |
{ |
636 |
var item = collection[i]; |
637 |
|
638 |
if (items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//디비에서 가져온 값과 마지막값부터 차례대로 비교 |
639 |
{//참=> 0제외한 모든 수 |
640 |
collection.RemoveAt(i); |
641 |
} |
642 |
} |
643 |
} |
644 |
|
645 |
if (statusCodeTypeList.Count() == 1) |
646 |
{ |
647 |
//추가 convert 후 추가됨 |
648 |
foreach (var item in items) |
649 |
{ |
650 |
if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감 |
651 |
{ |
652 |
/*for (int i = 0; i < collection.Count()+1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가*/ |
653 |
for (int i = 0; i < 200; i++) |
654 |
{ |
655 |
if (i < collection.Count() - 1) |
656 |
{ |
657 |
if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0) |
658 |
{ |
659 |
collection.Insert(i, item); |
660 |
break; |
661 |
} |
662 |
} |
663 |
else |
664 |
{ |
665 |
collection.Add(item); |
666 |
break; |
667 |
} |
668 |
} |
669 |
|
670 |
} |
671 |
|
672 |
} |
673 |
} |
674 |
|
675 |
} |
676 |
} |
677 |
|
678 |
} |
679 |
catch (Exception ex) |
680 |
{ |
681 |
//MessageBox.Show(ex.ToString()); |
682 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
683 |
} |
684 |
} |
685 |
|
686 |
private void DataSearch(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection) |
687 |
{ |
688 |
try |
689 |
{ |
690 |
using (markusEntities entities = new markusEntities()) |
691 |
{ |
692 |
|
693 |
|
694 |
int _status = 0; |
695 |
if (SelectedStatus != null) |
696 |
{ |
697 |
_status = (int)SelectedStatus.Value; |
698 |
} |
699 |
|
700 |
//DocumentID = unikey |
701 |
|
702 |
//null 왼쪽에서 부터 p_BEGIN_START_DATETIE, p_Finish_START_DATETIE, BEGIN_END_DATETIME, Finish_END_DATETIME, Group_No = 11로 해놈 없음 (전에 없애라고 하셔서..) |
703 |
//오류떠서 [Model].Context.tt File에서 288줄 Function.Name to edmFunction.FullName바꿨더니 오류 안남 |
704 |
var items = entities.SELECT_CONVERT_ITEM(ProjectNumberFilter, UniqueKeyFilter, _status, SelectedCount.ValueMember, SelectedCreateTimeBegin, SelectedCreateTimeEnd, null, null, null, null, 11.ToString(), |
705 |
Docuemnt_NameFilter, Docuemnt_NOFilter, RevisionFilter);//이대로 그냥 쓰면 쿼리 -> 쿼리 결과는 두 번 이상 열거할 수 없습니다 뜸 |
706 |
|
707 |
//SEARCH 할때 최소한 프로젝트 넘버랑 유니크키(다큐먼트 넘버) 크레이트타임 시작 끝 줘야함 |
708 |
|
709 |
List<ConvertItem> Listitems = new List<ConvertItem>(); |
710 |
|
711 |
foreach (var x in items) |
712 |
{ |
713 |
ConvertItem AddItem = new ConvertItem(x.ID, x.PROJECT_NO, x.STATUS, x.DOCUMENT_ID, x.DOCUMENT_NAME, x.DOCUMENT_NO, x.DOCUMENT_URL, x.REVISION, x.CURRENT_PAGE, x.TOTAL_PAGE, x.EXCEPTION, x.GROUP_NO); |
714 |
Listitems.Add(AddItem); |
715 |
} |
716 |
|
717 |
if (collection.Count() == 0) |
718 |
{ |
719 |
if (statusCodeTypeList.Count() == 1) |
720 |
{ |
721 |
foreach (var x in Listitems) |
722 |
{ |
723 |
collection.Add(x); |
724 |
} |
725 |
} |
726 |
} |
727 |
else |
728 |
{ |
729 |
|
730 |
////세미 업데이트 |
731 |
foreach (var newitem in Listitems) |
732 |
{ |
733 |
collection.UpdateWhere(changeitem => |
734 |
ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
735 |
} |
736 |
|
737 |
|
738 |
if (statusCodeTypeList.Count() == 1) |
739 |
{ |
740 |
|
741 |
//삭제 |
742 |
for (int i = collection.Count() - 1; i >= 0; --i) |
743 |
{ |
744 |
var item = collection[i]; |
745 |
|
746 |
if (Listitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
747 |
{ |
748 |
collection.RemoveAt(i); |
749 |
} |
750 |
} |
751 |
} |
752 |
|
753 |
if (statusCodeTypeList.Count() == 1) |
754 |
{ |
755 |
//추가 convert 후 추가됨 |
756 |
foreach (var item in Listitems) |
757 |
{ |
758 |
if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
759 |
{ |
760 |
for (int i = 0; i < 200; i++) |
761 |
{ |
762 |
if (i < collection.Count() - 1) |
763 |
{ |
764 |
if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0) |
765 |
{ |
766 |
collection.Insert(i, item); |
767 |
break; |
768 |
} |
769 |
} |
770 |
else |
771 |
{ |
772 |
collection.Add(item); |
773 |
break; |
774 |
} |
775 |
} |
776 |
|
777 |
} |
778 |
|
779 |
} |
780 |
} |
781 |
|
782 |
} |
783 |
} |
784 |
|
785 |
} |
786 |
catch (Exception ex) |
787 |
{ |
788 |
//MessageBox.Show(ex.ToString()); |
789 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
790 |
} |
791 |
} |
792 |
/// <summary> |
793 |
/// 서비스의 실시간 컨버터 Item |
794 |
/// </summary> |
795 |
private async void AliveDataSelect() |
796 |
{ |
797 |
try |
798 |
{ |
799 |
List<ConvertItem> newitems = new List<ConvertItem>(); |
800 |
|
801 |
foreach (var client in App.StationClientList) |
802 |
{ |
803 |
if (await SimplePingAsync(client.Endpoint.Address.ToString())) |
804 |
{ |
805 |
try |
806 |
{ |
807 |
List<ConvertItem> itemsToList = new List<ConvertItem>(); |
808 |
var items = await client.AliveConvertListAsync(); |
809 |
foreach (var item in items) |
810 |
{ |
811 |
ConvertItem itemsToEach = new ConvertItem(); |
812 |
itemsToEach.ServiceID = item.ServiceID; |
813 |
itemsToEach.ConvertID = item.ConvertID; |
814 |
itemsToEach.ProjectNumber = item.ProjectNumber; |
815 |
|
816 |
if (item.ConvertState != null) |
817 |
{ |
818 |
itemsToEach.ConvertState = (StatusCodeType)Enum.Parse(typeof(StatusCodeType), item.ConvertState); |
819 |
} |
820 |
|
821 |
itemsToEach.CurrentPageNo = item.CurrentPageNo; |
822 |
itemsToEach.TotalPage = item.TotalPage; |
823 |
itemsToEach.OriginfilePath = item.OriginfilePath; |
824 |
itemsToEach.ConvertPath = item.ConvertPath; |
825 |
itemsToEach.MarkusLink = item.MarkusLink; |
826 |
itemsToEach.UniqueKey = item.UniqueKey; |
827 |
itemsToEach.FileName = item.FileName; |
828 |
itemsToEach.ConvertPath = item.ConvertPath; |
829 |
itemsToEach.CreateTime = item.CreateTime; |
830 |
itemsToEach.Exception = item.Exception; |
831 |
itemsToEach.ProcessorAffinity = item.ProcessorAffinity; |
832 |
itemsToEach.ReConverter = item.ReConverter; |
833 |
itemsToEach.DocumentID = item.DocumentID; |
834 |
itemsToEach.DocumnetName = item.DocumnetName; |
835 |
itemsToEach.GroupNo = item.GroupNo; |
836 |
itemsToEach.Revision = item.Revision; |
837 |
itemsToEach.StartTime = item.StartTime; |
838 |
itemsToEach.EndTime = item.EndTime; |
839 |
|
840 |
|
841 |
itemsToList.Add(itemsToEach); |
842 |
} |
843 |
newitems.AddRange(itemsToList); |
844 |
System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping"); |
845 |
|
846 |
if (items.Count() == 0) |
847 |
{ |
848 |
System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero."); |
849 |
} |
850 |
} |
851 |
catch (Exception ex) |
852 |
{ |
853 |
System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}"); |
854 |
} |
855 |
} |
856 |
else |
857 |
{ |
858 |
System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error"); |
859 |
} |
860 |
} |
861 |
|
862 |
ItemsUpdate(newitems); |
863 |
await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems)); |
864 |
} |
865 |
catch (Exception ex) |
866 |
{ |
867 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
868 |
} |
869 |
} |
870 |
|
871 |
/// <summary> |
872 |
/// AliveDataSelect의 Data Update |
873 |
/// </summary> |
874 |
/// <param name="newitems"></param> |
875 |
private void ItemsUpdate(List<ConvertItem> newitems) |
876 |
{ |
877 |
|
878 |
foreach (var item in newitems) |
879 |
{ |
880 |
item.OriginfilePath = HttpUtility.UrlDecode(item.OriginfilePath); |
881 |
} |
882 |
|
883 |
if (AliveItems == null) |
884 |
{ |
885 |
AliveItems = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
886 |
|
887 |
foreach (var item in newitems) |
888 |
{ |
889 |
AliveItems.Add(item); |
890 |
} |
891 |
} |
892 |
else |
893 |
{ |
894 |
/// 데이터 업데이트 |
895 |
newitems.ForEach(newitem => |
896 |
{ |
897 |
AliveItems.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
898 |
}); |
899 |
|
900 |
// 추가 |
901 |
foreach (var item in newitems) |
902 |
{ |
903 |
if (AliveItems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
904 |
{ |
905 |
AliveItems.Add(item); |
906 |
} |
907 |
} |
908 |
|
909 |
/// 삭제 |
910 |
|
911 |
for (int i = AliveItems.Count() - 1; i > -1; --i) |
912 |
{ |
913 |
var item = AliveItems[i]; |
914 |
|
915 |
if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
916 |
{ |
917 |
try |
918 |
{ |
919 |
AliveItems.RemoveAt(i); |
920 |
} |
921 |
catch (Exception ex) |
922 |
{ |
923 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
924 |
} |
925 |
} |
926 |
} |
927 |
} |
928 |
} |
929 |
|
930 |
|
931 |
public static async Task<bool> SimplePingAsync(string uri) |
932 |
{ |
933 |
bool result = false; |
934 |
|
935 |
try |
936 |
{ |
937 |
using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient()) |
938 |
{ |
939 |
Client.Timeout = new TimeSpan(0, 0, 60); |
940 |
|
941 |
var message = await Client.GetAsync(uri); |
942 |
|
943 |
System.Net.HttpStatusCode StatusCode = message.StatusCode; |
944 |
|
945 |
switch (StatusCode) |
946 |
{ |
947 |
|
948 |
case System.Net.HttpStatusCode.Accepted: |
949 |
case System.Net.HttpStatusCode.OK: |
950 |
result = true; |
951 |
break; |
952 |
} |
953 |
} |
954 |
} |
955 |
catch (Exception ex) |
956 |
{ |
957 |
result = false; |
958 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
959 |
} |
960 |
|
961 |
return result; |
962 |
} |
963 |
|
964 |
#endregion |
965 |
|
966 |
#region Data Convert |
967 |
|
968 |
private void DataConvert(object obj) |
969 |
{ |
970 |
if (SelectFilterConvert == null && SelectRealConvert == null) |
971 |
{ |
972 |
MessageBox.Show("왼쪽 버튼 클릭 후 Converter 해주세요!"); |
973 |
} |
974 |
else |
975 |
{ |
976 |
ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString); |
977 |
var resultRealConvert = 0; |
978 |
var resultFiltertConvert = 0; |
979 |
|
980 |
if (SelectRealConvert != null) |
981 |
{ |
982 |
resultRealConvert = _DataConvert.SetCleanUpItem(SelectRealConvert); |
983 |
} |
984 |
else if (SelectFilterConvert != null) |
985 |
{ |
986 |
resultFiltertConvert = _DataConvert.SetCleanUpItem(SelectFilterConvert); |
987 |
} |
988 |
System.Diagnostics.Debug.WriteLine(resultRealConvert + " " + resultFiltertConvert); |
989 |
|
990 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
991 |
{ |
992 |
var items = database.GetConvertProjects(SelectFilterConvert); |
993 |
|
994 |
foreach (var item in items) |
995 |
{ |
996 |
RealConvertSource.Add(item); |
997 |
} |
998 |
if (RealConvertSource.Count() == 1) |
999 |
{ |
1000 |
ConvertShow = true; |
1001 |
} |
1002 |
} |
1003 |
} |
1004 |
} |
1005 |
|
1006 |
#endregion |
1007 |
|
1008 |
#region Validation |
1009 |
|
1010 |
private void DataValidate(object obj) |
1011 |
{ |
1012 |
|
1013 |
bool result = false; |
1014 |
|
1015 |
WebRequest webRequest = WebRequest.Create(SelectFilterConvert.OriginfilePath); |
1016 |
webRequest.Timeout = 1200; // miliseconds |
1017 |
webRequest.Method = "HEAD"; |
1018 |
|
1019 |
HttpWebResponse response = null; |
1020 |
|
1021 |
try |
1022 |
{ |
1023 |
response = (HttpWebResponse)webRequest.GetResponse(); |
1024 |
result = true; |
1025 |
} |
1026 |
catch (WebException webException) |
1027 |
{ |
1028 |
MessageBox.Show(SelectFilterConvert.FileName + " doesn't exist: " + webException.Message); |
1029 |
result = true; |
1030 |
} |
1031 |
finally |
1032 |
{ |
1033 |
if (response != null) |
1034 |
{ |
1035 |
response.Close(); |
1036 |
} |
1037 |
} |
1038 |
if (result == true) |
1039 |
{ |
1040 |
MessageBox.Show("File exists"); |
1041 |
} |
1042 |
} |
1043 |
|
1044 |
#endregion |
1045 |
|
1046 |
#region DataFilter |
1047 |
|
1048 |
public void DataFilter(object obj) |
1049 |
{ |
1050 |
dispatcherTimer.Tick -= new EventHandler(Timer_Tick); |
1051 |
DataSearch(new[] { (StatusCodeType)(SelectedStatus.Value) }, FilterConvertSource); |
1052 |
//dispatcherTimer.Start(); |
1053 |
} |
1054 |
|
1055 |
#endregion |
1056 |
|
1057 |
#region MarkusLink |
1058 |
|
1059 |
private void MarkusLink(object obj)///여기서 부터 |
1060 |
{ |
1061 |
if (obj is ConvertItem) |
1062 |
{ |
1063 |
if (obj != null) |
1064 |
{ |
1065 |
var convertitem = obj as ConvertItem; |
1066 |
|
1067 |
SelectFilterConvert = convertitem; |
1068 |
|
1069 |
SelectRealConvert = convertitem; |
1070 |
|
1071 |
ProcessStartInfo startInfo = null; |
1072 |
|
1073 |
startInfo = new ProcessStartInfo("iexplore.exe", convertitem.MarkusLink); |
1074 |
|
1075 |
Process.Start(startInfo); |
1076 |
} |
1077 |
} |
1078 |
} |
1079 |
|
1080 |
#endregion |
1081 |
|
1082 |
#region Data Delete |
1083 |
|
1084 |
private void DataDelete(object obj) |
1085 |
{ |
1086 |
RadWindow.Alert("do you want to delete it??", this.OnClosed); |
1087 |
} |
1088 |
|
1089 |
private void OnClosed(object sender, WindowClosedEventArgs e) |
1090 |
{ |
1091 |
var result = e.DialogResult; |
1092 |
if (result == true) |
1093 |
{ |
1094 |
ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString); |
1095 |
var resultRealConvert = _DataConvert.RemoveItem(SelectRealConvert.ConvertID); |
1096 |
var resultFiltertConvert = _DataConvert.RemoveItem(SelectFilterConvert.ConvertID); |
1097 |
System.Diagnostics.Debug.WriteLine(resultRealConvert + " " + resultFiltertConvert); |
1098 |
} |
1099 |
} |
1100 |
|
1101 |
|
1102 |
#endregion |
1103 |
|
1104 |
#region Data Export |
1105 |
|
1106 |
|
1107 |
/// <summary> |
1108 |
/// 필터된 상단 그리드 엑셀로 출력 |
1109 |
/// </summary> |
1110 |
|
1111 |
public void DataExportData(object obj) |
1112 |
{ |
1113 |
SaveFileDialog saveFileDialog = new SaveFileDialog(); |
1114 |
|
1115 |
saveFileDialog.FileName = "Document"; // Default file name |
1116 |
saveFileDialog.DefaultExt = ".txt"; // Default file extension |
1117 |
saveFileDialog.Filter = "Csv documents (.Csv)|*.csv|Excel(2017~2019)Worksheets|*.xlsx"; // Filter files by extension |
1118 |
|
1119 |
|
1120 |
if (saveFileDialog.ShowDialog() == true) |
1121 |
{ |
1122 |
|
1123 |
|
1124 |
if (!string.IsNullOrWhiteSpace(saveFileDialog.FileName)) |
1125 |
{ |
1126 |
|
1127 |
var extension = new System.IO.FileInfo(saveFileDialog.FileName).Extension; |
1128 |
|
1129 |
if (extension == ".xlsx" || extension == ".csv") |
1130 |
{ |
1131 |
|
1132 |
var headers = new List<HeaderMember> |
1133 |
{ |
1134 |
new HeaderMember{HeaderName = "ServiceID", Property = "ServiceID" }, |
1135 |
new HeaderMember{HeaderName = "ConvertID", Property = "ConvertID" }, |
1136 |
new HeaderMember{HeaderName = "ProjectNumber", Property = "ProjectNumber" }, |
1137 |
new HeaderMember{HeaderName = "ConvertState", Property = "ConvertState" }, |
1138 |
new HeaderMember{HeaderName = "CurrentPageNo", Property = "CurrentPageNo" }, |
1139 |
new HeaderMember{HeaderName = "TotalPage", Property = "TotalPage" }, |
1140 |
new HeaderMember{HeaderName = "OriginfilePath", Property = "OriginfilePath" }, |
1141 |
new HeaderMember{HeaderName = "ConvertPath", Property = "ConvertPath" }, |
1142 |
new HeaderMember{HeaderName = "CreateTime", Property = "CreateTime" }, |
1143 |
new HeaderMember{HeaderName = "Exception", Property = "Exception" }, |
1144 |
new HeaderMember{HeaderName = "ProcessorAffinity", Property = "ProcessorAffinity" }, |
1145 |
new HeaderMember{HeaderName = "ReConverter", Property = "ReConverter" }, |
1146 |
new HeaderMember{HeaderName = "UniqueKey", Property = "UniqueKey" } |
1147 |
}; |
1148 |
|
1149 |
|
1150 |
DataExport dataExport = new DataExport(); |
1151 |
dataExport.DataExportExcel(saveFileDialog.FileName, "Hello world", FilterConvertSource, headers); |
1152 |
//_dataExport.DataExportExcel(saveFileDialog.FileName, saveFileDialog.FileName.ToString(), Projectsource, headers); |
1153 |
//GemBoxFileSave(obj); |
1154 |
} |
1155 |
} |
1156 |
} |
1157 |
} |
1158 |
|
1159 |
#endregion |
1160 |
|
1161 |
#region Data Search |
1162 |
|
1163 |
|
1164 |
/// <summary> |
1165 |
/// Grid Filter |
1166 |
/// </summary> |
1167 |
|
1168 |
private bool DetailFilter(object item) |
1169 |
{ |
1170 |
var Item = item as ConvertItem; |
1171 |
if (ProjectNumberFilter == null) return true; |
1172 |
if (ProjectNumberFilter == Item.ProjectNumber) return true; |
1173 |
//if (ConvertStateFilter == null) return true; |
1174 |
//if (ConvertStateFilter == (StatusCodeType)Item.ConvertState) return true; |
1175 |
if (Docuemnt_NameFilter == null) return true; |
1176 |
if (Docuemnt_NameFilter == Item.DocumnetName) return true; |
1177 |
if (Service_IDFilter == null) return true; |
1178 |
if (Service_IDFilter == Item.ServiceID) return true; |
1179 |
if (UniqueKeyFilter == null) return true; |
1180 |
if (UniqueKeyFilter == Item.UniqueKey) return true; |
1181 |
if (Docuemnt_NOFilter == null) return true; |
1182 |
if (Docuemnt_NOFilter == Item.DocumnetNo) return true; |
1183 |
if (ReconverterFilter == null) return true; |
1184 |
if (ReconverterFilter == Item.ReConverter) return true; |
1185 |
if (RevisionFilter == null) return true; |
1186 |
if (RevisionFilter == Item.Revision) return true; |
1187 |
|
1188 |
return false; |
1189 |
} |
1190 |
|
1191 |
public void RemoveCreateTimeFilter(object obj) |
1192 |
{ |
1193 |
DefaultCreateTime = DateTime.Now; |
1194 |
SelectedCreateTimeBegin = DefaultCreateTime; |
1195 |
SelectedCreateTimeEnd = DefaultCreateTime; |
1196 |
|
1197 |
} |
1198 |
|
1199 |
#endregion |
1200 |
|
1201 |
#region Reset |
1202 |
|
1203 |
/// <summary> |
1204 |
/// 그리드 상단 원상복귀 버튼 |
1205 |
/// 필터를 끝낸 후 다시 복귀 |
1206 |
/// </summary> |
1207 |
|
1208 |
public void Reset(object obj) |
1209 |
{ |
1210 |
dispatcherTimer.Tick += new EventHandler(Timer_Tick); |
1211 |
} |
1212 |
|
1213 |
#endregion |
1214 |
|
1215 |
#endregion |
1216 |
} |
1217 |
} |
1218 |
|