프로젝트

일반

사용자정보

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

markus / KCOM / ViewModel / RequirementViewModel.cs @ b9df9ab0

이력 | 보기 | 이력해설 | 다운로드 (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 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
            else
180
            {
181
                SelectRequirement = (obj as Telerik.Windows.Controls.GridView.GridViewRow).DataContext as Requirement;
182
            }
183

    
184
            if (SelectRequirement != null && SelectionSet.Instance.SelectedItems?.Count() > 0)
185
            {
186
                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

    
195
                //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
            }
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
                if (SelectionSet.Instance.SelectedItems == null || SelectionSet.Instance.SelectedItems.Count() == 0)
219
                {
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
        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
                GotoMarkup(iditems);
256

    
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
        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
        private void GotoMarkup(IEnumerable<string> CommentIdList)
296
        {
297
            // Common.ViewerDataModel.Instance.SystemMain.dzMainMenu
298
            ///Common.ViewerDataModel.Instance._markupInfoList
299
            //var gridMarkup = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.gridViewMarkup;
300

    
301
            //var markuplist = (gridMarkup.ItemsSource as IEnumerable<IKCOM.MarkupInfoItem>).SelectMany(x => x.MarkupList);
302

    
303
            var infoList = Common.ViewerDataModel.Instance._markupInfoList.Where(x=>x.MarkupList != null).SelectMany(x => x.MarkupList).Where(f => f.ID == CommentIdList.First());
304

    
305
            if (infoList.Count() > 0)
306
            {
307
                var pageNavigator = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator;
308

    
309
                pageNavigator.GotoPage(infoList.First().PageNumber);
310

    
311
                pageNavigator.PageChanged += (snd, evt) =>
312
                {
313
                    var selectComments = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(x => CommentIdList.Count(y => y == x.CommentID) > 0).ToList();
314

    
315
                    if (selectComments.Count() > 0)
316
                    {
317
                        selectComments.ForEach(x => x.IsSelected = true);
318
                        GotoMarkup(selectComments);
319
                    }
320
                };
321
            }
322
        }
323

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

    
330
                try
331
                {
332
                    Rect rect = commentUserInfo.First().ItemRect;
333

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

    
338
                    }
339

    
340
                    SelectionSet.Instance.SelectItemByRect(rect, main);
341

    
342

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

    
347
                    ////matrix.RotateAt(Common.ViewerDataModel.Instance.Angle, Common.ViewerDataModel.Instance.ImageViewWidth/2, Common.ViewerDataModel.Instance.ImageViewHeight/2);
348

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

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

    
363
                    //double centerX = rect.Left + rect.Width / 2;
364
                    //double centerY = rect.Top + rect.Height / 2;
365

    
366

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

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

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

    
383
                    main.zoomAndPanControl.ContentScale = newScale;
384
                    main.zoomAndPanControl.ContentOffsetX = positionX;
385
                    main.zoomAndPanControl.ContentOffsetY = positionY;
386

    
387
                    main.zoomAndPanControl.ZoomTo(rect);
388

    
389

    
390
                    //double centerX = rect.Left + rect.Width / 2;
391
                    //double centerY = rect.Top + rect.Height / 2;
392

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

    
402
        private VpCommant selectedComment;
403

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

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

    
419
                    var result = await pemssServiceClient.RemoveRequirementCommentAsync(projectNo, docId, mdId, commentId, userId);
420

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

    
427
                await OnGetRequirementDataAsync(false);
428
            }
429
        }
430

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

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

    
445
                    RadWindow.Alert(parameters);
446
                    return;
447
                }
448

    
449
                string commentOnMarkup = addrequirement.Comment;
450

    
451
                string markupId = string.Join(",",SelectionSet.Instance.SelectedItems.Select(f => f.CommentID));
452
                string projectNo = App.ViewInfo.ProjectNO;
453
                string docId = App.ViewInfo.DocumentItemID;
454
                string mdId = SelectRequirement.mdId;
455
                string userId = App.PEMSSInfo.UserID;
456

    
457
                bool condition = addrequirement.IsContition;
458
         
459
                var result = await pemssServiceClient.SetRequirementCommentAsync(projectNo,docId,mdId,markupId,commentOnMarkup,condition,userId);
460

    
461
                await OnGetRequirementDataAsync(false);
462
            }
463
        }
464

    
465
        #endregion Command
466

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