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