markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseByStatusViewModel.cs @ a6e5055d
이력 | 보기 | 이력해설 | 다운로드 (5.74 KB)
1 | 06f13e11 | taeseongkim | |
---|---|---|---|
2 | 6f6e7dbf | taeseongkim | 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 | b92f142f | taeseongkim | using Markus.Service.StationController.Extensions; |
11 | using Markus.Service.Interface; |
||
12 | 3aafb914 | taeseongkim | using Markus.Service.StationController.Behaviors; |
13 | 6f6e7dbf | taeseongkim | |
14 | namespace Markus.Service.StationController.ViewModel |
||
15 | { |
||
16 | public class DataBaseByStatusViewModel : Mvvm.ToolKit.ViewModelBase |
||
17 | { |
||
18 | BackgroundWorker backgroundWorker; |
||
19 | |||
20 | b92f142f | taeseongkim | private System.Collections.ObjectModel.ObservableCollection<ConvertItem> items; |
21 | private ConvertItem selectItem; |
||
22 | |||
23 | 3aafb914 | taeseongkim | private StatusTypeList statusType; |
24 | 6f6e7dbf | taeseongkim | private bool isLoading; |
25 | |||
26 | b92f142f | taeseongkim | public System.Collections.ObjectModel.ObservableCollection<ConvertItem> Items |
27 | 6f6e7dbf | taeseongkim | { |
28 | get => items; set |
||
29 | { |
||
30 | items = value; |
||
31 | OnPropertyChanged(() => Items); |
||
32 | } |
||
33 | } |
||
34 | |||
35 | b92f142f | taeseongkim | public ConvertItem SelectItem |
36 | { |
||
37 | get => selectItem; set |
||
38 | { |
||
39 | selectItem = value; |
||
40 | OnPropertyChanged(() => SelectItem); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | |||
45 | 3aafb914 | taeseongkim | public StatusTypeList StatusType |
46 | 6f6e7dbf | taeseongkim | { |
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 | b92f142f | taeseongkim | |
67 | |||
68 | 6f6e7dbf | taeseongkim | 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 | b92f142f | taeseongkim | private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) |
84 | 6f6e7dbf | taeseongkim | { |
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 | b92f142f | taeseongkim | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
96 | 6f6e7dbf | taeseongkim | { |
97 | 60723dc9 | taeseongkim | foreach (var status in statusType) |
98 | { |
||
99 | newitems.AddRange(database.GetConvertItems(status, x => x.TOTAL_PAGE > 100, 10)); |
||
100 | } |
||
101 | 6f6e7dbf | taeseongkim | } |
102 | |||
103 | b92f142f | taeseongkim | if (Items == null) |
104 | { |
||
105 | Items = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
||
106 | 6f6e7dbf | taeseongkim | |
107 | b92f142f | taeseongkim | 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 | 6f6e7dbf | taeseongkim | } |
142 | catch (Exception ex) |
||
143 | { |
||
144 | a6e5055d | alzkakdixm | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
145 | 6f6e7dbf | taeseongkim | } |
146 | } |
||
147 | |||
148 | } |
||
149 | |||
150 | public override void Loaded() |
||
151 | { |
||
152 | base.Loaded(); |
||
153 | |||
154 | a34f58f6 | taeseongkim | if (!App.IsDesignMode) |
155 | b92f142f | taeseongkim | { |
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 | 6f6e7dbf | taeseongkim | |
162 | b92f142f | taeseongkim | backgroundWorker.RunWorkerAsync(); |
163 | } |
||
164 | 6f6e7dbf | taeseongkim | } |
165 | |||
166 | public override void Closed() |
||
167 | { |
||
168 | a34f58f6 | taeseongkim | if (!App.IsDesignMode) |
169 | b92f142f | taeseongkim | { |
170 | backgroundWorker.DoWork -= backgroundWorker_DoWork; |
||
171 | backgroundWorker.RunWorkerCompleted -= backgroundWorker_RunWorkerCompleted; |
||
172 | backgroundWorker.WorkerReportsProgress = false; |
||
173 | backgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
||
174 | 6f6e7dbf | taeseongkim | |
175 | b92f142f | taeseongkim | backgroundWorker.Dispose(); |
176 | } |
||
177 | 6f6e7dbf | taeseongkim | |
178 | base.Closed(); |
||
179 | } |
||
180 | } |
||
181 | } |