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