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