프로젝트

일반

사용자정보

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

markus / KCOM / ViewModel / RequirementViewModel.cs @ 0b75c341

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

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

    
92
        public RequirementViewModel()
93
        {
94
            try
95
            {
96
                if (pemssServiceClient == null)
97
                {
98
                    pemssServiceClient = new PemssServiceClient(App._binding, App._PemssEndPoint);
99
                }
100

    
101
                OnGetRequirementDataAsync().ConfigureAwait(false);
102
            }
103
            catch (Exception ex)
104
            {
105

    
106
                throw;
107
            }
108
        }
109

    
110
        public override void Loaded()
111
        {
112
            base.Loaded();
113
        }
114

    
115
        public override void Closed()
116
        {
117
            base.Closed();
118
        }
119

    
120
        #endregion
121

    
122
        #region Command
123
        private async Task OnGetRequirementDataAsync(bool IsInit = true)
124
        {
125
            var result = await pemssServiceClient.GetrequirementListAsync(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID);
126

    
127
            if (IsInit)
128
            {
129
                requirementList.Clear();
130
            }
131

    
132
            result.ForEach(newItem =>
133
            {
134
                newItem.IsExpanded = true;
135
                newItem.IsExpandable = false;
136

    
137
                if (IsInit)
138
                {
139
                    RequirementList.Add(newItem);
140
                }
141
                else
142
                {
143
                    RequirementList.UpdateWhere(changeitem => CollectionExtensions.ChangeValues(changeitem, newItem), x => x.mdId == newItem.mdId);
144
                }
145
            });
146
        }
147

    
148

    
149
        private void OnAddVPCommentCommand(object obj)
150
        {
151
            if (obj == null)
152
            {
153
                selectedComment = null;
154
            }
155
            else
156
            {
157
                SelectRequirement = (obj as Telerik.Windows.Controls.GridView.GridViewRow).DataContext as Requirement;
158
            }
159

    
160
            if (SelectRequirement != null && SelectionSet.Instance.SelectedItems?.Count() > 0)
161
            {
162
                Views.AddRequirement addRequirement = new Views.AddRequirement();
163
                addRequirement.Header = "정합성 코멘트 연결 추가";
164
                addRequirement.Width = 600;
165
                addRequirement.Header = 150;
166

    
167
                addRequirement.Closed += new EventHandler<WindowClosedEventArgs>(OnAddVpCommantWindowClosed);
168
                addRequirement.ShowDialogCenter();
169
                
170

    
171
                //var parameters = new DialogParameters()
172
                //{
173
                //    ContentStyle = (Style)App.Current.Resources["AddVpCommantWindowStyle"],
174
                //    Content = "마크업에 대한 코멘트 : ",
175
                //    Closed = new EventHandler<WindowClosedEventArgs>(OnAddVpCommantWindowClosed),
176
                //    Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault()
177
                //};
178

    
179
                //RadWindow.Prompt(parameters);
180
            }
181
            else
182
            {
183
                DialogParameters parameters = null;
184

    
185
                if (SelectRequirement == null)
186
                {
187
                    parameters = new DialogParameters()
188
                    {
189
                        Content = "추가할 정합성을 선택해야 합니다.",
190
                        Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault()
191
                    };
192
                }
193

    
194
                if (SelectionSet.Instance.SelectedItems == null || SelectionSet.Instance.SelectedItems.Count() == 0)
195
                {
196
                    parameters = new DialogParameters()
197
                    {
198
                        Content = "선택된 마크업이 없습니다.",
199
                        Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault()
200
                    };
201
                }
202

    
203
                RadWindow.Alert(parameters);
204
            }
205
        }
206

    
207
        private void OnDelVPCommentCommand(object obj)
208
        {
209
            if(obj is Telerik.Windows.Controls.GridView.GridViewRow)
210
            {
211
                selectedComment = (obj as Telerik.Windows.Controls.GridView.GridViewRow).DataContext as VpCommant;
212

    
213
                var parameters = new DialogParameters()
214
                {
215
                    Content = "해당 Comment를 삭제 하시겠습니까?",
216
                    Closed = new EventHandler<WindowClosedEventArgs>(OnDelVPCommentWindowClosed),
217
                    Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault(),
218
                   
219
                };
220

    
221
                RadWindow.Confirm(parameters);
222
            }
223
        }
224

    
225
        private void OnSelectedVPCommentCommand(object obj)
226
        {
227
            if (SelectVPComment != null)
228
            {
229
                var iditems = SelectVPComment.commentId.Split(',');
230

    
231
                var selectComments = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(x=>iditems.Count(y=> y == x.CommentID) > 0).ToList();
232

    
233
                if (selectComments.Count() > 0)
234
                {
235
                    var infoList = Common.ViewerDataModel.Instance.MyMarkupList.Where(f => f.MarkupInfoID == selectComments.First().MarkupInfoID);
236

    
237
                    if (infoList.Count() > 0)
238
                    {
239
                        Common.ViewerDataModel.Instance.PageBalanceNumber = infoList.First().PageNumber;
240
                        selectComments.First().IsSelected = true;
241
                        GotoMarkup(selectComments);
242

    
243
                    }
244
                }
245

    
246
                //selectedComment
247
                //SelectionSet.Instance.SelectControl  = selectedComment;
248

    
249
                //if (instanceFavoVP.PAGE_NO == Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber)
250
                //{
251
                //    Common.ViewerDataModel.Instance.SystemMain.DialogMessage_Alert("You have selected the current page", "Notice");
252
                //}
253
                //else
254
                //{
255
                //    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.GotoPage(instanceFavoVP.PAGE_NO);
256
                //}
257
            }
258
        }
259

    
260
        private void GotoMarkup(IEnumerable<MarkupToPDF.Common.CommentUserInfo> commentUserInfo)
261
        {
262
            if (commentUserInfo?.Count() > 0)
263
            {
264
                var main = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu;
265

    
266
                try
267
                {
268
                    Rect rect = commentUserInfo.First().ItemRect;
269

    
270
                    foreach (var instance in commentUserInfo)
271
                    {
272
                        rect = Rect.Union(rect,instance.ItemRect);
273

    
274
                    }
275
                      
276
                    SelectionSet.Instance.SelectItemByRect(rect, main);
277

    
278

    
279
                    //var matrix = new System.Windows.Media.Matrix();
280
                    ////var CenterPoint = VectorExtentions.Rotate(new Point(centerX, centerY), Common.ViewerDataModel.Instance.Angle,
281
                    //// new Point(Common.ViewerDataModel.Instance.ImageViewWidth / 2, Common.ViewerDataModel.Instance.ImageViewHeight / 2));
282

    
283
                    ////matrix.RotateAt(Common.ViewerDataModel.Instance.Angle, Common.ViewerDataModel.Instance.ImageViewWidth/2, Common.ViewerDataModel.Instance.ImageViewHeight/2);
284

    
285
                    //matrix.Rotate(Common.ViewerDataModel.Instance.Angle);
286
                    ////if (Math.Abs(Common.ViewerDataModel.Instance.Angle) == 90)
287
                    ////{
288
                    ////    matrix.Translate(Common.ViewerDataModel.Instance.ImageViewHeight, Common.ViewerDataModel.Instance.ImageViewWidth);
289
                    ////}
290

    
291
                    //rect.Transform(matrix);
292

    
293
                    main.zoomAndPanControl.ZoomTo(rect);
294

    
295
                    double centerX = rect.Left + rect.Width / 2;
296
                    double centerY = rect.Top + rect.Height / 2;
297

    
298
                    main.zoomAndPanControl.ZoomAboutPoint(main.zoomAndPanControl.ContentScale/3, new Point(centerX, centerY));
299
                }
300
                catch (Exception ex)
301
                {
302
                    main.DialogMessage_Alert(ex.Message, "Error");
303
                }
304
            }
305
        }
306

    
307
        private VpCommant selectedComment;
308

    
309
        private async void OnDelVPCommentWindowClosed(object sender, WindowClosedEventArgs e)
310
        {
311
            VpCommant deleteComment = selectedComment;
312
            selectedComment = null;
313

    
314
            if (e.DialogResult == true)
315
            {
316
                try
317
                {
318
                    string projectNo = App.ViewInfo.ProjectNO;
319
                    string docId = App.ViewInfo.DocumentItemID;
320
                    string mdId = deleteComment.mdId;
321
                    string userId = deleteComment.createdBy;
322
                    string commentId = deleteComment.commentId;
323

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

    
326
                }
327
                catch (Exception)
328
                {
329
                    //MessageBox.Show("삭제 오류");
330
                }
331

    
332
                await OnGetRequirementDataAsync(false);
333
            }
334
        }
335

    
336
        private async void OnAddVpCommantWindowClosed(object sender, WindowClosedEventArgs e)
337
        {
338
           if(e.DialogResult == true)
339
            {
340
                var addrequirement = sender as Views.AddRequirement;
341

    
342
                if(string.IsNullOrWhiteSpace(addrequirement.Comment))
343
                {
344
                    var parameters = new DialogParameters()
345
                    {
346
                        Content = "코멘트가 없습니다.",
347
                        Owner = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault()
348
                    };
349

    
350
                    RadWindow.Alert(parameters);
351
                    return;
352
                }
353

    
354
                string commentOnMarkup = addrequirement.Comment;
355

    
356
                string markupId = string.Join(",",SelectionSet.Instance.SelectedItems.Select(f => f.CommentID));
357
                string projectNo = App.ViewInfo.ProjectNO;
358
                string docId = App.ViewInfo.DocumentItemID;
359
                string mdId = SelectRequirement.mdId;
360
                string userId = App.PEMSSInfo.UserID;
361

    
362
                bool condition = addrequirement.IsContition;
363
         
364
                var result = await pemssServiceClient.SetRequirementCommentAsync(projectNo,docId,mdId,markupId,commentOnMarkup,condition,userId);
365

    
366
                await OnGetRequirementDataAsync(false);
367
            }
368
        }
369

    
370
        #endregion Command
371

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