markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseItemsModel.cs @ 0cb12397
이력 | 보기 | 이력해설 | 다운로드 (28.2 KB)
1 | a6e5055d | alzkakdixm | using GemBox.Spreadsheet; |
---|---|---|---|
2 | using Markus.Message; |
||
3 | using Markus.Service.DataBase; |
||
4 | using Markus.Service.Extensions; |
||
5 | using Markus.Service.StationController.Behaviors; |
||
6 | using Markus.Service.StationController.Extensions; |
||
7 | using Microsoft.Win32; |
||
8 | using System; |
||
9 | using System.Collections.Generic; |
||
10 | using System.ComponentModel; |
||
11 | using System.Linq; |
||
12 | 2decfbdf | alzkakdixm | using System.Threading.Tasks; |
13 | using System.Web; |
||
14 | a6e5055d | alzkakdixm | using System.Windows; |
15 | using Telerik.Windows.Controls; |
||
16 | using Telerik.Windows.Data; |
||
17 | using ConvertItem = Markus.Service.Interface.ConvertItem; |
||
18 | |||
19 | namespace Markus.Service.StationController.ViewModel |
||
20 | { |
||
21 | //세미 |
||
22 | dfc86b71 | taeseongkim | public class DataBaseItemsModel : Mvvm.ToolKit.ViewModelBase |
23 | a6e5055d | alzkakdixm | { |
24 | 2decfbdf | alzkakdixm | private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _AliveItems; |
25 | public System.Collections.ObjectModel.ObservableCollection<ConvertItem> AliveItems |
||
26 | { |
||
27 | get => _AliveItems; set |
||
28 | { |
||
29 | 0cb12397 | alzkakdixm | _AliveItems = value; |
30 | 2decfbdf | alzkakdixm | OnPropertyChanged(() => AliveItems); |
31 | } |
||
32 | } |
||
33 | |||
34 | dfc86b71 | taeseongkim | private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _FilterConvertSource; |
35 | public System.Collections.ObjectModel.ObservableCollection<ConvertItem> FilterConvertSource |
||
36 | { |
||
37 | get => _FilterConvertSource; |
||
38 | set |
||
39 | { |
||
40 | _FilterConvertSource = value; |
||
41 | OnPropertyChanged(() => FilterConvertSource); |
||
42 | } |
||
43 | } |
||
44 | |||
45 | |||
46 | private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _RealConvertSource; |
||
47 | public System.Collections.ObjectModel.ObservableCollection<ConvertItem> RealConvertSource |
||
48 | { |
||
49 | get => _RealConvertSource; |
||
50 | set |
||
51 | { |
||
52 | _RealConvertSource = value; |
||
53 | OnPropertyChanged(() => RealConvertSource); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | 2decfbdf | alzkakdixm | |
58 | 0cb12397 | alzkakdixm | private System.Windows.Documents.FlowDocument connectionLog; |
59 | 2decfbdf | alzkakdixm | public System.Windows.Documents.FlowDocument ConnectionLog |
60 | { |
||
61 | get => connectionLog; |
||
62 | set |
||
63 | { |
||
64 | if (connectionLog != value) |
||
65 | { |
||
66 | connectionLog = value; |
||
67 | OnPropertyChanged(() => ConnectionLog); |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | |||
72 | //public AliveViewModel() |
||
73 | //{ |
||
74 | //} |
||
75 | |||
76 | //// 진행률에 변화가 있을때 이벤트가 발생 |
||
77 | //private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) |
||
78 | //{ |
||
79 | //} |
||
80 | |||
81 | //// 일이 모두 마쳤을때 수행되어야할 코드 |
||
82 | //private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
||
83 | //{ |
||
84 | //} |
||
85 | |||
86 | // BackgroundWorker에서 수행할 일을 정의. |
||
87 | private void AlivebackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) |
||
88 | { |
||
89 | } |
||
90 | private void AlivebackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
||
91 | { |
||
92 | } |
||
93 | private async void AlivebackgroundWorker_DoWork(object sender, DoWorkEventArgs e) |
||
94 | { |
||
95 | while (IsAcitve) |
||
96 | { |
||
97 | |||
98 | if (!IsLoading) |
||
99 | { |
||
100 | IsLoading = true; |
||
101 | |||
102 | try |
||
103 | { |
||
104 | |||
105 | List<ConvertItem> newitems = new List<ConvertItem>(); |
||
106 | |||
107 | foreach (var client in App.StationClientList) |
||
108 | { |
||
109 | if (await SimplePingAsync(client.Endpoint.Address.ToString())) |
||
110 | { |
||
111 | try |
||
112 | { |
||
113 | List<ConvertItem> itemsToList = new List<ConvertItem>(); |
||
114 | var items = await client.AliveConvertListAsync(); |
||
115 | 0cb12397 | alzkakdixm | |
116 | 2decfbdf | alzkakdixm | foreach (var item in items) |
117 | { |
||
118 | ConvertItem itemsToEach = new ConvertItem(); |
||
119 | itemsToEach.ServiceID = item.ServiceID; |
||
120 | itemsToEach.ConvertID = item.ConvertID; |
||
121 | itemsToEach.ProjectNumber = item.ProjectNumber; |
||
122 | 0cb12397 | alzkakdixm | try |
123 | { |
||
124 | itemsToEach.ConvertState = (StatusCodeType)Enum.Parse(typeof(StatusCodeType), item.ConvertState); |
||
125 | } |
||
126 | catch (Exception ex) |
||
127 | { |
||
128 | |||
129 | throw ex; |
||
130 | } |
||
131 | |||
132 | //itemsToEach.ConvertState = (StatusCodeType)Enum.Parse(typeof(StatusCodeType), item.ConvertState); |
||
133 | 2decfbdf | alzkakdixm | itemsToEach.CurrentPageNo = item.CurrentPageNo; |
134 | itemsToEach.TotalPage = item.TotalPage; |
||
135 | itemsToEach.OriginfilePath = item.OriginfilePath; |
||
136 | itemsToEach.ConvertPath = item.ConvertPath; |
||
137 | |||
138 | itemsToList.Add(itemsToEach); |
||
139 | } |
||
140 | newitems.AddRange(itemsToList); |
||
141 | 0cb12397 | alzkakdixm | System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping"); |
142 | 2decfbdf | alzkakdixm | |
143 | if (items.Count() == 0) |
||
144 | { |
||
145 | 0cb12397 | alzkakdixm | System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero."); |
146 | 2decfbdf | alzkakdixm | } |
147 | } |
||
148 | catch (Exception ex) |
||
149 | { |
||
150 | 0cb12397 | alzkakdixm | System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}"); |
151 | 2decfbdf | alzkakdixm | } |
152 | } |
||
153 | else |
||
154 | { |
||
155 | 0cb12397 | alzkakdixm | System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error"); |
156 | 2decfbdf | alzkakdixm | } |
157 | } |
||
158 | await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems)); |
||
159 | } |
||
160 | catch (Exception ex) |
||
161 | { |
||
162 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
163 | } |
||
164 | |||
165 | IsLoading = false; |
||
166 | } |
||
167 | |||
168 | } |
||
169 | } |
||
170 | |||
171 | |||
172 | private async void AliveDataSelect() |
||
173 | { |
||
174 | try |
||
175 | { |
||
176 | List<ConvertItem> newitems = new List<ConvertItem>(); |
||
177 | |||
178 | foreach (var client in App.StationClientList) |
||
179 | { |
||
180 | if (await SimplePingAsync(client.Endpoint.Address.ToString())) |
||
181 | { |
||
182 | try |
||
183 | { |
||
184 | List<ConvertItem> itemsToList = new List<ConvertItem>(); |
||
185 | var items = await client.AliveConvertListAsync(); |
||
186 | foreach (var item in items) |
||
187 | { |
||
188 | ConvertItem itemsToEach = new ConvertItem(); |
||
189 | itemsToEach.ServiceID = item.ServiceID; |
||
190 | itemsToEach.ConvertID = item.ConvertID; |
||
191 | itemsToEach.ProjectNumber = item.ProjectNumber; |
||
192 | try |
||
193 | { |
||
194 | itemsToEach.ConvertState = (StatusCodeType)Enum.Parse(typeof(StatusCodeType), item.ConvertState); |
||
195 | } |
||
196 | catch (Exception ex) |
||
197 | { |
||
198 | |||
199 | throw ex; |
||
200 | } |
||
201 | 0cb12397 | alzkakdixm | |
202 | 2decfbdf | alzkakdixm | itemsToEach.CurrentPageNo = item.CurrentPageNo; |
203 | itemsToEach.TotalPage = item.TotalPage; |
||
204 | itemsToEach.OriginfilePath = item.OriginfilePath; |
||
205 | itemsToEach.ConvertPath = item.ConvertPath; |
||
206 | |||
207 | itemsToList.Add(itemsToEach); |
||
208 | } |
||
209 | newitems.AddRange(itemsToList); |
||
210 | System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping"); |
||
211 | |||
212 | if (items.Count() == 0) |
||
213 | { |
||
214 | System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero."); |
||
215 | } |
||
216 | } |
||
217 | catch (Exception ex) |
||
218 | { |
||
219 | System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}"); |
||
220 | } |
||
221 | } |
||
222 | else |
||
223 | { |
||
224 | System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error"); |
||
225 | } |
||
226 | } |
||
227 | |||
228 | 0cb12397 | alzkakdixm | ItemsUpdate(newitems); |
229 | 2decfbdf | alzkakdixm | await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems)); |
230 | } |
||
231 | catch (Exception ex) |
||
232 | { |
||
233 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
234 | } |
||
235 | } |
||
236 | |||
237 | |||
238 | private void ItemsUpdate(List<ConvertItem> newitems) |
||
239 | { |
||
240 | |||
241 | foreach (var item in newitems) |
||
242 | { |
||
243 | item.OriginfilePath = HttpUtility.UrlDecode(item.OriginfilePath); |
||
244 | } |
||
245 | |||
246 | 0cb12397 | alzkakdixm | if (AliveItems == null) |
247 | 2decfbdf | alzkakdixm | { |
248 | AliveItems = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
||
249 | |||
250 | foreach (var item in newitems) |
||
251 | { |
||
252 | AliveItems.Add(item); |
||
253 | } |
||
254 | } |
||
255 | else |
||
256 | { |
||
257 | /// 데이터 업데이트 |
||
258 | newitems.ForEach(newitem => |
||
259 | { |
||
260 | AliveItems.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
||
261 | }); |
||
262 | |||
263 | // 추가 |
||
264 | foreach (var item in newitems) |
||
265 | { |
||
266 | if (AliveItems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
||
267 | { |
||
268 | AliveItems.Add(item); |
||
269 | } |
||
270 | } |
||
271 | |||
272 | /// 삭제 |
||
273 | |||
274 | for (int i = AliveItems.Count() - 1; i > -1; --i) |
||
275 | { |
||
276 | var item = AliveItems[i]; |
||
277 | |||
278 | if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
||
279 | { |
||
280 | try |
||
281 | { |
||
282 | AliveItems.RemoveAt(i); |
||
283 | } |
||
284 | catch (Exception ex) |
||
285 | { |
||
286 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
287 | } |
||
288 | } |
||
289 | } |
||
290 | } |
||
291 | } |
||
292 | |||
293 | private void LogWrite(string log, bool IsError) |
||
294 | { |
||
295 | if (IsError) |
||
296 | { |
||
297 | System.Diagnostics.Trace.Fail(log); |
||
298 | } |
||
299 | else |
||
300 | { |
||
301 | System.Diagnostics.Trace.TraceInformation(log); |
||
302 | } |
||
303 | } |
||
304 | |||
305 | |||
306 | public static async Task<bool> SimplePingAsync(string uri) |
||
307 | { |
||
308 | bool result = false; |
||
309 | |||
310 | try |
||
311 | { |
||
312 | using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient()) |
||
313 | { |
||
314 | Client.Timeout = new TimeSpan(0, 0, 60); |
||
315 | |||
316 | var message = await Client.GetAsync(uri); |
||
317 | |||
318 | System.Net.HttpStatusCode StatusCode = message.StatusCode; |
||
319 | |||
320 | switch (StatusCode) |
||
321 | { |
||
322 | |||
323 | case System.Net.HttpStatusCode.Accepted: |
||
324 | case System.Net.HttpStatusCode.OK: |
||
325 | result = true; |
||
326 | break; |
||
327 | } |
||
328 | } |
||
329 | } |
||
330 | catch (Exception ex) |
||
331 | { |
||
332 | result = false; |
||
333 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
334 | } |
||
335 | |||
336 | return result; |
||
337 | } |
||
338 | |||
339 | a6e5055d | alzkakdixm | BackgroundWorker backgroundWorker; |
340 | 0cb12397 | alzkakdixm | private BackgroundWorker AlivebackgroundWorker; |
341 | a6e5055d | alzkakdixm | |
342 | Random rnd = new Random(); |
||
343 | |||
344 | private Telerik.Windows.Data.EnumMemberViewModel _SelectedStatus; |
||
345 | public Telerik.Windows.Data.EnumMemberViewModel SelectedStatus |
||
346 | { |
||
347 | get => _SelectedStatus; |
||
348 | set |
||
349 | { |
||
350 | _SelectedStatus = value; |
||
351 | 0cb12397 | alzkakdixm | OnPropertyChanged(() => SelectedStatus); |
352 | a6e5055d | alzkakdixm | } |
353 | } |
||
354 | |||
355 | |||
356 | private SelectedCountItem _SelectedCount; |
||
357 | public SelectedCountItem SelectedCount |
||
358 | { |
||
359 | get => _SelectedCount; |
||
360 | set |
||
361 | { |
||
362 | _SelectedCount = value; |
||
363 | dfc86b71 | taeseongkim | OnPropertyChanged(() => SelectedCount); |
364 | a6e5055d | alzkakdixm | } |
365 | } |
||
366 | |||
367 | private void DataConvert(object obj) |
||
368 | { |
||
369 | 2decfbdf | alzkakdixm | if (SelectFilterConvert == null && SelectRealConvert == null) |
370 | { |
||
371 | MessageBox.Show("왼쪽 버튼 클릭 후 Converter 해주세요!"); |
||
372 | } |
||
373 | else |
||
374 | { |
||
375 | ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString); |
||
376 | var resultRealConvert = 0; |
||
377 | var resultFiltertConvert = 0; |
||
378 | |||
379 | if (SelectRealConvert != null) |
||
380 | { |
||
381 | resultRealConvert = _DataConvert.SetCleanUpItem(SelectRealConvert); |
||
382 | } |
||
383 | else if (SelectFilterConvert != null) |
||
384 | { |
||
385 | resultFiltertConvert = _DataConvert.SetCleanUpItem(SelectFilterConvert); |
||
386 | } |
||
387 | System.Diagnostics.Debug.WriteLine(resultRealConvert + " " + resultFiltertConvert); |
||
388 | a6e5055d | alzkakdixm | |
389 | 2decfbdf | alzkakdixm | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
390 | { |
||
391 | var items = database.GetConvertProjects(SelectFilterConvert); |
||
392 | |||
393 | foreach (var item in items) |
||
394 | { |
||
395 | RealConvertSource.Add(item); |
||
396 | } |
||
397 | |||
398 | } |
||
399 | } |
||
400 | a6e5055d | alzkakdixm | } |
401 | |||
402 | private void DataDelete(object obj) |
||
403 | { |
||
404 | 2decfbdf | alzkakdixm | RadWindow.Alert("정말로 삭제 하시겠습니까?", this.OnClosed); |
405 | } |
||
406 | a6e5055d | alzkakdixm | |
407 | 2decfbdf | alzkakdixm | private void OnClosed(object sender, WindowClosedEventArgs e) |
408 | { |
||
409 | var result = e.DialogResult; |
||
410 | if (result == true) |
||
411 | { |
||
412 | ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString); |
||
413 | var resultRealConvert = _DataConvert.RemoveItem(SelectRealConvert.ConvertID); |
||
414 | var resultFiltertConvert = _DataConvert.RemoveItem(SelectFilterConvert.ConvertID); |
||
415 | System.Diagnostics.Debug.WriteLine(resultRealConvert + " " + resultFiltertConvert); |
||
416 | } |
||
417 | } |
||
418 | private void DataValidate(object obj) |
||
419 | { |
||
420 | MessageBox.Show("파일 체크 할껀데 정상인지 아닌지 "); |
||
421 | a6e5055d | alzkakdixm | |
422 | } |
||
423 | |||
424 | |||
425 | 0cb12397 | alzkakdixm | private ConvertItem _SelectFilterConvert; |
426 | a6e5055d | alzkakdixm | public ConvertItem SelectFilterConvert |
427 | { |
||
428 | get => _SelectFilterConvert; |
||
429 | set |
||
430 | { |
||
431 | _SelectFilterConvert = value; |
||
432 | dfc86b71 | taeseongkim | OnPropertyChanged(() => SelectFilterConvert); |
433 | a6e5055d | alzkakdixm | } |
434 | } |
||
435 | 0cb12397 | alzkakdixm | |
436 | private ConvertItem _SelectRealConvert; |
||
437 | a6e5055d | alzkakdixm | public ConvertItem SelectRealConvert |
438 | { |
||
439 | get => _SelectRealConvert; |
||
440 | set |
||
441 | { |
||
442 | _SelectRealConvert = value; |
||
443 | dfc86b71 | taeseongkim | OnPropertyChanged(() => SelectRealConvert); |
444 | a6e5055d | alzkakdixm | } |
445 | } |
||
446 | |||
447 | 0cb12397 | alzkakdixm | |
448 | private StatusTypeList _StatusType; |
||
449 | a6e5055d | alzkakdixm | public StatusTypeList StatusType |
450 | { |
||
451 | get => _StatusType; |
||
452 | set |
||
453 | { |
||
454 | _StatusType = value; |
||
455 | dfc86b71 | taeseongkim | OnPropertyChanged(() => StatusType); |
456 | a6e5055d | alzkakdixm | } |
457 | } |
||
458 | |||
459 | 0cb12397 | alzkakdixm | private bool _IsLoading; |
460 | a6e5055d | alzkakdixm | public bool IsLoading |
461 | { |
||
462 | get => _IsLoading; |
||
463 | set |
||
464 | { |
||
465 | if (_IsLoading != value) |
||
466 | { |
||
467 | _IsLoading = value; |
||
468 | dfc86b71 | taeseongkim | OnPropertyChanged(() => IsLoading); |
469 | a6e5055d | alzkakdixm | } |
470 | } |
||
471 | } |
||
472 | |||
473 | List<SelectedCountItem> _SelectedCountList; |
||
474 | public List<SelectedCountItem> SelectedCountList |
||
475 | { |
||
476 | get |
||
477 | { |
||
478 | if (_SelectedCountList == null) |
||
479 | { |
||
480 | _SelectedCountList = new List<SelectedCountItem> |
||
481 | { |
||
482 | new SelectedCountItem{DisplayMember = "50",ValueMember = 50}, |
||
483 | new SelectedCountItem{DisplayMember = "100",ValueMember = 100}, |
||
484 | new SelectedCountItem{DisplayMember = "150",ValueMember = 150}, |
||
485 | new SelectedCountItem{DisplayMember = "200",ValueMember = 200} |
||
486 | }; |
||
487 | } |
||
488 | |||
489 | return _SelectedCountList; |
||
490 | } |
||
491 | } |
||
492 | |||
493 | 0cb12397 | alzkakdixm | public DelegateCommand ConvertCommand { get; private set; } |
494 | public DelegateCommand DeleteCommand { get; private set; } |
||
495 | public DelegateCommand ValidateCommand { get; private set; } |
||
496 | |||
497 | a6e5055d | alzkakdixm | public DataBaseItemsModel() |
498 | { |
||
499 | 0cb12397 | alzkakdixm | DataSaveFileGemBoxCommand = new DelegateCommand(DataExportData); |
500 | a6e5055d | alzkakdixm | ConvertCommand = new DelegateCommand(DataConvert); |
501 | DeleteCommand = new DelegateCommand(DataDelete); |
||
502 | 2decfbdf | alzkakdixm | ValidateCommand = new DelegateCommand(DataValidate); |
503 | a6e5055d | alzkakdixm | } |
504 | |||
505 | // 진행률에 변화가 있을때 이벤트가 발생 |
||
506 | private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) |
||
507 | { |
||
508 | MessageBox.Show("진행률에 변화"); |
||
509 | } |
||
510 | |||
511 | // 일이 모두 마쳤을때 수행되어야할 코드 |
||
512 | private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
||
513 | { |
||
514 | MessageBox.Show("임무마침"); |
||
515 | } |
||
516 | |||
517 | IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> _StatusCodeList; |
||
518 | public IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> StatusCodeList |
||
519 | { |
||
520 | get |
||
521 | { |
||
522 | if (_StatusCodeList == null) |
||
523 | { |
||
524 | _StatusCodeList = Telerik.Windows.Data.EnumDataSource.FromType<StatusCodeType>(); |
||
525 | } |
||
526 | |||
527 | return _StatusCodeList; |
||
528 | } |
||
529 | } |
||
530 | // BackgroundWorker에서 수행할 일을 정의. |
||
531 | private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) |
||
532 | { |
||
533 | 0cb12397 | alzkakdixm | |
534 | a6e5055d | alzkakdixm | while (IsAcitve) |
535 | { |
||
536 | 2decfbdf | alzkakdixm | |
537 | a6e5055d | alzkakdixm | if (FilterConvertSource == null) |
538 | { |
||
539 | FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
||
540 | } |
||
541 | |||
542 | if (RealConvertSource == null) |
||
543 | { |
||
544 | RealConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
||
545 | } |
||
546 | |||
547 | /// combobox 에서 선택된 items |
||
548 | if (SelectedStatus != null) |
||
549 | { |
||
550 | DataSelect(new[] { (StatusCodeType)(SelectedStatus.Value) }, FilterConvertSource); |
||
551 | } |
||
552 | |||
553 | /// 컨버터중인 items |
||
554 | 2decfbdf | alzkakdixm | RealDataSelect(new[] { StatusCodeType.None, StatusCodeType.Wait, StatusCodeType.PageLoading, StatusCodeType.Saving }, RealConvertSource); |
555 | a6e5055d | alzkakdixm | } |
556 | } |
||
557 | |||
558 | 2decfbdf | alzkakdixm | |
559 | |||
560 | private void RealDataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection) |
||
561 | { |
||
562 | try |
||
563 | { |
||
564 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
||
565 | { |
||
566 | var items = database.GetConvertProjects(collection)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
||
567 | .Take(SelectedCount.ValueMember).ToList();// |
||
568 | |||
569 | items.ForEach(newitem => |
||
570 | { |
||
571 | collection.UpdateWhere(changeitem => |
||
572 | ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ConvertID == newitem.ConvertID && x.ProjectNumber == newitem.ProjectNumber); |
||
573 | }); |
||
574 | } |
||
575 | } |
||
576 | catch (Exception ex) |
||
577 | { |
||
578 | MessageBox.Show(ex.ToString()); |
||
579 | } |
||
580 | } |
||
581 | a6e5055d | alzkakdixm | //<>쓸때는 IEnumerable |
582 | 2decfbdf | alzkakdixm | |
583 | a6e5055d | alzkakdixm | private void DataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection) |
584 | { |
||
585 | try |
||
586 | { |
||
587 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
||
588 | { |
||
589 | |||
590 | 2decfbdf | alzkakdixm | int _status = 0; |
591 | if (SelectedStatus != null) |
||
592 | { |
||
593 | _status = (int)SelectedStatus.Value; |
||
594 | } |
||
595 | |||
596 | var items = database.GetConvertProjects(_status)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
||
597 | 0cb12397 | alzkakdixm | .Take(SelectedCount.ValueMember).ToList(); |
598 | 2decfbdf | alzkakdixm | |
599 | a6e5055d | alzkakdixm | if (collection.Count() == 0) |
600 | { |
||
601 | 2decfbdf | alzkakdixm | if (statusCodeTypeList.Count() == 1) |
602 | { |
||
603 | items.ForEach(x => collection.Add(x)); |
||
604 | } |
||
605 | a6e5055d | alzkakdixm | } |
606 | else |
||
607 | { |
||
608 | 2decfbdf | alzkakdixm | |
609 | ////세미 업데이트 |
||
610 | items.ForEach(newitem => |
||
611 | a6e5055d | alzkakdixm | { |
612 | collection.UpdateWhere(changeitem => |
||
613 | 2decfbdf | alzkakdixm | ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
614 | a6e5055d | alzkakdixm | }); |
615 | |||
616 | 2decfbdf | alzkakdixm | |
617 | if (statusCodeTypeList.Count() == 1) |
||
618 | a6e5055d | alzkakdixm | { |
619 | 2decfbdf | alzkakdixm | //삭제 |
620 | for (int i = collection.Count() - 1; i >= 0; --i) |
||
621 | a6e5055d | alzkakdixm | { |
622 | 2decfbdf | alzkakdixm | var item = collection[i]; |
623 | a6e5055d | alzkakdixm | |
624 | 2decfbdf | alzkakdixm | if (items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//디비에서 가져온 값과 마지막값부터 차례대로 비교 |
625 | {//참=> 0제외한 모든 수 |
||
626 | collection.RemoveAt(i); |
||
627 | } |
||
628 | } |
||
629 | a6e5055d | alzkakdixm | } |
630 | |||
631 | 2decfbdf | alzkakdixm | if (statusCodeTypeList.Count() == 1) |
632 | a6e5055d | alzkakdixm | { |
633 | 2decfbdf | alzkakdixm | //추가 convert 후 추가됨 |
634 | foreach (var item in items) |
||
635 | { |
||
636 | if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감 |
||
637 | { |
||
638 | /*for (int i = 0; i < collection.Count()+1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가*/ |
||
639 | for (int i = 0; i < 200; i++) |
||
640 | { |
||
641 | if (i < collection.Count() - 1) |
||
642 | { |
||
643 | if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0) |
||
644 | { |
||
645 | collection.Insert(i, item); |
||
646 | break; |
||
647 | } |
||
648 | } |
||
649 | else |
||
650 | { |
||
651 | collection.Add(item); |
||
652 | break; |
||
653 | } |
||
654 | } |
||
655 | |||
656 | } |
||
657 | a6e5055d | alzkakdixm | |
658 | } |
||
659 | } |
||
660 | 2decfbdf | alzkakdixm | |
661 | a6e5055d | alzkakdixm | } |
662 | } |
||
663 | 2decfbdf | alzkakdixm | |
664 | a6e5055d | alzkakdixm | } |
665 | catch (Exception ex) |
||
666 | { |
||
667 | MessageBox.Show(ex.ToString()); |
||
668 | } |
||
669 | } |
||
670 | |||
671 | public override void Loaded() |
||
672 | { |
||
673 | base.Loaded(); |
||
674 | |||
675 | if (!App.IsDesignMode) |
||
676 | { |
||
677 | backgroundWorker = new BackgroundWorker(); |
||
678 | backgroundWorker.DoWork += backgroundWorker_DoWork; |
||
679 | backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted; |
||
680 | backgroundWorker.WorkerReportsProgress = false; |
||
681 | backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
||
682 | |||
683 | backgroundWorker.RunWorkerAsync(); |
||
684 | 2decfbdf | alzkakdixm | |
685 | AlivebackgroundWorker = new BackgroundWorker(); |
||
686 | AlivebackgroundWorker.DoWork += AlivebackgroundWorker_DoWork; |
||
687 | AlivebackgroundWorker.RunWorkerCompleted += AlivebackgroundWorker_RunWorkerCompleted; |
||
688 | AlivebackgroundWorker.WorkerReportsProgress = false; |
||
689 | AlivebackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(AlivebackgroundWorker_ProgressChanged); |
||
690 | |||
691 | AlivebackgroundWorker.RunWorkerAsync(); |
||
692 | a6e5055d | alzkakdixm | } |
693 | } |
||
694 | |||
695 | public override void Closed() |
||
696 | { |
||
697 | |||
698 | if (backgroundWorker != null) |
||
699 | { |
||
700 | backgroundWorker.DoWork -= backgroundWorker_DoWork; |
||
701 | backgroundWorker.RunWorkerCompleted -= backgroundWorker_RunWorkerCompleted; |
||
702 | backgroundWorker.WorkerReportsProgress = false; |
||
703 | backgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
||
704 | |||
705 | 2decfbdf | alzkakdixm | AlivebackgroundWorker.DoWork -= AlivebackgroundWorker_DoWork; |
706 | AlivebackgroundWorker.RunWorkerCompleted -= AlivebackgroundWorker_RunWorkerCompleted; |
||
707 | AlivebackgroundWorker.WorkerReportsProgress = false; |
||
708 | AlivebackgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(AlivebackgroundWorker_ProgressChanged); |
||
709 | |||
710 | AlivebackgroundWorker.Dispose(); |
||
711 | a6e5055d | alzkakdixm | |
712 | 2decfbdf | alzkakdixm | } |
713 | a6e5055d | alzkakdixm | base.Closed(); |
714 | } |
||
715 | |||
716 | |||
717 | public DelegateCommand DataSaveFileGemBoxCommand { get; private set; } |
||
718 | 0cb12397 | alzkakdixm | public void DataExportData(object obj) |
719 | a6e5055d | alzkakdixm | { |
720 | 0cb12397 | alzkakdixm | DataExport dataExport = new DataExport(); |
721 | dataExport.DataExportData(FilterConvertSource); |
||
722 | a6e5055d | alzkakdixm | } |
723 | |||
724 | 0cb12397 | alzkakdixm | public class SelectedCountItem : INotifyPropertyChanged |
725 | { |
||
726 | public event PropertyChangedEventHandler PropertyChanged; |
||
727 | a6e5055d | alzkakdixm | |
728 | 0cb12397 | alzkakdixm | private void NotifyPropertyChanged(String info) |
729 | a6e5055d | alzkakdixm | { |
730 | 0cb12397 | alzkakdixm | if (PropertyChanged != null) |
731 | a6e5055d | alzkakdixm | { |
732 | 0cb12397 | alzkakdixm | PropertyChanged(this, new PropertyChangedEventArgs(info)); |
733 | a6e5055d | alzkakdixm | } |
734 | } |
||
735 | |||
736 | 0cb12397 | alzkakdixm | //public string DisplayMember { get; set; } |
737 | public string _DisplayMember; |
||
738 | a6e5055d | alzkakdixm | |
739 | 0cb12397 | alzkakdixm | public string DisplayMember |
740 | a6e5055d | alzkakdixm | { |
741 | 0cb12397 | alzkakdixm | get => _DisplayMember; |
742 | set |
||
743 | a6e5055d | alzkakdixm | { |
744 | 0cb12397 | alzkakdixm | _DisplayMember = value; |
745 | a6e5055d | alzkakdixm | |
746 | 0cb12397 | alzkakdixm | NotifyPropertyChanged("DisplayMember"); |
747 | a6e5055d | alzkakdixm | } |
748 | 2decfbdf | alzkakdixm | } |
749 | 0cb12397 | alzkakdixm | //public int ValueMember { get; set; } |
750 | public int _ValueMember; |
||
751 | public int ValueMember |
||
752 | 2decfbdf | alzkakdixm | { |
753 | 0cb12397 | alzkakdixm | get => _ValueMember; |
754 | set |
||
755 | { |
||
756 | _ValueMember = value; |
||
757 | NotifyPropertyChanged("ValueMember"); |
||
758 | } |
||
759 | 2decfbdf | alzkakdixm | } |
760 | } |
||
761 | a6e5055d | alzkakdixm | } |
762 | } |