프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseItemsModel.cs @ 5a954acc

이력 | 보기 | 이력해설 | 다운로드 (36.6 KB)

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