프로젝트

일반

사용자정보

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

markus / KCOM / ViewModel / RequirementViewModel.cs @ b10671a4

이력 | 보기 | 이력해설 | 다운로드 (15.3 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
        #endregion
89

    
90
        #region 초기화 및 종료 이벤트
91

    
92
        public RequirementViewModel()
93
        {
94
            if (App.IsDesignMode)
95
                return;
96

    
97
            try
98
            {
99
                if (pemssServiceClient == null)
100
                {
101
                    pemssServiceClient = new PemssServiceClient(App._binding, App._PemssEndPoint);
102
                }
103

    
104
                OnGetRequirementDataAsync().ConfigureAwait(false);
105
            }
106
            catch (Exception ex)
107
            {
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 OnGetRequirementDataAsync(bool IsInit = true)
127
        {
128
            var result = await pemssServiceClient.GetrequirementListAsync(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID);
129

    
130
            if (IsInit)
131
            {
132
                requirementList.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
                    RequirementList.Add(newItem);
148
                }
149
                else
150
                {
151
                    RequirementList.UpdateWhere(changeitem => CollectionExtensions.ChangeValues(changeitem, newItem), x => x.mdId == newItem.mdId);
152
                }
153
            });
154

    
155
            IsInit = true;
156
        }
157
        private void Instance_OnLoadPaged(object sender, EventArgs e)
158
        {
159
            var comment = RequirementList.SelectMany(x => x.VpComments).Where(y => y.commentId == App.PEMSSInfo.CommentID);
160

    
161
            if (comment.Count() > 0)
162
            {
163
                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
            else
176
            {
177
                SelectRequirement = (obj as Telerik.Windows.Controls.GridView.GridViewRow).DataContext as Requirement;
178
            }
179

    
180
            if (SelectRequirement != null && SelectionSet.Instance.SelectedItems?.Count() > 0)
181
            {
182
                Views.AddRequirement addRequirement = new Views.AddRequirement();
183
                addRequirement.Header = "정합성 코멘트 연결 추가";
184
                addRequirement.Width = 600;
185
                addRequirement.Header = 150;
186

    
187
                addRequirement.Closed += new EventHandler<WindowClosedEventArgs>(OnAddVpCommantWindowClosed);
188
                addRequirement.ShowDialogCenter();
189
                
190

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

    
199
                //RadWindow.Prompt(parameters);
200
            }
201
            else
202
            {
203
                DialogParameters parameters = null;
204

    
205
                if (SelectRequirement == null)
206
                {
207
                    parameters = new DialogParameters()
208
                    {
209
                        Content = "추가할 정합성을 선택해야 합니다.",
210
                        Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault()
211
                    };
212
                }
213

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

    
223
                RadWindow.Alert(parameters);
224
            }
225
        }
226

    
227
        private void OnDelVPCommentCommand(object obj)
228
        {
229
            if(obj is Telerik.Windows.Controls.GridView.GridViewRow)
230
            {
231
                selectedComment = (obj as Telerik.Windows.Controls.GridView.GridViewRow).DataContext as VpCommant;
232

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

    
241
                RadWindow.Confirm(parameters);
242
            }
243
        }
244

    
245
        private void OnSelectedVPCommentCommand(object obj)
246
        {
247
            if (SelectVPComment != null)
248
            {
249
                var iditems = SelectVPComment.commentId.Split(',');
250

    
251
                GotoMarkup(iditems);
252

    
253
                //selectedComment
254
                //SelectionSet.Instance.SelectControl  = selectedComment;
255

    
256
                //if (instanceFavoVP.PAGE_NO == Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber)
257
                //{
258
                //    Common.ViewerDataModel.Instance.SystemMain.DialogMessage_Alert("You have selected the current page", "Notice");
259
                //}
260
                //else
261
                //{
262
                //    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.GotoPage(instanceFavoVP.PAGE_NO);
263
                //}
264
            }
265
        }
266

    
267
        private void GotoMarkup(IEnumerable<string> CommentIdList)
268
        {
269
             var selectComments = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(x=> CommentIdList.Count(y=> y == x.CommentID) > 0).ToList();
270

    
271
                if (selectComments.Count() > 0)
272
                {
273
                    var infoList = Common.ViewerDataModel.Instance.MyMarkupList.Where(f => f.MarkupInfoID == selectComments.First().MarkupInfoID);
274

    
275
                    if (infoList.Count() > 0)
276
                    {
277
                        Common.ViewerDataModel.Instance.PageBalanceNumber = infoList.First().PageNumber;
278
                        selectComments.First().IsSelected = true;
279
                        GotoMarkup(selectComments);
280

    
281
                        selectComments.First().IsSelected =false;
282
                    }
283
                }
284
        }
285

    
286
        private void GotoMarkup(IEnumerable<MarkupToPDF.Common.CommentUserInfo> commentUserInfo)
287
        {
288
            if (commentUserInfo?.Count() > 0)
289
            {
290
                var main = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu;
291

    
292
                try
293
                {
294
                    Rect rect = commentUserInfo.First().ItemRect;
295

    
296
                    foreach (var instance in commentUserInfo)
297
                    {
298
                        rect = Rect.Union(rect, instance.ItemRect);
299

    
300
                    }
301

    
302
                    SelectionSet.Instance.SelectItemByRect(rect, main);
303

    
304

    
305
                    //var matrix = new System.Windows.Media.Matrix();
306
                    ////var CenterPoint = VectorExtentions.Rotate(new Point(centerX, centerY), Common.ViewerDataModel.Instance.Angle,
307
                    //// new Point(Common.ViewerDataModel.Instance.ImageViewWidth / 2, Common.ViewerDataModel.Instance.ImageViewHeight / 2));
308

    
309
                    ////matrix.RotateAt(Common.ViewerDataModel.Instance.Angle, Common.ViewerDataModel.Instance.ImageViewWidth/2, Common.ViewerDataModel.Instance.ImageViewHeight/2);
310

    
311
                    //matrix.Rotate(Common.ViewerDataModel.Instance.Angle);
312
                    ////if (Math.Abs(Common.ViewerDataModel.Instance.Angle) == 90)
313
                    ////{
314
                    ////    matrix.Translate(Common.ViewerDataModel.Instance.ImageViewHeight, Common.ViewerDataModel.Instance.ImageViewWidth);
315
                    ////}
316

    
317
                    //rect.Transform(matrix);
318
                    //if (Math.Abs(Common.ViewerDataModel.Instance.Angle) == 90)
319
                    //{ 
320
                    //    var matrix = new System.Windows.Media.Matrix();
321
                    //    matrix.RotateAt(Common.ViewerDataModel.Instance.Angle, Common.ViewerDataModel.Instance.ImageViewWidth / 2, Common.ViewerDataModel.Instance.ImageViewHeight / 2);
322
                    //    rect.Transform(matrix);
323
                    //}
324

    
325
                    //double centerX = rect.Left + rect.Width / 2;
326
                    //double centerY = rect.Top + rect.Height / 2;
327

    
328

    
329
                    var center = new Vector(Common.ViewerDataModel.Instance.ImageViewWidth / 2, Common.ViewerDataModel.Instance.ImageViewHeight / 2);
330
                    var matrix = MatrixHelper.Rotation(Common.ViewerDataModel.Instance.Angle, center);
331
                     rect.Transform(matrix);
332

    
333
                    double scaleX = Common.ViewerDataModel.Instance.ImageViewWidth / rect.Width;
334
                    double scaleY = Common.ViewerDataModel.Instance.ImageViewHeight / rect.Height;
335
                    double newScale = main.zoomAndPanControl.ContentScale * Math.Min(scaleX, scaleY);
336
                    double positionX = 0;
337
                    double positionY = 0;
338

    
339
                    if (Common.ViewerDataModel.Instance.Angle == 90)
340
                    {
341
                        positionX = Common.ViewerDataModel.Instance.ImageViewHeight - rect.X;
342
                        positionY = Common.ViewerDataModel.Instance.ImageViewWidth - rect.Y;
343
                    }
344

    
345
                    main.zoomAndPanControl.ContentScale = newScale;
346
                    main.zoomAndPanControl.ContentOffsetX = positionX;
347
                    main.zoomAndPanControl.ContentOffsetY = positionY;
348

    
349
                    main.zoomAndPanControl.ZoomTo(rect);
350

    
351

    
352
                    //double centerX = rect.Left + rect.Width / 2;
353
                    //double centerY = rect.Top + rect.Height / 2;
354

    
355
                    //main.zoomAndPanControl.ZoomAboutPoint(main.zoomAndPanControl.ContentScale, new Point(centerX, centerY));
356
                }
357
                catch (Exception ex)
358
                {
359
                    main.DialogMessage_Alert(ex.Message, "Error");
360
                }
361
            }
362
        }
363

    
364
        private VpCommant selectedComment;
365

    
366
        private async void OnDelVPCommentWindowClosed(object sender, WindowClosedEventArgs e)
367
        {
368
            VpCommant deleteComment = selectedComment;
369
            selectedComment = null;
370

    
371
            if (e.DialogResult == true)
372
            {
373
                try
374
                {
375
                    string projectNo = App.ViewInfo.ProjectNO;
376
                    string docId = App.ViewInfo.DocumentItemID;
377
                    string mdId = deleteComment.mdId;
378
                    string userId = deleteComment.createdBy;
379
                    string commentId = deleteComment.commentId;
380

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

    
383
                }
384
                catch (Exception)
385
                {
386
                    //MessageBox.Show("삭제 오류");
387
                }
388

    
389
                await OnGetRequirementDataAsync(false);
390
            }
391
        }
392

    
393
        private async void OnAddVpCommantWindowClosed(object sender, WindowClosedEventArgs e)
394
        {
395
           if(e.DialogResult == true)
396
            {
397
                var addrequirement = sender as Views.AddRequirement;
398

    
399
                if(string.IsNullOrWhiteSpace(addrequirement.Comment))
400
                {
401
                    var parameters = new DialogParameters()
402
                    {
403
                        Content = "코멘트가 없습니다.",
404
                        Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault()
405
                    };
406

    
407
                    RadWindow.Alert(parameters);
408
                    return;
409
                }
410

    
411
                string commentOnMarkup = addrequirement.Comment;
412

    
413
                string markupId = string.Join(",",SelectionSet.Instance.SelectedItems.Select(f => f.CommentID));
414
                string projectNo = App.ViewInfo.ProjectNO;
415
                string docId = App.ViewInfo.DocumentItemID;
416
                string mdId = SelectRequirement.mdId;
417
                string userId = App.PEMSSInfo.UserID;
418

    
419
                bool condition = addrequirement.IsContition;
420
         
421
                var result = await pemssServiceClient.SetRequirementCommentAsync(projectNo,docId,mdId,markupId,commentOnMarkup,condition,userId);
422

    
423
                await OnGetRequirementDataAsync(false);
424
            }
425
        }
426

    
427
        #endregion Command
428

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