프로젝트

일반

사용자정보

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

markus / KCOM / ViewModel / RequirementViewModel.cs @ df2e7646

이력 | 보기 | 이력해설 | 다운로드 (16.2 KB)

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