markus / KCOM / ViewModel / BiddersViewModel.cs @ b35682c3
이력 | 보기 | 이력해설 | 다운로드 (15.9 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 BiddersViewModel : Markus.Mvvm.ToolKit.ViewModelBase |
16 |
{ |
17 |
PemssService.PemssServiceClient pemssServiceClient; |
18 |
|
19 |
private System.Collections.ObjectModel.ObservableCollection<Bidders> biddersList; |
20 |
|
21 |
public ObservableCollection<Bidders> BiddersList |
22 |
{ |
23 |
get |
24 |
{ |
25 |
if (biddersList == null) |
26 |
{ |
27 |
biddersList = new ObservableCollection<Bidders>(); |
28 |
} |
29 |
|
30 |
return biddersList; |
31 |
} |
32 |
set |
33 |
{ |
34 |
if (biddersList != value) |
35 |
{ |
36 |
biddersList = value; |
37 |
OnPropertyChanged(() => BiddersList); |
38 |
} |
39 |
} |
40 |
} |
41 |
|
42 |
private Bidders selectBidders; |
43 |
|
44 |
public Bidders SelectBidders |
45 |
{ |
46 |
get |
47 |
{ |
48 |
return selectBidders; |
49 |
} |
50 |
set |
51 |
{ |
52 |
if (selectBidders != value) |
53 |
{ |
54 |
selectBidders = value; |
55 |
OnPropertyChanged(() => SelectBidders); |
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 RelayCommand AddVPCommentCommand => new RelayCommand(x => OnAddVPCommentCommand(x)); |
81 |
|
82 |
public RelayCommand DelVPCommentCommand => new RelayCommand(x => OnDelVPCommentCommand(x)); |
83 |
|
84 |
public RelayCommand SelectedVPCommentCommand => new RelayCommand(x => OnSelectedVPCommentCommand(x)); |
85 |
|
86 |
public RelayCommand BiddersSearchCommand => new RelayCommand(x => OnBiddersSearchCommand(x)); |
87 |
|
88 |
|
89 |
#endregion |
90 |
|
91 |
#region 초기화 및 종료 이벤트 |
92 |
|
93 |
public BiddersViewModel() |
94 |
{ |
95 |
if (App.IsDesignMode) |
96 |
return; |
97 |
|
98 |
try |
99 |
{ |
100 |
if (pemssServiceClient == null) |
101 |
{ |
102 |
pemssServiceClient = new PemssServiceClient(App._binding, App._PemssEndPoint); |
103 |
} |
104 |
|
105 |
OnGetBiddersDataAsync().ConfigureAwait(false); |
106 |
} |
107 |
catch (Exception ex) |
108 |
{ |
109 |
System.Diagnostics.Debug.WriteLine(ex); |
110 |
} |
111 |
} |
112 |
|
113 |
public override void Loaded() |
114 |
{ |
115 |
base.Loaded(); |
116 |
} |
117 |
|
118 |
public override void Closed() |
119 |
{ |
120 |
base.Closed(); |
121 |
} |
122 |
|
123 |
#endregion |
124 |
|
125 |
#region Command |
126 |
private async Task OnGetBiddersDataAsync(bool IsInit = true) |
127 |
{ |
128 |
var result = await pemssServiceClient.GetBidderstListAsync(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID); |
129 |
|
130 |
if (IsInit) |
131 |
{ |
132 |
BiddersList.Clear(); |
133 |
|
134 |
if (!string.IsNullOrWhiteSpace(App.PEMSSInfo.CommentID)) |
135 |
{ |
136 |
Common.ViewerDataModel.Instance.OnLoadPaged += Instance_OnLoadPaged; |
137 |
} |
138 |
} |
139 |
|
140 |
result.ForEach(newItem => |
141 |
{ |
142 |
newItem.IsExpanded = true; |
143 |
newItem.IsExpandable = true; |
144 |
|
145 |
if (IsInit) |
146 |
{ |
147 |
BiddersList.Add(newItem); |
148 |
} |
149 |
else |
150 |
{ |
151 |
BiddersList.UpdateWhere(changeitem => CollectionExtensions.ChangeValues(changeitem, newItem), x => x.bdId == newItem.bdId); |
152 |
} |
153 |
}); |
154 |
|
155 |
IsInit = true; |
156 |
} |
157 |
private void Instance_OnLoadPaged(object sender, EventArgs e) |
158 |
{ |
159 |
var comment = BiddersList.SelectMany(x => x.VpComments).Where(y => y.commentId == App.PEMSSInfo.CommentID); |
160 |
|
161 |
if (comment.Count() > 0) |
162 |
{ |
163 |
GotoMarkup(new[] { App.PEMSSInfo.CommentID }); |
164 |
} |
165 |
|
166 |
Common.ViewerDataModel.Instance.OnLoadPaged -= Instance_OnLoadPaged; |
167 |
} |
168 |
|
169 |
private void OnAddVPCommentCommand(object obj) |
170 |
{ |
171 |
if (obj == null) |
172 |
{ |
173 |
selectedComment = null; |
174 |
} |
175 |
else |
176 |
{ |
177 |
SelectBidders = (obj as Telerik.Windows.Controls.GridView.GridViewRow).DataContext as Bidders; |
178 |
} |
179 |
|
180 |
if (SelectBidders != null && SelectionSet.Instance.SelectedItems?.Count() > 0) |
181 |
{ |
182 |
Views.AddRequirement addRequirement = new Views.AddRequirement(); |
183 |
addRequirement.Header = "Bidders 코멘트 연결 추가"; |
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 (SelectBidders == null) |
206 |
{ |
207 |
parameters = new DialogParameters() |
208 |
{ |
209 |
Content = "추가할 BIdders을 선택해야 합니다.", |
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 Telerik.Windows.Controls.GridView.GridViewRow) |
230 |
{ |
231 |
selectedComment = (obj as Telerik.Windows.Controls.GridView.GridViewRow).DataContext 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 |
private void OnBiddersSearchCommand(object obj) |
267 |
{ |
268 |
var searchView = new Views.BiddersSearchView(); |
269 |
RadWindow window = new RadWindow(); |
270 |
window.Header = "Bidders 목록"; |
271 |
window.Content = searchView; |
272 |
window.Width = 1268; |
273 |
window.Height = 700; |
274 |
|
275 |
window.Closed += (snd, evt) => |
276 |
{ |
277 |
if (evt.DialogResult == true) |
278 |
{ |
279 |
if (!string.IsNullOrEmpty(evt.PromptResult)) |
280 |
{ |
281 |
SelectBidders = BiddersList.Where(x => x.bdId == evt.PromptResult).First(); |
282 |
} |
283 |
} |
284 |
}; |
285 |
|
286 |
window.ShowDialogCenter(); |
287 |
} |
288 |
|
289 |
private void GotoMarkup(IEnumerable<string> CommentIdList) |
290 |
{ |
291 |
var selectComments = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(x=> CommentIdList.Count(y=> y == x.CommentID) > 0).ToList(); |
292 |
|
293 |
if (selectComments.Count() > 0) |
294 |
{ |
295 |
var infoList = Common.ViewerDataModel.Instance.MyMarkupList.Where(f => f.MarkupInfoID == selectComments.First().MarkupInfoID); |
296 |
|
297 |
if (infoList.Count() > 0) |
298 |
{ |
299 |
Common.ViewerDataModel.Instance.PageBalanceNumber = infoList.First().PageNumber; |
300 |
selectComments.First().IsSelected = true; |
301 |
GotoMarkup(selectComments); |
302 |
|
303 |
selectComments.First().IsSelected =false; |
304 |
} |
305 |
} |
306 |
} |
307 |
|
308 |
private void GotoMarkup(IEnumerable<MarkupToPDF.Common.CommentUserInfo> commentUserInfo) |
309 |
{ |
310 |
if (commentUserInfo?.Count() > 0) |
311 |
{ |
312 |
var main = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu; |
313 |
|
314 |
try |
315 |
{ |
316 |
Rect rect = commentUserInfo.First().ItemRect; |
317 |
|
318 |
foreach (var instance in commentUserInfo) |
319 |
{ |
320 |
rect = Rect.Union(rect, instance.ItemRect); |
321 |
|
322 |
} |
323 |
|
324 |
SelectionSet.Instance.SelectItemByRect(rect, main); |
325 |
|
326 |
|
327 |
//var matrix = new System.Windows.Media.Matrix(); |
328 |
////var CenterPoint = VectorExtentions.Rotate(new Point(centerX, centerY), Common.ViewerDataModel.Instance.Angle, |
329 |
//// new Point(Common.ViewerDataModel.Instance.ImageViewWidth / 2, Common.ViewerDataModel.Instance.ImageViewHeight / 2)); |
330 |
|
331 |
////matrix.RotateAt(Common.ViewerDataModel.Instance.Angle, Common.ViewerDataModel.Instance.ImageViewWidth/2, Common.ViewerDataModel.Instance.ImageViewHeight/2); |
332 |
|
333 |
//matrix.Rotate(Common.ViewerDataModel.Instance.Angle); |
334 |
////if (Math.Abs(Common.ViewerDataModel.Instance.Angle) == 90) |
335 |
////{ |
336 |
//// matrix.Translate(Common.ViewerDataModel.Instance.ImageViewHeight, Common.ViewerDataModel.Instance.ImageViewWidth); |
337 |
////} |
338 |
|
339 |
//rect.Transform(matrix); |
340 |
//if (Math.Abs(Common.ViewerDataModel.Instance.Angle) == 90) |
341 |
//{ |
342 |
// var matrix = new System.Windows.Media.Matrix(); |
343 |
// matrix.RotateAt(Common.ViewerDataModel.Instance.Angle, Common.ViewerDataModel.Instance.ImageViewWidth / 2, Common.ViewerDataModel.Instance.ImageViewHeight / 2); |
344 |
// rect.Transform(matrix); |
345 |
//} |
346 |
|
347 |
//double centerX = rect.Left + rect.Width / 2; |
348 |
//double centerY = rect.Top + rect.Height / 2; |
349 |
|
350 |
|
351 |
var center = new Vector(Common.ViewerDataModel.Instance.ImageViewWidth / 2, Common.ViewerDataModel.Instance.ImageViewHeight / 2); |
352 |
var matrix = MatrixHelper.Rotation(Common.ViewerDataModel.Instance.PageAngle, center); |
353 |
rect.Transform(matrix); |
354 |
|
355 |
double scaleX = Common.ViewerDataModel.Instance.ImageViewWidth / rect.Width; |
356 |
double scaleY = Common.ViewerDataModel.Instance.ImageViewHeight / rect.Height; |
357 |
double newScale = main.zoomAndPanControl.ContentScale * Math.Min(scaleX, scaleY); |
358 |
double positionX = 0; |
359 |
double positionY = 0; |
360 |
|
361 |
if (Common.ViewerDataModel.Instance.PageAngle == 90) |
362 |
{ |
363 |
positionX = Common.ViewerDataModel.Instance.ImageViewHeight - rect.X; |
364 |
positionY = Common.ViewerDataModel.Instance.ImageViewWidth - rect.Y; |
365 |
} |
366 |
|
367 |
main.zoomAndPanControl.ContentScale = newScale; |
368 |
main.zoomAndPanControl.ContentOffsetX = positionX; |
369 |
main.zoomAndPanControl.ContentOffsetY = positionY; |
370 |
|
371 |
main.zoomAndPanControl.ZoomTo(rect); |
372 |
|
373 |
|
374 |
//double centerX = rect.Left + rect.Width / 2; |
375 |
//double centerY = rect.Top + rect.Height / 2; |
376 |
|
377 |
//main.zoomAndPanControl.ZoomAboutPoint(main.zoomAndPanControl.ContentScale, new Point(centerX, centerY)); |
378 |
} |
379 |
catch (Exception ex) |
380 |
{ |
381 |
main.DialogMessage_Alert(ex.Message, "Error"); |
382 |
} |
383 |
} |
384 |
} |
385 |
|
386 |
private VpCommant selectedComment; |
387 |
|
388 |
private async void OnDelVPCommentWindowClosed(object sender, WindowClosedEventArgs e) |
389 |
{ |
390 |
VpCommant deleteComment = selectedComment; |
391 |
selectedComment = null; |
392 |
|
393 |
if (e.DialogResult == true) |
394 |
{ |
395 |
try |
396 |
{ |
397 |
string projectNo = App.ViewInfo.ProjectNO; |
398 |
string docId = App.ViewInfo.DocumentItemID; |
399 |
string mdId = SelectBidders.bdId; |
400 |
string userId = deleteComment.createdBy; |
401 |
string commentId = deleteComment.commentId; |
402 |
|
403 |
var result = await pemssServiceClient.RemoveBiddersCommentAsync(projectNo, docId, mdId, commentId, userId); |
404 |
|
405 |
} |
406 |
catch (Exception) |
407 |
{ |
408 |
//MessageBox.Show("삭제 오류"); |
409 |
} |
410 |
|
411 |
await OnGetBiddersDataAsync(false); |
412 |
} |
413 |
} |
414 |
|
415 |
private async void OnAddVpCommantWindowClosed(object sender, WindowClosedEventArgs e) |
416 |
{ |
417 |
if(e.DialogResult == true) |
418 |
{ |
419 |
var addrequirement = sender as Views.AddRequirement; |
420 |
|
421 |
if(string.IsNullOrWhiteSpace(addrequirement.Comment)) |
422 |
{ |
423 |
var parameters = new DialogParameters() |
424 |
{ |
425 |
Content = "코멘트가 없습니다.", |
426 |
Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault() |
427 |
}; |
428 |
|
429 |
RadWindow.Alert(parameters); |
430 |
return; |
431 |
} |
432 |
|
433 |
string commentOnMarkup = addrequirement.Comment; |
434 |
|
435 |
string markupId = string.Join(",",SelectionSet.Instance.SelectedItems.Select(f => f.CommentID)); |
436 |
string projectNo = App.ViewInfo.ProjectNO; |
437 |
string docId = App.ViewInfo.DocumentItemID; |
438 |
string bdId = SelectBidders.bdId; |
439 |
string userId = App.PEMSSInfo.UserID; |
440 |
|
441 |
bool condition = addrequirement.IsContition; |
442 |
|
443 |
var result = await pemssServiceClient.SetBiddersCommentAsync(projectNo,docId, bdId, markupId,commentOnMarkup,condition,userId); |
444 |
|
445 |
await OnGetBiddersDataAsync(false); |
446 |
} |
447 |
} |
448 |
|
449 |
#endregion Command |
450 |
|
451 |
} |
452 |
} |