markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseItemsModel.cs @ 902f397c
이력 | 보기 | 이력해설 | 다운로드 (32.1 KB)
1 | e6281033 | alzkakdixm | using Markus.Message; |
---|---|---|---|
2 | a6e5055d | alzkakdixm | using Markus.Service.DataBase; |
3 | using Markus.Service.Extensions; |
||
4 | e6281033 | alzkakdixm | using Markus.Service.StationController.Data; |
5 | a6e5055d | alzkakdixm | 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 | e6281033 | alzkakdixm | using System.Net; |
19 | using System.Windows.Threading; |
||
20 | e78f0871 | alzkakdixm | using System.Diagnostics; |
21 | using System.Windows.Input; |
||
22 | using Markus.Mvvm.ToolKit; |
||
23 | 902f397c | semi | using System.Windows.Data; |
24 | a6e5055d | alzkakdixm | |
25 | namespace Markus.Service.StationController.ViewModel |
||
26 | { |
||
27 | //세미 |
||
28 | dfc86b71 | taeseongkim | public class DataBaseItemsModel : Mvvm.ToolKit.ViewModelBase |
29 | a6e5055d | alzkakdixm | { |
30 | e6281033 | alzkakdixm | #region Constructor |
31 | |||
32 | /// <summary> |
||
33 | /// 실행하면 처음 들어가는 부분 |
||
34 | /// </summary> |
||
35 | public DataBaseItemsModel() |
||
36 | { |
||
37 | DataSaveFileGemBoxCommand = new DelegateCommand(DataExportData); |
||
38 | ConvertCommand = new DelegateCommand(DataConvert); |
||
39 | DeleteCommand = new DelegateCommand(DataDelete); |
||
40 | ValidateCommand = new DelegateCommand(DataValidate); |
||
41 | e78f0871 | alzkakdixm | MarkusLinkCommand = new DelegateCommand(MarkusLink); |
42 | e6281033 | alzkakdixm | } |
43 | |||
44 | #endregion |
||
45 | |||
46 | #region Properties |
||
47 | |||
48 | 2decfbdf | alzkakdixm | private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _AliveItems; |
49 | public System.Collections.ObjectModel.ObservableCollection<ConvertItem> AliveItems |
||
50 | { |
||
51 | e6281033 | alzkakdixm | get => _AliveItems; |
52 | set |
||
53 | 2decfbdf | alzkakdixm | { |
54 | 0cb12397 | alzkakdixm | _AliveItems = value; |
55 | 2decfbdf | alzkakdixm | OnPropertyChanged(() => AliveItems); |
56 | } |
||
57 | } |
||
58 | |||
59 | dfc86b71 | taeseongkim | private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _FilterConvertSource; |
60 | public System.Collections.ObjectModel.ObservableCollection<ConvertItem> FilterConvertSource |
||
61 | { |
||
62 | 902f397c | semi | //get => _FilterConvertSource; |
63 | get |
||
64 | { |
||
65 | //if (_FilterConvertSource == null) |
||
66 | //{ |
||
67 | // _FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
||
68 | //} |
||
69 | //var view = CollectionViewSource.GetDefaultView(FilterConvertSource); |
||
70 | //if (view.CanFilter) |
||
71 | //{ |
||
72 | // view.Filter = TestFilter; |
||
73 | //} |
||
74 | return _FilterConvertSource; |
||
75 | } |
||
76 | dfc86b71 | taeseongkim | set |
77 | { |
||
78 | _FilterConvertSource = value; |
||
79 | OnPropertyChanged(() => FilterConvertSource); |
||
80 | } |
||
81 | } |
||
82 | |||
83 | |||
84 | private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _RealConvertSource; |
||
85 | public System.Collections.ObjectModel.ObservableCollection<ConvertItem> RealConvertSource |
||
86 | { |
||
87 | get => _RealConvertSource; |
||
88 | set |
||
89 | { |
||
90 | _RealConvertSource = value; |
||
91 | OnPropertyChanged(() => RealConvertSource); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | 2decfbdf | alzkakdixm | |
96 | 0cb12397 | alzkakdixm | private System.Windows.Documents.FlowDocument connectionLog; |
97 | 2decfbdf | alzkakdixm | public System.Windows.Documents.FlowDocument ConnectionLog |
98 | { |
||
99 | get => connectionLog; |
||
100 | set |
||
101 | { |
||
102 | if (connectionLog != value) |
||
103 | { |
||
104 | connectionLog = value; |
||
105 | OnPropertyChanged(() => ConnectionLog); |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 | |||
110 | a6e5055d | alzkakdixm | |
111 | private Telerik.Windows.Data.EnumMemberViewModel _SelectedStatus; |
||
112 | public Telerik.Windows.Data.EnumMemberViewModel SelectedStatus |
||
113 | { |
||
114 | get => _SelectedStatus; |
||
115 | set |
||
116 | { |
||
117 | _SelectedStatus = value; |
||
118 | 0cb12397 | alzkakdixm | OnPropertyChanged(() => SelectedStatus); |
119 | a6e5055d | alzkakdixm | } |
120 | } |
||
121 | |||
122 | |||
123 | private SelectedCountItem _SelectedCount; |
||
124 | public SelectedCountItem SelectedCount |
||
125 | { |
||
126 | get => _SelectedCount; |
||
127 | set |
||
128 | { |
||
129 | _SelectedCount = value; |
||
130 | dfc86b71 | taeseongkim | OnPropertyChanged(() => SelectedCount); |
131 | a6e5055d | alzkakdixm | } |
132 | } |
||
133 | |||
134 | e6281033 | alzkakdixm | List<SelectedCountItem> _SelectedCountList; |
135 | public List<SelectedCountItem> SelectedCountList |
||
136 | a6e5055d | alzkakdixm | { |
137 | e6281033 | alzkakdixm | get |
138 | 2decfbdf | alzkakdixm | { |
139 | e6281033 | alzkakdixm | if (_SelectedCountList == null) |
140 | 2decfbdf | alzkakdixm | { |
141 | e6281033 | alzkakdixm | _SelectedCountList = new List<SelectedCountItem> |
142 | 2decfbdf | alzkakdixm | { |
143 | e6281033 | alzkakdixm | new SelectedCountItem{DisplayMember = "50",ValueMember = 50}, |
144 | new SelectedCountItem{DisplayMember = "100",ValueMember = 100}, |
||
145 | new SelectedCountItem{DisplayMember = "150",ValueMember = 150}, |
||
146 | new SelectedCountItem{DisplayMember = "200",ValueMember = 200} |
||
147 | }; |
||
148 | 2decfbdf | alzkakdixm | } |
149 | a6e5055d | alzkakdixm | |
150 | e6281033 | alzkakdixm | return _SelectedCountList; |
151 | 2decfbdf | alzkakdixm | } |
152 | } |
||
153 | a6e5055d | alzkakdixm | |
154 | 0cb12397 | alzkakdixm | private ConvertItem _SelectFilterConvert; |
155 | a6e5055d | alzkakdixm | public ConvertItem SelectFilterConvert |
156 | { |
||
157 | get => _SelectFilterConvert; |
||
158 | set |
||
159 | { |
||
160 | _SelectFilterConvert = value; |
||
161 | dfc86b71 | taeseongkim | OnPropertyChanged(() => SelectFilterConvert); |
162 | a6e5055d | alzkakdixm | } |
163 | } |
||
164 | 0cb12397 | alzkakdixm | |
165 | private ConvertItem _SelectRealConvert; |
||
166 | a6e5055d | alzkakdixm | public ConvertItem SelectRealConvert |
167 | { |
||
168 | get => _SelectRealConvert; |
||
169 | set |
||
170 | { |
||
171 | _SelectRealConvert = value; |
||
172 | dfc86b71 | taeseongkim | OnPropertyChanged(() => SelectRealConvert); |
173 | a6e5055d | alzkakdixm | } |
174 | } |
||
175 | |||
176 | 0cb12397 | alzkakdixm | |
177 | private StatusTypeList _StatusType; |
||
178 | a6e5055d | alzkakdixm | public StatusTypeList StatusType |
179 | { |
||
180 | get => _StatusType; |
||
181 | set |
||
182 | { |
||
183 | _StatusType = value; |
||
184 | dfc86b71 | taeseongkim | OnPropertyChanged(() => StatusType); |
185 | a6e5055d | alzkakdixm | } |
186 | } |
||
187 | |||
188 | 0cb12397 | alzkakdixm | private bool _IsLoading; |
189 | a6e5055d | alzkakdixm | public bool IsLoading |
190 | { |
||
191 | get => _IsLoading; |
||
192 | set |
||
193 | { |
||
194 | if (_IsLoading != value) |
||
195 | { |
||
196 | _IsLoading = value; |
||
197 | dfc86b71 | taeseongkim | OnPropertyChanged(() => IsLoading); |
198 | a6e5055d | alzkakdixm | } |
199 | } |
||
200 | } |
||
201 | |||
202 | e6281033 | alzkakdixm | IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> _StatusCodeList; |
203 | public IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> StatusCodeList |
||
204 | a6e5055d | alzkakdixm | { |
205 | get |
||
206 | { |
||
207 | e6281033 | alzkakdixm | if (_StatusCodeList == null) |
208 | a6e5055d | alzkakdixm | { |
209 | e6281033 | alzkakdixm | _StatusCodeList = Telerik.Windows.Data.EnumDataSource.FromType<StatusCodeType>(); |
210 | a6e5055d | alzkakdixm | } |
211 | |||
212 | e6281033 | alzkakdixm | return _StatusCodeList; |
213 | a6e5055d | alzkakdixm | } |
214 | } |
||
215 | 8c7d1ea1 | alzkakdixm | |
216 | public bool _ConvertShow; |
||
217 | public bool ConvertShow |
||
218 | { |
||
219 | get => _ConvertShow; |
||
220 | set |
||
221 | { |
||
222 | if(_ConvertShow =! value) |
||
223 | { |
||
224 | _ConvertShow = false; |
||
225 | } |
||
226 | _ConvertShow = value; |
||
227 | OnPropertyChanged(() => ConvertShow); |
||
228 | } |
||
229 | } |
||
230 | 902f397c | semi | |
231 | public string _ProjectNumberFilter; |
||
232 | public string ProjectNumberFilter |
||
233 | { |
||
234 | get { return _ProjectNumberFilter; } |
||
235 | set |
||
236 | { |
||
237 | if (_ProjectNumberFilter != value) |
||
238 | { |
||
239 | _ProjectNumberFilter = value; |
||
240 | OnPropertyChanged(() => ProjectNumberFilter); |
||
241 | CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
||
242 | } |
||
243 | } |
||
244 | } |
||
245 | |||
246 | public string _UniqueKeyFilter; |
||
247 | public string UniqueKeyFilter |
||
248 | { |
||
249 | get { return _UniqueKeyFilter; } |
||
250 | set |
||
251 | { |
||
252 | if (_UniqueKeyFilter != value) |
||
253 | { |
||
254 | _UniqueKeyFilter = value; |
||
255 | OnPropertyChanged(() => UniqueKeyFilter); |
||
256 | CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
||
257 | } |
||
258 | } |
||
259 | } |
||
260 | |||
261 | public string _ConvertStateFilter; |
||
262 | public string ConvertStateFilter |
||
263 | { |
||
264 | get { return _ConvertStateFilter; } |
||
265 | set |
||
266 | { |
||
267 | if (_ConvertStateFilter != value) |
||
268 | { |
||
269 | _ConvertStateFilter = value; |
||
270 | OnPropertyChanged(() => ConvertStateFilter); |
||
271 | CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
||
272 | } |
||
273 | } |
||
274 | } |
||
275 | |||
276 | public string _Docuemnt_NOFilter; |
||
277 | public string Docuemnt_NOFilter |
||
278 | { |
||
279 | get { return _Docuemnt_NOFilter; } |
||
280 | set |
||
281 | { |
||
282 | if (_Docuemnt_NOFilter != value) |
||
283 | { |
||
284 | _Docuemnt_NOFilter = value; |
||
285 | OnPropertyChanged(() => Docuemnt_NOFilter); |
||
286 | CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
||
287 | } |
||
288 | } |
||
289 | } |
||
290 | |||
291 | public string _Docuemnt_NameFilter; |
||
292 | public string Docuemnt_NameFilter |
||
293 | { |
||
294 | get { return _Docuemnt_NameFilter; } |
||
295 | set |
||
296 | { |
||
297 | if (_Docuemnt_NameFilter != value) |
||
298 | { |
||
299 | _Docuemnt_NameFilter = value; |
||
300 | OnPropertyChanged(() => Docuemnt_NameFilter); |
||
301 | CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
||
302 | } |
||
303 | } |
||
304 | } |
||
305 | |||
306 | public string _ReconverterFilter; |
||
307 | public string ReconverterFilter |
||
308 | { |
||
309 | get { return _ReconverterFilter; } |
||
310 | set |
||
311 | { |
||
312 | if (_ReconverterFilter != value) |
||
313 | { |
||
314 | _ReconverterFilter = value; |
||
315 | OnPropertyChanged(() => ReconverterFilter); |
||
316 | CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
||
317 | } |
||
318 | } |
||
319 | } |
||
320 | |||
321 | public string _Service_IDFilter; |
||
322 | public string Service_IDFilter |
||
323 | { |
||
324 | get { return _Service_IDFilter; } |
||
325 | set |
||
326 | { |
||
327 | if (_Service_IDFilter != value) |
||
328 | { |
||
329 | _Service_IDFilter = value; |
||
330 | OnPropertyChanged(() => Service_IDFilter); |
||
331 | CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
||
332 | } |
||
333 | } |
||
334 | } |
||
335 | |||
336 | public string _RevisionFilter; |
||
337 | public string RevisionFilter |
||
338 | { |
||
339 | get { return _RevisionFilter; } |
||
340 | set |
||
341 | { |
||
342 | if (_RevisionFilter != value) |
||
343 | { |
||
344 | _RevisionFilter = value; |
||
345 | OnPropertyChanged(() => RevisionFilter); |
||
346 | CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
||
347 | } |
||
348 | } |
||
349 | } |
||
350 | e6281033 | alzkakdixm | #endregion |
351 | |||
352 | #region Command |
||
353 | a6e5055d | alzkakdixm | |
354 | 0cb12397 | alzkakdixm | public DelegateCommand ConvertCommand { get; private set; } |
355 | public DelegateCommand DeleteCommand { get; private set; } |
||
356 | public DelegateCommand ValidateCommand { get; private set; } |
||
357 | e6281033 | alzkakdixm | public DelegateCommand DataSaveFileGemBoxCommand { get; private set; } |
358 | e78f0871 | alzkakdixm | public DelegateCommand MarkusLinkCommand { get; private set; } |
359 | e6281033 | alzkakdixm | #endregion |
360 | a6e5055d | alzkakdixm | |
361 | e6281033 | alzkakdixm | #region Main Logic |
362 | a6e5055d | alzkakdixm | |
363 | e6281033 | alzkakdixm | /// <summary> |
364 | /// 각각의 Grid row 객체들 업데이트 |
||
365 | /// </summary> |
||
366 | |||
367 | private DispatcherTimer dispatcherTimer; |
||
368 | public override void Loaded() |
||
369 | a6e5055d | alzkakdixm | { |
370 | e6281033 | alzkakdixm | base.Loaded(); |
371 | |||
372 | if (!App.IsDesignMode) |
||
373 | { |
||
374 | dispatcherTimer = new DispatcherTimer(); |
||
375 | dispatcherTimer.Tick += new EventHandler(Timer_Tick); |
||
376 | dispatcherTimer.Interval = new TimeSpan(0, 0, 1); |
||
377 | dispatcherTimer.Start(); |
||
378 | } |
||
379 | a6e5055d | alzkakdixm | } |
380 | |||
381 | b119eeaa | taeseongkim | private async void Timer_Tick(object sender, EventArgs e) |
382 | a6e5055d | alzkakdixm | { |
383 | e6281033 | alzkakdixm | dispatcherTimer.Stop(); |
384 | |||
385 | if (IsAcitve) |
||
386 | a6e5055d | alzkakdixm | { |
387 | b119eeaa | taeseongkim | await App.Current.Dispatcher.InvokeAsync(() => |
388 | a6e5055d | alzkakdixm | { |
389 | e6281033 | alzkakdixm | DataSelect(); |
390 | |||
391 | AliveDataSelect(); |
||
392 | }); |
||
393 | } |
||
394 | |||
395 | b119eeaa | taeseongkim | await Task.Delay(5000); |
396 | |||
397 | //System.Threading.Thread.Sleep(new TimeSpan(0,0,0,0,100)); |
||
398 | e6281033 | alzkakdixm | |
399 | dispatcherTimer.Start(); |
||
400 | } |
||
401 | a6e5055d | alzkakdixm | |
402 | e6281033 | alzkakdixm | public override void Closed() |
403 | { |
||
404 | if (dispatcherTimer != null) |
||
405 | { |
||
406 | dispatcherTimer.Stop(); |
||
407 | a6e5055d | alzkakdixm | } |
408 | e6281033 | alzkakdixm | |
409 | base.Closed(); |
||
410 | a6e5055d | alzkakdixm | } |
411 | 0cb12397 | alzkakdixm | |
412 | 2decfbdf | alzkakdixm | |
413 | e6281033 | alzkakdixm | #endregion |
414 | a6e5055d | alzkakdixm | |
415 | e6281033 | alzkakdixm | #region Function |
416 | a6e5055d | alzkakdixm | |
417 | e6281033 | alzkakdixm | #region Data Select |
418 | |||
419 | /// <summary> |
||
420 | /// 상단 그리드 중앙 그리드 출력 데이터 |
||
421 | /// </summary> |
||
422 | private void DataSelect() |
||
423 | { |
||
424 | a6e5055d | alzkakdixm | |
425 | e6281033 | alzkakdixm | if (FilterConvertSource == null) |
426 | { |
||
427 | FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
||
428 | } |
||
429 | |||
430 | if (RealConvertSource == null) |
||
431 | { |
||
432 | RealConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
||
433 | } |
||
434 | |||
435 | /// combobox 에서 선택된 items |
||
436 | if (SelectedStatus != null) |
||
437 | { |
||
438 | DataSelect(new[] { (StatusCodeType)(SelectedStatus.Value) }, FilterConvertSource); |
||
439 | a6e5055d | alzkakdixm | } |
440 | |||
441 | e6281033 | alzkakdixm | /// 컨버터중인 items |
442 | RealDataSelect(new[] { StatusCodeType.None, StatusCodeType.Wait, StatusCodeType.PageLoading, StatusCodeType.Saving }, RealConvertSource); |
||
443 | 2decfbdf | alzkakdixm | |
444 | e6281033 | alzkakdixm | } |
445 | 2decfbdf | alzkakdixm | |
446 | private void RealDataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection) |
||
447 | { |
||
448 | try |
||
449 | { |
||
450 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
||
451 | { |
||
452 | var items = database.GetConvertProjects(collection)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
||
453 | .Take(SelectedCount.ValueMember).ToList();// |
||
454 | |||
455 | items.ForEach(newitem => |
||
456 | { |
||
457 | collection.UpdateWhere(changeitem => |
||
458 | ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ConvertID == newitem.ConvertID && x.ProjectNumber == newitem.ProjectNumber); |
||
459 | }); |
||
460 | } |
||
461 | } |
||
462 | catch (Exception ex) |
||
463 | { |
||
464 | MessageBox.Show(ex.ToString()); |
||
465 | } |
||
466 | } |
||
467 | |||
468 | a6e5055d | alzkakdixm | private void DataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection) |
469 | { |
||
470 | try |
||
471 | { |
||
472 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
||
473 | { |
||
474 | |||
475 | 2decfbdf | alzkakdixm | int _status = 0; |
476 | if (SelectedStatus != null) |
||
477 | { |
||
478 | _status = (int)SelectedStatus.Value; |
||
479 | } |
||
480 | |||
481 | 902f397c | semi | //if (ProjectNumberFilter != null) |
482 | //{ |
||
483 | // from item in FilterConvertSource |
||
484 | // where like % item.ProjectNumber |
||
485 | //} |
||
486 | |||
487 | 2decfbdf | alzkakdixm | var items = database.GetConvertProjects(_status)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
488 | 0cb12397 | alzkakdixm | .Take(SelectedCount.ValueMember).ToList(); |
489 | 2decfbdf | alzkakdixm | |
490 | a6e5055d | alzkakdixm | if (collection.Count() == 0) |
491 | { |
||
492 | 2decfbdf | alzkakdixm | if (statusCodeTypeList.Count() == 1) |
493 | { |
||
494 | items.ForEach(x => collection.Add(x)); |
||
495 | } |
||
496 | a6e5055d | alzkakdixm | } |
497 | else |
||
498 | { |
||
499 | 2decfbdf | alzkakdixm | |
500 | ////세미 업데이트 |
||
501 | items.ForEach(newitem => |
||
502 | a6e5055d | alzkakdixm | { |
503 | collection.UpdateWhere(changeitem => |
||
504 | 2decfbdf | alzkakdixm | ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
505 | a6e5055d | alzkakdixm | }); |
506 | |||
507 | 2decfbdf | alzkakdixm | |
508 | if (statusCodeTypeList.Count() == 1) |
||
509 | a6e5055d | alzkakdixm | { |
510 | 2decfbdf | alzkakdixm | //삭제 |
511 | for (int i = collection.Count() - 1; i >= 0; --i) |
||
512 | a6e5055d | alzkakdixm | { |
513 | 2decfbdf | alzkakdixm | var item = collection[i]; |
514 | a6e5055d | alzkakdixm | |
515 | 2decfbdf | alzkakdixm | if (items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//디비에서 가져온 값과 마지막값부터 차례대로 비교 |
516 | {//참=> 0제외한 모든 수 |
||
517 | collection.RemoveAt(i); |
||
518 | } |
||
519 | } |
||
520 | a6e5055d | alzkakdixm | } |
521 | |||
522 | 2decfbdf | alzkakdixm | if (statusCodeTypeList.Count() == 1) |
523 | a6e5055d | alzkakdixm | { |
524 | 2decfbdf | alzkakdixm | //추가 convert 후 추가됨 |
525 | foreach (var item in items) |
||
526 | { |
||
527 | if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감 |
||
528 | { |
||
529 | /*for (int i = 0; i < collection.Count()+1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가*/ |
||
530 | for (int i = 0; i < 200; i++) |
||
531 | { |
||
532 | if (i < collection.Count() - 1) |
||
533 | { |
||
534 | if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0) |
||
535 | { |
||
536 | collection.Insert(i, item); |
||
537 | break; |
||
538 | } |
||
539 | } |
||
540 | else |
||
541 | { |
||
542 | collection.Add(item); |
||
543 | break; |
||
544 | } |
||
545 | } |
||
546 | |||
547 | } |
||
548 | a6e5055d | alzkakdixm | |
549 | } |
||
550 | } |
||
551 | 2decfbdf | alzkakdixm | |
552 | a6e5055d | alzkakdixm | } |
553 | } |
||
554 | 2decfbdf | alzkakdixm | |
555 | a6e5055d | alzkakdixm | } |
556 | catch (Exception ex) |
||
557 | { |
||
558 | MessageBox.Show(ex.ToString()); |
||
559 | } |
||
560 | } |
||
561 | |||
562 | e6281033 | alzkakdixm | /// <summary> |
563 | /// 서비스의 실시간 컨버터 Item |
||
564 | /// </summary> |
||
565 | private async void AliveDataSelect() |
||
566 | a6e5055d | alzkakdixm | { |
567 | e6281033 | alzkakdixm | try |
568 | a6e5055d | alzkakdixm | { |
569 | e6281033 | alzkakdixm | List<ConvertItem> newitems = new List<ConvertItem>(); |
570 | a6e5055d | alzkakdixm | |
571 | e6281033 | alzkakdixm | foreach (var client in App.StationClientList) |
572 | { |
||
573 | if (await SimplePingAsync(client.Endpoint.Address.ToString())) |
||
574 | { |
||
575 | try |
||
576 | { |
||
577 | List<ConvertItem> itemsToList = new List<ConvertItem>(); |
||
578 | var items = await client.AliveConvertListAsync(); |
||
579 | foreach (var item in items) |
||
580 | { |
||
581 | ConvertItem itemsToEach = new ConvertItem(); |
||
582 | itemsToEach.ServiceID = item.ServiceID; |
||
583 | itemsToEach.ConvertID = item.ConvertID; |
||
584 | itemsToEach.ProjectNumber = item.ProjectNumber; |
||
585 | 29000595 | alzkakdixm | |
586 | if (item.ConvertState != null) |
||
587 | e6281033 | alzkakdixm | { |
588 | itemsToEach.ConvertState = (StatusCodeType)Enum.Parse(typeof(StatusCodeType), item.ConvertState); |
||
589 | } |
||
590 | |||
591 | itemsToEach.CurrentPageNo = item.CurrentPageNo; |
||
592 | itemsToEach.TotalPage = item.TotalPage; |
||
593 | itemsToEach.OriginfilePath = item.OriginfilePath; |
||
594 | itemsToEach.ConvertPath = item.ConvertPath; |
||
595 | 344ac7ed | alzkakdixm | itemsToEach.MarkusLink = item.MarkusLink; |
596 | itemsToEach.UniqueKey = item.UniqueKey; |
||
597 | itemsToEach.FileName = item.FileName; |
||
598 | itemsToEach.ConvertPath = item.ConvertPath; |
||
599 | itemsToEach.CreateTime = item.CreateTime; |
||
600 | itemsToEach.Exception = item.Exception; |
||
601 | itemsToEach.ProcessorAffinity = item.ProcessorAffinity; |
||
602 | itemsToEach.ReConverter = item.ReConverter; |
||
603 | itemsToEach.DocumentID = item.DocumentID; |
||
604 | itemsToEach.DocumnetName = item.DocumnetName; |
||
605 | itemsToEach.GroupNo = item.GroupNo; |
||
606 | itemsToEach.Revision = item.Revision; |
||
607 | itemsToEach.StartTime = item.StartTime; |
||
608 | itemsToEach.EndTime = item.EndTime; |
||
609 | |||
610 | e6281033 | alzkakdixm | |
611 | itemsToList.Add(itemsToEach); |
||
612 | } |
||
613 | newitems.AddRange(itemsToList); |
||
614 | System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping"); |
||
615 | 2decfbdf | alzkakdixm | |
616 | e6281033 | alzkakdixm | if (items.Count() == 0) |
617 | { |
||
618 | System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero."); |
||
619 | } |
||
620 | } |
||
621 | catch (Exception ex) |
||
622 | { |
||
623 | System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}"); |
||
624 | } |
||
625 | } |
||
626 | else |
||
627 | { |
||
628 | System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error"); |
||
629 | } |
||
630 | } |
||
631 | 2decfbdf | alzkakdixm | |
632 | e6281033 | alzkakdixm | ItemsUpdate(newitems); |
633 | await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems)); |
||
634 | } |
||
635 | catch (Exception ex) |
||
636 | { |
||
637 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
638 | a6e5055d | alzkakdixm | } |
639 | } |
||
640 | |||
641 | e6281033 | alzkakdixm | /// <summary> |
642 | /// AliveDataSelect의 Data Update |
||
643 | /// </summary> |
||
644 | /// <param name="newitems"></param> |
||
645 | private void ItemsUpdate(List<ConvertItem> newitems) |
||
646 | a6e5055d | alzkakdixm | { |
647 | |||
648 | e6281033 | alzkakdixm | foreach (var item in newitems) |
649 | { |
||
650 | item.OriginfilePath = HttpUtility.UrlDecode(item.OriginfilePath); |
||
651 | } |
||
652 | |||
653 | if (AliveItems == null) |
||
654 | { |
||
655 | AliveItems = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
||
656 | |||
657 | foreach (var item in newitems) |
||
658 | { |
||
659 | AliveItems.Add(item); |
||
660 | } |
||
661 | } |
||
662 | else |
||
663 | a6e5055d | alzkakdixm | { |
664 | e6281033 | alzkakdixm | /// 데이터 업데이트 |
665 | newitems.ForEach(newitem => |
||
666 | { |
||
667 | AliveItems.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
||
668 | }); |
||
669 | |||
670 | // 추가 |
||
671 | foreach (var item in newitems) |
||
672 | { |
||
673 | if (AliveItems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
||
674 | { |
||
675 | AliveItems.Add(item); |
||
676 | } |
||
677 | } |
||
678 | a6e5055d | alzkakdixm | |
679 | e6281033 | alzkakdixm | /// 삭제 |
680 | 2decfbdf | alzkakdixm | |
681 | e6281033 | alzkakdixm | for (int i = AliveItems.Count() - 1; i > -1; --i) |
682 | { |
||
683 | var item = AliveItems[i]; |
||
684 | a6e5055d | alzkakdixm | |
685 | e6281033 | alzkakdixm | if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
686 | { |
||
687 | try |
||
688 | { |
||
689 | AliveItems.RemoveAt(i); |
||
690 | } |
||
691 | catch (Exception ex) |
||
692 | { |
||
693 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
694 | } |
||
695 | } |
||
696 | } |
||
697 | 2decfbdf | alzkakdixm | } |
698 | a6e5055d | alzkakdixm | } |
699 | |||
700 | |||
701 | e6281033 | alzkakdixm | public static async Task<bool> SimplePingAsync(string uri) |
702 | a6e5055d | alzkakdixm | { |
703 | e6281033 | alzkakdixm | bool result = false; |
704 | |||
705 | try |
||
706 | { |
||
707 | using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient()) |
||
708 | { |
||
709 | Client.Timeout = new TimeSpan(0, 0, 60); |
||
710 | |||
711 | var message = await Client.GetAsync(uri); |
||
712 | |||
713 | System.Net.HttpStatusCode StatusCode = message.StatusCode; |
||
714 | |||
715 | switch (StatusCode) |
||
716 | { |
||
717 | |||
718 | case System.Net.HttpStatusCode.Accepted: |
||
719 | case System.Net.HttpStatusCode.OK: |
||
720 | result = true; |
||
721 | break; |
||
722 | } |
||
723 | } |
||
724 | } |
||
725 | catch (Exception ex) |
||
726 | { |
||
727 | result = false; |
||
728 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
729 | } |
||
730 | |||
731 | return result; |
||
732 | a6e5055d | alzkakdixm | } |
733 | |||
734 | e6281033 | alzkakdixm | #endregion |
735 | |||
736 | #region Data Convert |
||
737 | a6e5055d | alzkakdixm | |
738 | e6281033 | alzkakdixm | private void DataConvert(object obj) |
739 | { |
||
740 | if (SelectFilterConvert == null && SelectRealConvert == null) |
||
741 | { |
||
742 | MessageBox.Show("왼쪽 버튼 클릭 후 Converter 해주세요!"); |
||
743 | } |
||
744 | else |
||
745 | a6e5055d | alzkakdixm | { |
746 | e6281033 | alzkakdixm | ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString); |
747 | var resultRealConvert = 0; |
||
748 | var resultFiltertConvert = 0; |
||
749 | |||
750 | if (SelectRealConvert != null) |
||
751 | { |
||
752 | resultRealConvert = _DataConvert.SetCleanUpItem(SelectRealConvert); |
||
753 | } |
||
754 | else if (SelectFilterConvert != null) |
||
755 | a6e5055d | alzkakdixm | { |
756 | e6281033 | alzkakdixm | resultFiltertConvert = _DataConvert.SetCleanUpItem(SelectFilterConvert); |
757 | } |
||
758 | System.Diagnostics.Debug.WriteLine(resultRealConvert + " " + resultFiltertConvert); |
||
759 | |||
760 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
||
761 | { |
||
762 | var items = database.GetConvertProjects(SelectFilterConvert); |
||
763 | |||
764 | foreach (var item in items) |
||
765 | { |
||
766 | RealConvertSource.Add(item); |
||
767 | } |
||
768 | 8c7d1ea1 | alzkakdixm | if (RealConvertSource.Count() == 1) |
769 | { |
||
770 | ConvertShow = true; |
||
771 | } |
||
772 | a6e5055d | alzkakdixm | } |
773 | } |
||
774 | e6281033 | alzkakdixm | } |
775 | |||
776 | #endregion |
||
777 | |||
778 | #region Validation |
||
779 | a6e5055d | alzkakdixm | |
780 | e6281033 | alzkakdixm | private void DataValidate(object obj) |
781 | { |
||
782 | |||
783 | bool result = false; |
||
784 | a6e5055d | alzkakdixm | |
785 | e6281033 | alzkakdixm | WebRequest webRequest = WebRequest.Create(SelectFilterConvert.OriginfilePath); |
786 | webRequest.Timeout = 1200; // miliseconds |
||
787 | webRequest.Method = "HEAD"; |
||
788 | |||
789 | HttpWebResponse response = null; |
||
790 | |||
791 | try |
||
792 | { |
||
793 | response = (HttpWebResponse)webRequest.GetResponse(); |
||
794 | result = true; |
||
795 | } |
||
796 | catch (WebException webException) |
||
797 | { |
||
798 | MessageBox.Show(SelectFilterConvert.FileName + " doesn't exist: " + webException.Message); |
||
799 | result = true; |
||
800 | } |
||
801 | finally |
||
802 | a6e5055d | alzkakdixm | { |
803 | e6281033 | alzkakdixm | if (response != null) |
804 | a6e5055d | alzkakdixm | { |
805 | e6281033 | alzkakdixm | response.Close(); |
806 | a6e5055d | alzkakdixm | } |
807 | 2decfbdf | alzkakdixm | } |
808 | e6281033 | alzkakdixm | if (result == true) |
809 | { |
||
810 | MessageBox.Show("File exists"); |
||
811 | } |
||
812 | } |
||
813 | |||
814 | #endregion |
||
815 | |||
816 | e78f0871 | alzkakdixm | #region MarkusLink |
817 | |||
818 | private void MarkusLink(object obj)///여기서 부터 |
||
819 | { |
||
820 | if (obj is ConvertItem) |
||
821 | { |
||
822 | if (obj != null) |
||
823 | { |
||
824 | var convertitem = obj as ConvertItem; |
||
825 | |||
826 | SelectFilterConvert = convertitem; |
||
827 | |||
828 | SelectRealConvert = convertitem; |
||
829 | |||
830 | ProcessStartInfo startInfo = null; |
||
831 | |||
832 | startInfo = new ProcessStartInfo("iexplore.exe", convertitem.MarkusLink); |
||
833 | |||
834 | Process.Start(startInfo); |
||
835 | } |
||
836 | } |
||
837 | } |
||
838 | |||
839 | #endregion |
||
840 | |||
841 | e6281033 | alzkakdixm | #region Data Delete |
842 | |||
843 | private void DataDelete(object obj) |
||
844 | { |
||
845 | 8c7d1ea1 | alzkakdixm | RadWindow.Alert("do you want to delete it??", this.OnClosed); |
846 | e6281033 | alzkakdixm | } |
847 | |||
848 | private void OnClosed(object sender, WindowClosedEventArgs e) |
||
849 | { |
||
850 | var result = e.DialogResult; |
||
851 | if (result == true) |
||
852 | { |
||
853 | ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString); |
||
854 | var resultRealConvert = _DataConvert.RemoveItem(SelectRealConvert.ConvertID); |
||
855 | var resultFiltertConvert = _DataConvert.RemoveItem(SelectFilterConvert.ConvertID); |
||
856 | System.Diagnostics.Debug.WriteLine(resultRealConvert + " " + resultFiltertConvert); |
||
857 | } |
||
858 | } |
||
859 | |||
860 | |||
861 | #endregion |
||
862 | |||
863 | #region Data Export |
||
864 | |||
865 | |||
866 | /// <summary> |
||
867 | /// 필터된 상단 그리드 엑셀로 출력 |
||
868 | /// </summary> |
||
869 | |||
870 | public void DataExportData(object obj) |
||
871 | { |
||
872 | SaveFileDialog saveFileDialog = new SaveFileDialog(); |
||
873 | |||
874 | saveFileDialog.FileName = "Document"; // Default file name |
||
875 | saveFileDialog.DefaultExt = ".txt"; // Default file extension |
||
876 | saveFileDialog.Filter = "Csv documents (.Csv)|*.csv|Excel(2017~2019)Worksheets|*.xlsx"; // Filter files by extension |
||
877 | |||
878 | |||
879 | if (saveFileDialog.ShowDialog() == true) |
||
880 | 2decfbdf | alzkakdixm | { |
881 | e6281033 | alzkakdixm | |
882 | |||
883 | if (!string.IsNullOrWhiteSpace(saveFileDialog.FileName)) |
||
884 | 0cb12397 | alzkakdixm | { |
885 | e6281033 | alzkakdixm | |
886 | var extension = new System.IO.FileInfo(saveFileDialog.FileName).Extension; |
||
887 | |||
888 | if (extension == ".xlsx" || extension == ".csv") |
||
889 | { |
||
890 | |||
891 | var headers = new List<HeaderMember> |
||
892 | { |
||
893 | new HeaderMember{HeaderName = "ServiceID", Property = "ServiceID" }, |
||
894 | new HeaderMember{HeaderName = "ConvertID", Property = "ConvertID" }, |
||
895 | new HeaderMember{HeaderName = "ProjectNumber", Property = "ProjectNumber" }, |
||
896 | new HeaderMember{HeaderName = "ConvertState", Property = "ConvertState" }, |
||
897 | new HeaderMember{HeaderName = "CurrentPageNo", Property = "CurrentPageNo" }, |
||
898 | new HeaderMember{HeaderName = "TotalPage", Property = "TotalPage" }, |
||
899 | new HeaderMember{HeaderName = "OriginfilePath", Property = "OriginfilePath" }, |
||
900 | new HeaderMember{HeaderName = "ConvertPath", Property = "ConvertPath" }, |
||
901 | new HeaderMember{HeaderName = "CreateTime", Property = "CreateTime" }, |
||
902 | new HeaderMember{HeaderName = "Exception", Property = "Exception" }, |
||
903 | new HeaderMember{HeaderName = "ProcessorAffinity", Property = "ProcessorAffinity" }, |
||
904 | new HeaderMember{HeaderName = "ReConverter", Property = "ReConverter" }, |
||
905 | new HeaderMember{HeaderName = "UniqueKey", Property = "UniqueKey" } |
||
906 | }; |
||
907 | |||
908 | |||
909 | DataExport dataExport = new DataExport(); |
||
910 | dataExport.DataExportExcel(saveFileDialog.FileName, "Hello world", FilterConvertSource, headers); |
||
911 | //_dataExport.DataExportExcel(saveFileDialog.FileName, saveFileDialog.FileName.ToString(), Projectsource, headers); |
||
912 | //GemBoxFileSave(obj); |
||
913 | } |
||
914 | 0cb12397 | alzkakdixm | } |
915 | 2decfbdf | alzkakdixm | } |
916 | } |
||
917 | e6281033 | alzkakdixm | |
918 | #endregion |
||
919 | |||
920 | 902f397c | semi | #region TestFilter |
921 | |||
922 | |||
923 | /// <summary> |
||
924 | /// Grid Filter |
||
925 | /// </summary> |
||
926 | |||
927 | private bool TestFilter(object item) |
||
928 | { |
||
929 | var Item = item as ConvertItem; |
||
930 | if (ProjectNumberFilter == null) return true; |
||
931 | if (ProjectNumberFilter == Item.ProjectNumber) return true; |
||
932 | return false; |
||
933 | } |
||
934 | |||
935 | #endregion |
||
936 | |||
937 | e6281033 | alzkakdixm | #endregion |
938 | a6e5055d | alzkakdixm | } |
939 | } |