markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseByStatusViewModel.cs @ 2bbea412
이력 | 보기 | 이력해설 | 다운로드 (5.64 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 |
|
13 |
namespace Markus.Service.StationController.ViewModel |
14 |
{ |
15 |
public class DataBaseByStatusViewModel : Mvvm.ToolKit.ViewModelBase |
16 |
{ |
17 |
BackgroundWorker backgroundWorker; |
18 |
|
19 |
private System.Collections.ObjectModel.ObservableCollection<ConvertItem> items; |
20 |
private ConvertItem selectItem; |
21 |
|
22 |
private IEnumerable<StatusCodeType> statusType; |
23 |
private bool isLoading; |
24 |
|
25 |
public System.Collections.ObjectModel.ObservableCollection<ConvertItem> Items |
26 |
{ |
27 |
get => items; set |
28 |
{ |
29 |
items = value; |
30 |
OnPropertyChanged(() => Items); |
31 |
} |
32 |
} |
33 |
|
34 |
public ConvertItem SelectItem |
35 |
{ |
36 |
get => selectItem; set |
37 |
{ |
38 |
selectItem = value; |
39 |
OnPropertyChanged(() => SelectItem); |
40 |
} |
41 |
} |
42 |
|
43 |
|
44 |
public IEnumerable<StatusCodeType> StatusType |
45 |
{ |
46 |
get => statusType; set |
47 |
{ |
48 |
statusType = value; |
49 |
OnPropertyChanged(() => StatusType); |
50 |
} |
51 |
} |
52 |
|
53 |
public bool IsLoading |
54 |
{ |
55 |
get => isLoading; set |
56 |
{ |
57 |
if (isLoading != value) |
58 |
{ |
59 |
isLoading = value; |
60 |
OnPropertyChanged(() => IsLoading); |
61 |
} |
62 |
} |
63 |
} |
64 |
|
65 |
|
66 |
|
67 |
public DataBaseByStatusViewModel() |
68 |
{ |
69 |
} |
70 |
|
71 |
// 진행률에 변화가 있을때 이벤트가 발생 |
72 |
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) |
73 |
{ |
74 |
} |
75 |
|
76 |
// 일이 모두 마쳤을때 수행되어야할 코드 |
77 |
private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
78 |
{ |
79 |
} |
80 |
|
81 |
// BackgroundWorker에서 수행할 일을 정의. |
82 |
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) |
83 |
{ |
84 |
while (IsAcitve) |
85 |
{ |
86 |
System.Threading.Thread.Sleep(1000); |
87 |
|
88 |
try |
89 |
{ |
90 |
IsLoading = true; |
91 |
|
92 |
List<ConvertItem> newitems = new List<ConvertItem>(); |
93 |
|
94 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
95 |
{ |
96 |
foreach (var status in statusType) |
97 |
{ |
98 |
newitems.AddRange(database.GetConvertItems(status, x => x.TOTAL_PAGE > 100, 10)); |
99 |
} |
100 |
} |
101 |
|
102 |
if (Items == null) |
103 |
{ |
104 |
Items = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
105 |
|
106 |
foreach (var item in newitems) |
107 |
{ |
108 |
Items.Add(item); |
109 |
} |
110 |
} |
111 |
else |
112 |
{ |
113 |
/// 데이터 업데이트 |
114 |
newitems.ForEach(newitem => |
115 |
{ |
116 |
Items.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
117 |
}); |
118 |
|
119 |
// 추가 |
120 |
foreach (var item in newitems) |
121 |
{ |
122 |
if (Items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
123 |
{ |
124 |
Items.Add(item); |
125 |
} |
126 |
} |
127 |
|
128 |
/// 삭제 |
129 |
|
130 |
for (int i = Items.Count() - 1; i > -1; --i) |
131 |
{ |
132 |
var item = Items[i]; |
133 |
|
134 |
if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
135 |
{ |
136 |
Items.RemoveAt(i); |
137 |
} |
138 |
} |
139 |
} |
140 |
} |
141 |
catch (Exception ex) |
142 |
{ |
143 |
} |
144 |
} |
145 |
|
146 |
} |
147 |
|
148 |
public override void Loaded() |
149 |
{ |
150 |
base.Loaded(); |
151 |
|
152 |
if (!App.IsDesignMode) |
153 |
{ |
154 |
backgroundWorker = new BackgroundWorker(); |
155 |
backgroundWorker.DoWork += backgroundWorker_DoWork; |
156 |
backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted; |
157 |
backgroundWorker.WorkerReportsProgress = false; |
158 |
backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
159 |
|
160 |
backgroundWorker.RunWorkerAsync(); |
161 |
} |
162 |
} |
163 |
|
164 |
public override void Closed() |
165 |
{ |
166 |
if (!App.IsDesignMode) |
167 |
{ |
168 |
backgroundWorker.DoWork -= backgroundWorker_DoWork; |
169 |
backgroundWorker.RunWorkerCompleted -= backgroundWorker_RunWorkerCompleted; |
170 |
backgroundWorker.WorkerReportsProgress = false; |
171 |
backgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
172 |
|
173 |
backgroundWorker.Dispose(); |
174 |
} |
175 |
|
176 |
base.Closed(); |
177 |
} |
178 |
} |
179 |
} |