markus / KCOM / ViewModel / RequirementViewModel.cs @ c854511f
이력 | 보기 | 이력해설 | 다운로드 (17.3 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 |
#region UI에 대한 이벤트 |
79 |
|
80 |
public AsyncCommand RefreshCommand => new AsyncCommand(()=> OnGetRequirementDataAsync()); |
81 |
|
82 |
public RelayCommand AddVPCommentCommand => new RelayCommand(x => OnAddVPCommentCommand(x)); |
83 |
|
84 |
public RelayCommand DelVPCommentCommand => new RelayCommand(x => OnDelVPCommentCommand(x)); |
85 |
|
86 |
public RelayCommand SelectedVPCommentCommand => new RelayCommand(x => OnSelectedVPCommentCommand(x)); |
87 |
|
88 |
public RelayCommand RequirementSearchCommand => new RelayCommand(x => OnRequirementSearchCommand(x)); |
89 |
|
90 |
|
91 |
|
92 |
#endregion |
93 |
|
94 |
#region 초기화 및 종료 이벤트 |
95 |
|
96 |
public RequirementViewModel() |
97 |
{ |
98 |
if (App.IsDesignMode) |
99 |
return; |
100 |
|
101 |
try |
102 |
{ |
103 |
if (pemssServiceClient == null) |
104 |
{ |
105 |
pemssServiceClient = new PemssServiceClient(App._binding, App._PemssEndPoint); |
106 |
} |
107 |
|
108 |
OnGetRequirementDataAsync().ConfigureAwait(false); |
109 |
} |
110 |
catch (Exception ex) |
111 |
{ |
112 |
|
113 |
System.Diagnostics.Debug.WriteLine(ex); |
114 |
} |
115 |
} |
116 |
|
117 |
public override void Loaded() |
118 |
{ |
119 |
base.Loaded(); |
120 |
} |
121 |
|
122 |
public override void Closed() |
123 |
{ |
124 |
base.Closed(); |
125 |
} |
126 |
|
127 |
#endregion |
128 |
|
129 |
#region Command |
130 |
private async Task OnGetRequirementDataAsync(bool IsInit = true) |
131 |
{ |
132 |
var result = await pemssServiceClient.GetrequirementListAsync(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID); |
133 |
|
134 |
if (IsInit) |
135 |
{ |
136 |
requirementList.Clear(); |
137 |
|
138 |
if (!string.IsNullOrWhiteSpace(App.PEMSSInfo.CommentID)) |
139 |
{ |
140 |
Common.ViewerDataModel.Instance.OnLoadPaged += Instance_OnLoadPaged; |
141 |
} |
142 |
} |
143 |
|
144 |
result.ForEach(newItem => |
145 |
{ |
146 |
newItem.IsExpanded = true; |
147 |
newItem.IsExpandable = true; |
148 |
|
149 |
if (IsInit) |
150 |
{ |
151 |
RequirementList.Add(newItem); |
152 |
} |
153 |
else |
154 |
{ |
155 |
RequirementList.UpdateWhere(changeitem => CollectionExtensions.ChangeValues(changeitem, newItem), x => x.mdId == newItem.mdId); |
156 |
} |
157 |
}); |
158 |
|
159 |
IsInit = true; |
160 |
} |
161 |
private void Instance_OnLoadPaged(object sender, EventArgs e) |
162 |
{ |
163 |
var comment = RequirementList.SelectMany(x => x.VpComments).Where(y => y.commentId == App.PEMSSInfo.CommentID); |
164 |
|
165 |
if (comment.Count() > 0) |
166 |
{ |
167 |
GotoMarkup(new[] { App.PEMSSInfo.CommentID }); |
168 |
} |
169 |
|
170 |
Common.ViewerDataModel.Instance.OnLoadPaged -= Instance_OnLoadPaged; |
171 |
} |
172 |
|
173 |
private void OnAddVPCommentCommand(object obj) |
174 |
{ |
175 |
if (obj == null) |
176 |
{ |
177 |
selectedComment = null; |
178 |
} |
179 |
|
180 |
if (SelectRequirement != null && SelectionSet.Instance.SelectedItems?.Count() > 0) |
181 |
{ |
182 |
Views.AddRequirement addRequirement = new Views.AddRequirement(); |
183 |
addRequirement.Header = "정합성 코멘트 연결 추가"; |
184 |
addRequirement.Width = 600; |
185 |
addRequirement.Header = 150; |
186 |
|
187 |
addRequirement.Closed += new EventHandler<WindowClosedEventArgs>(OnAddVpCommantWindowClosed); |
188 |
addRequirement.ShowDialogCenter(); |
189 |
|
190 |
|
191 |
//var parameters = new DialogParameters() |
192 |
//{ |
193 |
// ContentStyle = (Style)App.Current.Resources["AddVpCommantWindowStyle"], |
194 |
// Content = "마크업에 대한 코멘트 : ", |
195 |
// Closed = new EventHandler<WindowClosedEventArgs>(OnAddVpCommantWindowClosed), |
196 |
// Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault() |
197 |
//}; |
198 |
|
199 |
//RadWindow.Prompt(parameters); |
200 |
} |
201 |
else |
202 |
{ |
203 |
DialogParameters parameters = null; |
204 |
|
205 |
if (SelectRequirement == null) |
206 |
{ |
207 |
parameters = new DialogParameters() |
208 |
{ |
209 |
Content = "추가할 정합성을 선택해야 합니다.", |
210 |
Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault() |
211 |
}; |
212 |
} |
213 |
|
214 |
if (SelectionSet.Instance.SelectedItems == null || SelectionSet.Instance.SelectedItems.Count() == 0) |
215 |
{ |
216 |
parameters = new DialogParameters() |
217 |
{ |
218 |
Content = "선택된 마크업이 없습니다.", |
219 |
Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault() |
220 |
}; |
221 |
} |
222 |
|
223 |
RadWindow.Alert(parameters); |
224 |
} |
225 |
} |
226 |
|
227 |
private void OnDelVPCommentCommand(object obj) |
228 |
{ |
229 |
if(obj is VpCommant) |
230 |
{ |
231 |
selectedComment = obj as VpCommant; |
232 |
|
233 |
var parameters = new DialogParameters() |
234 |
{ |
235 |
Content = "해당 Comment를 삭제 하시겠습니까?", |
236 |
Closed = new EventHandler<WindowClosedEventArgs>(OnDelVPCommentWindowClosed), |
237 |
Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault(), |
238 |
|
239 |
}; |
240 |
|
241 |
RadWindow.Confirm(parameters); |
242 |
} |
243 |
} |
244 |
|
245 |
private void OnSelectedVPCommentCommand(object obj) |
246 |
{ |
247 |
if (SelectVPComment != null) |
248 |
{ |
249 |
var iditems = SelectVPComment.commentId.Split(','); |
250 |
|
251 |
GotoMarkup(iditems); |
252 |
|
253 |
//selectedComment |
254 |
//SelectionSet.Instance.SelectControl = selectedComment; |
255 |
|
256 |
//if (instanceFavoVP.PAGE_NO == Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber) |
257 |
//{ |
258 |
// Common.ViewerDataModel.Instance.SystemMain.DialogMessage_Alert("You have selected the current page", "Notice"); |
259 |
//} |
260 |
//else |
261 |
//{ |
262 |
// Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.GotoPage(instanceFavoVP.PAGE_NO); |
263 |
//} |
264 |
} |
265 |
} |
266 |
|
267 |
private void OnRequirementSearchCommand(object obj) |
268 |
{ |
269 |
var searchView = new Views.RequirementSearchView(); |
270 |
RadWindow window = new RadWindow(); |
271 |
window.Header = "정합성 목록"; |
272 |
window.Content = searchView; |
273 |
window.Width = 1268; |
274 |
window.Height = 700; |
275 |
|
276 |
window.Closed += (snd, evt) => |
277 |
{ |
278 |
if(evt.DialogResult == true) |
279 |
{ |
280 |
if(!string.IsNullOrEmpty( evt.PromptResult)) |
281 |
{ |
282 |
SelectRequirement = RequirementList.Where(x => x.mdId == evt.PromptResult).First(); |
283 |
} |
284 |
} |
285 |
}; |
286 |
|
287 |
window.ShowDialogCenter(); |
288 |
|
289 |
} |
290 |
|
291 |
private void GotoMarkup(IEnumerable<string> CommentIdList) |
292 |
{ |
293 |
// Common.ViewerDataModel.Instance.SystemMain.dzMainMenu |
294 |
///Common.ViewerDataModel.Instance._markupInfoList |
295 |
//var gridMarkup = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.gridViewMarkup; |
296 |
|
297 |
//var markuplist = (gridMarkup.ItemsSource as IEnumerable<IKCOM.MarkupInfoItem>).SelectMany(x => x.MarkupList); |
298 |
var instance = Common.ViewerDataModel.Instance; |
299 |
|
300 |
var commentList = instance._markupInfoList.Where(x=>x.MarkupList != null).SelectMany(x => x.MarkupList).Where(f => f.ID == CommentIdList.First()); |
301 |
|
302 |
if (commentList.Count() > 0) |
303 |
{ |
304 |
//하단 그리드의 markup list에서 commentid가 포함된 markupinfo를 선택되게 한다. |
305 |
#region markup list grid select items |
306 |
|
307 |
var infoItem = instance._markupInfoList.Where(x => x.MarkupList != null).Where(f => f.MarkupList.Count(y => y == commentList.First()) > 0); |
308 |
|
309 |
if (infoItem.Count() > 0) |
310 |
{ |
311 |
var gridMarkup = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.gridViewMarkup; |
312 |
gridMarkup.SelectedItems.Add(infoItem.First()); |
313 |
} |
314 |
|
315 |
#endregion |
316 |
|
317 |
var pageNavigator = instance.SystemMain.dzMainMenu.pageNavigator; |
318 |
|
319 |
pageNavigator.GotoPage(commentList.First().PageNumber); |
320 |
|
321 |
pageNavigator.PageChanged += (snd, evt) => |
322 |
{ |
323 |
var selectOrderComments = instance.MarkupControls.Where(x => CommentIdList.Count(y => y == x.CommentID) > 0).ToList(); |
324 |
var selectMyComments = instance.MarkupControls_USER.Where(x => CommentIdList.Count(y => y == x.CommentID) > 0).ToList(); |
325 |
|
326 |
if (selectMyComments.Count() > 0 || selectOrderComments.Count() > 0) |
327 |
{ |
328 |
selectMyComments.ForEach(x => x.IsSelected = true); |
329 |
selectMyComments.AddRange(selectOrderComments); |
330 |
|
331 |
GotoMarkup(selectMyComments); |
332 |
} |
333 |
}; |
334 |
} |
335 |
} |
336 |
|
337 |
private void GotoMarkup(IEnumerable<MarkupToPDF.Common.CommentUserInfo> commentUserInfo) |
338 |
{ |
339 |
if (commentUserInfo?.Count() > 0) |
340 |
{ |
341 |
var main = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu; |
342 |
|
343 |
try |
344 |
{ |
345 |
Rect rect = commentUserInfo.First().ItemRect; |
346 |
|
347 |
foreach (var instance in commentUserInfo) |
348 |
{ |
349 |
rect = Rect.Union(rect, instance.ItemRect); |
350 |
|
351 |
} |
352 |
|
353 |
SelectionSet.Instance.SelectItemByRect(rect, main); |
354 |
|
355 |
|
356 |
//var matrix = new System.Windows.Media.Matrix(); |
357 |
////var CenterPoint = VectorExtentions.Rotate(new Point(centerX, centerY), Common.ViewerDataModel.Instance.Angle, |
358 |
//// new Point(Common.ViewerDataModel.Instance.ImageViewWidth / 2, Common.ViewerDataModel.Instance.ImageViewHeight / 2)); |
359 |
|
360 |
////matrix.RotateAt(Common.ViewerDataModel.Instance.Angle, Common.ViewerDataModel.Instance.ImageViewWidth/2, Common.ViewerDataModel.Instance.ImageViewHeight/2); |
361 |
|
362 |
//matrix.Rotate(Common.ViewerDataModel.Instance.Angle); |
363 |
////if (Math.Abs(Common.ViewerDataModel.Instance.Angle) == 90) |
364 |
////{ |
365 |
//// matrix.Translate(Common.ViewerDataModel.Instance.ImageViewHeight, Common.ViewerDataModel.Instance.ImageViewWidth); |
366 |
////} |
367 |
|
368 |
//rect.Transform(matrix); |
369 |
//if (Math.Abs(Common.ViewerDataModel.Instance.Angle) == 90) |
370 |
//{ |
371 |
// var matrix = new System.Windows.Media.Matrix(); |
372 |
// matrix.RotateAt(Common.ViewerDataModel.Instance.Angle, Common.ViewerDataModel.Instance.ImageViewWidth / 2, Common.ViewerDataModel.Instance.ImageViewHeight / 2); |
373 |
// rect.Transform(matrix); |
374 |
//} |
375 |
|
376 |
//double centerX = rect.Left + rect.Width / 2; |
377 |
//double centerY = rect.Top + rect.Height / 2; |
378 |
|
379 |
|
380 |
var center = new Vector(Common.ViewerDataModel.Instance.ImageViewWidth / 2, Common.ViewerDataModel.Instance.ImageViewHeight / 2); |
381 |
var matrix = MatrixHelper.Rotation(Common.ViewerDataModel.Instance.PageAngle, center); |
382 |
rect.Transform(matrix); |
383 |
|
384 |
double scaleX = Common.ViewerDataModel.Instance.ImageViewWidth / rect.Width; |
385 |
double scaleY = Common.ViewerDataModel.Instance.ImageViewHeight / rect.Height; |
386 |
double newScale = main.zoomAndPanControl.ContentScale * Math.Min(scaleX, scaleY); |
387 |
double positionX = 0; |
388 |
double positionY = 0; |
389 |
|
390 |
if (Common.ViewerDataModel.Instance.PageAngle == 90) |
391 |
{ |
392 |
positionX = Common.ViewerDataModel.Instance.ImageViewHeight - rect.X; |
393 |
positionY = Common.ViewerDataModel.Instance.ImageViewWidth - rect.Y; |
394 |
} |
395 |
|
396 |
main.zoomAndPanControl.ContentScale = newScale; |
397 |
main.zoomAndPanControl.ContentOffsetX = positionX; |
398 |
main.zoomAndPanControl.ContentOffsetY = positionY; |
399 |
|
400 |
main.zoomAndPanControl.ZoomTo(rect); |
401 |
|
402 |
|
403 |
//double centerX = rect.Left + rect.Width / 2; |
404 |
//double centerY = rect.Top + rect.Height / 2; |
405 |
|
406 |
//main.zoomAndPanControl.ZoomAboutPoint(main.zoomAndPanControl.ContentScale, new Point(centerX, centerY)); |
407 |
} |
408 |
catch (Exception ex) |
409 |
{ |
410 |
main.DialogMessage_Alert(ex.Message, "Error"); |
411 |
} |
412 |
} |
413 |
} |
414 |
|
415 |
private VpCommant selectedComment; |
416 |
|
417 |
private async void OnDelVPCommentWindowClosed(object sender, WindowClosedEventArgs e) |
418 |
{ |
419 |
VpCommant deleteComment = selectedComment; |
420 |
selectedComment = null; |
421 |
|
422 |
if (e.DialogResult == true) |
423 |
{ |
424 |
try |
425 |
{ |
426 |
string projectNo = App.ViewInfo.ProjectNO; |
427 |
string docId = App.ViewInfo.DocumentItemID; |
428 |
string mdId = SelectRequirement.mdId; |
429 |
string userId = deleteComment.createdBy; |
430 |
string commentId = deleteComment.commentId; |
431 |
|
432 |
var result = await pemssServiceClient.RemoveRequirementCommentAsync(projectNo, docId, mdId, commentId, userId); |
433 |
|
434 |
} |
435 |
catch (Exception) |
436 |
{ |
437 |
//MessageBox.Show("삭제 오류"); |
438 |
} |
439 |
|
440 |
await OnGetRequirementDataAsync(false); |
441 |
} |
442 |
} |
443 |
|
444 |
private async void OnAddVpCommantWindowClosed(object sender, WindowClosedEventArgs e) |
445 |
{ |
446 |
if(e.DialogResult == true) |
447 |
{ |
448 |
var addrequirement = sender as Views.AddRequirement; |
449 |
|
450 |
if(string.IsNullOrWhiteSpace(addrequirement.Comment)) |
451 |
{ |
452 |
var parameters = new DialogParameters() |
453 |
{ |
454 |
Content = "코멘트가 없습니다.", |
455 |
Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault() |
456 |
}; |
457 |
|
458 |
RadWindow.Alert(parameters); |
459 |
return; |
460 |
} |
461 |
|
462 |
string commentOnMarkup = addrequirement.Comment; |
463 |
|
464 |
string markupId = string.Join(",",SelectionSet.Instance.SelectedItems.Select(f => f.CommentID)); |
465 |
string projectNo = App.ViewInfo.ProjectNO; |
466 |
string docId = App.ViewInfo.DocumentItemID; |
467 |
string mdId = SelectRequirement.mdId; |
468 |
string userId = App.PEMSSInfo.UserID; |
469 |
|
470 |
bool condition = addrequirement.IsContition; |
471 |
|
472 |
var result = await pemssServiceClient.SetRequirementCommentAsync(projectNo,docId,mdId,markupId,commentOnMarkup,condition,userId); |
473 |
|
474 |
await OnGetRequirementDataAsync(false); |
475 |
} |
476 |
} |
477 |
|
478 |
#endregion Command |
479 |
|
480 |
} |
481 |
} |