프로젝트

일반

사용자정보

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

markus / KCOM / ViewModel / BiddersViewModel.cs @ 2e35dd78

이력 | 보기 | 이력해설 | 다운로드 (16.7 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
                MarkupHelper.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

    
176
            if (SelectBidders != null && SelectionSet.Instance.SelectedItems?.Count() > 0)
177
            {
178
                Views.AddRequirement addRequirement = new Views.AddRequirement();
179
                addRequirement.Header = "Bidders 코멘트 연결 추가";
180
                addRequirement.Width = 600;
181
                addRequirement.Header = 150;
182

    
183
                addRequirement.Closed += new EventHandler<WindowClosedEventArgs>(OnAddVpCommantWindowClosed);
184
                addRequirement.ShowDialogCenter();
185
                
186

    
187
                //var parameters = new DialogParameters()
188
                //{
189
                //    ContentStyle = (Style)App.Current.Resources["AddVpCommantWindowStyle"],
190
                //    Content = "마크업에 대한 코멘트 : ",
191
                //    Closed = new EventHandler<WindowClosedEventArgs>(OnAddVpCommantWindowClosed),
192
                //    Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault()
193
                //};
194

    
195
                //RadWindow.Prompt(parameters);
196
            }
197
            else
198
            {
199
                DialogParameters parameters = null;
200

    
201
                if (SelectBidders == null)
202
                {
203
                    parameters = new DialogParameters()
204
                    {
205
                        Content = "추가할 BIdders을 선택해야 합니다.",
206
                        Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault()
207
                    };
208
                }
209

    
210
                if (SelectionSet.Instance.SelectedItems == null || SelectionSet.Instance.SelectedItems.Count() == 0)
211
                {
212
                    parameters = new DialogParameters()
213
                    {
214
                        Content = "선택된 마크업이 없습니다.",
215
                        Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault()
216
                    };
217
                }
218

    
219
                RadWindow.Alert(parameters);
220
            }
221
        }
222

    
223
        private void OnDelVPCommentCommand(object obj)
224
        {
225
            if(obj is VpCommant)
226
            {
227
                selectedComment = obj as VpCommant;
228

    
229
                var parameters = new DialogParameters()
230
                {
231
                    Content = "해당 Comment를 삭제 하시겠습니까?",
232
                    Closed = new EventHandler<WindowClosedEventArgs>(OnDelVPCommentWindowClosed),
233
                    Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault(),
234
                   
235
                };
236

    
237
                RadWindow.Confirm(parameters);
238
            }
239
        }
240

    
241
        private void OnSelectedVPCommentCommand(object obj)
242
        {
243
            if (SelectVPComment != null)
244
            {
245
                var iditems = SelectVPComment.commentId.Split(',');
246

    
247
                MarkupHelper.GotoMarkup(iditems);
248

    
249
                //selectedComment
250
                //SelectionSet.Instance.SelectControl  = selectedComment;
251

    
252
                //if (instanceFavoVP.PAGE_NO == Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber)
253
                //{
254
                //    Common.ViewerDataModel.Instance.SystemMain.DialogMessage_Alert("You have selected the current page", "Notice");
255
                //}
256
                //else
257
                //{
258
                //    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.GotoPage(instanceFavoVP.PAGE_NO);
259
                //}
260
            }
261
        }
262
        private void OnBiddersSearchCommand(object obj)
263
        {
264
            var searchView = new Views.BiddersSearchView();
265
            RadWindow window = new RadWindow();
266
            window.Header = "Bidders 목록";
267
            window.Content = searchView;
268
            window.Width = 1268;
269
            window.Height = 700;
270

    
271
            window.Closed += (snd, evt) =>
272
            {
273
                if (evt.DialogResult == true)
274
                {
275
                    if (!string.IsNullOrEmpty(evt.PromptResult))
276
                    {
277
                        SelectBidders = BiddersList.Where(x => x.bdId == evt.PromptResult).First();
278
                    }
279
                }
280
            };
281

    
282
            window.ShowDialogCenter();
283
        }
284

    
285
        private void GotoMarkup(IEnumerable<string> CommentIdList)
286
        {
287
            var instance = Common.ViewerDataModel.Instance;
288

    
289
            var commentList = instance._markupInfoList.Where(x => x.MarkupList != null).SelectMany(x => x.MarkupList).Where(f => f.ID == CommentIdList.First());
290

    
291
            if (commentList.Count() > 0)
292
            {
293
                //하단 그리드의 markup list에서 commentid가 포함된 markupinfo를 선택되게 한다.
294
                #region markup list grid select items
295

    
296
                var infoItem = instance._markupInfoList.Where(x => x.MarkupList != null).Where(f => f.MarkupList.Count(y => y == commentList.First()) > 0);
297

    
298
                if (infoItem.Count() > 0)
299
                {
300
                    var gridMarkup = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.gridViewMarkup;
301
                    gridMarkup.SelectedItems.Add(infoItem.First());
302
                }
303

    
304
                #endregion
305

    
306
                var pageNavigator = instance.SystemMain.dzMainMenu.pageNavigator;
307

    
308
                pageNavigator.GotoPage(commentList.First().PageNumber);
309

    
310
                pageNavigator.PageChanged += (snd, evt) =>
311
                {
312
                    var selectOrderComments = instance.MarkupControls.Where(x => CommentIdList.Count(y => y == x.CommentID) > 0).ToList();
313
                    var selectMyComments = instance.MarkupControls_USER.Where(x => CommentIdList.Count(y => y == x.CommentID) > 0).ToList();
314

    
315
                    if (selectMyComments.Count() > 0 || selectOrderComments.Count() > 0)
316
                    {
317
                        selectMyComments.ForEach(x => x.IsSelected = true);
318
                        selectMyComments.AddRange(selectOrderComments);
319

    
320
                        GotoMarkup(selectMyComments);
321
                    }
322
                };
323
            }
324
        }
325

    
326
        private void GotoMarkup(IEnumerable<MarkupToPDF.Common.CommentUserInfo> commentUserInfo)
327
        {
328
            if (commentUserInfo?.Count() > 0)
329
            {
330
                var main = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu;
331

    
332
                try
333
                {
334
                    Rect rect = commentUserInfo.First().ItemRect;
335

    
336
                    foreach (var instance in commentUserInfo)
337
                    {
338
                        rect = Rect.Union(rect, instance.ItemRect);
339

    
340
                    }
341

    
342
                    SelectionSet.Instance.SelectItemByRect(rect, main);
343

    
344

    
345
                    //var matrix = new System.Windows.Media.Matrix();
346
                    ////var CenterPoint = VectorExtentions.Rotate(new Point(centerX, centerY), Common.ViewerDataModel.Instance.Angle,
347
                    //// new Point(Common.ViewerDataModel.Instance.ImageViewWidth / 2, Common.ViewerDataModel.Instance.ImageViewHeight / 2));
348

    
349
                    ////matrix.RotateAt(Common.ViewerDataModel.Instance.Angle, Common.ViewerDataModel.Instance.ImageViewWidth/2, Common.ViewerDataModel.Instance.ImageViewHeight/2);
350

    
351
                    //matrix.Rotate(Common.ViewerDataModel.Instance.Angle);
352
                    ////if (Math.Abs(Common.ViewerDataModel.Instance.Angle) == 90)
353
                    ////{
354
                    ////    matrix.Translate(Common.ViewerDataModel.Instance.ImageViewHeight, Common.ViewerDataModel.Instance.ImageViewWidth);
355
                    ////}
356

    
357
                    //rect.Transform(matrix);
358
                    //if (Math.Abs(Common.ViewerDataModel.Instance.Angle) == 90)
359
                    //{ 
360
                    //    var matrix = new System.Windows.Media.Matrix();
361
                    //    matrix.RotateAt(Common.ViewerDataModel.Instance.Angle, Common.ViewerDataModel.Instance.ImageViewWidth / 2, Common.ViewerDataModel.Instance.ImageViewHeight / 2);
362
                    //    rect.Transform(matrix);
363
                    //}
364

    
365
                    //double centerX = rect.Left + rect.Width / 2;
366
                    //double centerY = rect.Top + rect.Height / 2;
367

    
368

    
369
                    var center = new Vector(Common.ViewerDataModel.Instance.ImageViewWidth / 2, Common.ViewerDataModel.Instance.ImageViewHeight / 2);
370
                    var matrix = MatrixHelper.Rotation(Common.ViewerDataModel.Instance.PageAngle, center);
371
                     rect.Transform(matrix);
372

    
373
                    double scaleX = Common.ViewerDataModel.Instance.ImageViewWidth / rect.Width;
374
                    double scaleY = Common.ViewerDataModel.Instance.ImageViewHeight / rect.Height;
375
                    double newScale = main.zoomAndPanControl.ContentScale * Math.Min(scaleX, scaleY);
376
                    double positionX = 0;
377
                    double positionY = 0;
378

    
379
                    if (Common.ViewerDataModel.Instance.PageAngle == 90)
380
                    {
381
                        positionX = Common.ViewerDataModel.Instance.ImageViewHeight - rect.X;
382
                        positionY = Common.ViewerDataModel.Instance.ImageViewWidth - rect.Y;
383
                    }
384

    
385
                    main.zoomAndPanControl.ContentScale = newScale;
386
                    main.zoomAndPanControl.ContentOffsetX = positionX;
387
                    main.zoomAndPanControl.ContentOffsetY = positionY;
388

    
389
                    main.zoomAndPanControl.ZoomTo(rect);
390

    
391

    
392
                    //double centerX = rect.Left + rect.Width / 2;
393
                    //double centerY = rect.Top + rect.Height / 2;
394

    
395
                    //main.zoomAndPanControl.ZoomAboutPoint(main.zoomAndPanControl.ContentScale, new Point(centerX, centerY));
396
                }
397
                catch (Exception ex)
398
                {
399
                    main.DialogMessage_Alert(ex.Message, "Error");
400
                }
401
            }
402
        }
403

    
404
        private VpCommant selectedComment;
405

    
406
        private async void OnDelVPCommentWindowClosed(object sender, WindowClosedEventArgs e)
407
        {
408
            VpCommant deleteComment = selectedComment;
409
            selectedComment = null;
410

    
411
            if (e.DialogResult == true)
412
            {
413
                try
414
                {
415
                    string projectNo = App.ViewInfo.ProjectNO;
416
                    string docId = App.ViewInfo.DocumentItemID;
417
                    string mdId = SelectBidders.bdId;
418
                    string userId = deleteComment.createdBy;
419
                    string commentId = deleteComment.commentId;
420

    
421
                    var result = await pemssServiceClient.RemoveBiddersCommentAsync(projectNo, docId, mdId, commentId, userId);
422

    
423
                }
424
                catch (Exception)
425
                {
426
                    //MessageBox.Show("삭제 오류");
427
                }
428

    
429
                await OnGetBiddersDataAsync(false);
430
            }
431
        }
432

    
433
        private async void OnAddVpCommantWindowClosed(object sender, WindowClosedEventArgs e)
434
        {
435
           if(e.DialogResult == true)
436
            {
437
                var addrequirement = sender as Views.AddRequirement;
438

    
439
                if(string.IsNullOrWhiteSpace(addrequirement.Comment))
440
                {
441
                    var parameters = new DialogParameters()
442
                    {
443
                        Content = "코멘트가 없습니다.",
444
                        Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault()
445
                    };
446

    
447
                    RadWindow.Alert(parameters);
448
                    return;
449
                }
450

    
451
                string commentOnMarkup = addrequirement.Comment;
452

    
453
                string markupId = string.Join(",",SelectionSet.Instance.SelectedItems.Select(f => f.CommentID));
454
                string projectNo = App.ViewInfo.ProjectNO;
455
                string docId = App.ViewInfo.DocumentItemID;
456
                string bdId = SelectBidders.bdId;
457
                string userId = App.PEMSSInfo.UserID;
458

    
459
                bool condition = addrequirement.IsContition;
460
         
461
                var result = await pemssServiceClient.SetBiddersCommentAsync(projectNo,docId, bdId, markupId,commentOnMarkup,condition,userId);
462

    
463
                await OnGetBiddersDataAsync(false);
464
            }
465
        }
466

    
467
        #endregion Command
468

    
469
    }
470
}
클립보드 이미지 추가 (최대 크기: 500 MB)