markus / KCOM / ViewModel / RequirementViewModel.cs @ fe5ec96f
이력 | 보기 | 이력해설 | 다운로드 (11.4 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Collections.ObjectModel; |
4 |
using System.Linq; |
5 |
using System.Text; |
6 |
using System.Threading.Tasks; |
7 |
using System.Windows; |
8 |
using KCOM.Common; |
9 |
using KCOM.PemssService; |
10 |
using Markus.Mvvm.ToolKit; |
11 |
using Telerik.Windows.Controls; |
12 |
|
13 |
namespace KCOM.ViewModel |
14 |
{ |
15 |
public class RequirementViewModel : Markus.Mvvm.ToolKit.ViewModelBase |
16 |
{ |
17 |
PemssService.PemssServiceClient pemssServiceClient; |
18 |
|
19 |
private System.Collections.ObjectModel.ObservableCollection<Requirement> requirementList; |
20 |
|
21 |
public ObservableCollection<Requirement> RequirementList |
22 |
{ |
23 |
get |
24 |
{ |
25 |
if (requirementList == null) |
26 |
{ |
27 |
requirementList = new ObservableCollection<Requirement>(); |
28 |
} |
29 |
|
30 |
return requirementList; |
31 |
} |
32 |
set |
33 |
{ |
34 |
if (requirementList != value) |
35 |
{ |
36 |
requirementList = value; |
37 |
OnPropertyChanged(() => RequirementList); |
38 |
} |
39 |
} |
40 |
} |
41 |
|
42 |
private Requirement selectRequirement; |
43 |
|
44 |
public Requirement SelectRequirement |
45 |
{ |
46 |
get |
47 |
{ |
48 |
return selectRequirement; |
49 |
} |
50 |
set |
51 |
{ |
52 |
if (selectRequirement != value) |
53 |
{ |
54 |
selectRequirement = value; |
55 |
OnPropertyChanged(() => SelectRequirement); |
56 |
} |
57 |
} |
58 |
} |
59 |
|
60 |
private VpCommant selectVPComment; |
61 |
|
62 |
public VpCommant SelectVPComment |
63 |
{ |
64 |
get |
65 |
{ |
66 |
return selectVPComment; |
67 |
} |
68 |
set |
69 |
{ |
70 |
if (selectVPComment != value) |
71 |
{ |
72 |
selectVPComment = value; |
73 |
OnPropertyChanged(() => SelectVPComment); |
74 |
} |
75 |
} |
76 |
} |
77 |
|
78 |
|
79 |
public AsyncCommand RefreshCommand => new AsyncCommand(()=> OnGetRequirementDataAsync()); |
80 |
|
81 |
public RelayCommand AddVPCommentCommand => new RelayCommand(x => OnAddVPCommentCommand(x)); |
82 |
|
83 |
public RelayCommand DelVPCommentCommand => new RelayCommand(x => OnDelVPCommentCommand(x)); |
84 |
|
85 |
public RelayCommand SelectedVPCommentCommand => new RelayCommand(x => OnSelectedVPCommentCommand(x)); |
86 |
|
87 |
|
88 |
#region 초기화 및 종료 이벤트 |
89 |
|
90 |
public RequirementViewModel() |
91 |
{ |
92 |
try |
93 |
{ |
94 |
if (pemssServiceClient == null) |
95 |
{ |
96 |
pemssServiceClient = new PemssServiceClient(App._binding, App._PemssEndPoint); |
97 |
} |
98 |
|
99 |
OnGetRequirementDataAsync().ConfigureAwait(false); |
100 |
} |
101 |
catch (Exception EX) |
102 |
{ |
103 |
|
104 |
throw; |
105 |
} |
106 |
} |
107 |
|
108 |
public override void Loaded() |
109 |
{ |
110 |
base.Loaded(); |
111 |
} |
112 |
|
113 |
public override void Closed() |
114 |
{ |
115 |
base.Closed(); |
116 |
} |
117 |
|
118 |
#endregion |
119 |
|
120 |
#region Command |
121 |
private async Task OnGetRequirementDataAsync() |
122 |
{ |
123 |
var result = await pemssServiceClient.GetrequirementListAsync(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID); |
124 |
|
125 |
requirementList.Clear(); |
126 |
result.ForEach(x => |
127 |
{ |
128 |
x.IsExpanded = true; |
129 |
x.IsExpandable = false; |
130 |
RequirementList.Add(x); |
131 |
}); |
132 |
} |
133 |
|
134 |
|
135 |
private void OnAddVPCommentCommand(object obj) |
136 |
{ |
137 |
if (obj == null) |
138 |
{ |
139 |
selectedComment = null; |
140 |
} |
141 |
else |
142 |
{ |
143 |
SelectRequirement = (obj as Telerik.Windows.Controls.GridView.GridViewRow).DataContext as Requirement; |
144 |
} |
145 |
|
146 |
if (SelectRequirement != null && SelectionSet.Instance.SelectedItems?.Count() > 0) |
147 |
{ |
148 |
Views.AddRequirement addRequirement = new Views.AddRequirement(); |
149 |
addRequirement.Header = "정합성 코멘트 연결 추가"; |
150 |
addRequirement.Width = 600; |
151 |
addRequirement.Header = 150; |
152 |
|
153 |
addRequirement.Closed += new EventHandler<WindowClosedEventArgs>(OnAddVpCommantWindowClosed); |
154 |
addRequirement.ShowDialogCenter(); |
155 |
|
156 |
|
157 |
//var parameters = new DialogParameters() |
158 |
//{ |
159 |
// ContentStyle = (Style)App.Current.Resources["AddVpCommantWindowStyle"], |
160 |
// Content = "마크업에 대한 코멘트 : ", |
161 |
// Closed = new EventHandler<WindowClosedEventArgs>(OnAddVpCommantWindowClosed), |
162 |
// Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault() |
163 |
//}; |
164 |
|
165 |
//RadWindow.Prompt(parameters); |
166 |
} |
167 |
else |
168 |
{ |
169 |
DialogParameters parameters = null; |
170 |
|
171 |
if (SelectRequirement == null) |
172 |
{ |
173 |
parameters = new DialogParameters() |
174 |
{ |
175 |
Content = "추가할 정합성을 선택해야 합니다.", |
176 |
Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault() |
177 |
}; |
178 |
} |
179 |
|
180 |
if (SelectionSet.Instance.SelectedItems == null || SelectionSet.Instance.SelectedItems.Count() == 0) |
181 |
{ |
182 |
parameters = new DialogParameters() |
183 |
{ |
184 |
Content = "선택된 마크업이 없습니다.", |
185 |
Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault() |
186 |
}; |
187 |
} |
188 |
|
189 |
RadWindow.Alert(parameters); |
190 |
} |
191 |
} |
192 |
|
193 |
private void OnDelVPCommentCommand(object obj) |
194 |
{ |
195 |
if(obj is Telerik.Windows.Controls.GridView.GridViewRow) |
196 |
{ |
197 |
selectedComment = (obj as Telerik.Windows.Controls.GridView.GridViewRow).DataContext as VpCommant; |
198 |
|
199 |
var parameters = new DialogParameters() |
200 |
{ |
201 |
Content = "해당 Comment를 삭제 하시겠습니까?", |
202 |
Closed = new EventHandler<WindowClosedEventArgs>(OnDelVPCommentWindowClosed), |
203 |
Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault(), |
204 |
|
205 |
}; |
206 |
|
207 |
RadWindow.Confirm(parameters); |
208 |
} |
209 |
} |
210 |
|
211 |
private void OnSelectedVPCommentCommand(object obj) |
212 |
{ |
213 |
if (SelectVPComment != null) |
214 |
{ |
215 |
var iditems = SelectVPComment.commentId.Split(','); |
216 |
|
217 |
var selectComments = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(x=>iditems.Count(y=> y == x.CommentID) > 0).ToList(); |
218 |
|
219 |
if (selectComments.Count() > 0) |
220 |
{ |
221 |
var infoList = Common.ViewerDataModel.Instance.MyMarkupList.Where(f => f.MarkupInfoID == selectComments.First().MarkupInfoID); |
222 |
|
223 |
if (infoList.Count() > 0) |
224 |
{ |
225 |
Common.ViewerDataModel.Instance.PageBalanceNumber = infoList.First().PageNumber; |
226 |
selectComments.First().IsSelected = true; |
227 |
GotoMarkup(selectComments); |
228 |
|
229 |
} |
230 |
} |
231 |
|
232 |
//selectedComment |
233 |
//SelectionSet.Instance.SelectControl = selectedComment; |
234 |
|
235 |
//if (instanceFavoVP.PAGE_NO == Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber) |
236 |
//{ |
237 |
// Common.ViewerDataModel.Instance.SystemMain.DialogMessage_Alert("You have selected the current page", "Notice"); |
238 |
//} |
239 |
//else |
240 |
//{ |
241 |
// Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.GotoPage(instanceFavoVP.PAGE_NO); |
242 |
//} |
243 |
} |
244 |
} |
245 |
|
246 |
private void GotoMarkup(IEnumerable<MarkupToPDF.Common.CommentUserInfo> commentUserInfo) |
247 |
{ |
248 |
if (commentUserInfo?.Count() > 0) |
249 |
{ |
250 |
var main = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu; |
251 |
|
252 |
try |
253 |
{ |
254 |
Rect rect = commentUserInfo.First().ItemRect; |
255 |
|
256 |
foreach (var instance in commentUserInfo) |
257 |
{ |
258 |
rect = Rect.Union(rect,instance.ItemRect); |
259 |
|
260 |
} |
261 |
|
262 |
SelectionSet.Instance.SelectItemByRect(rect, main); |
263 |
//rect.Scale(4, 4); |
264 |
|
265 |
main.zoomAndPanControl.ZoomTo(rect); |
266 |
// main.zoomAndPanControl.ZoomAboutPoint(main.zoomAndPanControl.ContentScale - 0.2, contentZoomCenter); |
267 |
} |
268 |
catch (Exception ex) |
269 |
{ |
270 |
main.DialogMessage_Alert(ex.Message, "Error"); |
271 |
} |
272 |
} |
273 |
} |
274 |
|
275 |
private void OnVpCommentSelectCommand(object x) |
276 |
{ |
277 |
throw new NotImplementedException(); |
278 |
} |
279 |
|
280 |
|
281 |
private VpCommant selectedComment; |
282 |
|
283 |
private async void OnDelVPCommentWindowClosed(object sender, WindowClosedEventArgs e) |
284 |
{ |
285 |
VpCommant deleteComment = selectedComment; |
286 |
selectedComment = null; |
287 |
|
288 |
if (e.DialogResult == true) |
289 |
{ |
290 |
try |
291 |
{ |
292 |
string projectNo = App.ViewInfo.ProjectNO; |
293 |
string docId = App.ViewInfo.DocumentItemID; |
294 |
string mdId = deleteComment.mdId; |
295 |
string userId = deleteComment.createdBy; |
296 |
string commentId = deleteComment.commentId; |
297 |
|
298 |
var result = await pemssServiceClient.RemoveRequirementCommentAsync(projectNo, docId, mdId, commentId, userId); |
299 |
|
300 |
} |
301 |
catch (Exception) |
302 |
{ |
303 |
//MessageBox.Show("삭제 오류"); |
304 |
} |
305 |
|
306 |
await OnGetRequirementDataAsync(); |
307 |
} |
308 |
} |
309 |
|
310 |
private async void OnAddVpCommantWindowClosed(object sender, WindowClosedEventArgs e) |
311 |
{ |
312 |
if(e.DialogResult == true) |
313 |
{ |
314 |
var addrequirement = sender as Views.AddRequirement; |
315 |
|
316 |
if(string.IsNullOrWhiteSpace(addrequirement.Comment)) |
317 |
{ |
318 |
var parameters = new DialogParameters() |
319 |
{ |
320 |
Content = "코멘트가 없습니다.", |
321 |
Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault() |
322 |
}; |
323 |
|
324 |
RadWindow.Alert(parameters); |
325 |
return; |
326 |
} |
327 |
|
328 |
string commentOnMarkup = addrequirement.Comment; |
329 |
|
330 |
string markupId = string.Join(",",SelectionSet.Instance.SelectedItems.Select(f => f.CommentID)); |
331 |
string projectNo = App.ViewInfo.ProjectNO; |
332 |
string docId = App.ViewInfo.DocumentItemID; |
333 |
string mdId = SelectRequirement.mdId; |
334 |
string userId = App.PEMSSInfo.UserID; |
335 |
|
336 |
bool condition = addrequirement.IsContition; |
337 |
|
338 |
var result = await pemssServiceClient.SetRequirementCommentAsync(projectNo,docId,mdId,markupId,commentOnMarkup,condition,userId); |
339 |
|
340 |
await OnGetRequirementDataAsync(); |
341 |
} |
342 |
} |
343 |
|
344 |
#endregion Command |
345 |
|
346 |
} |
347 |
} |