markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseItemsModel.cs @ dfc86b71
이력 | 보기 | 이력해설 | 다운로드 (55.4 KB)
1 | a6e5055d | alzkakdixm | using GemBox.Spreadsheet; |
---|---|---|---|
2 | using Markus.Message; |
||
3 | using Markus.Service.DataBase; |
||
4 | using Markus.Service.Extensions; |
||
5 | 2decfbdf | alzkakdixm | //using Markus.Service.Interface; |
6 | using Markus.Service.StationController; |
||
7 | a6e5055d | alzkakdixm | using Markus.Service.StationController.Behaviors; |
8 | using Markus.Service.StationController.Extensions; |
||
9 | using Microsoft.Win32; |
||
10 | using System; |
||
11 | using System.Collections.Generic; |
||
12 | 2decfbdf | alzkakdixm | using System.Collections.ObjectModel; |
13 | a6e5055d | alzkakdixm | using System.ComponentModel; |
14 | 2decfbdf | alzkakdixm | using System.Diagnostics; |
15 | a6e5055d | alzkakdixm | using System.Linq; |
16 | 2decfbdf | alzkakdixm | using System.Threading.Tasks; |
17 | using System.Web; |
||
18 | a6e5055d | alzkakdixm | using System.Windows; |
19 | using Telerik.Windows.Controls; |
||
20 | using Telerik.Windows.Data; |
||
21 | using ConvertItem = Markus.Service.Interface.ConvertItem; |
||
22 | 2decfbdf | alzkakdixm | //using AliveConvertItem = Markus.Service.WcfClient.StationServiceTask.ConvertItem; |
23 | using Markus.Service.WcfClient.StationServiceTask; |
||
24 | using System.Text; |
||
25 | using Markus.Service.Helper; |
||
26 | a6e5055d | alzkakdixm | |
27 | namespace Markus.Service.StationController.ViewModel |
||
28 | { |
||
29 | //세미 |
||
30 | dfc86b71 | taeseongkim | public class DataBaseItemsModel : Mvvm.ToolKit.ViewModelBase |
31 | a6e5055d | alzkakdixm | { |
32 | 2decfbdf | alzkakdixm | //alive |
33 | private BackgroundWorker AlivebackgroundWorker; |
||
34 | |||
35 | private System.Windows.Documents.FlowDocument connectionLog; |
||
36 | |||
37 | private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _AliveItems; |
||
38 | |||
39 | public System.Collections.ObjectModel.ObservableCollection<ConvertItem> AliveItems |
||
40 | { |
||
41 | get => _AliveItems; set |
||
42 | { |
||
43 | _AliveItems = value; |
||
44 | OnPropertyChanged(() => AliveItems); |
||
45 | } |
||
46 | } |
||
47 | |||
48 | dfc86b71 | taeseongkim | private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _FilterConvertSource; |
49 | |||
50 | public System.Collections.ObjectModel.ObservableCollection<ConvertItem> FilterConvertSource |
||
51 | { |
||
52 | get => _FilterConvertSource; |
||
53 | set |
||
54 | { |
||
55 | _FilterConvertSource = value; |
||
56 | OnPropertyChanged(() => FilterConvertSource); |
||
57 | } |
||
58 | } |
||
59 | |||
60 | |||
61 | private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _RealConvertSource; |
||
62 | public System.Collections.ObjectModel.ObservableCollection<ConvertItem> RealConvertSource |
||
63 | { |
||
64 | get => _RealConvertSource; |
||
65 | set |
||
66 | { |
||
67 | _RealConvertSource = value; |
||
68 | OnPropertyChanged(() => RealConvertSource); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | private bool isLoading; |
||
73 | |||
74 | 2decfbdf | alzkakdixm | public bool AliveIsLoading |
75 | { |
||
76 | get => isLoading; set |
||
77 | { |
||
78 | if (isLoading != value) |
||
79 | { |
||
80 | isLoading = value; |
||
81 | OnPropertyChanged(() => AliveIsLoading); |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | |||
86 | |||
87 | public System.Windows.Documents.FlowDocument ConnectionLog |
||
88 | { |
||
89 | get => connectionLog; |
||
90 | set |
||
91 | { |
||
92 | if (connectionLog != value) |
||
93 | { |
||
94 | connectionLog = value; |
||
95 | OnPropertyChanged(() => ConnectionLog); |
||
96 | } |
||
97 | } |
||
98 | } |
||
99 | |||
100 | //public AliveViewModel() |
||
101 | //{ |
||
102 | //} |
||
103 | |||
104 | //// 진행률에 변화가 있을때 이벤트가 발생 |
||
105 | //private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) |
||
106 | //{ |
||
107 | //} |
||
108 | |||
109 | //// 일이 모두 마쳤을때 수행되어야할 코드 |
||
110 | //private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
||
111 | //{ |
||
112 | //} |
||
113 | |||
114 | // BackgroundWorker에서 수행할 일을 정의. |
||
115 | private void AlivebackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) |
||
116 | { |
||
117 | } |
||
118 | private void AlivebackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
||
119 | { |
||
120 | } |
||
121 | private async void AlivebackgroundWorker_DoWork(object sender, DoWorkEventArgs e) |
||
122 | { |
||
123 | while (IsAcitve) |
||
124 | { |
||
125 | //System.Threading.Thread.Sleep(new TimeSpan(0, 0, 3)); |
||
126 | |||
127 | if (!IsLoading) |
||
128 | { |
||
129 | IsLoading = true; |
||
130 | |||
131 | try |
||
132 | { |
||
133 | |||
134 | List<ConvertItem> newitems = new List<ConvertItem>(); |
||
135 | |||
136 | foreach (var client in App.StationClientList) |
||
137 | { |
||
138 | if (await SimplePingAsync(client.Endpoint.Address.ToString())) |
||
139 | { |
||
140 | try |
||
141 | { |
||
142 | List<ConvertItem> itemsToList = new List<ConvertItem>(); |
||
143 | var items = await client.AliveConvertListAsync(); |
||
144 | //int i = 0; |
||
145 | foreach (var item in items) |
||
146 | { |
||
147 | ConvertItem itemsToEach = new ConvertItem(); |
||
148 | itemsToEach.ServiceID = item.ServiceID; |
||
149 | itemsToEach.ConvertID = item.ConvertID; |
||
150 | itemsToEach.ProjectNumber = item.ProjectNumber; |
||
151 | //itemsToEach.ConvertState = (StatusCodeType.)item.ConvertState;// (StatusCodeType) item.ConvertState; |
||
152 | itemsToEach.ConvertState = (StatusCodeType)Enum.Parse(typeof(StatusCodeType), item.ConvertState); |
||
153 | itemsToEach.CurrentPageNo = item.CurrentPageNo; |
||
154 | itemsToEach.TotalPage = item.TotalPage; |
||
155 | itemsToEach.OriginfilePath = item.OriginfilePath; |
||
156 | itemsToEach.ConvertPath = item.ConvertPath; |
||
157 | |||
158 | itemsToList.Add(itemsToEach); |
||
159 | //i++; |
||
160 | } |
||
161 | newitems.AddRange(itemsToList); |
||
162 | //System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping"); |
||
163 | |||
164 | if (items.Count() == 0) |
||
165 | { |
||
166 | //System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero."); |
||
167 | } |
||
168 | } |
||
169 | catch (Exception ex) |
||
170 | { |
||
171 | //System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}"); |
||
172 | } |
||
173 | } |
||
174 | else |
||
175 | { |
||
176 | //System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error"); |
||
177 | } |
||
178 | } |
||
179 | |||
180 | // ItemsUpdate(newitems); |
||
181 | await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems)); |
||
182 | } |
||
183 | catch (Exception ex) |
||
184 | { |
||
185 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
186 | } |
||
187 | |||
188 | IsLoading = false; |
||
189 | } |
||
190 | |||
191 | } |
||
192 | } |
||
193 | |||
194 | |||
195 | private async void AliveDataSelect() |
||
196 | { |
||
197 | try |
||
198 | { |
||
199 | List<ConvertItem> newitems = new List<ConvertItem>(); |
||
200 | |||
201 | foreach (var client in App.StationClientList) |
||
202 | { |
||
203 | if (await SimplePingAsync(client.Endpoint.Address.ToString())) |
||
204 | { |
||
205 | try |
||
206 | { |
||
207 | List<ConvertItem> itemsToList = new List<ConvertItem>(); |
||
208 | var items = await client.AliveConvertListAsync(); |
||
209 | //int i = 0; |
||
210 | foreach (var item in items) |
||
211 | { |
||
212 | ConvertItem itemsToEach = new ConvertItem(); |
||
213 | itemsToEach.ServiceID = item.ServiceID; |
||
214 | itemsToEach.ConvertID = item.ConvertID; |
||
215 | itemsToEach.ProjectNumber = item.ProjectNumber; |
||
216 | //itemsToEach.ConvertState = (StatusCodeType.)item.ConvertState;// (StatusCodeType) item.ConvertState; |
||
217 | try |
||
218 | { |
||
219 | itemsToEach.ConvertState = (StatusCodeType)Enum.Parse(typeof(StatusCodeType), item.ConvertState); |
||
220 | } |
||
221 | catch (Exception ex) |
||
222 | { |
||
223 | |||
224 | throw ex; |
||
225 | } |
||
226 | |||
227 | itemsToEach.CurrentPageNo = item.CurrentPageNo; |
||
228 | itemsToEach.TotalPage = item.TotalPage; |
||
229 | itemsToEach.OriginfilePath = item.OriginfilePath; |
||
230 | itemsToEach.ConvertPath = item.ConvertPath; |
||
231 | |||
232 | itemsToList.Add(itemsToEach); |
||
233 | //i++; |
||
234 | } |
||
235 | newitems.AddRange(itemsToList); |
||
236 | System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping"); |
||
237 | |||
238 | if (items.Count() == 0) |
||
239 | { |
||
240 | System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero."); |
||
241 | } |
||
242 | } |
||
243 | catch (Exception ex) |
||
244 | { |
||
245 | System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}"); |
||
246 | } |
||
247 | } |
||
248 | else |
||
249 | { |
||
250 | System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error"); |
||
251 | } |
||
252 | } |
||
253 | |||
254 | ItemsUpdate(newitems); |
||
255 | await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems)); |
||
256 | } |
||
257 | catch (Exception ex) |
||
258 | { |
||
259 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
260 | } |
||
261 | } |
||
262 | |||
263 | |||
264 | private void ItemsUpdate(List<ConvertItem> newitems) |
||
265 | { |
||
266 | |||
267 | foreach (var item in newitems) |
||
268 | { |
||
269 | item.OriginfilePath = HttpUtility.UrlDecode(item.OriginfilePath); |
||
270 | } |
||
271 | |||
272 | if (AliveItems == null) |
||
273 | { |
||
274 | AliveItems = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
||
275 | |||
276 | foreach (var item in newitems) |
||
277 | { |
||
278 | AliveItems.Add(item); |
||
279 | } |
||
280 | } |
||
281 | else |
||
282 | { |
||
283 | /// 데이터 업데이트 |
||
284 | newitems.ForEach(newitem => |
||
285 | { |
||
286 | AliveItems.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
||
287 | }); |
||
288 | |||
289 | // 추가 |
||
290 | foreach (var item in newitems) |
||
291 | { |
||
292 | if (AliveItems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
||
293 | { |
||
294 | AliveItems.Add(item); |
||
295 | } |
||
296 | } |
||
297 | |||
298 | /// 삭제 |
||
299 | |||
300 | for (int i = AliveItems.Count() - 1; i > -1; --i) |
||
301 | { |
||
302 | var item = AliveItems[i]; |
||
303 | |||
304 | if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
||
305 | { |
||
306 | try |
||
307 | { |
||
308 | AliveItems.RemoveAt(i); |
||
309 | } |
||
310 | catch (Exception ex) |
||
311 | { |
||
312 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
313 | } |
||
314 | } |
||
315 | } |
||
316 | } |
||
317 | } |
||
318 | |||
319 | private void LogWrite(string log, bool IsError) |
||
320 | { |
||
321 | if (IsError) |
||
322 | { |
||
323 | System.Diagnostics.Trace.Fail(log); |
||
324 | } |
||
325 | else |
||
326 | { |
||
327 | System.Diagnostics.Trace.TraceInformation(log); |
||
328 | } |
||
329 | } |
||
330 | |||
331 | |||
332 | public static async Task<bool> SimplePingAsync(string uri) |
||
333 | { |
||
334 | bool result = false; |
||
335 | |||
336 | try |
||
337 | { |
||
338 | using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient()) |
||
339 | { |
||
340 | Client.Timeout = new TimeSpan(0, 0, 60); |
||
341 | |||
342 | var message = await Client.GetAsync(uri); |
||
343 | |||
344 | System.Net.HttpStatusCode StatusCode = message.StatusCode; |
||
345 | |||
346 | switch (StatusCode) |
||
347 | { |
||
348 | |||
349 | case System.Net.HttpStatusCode.Accepted: |
||
350 | case System.Net.HttpStatusCode.OK: |
||
351 | result = true; |
||
352 | break; |
||
353 | } |
||
354 | } |
||
355 | } |
||
356 | catch (Exception ex) |
||
357 | { |
||
358 | result = false; |
||
359 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
360 | } |
||
361 | |||
362 | return result; |
||
363 | } |
||
364 | |||
365 | //public override void Loaded() |
||
366 | //{ |
||
367 | // base.Loaded(); |
||
368 | |||
369 | // if (!App.IsDesignMode) |
||
370 | // { |
||
371 | // backgroundWorker = new BackgroundWorker(); |
||
372 | // backgroundWorker.DoWork += backgroundWorker_DoWork; |
||
373 | // backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted; |
||
374 | // backgroundWorker.WorkerReportsProgress = false; |
||
375 | // backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
||
376 | |||
377 | // backgroundWorker.RunWorkerAsync(); |
||
378 | // } |
||
379 | //} |
||
380 | |||
381 | //public override void AliveClosed() |
||
382 | //{ |
||
383 | // if (backgroundWorker != null) |
||
384 | // { |
||
385 | // backgroundWorker.DoWork -= backgroundWorker_DoWork; |
||
386 | // backgroundWorker.RunWorkerCompleted -= backgroundWorker_RunWorkerCompleted; |
||
387 | // backgroundWorker.WorkerReportsProgress = false; |
||
388 | // backgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
||
389 | |||
390 | // backgroundWorker.Dispose(); |
||
391 | // } |
||
392 | |||
393 | // base.Closed(); |
||
394 | //} |
||
395 | //alive |
||
396 | |||
397 | a6e5055d | alzkakdixm | BackgroundWorker backgroundWorker; |
398 | |||
399 | Random rnd = new Random(); |
||
400 | |||
401 | private ConvertItem _SelectRealConvert; |
||
402 | private ConvertItem _SelectFilterConvert; |
||
403 | |||
404 | private StatusTypeList _StatusType; |
||
405 | private bool _IsLoading; |
||
406 | |||
407 | private Telerik.Windows.Data.EnumMemberViewModel _SelectedStatus; |
||
408 | |||
409 | public Telerik.Windows.Data.EnumMemberViewModel SelectedStatus |
||
410 | { |
||
411 | get => _SelectedStatus; |
||
412 | set |
||
413 | { |
||
414 | _SelectedStatus = value; |
||
415 | dfc86b71 | taeseongkim | OnPropertyChanged(()=> SelectedStatus); |
416 | a6e5055d | alzkakdixm | } |
417 | } |
||
418 | |||
419 | |||
420 | private SelectedCountItem _SelectedCount; |
||
421 | |||
422 | public SelectedCountItem SelectedCount |
||
423 | { |
||
424 | get => _SelectedCount; |
||
425 | set |
||
426 | { |
||
427 | _SelectedCount = value; |
||
428 | dfc86b71 | taeseongkim | OnPropertyChanged(() => SelectedCount); |
429 | a6e5055d | alzkakdixm | } |
430 | } |
||
431 | |||
432 | |||
433 | public DelegateCommand ConvertCommand { get; private set; } |
||
434 | public DelegateCommand DeleteCommand { get; private set; } |
||
435 | 2decfbdf | alzkakdixm | public DelegateCommand ValidateCommand { get; private set; } |
436 | a6e5055d | alzkakdixm | |
437 | |||
438 | private void DataConvert(object obj) |
||
439 | { |
||
440 | 2decfbdf | alzkakdixm | if (SelectFilterConvert == null && SelectRealConvert == null) |
441 | { |
||
442 | MessageBox.Show("왼쪽 버튼 클릭 후 Converter 해주세요!"); |
||
443 | } |
||
444 | else |
||
445 | { |
||
446 | ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString); |
||
447 | var resultRealConvert = 0; |
||
448 | var resultFiltertConvert = 0; |
||
449 | |||
450 | if (SelectRealConvert != null) |
||
451 | { |
||
452 | /*resultRealConvert = _DataConvert.SetCleanUpItem(SelectRealConvert.ConvertID, SelectRealConvert.ReConverter);*/ |
||
453 | resultRealConvert = _DataConvert.SetCleanUpItem(SelectRealConvert); |
||
454 | } |
||
455 | else if (SelectFilterConvert != null) |
||
456 | { |
||
457 | //resultFiltertConvert = _DataConvert.SetCleanUpItem(SelectFilterConvert.ConvertID, SelectFilterConvert.ReConverter); |
||
458 | resultFiltertConvert = _DataConvert.SetCleanUpItem(SelectFilterConvert); |
||
459 | } |
||
460 | System.Diagnostics.Debug.WriteLine(resultRealConvert + " " + resultFiltertConvert); |
||
461 | a6e5055d | alzkakdixm | |
462 | 2decfbdf | alzkakdixm | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
463 | { |
||
464 | var items = database.GetConvertProjects(SelectFilterConvert); |
||
465 | |||
466 | foreach (var item in items) |
||
467 | { |
||
468 | RealConvertSource.Add(item); |
||
469 | } |
||
470 | |||
471 | } |
||
472 | } |
||
473 | a6e5055d | alzkakdixm | } |
474 | |||
475 | private void DataDelete(object obj) |
||
476 | { |
||
477 | 2decfbdf | alzkakdixm | RadWindow.Alert("정말로 삭제 하시겠습니까?", this.OnClosed); |
478 | } |
||
479 | a6e5055d | alzkakdixm | |
480 | 2decfbdf | alzkakdixm | private void OnClosed(object sender, WindowClosedEventArgs e) |
481 | { |
||
482 | var result = e.DialogResult; |
||
483 | if (result == true) |
||
484 | { |
||
485 | ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString); |
||
486 | var resultRealConvert = _DataConvert.RemoveItem(SelectRealConvert.ConvertID); |
||
487 | var resultFiltertConvert = _DataConvert.RemoveItem(SelectFilterConvert.ConvertID); |
||
488 | System.Diagnostics.Debug.WriteLine(resultRealConvert + " " + resultFiltertConvert); |
||
489 | } |
||
490 | } |
||
491 | private void DataValidate(object obj) |
||
492 | { |
||
493 | MessageBox.Show("파일 체크 할껀데 정상인지 아닌지 "); |
||
494 | a6e5055d | alzkakdixm | |
495 | } |
||
496 | |||
497 | |||
498 | |||
499 | public ConvertItem SelectFilterConvert |
||
500 | { |
||
501 | get => _SelectFilterConvert; |
||
502 | set |
||
503 | { |
||
504 | _SelectFilterConvert = value; |
||
505 | dfc86b71 | taeseongkim | OnPropertyChanged(() => SelectFilterConvert); |
506 | a6e5055d | alzkakdixm | } |
507 | } |
||
508 | public ConvertItem SelectRealConvert |
||
509 | { |
||
510 | get => _SelectRealConvert; |
||
511 | set |
||
512 | { |
||
513 | _SelectRealConvert = value; |
||
514 | dfc86b71 | taeseongkim | OnPropertyChanged(() => SelectRealConvert); |
515 | a6e5055d | alzkakdixm | } |
516 | } |
||
517 | |||
518 | public StatusTypeList StatusType |
||
519 | { |
||
520 | get => _StatusType; |
||
521 | set |
||
522 | { |
||
523 | _StatusType = value; |
||
524 | dfc86b71 | taeseongkim | OnPropertyChanged(() => StatusType); |
525 | a6e5055d | alzkakdixm | } |
526 | } |
||
527 | |||
528 | public bool IsLoading |
||
529 | { |
||
530 | get => _IsLoading; |
||
531 | set |
||
532 | { |
||
533 | if (_IsLoading != value) |
||
534 | { |
||
535 | _IsLoading = value; |
||
536 | dfc86b71 | taeseongkim | OnPropertyChanged(() => IsLoading); |
537 | a6e5055d | alzkakdixm | } |
538 | } |
||
539 | } |
||
540 | |||
541 | List<SelectedCountItem> _SelectedCountList; |
||
542 | |||
543 | public List<SelectedCountItem> SelectedCountList |
||
544 | { |
||
545 | get |
||
546 | { |
||
547 | if (_SelectedCountList == null) |
||
548 | { |
||
549 | _SelectedCountList = new List<SelectedCountItem> |
||
550 | { |
||
551 | new SelectedCountItem{DisplayMember = "50",ValueMember = 50}, |
||
552 | new SelectedCountItem{DisplayMember = "100",ValueMember = 100}, |
||
553 | new SelectedCountItem{DisplayMember = "150",ValueMember = 150}, |
||
554 | new SelectedCountItem{DisplayMember = "200",ValueMember = 200} |
||
555 | }; |
||
556 | } |
||
557 | |||
558 | return _SelectedCountList; |
||
559 | } |
||
560 | } |
||
561 | |||
562 | public DataBaseItemsModel() |
||
563 | { |
||
564 | |||
565 | DataSaveFileGemBoxCommand = new DelegateCommand(DataExport); |
||
566 | ConvertCommand = new DelegateCommand(DataConvert); |
||
567 | DeleteCommand = new DelegateCommand(DataDelete); |
||
568 | 2decfbdf | alzkakdixm | ValidateCommand = new DelegateCommand(DataValidate); |
569 | a6e5055d | alzkakdixm | //Loaded(); |
570 | } |
||
571 | |||
572 | // 진행률에 변화가 있을때 이벤트가 발생 |
||
573 | private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) |
||
574 | { |
||
575 | MessageBox.Show("진행률에 변화"); |
||
576 | } |
||
577 | |||
578 | // 일이 모두 마쳤을때 수행되어야할 코드 |
||
579 | private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
||
580 | { |
||
581 | MessageBox.Show("임무마침"); |
||
582 | } |
||
583 | |||
584 | IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> _StatusCodeList; |
||
585 | |||
586 | public IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> StatusCodeList |
||
587 | { |
||
588 | get |
||
589 | { |
||
590 | if (_StatusCodeList == null) |
||
591 | { |
||
592 | _StatusCodeList = Telerik.Windows.Data.EnumDataSource.FromType<StatusCodeType>(); |
||
593 | } |
||
594 | |||
595 | return _StatusCodeList; |
||
596 | } |
||
597 | } |
||
598 | // BackgroundWorker에서 수행할 일을 정의. |
||
599 | private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) |
||
600 | { |
||
601 | 2decfbdf | alzkakdixm | |
602 | a6e5055d | alzkakdixm | while (IsAcitve) |
603 | { |
||
604 | 2decfbdf | alzkakdixm | |
605 | a6e5055d | alzkakdixm | if (FilterConvertSource == null) |
606 | { |
||
607 | FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
||
608 | } |
||
609 | |||
610 | if (RealConvertSource == null) |
||
611 | { |
||
612 | RealConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
||
613 | } |
||
614 | |||
615 | /// combobox 에서 선택된 items |
||
616 | if (SelectedStatus != null) |
||
617 | { |
||
618 | DataSelect(new[] { (StatusCodeType)(SelectedStatus.Value) }, FilterConvertSource); |
||
619 | } |
||
620 | |||
621 | /// 컨버터중인 items |
||
622 | 2decfbdf | alzkakdixm | RealDataSelect(new[] { StatusCodeType.None, StatusCodeType.Wait, StatusCodeType.PageLoading, StatusCodeType.Saving }, RealConvertSource); |
623 | a6e5055d | alzkakdixm | } |
624 | } |
||
625 | |||
626 | 2decfbdf | alzkakdixm | System.Windows.Threading.DispatcherTimer DispatcherTimer = new System.Windows.Threading.DispatcherTimer(); |
627 | |||
628 | |||
629 | private void RealDataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection) |
||
630 | { |
||
631 | |||
632 | try |
||
633 | { |
||
634 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
||
635 | { |
||
636 | |||
637 | |||
638 | |||
639 | //var items = database.GetConvertProjects(x => statusCodeTypeList.Count(y => (int)y == x.STATUS) > 0)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
||
640 | // .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList(); |
||
641 | |||
642 | //var items = database.GetConvertProjects(x => statusCodeTypeList.Count(y => ((int)y).ToString() == x.ConvertState) > 0)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
||
643 | // .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList(); |
||
644 | //int _status = 0; |
||
645 | //if (SelectedStatus != null) |
||
646 | //{ |
||
647 | // _status = (int)SelectedStatus.Value; |
||
648 | //} |
||
649 | |||
650 | var items = database.GetConvertProjects(collection)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
||
651 | .Take(SelectedCount.ValueMember).ToList();// |
||
652 | |||
653 | //if (statusCodeTypeList.Count() == 4) |
||
654 | //{ |
||
655 | // items.Clear(); |
||
656 | |||
657 | // //items = database.GetConvertProjects(x => statusCodeTypeList.Count(y => (int)y == x.STATUS) > 0)//연습용 |
||
658 | // // .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList();//실행시킨 날 보다 createtime이 최신 일때 |
||
659 | |||
660 | // //items = database.GetConvertProjects(x => DateTime.Compare(x.CREATE_DATETIME, now) > 0 && statusCodeTypeList.Count(y => (int)y == x.STATUS) > 0) |
||
661 | // // .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList();//실행시킨 날 보다 createtime이 최신 일때 |
||
662 | |||
663 | // items = database.GetConvertProjects(x => DateTime.Compare(x.CreateTime, now) > 0 , _status)//statusCodeTypeList.Count(y => ((int)y).ToString() == x.ConvertState) > 0 |
||
664 | // .Take(SelectedCount.ValueMember).ToList(); //아래그리드는 양이 적어서 원래 대로 해도 됨 |
||
665 | //} |
||
666 | //if (collection.Count() == 0) |
||
667 | //{ |
||
668 | // if (statusCodeTypeList.Count() == 1) |
||
669 | // { |
||
670 | // items.ForEach(x => collection.Add(x)); |
||
671 | // } |
||
672 | //} |
||
673 | |||
674 | //else |
||
675 | //{ |
||
676 | ////세미 업데이트 |
||
677 | items.ForEach(newitem => |
||
678 | { |
||
679 | collection.UpdateWhere(changeitem => |
||
680 | ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ConvertID == newitem.ConvertID && x.ProjectNumber == newitem.ProjectNumber); |
||
681 | }); |
||
682 | |||
683 | |||
684 | //if (statusCodeTypeList.Count() == 1) |
||
685 | //{ |
||
686 | // //추가 convert 후 추가됨 |
||
687 | // foreach (var item in items) |
||
688 | // { |
||
689 | // if (collection.Count(x => x.DocumentID == item.DocumentID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감 |
||
690 | // { |
||
691 | // for (int i = 0; i < collection.Count() - 1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가 |
||
692 | // { |
||
693 | // if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0) |
||
694 | // { |
||
695 | // collection.Insert(i, item); |
||
696 | // } |
||
697 | // } |
||
698 | // } |
||
699 | |||
700 | // } |
||
701 | //} |
||
702 | |||
703 | //if (statusCodeTypeList.Count() == 1) |
||
704 | //{ |
||
705 | // //추가 convert 후 추가됨 |
||
706 | // foreach (var item in items) |
||
707 | // { |
||
708 | // if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감 |
||
709 | // { |
||
710 | // for (int i = 0; i < collection.Count() - 1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가 |
||
711 | // { |
||
712 | // if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0) |
||
713 | // { |
||
714 | // collection.Insert(i, item); |
||
715 | // } |
||
716 | // } |
||
717 | // } |
||
718 | |||
719 | // } |
||
720 | //} |
||
721 | |||
722 | //} |
||
723 | } |
||
724 | |||
725 | } |
||
726 | catch (Exception ex) |
||
727 | { |
||
728 | MessageBox.Show(ex.ToString()); |
||
729 | } |
||
730 | |||
731 | |||
732 | } |
||
733 | |||
734 | a6e5055d | alzkakdixm | //<>쓸때는 IEnumerable |
735 | 2decfbdf | alzkakdixm | |
736 | a6e5055d | alzkakdixm | private void DataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection) |
737 | { |
||
738 | 2decfbdf | alzkakdixm | |
739 | a6e5055d | alzkakdixm | try |
740 | { |
||
741 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
||
742 | { |
||
743 | |||
744 | 2decfbdf | alzkakdixm | |
745 | |||
746 | //var items = database.GetConvertProjects(x => statusCodeTypeList.Count(y => (int)y == x.STATUS) > 0)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
||
747 | // .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList(); |
||
748 | |||
749 | //var items = database.GetConvertProjects(x => statusCodeTypeList.Count(y => ((int)y).ToString() == x.ConvertState) > 0)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
||
750 | // .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList(); |
||
751 | int _status = 0; |
||
752 | if (SelectedStatus != null) |
||
753 | { |
||
754 | _status = (int)SelectedStatus.Value; |
||
755 | } |
||
756 | |||
757 | var items = database.GetConvertProjects(_status)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
||
758 | .Take(SelectedCount.ValueMember).ToList();// |
||
759 | |||
760 | //if (statusCodeTypeList.Count() == 4) |
||
761 | //{ |
||
762 | // items.Clear(); |
||
763 | |||
764 | // //items = database.GetConvertProjects(x => statusCodeTypeList.Count(y => (int)y == x.STATUS) > 0)//연습용 |
||
765 | // // .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList();//실행시킨 날 보다 createtime이 최신 일때 |
||
766 | |||
767 | // //items = database.GetConvertProjects(x => DateTime.Compare(x.CREATE_DATETIME, now) > 0 && statusCodeTypeList.Count(y => (int)y == x.STATUS) > 0) |
||
768 | // // .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList();//실행시킨 날 보다 createtime이 최신 일때 |
||
769 | |||
770 | // items = database.GetConvertProjects(x => DateTime.Compare(x.CreateTime, now) > 0 , _status)//statusCodeTypeList.Count(y => ((int)y).ToString() == x.ConvertState) > 0 |
||
771 | // .Take(SelectedCount.ValueMember).ToList(); //아래그리드는 양이 적어서 원래 대로 해도 됨 |
||
772 | //} |
||
773 | a6e5055d | alzkakdixm | if (collection.Count() == 0) |
774 | { |
||
775 | 2decfbdf | alzkakdixm | if (statusCodeTypeList.Count() == 1) |
776 | { |
||
777 | items.ForEach(x => collection.Add(x)); |
||
778 | } |
||
779 | a6e5055d | alzkakdixm | } |
780 | 2decfbdf | alzkakdixm | |
781 | a6e5055d | alzkakdixm | else |
782 | { |
||
783 | 2decfbdf | alzkakdixm | ////세미 업데이트 |
784 | //items.ForEach(newitem => |
||
785 | //{ |
||
786 | // collection.UpdateWhere(changeitem => |
||
787 | // ConvertItemEx.ChangeValues(changeitem, newitem), x => x.DocumentID == newitem.DocumentID && x.ProjectNumber == newitem.ProjectNumber); |
||
788 | //}); |
||
789 | |||
790 | ////세미 업데이트 |
||
791 | items.ForEach(newitem => |
||
792 | a6e5055d | alzkakdixm | { |
793 | collection.UpdateWhere(changeitem => |
||
794 | 2decfbdf | alzkakdixm | ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
795 | a6e5055d | alzkakdixm | }); |
796 | |||
797 | 2decfbdf | alzkakdixm | //if (statusCodeTypeList.Count() == 1) |
798 | //{ |
||
799 | // //삭제 |
||
800 | // for (int i = collection.Count() - 1; i >= 0; --i) |
||
801 | // { |
||
802 | // var item = collection[i]; |
||
803 | |||
804 | // if (items.Count(x => x.DocumentID == item.DocumentID && x.ProjectNumber == item.ProjectNumber) == 0)//디비에서 가져온 값과 마지막값부터 차례대로 비교 |
||
805 | // {//참=> 0제외한 모든 수 |
||
806 | // collection.RemoveAt(i); |
||
807 | // } |
||
808 | // } |
||
809 | //} |
||
810 | |||
811 | //if (statusCodeTypeList.Count() == 1) |
||
812 | //{ |
||
813 | // //추가 convert 후 추가됨 |
||
814 | // foreach (var item in items) |
||
815 | // { |
||
816 | // if (collection.Count(x => x.DocumentID == item.DocumentID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감 |
||
817 | // { |
||
818 | // for (int i = 0; i < collection.Count() - 1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가 |
||
819 | // { |
||
820 | // if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0) |
||
821 | // { |
||
822 | // collection.Insert(i, item); |
||
823 | // } |
||
824 | // } |
||
825 | // } |
||
826 | |||
827 | // } |
||
828 | //} |
||
829 | |||
830 | if (statusCodeTypeList.Count() == 1) |
||
831 | a6e5055d | alzkakdixm | { |
832 | 2decfbdf | alzkakdixm | //삭제 |
833 | for (int i = collection.Count() - 1; i >= 0; --i) |
||
834 | a6e5055d | alzkakdixm | { |
835 | 2decfbdf | alzkakdixm | var item = collection[i]; |
836 | a6e5055d | alzkakdixm | |
837 | 2decfbdf | alzkakdixm | if (items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//디비에서 가져온 값과 마지막값부터 차례대로 비교 |
838 | {//참=> 0제외한 모든 수 |
||
839 | collection.RemoveAt(i); |
||
840 | } |
||
841 | } |
||
842 | a6e5055d | alzkakdixm | } |
843 | |||
844 | 2decfbdf | alzkakdixm | if (statusCodeTypeList.Count() == 1) |
845 | a6e5055d | alzkakdixm | { |
846 | 2decfbdf | alzkakdixm | //추가 convert 후 추가됨 |
847 | foreach (var item in items) |
||
848 | { |
||
849 | if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감 |
||
850 | { |
||
851 | /*for (int i = 0; i < collection.Count()+1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가*/ |
||
852 | for (int i = 0; i < 200; i++) |
||
853 | { |
||
854 | if (i < collection.Count() - 1) |
||
855 | { |
||
856 | if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0) |
||
857 | { |
||
858 | collection.Insert(i, item); |
||
859 | break; |
||
860 | } |
||
861 | } |
||
862 | else |
||
863 | { |
||
864 | collection.Add(item); |
||
865 | break; |
||
866 | } |
||
867 | } |
||
868 | |||
869 | } |
||
870 | a6e5055d | alzkakdixm | |
871 | } |
||
872 | } |
||
873 | 2decfbdf | alzkakdixm | |
874 | a6e5055d | alzkakdixm | } |
875 | } |
||
876 | 2decfbdf | alzkakdixm | |
877 | a6e5055d | alzkakdixm | } |
878 | catch (Exception ex) |
||
879 | { |
||
880 | MessageBox.Show(ex.ToString()); |
||
881 | 2decfbdf | alzkakdixm | //System.Diagnostics.Debug.WriteLine(ex.ToString()); |
882 | a6e5055d | alzkakdixm | } |
883 | |||
884 | |||
885 | } |
||
886 | |||
887 | 2decfbdf | alzkakdixm | |
888 | a6e5055d | alzkakdixm | public override void Loaded() |
889 | { |
||
890 | base.Loaded(); |
||
891 | |||
892 | if (!App.IsDesignMode) |
||
893 | { |
||
894 | backgroundWorker = new BackgroundWorker(); |
||
895 | backgroundWorker.DoWork += backgroundWorker_DoWork; |
||
896 | backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted; |
||
897 | backgroundWorker.WorkerReportsProgress = false; |
||
898 | backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
||
899 | |||
900 | backgroundWorker.RunWorkerAsync(); |
||
901 | 2decfbdf | alzkakdixm | |
902 | AlivebackgroundWorker = new BackgroundWorker(); |
||
903 | AlivebackgroundWorker.DoWork += AlivebackgroundWorker_DoWork; |
||
904 | AlivebackgroundWorker.RunWorkerCompleted += AlivebackgroundWorker_RunWorkerCompleted; |
||
905 | AlivebackgroundWorker.WorkerReportsProgress = false; |
||
906 | AlivebackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(AlivebackgroundWorker_ProgressChanged); |
||
907 | |||
908 | AlivebackgroundWorker.RunWorkerAsync(); |
||
909 | a6e5055d | alzkakdixm | } |
910 | } |
||
911 | |||
912 | public override void Closed() |
||
913 | { |
||
914 | |||
915 | if (backgroundWorker != null) |
||
916 | { |
||
917 | backgroundWorker.DoWork -= backgroundWorker_DoWork; |
||
918 | backgroundWorker.RunWorkerCompleted -= backgroundWorker_RunWorkerCompleted; |
||
919 | backgroundWorker.WorkerReportsProgress = false; |
||
920 | backgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
||
921 | |||
922 | 2decfbdf | alzkakdixm | AlivebackgroundWorker.DoWork -= AlivebackgroundWorker_DoWork; |
923 | AlivebackgroundWorker.RunWorkerCompleted -= AlivebackgroundWorker_RunWorkerCompleted; |
||
924 | AlivebackgroundWorker.WorkerReportsProgress = false; |
||
925 | AlivebackgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(AlivebackgroundWorker_ProgressChanged); |
||
926 | |||
927 | AlivebackgroundWorker.Dispose(); |
||
928 | a6e5055d | alzkakdixm | |
929 | 2decfbdf | alzkakdixm | } |
930 | a6e5055d | alzkakdixm | base.Closed(); |
931 | } |
||
932 | |||
933 | |||
934 | public DelegateCommand DataSaveFileGemBoxCommand { get; private set; } |
||
935 | |||
936 | public class HeaderMember |
||
937 | { |
||
938 | public string HeaderName { get; set; } |
||
939 | public string Property { get; set; } |
||
940 | } |
||
941 | //public void DataExport<T>(IEnumerable<T> AliveItems) |
||
942 | public void DataExport(object obj) |
||
943 | { |
||
944 | SaveFileDialog saveFileDialog = new SaveFileDialog(); |
||
945 | |||
946 | saveFileDialog.FileName = "Document"; // Default file name |
||
947 | saveFileDialog.DefaultExt = ".txt"; // Default file extension |
||
948 | saveFileDialog.Filter = "Csv documents (.Csv)|*.csv|Excel(2017~2019)Worksheets|*.xlsx"; // Filter files by extension |
||
949 | |||
950 | |||
951 | if (saveFileDialog.ShowDialog() == true) |
||
952 | { |
||
953 | |||
954 | |||
955 | if (!string.IsNullOrWhiteSpace(saveFileDialog.FileName)) |
||
956 | { |
||
957 | |||
958 | var extension = new System.IO.FileInfo(saveFileDialog.FileName).Extension; |
||
959 | |||
960 | if (extension == ".xlsx" || extension == ".csv") |
||
961 | { |
||
962 | |||
963 | var headers = new List<HeaderMember> |
||
964 | { |
||
965 | new HeaderMember{HeaderName = "ServiceID", Property = "ServiceID" }, |
||
966 | new HeaderMember{HeaderName = "ConvertID", Property = "ConvertID" }, |
||
967 | new HeaderMember{HeaderName = "ProjectNumber", Property = "ProjectNumber" }, |
||
968 | new HeaderMember{HeaderName = "ConvertState", Property = "ConvertState" }, |
||
969 | new HeaderMember{HeaderName = "CurrentPageNo", Property = "CurrentPageNo" }, |
||
970 | new HeaderMember{HeaderName = "TotalPage", Property = "TotalPage" }, |
||
971 | new HeaderMember{HeaderName = "OriginfilePath", Property = "OriginfilePath" }, |
||
972 | new HeaderMember{HeaderName = "ConvertPath", Property = "ConvertPath" }, |
||
973 | new HeaderMember{HeaderName = "CreateTime", Property = "CreateTime" }, |
||
974 | new HeaderMember{HeaderName = "Exception", Property = "Exception" }, |
||
975 | new HeaderMember{HeaderName = "ProcessorAffinity", Property = "ProcessorAffinity" }, |
||
976 | new HeaderMember{HeaderName = "ReConverter", Property = "ReConverter" }, |
||
977 | new HeaderMember{HeaderName = "UniqueKey", Property = "UniqueKey" } |
||
978 | }; |
||
979 | |||
980 | |||
981 | |||
982 | DataExportExcel(saveFileDialog.FileName, "Hello world", FilterConvertSource, headers); |
||
983 | //_dataExport.DataExportExcel(saveFileDialog.FileName, saveFileDialog.FileName.ToString(), Projectsource, headers); |
||
984 | //GemBoxFileSave(obj); |
||
985 | } |
||
986 | } |
||
987 | } |
||
988 | } |
||
989 | |||
990 | |||
991 | public void DataExportExcel<T>(string SaveFile, string SheetName, IEnumerable<T> collections, List<HeaderMember> headerMembers) |
||
992 | { |
||
993 | |||
994 | try |
||
995 | { |
||
996 | SpreadsheetInfo.SetLicense("EXK0-W4HZ-N518-IMEW"); |
||
997 | // SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");//프리버전은 15줄까지만 가능 |
||
998 | |||
999 | var workbook = new ExcelFile(); |
||
1000 | var worksheet = workbook.Worksheets.Add(SheetName); |
||
1001 | |||
1002 | // IEnumerable<T> collections를 for문 |
||
1003 | for (int rowNumber = 0; rowNumber < collections.Count(); rowNumber++)//1857 양이 너무 많아서 빨리 엑셀출력 누르면 숫자가 감소됨 차분히 기다리면 숫자 늘어남 |
||
1004 | { |
||
1005 | // index에 해당하는 row를 가져온다. |
||
1006 | object row = collections.ElementAt(rowNumber);//우왕좌왕하게 모든 프로퍼티 있음 생성자 프로퍼티도 있음 |
||
1007 | |||
1008 | //row의 properties를 가져옴. |
||
1009 | var rowPropInfos = row.GetType().GetProperties();//행렬로 보기좋게 프로퍼티 나옴 |
||
1010 | |||
1011 | /// 지정된 header에 대해서 프로퍼티에 해당하는 값을 가져와서 cell에 출력 |
||
1012 | for (int i = 0; i < headerMembers.Count(); i++)//13 |
||
1013 | { |
||
1014 | var prop = rowPropInfos.Where(x => x.Name == headerMembers[i].Property);//prop 0으로 나옴 |
||
1015 | if (headerMembers[i].Property == "CreateTime") |
||
1016 | { |
||
1017 | worksheet.Cells[rowNumber + 1, i].Value = prop.First().GetValue(row).ToString(); |
||
1018 | } |
||
1019 | else if (prop.Count() > 0) |
||
1020 | { |
||
1021 | worksheet.Cells[rowNumber + 1, i].Value = prop.First().GetValue(row); |
||
1022 | } |
||
1023 | } |
||
1024 | } |
||
1025 | |||
1026 | int k = 0; |
||
1027 | foreach (var HeadInfo in headerMembers) |
||
1028 | { |
||
1029 | worksheet.Cells[0, k].Value = HeadInfo.HeaderName; |
||
1030 | k++; |
||
1031 | } |
||
1032 | |||
1033 | int columnCount = worksheet.CalculateMaxUsedColumns(); |
||
1034 | for (int i = 0; i < columnCount; i++) |
||
1035 | { |
||
1036 | worksheet.Columns[i].AutoFit(); |
||
1037 | } |
||
1038 | |||
1039 | |||
1040 | |||
1041 | var header = new CellStyle();//헤더 |
||
1042 | |||
1043 | header.FillPattern.SetSolid(SpreadsheetColor.FromArgb(0, 100, 220)); |
||
1044 | header.Font.Weight = ExcelFont.BoldWeight; |
||
1045 | header.HorizontalAlignment = HorizontalAlignmentStyle.Center; |
||
1046 | header.VerticalAlignment = VerticalAlignmentStyle.Center; |
||
1047 | //worksheet.Cells.GetSubrange("A1:M1").Style = header; |
||
1048 | worksheet.Cells.GetSubrangeAbsolute(0, 0, collections.Count(), headerMembers.Count() - 1).Style = header; |
||
1049 | |||
1050 | |||
1051 | |||
1052 | var style = new CellStyle(); |
||
1053 | //style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Top | MultipleBorders.Left | MultipleBorders.Bottom, SpreadsheetColor.FromArgb(140, 120, 50), LineStyle.Thick);//바깥쪽 border 두껍게 성공 |
||
1054 | style.Borders.SetBorders(MultipleBorders.Outside, SpreadsheetColor.FromArgb(140, 120, 50), LineStyle.Thick);//바깥쪽 border 두껍게 성공 |
||
1055 | |||
1056 | |||
1057 | |||
1058 | style.HorizontalAlignment = HorizontalAlignmentStyle.Center; |
||
1059 | style.VerticalAlignment = VerticalAlignmentStyle.Center; |
||
1060 | style.Font.Color = SpreadsheetColor.FromArgb(75, 60, 50);//글자 색갈 |
||
1061 | style.FillPattern.SetSolid(SpreadsheetColor.FromArgb(126, 239, 239));//cell 색갈 |
||
1062 | style.Font.Name = "맑은 고딕"; |
||
1063 | style.Font.Size = 9 * 20; |
||
1064 | worksheet.Cells.GetSubrangeAbsolute(0, 0, collections.Count(), headerMembers.Count() - 1).Style = style; |
||
1065 | //worksheet.Cells.GetSubrange("A1:M1858").Style = style; |
||
1066 | |||
1067 | for (int line = 0; line < collections.Count() - 1; line++) //바깥border과 안쪽 얇은 border 같이 쓰면 안됨 |
||
1068 | { |
||
1069 | //for (int j = 0; j < 14 - 1 - 1; j++) |
||
1070 | for (int j = 0; j < headerMembers.Count() - 1 - 1; j++) |
||
1071 | { |
||
1072 | worksheet.Cells[line + 1, j + 1].Style.Borders.SetBorders(MultipleBorders.Outside, SpreadsheetColor.FromArgb(140, 120, 50), LineStyle.Thin);//안쪽 (1,1) ~ (마지막-1,마지막-1) 가운데 성공 |
||
1073 | } |
||
1074 | } |
||
1075 | |||
1076 | |||
1077 | for (int line = 0; line < collections.Count(); line++) //바깥border과 안쪽 얇은 border 같이 쓰면 안됨 |
||
1078 | {//Projectsource.Count() = 761개 ( 0 ~ 760 ) |
||
1079 | for (int j = 0; j < headerMembers.Count() - 1; j++) |
||
1080 | { |
||
1081 | worksheet.Cells[0, j].Style.Borders.SetBorders(MultipleBorders.Right, SpreadsheetColor.FromArgb(140, 120, 50), LineStyle.Thin);//(0,0) ~ (0,마지막-1) 위 성공 |
||
1082 | |||
1083 | worksheet.Cells[collections.Count(), j].Style.Borders.SetBorders(MultipleBorders.Right, SpreadsheetColor.FromArgb(140, 120, 50), LineStyle.Thin);//(마지막,0) ~ (마지막,마지막-1) 아래 성공 |
||
1084 | } |
||
1085 | |||
1086 | worksheet.Cells[line, 0].Style.Borders.SetBorders(MultipleBorders.Bottom, SpreadsheetColor.FromArgb(140, 120, 50), LineStyle.Thin);//(0,0) ~ (마지막-1,0) 왼쪽 성공 |
||
1087 | |||
1088 | worksheet.Cells[line, headerMembers.Count() - 1].Style.Borders.SetBorders(MultipleBorders.Bottom, SpreadsheetColor.FromArgb(140, 120, 50), LineStyle.Thin);//(0,마지막) ~ (마지막-1,마지막) 오른쪽 성공 |
||
1089 | |||
1090 | } |
||
1091 | |||
1092 | workbook.Save(SaveFile);//파일 열었던 파일로 저장 성공 |
||
1093 | MessageBox.Show("성공"); |
||
1094 | } |
||
1095 | |||
1096 | catch (Exception ex) |
||
1097 | { |
||
1098 | Console.WriteLine("예외 발생!! 메세지: {0}", ex.Message); |
||
1099 | } |
||
1100 | } |
||
1101 | |||
1102 | } |
||
1103 | |||
1104 | 2decfbdf | alzkakdixm | |
1105 | public class SelectedCountItem : INotifyPropertyChanged |
||
1106 | a6e5055d | alzkakdixm | { |
1107 | 2decfbdf | alzkakdixm | public event PropertyChangedEventHandler PropertyChanged; |
1108 | |||
1109 | private void NotifyPropertyChanged(String info) |
||
1110 | { |
||
1111 | if (PropertyChanged != null) |
||
1112 | { |
||
1113 | PropertyChanged(this, new PropertyChangedEventArgs(info)); |
||
1114 | } |
||
1115 | } |
||
1116 | |||
1117 | //public string DisplayMember { get; set; } |
||
1118 | public string _DisplayMember; |
||
1119 | |||
1120 | public string DisplayMember |
||
1121 | { |
||
1122 | get => _DisplayMember; |
||
1123 | set |
||
1124 | { |
||
1125 | _DisplayMember = value; |
||
1126 | dfc86b71 | taeseongkim | |
1127 | 2decfbdf | alzkakdixm | NotifyPropertyChanged("DisplayMember"); |
1128 | } |
||
1129 | } |
||
1130 | //public int ValueMember { get; set; } |
||
1131 | public int _ValueMember; |
||
1132 | public int ValueMember |
||
1133 | { |
||
1134 | get => _ValueMember; |
||
1135 | set |
||
1136 | { |
||
1137 | _ValueMember = value; |
||
1138 | NotifyPropertyChanged("ValueMember"); |
||
1139 | } |
||
1140 | } |
||
1141 | a6e5055d | alzkakdixm | } |
1142 | 2decfbdf | alzkakdixm | |
1143 | a6e5055d | alzkakdixm | } |
1144 | 2decfbdf | alzkakdixm | |
1145 | //public class AliveViewModel : Markus.Mvvm.ToolKit.ViewModelBase |
||
1146 | //{ |
||
1147 | // BackgroundWorker backgroundWorker; |
||
1148 | |||
1149 | // private System.Collections.ObjectModel.ObservableCollection<Markus.Service.WcfClient.StationServiceTask.ConvertItem> aliveItems; |
||
1150 | // private bool isLoading; |
||
1151 | // private System.Windows.Documents.FlowDocument connectionLog; |
||
1152 | |||
1153 | // public System.Collections.ObjectModel.ObservableCollection<Markus.Service.WcfClient.StationServiceTask.ConvertItem> AliveItems |
||
1154 | // { |
||
1155 | // get => aliveItems; set |
||
1156 | // { |
||
1157 | // aliveItems = value; |
||
1158 | // OnPropertyChanged(() => AliveItems); |
||
1159 | // } |
||
1160 | // } |
||
1161 | |||
1162 | // public bool IsLoading |
||
1163 | // { |
||
1164 | // get => isLoading; set |
||
1165 | // { |
||
1166 | // if (isLoading != value) |
||
1167 | // { |
||
1168 | // isLoading = value; |
||
1169 | // OnPropertyChanged(() => IsLoading); |
||
1170 | // } |
||
1171 | // } |
||
1172 | // } |
||
1173 | |||
1174 | |||
1175 | // public System.Windows.Documents.FlowDocument ConnectionLog |
||
1176 | // { |
||
1177 | // get => connectionLog; |
||
1178 | // set |
||
1179 | // { |
||
1180 | // if (connectionLog != value) |
||
1181 | // { |
||
1182 | // connectionLog = value; |
||
1183 | // OnPropertyChanged(() => ConnectionLog); |
||
1184 | // } |
||
1185 | // } |
||
1186 | // } |
||
1187 | |||
1188 | // public AliveViewModel() |
||
1189 | // { |
||
1190 | // } |
||
1191 | |||
1192 | // // 진행률에 변화가 있을때 이벤트가 발생 |
||
1193 | // private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) |
||
1194 | // { |
||
1195 | // } |
||
1196 | |||
1197 | // // 일이 모두 마쳤을때 수행되어야할 코드 |
||
1198 | // private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
||
1199 | // { |
||
1200 | // } |
||
1201 | |||
1202 | // // BackgroundWorker에서 수행할 일을 정의. |
||
1203 | // private async void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) |
||
1204 | // { |
||
1205 | // while (IsAcitve) |
||
1206 | // { |
||
1207 | // System.Threading.Thread.Sleep(new TimeSpan(0, 0, 3)); |
||
1208 | |||
1209 | // if (!IsLoading) |
||
1210 | // { |
||
1211 | // IsLoading = true; |
||
1212 | |||
1213 | // try |
||
1214 | // { |
||
1215 | |||
1216 | // List<Markus.Service.WcfClient.StationServiceTask.ConvertItem> newitems = new List<Markus.Service.WcfClient.StationServiceTask.ConvertItem>(); |
||
1217 | |||
1218 | // foreach (var client in App.StationClientList) |
||
1219 | // { |
||
1220 | // if (await SimplePingAsync(client.Endpoint.Address.ToString())) |
||
1221 | // { |
||
1222 | // try |
||
1223 | // { |
||
1224 | // Markus.Service.WcfClient.StationServiceTask.ConvertItem[] items = await client.AliveConvertListAsync(); |
||
1225 | // newitems.AddRange(items); |
||
1226 | // //System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping"); |
||
1227 | |||
1228 | // if (items.Count() == 0) |
||
1229 | // { |
||
1230 | // //System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero."); |
||
1231 | // } |
||
1232 | // } |
||
1233 | // catch (Exception ex) |
||
1234 | // { |
||
1235 | // //System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}"); |
||
1236 | // } |
||
1237 | // } |
||
1238 | // else |
||
1239 | // { |
||
1240 | // //System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error"); |
||
1241 | // } |
||
1242 | // } |
||
1243 | |||
1244 | // await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems)); |
||
1245 | // } |
||
1246 | // catch (Exception ex) |
||
1247 | // { |
||
1248 | // System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
1249 | // } |
||
1250 | |||
1251 | // IsLoading = false; |
||
1252 | // } |
||
1253 | |||
1254 | // } |
||
1255 | // } |
||
1256 | |||
1257 | |||
1258 | |||
1259 | // private void ItemsUpdate(List<Markus.Service.WcfClient.StationServiceTask.ConvertItem> newitems) |
||
1260 | // { |
||
1261 | |||
1262 | // foreach (var item in newitems) |
||
1263 | // { |
||
1264 | // item.OriginfilePath = HttpUtility.UrlDecode(item.OriginfilePath); |
||
1265 | // } |
||
1266 | |||
1267 | // if (AliveItems == null) |
||
1268 | // { |
||
1269 | // AliveItems = new System.Collections.ObjectModel.ObservableCollection<Markus.Service.WcfClient.StationServiceTask.ConvertItem>(); |
||
1270 | |||
1271 | // foreach (var item in newitems) |
||
1272 | // { |
||
1273 | // AliveItems.Add(item); |
||
1274 | // } |
||
1275 | // } |
||
1276 | // else |
||
1277 | // { |
||
1278 | // /// 데이터 업데이트 |
||
1279 | // newitems.ForEach(newitem => |
||
1280 | // { |
||
1281 | // AliveItems.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
||
1282 | // }); |
||
1283 | |||
1284 | // // 추가 |
||
1285 | // foreach (var item in newitems) |
||
1286 | // { |
||
1287 | // if (AliveItems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
||
1288 | // { |
||
1289 | // AliveItems.Add(item); |
||
1290 | // } |
||
1291 | // } |
||
1292 | |||
1293 | // /// 삭제 |
||
1294 | |||
1295 | // for (int i = AliveItems.Count() - 1; i > -1; --i) |
||
1296 | // { |
||
1297 | // var item = AliveItems[i]; |
||
1298 | |||
1299 | // if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
||
1300 | // { |
||
1301 | // try |
||
1302 | // { |
||
1303 | // AliveItems.RemoveAt(i); |
||
1304 | // } |
||
1305 | // catch (Exception ex) |
||
1306 | // { |
||
1307 | // System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
1308 | // } |
||
1309 | // } |
||
1310 | // } |
||
1311 | // } |
||
1312 | // } |
||
1313 | |||
1314 | // private void LogWrite(string log, bool IsError) |
||
1315 | // { |
||
1316 | // if (IsError) |
||
1317 | // { |
||
1318 | // //System.Diagnostics.Trace.Fail(log); |
||
1319 | // } |
||
1320 | // else |
||
1321 | // { |
||
1322 | // //System.Diagnostics.Trace.TraceInformation(log); |
||
1323 | // } |
||
1324 | // } |
||
1325 | |||
1326 | |||
1327 | // public static async Task<bool> SimplePingAsync(string uri) |
||
1328 | // { |
||
1329 | // bool result = false; |
||
1330 | |||
1331 | // try |
||
1332 | // { |
||
1333 | // using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient()) |
||
1334 | // { |
||
1335 | // Client.Timeout = new TimeSpan(0, 0, 60); |
||
1336 | |||
1337 | // var message = await Client.GetAsync(uri); |
||
1338 | |||
1339 | // System.Net.HttpStatusCode StatusCode = message.StatusCode; |
||
1340 | |||
1341 | // switch (StatusCode) |
||
1342 | // { |
||
1343 | |||
1344 | // case System.Net.HttpStatusCode.Accepted: |
||
1345 | // case System.Net.HttpStatusCode.OK: |
||
1346 | // result = true; |
||
1347 | // break; |
||
1348 | // } |
||
1349 | // } |
||
1350 | // } |
||
1351 | // catch (Exception ex) |
||
1352 | // { |
||
1353 | // result = false; |
||
1354 | // System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
1355 | // } |
||
1356 | |||
1357 | // return result; |
||
1358 | // } |
||
1359 | |||
1360 | // public override void Loaded() |
||
1361 | // { |
||
1362 | // base.Loaded(); |
||
1363 | |||
1364 | // if (!App.IsDesignMode) |
||
1365 | // { |
||
1366 | // backgroundWorker = new BackgroundWorker(); |
||
1367 | // backgroundWorker.DoWork += backgroundWorker_DoWork; |
||
1368 | // backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted; |
||
1369 | // backgroundWorker.WorkerReportsProgress = false; |
||
1370 | // backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
||
1371 | |||
1372 | // backgroundWorker.RunWorkerAsync(); |
||
1373 | // } |
||
1374 | // } |
||
1375 | |||
1376 | // public override void Closed() |
||
1377 | // { |
||
1378 | // if (backgroundWorker != null) |
||
1379 | // { |
||
1380 | // backgroundWorker.DoWork -= backgroundWorker_DoWork; |
||
1381 | // backgroundWorker.RunWorkerCompleted -= backgroundWorker_RunWorkerCompleted; |
||
1382 | // backgroundWorker.WorkerReportsProgress = false; |
||
1383 | // backgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
||
1384 | |||
1385 | // backgroundWorker.Dispose(); |
||
1386 | // } |
||
1387 | |||
1388 | // base.Closed(); |
||
1389 | // } |
||
1390 | //} |