프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseItemsModel.cs @ 85f68fef

이력 | 보기 | 이력해설 | 다운로드 (43.8 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
using System.Windows.Controls;
26

    
27
namespace Markus.Service.StationController.ViewModel
28
{
29
    //세미
30
    public class DataBaseItemsModel : Mvvm.ToolKit.ViewModelBase
31
    {
32
        #region Constructor
33

    
34
        /// <summary>
35
        /// 실행하면 처음 들어가는 부분
36
        /// </summary>
37
        public DataBaseItemsModel()
38
        {
39
            DataFilterCommand = new DelegateCommand(DataFilter);
40
            DataSaveFileGemBoxCommand = new DelegateCommand(DataExportData);
41
            ConvertCommand = new DelegateCommand(DataConvert);
42
            DeleteCommand = new DelegateCommand(DataDelete);
43
            ValidateCommand = new DelegateCommand(DataValidate);
44
            MarkusLinkCommand = new DelegateCommand(MarkusLink);
45
            RemoveCreateTimeFilterCommand = new DelegateCommand(RemoveCreateTimeFilter);
46
            ResetCommand = new DelegateCommand(Reset);
47
            ConverAddCommand = new DelegateCommand(ConverAdd);
48
        }
49

    
50
        #endregion
51

    
52
        #region Properties
53

    
54
        private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _FilterSearch;
55
        public System.Collections.ObjectModel.ObservableCollection<ConvertItem> FilterSearch
56
        {
57
            get
58
            {
59
                if (_FilterSearch == null)
60
                {
61
                    _FilterSearch = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>
62
                    {
63
                        new ConvertItem{ProjectNumber = "Filter Search"}
64
                    };
65
                }
66

    
67
                return _FilterSearch;
68
            }
69
        }
70

    
71
        private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _AliveItems;
72
        public System.Collections.ObjectModel.ObservableCollection<ConvertItem> AliveItems
73
        {
74
            get => _AliveItems;
75
            set
76
            {
77
                _AliveItems = value;
78
                OnPropertyChanged(() => AliveItems);
79
            }
80
        }
81

    
82
        public ICollectionView FilterConvertSourceView
83
        {
84
            get
85
            {
86
                var view = CollectionViewSource.GetDefaultView(FilterConvertSource);
87
                return view;
88
            }
89
        }
90

    
91
        private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _FilterConvertSource;
92
        public System.Collections.ObjectModel.ObservableCollection<ConvertItem> FilterConvertSource
93
        {
94
            get
95
            {
96
                if (_FilterConvertSource == null)
97
                {
98
                    _FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
99
                }
100
                return _FilterConvertSource;
101
            }
102
            set
103
            {
104
                _FilterConvertSource = value;
105
                OnPropertyChanged(() => FilterConvertSource);
106
            }
107
        }
108

    
109

    
110
        private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _RealConvertSource;
111
        public System.Collections.ObjectModel.ObservableCollection<ConvertItem> RealConvertSource
112
        {
113
            get => _RealConvertSource;
114
            set
115
            {
116
                _RealConvertSource = value;
117
                OnPropertyChanged(() => RealConvertSource);
118
            }
119
        }
120

    
121

    
122
        private System.Windows.Documents.FlowDocument connectionLog;
123
        public System.Windows.Documents.FlowDocument ConnectionLog
124
        {
125
            get => connectionLog;
126
            set
127
            {
128
                if (connectionLog != value)
129
                {
130
                    connectionLog = value;
131
                    OnPropertyChanged(() => ConnectionLog);
132
                }
133
            }
134
        }
135

    
136

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

    
148

    
149
        private SelectedCountItem _SelectedCount;
150
        public SelectedCountItem SelectedCount
151
        {
152
            get => _SelectedCount;
153
            set
154
            {
155
                _SelectedCount = value;
156
                OnPropertyChanged(() => SelectedCount);
157
            }
158
        }
159

    
160
        List<SelectedCountItem> _SelectedCountList;
161
        public List<SelectedCountItem> SelectedCountList
162
        {
163
            get
164
            {
165
                if (_SelectedCountList == null)
166
                {
167
                    _SelectedCountList = new List<SelectedCountItem>
168
                    {
169
                        new SelectedCountItem{DisplayMember = "50",ValueMember = 50},
170
                        new SelectedCountItem{DisplayMember = "100",ValueMember = 100},
171
                        new SelectedCountItem{DisplayMember = "150",ValueMember = 150},
172
                        new SelectedCountItem{DisplayMember = "200",ValueMember = 200}
173
                    };
174
                }
175

    
176
                return _SelectedCountList;
177
            }
178
        }
179

    
180
        private ConvertItem _SelectFilterConvert;
181
        public ConvertItem SelectFilterConvert
182
        {
183
            get => _SelectFilterConvert;
184
            set
185
            {
186
                _SelectFilterConvert = value;
187
                OnPropertyChanged(() => SelectFilterConvert);
188
            }
189
        }
190

    
191
        private ConvertItem _SelectRealConvert;
192
        public ConvertItem SelectRealConvert
193
        {
194
            get => _SelectRealConvert;
195
            set
196
            {
197
                _SelectRealConvert = value;
198
                OnPropertyChanged(() => SelectRealConvert);
199
            }
200
        }
201

    
202

    
203
        private ConvertItem _SelectAliveConvert;
204
        public ConvertItem SelectAliveConvert
205
        {
206
            get => _SelectAliveConvert;
207
            set
208
            {
209
                _SelectAliveConvert = value;
210
                OnPropertyChanged(() => SelectAliveConvert);
211
            }
212
        }
213

    
214

    
215
        private StatusTypeList _StatusType;
216
        public StatusTypeList StatusType
217
        {
218
            get => _StatusType;
219
            set
220
            {
221
                _StatusType = value;
222
                OnPropertyChanged(() => StatusType);
223
            }
224
        }
225

    
226
        private bool _IsLoading;
227
        public bool IsLoading
228
        {
229
            get => _IsLoading;
230
            set
231
            {
232
                if (_IsLoading != value)
233
                {
234
                    _IsLoading = value;
235
                    OnPropertyChanged(() => IsLoading);
236
                }
237
            }
238
        }
239

    
240
        IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> _StatusCodeList;
241
        public IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> StatusCodeList
242
        {
243
            get
244
            {
245
                if (_StatusCodeList == null)
246
                {
247
                    _StatusCodeList = Telerik.Windows.Data.EnumDataSource.FromType<StatusCodeType>();
248
                }
249

    
250
                return _StatusCodeList;
251
            }
252
        }
253

    
254
        public string _ProjectNumberFilter;
255
        public string ProjectNumberFilter
256
        {
257
            get { return _ProjectNumberFilter; }
258
            set
259
            {
260
                if (_ProjectNumberFilter == "")
261
                {
262
                    _ProjectNumberFilter = null;
263
                }
264
                else if (_ProjectNumberFilter != value)
265
                {
266
                    _ProjectNumberFilter = value;
267
                    OnPropertyChanged(() => ProjectNumberFilter);
268
                }
269
            }
270
        }
271

    
272
        public string _UniqueKeyFilter;
273
        public string UniqueKeyFilter
274
        {
275
            get
276
            {
277
                return _UniqueKeyFilter;
278
            }
279
            set
280
            {
281
                if (_UniqueKeyFilter == "")
282
                {
283
                    _UniqueKeyFilter = null;
284
                }
285
                else if (_UniqueKeyFilter != value)
286
                {
287
                    _UniqueKeyFilter = value;
288
                    OnPropertyChanged(() => UniqueKeyFilter);
289
                }
290
            }
291
        }
292

    
293
        public StatusCodeType _ConvertStateFilter;
294
        public StatusCodeType ConvertStateFilter
295
        {
296
            get { return _ConvertStateFilter; }
297
            set
298
            {
299
                if (_ConvertStateFilter != value)
300
                {
301
                    _ConvertStateFilter = value;
302
                    OnPropertyChanged(() => ConvertStateFilter);
303
                }
304
            }
305
        }
306

    
307
        public string _Docuemnt_NOFilter;
308
        public string Docuemnt_NOFilter
309
        {
310
            get { return _Docuemnt_NOFilter; }
311
            set
312
            {
313
                if (_Docuemnt_NOFilter == "")
314
                {
315
                    _Docuemnt_NOFilter = null;
316
                }
317
                else if (_Docuemnt_NOFilter != value)
318
                {
319
                    _Docuemnt_NOFilter = value;
320
                    OnPropertyChanged(() => Docuemnt_NOFilter);
321
                }
322
            }
323
        }
324

    
325
        public string _Docuemnt_NameFilter;
326
        public string Docuemnt_NameFilter
327
        {
328
            get { return _Docuemnt_NameFilter; }
329
            set
330
            {
331
                if (_Docuemnt_NameFilter == "")
332
                {
333
                    _Docuemnt_NameFilter = null;
334
                }
335
                else if (_Docuemnt_NameFilter != value)
336
                {
337
                    _Docuemnt_NameFilter = value;
338
                    OnPropertyChanged(() => Docuemnt_NameFilter);
339
                }
340
            }
341
        }
342

    
343
        public int? _ReconverterFilter = 0;
344
        public int? ReconverterFilter
345
        {
346
            get { return _ReconverterFilter; }
347
            set
348
            {
349
                if (_ReconverterFilter == null)
350
                {
351
                    _ReconverterFilter = 0;
352
                }
353
                else if (_ReconverterFilter != value)
354
                {
355
                    _ReconverterFilter = value;
356
                    OnPropertyChanged(() => ReconverterFilter);
357

    
358
                }
359
            }
360
        }
361

    
362
        public string _Service_IDFilter;
363
        public string Service_IDFilter
364
        {
365
            get { return _Service_IDFilter; }
366
            set
367
            {
368
                if (_Service_IDFilter == "")
369
                {
370
                    _Service_IDFilter = null;
371
                }
372
                else if (_Service_IDFilter != value)
373
                {
374
                    _Service_IDFilter = value;
375
                    OnPropertyChanged(() => Service_IDFilter);
376
                }
377
            }
378
        }
379

    
380
        public string _RevisionFilter;
381
        public string RevisionFilter
382
        {
383
            get { return _RevisionFilter; }
384
            set
385
            {
386
                if (_RevisionFilter == "")
387
                {
388
                    _RevisionFilter = null;
389
                }
390
                else if (_RevisionFilter != value)
391
                {
392
                    _RevisionFilter = value;
393
                    OnPropertyChanged(() => RevisionFilter);
394
                }
395
            }
396
        }
397

    
398
        public string _GroupNOFilter;
399
        public string GroupNOFilter
400
        {
401
            get { return _GroupNOFilter; }
402
            set
403
            {
404
                if (_GroupNOFilter == "")
405
                {
406
                    _GroupNOFilter = null;
407
                }
408
                else if (_GroupNOFilter != value)
409
                {
410
                    _GroupNOFilter = value;
411
                    OnPropertyChanged(() => GroupNOFilter);
412
                }
413
            }
414
        }
415

    
416
        static DateTime DefaultCreateTime = DateTime.Now;
417
        private DateTime _SelectedCreateTimeBegin = DefaultCreateTime;
418
        public DateTime SelectedCreateTimeBegin
419
        {
420

    
421
            get { return _SelectedCreateTimeBegin; }
422
            set
423
            {
424
                if (_SelectedCreateTimeBegin == value)
425
                    return;
426
                _SelectedCreateTimeBegin = value;
427
                OnPropertyChanged(() => SelectedCreateTimeBegin);
428

    
429
            }
430
        }
431

    
432
        private DateTime _SelectedCreateTimeEnd = DefaultCreateTime;
433
        public DateTime SelectedCreateTimeEnd
434
        {
435

    
436
            get { return _SelectedCreateTimeEnd; }
437
            set
438
            {
439
                if (_SelectedCreateTimeEnd == value)
440
                    return;
441
                _SelectedCreateTimeEnd = value;
442
                OnPropertyChanged(() => SelectedCreateTimeEnd);
443
            }
444
        }
445

    
446
        public int _DataBase_ItemsHeight = 800;
447
        public int DataBase_ItemsHeight
448
        {
449
            get { return _DataBase_ItemsHeight; }
450
            set
451
            {
452
                _DataBase_ItemsHeight = value;
453
                OnPropertyChanged(() => DataBase_ItemsHeight);
454
            }
455
        }
456

    
457

    
458
        public int _RealConvert_Height = 80;
459
        public int RealConvert_Height
460
        {
461
            get { return _RealConvert_Height; }
462
            set
463
            {
464
                _RealConvert_Height = value;
465
                OnPropertyChanged(() => RealConvert_Height);
466
            }
467
        }
468

    
469
        public int _Alive_Height = 80;
470
        public int Alive_Height
471
        {
472
            get { return _Alive_Height; }
473
            set
474
            {
475
                _Alive_Height = value;
476
                OnPropertyChanged(() => Alive_Height);
477
            }
478
        }
479

    
480
        public bool _ConvertShow;
481
        public bool ConvertShow
482
        {
483
            get => _ConvertShow;
484
            set
485
            {
486
                if (_ConvertShow = !value)
487
                {
488
                    _ConvertShow = false;
489
                }
490
                _ConvertShow = value;
491
                OnPropertyChanged(() => ConvertShow);
492
            }
493
        }
494

    
495
        #endregion
496

    
497
        #region Command
498

    
499
        public DelegateCommand ConvertCommand { get; private set; }
500
        public DelegateCommand DeleteCommand { get; private set; }
501
        public DelegateCommand ValidateCommand { get; private set; }
502
        public DelegateCommand DataSaveFileGemBoxCommand { get; private set; }
503
        public DelegateCommand MarkusLinkCommand { get; private set; }
504
        public DelegateCommand RemoveCreateTimeFilterCommand { get; private set; }
505

    
506
        public DelegateCommand DataFilterCommand { get; private set; }
507
        public DelegateCommand ResetCommand { get; private set; }
508
        public DelegateCommand ConverAddCommand { get; private set; }
509

    
510
        #endregion
511

    
512
        #region Main Logic
513

    
514
        /// <summary>
515
        /// 각각의 Grid row 객체들 업데이트
516
        /// </summary>
517

    
518
        private DispatcherTimer dispatcherTimer;
519
        public override void Loaded()
520
        {
521
            base.Loaded();
522

    
523
            if (!App.IsDesignMode)
524
            {
525
                dispatcherTimer = new DispatcherTimer();
526
                dispatcherTimer.Tick += new EventHandler(Timer_Tick);
527
                dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
528
                dispatcherTimer.Start();
529
            }
530
        }
531

    
532
        private async void Timer_Tick(object sender, EventArgs e)
533
        {
534
            dispatcherTimer.Stop();
535

    
536
            if (IsAcitve)
537
            {
538
                await App.Current.Dispatcher.InvokeAsync(() =>
539
                {
540
                    DataSelect();
541

    
542
                    AliveDataSelect();
543
                });
544
            }
545

    
546
            await Task.Delay(5000);
547

    
548
            //System.Threading.Thread.Sleep(new TimeSpan(0,0,0,0,100));
549

    
550
            dispatcherTimer.Start();
551
        }
552

    
553
        public override void Closed()
554
        {
555
            if (dispatcherTimer != null)
556
            {
557
                dispatcherTimer.Stop();
558
            }
559

    
560
            base.Closed();
561
        }
562

    
563

    
564
        #endregion
565

    
566
        #region Function
567

    
568
        #region Data Select
569

    
570
        /// <summary>
571
        /// 상단 그리드 중앙 그리드 출력 데이터
572
        /// </summary>
573
        private void DataSelect()
574
        {
575

    
576
            if (FilterConvertSource == null)
577
            {
578
                FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
579
            }
580

    
581
            if (RealConvertSource == null)
582
            {
583
                RealConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
584
            }
585

    
586
            /// combobox 에서 선택된 items
587
            if (SelectedStatus != null)
588
            {
589
                DataSelect(new[] { (StatusCodeType)(SelectedStatus.Value) }, FilterConvertSource);
590
            }
591

    
592
            /// 컨버터중인 items
593
            RealDataSelect(new[] { StatusCodeType.None, StatusCodeType.Wait, StatusCodeType.PageLoading, StatusCodeType.Saving }, RealConvertSource);
594

    
595
        }
596

    
597
        private void RealDataSelect(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
                    var items = database.GetConvertProjects(collection)//x:database객체 y:statusCodeTypeList의값  Count()안에 predicator 조건 만족하면 count개수안에 넣음
604
                                          .Take(SelectedCount.ValueMember).ToList();//
605

    
606
                    items.ForEach(newitem =>
607
                    {
608
                        collection.UpdateWhere(changeitem =>
609
                        ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ConvertID == newitem.ConvertID && x.ProjectNumber == newitem.ProjectNumber);
610
                    });
611

    
612
                    RealConvert_Height = 80 + (10 * collection.Count());
613
                    DataBase_ItemsHeight = 800 - (RealConvert_Height + Alive_Height);
614
                }
615
            }
616
            catch (Exception ex)
617
            {
618
                MessageBox.Show(ex.ToString());
619
            }
620
        }
621

    
622
        private void DataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection)
623
        {
624
            try
625
            {
626
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
627
                {
628

    
629
                    int _status = 0;
630
                    if (SelectedStatus != null)
631
                    {
632
                        _status = (int)SelectedStatus.Value;
633
                    }
634

    
635

    
636
                    var items = database.GetConvertProjects(_status, ProjectNumberFilter, UniqueKeyFilter, Docuemnt_NameFilter, Service_IDFilter, Docuemnt_NOFilter
637
                        , ReconverterFilter, RevisionFilter)//x:database객체 y:statusCodeTypeList의값  Count()안에 predicator 조건 만족하면 count개수안에 넣음
638
                                          .Take(SelectedCount.ValueMember).ToList();
639

    
640
                    if (collection.Count() == 0)
641
                    {
642
                        if (statusCodeTypeList.Count() == 1)
643
                        {
644
                            items.ForEach(x => collection.Add(x));
645
                        }
646
                    }
647
                    else
648
                    {
649

    
650
                        ////세미 업데이트
651
                        items.ForEach(newitem =>
652
                        {
653
                            collection.UpdateWhere(changeitem =>
654
                            ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID);
655
                        });
656

    
657
                        if (statusCodeTypeList.Count() == 1)
658
                        {
659
                            //삭제
660
                            for (int i = collection.Count() - 1; i >= 0; --i)
661
                            {
662
                                var item = collection[i];
663

    
664
                                if (items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//디비에서 가져온 값과 마지막값부터 차례대로 비교
665
                                {//참=> 0제외한 모든 수
666
                                    collection.RemoveAt(i);
667
                                }
668
                            }
669
                        }
670

    
671
                        if (statusCodeTypeList.Count() == 1)
672
                        {
673
                            //추가 convert 후 추가됨
674
                            foreach (var item in items)
675
                            {
676
                                if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감
677
                                {
678
                                    /*for (int i = 0; i < collection.Count()+1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가*/
679
                                    for (int i = 0; i < 200; i++)
680
                                    {
681
                                        if (i < collection.Count() - 1)
682
                                        {
683
                                            if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0)
684
                                            {
685
                                                collection.Insert(i, item);
686
                                                break;
687
                                            }
688
                                        }
689
                                        else
690
                                        {
691
                                            collection.Add(item);
692
                                            break;
693
                                        }
694
                                    }
695

    
696
                                }
697

    
698
                            }
699
                        }
700

    
701
                    }
702
                }
703

    
704
            }
705
            catch (Exception ex)
706
            {
707
                //MessageBox.Show(ex.ToString());
708
                System.Diagnostics.Debug.WriteLine(ex.ToString());
709
            }
710
        }
711

    
712
        private void DataSearch(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection)
713
        {
714
            try
715
            {
716
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
717
                {
718
                    using (markusEntities entities = new markusEntities())
719
                    {
720

    
721

    
722
                        int _status = 0;
723
                        if (SelectedStatus != null)
724
                        {
725
                            _status = (int)SelectedStatus.Value;
726
                        }
727

    
728
                        //DocumentID = unikey
729

    
730
                        var items = entities.SELECT_CONVERT_ITEM(ProjectNumberFilter, UniqueKeyFilter, _status, SelectedCount.ValueMember, SelectedCreateTimeBegin, SelectedCreateTimeEnd, null, null, null, null, GroupNOFilter,
731
                            Docuemnt_NameFilter, Docuemnt_NOFilter, RevisionFilter).ToList();
732

    
733
                        //SEARCH 할때 최소한 프로젝트 넘버랑 유니크키(다큐먼트 넘버) 크레이트타임 시작 줘야함
734

    
735
                        List<ConvertItem> Listitems = new List<ConvertItem>();
736

    
737
                        foreach (var x in items)
738
                        {
739
                            var convertpath = database.GetSearchConvertPathAndMarkus(x.PROJECT_NO, x.DOCUMENT_ID);
740

    
741
                            ConvertItem AddItem = new ConvertItem(x.SERVICE_ID, 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, x.CREATE_DATETIME, x.START_DATETIME, x.END_DATETIME
742
                             , x.DOCUMENT_URL, convertpath[0], convertpath[1]);
743
                            Listitems.Add(AddItem);
744
                            //이거 없으면 collection.Insert(i, item); 할때 문제 생김
745
                        }
746

    
747
                        if (collection.Count() == 0)
748
                        {
749
                            if (statusCodeTypeList.Count() == 1)
750
                            {
751
                                foreach (var x in Listitems)
752
                                {
753
                                    collection.Add(x);
754
                                }
755
                            }
756
                        }
757
                        else
758
                        {
759

    
760
                            ////세미 업데이트
761
                            foreach (var newitem in Listitems)
762
                            {
763
                                collection.UpdateWhere(changeitem =>
764
                                ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID);
765
                            }
766

    
767

    
768
                            if (statusCodeTypeList.Count() == 1)
769
                            {
770

    
771
                                //삭제
772
                                for (int i = collection.Count() - 1; i >= 0; --i)
773
                                {
774
                                    var item = collection[i];
775

    
776
                                    if (Listitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
777
                                    {
778
                                        collection.RemoveAt(i);
779
                                    }
780
                                }
781
                            }
782

    
783
                            if (statusCodeTypeList.Count() == 1)
784
                            {
785
                                //추가 convert 후 추가됨
786
                                foreach (var item in Listitems)
787
                                {
788
                                    if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
789
                                    {
790
                                        for (int i = 0; i < 200; i++)
791
                                        {
792
                                            if (i < collection.Count() - 1)
793
                                            {
794
                                                if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0)
795
                                                {
796
                                                    collection.Insert(i, item);
797
                                                    break;
798
                                                }
799
                                            }
800
                                            else
801
                                            {
802
                                                collection.Add(item);
803
                                                break;
804
                                            }
805
                                        }
806

    
807
                                    }
808

    
809
                                }
810
                            }
811

    
812
                        }
813
                    }
814
                }
815

    
816
            }
817
            catch (Exception ex)
818
            {
819
                //MessageBox.Show(ex.ToString());
820
                System.Diagnostics.Debug.WriteLine(ex.ToString());
821
            }
822
        }
823
        /// <summary>
824
        /// 서비스의 실시간 컨버터 Item
825
        /// </summary>
826
        private async void AliveDataSelect()
827
        {
828
            try
829
            {
830
                List<ConvertItem> newitems = new List<ConvertItem>();
831
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
832
                {
833
                    foreach (var client in App.StationClientList)
834
                    {
835
                        if (await SimplePingAsync(client.Endpoint.Address.ToString()))
836
                        {
837
                            try
838
                            {
839
                                List<ConvertItem> itemsToList = new List<ConvertItem>();
840
                                var items = await client.AliveConvertListAsync();
841
                                string result = "";
842

    
843
                                foreach (var item in items)
844
                                {
845
                                    ConvertItem itemsToEach = new ConvertItem();
846
                                    itemsToEach.ServiceID = item.ServiceID;
847
                                    itemsToEach.ConvertID = item.ConvertID;
848
                                    itemsToEach.ProjectNumber = item.ProjectNumber;
849

    
850
                                    var convertpath = database.GetSearchConvertPathAndMarkus(item.ProjectNumber, item.UniqueKey);
851

    
852
                                    if (item.ConvertState != null)
853
                                    {
854
                                        itemsToEach.ConvertState = (StatusCodeType)Enum.Parse(typeof(StatusCodeType), item.ConvertState);
855
                                    }
856

    
857
                                    if (item.OriginfilePath.Contains("/"))
858
                                    {
859
                                        result = item.OriginfilePath.Substring(item.OriginfilePath.LastIndexOf("/") + 1);
860
                                    }
861
                                    else
862
                                    {
863
                                        result = item.OriginfilePath.Substring(item.OriginfilePath.LastIndexOf("%") + 1);
864
                                    }
865
                                    itemsToEach.FileName = result;
866

    
867
                                    itemsToEach.CurrentPageNo = item.CurrentPageNo;
868
                                    itemsToEach.TotalPage = item.TotalPage;
869
                                    itemsToEach.OriginfilePath = item.OriginfilePath;
870
                                    itemsToEach.ConvertPath = item.ConvertPath;
871
                                    itemsToEach.MarkusLink = convertpath[1];
872
                                    itemsToEach.UniqueKey = item.UniqueKey;
873
                                    itemsToEach.GroupNo = item.GroupNo;
874
                                    itemsToEach.ProcessorAffinity = item.ProcessorAffinity;
875
                                    itemsToEach.DocumnetName = item.DocumnetName;
876
                                    itemsToEach.Revision = item.Revision;
877
                                    itemsToEach.Exception = item.Exception;
878
                                    itemsToEach.ConvertPath = convertpath[0];
879
                                    itemsToEach.CreateTime = item.CreateTime;
880
                                    itemsToEach.ReConverter = item.ReConverter;
881
                                    itemsToEach.DocumentID = item.DocumentID;
882
                                    itemsToEach.StartTime = item.StartTime;
883
                                    itemsToEach.EndTime = item.EndTime;
884

    
885
                                    itemsToList.Add(itemsToEach);
886
                                }
887
                                newitems.AddRange(itemsToList);
888
                                System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping");
889

    
890
                                if (items.Count() == 0)
891
                                {
892
                                    System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero.");
893
                                }
894
                            }
895
                            catch (Exception ex)
896
                            {
897
                                System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}");
898
                            }
899
                        }
900
                        else
901
                        {
902
                            System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error");
903
                        }
904
                    }
905
                }
906
                ItemsUpdate(newitems);
907
                await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems));
908
            }
909
            catch (Exception ex)
910
            {
911
                System.Diagnostics.Debug.WriteLine(ex.ToString());
912
            }
913
        }
914

    
915
        /// <summary>
916
        /// AliveDataSelect의 Data Update
917
        /// </summary>
918
        /// <param name="newitems"></param>
919
        private void ItemsUpdate(List<ConvertItem> newitems)
920
        {
921

    
922
            foreach (var item in newitems)
923
            {
924
                item.OriginfilePath = HttpUtility.UrlDecode(item.OriginfilePath);
925
            }
926

    
927
            if (AliveItems == null)
928
            {
929
                AliveItems = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
930

    
931
                foreach (var item in newitems)
932
                {
933
                    AliveItems.Add(item);
934
                }
935
            }
936
            else
937
            {
938
                /// 데이터 업데이트
939
                newitems.ForEach(newitem =>
940
                {
941
                    AliveItems.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID);
942
                });
943

    
944
                // 추가
945
                foreach (var item in newitems)
946
                {
947
                    if (AliveItems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
948
                    {
949
                        AliveItems.Add(item);
950
                    }
951
                }
952

    
953
                /// 삭제
954

    
955
                for (int i = AliveItems.Count() - 1; i > -1; --i)
956
                {
957
                    var item = AliveItems[i];
958

    
959
                    if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
960
                    {
961
                        try
962
                        {
963
                            AliveItems.RemoveAt(i);
964
                        }
965
                        catch (Exception ex)
966
                        {
967
                            System.Diagnostics.Debug.WriteLine(ex.ToString());
968
                        }
969
                    }
970
                }
971
            }
972

    
973
            Alive_Height = 80 + (newitems.Count() * 10);
974
            DataBase_ItemsHeight = 800 - (RealConvert_Height + Alive_Height);
975
        }
976

    
977

    
978
        public static async Task<bool> SimplePingAsync(string uri)
979
        {
980
            bool result = false;
981

    
982
            try
983
            {
984
                using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient())
985
                {
986
                    Client.Timeout = new TimeSpan(0, 0, 60);
987

    
988
                    var message = await Client.GetAsync(uri);
989

    
990
                    System.Net.HttpStatusCode StatusCode = message.StatusCode;
991

    
992
                    switch (StatusCode)
993
                    {
994

    
995
                        case System.Net.HttpStatusCode.Accepted:
996
                        case System.Net.HttpStatusCode.OK:
997
                            result = true;
998
                            break;
999
                    }
1000
                }
1001
            }
1002
            catch (Exception ex)
1003
            {
1004
                result = false;
1005
                System.Diagnostics.Debug.WriteLine(ex.ToString());
1006
            }
1007

    
1008
            return result;
1009
        }
1010

    
1011
        #endregion
1012

    
1013
        #region Data Convert
1014

    
1015
        private void DataConvert(object obj)
1016
        {
1017
            if (SelectFilterConvert == null && SelectRealConvert == null)
1018
            {
1019
                MessageBox.Show("왼쪽 버튼 클릭 후 Converter 해주세요!");
1020
            }
1021
            else
1022
            {
1023
                ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString);
1024
                var resultRealConvert = 0;
1025
                var resultFiltertConvert = 0;
1026

    
1027
                if (SelectRealConvert != null)
1028
                {
1029
                    resultRealConvert = _DataConvert.SetCleanUpItem(SelectRealConvert);
1030
                }
1031
                else if (SelectFilterConvert != null)
1032
                {
1033
                    resultFiltertConvert = _DataConvert.SetCleanUpItem(SelectFilterConvert);
1034
                }
1035
                System.Diagnostics.Debug.WriteLine(resultRealConvert + "  " + resultFiltertConvert);
1036

    
1037
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
1038
                {
1039
                    var items = database.GetConvertProjects(SelectFilterConvert);
1040

    
1041
                    foreach (var item in items)
1042
                    {
1043
                        RealConvertSource.Add(item);
1044
                    }
1045
                    if (RealConvertSource.Count() == 1)
1046
                    {
1047
                        ConvertShow = true;
1048
                    }
1049
                }
1050
            }
1051
        }
1052

    
1053
        #endregion
1054

    
1055
        #region Validation
1056

    
1057
        private void DataValidate(object obj)
1058
        {
1059

    
1060
            bool result = false;
1061

    
1062
            WebRequest webRequest = WebRequest.Create(SelectFilterConvert.OriginfilePath);
1063
            webRequest.Timeout = 1200; // miliseconds
1064
            webRequest.Method = "HEAD";
1065

    
1066
            HttpWebResponse response = null;
1067

    
1068
            try
1069
            {
1070
                response = (HttpWebResponse)webRequest.GetResponse();
1071
                result = true;
1072
            }
1073
            catch (WebException webException)
1074
            {
1075
                MessageBox.Show(SelectFilterConvert.FileName + " doesn't exist: " + webException.Message);
1076
                result = true;
1077
            }
1078
            finally
1079
            {
1080
                if (response != null)
1081
                {
1082
                    response.Close();
1083
                }
1084
            }
1085
            if (result == true)
1086
            {
1087
                MessageBox.Show("File exists");
1088
            }
1089
        }
1090

    
1091
        #endregion
1092

    
1093
        #region DataFilter
1094

    
1095
        public void DataFilter(object obj)
1096
        {
1097
            dispatcherTimer.Tick -= new EventHandler(Timer_Tick);
1098
            DataSearch(new[] { (StatusCodeType)(SelectedStatus.Value) }, FilterConvertSource);
1099
            //dispatcherTimer.Start();
1100
        }
1101

    
1102
        #endregion
1103

    
1104
        #region MarkusLink
1105

    
1106
        private void MarkusLink(object obj)///여기서 부터 
1107
        {
1108
            if (obj is ConvertItem)
1109
            {
1110
                if (obj != null)
1111
                {
1112
                    var convertitem = obj as ConvertItem;
1113

    
1114
                    SelectFilterConvert = convertitem;
1115

    
1116
                    SelectRealConvert = convertitem;
1117

    
1118
                    ProcessStartInfo startInfo = null;
1119

    
1120
                    startInfo = new ProcessStartInfo("iexplore.exe", convertitem.MarkusLink);
1121

    
1122
                    Process.Start(startInfo);
1123
                }
1124
            }
1125
        }
1126

    
1127
        #endregion
1128

    
1129
        #region Data Delete
1130

    
1131
        private void DataDelete(object obj)
1132
        {
1133
            RadWindow.Alert("do you want to delete it??", this.OnClosed);
1134
        }
1135

    
1136
        private void OnClosed(object sender, WindowClosedEventArgs e)
1137
        {
1138
            var result = e.DialogResult;
1139
            if (result == true)
1140
            {
1141
                ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString);
1142
                var resultRealConvert = _DataConvert.RemoveItem(SelectRealConvert.ConvertID);
1143
                var resultFiltertConvert = _DataConvert.RemoveItem(SelectFilterConvert.ConvertID);
1144
                System.Diagnostics.Debug.WriteLine(resultRealConvert + "  " + resultFiltertConvert);
1145
            }
1146
        }
1147

    
1148

    
1149
        #endregion
1150

    
1151
        #region Data Export
1152

    
1153

    
1154
        /// <summary>
1155
        /// 필터된 상단 그리드 엑셀로 출력
1156
        /// </summary>
1157

    
1158
        public void DataExportData(object obj)
1159
        {
1160
            SaveFileDialog saveFileDialog = new SaveFileDialog();
1161

    
1162
            saveFileDialog.FileName = "Document"; // Default file name
1163
            saveFileDialog.DefaultExt = ".txt"; // Default file extension
1164
            saveFileDialog.Filter = "Csv documents (.Csv)|*.csv|Excel(2017~2019)Worksheets|*.xlsx"; // Filter files by extension
1165

    
1166

    
1167
            if (saveFileDialog.ShowDialog() == true)
1168
            {
1169

    
1170

    
1171
                if (!string.IsNullOrWhiteSpace(saveFileDialog.FileName))
1172
                {
1173

    
1174
                    var extension = new System.IO.FileInfo(saveFileDialog.FileName).Extension;
1175

    
1176
                    if (extension == ".xlsx" || extension == ".csv")
1177
                    {
1178

    
1179
                        var headers = new List<HeaderMember>
1180
                        {
1181
                            new HeaderMember{HeaderName = "ServiceID", Property = "ServiceID" },
1182
                            new HeaderMember{HeaderName = "ConvertID", Property = "ConvertID" },
1183
                            new HeaderMember{HeaderName = "ProjectNumber", Property = "ProjectNumber" },
1184
                            new HeaderMember{HeaderName = "ConvertState", Property = "ConvertState" },
1185
                            new HeaderMember{HeaderName = "CurrentPageNo", Property = "CurrentPageNo" },
1186
                            new HeaderMember{HeaderName = "TotalPage", Property = "TotalPage" },
1187
                            new HeaderMember{HeaderName = "OriginfilePath", Property = "OriginfilePath" },
1188
                            new HeaderMember{HeaderName = "ConvertPath", Property = "ConvertPath" },
1189
                            new HeaderMember{HeaderName = "CreateTime", Property = "CreateTime" },
1190
                            new HeaderMember{HeaderName = "Exception", Property = "Exception" },
1191
                            new HeaderMember{HeaderName = "ProcessorAffinity", Property = "ProcessorAffinity" },
1192
                            new HeaderMember{HeaderName = "ReConverter", Property = "ReConverter" },
1193
                            new HeaderMember{HeaderName = "UniqueKey", Property = "UniqueKey" }
1194
                        };
1195

    
1196

    
1197
                        DataExport dataExport = new DataExport();
1198
                        dataExport.DataExportExcel(saveFileDialog.FileName, "Hello world", FilterConvertSource, headers);
1199
                        //_dataExport.DataExportExcel(saveFileDialog.FileName, saveFileDialog.FileName.ToString(),  Projectsource, headers);
1200
                        //GemBoxFileSave(obj);
1201
                    }
1202
                }
1203
            }
1204
        }
1205

    
1206
        #endregion
1207

    
1208
        #region Data Search
1209

    
1210
        public void RemoveCreateTimeFilter(object obj)
1211
        {
1212
            DefaultCreateTime = DateTime.Now;
1213
            SelectedCreateTimeBegin = DefaultCreateTime;
1214
            SelectedCreateTimeEnd = DefaultCreateTime;
1215

    
1216
        }
1217

    
1218
        #endregion
1219

    
1220
        #region Reset
1221

    
1222
        /// <summary>
1223
        /// 그리드 상단 원상복귀 버튼
1224
        /// 필터를 끝낸 후 다시 복귀
1225
        /// </summary>
1226

    
1227
        public void Reset(object obj)
1228
        {
1229
            dispatcherTimer.Tick += new EventHandler(Timer_Tick);
1230
        }
1231

    
1232
        #endregion
1233

    
1234

    
1235
        #region ConvertAddDialog
1236

    
1237
        /// <summary>
1238
        /// 그리드 상단 Conver 추가 버튼
1239
        /// ProjectNo, DocumentURL, DocumentID, 입력해서 저장 프로시저에서 추가 
1240
        /// </summary>
1241

    
1242
        public void ConverAdd(object obj)
1243
        {
1244
            dispatcherTimer.Tick -= new EventHandler(Timer_Tick);
1245

    
1246
            Views.ConvertAddDialog convertAddDialog = new Views.ConvertAddDialog();
1247

    
1248
            convertAddDialog.ShowDialog();
1249

    
1250
            dispatcherTimer.Tick += new EventHandler(Timer_Tick);
1251
        }
1252

    
1253
        #endregion
1254

    
1255
        #endregion
1256
    }
1257
}
1258

    
클립보드 이미지 추가 (최대 크기: 500 MB)