프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseItemsModel.cs @ 8c128693

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

1
using Markus.Message;
2
using Markus.Service.DataBase;
3
using Markus.Service.Extensions;
4
using Markus.Service.StationController.Data;
5
using Markus.Service.StationController.Behaviors;
6
using Markus.Service.StationController.Extensions;
7
using Markus.Service.StationController.Controls;
8
using Microsoft.Win32;
9
using System;
10
using System.Collections.Generic;
11
using System.ComponentModel;
12
using System.Linq;
13
using System.Threading.Tasks;
14
using System.Web;
15
using System.Windows;
16
using Telerik.Windows.Controls;
17
using Telerik.Windows.Data;
18
using ConvertItem = Markus.Service.Interface.ConvertItem;
19
using System.Net;
20
using System.Windows.Threading;
21
using System.Diagnostics;
22
using System.Windows.Input;
23
using Markus.Mvvm.ToolKit;
24
using System.Windows.Data;
25

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

    
33
        /// <summary>
34
        /// 실행하면 처음 들어가는 부분
35
        /// </summary>
36
        public DataBaseItemsModel()
37
        {
38
            DataFilterCommand = new DelegateCommand(DataFilter);
39
            DataSaveFileGemBoxCommand = new DelegateCommand(DataExportData);
40
            ConvertCommand = new DelegateCommand(DataConvert);
41
            DeleteCommand = new DelegateCommand(DataDelete);
42
            ValidateCommand = new DelegateCommand(DataValidate);
43
            MarkusLinkCommand = new DelegateCommand(MarkusLink);
44
            RemoveCreateTimeFilterCommand = new DelegateCommand(RemoveCreateTimeFilter);
45
            FilterConvertSourceView.Filter = new Predicate<object>(o => DetailFilter(o as ConvertItem));
46
            ResetCommand = new DelegateCommand(Reset);
47
            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
                //if (view.CanFilter)
88
                //{
89
                //    view.Filter = DetailFilter;
90
                //    view.Filter = o => String.IsNullOrEmpty(ProjectNumberFilter) ? true : ((string)o).Contains(ProjectNumberFilter);
91
                //    view.Filter = o => String.IsNullOrEmpty(UniqueKeyFilter) ? true : ((string)o).Contains(UniqueKeyFilter);
92
                //}
93
                return view;
94
            }
95
        }
96

    
97
        private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _FilterConvertSource;
98
        public System.Collections.ObjectModel.ObservableCollection<ConvertItem> FilterConvertSource
99
        {
100
            //get => _FilterConvertSource;
101
            get
102
            {
103
                if (_FilterConvertSource == null)
104
                {
105
                    _FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
106
                }
107
                //if (_FilterConvertSource != null)
108
                //{
109
                //    var view = CollectionViewSource.GetDefaultView(FilterConvertSource);
110
                //    if (view.CanFilter)
111
                //    {
112
                //        view.Filter = DetailFilter;
113
                //    }
114
                //}
115
                return _FilterConvertSource;
116
            }
117
            set
118
            {
119
                _FilterConvertSource = value;
120
                OnPropertyChanged(() => FilterConvertSource);
121
            }
122
        }
123

    
124

    
125
        private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _RealConvertSource;
126
        public System.Collections.ObjectModel.ObservableCollection<ConvertItem> RealConvertSource
127
        {
128
            get => _RealConvertSource;
129
            set
130
            {
131
                _RealConvertSource = value;
132
                OnPropertyChanged(() => RealConvertSource);
133
            }
134
        }
135

    
136

    
137
        private System.Windows.Documents.FlowDocument connectionLog;
138
        public System.Windows.Documents.FlowDocument ConnectionLog
139
        {
140
            get => connectionLog;
141
            set
142
            {
143
                if (connectionLog != value)
144
                {
145
                    connectionLog = value;
146
                    OnPropertyChanged(() => ConnectionLog);
147
                }
148
            }
149
        }
150

    
151

    
152
        private Telerik.Windows.Data.EnumMemberViewModel _SelectedStatus;
153
        public Telerik.Windows.Data.EnumMemberViewModel SelectedStatus
154
        {
155
            get => _SelectedStatus;
156
            set
157
            {
158
                _SelectedStatus = value;
159
                OnPropertyChanged(() => SelectedStatus);
160
            }
161
        }
162

    
163

    
164
        private SelectedCountItem _SelectedCount;
165
        public SelectedCountItem SelectedCount
166
        {
167
            get => _SelectedCount;
168
            set
169
            {
170
                _SelectedCount = value;
171
                OnPropertyChanged(() => SelectedCount);
172
            }
173
        }
174

    
175
        List<SelectedCountItem> _SelectedCountList;
176
        public List<SelectedCountItem> SelectedCountList
177
        {
178
            get
179
            {
180
                if (_SelectedCountList == null)
181
                {
182
                    _SelectedCountList = new List<SelectedCountItem>
183
                    {
184
                        new SelectedCountItem{DisplayMember = "50",ValueMember = 50},
185
                        new SelectedCountItem{DisplayMember = "100",ValueMember = 100},
186
                        new SelectedCountItem{DisplayMember = "150",ValueMember = 150},
187
                        new SelectedCountItem{DisplayMember = "200",ValueMember = 200}
188
                    };
189
                }
190

    
191
                return _SelectedCountList;
192
            }
193
        }
194

    
195
        private ConvertItem _SelectFilterConvert;
196
        public ConvertItem SelectFilterConvert
197
        {
198
            get => _SelectFilterConvert;
199
            set
200
            {
201
                _SelectFilterConvert = value;
202
                OnPropertyChanged(() => SelectFilterConvert);
203
            }
204
        }
205

    
206
        private ConvertItem _SelectRealConvert;
207
        public ConvertItem SelectRealConvert
208
        {
209
            get => _SelectRealConvert;
210
            set
211
            {
212
                _SelectRealConvert = value;
213
                OnPropertyChanged(() => SelectRealConvert);
214
            }
215
        }
216

    
217

    
218
        private ConvertItem _SelectAliveConvert;
219
        public ConvertItem SelectAliveConvert
220
        {
221
            get => _SelectAliveConvert;
222
            set
223
            {
224
                _SelectAliveConvert = value;
225
                OnPropertyChanged(() => SelectAliveConvert);
226
            }
227
        }
228

    
229

    
230
        private StatusTypeList _StatusType;
231
        public StatusTypeList StatusType
232
        {
233
            get => _StatusType;
234
            set
235
            {
236
                _StatusType = value;
237
                OnPropertyChanged(() => StatusType);
238
            }
239
        }
240

    
241
        private bool _IsLoading;
242
        public bool IsLoading
243
        {
244
            get => _IsLoading;
245
            set
246
            {
247
                if (_IsLoading != value)
248
                {
249
                    _IsLoading = value;
250
                    OnPropertyChanged(() => IsLoading);
251
                }
252
            }
253
        }
254

    
255
        IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> _StatusCodeList;
256
        public IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> StatusCodeList
257
        {
258
            get
259
            {
260
                if (_StatusCodeList == null)
261
                {
262
                    _StatusCodeList = Telerik.Windows.Data.EnumDataSource.FromType<StatusCodeType>();
263
                }
264

    
265
                return _StatusCodeList;
266
            }
267
        }
268

    
269
        public string _ProjectNumberFilter;
270
        public string ProjectNumberFilter
271
        {
272
            get { return _ProjectNumberFilter; }
273
            set
274
            {
275
                if(_ProjectNumberFilter == "")
276
                {
277
                    _ProjectNumberFilter = null;
278
                }
279
                else if (_ProjectNumberFilter != value)
280
                {
281
                    _ProjectNumberFilter = value;
282
                    OnPropertyChanged(() => ProjectNumberFilter);
283
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
284
                    //FilterConvertSourceView.Refresh();
285
                }
286
            }
287
        }
288

    
289
        public string _UniqueKeyFilter;
290
        public string UniqueKeyFilter
291
        {
292
            get
293
            {
294
                return _UniqueKeyFilter;
295
            }
296
            set
297
            {
298
                if (_UniqueKeyFilter == "")
299
                {
300
                    _UniqueKeyFilter = null;
301
                }
302
                else if (_UniqueKeyFilter != value)
303
                {
304
                    _UniqueKeyFilter = value;
305
                    OnPropertyChanged(() => UniqueKeyFilter);
306
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
307
                    //FilterConvertSourceView.Refresh();
308
                }
309
            }
310
        }
311

    
312
        public StatusCodeType _ConvertStateFilter;
313
        public StatusCodeType ConvertStateFilter
314
        {
315
            get { return _ConvertStateFilter; }
316
            set
317
            {
318
                if (_ConvertStateFilter != value)
319
                {
320
                    _ConvertStateFilter = value;
321
                    OnPropertyChanged(() => ConvertStateFilter);
322
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
323
                    //FilterConvertSourceView.Refresh();
324
                }
325
            }
326
        }
327

    
328
        public string _Docuemnt_NOFilter;
329
        public string Docuemnt_NOFilter
330
        {
331
            get { return _Docuemnt_NOFilter; }
332
            set
333
            {
334
                if (_Docuemnt_NOFilter == "")
335
                {
336
                    _Docuemnt_NOFilter = null;
337
                }
338
                else if (_Docuemnt_NOFilter != value)
339
                {
340
                    _Docuemnt_NOFilter = value;
341
                    OnPropertyChanged(() => Docuemnt_NOFilter);
342
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
343
                    //FilterConvertSourceView.Refresh();
344
                }
345
            }
346
        }
347

    
348
        public string _Docuemnt_NameFilter;
349
        public string Docuemnt_NameFilter
350
        {
351
            get { return _Docuemnt_NameFilter; }
352
            set
353
            {
354
                if (_Docuemnt_NameFilter == "")
355
                {
356
                    _Docuemnt_NameFilter = null;
357
                }
358
                else if (_Docuemnt_NameFilter != value)
359
                {
360
                    _Docuemnt_NameFilter = value;
361
                    OnPropertyChanged(() => Docuemnt_NameFilter);
362
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
363
                    //FilterConvertSourceView.Refresh();
364
                }
365
            }
366
        }
367

    
368
        public int? _ReconverterFilter = 0;
369
        public int? ReconverterFilter
370
        {
371
            get { return _ReconverterFilter; }
372
            set
373
            {
374
                if (_ReconverterFilter ==  null)
375
                {
376
                    _ReconverterFilter = 0;
377
                }
378
                else if (_ReconverterFilter != value)
379
                {
380
                    _ReconverterFilter = value;
381
                    OnPropertyChanged(() => ReconverterFilter);
382
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
383
                    //FilterConvertSourceView.Refresh();
384

    
385
                }
386
            }
387
        }
388

    
389
        public string _Service_IDFilter;
390
        public string Service_IDFilter
391
        {
392
            get { return _Service_IDFilter; }
393
            set
394
            {
395
                if (_Service_IDFilter == "")
396
                {
397
                    _Service_IDFilter = null;
398
                }
399
                else  if (_Service_IDFilter != value)
400
                {
401
                    _Service_IDFilter = value;
402
                    OnPropertyChanged(() => Service_IDFilter);
403
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
404
                    //FilterConvertSourceView.Refresh();
405
                }
406
            }
407
        }
408

    
409
        public string _RevisionFilter;
410
        public string RevisionFilter
411
        {
412
            get { return _RevisionFilter; }
413
            set
414
            {
415
                if (_RevisionFilter == "")
416
                {
417
                    _RevisionFilter = null ;
418
                }
419
                else if (_RevisionFilter != value)
420
                {
421
                    _RevisionFilter = value;
422
                    OnPropertyChanged(() => RevisionFilter);
423
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
424
                    //FilterConvertSourceView.Refresh();
425
                }
426
            }
427
        }
428

    
429
        public string _GroupNOFilter;
430
        public string GroupNOFilter
431
        {
432
            get { return _GroupNOFilter; }
433
            set
434
            {
435
                if (_GroupNOFilter == "")
436
                {
437
                    _GroupNOFilter = null;
438
                }
439
                else if (_GroupNOFilter != value)
440
                {
441
                    _GroupNOFilter = value;
442
                    OnPropertyChanged(() => GroupNOFilter);
443
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
444
                    //FilterConvertSourceView.Refresh();
445
                }
446
            }
447
        }
448

    
449
        static DateTime DefaultCreateTime = DateTime.Now;
450
        private DateTime _SelectedCreateTimeBegin = DefaultCreateTime;
451
        public DateTime SelectedCreateTimeBegin
452
        {
453

    
454
            get { return _SelectedCreateTimeBegin; }
455
            set
456
            {
457
                if (_SelectedCreateTimeBegin == value)
458
                    return;
459
                _SelectedCreateTimeBegin = value;
460
                OnPropertyChanged(() => SelectedCreateTimeBegin);
461
                //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
462
                //FilterConvertSourceView.Refresh();
463
                //AddGeneratorBeginFilter();
464

    
465
            }
466
        }
467

    
468
        private DateTime _SelectedCreateTimeEnd = DefaultCreateTime;
469
        public DateTime SelectedCreateTimeEnd
470
        {
471

    
472
            get { return _SelectedCreateTimeEnd; }
473
            set
474
            {
475
                if (_SelectedCreateTimeEnd == value)
476
                    return;
477
                _SelectedCreateTimeEnd = value;
478
                OnPropertyChanged(() => SelectedCreateTimeEnd);
479
                //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
480
                //FilterConvertSourceView.Refresh();
481
                //AddGeneratorBeginFilter();
482

    
483
            }
484
        }
485

    
486
        public int _DataBase_ItemsHeight = 800;
487
        public int DataBase_ItemsHeight 
488
        {
489
            get { return _DataBase_ItemsHeight; }
490
            set
491
            {
492
                _DataBase_ItemsHeight = value;
493
                OnPropertyChanged(() => DataBase_ItemsHeight);
494

    
495
            }
496
        }
497

    
498

    
499
        public int _RealConvert_Height = 80;
500
        public int RealConvert_Height
501
        {
502
            get { return _RealConvert_Height; }
503
            set
504
            {
505
                _RealConvert_Height = value;
506
                OnPropertyChanged(() => RealConvert_Height);
507
            }
508
        }
509

    
510
        public int _Alive_Height = 80;
511
        public int Alive_Height
512
        {
513
            get { return _Alive_Height; }
514
            set
515
            {
516
                _Alive_Height = value;
517
                OnPropertyChanged(() => Alive_Height);
518
            }
519
        }
520

    
521
        public bool _ConvertShow;
522
        public bool ConvertShow
523
        {
524
            get => _ConvertShow;
525
            set
526
            {
527
                if (_ConvertShow = !value)
528
                {
529
                    _ConvertShow = false;
530
                }
531
                _ConvertShow = value;
532
                OnPropertyChanged(() => ConvertShow);
533
            }
534
        }
535

    
536
        #endregion
537

    
538
        #region Command
539

    
540
        public DelegateCommand ConvertCommand { get; private set; }
541
        public DelegateCommand DeleteCommand { get; private set; }
542
        public DelegateCommand ValidateCommand { get; private set; }
543
        public DelegateCommand DataSaveFileGemBoxCommand { get; private set; }
544
        public DelegateCommand MarkusLinkCommand { get; private set; }
545
        public DelegateCommand RemoveCreateTimeFilterCommand { get; private set; }
546

    
547
        public DelegateCommand DataFilterCommand { get; private set; }
548
        public DelegateCommand ResetCommand { get; private set; }
549
        public DelegateCommand ConverAddCommand { get; private set; }
550

    
551
        #endregion
552

    
553
        #region Main Logic
554

    
555
        /// <summary>
556
        /// 각각의 Grid row 객체들 업데이트
557
        /// </summary>
558

    
559
        private DispatcherTimer dispatcherTimer;
560
        public override void Loaded()
561
        {
562
            base.Loaded();
563

    
564
            if (!App.IsDesignMode)
565
            {
566
                dispatcherTimer = new DispatcherTimer();
567
                dispatcherTimer.Tick += new EventHandler(Timer_Tick);
568
                dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
569
                dispatcherTimer.Start();
570
            }
571
        }
572

    
573
        private async void Timer_Tick(object sender, EventArgs e)
574
        {
575
            dispatcherTimer.Stop();
576

    
577
            if (IsAcitve)
578
            {
579
                await App.Current.Dispatcher.InvokeAsync(() =>
580
                {
581
                    DataSelect();
582

    
583
                    AliveDataSelect();
584
                });
585
            }
586

    
587
            await Task.Delay(5000);
588

    
589
            //System.Threading.Thread.Sleep(new TimeSpan(0,0,0,0,100));
590

    
591
            dispatcherTimer.Start();
592
        }
593

    
594
        public override void Closed()
595
        {
596
            if (dispatcherTimer != null)
597
            {
598
                dispatcherTimer.Stop();
599
            }
600

    
601
            base.Closed();
602
        }
603

    
604

    
605
        #endregion
606

    
607
        #region Function
608

    
609
        #region Data Select
610

    
611
        /// <summary>
612
        /// 상단 그리드 중앙 그리드 출력 데이터
613
        /// </summary>
614
        private void DataSelect()
615
        {
616

    
617
            if (FilterConvertSource == null)
618
            {
619
                FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
620
            }
621

    
622
            if (RealConvertSource == null)
623
            {
624
                RealConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
625
            }
626

    
627
            /// combobox 에서 선택된 items
628
            if (SelectedStatus != null)
629
            {
630
                DataSelect(new[] { (StatusCodeType)(SelectedStatus.Value) }, FilterConvertSource);
631
            }
632

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

    
636
        }
637

    
638
        private void RealDataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection)
639
        {
640
            try
641
            {
642
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
643
                {
644
                    var items = database.GetConvertProjects(collection)//x:database객체 y:statusCodeTypeList의값  Count()안에 predicator 조건 만족하면 count개수안에 넣음
645
                                          .Take(SelectedCount.ValueMember).ToList();//
646

    
647
                    items.ForEach(newitem =>
648
                    {
649
                        collection.UpdateWhere(changeitem =>
650
                        ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ConvertID == newitem.ConvertID && x.ProjectNumber == newitem.ProjectNumber);
651
                    });
652

    
653
                    RealConvert_Height = 80 + ( 10 * collection.Count());
654
                    DataBase_ItemsHeight = 800 - (RealConvert_Height + Alive_Height);
655
                }
656
            }
657
            catch (Exception ex)
658
            {
659
                MessageBox.Show(ex.ToString());
660
            }
661
        }
662

    
663
        private void DataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection)
664
        {
665
            try
666
            {
667
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
668
                {
669

    
670
                    int _status = 0;
671
                    if (SelectedStatus != null)
672
                    {
673
                        _status = (int)SelectedStatus.Value;
674
                    }
675

    
676

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

    
681
                    if (collection.Count() == 0)
682
                    {
683
                        if (statusCodeTypeList.Count() == 1)
684
                        {
685
                            items.ForEach(x => collection.Add(x));
686
                        }
687
                    }
688
                    else
689
                    {
690

    
691
                        ////세미 업데이트
692
                        items.ForEach(newitem =>
693
                        {
694
                            collection.UpdateWhere(changeitem =>
695
                            ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID);
696
                        });
697

    
698
                        if (statusCodeTypeList.Count() == 1)
699
                        {
700
                            //삭제
701
                            for (int i = collection.Count() - 1; i >= 0; --i)
702
                            {
703
                                var item = collection[i];
704

    
705
                                if (items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//디비에서 가져온 값과 마지막값부터 차례대로 비교
706
                                {//참=> 0제외한 모든 수
707
                                    collection.RemoveAt(i);
708
                                }
709
                            }
710
                        }
711

    
712
                        if (statusCodeTypeList.Count() == 1)
713
                        {
714
                            //추가 convert 후 추가됨
715
                            foreach (var item in items)
716
                            {
717
                                if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감
718
                                {
719
                                    /*for (int i = 0; i < collection.Count()+1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가*/
720
                                    for (int i = 0; i < 200; i++)
721
                                    {
722
                                        if (i < collection.Count() - 1)
723
                                        {
724
                                            if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0)
725
                                            {
726
                                                collection.Insert(i, item);
727
                                                break;
728
                                            }
729
                                        }
730
                                        else
731
                                        {
732
                                            collection.Add(item);
733
                                            break;
734
                                        }
735
                                    }
736

    
737
                                }
738

    
739
                            }
740
                        }
741

    
742
                    }
743
                }
744

    
745
            }
746
            catch (Exception ex)
747
            {
748
                //MessageBox.Show(ex.ToString());
749
                System.Diagnostics.Debug.WriteLine(ex.ToString());
750
            }
751
        }
752

    
753
        private void DataSearch(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection)
754
        {
755
            try
756
            {
757
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
758
                {
759
                    using (markusEntities entities = new markusEntities())
760
                    {
761

    
762

    
763
                        int _status = 0;
764
                        if (SelectedStatus != null)
765
                        {
766
                            _status = (int)SelectedStatus.Value;
767
                        }
768

    
769
                        //DocumentID = unikey
770

    
771
                        //null 왼쪽에서 부터 p_BEGIN_START_DATETIE, p_Finish_START_DATETIE, BEGIN_END_DATETIME, Finish_END_DATETIME (전에 없애라고 하셔서..)
772
                        //오류떠서  [Model].Context.tt File에서  288줄  Function.Name to edmFunction.FullName바꿨더니 오류 안남
773
                        var items = entities.SELECT_CONVERT_ITEM(ProjectNumberFilter, UniqueKeyFilter, _status, SelectedCount.ValueMember, SelectedCreateTimeBegin, SelectedCreateTimeEnd, null, null, null, null, GroupNOFilter,
774
                            Docuemnt_NameFilter, Docuemnt_NOFilter, RevisionFilter).ToList();//이대로 그냥 쓰면 쿼리 -> 쿼리 결과는 두 번 이상 열거할 수 없습니다 뜸
775

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

    
778
                        List<ConvertItem> Listitems = new List<ConvertItem>();
779

    
780
                        foreach (var x in items)
781
                        {
782
                            var convertpath = database.GetSearchConvertPathAndMarkus(x.PROJECT_NO, x.DOCUMENT_ID);
783

    
784
                            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
785
                             , x.DOCUMENT_URL, convertpath[0], convertpath[1]);
786
                            Listitems.Add(AddItem);
787
                            //이거 없으면 collection.Insert(i, item); 할때 문제 생김
788
                        }
789

    
790
                        if (collection.Count() == 0)
791
                        {
792
                            if (statusCodeTypeList.Count() == 1)
793
                            {
794
                                foreach (var x in Listitems)
795
                                {
796
                                    collection.Add(x);
797
                                }
798
                            }
799
                        }
800
                        else
801
                        {
802

    
803
                            ////세미 업데이트
804
                            foreach (var newitem in Listitems)
805
                            {
806
                                collection.UpdateWhere(changeitem =>
807
                                ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID);
808
                            }
809

    
810

    
811
                            if (statusCodeTypeList.Count() == 1)
812
                            {
813

    
814
                                //삭제
815
                                for (int i = collection.Count() - 1; i >= 0; --i)
816
                                {
817
                                    var item = collection[i];
818

    
819
                                    if (Listitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
820
                                    {
821
                                        collection.RemoveAt(i);
822
                                    }
823
                                }
824
                            }
825

    
826
                            if (statusCodeTypeList.Count() == 1)
827
                            {
828
                                //추가 convert 후 추가됨
829
                                foreach (var item in Listitems)
830
                                {
831
                                    if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
832
                                    {
833
                                        for (int i = 0; i < 200; i++)
834
                                        {
835
                                            if (i < collection.Count() - 1)
836
                                            {
837
                                                if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0)
838
                                                {
839
                                                    collection.Insert(i, item);
840
                                                    break;
841
                                                }
842
                                            }
843
                                            else
844
                                            {
845
                                                collection.Add(item);
846
                                                break;
847
                                            }
848
                                        }
849

    
850
                                    }
851

    
852
                                }
853
                            }
854

    
855
                        }
856
                    }
857
                }
858

    
859
            }
860
            catch (Exception ex)
861
            {
862
                //MessageBox.Show(ex.ToString());
863
                System.Diagnostics.Debug.WriteLine(ex.ToString());
864
            }
865
        }
866
        /// <summary>
867
        /// 서비스의 실시간 컨버터 Item
868
        /// </summary>
869
        private async void AliveDataSelect()
870
        {
871
            try
872
            {
873
                List<ConvertItem> newitems = new List<ConvertItem>();
874
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
875
                {
876
                    foreach (var client in App.StationClientList)
877
                    {
878
                        if (await SimplePingAsync(client.Endpoint.Address.ToString()))
879
                        {
880
                            try
881
                            {
882
                                List<ConvertItem> itemsToList = new List<ConvertItem>();
883
                                var items = await client.AliveConvertListAsync();
884
                                string result = "";
885

    
886
                                foreach (var item in items)
887
                                {
888
                                    ConvertItem itemsToEach = new ConvertItem();
889
                                    itemsToEach.ServiceID = item.ServiceID;
890
                                    itemsToEach.ConvertID = item.ConvertID;
891
                                    itemsToEach.ProjectNumber = item.ProjectNumber;
892

    
893
                                    var convertpath = database.GetSearchConvertPathAndMarkus(item.ProjectNumber, item.UniqueKey);
894

    
895
                                    if (item.ConvertState != null)
896
                                    {
897
                                        itemsToEach.ConvertState = (StatusCodeType)Enum.Parse(typeof(StatusCodeType), item.ConvertState);
898
                                    }
899

    
900
                                    if (item.OriginfilePath.Contains("/"))
901
                                    {
902
                                        result = item.OriginfilePath.Substring(item.OriginfilePath.LastIndexOf("/") + 1);
903
                                    }
904
                                    else
905
                                    {
906
                                        result = item.OriginfilePath.Substring(item.OriginfilePath.LastIndexOf("%") + 1);
907
                                    }
908
                                    itemsToEach.FileName = result;
909

    
910
                                    itemsToEach.CurrentPageNo = item.CurrentPageNo;
911
                                    itemsToEach.TotalPage = item.TotalPage;
912
                                    itemsToEach.OriginfilePath = item.OriginfilePath;
913
                                    itemsToEach.ConvertPath = item.ConvertPath;
914
                                    itemsToEach.MarkusLink = convertpath[1];
915
                                    itemsToEach.UniqueKey = item.UniqueKey;
916

    
917
                                    //itemsToEach.ConvertPath = item.ConvertPath;
918
                                    itemsToEach.ConvertPath = convertpath[0];
919
                                    itemsToEach.CreateTime = item.CreateTime;
920
                                    itemsToEach.Exception = item.Exception;
921
                                    itemsToEach.ProcessorAffinity = item.ProcessorAffinity;
922
                                    itemsToEach.ReConverter = item.ReConverter;
923
                                    itemsToEach.DocumentID = item.DocumentID;
924
                                    itemsToEach.DocumnetName = item.DocumnetName;
925
                                    itemsToEach.GroupNo = item.GroupNo;
926
                                    itemsToEach.Revision = item.Revision;
927
                                    itemsToEach.StartTime = item.StartTime;
928
                                    itemsToEach.EndTime = item.EndTime;
929

    
930
                                    itemsToList.Add(itemsToEach);
931
                                }
932
                                newitems.AddRange(itemsToList);
933
                                System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping");
934

    
935
                                if (items.Count() == 0)
936
                                {
937
                                    System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero.");
938
                                }
939
                            }
940
                            catch (Exception ex)
941
                            {
942
                                System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}");
943
                            }
944
                        }
945
                        else
946
                        {
947
                            System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error");
948
                        }
949
                    }
950
                }
951
                ItemsUpdate(newitems);
952
                await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems));
953
            }
954
            catch (Exception ex)
955
            {
956
                System.Diagnostics.Debug.WriteLine(ex.ToString());
957
            }
958
        }
959

    
960
        /// <summary>
961
        /// AliveDataSelect의 Data Update
962
        /// </summary>
963
        /// <param name="newitems"></param>
964
        private void ItemsUpdate(List<ConvertItem> newitems)
965
        {
966

    
967
            foreach (var item in newitems)
968
            {
969
                item.OriginfilePath = HttpUtility.UrlDecode(item.OriginfilePath);
970
            }
971

    
972
            if (AliveItems == null)
973
            {
974
                AliveItems = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
975

    
976
                foreach (var item in newitems)
977
                {
978
                    AliveItems.Add(item);
979
                }
980
            }
981
            else
982
            {
983
                /// 데이터 업데이트
984
                newitems.ForEach(newitem =>
985
                {
986
                    AliveItems.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID);
987
                });
988

    
989
                // 추가
990
                foreach (var item in newitems)
991
                {
992
                    if (AliveItems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
993
                    {
994
                        AliveItems.Add(item);
995
                    }
996
                }
997

    
998
                /// 삭제
999

    
1000
                for (int i = AliveItems.Count() - 1; i > -1; --i)
1001
                {
1002
                    var item = AliveItems[i];
1003

    
1004
                    if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
1005
                    {
1006
                        try
1007
                        {
1008
                            AliveItems.RemoveAt(i);
1009
                        }
1010
                        catch (Exception ex)
1011
                        {
1012
                            System.Diagnostics.Debug.WriteLine(ex.ToString());
1013
                        }
1014
                    }
1015
                }
1016
            }
1017

    
1018
            Alive_Height = 80 + (newitems.Count() * 10 );
1019
            DataBase_ItemsHeight = 800 - ( RealConvert_Height + Alive_Height);
1020
        }
1021

    
1022

    
1023
        public static async Task<bool> SimplePingAsync(string uri)
1024
        {
1025
            bool result = false;
1026

    
1027
            try
1028
            {
1029
                using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient())
1030
                {
1031
                    Client.Timeout = new TimeSpan(0, 0, 60);
1032

    
1033
                    var message = await Client.GetAsync(uri);
1034

    
1035
                    System.Net.HttpStatusCode StatusCode = message.StatusCode;
1036

    
1037
                    switch (StatusCode)
1038
                    {
1039

    
1040
                        case System.Net.HttpStatusCode.Accepted:
1041
                        case System.Net.HttpStatusCode.OK:
1042
                            result = true;
1043
                            break;
1044
                    }
1045
                }
1046
            }
1047
            catch (Exception ex)
1048
            {
1049
                result = false;
1050
                System.Diagnostics.Debug.WriteLine(ex.ToString());
1051
            }
1052

    
1053
            return result;
1054
        }
1055

    
1056
        #endregion
1057

    
1058
        #region Data Convert
1059

    
1060
        private void DataConvert(object obj)
1061
        {
1062
            if (SelectFilterConvert == null && SelectRealConvert == null)
1063
            {
1064
                MessageBox.Show("왼쪽 버튼 클릭 후 Converter 해주세요!");
1065
            }
1066
            else
1067
            {
1068
                ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString);
1069
                var resultRealConvert = 0;
1070
                var resultFiltertConvert = 0;
1071

    
1072
                if (SelectRealConvert != null)
1073
                {
1074
                    resultRealConvert = _DataConvert.SetCleanUpItem(SelectRealConvert);
1075
                }
1076
                else if (SelectFilterConvert != null)
1077
                {
1078
                    resultFiltertConvert = _DataConvert.SetCleanUpItem(SelectFilterConvert);
1079
                }
1080
                System.Diagnostics.Debug.WriteLine(resultRealConvert + "  " + resultFiltertConvert);
1081

    
1082
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
1083
                {
1084
                    var items = database.GetConvertProjects(SelectFilterConvert);
1085

    
1086
                    foreach (var item in items)
1087
                    {
1088
                        RealConvertSource.Add(item);
1089
                    }
1090
                    if (RealConvertSource.Count() == 1)
1091
                    {
1092
                        ConvertShow = true;
1093
                    }
1094
                }
1095
            }
1096
        }
1097

    
1098
        #endregion
1099

    
1100
        #region Validation
1101

    
1102
        private void DataValidate(object obj)
1103
        {
1104

    
1105
            bool result = false;
1106

    
1107
            WebRequest webRequest = WebRequest.Create(SelectFilterConvert.OriginfilePath);
1108
            webRequest.Timeout = 1200; // miliseconds
1109
            webRequest.Method = "HEAD";
1110

    
1111
            HttpWebResponse response = null;
1112

    
1113
            try
1114
            {
1115
                response = (HttpWebResponse)webRequest.GetResponse();
1116
                result = true;
1117
            }
1118
            catch (WebException webException)
1119
            {
1120
                MessageBox.Show(SelectFilterConvert.FileName + " doesn't exist: " + webException.Message);
1121
                result = true;
1122
            }
1123
            finally
1124
            {
1125
                if (response != null)
1126
                {
1127
                    response.Close();
1128
                }
1129
            }
1130
            if (result == true)
1131
            {
1132
                MessageBox.Show("File exists");
1133
            }
1134
        }
1135

    
1136
        #endregion
1137

    
1138
        #region DataFilter
1139

    
1140
        public void DataFilter(object obj)
1141
        {
1142
            dispatcherTimer.Tick -= new EventHandler(Timer_Tick);
1143
            DataSearch(new[] { (StatusCodeType)(SelectedStatus.Value) }, FilterConvertSource);
1144
            //dispatcherTimer.Start();
1145
        }
1146

    
1147
        #endregion
1148

    
1149
        #region MarkusLink
1150

    
1151
        private void MarkusLink(object obj)///여기서 부터 
1152
        {
1153
            if (obj is ConvertItem)
1154
            {
1155
                if (obj != null)
1156
                {
1157
                    var convertitem = obj as ConvertItem;
1158

    
1159
                    SelectFilterConvert = convertitem;
1160

    
1161
                    SelectRealConvert = convertitem;
1162

    
1163
                    ProcessStartInfo startInfo = null;
1164

    
1165
                    startInfo = new ProcessStartInfo("iexplore.exe", convertitem.MarkusLink);
1166

    
1167
                    Process.Start(startInfo);
1168
                }
1169
            }
1170
        }
1171

    
1172
        #endregion
1173

    
1174
        #region Data Delete
1175

    
1176
        private void DataDelete(object obj)
1177
        {
1178
            RadWindow.Alert("do you want to delete it??", this.OnClosed);
1179
        }
1180

    
1181
        private void OnClosed(object sender, WindowClosedEventArgs e)
1182
        {
1183
            var result = e.DialogResult;
1184
            if (result == true)
1185
            {
1186
                ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString);
1187
                var resultRealConvert = _DataConvert.RemoveItem(SelectRealConvert.ConvertID);
1188
                var resultFiltertConvert = _DataConvert.RemoveItem(SelectFilterConvert.ConvertID);
1189
                System.Diagnostics.Debug.WriteLine(resultRealConvert + "  " + resultFiltertConvert);
1190
            }
1191
        }
1192

    
1193

    
1194
        #endregion
1195

    
1196
        #region Data Export
1197

    
1198

    
1199
        /// <summary>
1200
        /// 필터된 상단 그리드 엑셀로 출력
1201
        /// </summary>
1202

    
1203
        public void DataExportData(object obj)
1204
        {
1205
            SaveFileDialog saveFileDialog = new SaveFileDialog();
1206

    
1207
            saveFileDialog.FileName = "Document"; // Default file name
1208
            saveFileDialog.DefaultExt = ".txt"; // Default file extension
1209
            saveFileDialog.Filter = "Csv documents (.Csv)|*.csv|Excel(2017~2019)Worksheets|*.xlsx"; // Filter files by extension
1210

    
1211

    
1212
            if (saveFileDialog.ShowDialog() == true)
1213
            {
1214

    
1215

    
1216
                if (!string.IsNullOrWhiteSpace(saveFileDialog.FileName))
1217
                {
1218

    
1219
                    var extension = new System.IO.FileInfo(saveFileDialog.FileName).Extension;
1220

    
1221
                    if (extension == ".xlsx" || extension == ".csv")
1222
                    {
1223

    
1224
                        var headers = new List<HeaderMember>
1225
                        {
1226
                            new HeaderMember{HeaderName = "ServiceID", Property = "ServiceID" },
1227
                            new HeaderMember{HeaderName = "ConvertID", Property = "ConvertID" },
1228
                            new HeaderMember{HeaderName = "ProjectNumber", Property = "ProjectNumber" },
1229
                            new HeaderMember{HeaderName = "ConvertState", Property = "ConvertState" },
1230
                            new HeaderMember{HeaderName = "CurrentPageNo", Property = "CurrentPageNo" },
1231
                            new HeaderMember{HeaderName = "TotalPage", Property = "TotalPage" },
1232
                            new HeaderMember{HeaderName = "OriginfilePath", Property = "OriginfilePath" },
1233
                            new HeaderMember{HeaderName = "ConvertPath", Property = "ConvertPath" },
1234
                            new HeaderMember{HeaderName = "CreateTime", Property = "CreateTime" },
1235
                            new HeaderMember{HeaderName = "Exception", Property = "Exception" },
1236
                            new HeaderMember{HeaderName = "ProcessorAffinity", Property = "ProcessorAffinity" },
1237
                            new HeaderMember{HeaderName = "ReConverter", Property = "ReConverter" },
1238
                            new HeaderMember{HeaderName = "UniqueKey", Property = "UniqueKey" }
1239
                        };
1240

    
1241

    
1242
                        DataExport dataExport = new DataExport();
1243
                        dataExport.DataExportExcel(saveFileDialog.FileName, "Hello world", FilterConvertSource, headers);
1244
                        //_dataExport.DataExportExcel(saveFileDialog.FileName, saveFileDialog.FileName.ToString(),  Projectsource, headers);
1245
                        //GemBoxFileSave(obj);
1246
                    }
1247
                }
1248
            }
1249
        }
1250

    
1251
        #endregion
1252

    
1253
        #region Data Search
1254

    
1255

    
1256
        /// <summary>
1257
        /// Grid Filter
1258
        /// </summary>
1259

    
1260
        private bool DetailFilter(object item)
1261
        {
1262
            var Item = item as ConvertItem;
1263
            if (ProjectNumberFilter == null) return true;
1264
            if (ProjectNumberFilter == Item.ProjectNumber) return true;
1265
            //if (ConvertStateFilter == null) return true;
1266
            //if (ConvertStateFilter == (StatusCodeType)Item.ConvertState) return true;
1267
            if (Docuemnt_NameFilter == null) return true;
1268
            if (Docuemnt_NameFilter == Item.DocumnetName) return true;
1269
            if (Service_IDFilter == null) return true;
1270
            if (Service_IDFilter == Item.ServiceID) return true;
1271
            if (UniqueKeyFilter == null) return true;
1272
            if (UniqueKeyFilter == Item.UniqueKey) return true;
1273
            if (Docuemnt_NOFilter == null) return true;
1274
            if (Docuemnt_NOFilter == Item.DocumnetNo) return true;
1275
            if (ReconverterFilter == null) return true;
1276
            if (ReconverterFilter == Item.ReConverter) return true;
1277
            if (RevisionFilter == null) return true;
1278
            if (RevisionFilter == Item.Revision) return true;
1279

    
1280
            return false;
1281
        }
1282

    
1283
        public void RemoveCreateTimeFilter(object obj)
1284
        {
1285
            DefaultCreateTime = DateTime.Now;
1286
            SelectedCreateTimeBegin = DefaultCreateTime;
1287
            SelectedCreateTimeEnd = DefaultCreateTime;
1288

    
1289
        }
1290

    
1291
        #endregion
1292

    
1293
        #region Reset
1294

    
1295
        /// <summary>
1296
        /// 그리드 상단 원상복귀 버튼
1297
        /// 필터를 끝낸 후 다시 복귀
1298
        /// </summary>
1299

    
1300
        public void Reset(object obj)
1301
        {
1302
            dispatcherTimer.Tick += new EventHandler(Timer_Tick);
1303
        }
1304

    
1305
        #endregion
1306

    
1307

    
1308
        #region ConvertAddDialog
1309

    
1310
        /// <summary>
1311
        /// 그리드 상단 Conver 추가 버튼
1312
        /// ProjectNo, DocumentURL, DocumentID, 입력해서 저장 프로시저에서 추가 
1313
        /// </summary>
1314

    
1315
        public void ConverAdd(object obj)
1316
        {
1317
            dispatcherTimer.Tick -= new EventHandler(Timer_Tick);
1318

    
1319
            Views.ConvertAddDialog convertAddDialog = new Views.ConvertAddDialog();
1320

    
1321
            convertAddDialog.ShowDialog();
1322

    
1323
            dispatcherTimer.Tick += new EventHandler(Timer_Tick);
1324
        }
1325

    
1326
        #endregion
1327

    
1328

    
1329
        #endregion
1330
    }
1331
}
1332

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