프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseByStatusViewModel.cs @ 2bbea412

이력 | 보기 | 이력해설 | 다운로드 (5.64 KB)

1 06f13e11 taeseongkim

2 6f6e7dbf taeseongkim
using System;
3
using System.Collections.Generic;
4
using System.ComponentModel;
5
using System.Linq;
6
using System.Text;
7
using System.Threading.Tasks;
8
using Markus.Service.Extensions;
9
using Markus.Message;
10 b92f142f taeseongkim
using Markus.Service.StationController.Extensions;
11
using Markus.Service.Interface;
12 6f6e7dbf taeseongkim
13
namespace Markus.Service.StationController.ViewModel
14
{
15
    public class DataBaseByStatusViewModel : Mvvm.ToolKit.ViewModelBase
16
    {
17
        BackgroundWorker backgroundWorker;
18
19 b92f142f taeseongkim
        private System.Collections.ObjectModel.ObservableCollection<ConvertItem> items;
20
        private ConvertItem selectItem;
21
22 f363a40e taeseongkim
        private IEnumerable<StatusCodeType> statusType;
23 6f6e7dbf taeseongkim
        private bool isLoading;
24
25 b92f142f taeseongkim
        public System.Collections.ObjectModel.ObservableCollection<ConvertItem> Items
26 6f6e7dbf taeseongkim
        {
27
            get => items; set
28
            {
29
                items = value;
30
                OnPropertyChanged(() => Items);
31
            }
32
        }
33
34 b92f142f taeseongkim
        public ConvertItem SelectItem
35
        {
36
            get => selectItem; set
37
            {
38
                selectItem = value;
39
                OnPropertyChanged(() => SelectItem);
40
            }
41
        }
42
43
44 f363a40e taeseongkim
        public IEnumerable<StatusCodeType> StatusType
45 6f6e7dbf taeseongkim
        {
46
            get => statusType; set
47
            {
48
                statusType = value;
49
                OnPropertyChanged(() => StatusType);
50
            }
51
        }
52
53
        public bool IsLoading
54
        {
55
            get => isLoading; set
56
            {
57
                if (isLoading != value)
58
                {
59
                    isLoading = value;
60
                    OnPropertyChanged(() => IsLoading);
61
                }
62
            }
63
        }
64
65 b92f142f taeseongkim
       
66
67 6f6e7dbf taeseongkim
        public DataBaseByStatusViewModel()
68
        {
69
        }
70
71
        // 진행률에 변화가 있을때 이벤트가 발생
72
        private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
73
        {
74
        }
75
76
        // 일이 모두 마쳤을때 수행되어야할 코드
77
        private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
78
        {
79
        }
80
81
        // BackgroundWorker에서 수행할 일을 정의.
82 b92f142f taeseongkim
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
83 6f6e7dbf taeseongkim
        {
84
            while (IsAcitve)
85
            {
86
                System.Threading.Thread.Sleep(1000);
87
88
                try
89
                {
90
                    IsLoading = true;
91
92
                    List<ConvertItem> newitems = new List<ConvertItem>();
93
94 b92f142f taeseongkim
                    using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
95 6f6e7dbf taeseongkim
                    {
96 60723dc9 taeseongkim
                        foreach (var status in statusType)
97
                        {
98
                            newitems.AddRange(database.GetConvertItems(status, x => x.TOTAL_PAGE > 100, 10));
99
                        }
100 6f6e7dbf taeseongkim
                    }
101
102 b92f142f taeseongkim
                    if (Items == null)
103
                    {
104
                        Items = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
105 6f6e7dbf taeseongkim
106 b92f142f taeseongkim
                        foreach (var item in newitems)
107
                        {
108
                            Items.Add(item);
109
                        }
110
                    }
111
                    else
112
                    {
113
                        /// 데이터 업데이트
114
                        newitems.ForEach(newitem =>
115
                        {
116
                            Items.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID);
117
                        });
118
119
                        // 추가
120
                        foreach (var item in newitems)
121
                        {
122
                            if (Items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
123
                            {
124
                                Items.Add(item);
125
                            }
126
                        }
127
128
                        /// 삭제
129
130
                        for (int i = Items.Count() - 1; i > -1; --i)
131
                        {
132
                            var item = Items[i];
133
134
                            if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
135
                            {
136
                                Items.RemoveAt(i);
137
                            }
138
                        }
139
                    }
140 6f6e7dbf taeseongkim
                }
141
                catch (Exception ex)
142
                {
143
                }
144
            }
145
            
146
        }
147
148
        public override void Loaded()
149
        {
150
            base.Loaded();
151
152 a34f58f6 taeseongkim
            if (!App.IsDesignMode)
153 b92f142f taeseongkim
            {
154
                backgroundWorker = new BackgroundWorker();
155
                backgroundWorker.DoWork += backgroundWorker_DoWork;
156
                backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;
157
                backgroundWorker.WorkerReportsProgress = false;
158
                backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
159 6f6e7dbf taeseongkim
160 b92f142f taeseongkim
                backgroundWorker.RunWorkerAsync();
161
            }
162 6f6e7dbf taeseongkim
        }
163
164
        public override void Closed()
165
        {
166 a34f58f6 taeseongkim
            if (!App.IsDesignMode)
167 b92f142f taeseongkim
            {
168
                backgroundWorker.DoWork -= backgroundWorker_DoWork;
169
                backgroundWorker.RunWorkerCompleted -= backgroundWorker_RunWorkerCompleted;
170
                backgroundWorker.WorkerReportsProgress = false;
171
                backgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
172 6f6e7dbf taeseongkim
173 b92f142f taeseongkim
                backgroundWorker.Dispose();
174
            }
175 6f6e7dbf taeseongkim
176
            base.Closed();
177
        }
178
    }
179
}
클립보드 이미지 추가 (최대 크기: 500 MB)