프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseByStatusViewModel.cs @ 2decfbdf

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

1

2
using System;
3
using System.Collections.Generic;
4
using System.ComponentModel;
5
using System.Linq;
6
using System.Text;
7
using System.Threading.Tasks;
8
using Markus.Service.Extensions;
9
using Markus.Message;
10
using Markus.Service.StationController.Extensions;
11
using Markus.Service.Interface;
12
using Markus.Service.StationController.Behaviors;
13

    
14
namespace Markus.Service.StationController.ViewModel
15
{
16
    public class DataBaseByStatusViewModel : Mvvm.ToolKit.ViewModelBase
17
    {
18
        BackgroundWorker backgroundWorker;
19

    
20
        private System.Collections.ObjectModel.ObservableCollection<ConvertItem> items;
21
        private ConvertItem selectItem;
22

    
23
        private StatusTypeList statusType;
24
        private bool isLoading;
25

    
26
        public System.Collections.ObjectModel.ObservableCollection<ConvertItem> Items
27
        {
28
            get => items; set
29
            {
30
                items = value;
31
                OnPropertyChanged(() => Items);
32
            }
33
        }
34

    
35
        public ConvertItem SelectItem
36
        {
37
            get => selectItem; set
38
            {
39
                selectItem = value;
40
                OnPropertyChanged(() => SelectItem);
41
            }
42
        }
43

    
44

    
45
        public StatusTypeList StatusType
46
        {
47
            get => statusType; set
48
            {
49
                statusType = value;
50
                OnPropertyChanged(() => StatusType);
51
            }
52
        }
53

    
54
        public bool IsLoading
55
        {
56
            get => isLoading; set
57
            {
58
                if (isLoading != value)
59
                {
60
                    isLoading = value;
61
                    OnPropertyChanged(() => IsLoading);
62
                }
63
            }
64
        }
65

    
66

    
67

    
68
        public DataBaseByStatusViewModel()
69
        {
70
        }
71

    
72
        // 진행률에 변화가 있을때 이벤트가 발생
73
        private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
74
        {
75
        }
76

    
77
        // 일이 모두 마쳤을때 수행되어야할 코드
78
        private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
79
        {
80
        }
81

    
82
        // BackgroundWorker에서 수행할 일을 정의.
83
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
84
        {
85
            while (IsAcitve)
86
            {
87
                System.Threading.Thread.Sleep(1000);
88

    
89
                try
90
                {
91
                    IsLoading = true;
92

    
93
                    List<ConvertItem> newitems = new List<ConvertItem>();
94

    
95
                    using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
96
                    {
97
                        foreach (var status in statusType)
98
                        {
99
                            newitems.AddRange(database.GetConvertItems(status, x => x.TOTAL_PAGE > 100, 10));
100
                        }
101
                    }
102

    
103
                    if (Items == null)
104
                    {
105
                        Items = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
106

    
107
                        foreach (var item in newitems)
108
                        {
109
                            Items.Add(item);
110
                        }
111
                    }
112
                    else
113
                    {
114
                        /// 데이터 업데이트
115
                        newitems.ForEach(newitem =>
116
                        {
117
                            Items.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID);
118
                        });
119

    
120
                        // 추가
121
                        foreach (var item in newitems)
122
                        {
123
                            if (Items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
124
                            {
125
                                Items.Add(item);
126
                            }
127
                        }
128

    
129
                        /// 삭제
130

    
131
                        for (int i = Items.Count() - 1; i > -1; --i)
132
                        {
133
                            var item = Items[i];
134

    
135
                            if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
136
                            {
137
                                Items.RemoveAt(i);
138
                            }
139
                        }
140
                    }
141
                }
142
                catch (Exception ex)
143
                {
144
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
145
                }
146
            }
147

    
148
        }
149

    
150
        public override void Loaded()
151
        {
152
            base.Loaded();
153

    
154
            if (!App.IsDesignMode)
155
            {
156
                backgroundWorker = new BackgroundWorker();
157
                backgroundWorker.DoWork += backgroundWorker_DoWork;
158
                backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;
159
                backgroundWorker.WorkerReportsProgress = false;
160
                backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
161

    
162
                backgroundWorker.RunWorkerAsync();
163
            }
164
        }
165

    
166
        public override void Closed()
167
        {
168
            if (!App.IsDesignMode)
169
            {
170
                backgroundWorker.DoWork -= backgroundWorker_DoWork;
171
                backgroundWorker.RunWorkerCompleted -= backgroundWorker_RunWorkerCompleted;
172
                backgroundWorker.WorkerReportsProgress = false;
173
                backgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
174

    
175
                backgroundWorker.Dispose();
176
            }
177

    
178
            base.Closed();
179
        }
180
    }
181
}
클립보드 이미지 추가 (최대 크기: 500 MB)