프로젝트

일반

사용자정보

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

markus / KCOM / ViewModel / RequirementViewModel.cs @ df2e7646

이력 | 보기 | 이력해설 | 다운로드 (16.2 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
             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
        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
                    Rect rect = commentUserInfo.First().ItemRect;
323

    
324
                    foreach (var instance in commentUserInfo)
325
                    {
326
                        rect = Rect.Union(rect, instance.ItemRect);
327

    
328
                    }
329

    
330
                    SelectionSet.Instance.SelectItemByRect(rect, main);
331

    
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
                    //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

    
377
                    main.zoomAndPanControl.ZoomTo(rect);
378

    
379

    
380
                    //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
                }
385
                catch (Exception ex)
386
                {
387
                    main.DialogMessage_Alert(ex.Message, "Error");
388
                }
389
            }
390
        }
391

    
392
        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
                    //MessageBox.Show("삭제 오류");
415
                }
416

    
417
                await OnGetRequirementDataAsync(false);
418
            }
419
        }
420

    
421
        private async void OnAddVpCommantWindowClosed(object sender, WindowClosedEventArgs e)
422
        {
423
           if(e.DialogResult == true)
424
            {
425
                var addrequirement = sender as Views.AddRequirement;
426

    
427
                if(string.IsNullOrWhiteSpace(addrequirement.Comment))
428
                {
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
                string commentOnMarkup = addrequirement.Comment;
440

    
441
                string markupId = string.Join(",",SelectionSet.Instance.SelectedItems.Select(f => f.CommentID));
442
                string projectNo = App.ViewInfo.ProjectNO;
443
                string docId = App.ViewInfo.DocumentItemID;
444
                string mdId = SelectRequirement.mdId;
445
                string userId = App.PEMSSInfo.UserID;
446

    
447
                bool condition = addrequirement.IsContition;
448
         
449
                var result = await pemssServiceClient.SetRequirementCommentAsync(projectNo,docId,mdId,markupId,commentOnMarkup,condition,userId);
450

    
451
                await OnGetRequirementDataAsync(false);
452
            }
453
        }
454

    
455
        #endregion Command
456

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