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