프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseItemsModel.cs @ 43b2e236

이력 | 보기 | 이력해설 | 다운로드 (45.7 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 StatusTypeList _StatusType;
219
        public StatusTypeList StatusType
220
        {
221
            get => _StatusType;
222
            set
223
            {
224
                _StatusType = value;
225
                OnPropertyChanged(() => StatusType);
226
            }
227
        }
228

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

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

    
253
                return _StatusCodeList;
254
            }
255
        }
256

    
257
        public bool _ConvertShow;
258
        public bool ConvertShow
259
        {
260
            get => _ConvertShow;
261
            set
262
            {
263
                if (_ConvertShow = !value)
264
                {
265
                    _ConvertShow = false;
266
                }
267
                _ConvertShow = value;
268
                OnPropertyChanged(() => ConvertShow);
269
            }
270
        }
271

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

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

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

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

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

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

    
388
                }
389
            }
390
        }
391

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

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

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

    
452
        static DateTime DefaultCreateTime = DateTime.Now;
453
        private DateTime _SelectedCreateTimeBegin = DefaultCreateTime;
454
        public DateTime SelectedCreateTimeBegin
455
        {
456

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

    
468
            }
469
        }
470

    
471
        private DateTime _SelectedCreateTimeEnd = DefaultCreateTime;
472
        public DateTime SelectedCreateTimeEnd
473
        {
474

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

    
486
            }
487
        }
488

    
489
        public int _DocpanelHeigh = 800;
490
        public int DocpanelHeight //나중에 다시 해야함
491
        {
492
            get { return _DocpanelHeigh; }
493
            set
494
            {
495
                _DocpanelHeigh = value;
496
                OnPropertyChanged(() => DocpanelHeight);
497
            }
498
        }
499

    
500
        private string _Click = "Click";
501
        public string Click
502
        {
503

    
504
            get { return _Click; }
505
        }
506
        #endregion
507

    
508
        #region Command
509

    
510
        public DelegateCommand ConvertCommand { get; private set; }
511
        public DelegateCommand DeleteCommand { get; private set; }
512
        public DelegateCommand ValidateCommand { get; private set; }
513
        public DelegateCommand DataSaveFileGemBoxCommand { get; private set; }
514
        public DelegateCommand MarkusLinkCommand { get; private set; }
515
        public DelegateCommand RemoveCreateTimeFilterCommand { get; private set; }
516

    
517
        public DelegateCommand DataFilterCommand { get; private set; }
518
        public DelegateCommand ResetCommand { get; private set; }
519
        public DelegateCommand ConverAddCommand { get; private set; }
520

    
521
        #endregion
522

    
523
        #region Main Logic
524

    
525
        /// <summary>
526
        /// 각각의 Grid row 객체들 업데이트
527
        /// </summary>
528

    
529
        private DispatcherTimer dispatcherTimer;
530
        //public override void Loaded()
531
        //{
532
        //    base.Loaded();
533

    
534
        //    if (!App.IsDesignMode)
535
        //    {
536
        //        dispatcherTimer = new DispatcherTimer();
537
        //        dispatcherTimer.Tick += new EventHandler(Timer_Tick);
538
        //        dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
539
        //        dispatcherTimer.Start();
540
        //    }
541
        //}
542

    
543
        private async void Timer_Tick(object sender, EventArgs e)
544
        {
545
            dispatcherTimer.Stop();
546

    
547
            if (IsAcitve)
548
            {
549
                await App.Current.Dispatcher.InvokeAsync(() =>
550
                {
551
                    DataSelect();
552

    
553
                    AliveDataSelect();
554
                });
555
            }
556

    
557
            await Task.Delay(5000);
558

    
559
            //System.Threading.Thread.Sleep(new TimeSpan(0,0,0,0,100));
560

    
561
            dispatcherTimer.Start();
562
        }
563

    
564
        public override void Closed()
565
        {
566
            if (dispatcherTimer != null)
567
            {
568
                dispatcherTimer.Stop();
569
            }
570

    
571
            base.Closed();
572
        }
573

    
574

    
575
        #endregion
576

    
577
        #region Function
578

    
579
        #region Data Select
580

    
581
        /// <summary>
582
        /// 상단 그리드 중앙 그리드 출력 데이터
583
        /// </summary>
584
        private void DataSelect()
585
        {
586

    
587
            if (FilterConvertSource == null)
588
            {
589
                FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
590
            }
591

    
592
            if (RealConvertSource == null)
593
            {
594
                RealConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
595
            }
596

    
597
            /// combobox 에서 선택된 items
598
            if (SelectedStatus != null)
599
            {
600
                DataSelect(new[] { (StatusCodeType)(SelectedStatus.Value) }, FilterConvertSource);
601
            }
602

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

    
606
        }
607

    
608
        private void RealDataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection)
609
        {
610
            try
611
            {
612
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
613
                {
614
                    var items = database.GetConvertProjects(collection)//x:database객체 y:statusCodeTypeList의값  Count()안에 predicator 조건 만족하면 count개수안에 넣음
615
                                          .Take(SelectedCount.ValueMember).ToList();//
616

    
617
                    items.ForEach(newitem =>
618
                    {
619
                        collection.UpdateWhere(changeitem =>
620
                        ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ConvertID == newitem.ConvertID && x.ProjectNumber == newitem.ProjectNumber);
621
                    });
622
                }
623
            }
624
            catch (Exception ex)
625
            {
626
                MessageBox.Show(ex.ToString());
627
            }
628
        }
629

    
630
        private void DataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection)
631
        {
632
            try
633
            {
634
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
635
                {
636

    
637
                    int _status = 0;
638
                    if (SelectedStatus != null)
639
                    {
640
                        _status = (int)SelectedStatus.Value;
641
                    }
642

    
643

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

    
648
                    if (collection.Count() == 0)
649
                    {
650
                        if (statusCodeTypeList.Count() == 1)
651
                        {
652
                            items.ForEach(x => collection.Add(x));
653
                        }
654
                    }
655
                    else
656
                    {
657

    
658
                        ////세미 업데이트
659
                        items.ForEach(newitem =>
660
                        {
661
                            collection.UpdateWhere(changeitem =>
662
                            ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID);
663
                        });
664

    
665
                        if (statusCodeTypeList.Count() == 1)
666
                        {
667
                            //삭제
668
                            for (int i = collection.Count() - 1; i >= 0; --i)
669
                            {
670
                                var item = collection[i];
671

    
672
                                if (items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//디비에서 가져온 값과 마지막값부터 차례대로 비교
673
                                {//참=> 0제외한 모든 수
674
                                    collection.RemoveAt(i);
675
                                }
676
                            }
677
                        }
678

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

    
704
                                }
705

    
706
                            }
707
                        }
708

    
709
                    }
710
                }
711

    
712
            }
713
            catch (Exception ex)
714
            {
715
                //MessageBox.Show(ex.ToString());
716
                System.Diagnostics.Debug.WriteLine(ex.ToString());
717
            }
718
        }
719

    
720
        private void DataSearch(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection)
721
        {
722
            try
723
            {
724
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
725
                {
726
                    using (markusEntities entities = new markusEntities())
727
                    {
728

    
729

    
730
                        int _status = 0;
731
                        if (SelectedStatus != null)
732
                        {
733
                            _status = (int)SelectedStatus.Value;
734
                        }
735

    
736
                        //DocumentID = unikey
737

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

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

    
745
                        List<ConvertItem> Listitems = new List<ConvertItem>();
746

    
747
                        foreach (var x in items)
748
                        {
749
                            var convertpath = database.GetSearchConvertPathAndMarkus(x.PROJECT_NO, x.DOCUMENT_ID);
750

    
751
                            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
752
                             , x.DOCUMENT_URL, convertpath[0], convertpath[1]);
753
                            Listitems.Add(AddItem);
754
                            //이거 없으면 collection.Insert(i, item); 할때 문제 생김
755
                        }
756

    
757
                        if (collection.Count() == 0)
758
                        {
759
                            if (statusCodeTypeList.Count() == 1)
760
                            {
761
                                foreach (var x in Listitems)
762
                                {
763
                                    collection.Add(x);
764
                                }
765
                            }
766
                        }
767
                        else
768
                        {
769

    
770
                            ////세미 업데이트
771
                            foreach (var newitem in Listitems)
772
                            {
773
                                collection.UpdateWhere(changeitem =>
774
                                ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID);
775
                            }
776

    
777

    
778
                            if (statusCodeTypeList.Count() == 1)
779
                            {
780

    
781
                                //삭제
782
                                for (int i = collection.Count() - 1; i >= 0; --i)
783
                                {
784
                                    var item = collection[i];
785

    
786
                                    if (Listitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
787
                                    {
788
                                        collection.RemoveAt(i);
789
                                    }
790
                                }
791
                            }
792

    
793
                            if (statusCodeTypeList.Count() == 1)
794
                            {
795
                                //추가 convert 후 추가됨
796
                                foreach (var item in Listitems)
797
                                {
798
                                    if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
799
                                    {
800
                                        for (int i = 0; i < 200; i++)
801
                                        {
802
                                            if (i < collection.Count() - 1)
803
                                            {
804
                                                if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0)
805
                                                {
806
                                                    collection.Insert(i, item);
807
                                                    break;
808
                                                }
809
                                            }
810
                                            else
811
                                            {
812
                                                collection.Add(item);
813
                                                break;
814
                                            }
815
                                        }
816

    
817
                                    }
818

    
819
                                }
820
                            }
821

    
822
                        }
823
                    }
824
                }
825

    
826
            }
827
            catch (Exception ex)
828
            {
829
                //MessageBox.Show(ex.ToString());
830
                System.Diagnostics.Debug.WriteLine(ex.ToString());
831
            }
832
        }
833
        /// <summary>
834
        /// 서비스의 실시간 컨버터 Item
835
        /// </summary>
836
        private async void AliveDataSelect()
837
        {
838
            try
839
            {
840
                List<ConvertItem> newitems = new List<ConvertItem>();
841

    
842
                foreach (var client in App.StationClientList)
843
                {
844
                    if (await SimplePingAsync(client.Endpoint.Address.ToString()))
845
                    {
846
                        try
847
                        {
848
                            List<ConvertItem> itemsToList = new List<ConvertItem>();
849
                            var items = await client.AliveConvertListAsync();
850
                            foreach (var item in items)
851
                            {
852
                                ConvertItem itemsToEach = new ConvertItem();
853
                                itemsToEach.ServiceID = item.ServiceID;
854
                                itemsToEach.ConvertID = item.ConvertID;
855
                                itemsToEach.ProjectNumber = item.ProjectNumber;
856

    
857
                                if (item.ConvertState != null)
858
                                {
859
                                    itemsToEach.ConvertState = (StatusCodeType)Enum.Parse(typeof(StatusCodeType), item.ConvertState);
860
                                }
861

    
862
                                itemsToEach.CurrentPageNo = item.CurrentPageNo;
863
                                itemsToEach.TotalPage = item.TotalPage;
864
                                itemsToEach.OriginfilePath = item.OriginfilePath;
865
                                itemsToEach.ConvertPath = item.ConvertPath;
866
                                itemsToEach.MarkusLink = item.MarkusLink;
867
                                itemsToEach.UniqueKey = item.UniqueKey;
868
                                itemsToEach.FileName = item.FileName;
869
                                itemsToEach.ConvertPath = item.ConvertPath;
870
                                itemsToEach.CreateTime = item.CreateTime;
871
                                itemsToEach.Exception = item.Exception;
872
                                itemsToEach.ProcessorAffinity = item.ProcessorAffinity;
873
                                itemsToEach.ReConverter = item.ReConverter;
874
                                itemsToEach.DocumentID = item.DocumentID;
875
                                itemsToEach.DocumnetName = item.DocumnetName;
876
                                itemsToEach.GroupNo = item.GroupNo;
877
                                itemsToEach.Revision = item.Revision;
878
                                itemsToEach.StartTime = item.StartTime;
879
                                itemsToEach.EndTime = item.EndTime;
880

    
881

    
882
                                itemsToList.Add(itemsToEach);
883
                            }
884
                            newitems.AddRange(itemsToList);
885
                            System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping");
886

    
887
                            if (items.Count() == 0)
888
                            {
889
                                System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero.");
890
                            }
891
                        }
892
                        catch (Exception ex)
893
                        {
894
                            System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}");
895
                        }
896
                    }
897
                    else
898
                    {
899
                        System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error");
900
                    }
901
                }
902

    
903
                ItemsUpdate(newitems);
904
                await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems));
905
            }
906
            catch (Exception ex)
907
            {
908
                System.Diagnostics.Debug.WriteLine(ex.ToString());
909
            }
910
        }
911

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

    
919
            foreach (var item in newitems)
920
            {
921
                item.OriginfilePath = HttpUtility.UrlDecode(item.OriginfilePath);
922
            }
923

    
924
            if (AliveItems == null)
925
            {
926
                AliveItems = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
927

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

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

    
950
                /// 삭제
951

    
952
                for (int i = AliveItems.Count() - 1; i > -1; --i)
953
                {
954
                    var item = AliveItems[i];
955

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

    
971

    
972
        public static async Task<bool> SimplePingAsync(string uri)
973
        {
974
            bool result = false;
975

    
976
            try
977
            {
978
                using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient())
979
                {
980
                    Client.Timeout = new TimeSpan(0, 0, 60);
981

    
982
                    var message = await Client.GetAsync(uri);
983

    
984
                    System.Net.HttpStatusCode StatusCode = message.StatusCode;
985

    
986
                    switch (StatusCode)
987
                    {
988

    
989
                        case System.Net.HttpStatusCode.Accepted:
990
                        case System.Net.HttpStatusCode.OK:
991
                            result = true;
992
                            break;
993
                    }
994
                }
995
            }
996
            catch (Exception ex)
997
            {
998
                result = false;
999
                System.Diagnostics.Debug.WriteLine(ex.ToString());
1000
            }
1001

    
1002
            return result;
1003
        }
1004

    
1005
        #endregion
1006

    
1007
        #region Data Convert
1008

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

    
1021
                if (SelectRealConvert != null)
1022
                {
1023
                    resultRealConvert = _DataConvert.SetCleanUpItem(SelectRealConvert);
1024
                }
1025
                else if (SelectFilterConvert != null)
1026
                {
1027
                    resultFiltertConvert = _DataConvert.SetCleanUpItem(SelectFilterConvert);
1028
                }
1029
                System.Diagnostics.Debug.WriteLine(resultRealConvert + "  " + resultFiltertConvert);
1030

    
1031
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
1032
                {
1033
                    var items = database.GetConvertProjects(SelectFilterConvert);
1034

    
1035
                    foreach (var item in items)
1036
                    {
1037
                        RealConvertSource.Add(item);
1038
                    }
1039
                    if (RealConvertSource.Count() == 1)
1040
                    {
1041
                        ConvertShow = true;
1042
                    }
1043
                }
1044
            }
1045
        }
1046

    
1047
        #endregion
1048

    
1049
        #region Validation
1050

    
1051
        private void DataValidate(object obj)
1052
        {
1053

    
1054
            bool result = false;
1055

    
1056
            WebRequest webRequest = WebRequest.Create(SelectFilterConvert.OriginfilePath);
1057
            webRequest.Timeout = 1200; // miliseconds
1058
            webRequest.Method = "HEAD";
1059

    
1060
            HttpWebResponse response = null;
1061

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

    
1085
        #endregion
1086

    
1087
        #region DataFilter
1088

    
1089
        public void DataFilter(object obj)
1090
        {
1091
            dispatcherTimer.Tick -= new EventHandler(Timer_Tick);
1092
            DataSearch(new[] { (StatusCodeType)(SelectedStatus.Value) }, FilterConvertSource);
1093
            //dispatcherTimer.Start();
1094
        }
1095

    
1096
        #endregion
1097

    
1098
        #region MarkusLink
1099

    
1100
        private void MarkusLink(object obj)///여기서 부터 
1101
        {
1102
            if (obj is ConvertItem)
1103
            {
1104
                if (obj != null)
1105
                {
1106
                    var convertitem = obj as ConvertItem;
1107

    
1108
                    SelectFilterConvert = convertitem;
1109

    
1110
                    SelectRealConvert = convertitem;
1111

    
1112
                    ProcessStartInfo startInfo = null;
1113

    
1114
                    startInfo = new ProcessStartInfo("iexplore.exe", convertitem.MarkusLink);
1115

    
1116
                    Process.Start(startInfo);
1117
                }
1118
            }
1119
        }
1120

    
1121
        #endregion
1122

    
1123
        #region Data Delete
1124

    
1125
        private void DataDelete(object obj)
1126
        {
1127
            RadWindow.Alert("do you want to delete it??", this.OnClosed);
1128
        }
1129

    
1130
        private void OnClosed(object sender, WindowClosedEventArgs e)
1131
        {
1132
            var result = e.DialogResult;
1133
            if (result == true)
1134
            {
1135
                ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString);
1136
                var resultRealConvert = _DataConvert.RemoveItem(SelectRealConvert.ConvertID);
1137
                var resultFiltertConvert = _DataConvert.RemoveItem(SelectFilterConvert.ConvertID);
1138
                System.Diagnostics.Debug.WriteLine(resultRealConvert + "  " + resultFiltertConvert);
1139
            }
1140
        }
1141

    
1142

    
1143
        #endregion
1144

    
1145
        #region Data Export
1146

    
1147

    
1148
        /// <summary>
1149
        /// 필터된 상단 그리드 엑셀로 출력
1150
        /// </summary>
1151

    
1152
        public void DataExportData(object obj)
1153
        {
1154
            SaveFileDialog saveFileDialog = new SaveFileDialog();
1155

    
1156
            saveFileDialog.FileName = "Document"; // Default file name
1157
            saveFileDialog.DefaultExt = ".txt"; // Default file extension
1158
            saveFileDialog.Filter = "Csv documents (.Csv)|*.csv|Excel(2017~2019)Worksheets|*.xlsx"; // Filter files by extension
1159

    
1160

    
1161
            if (saveFileDialog.ShowDialog() == true)
1162
            {
1163

    
1164

    
1165
                if (!string.IsNullOrWhiteSpace(saveFileDialog.FileName))
1166
                {
1167

    
1168
                    var extension = new System.IO.FileInfo(saveFileDialog.FileName).Extension;
1169

    
1170
                    if (extension == ".xlsx" || extension == ".csv")
1171
                    {
1172

    
1173
                        var headers = new List<HeaderMember>
1174
                        {
1175
                            new HeaderMember{HeaderName = "ServiceID", Property = "ServiceID" },
1176
                            new HeaderMember{HeaderName = "ConvertID", Property = "ConvertID" },
1177
                            new HeaderMember{HeaderName = "ProjectNumber", Property = "ProjectNumber" },
1178
                            new HeaderMember{HeaderName = "ConvertState", Property = "ConvertState" },
1179
                            new HeaderMember{HeaderName = "CurrentPageNo", Property = "CurrentPageNo" },
1180
                            new HeaderMember{HeaderName = "TotalPage", Property = "TotalPage" },
1181
                            new HeaderMember{HeaderName = "OriginfilePath", Property = "OriginfilePath" },
1182
                            new HeaderMember{HeaderName = "ConvertPath", Property = "ConvertPath" },
1183
                            new HeaderMember{HeaderName = "CreateTime", Property = "CreateTime" },
1184
                            new HeaderMember{HeaderName = "Exception", Property = "Exception" },
1185
                            new HeaderMember{HeaderName = "ProcessorAffinity", Property = "ProcessorAffinity" },
1186
                            new HeaderMember{HeaderName = "ReConverter", Property = "ReConverter" },
1187
                            new HeaderMember{HeaderName = "UniqueKey", Property = "UniqueKey" }
1188
                        };
1189

    
1190

    
1191
                        DataExport dataExport = new DataExport();
1192
                        dataExport.DataExportExcel(saveFileDialog.FileName, "Hello world", FilterConvertSource, headers);
1193
                        //_dataExport.DataExportExcel(saveFileDialog.FileName, saveFileDialog.FileName.ToString(),  Projectsource, headers);
1194
                        //GemBoxFileSave(obj);
1195
                    }
1196
                }
1197
            }
1198
        }
1199

    
1200
        #endregion
1201

    
1202
        #region Data Search
1203

    
1204

    
1205
        /// <summary>
1206
        /// Grid Filter
1207
        /// </summary>
1208

    
1209
        private bool DetailFilter(object item)
1210
        {
1211
            var Item = item as ConvertItem;
1212
            if (ProjectNumberFilter == null) return true;
1213
            if (ProjectNumberFilter == Item.ProjectNumber) return true;
1214
            //if (ConvertStateFilter == null) return true;
1215
            //if (ConvertStateFilter == (StatusCodeType)Item.ConvertState) return true;
1216
            if (Docuemnt_NameFilter == null) return true;
1217
            if (Docuemnt_NameFilter == Item.DocumnetName) return true;
1218
            if (Service_IDFilter == null) return true;
1219
            if (Service_IDFilter == Item.ServiceID) return true;
1220
            if (UniqueKeyFilter == null) return true;
1221
            if (UniqueKeyFilter == Item.UniqueKey) return true;
1222
            if (Docuemnt_NOFilter == null) return true;
1223
            if (Docuemnt_NOFilter == Item.DocumnetNo) return true;
1224
            if (ReconverterFilter == null) return true;
1225
            if (ReconverterFilter == Item.ReConverter) return true;
1226
            if (RevisionFilter == null) return true;
1227
            if (RevisionFilter == Item.Revision) return true;
1228

    
1229
            return false;
1230
        }
1231

    
1232
        public void RemoveCreateTimeFilter(object obj)
1233
        {
1234
            DefaultCreateTime = DateTime.Now;
1235
            SelectedCreateTimeBegin = DefaultCreateTime;
1236
            SelectedCreateTimeEnd = DefaultCreateTime;
1237

    
1238
        }
1239

    
1240
        #endregion
1241

    
1242
        #region Reset
1243

    
1244
        /// <summary>
1245
        /// 그리드 상단 원상복귀 버튼
1246
        /// 필터를 끝낸 후 다시 복귀
1247
        /// </summary>
1248

    
1249
        public void Reset(object obj)
1250
        {
1251
            dispatcherTimer.Tick += new EventHandler(Timer_Tick);
1252
        }
1253

    
1254
        #endregion
1255

    
1256

    
1257
        #region
1258

    
1259
        /// <summary>
1260
        /// 그리드 상단 Conver 추가 버튼
1261
        /// ProjectNo, DocumentURL, DocumentID, 입력해서 저장 프로시저에서 추가 
1262
        /// </summary>
1263

    
1264
        public void ConverAdd(object obj)
1265
        {
1266
            //줄 530줄 load부분 주석 처리하면 잘됨 
1267
            //dispatcherTimer.Stop();
1268

    
1269
            Views.ConvertAddDialog convertAddDialog = new Views.ConvertAddDialog();
1270
            convertAddDialog.ShowDialog();
1271

    
1272
            //dispatcherTimer.Start();
1273
        }
1274

    
1275
        #endregion
1276

    
1277
        #endregion
1278
    }
1279
}
1280

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