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