프로젝트

일반

사용자정보

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

markus / KCOM / Services / BaseServices.cs @ a197bf6f

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

1
using Microsoft.AspNet.SignalR.Client;
2
using IKCOM;
3
using KCOM.Common;
4
using KCOM.ServiceDeepView;
5
using KCOMDataModel.DataModel;
6
using Newtonsoft.Json;
7
using System;
8
using System.Collections.Generic;
9
using System.Collections.ObjectModel;
10
using System.ComponentModel;
11
using System.Linq;
12
using System.Runtime.CompilerServices;
13
using System.Text;
14
using System.Windows;
15
using System.Windows.Controls;
16
using Telerik.Windows.Controls;
17
using MarkupToPDF.Controls.Parsing;
18
using Telerik.Windows.Data;
19
using System.Web;
20
using System.ServiceModel.Security;
21

    
22
namespace KCOM.Views
23
{
24
    public partial class MainMenu : UserControl, INotifyPropertyChanged
25
    {
26
        //const string DeepZoomUrl = @"http://{baseUrl}/TileSource/{TileSourcePath}/{ItemsPath}/{SharepointItemID}/{PageNo}.jpg";
27
        public ServiceDeepViewClient BaseClient;
28
        public KcomService.ServiceDeepViewClient BaseTaskClient
29
        {
30
            get {
31
                var service = new KcomService.ServiceDeepViewClient(App._binding, App._EndPoint);
32
                return service;
33
            }
34
        }
35

    
36
        public ViewInfo _ViewInfo;
37
        public DOCINFO _DocInfo;
38
        public DOCUMENT_ITEM _DocItem;
39
        public MEMBER userData;
40
        public List<int> MarkupSortList = new List<int>();
41

    
42
        public event PropertyChangedEventHandler PropertyChanged;
43
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
44
        {
45
            if (PropertyChanged != null)
46
            {
47
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
48
            }
49
        }
50

    
51
        private Common.DocumentSet _CurrentDoc { get; set; }
52
        public Common.DocumentSet CurrentDoc
53
        {
54
            get
55
            {
56
                return _CurrentDoc;
57
            }
58
            set
59
            {
60
                if (value != CurrentDoc)
61
                {
62
                    _CurrentDoc = value;
63
                    NotifyPropertyChanged();
64
                }
65
            }
66
        }
67
        public void ServiceOn()
68
        {
69
            //BaseTaskClient = new KcomService.ServiceDeepViewClient(App._binding, App._EndPoint);
70
            BaseClient = new ServiceDeepViewClient(App._binding, App._EndPoint);
71

    
72
            #region 이벤트 핸들러 등록
73
            BaseClient.GetDocInfoCompleted += BaseClient_GetDocInfoCompleted; //문서 섬네일, 페이지크기, 마크업 정보 [3]
74
            BaseClient.GetConversionStateCompleted += BaseClient_GetConversionStateCompleted;  //컨버팅의 여부 [2] 
75
            BaseClient.GetSystemDataCompleted += BaseClient_GetSystemDataCompleted; //시스템 정보 [1] 
76
            BaseClient.GetDocumentItemInfoCompleted += BaseClient_GetDocumentItemInfoCompleted; // 문서 자체의 정보 [4]
77
            BaseClient.GetMarkupInfoItemsCompleted += BaseClient_GetMarkupInfoItemsCompleted;
78
            BaseClient.GetDeptDataCompleted += BaseClient_GetDeptDataCompleted;
79
            BaseClient.DeleteMarkupCompleted += BaseClient_DeleteMarkupCompleted;
80
            BaseClient.GetVPRevisionHistoryCompleted += BaseClient_GetVPRevisionHistoryCompleted;
81
            BaseClient.SetFinalPDFCompleted += BaseClient_SetFinalPDFCompleted;
82
            BaseClient.GetCompareRectCompleted += BaseClient_GetCompareRectCompleted;
83
            BaseClient.DeleteMarkupCompleted += BaseClient_DeleteMarkupCompleted;
84
            BaseClient.DelFavoriteVPCompleted += BaseClient_DelFavoriteVPCompleted;
85
            BaseClient.EditFavoriteVPCompleted += BaseClient_EditFavoriteVPCompleted;
86

    
87
            BaseClient.SaveSymbolCompleted += BaseClient_SaveSymbolCompleted;
88
            BaseClient.AddPublicSymbolCompleted += BaseClient_AddPublicSymbolCompleted;
89
            #endregion
90
        }
91

    
92
        private void BaseClient_EditFavoriteVPCompleted(object sender, EditFavoriteVPCompletedEventArgs e)
93
        {
94
            //Logger.sendResLog("EditFavoriteVPCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
95
            
96
            if (e.Error == null && e.Result != false)
97
            {
98
                //Logger.sendReqLog("GetFavoriteVPAsync", App.ViewInfo.ProjectNO + "," + App.ViewInfo.UserID + "," + App.ViewInfo.DocumentItemID, 1);
99
                BaseClient.GetFavoriteVPAsync(App.ViewInfo.ProjectNO, App.ViewInfo.UserID, App.ViewInfo.DocumentItemID);
100
            }
101
            else
102
            {
103
                DialogMessage_Alert("Unable to delete the file due to a system failure", "Warning");
104
            }
105
        }
106

    
107
        private void BaseClient_DelFavoriteVPCompleted(object sender, DelFavoriteVPCompletedEventArgs e)
108
        {
109
            //Logger.sendResLog("DelFavoriteVPCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
110

    
111
            if (e.Error == null && e.Result != false)
112
            {
113
                //Logger.sendReqLog("GetFavoriteVPAsync", App.ViewInfo.ProjectNO + "," + App.ViewInfo.UserID + "," + App.ViewInfo.DocumentItemID, 1);
114
                BaseClient.GetFavoriteVPAsync(App.ViewInfo.ProjectNO, App.ViewInfo.UserID, App.ViewInfo.DocumentItemID);
115
            }
116
            else
117
            {
118
                DialogMessage_Alert("Unable to delete the file due to a system failure", "Warning");
119
            }
120
        }
121

    
122
        /// <summary>
123
        /// Compare 결과를 받아 화면에 표시한다
124
        /// </summary>
125
        /// <param name="sender"></param>
126
        /// <param name="e"></param>
127
        private void BaseClient_GetCompareRectCompleted(object sender, GetCompareRectCompletedEventArgs e)
128
        {
129
            if (e.Error != null || e.Result == null)
130
            {
131
                if (e.Error != null)
132
                {
133
                    DialogMessage_Alert(e.Error.ToString(), "Error");
134
                }
135
                else
136
                {
137
                    DialogMessage_Alert("Compare 기능을 원활히 실행하기 위한 데이터가 부족합니다", "안내");
138
                }
139
            }
140
            else
141
            {
142
                e.Result.ForEach(d =>
143
                {
144
                    d.Width = d.Width;
145
                    d.Height = d.Height;
146
                    var point = MarkupToPDF.Controls.Common.MathSet.getRectMiddlePoint(d);
147
                    System.Windows.Shapes.Rectangle myEllipse = new System.Windows.Shapes.Rectangle();
148
                    myEllipse.Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(150, 33, 215, 119));
149
                    myEllipse.Opacity = 1;
150
                    myEllipse.Width = d.Width;
151
                    myEllipse.Height = d.Height;
152
                    Canvas.SetLeft(myEllipse, d.X - ((point.X - d.X) / 2.0));
153
                    Canvas.SetTop(myEllipse, d.Y - ((point.Y - d.Y) / 2.0));
154
                    myEllipse.RenderTransformOrigin = point;
155
                    canvas_compareBorder.Children.Add(myEllipse);
156
                });
157
                canvas_compareBorder.Visibility = Visibility.Visible;
158
                da.From = 1;
159
                da.To = 0.5;
160
                da.Duration = new Duration(TimeSpan.FromSeconds(1));
161
                da.AutoReverse = true;
162
                canvas_compareBorder.BeginAnimation(OpacityProperty, da);
163
            }
164
        }
165

    
166
        /// <summary>
167
        /// FinalPDF를 수행 후 관련 메시지를 표시한다.
168
        /// </summary>
169
        /// <param name="sender"></param>
170
        /// <param name="e"></param>
171
        private void BaseClient_SetFinalPDFCompleted(object sender, SetFinalPDFCompletedEventArgs e)
172
        {
173
            if (e.Error != null || e.Result.Status == FinalStatus.Error)
174
            {
175
                string errormsg = CommonLib.Common.GetAlertMessageString("SetFinalPDFError", "MSG", $"최종 파일을 만드는데 문제가 발생하였습니다{System.Environment.NewLine}{e.Result.Exception}");
176
                DialogMessage_Alert(errormsg, "안내");
177
            }
178
            else
179
            {
180
                string successmsg = CommonLib.Common.GetAlertMessageString("SetFinalPDFSuccess", "MSG", "최종 파일 생성 중입니다. 문서관리시스템을 확인해주세요");
181
                DialogMessage_Alert(successmsg, "안내");
182
            }
183
        }
184

    
185
        private void BaseClient_GetVPRevisionHistoryCompleted(object sender, GetVPRevisionHistoryCompletedEventArgs e)
186
        {
187
            //Logger.sendResLog("GetVPRevisionHistoryCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.Count + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
188

    
189
            if (e.Result != null && e.Error == null)
190
            {
191
                List<VPRevision> list = e.Result;
192
                foreach (var item in list)
193
                {
194

    
195
                    if (App.isExternal)
196
                    {
197
                        var sBaseServiceURL = CommonLib.Common.GetConfigString("ExternalOriginalFileUrl", "URL", "", App.isExternal);
198

    
199
                        if (!string.IsNullOrWhiteSpace(item.TO_VENDOR))
200
                        {
201
                            var toUri = new Uri(HttpUtility.UrlDecode(item.TO_VENDOR));
202
                            item.TO_VENDOR = $"{sBaseServiceURL}{toUri.LocalPath}";
203
                        }
204

    
205
                        if (!string.IsNullOrWhiteSpace(item.FROM_VENDOR))
206
                        {
207
                            var fromUri = new Uri(HttpUtility.UrlDecode(item.FROM_VENDOR));
208
                            item.FROM_VENDOR = $"{sBaseServiceURL}{fromUri.LocalPath}";
209
                        }
210
                    }
211
                    else
212
                    {
213
                        item.TO_VENDOR = HttpUtility.UrlDecode(item.TO_VENDOR);
214
                        item.FROM_VENDOR = HttpUtility.UrlDecode(item.FROM_VENDOR);
215
                        item.EnsembleLink = HttpUtility.UrlDecode(item.EnsembleLink);
216
                    }
217
                }
218
                //int result;
219
                //bool iCheck = true;
220
                //foreach (var li in list)
221
                //{                    
222
                //    iCheck = int.TryParse(li.GroupNo, out result);
223
                //    if (!iCheck)
224
                //        break;
225
                //}
226
                //if(iCheck)
227
                    gridViewHistory.ItemsSource = list.OrderByDescending(x => x.GroupNo); //20240611 LJY string 인거 전달드림 slip no 내림차순으로 그냥 해달라고 요청
228
                //else
229
                //    gridViewHistory.ItemsSource = list.OrderByDescending(x => x.RevNo);
230

    
231
            }
232
            //TempFile.TempLoad();
233
        }
234

    
235
        private void BaseClient_DeleteMarkupCompleted(object sender, DeleteMarkupCompletedEventArgs e)
236
        {
237
            //Logger.sendResLog("DeleteMarkupCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
238

    
239
            foreach(var info in ViewerDataModel.Instance._markupInfoList)
240
            {
241
                if(info.UserID == App.ViewInfo.UserID)
242
                {
243
                    info.userDelete = true;
244
                    info.DisplayColor = "#FFFF0000";
245
                }
246
                else
247
                {
248
                    info.userDelete = false;
249
                }
250
            }
251
        }
252

    
253
        private void BaseClient_GetDeptDataCompleted(object sender, GetDeptDataCompletedEventArgs e)
254
        {
255
            if (e.Error == null)
256
            {
257
                //Logger.sendResLog("GetDeptDataCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.Count + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
258
            }
259
            else
260
            {
261
                //Logger.sendResLog("GetDeptDataCompleted",  "\r Error :" + e.Error, 1);
262
            }
263

    
264
            if (e.Result != null)
265
            {
266
                e.Result.Sort();
267
                //cbSymbolPublic.ItemsSource = e.Result.ToList();
268
            }
269
        }
270

    
271
        /// <summary>
272
        /// ???
273
        /// </summary>
274
        public MarkupInfoItem PreviewUserMarkupInfoItem { get; set; }
275

    
276
        /// <summary>
277
        /// 문서 정보를 가져온다
278
        /// </summary>
279
        /// <param name="sender"></param>
280
        /// <param name="e"></param>
281
        private async void BaseClient_GetDocInfoCompleted(object sender, GetDocInfoCompletedEventArgs e)
282
        {
283
            ////Logger.sendResLog("GetDocInfoCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
284

    
285
            if (e.Error != null)
286
            {
287
                DialogMessage_Alert("The page cannot be displayed.", "Alert");
288
            }
289
            else if (e.Result == null)
290
            {
291
                DialogMessage_Alert("Document information is missing.", "Alert");
292
            }
293
            else
294
            {
295
                string sFolder = _ViewInfo.DocumentItemID.All(char.IsDigit) ? (Convert.ToUInt64(_ViewInfo.DocumentItemID) / 100).ToString() : (_ViewInfo.DocumentItemID.Length >= 5 ? _ViewInfo.DocumentItemID.Substring(0, 5) : _ViewInfo.DocumentItemID);
296

    
297
                /// 화면의 좌측 Thumbnail의 주소
298
                var MainUrl = string.Format(CommonLib.Common.GetConfigString("mainServerImageWebPath", "URL", "", App.isExternal).Replace("png", "jpg"), _ViewInfo.ProjectNO, sFolder, _ViewInfo.DocumentItemID, "{PageNo}");
299
                _DocInfo = e.Result;
300
                _DocInfo.ORIGINAL_FILE = HttpUtility.UrlDecode(_DocInfo.ORIGINAL_FILE);
301
                foreach (var item in _DocInfo.DOCPAGE.OrderBy(order => order.PAGE_NUMBER))
302
                {
303
                    ViewerDataModel.Instance.Document_Info.Add(item);
304
                }
305
                //Logger.sendReqLog("GetMarkupInfoItemsAsync", _ViewInfo.ProjectNO + "," + _DocInfo.ID, 1);
306
                CurrentDoc = new Common.DocumentSet
307
                {
308
                    docInfo = _DocInfo,
309
                    Document_Id = _DocInfo.DOCUMENT_ID,
310
                    File_Original = _DocInfo.ORIGINAL_FILE,
311

    
312
                    Document_NO = _DocItem?.DOCUMENT_NO,
313
                    File_Result = _DocItem?.RESULT_FILE,
314
                    Group_No = _DocItem?.GROUP_NO,
315
                    ProjectNo = _DocItem?.PROJECT_NO,
316
                    Revision = _DocItem?.REVISION,
317
                };
318

    
319
                var instanceMain = this.ParentOfType<MainWindow>();
320
                string firstpage = "1";
321
                string lastpage = _DocInfo.PAGE_COUNT.ToString();
322
                instanceMain.dzTopMenu.tlcurrentPage.Text = firstpage;
323
                instanceMain.dzTopMenu.tlcurrentPage_readonly.Text = lastpage;
324
                App.MarkusVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
325

    
326
                string apptitle = string.Format("MARKUS(ver.{2}) - {0}(Rev.{1})", _DocItem?.DOCUMENT_NO, _DocItem?.REVISION, App.MarkusVersion);
327

    
328
                instanceMain.Title = apptitle;
329

    
330
                #region 페이지 이미지를 로컬에 저장
331
                string tempStoragePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "MARKUS", System.IO.Path.GetRandomFileName());
332

    
333
                //.Replace("jpg", "png")을 붙이는 이유는 MainUrl에 확장명이 jpg로 설정한 경우가 있기 때문
334

    
335
                #endregion
336

    
337
                App.PageStorage = new PageManager.PageStorage(MainUrl.Replace("jpg", "png"), tempStoragePath, "png", _DocInfo.PAGE_COUNT, 1);
338

    
339
                //App.SamplePageStorage = new PageManager.PageStorage(MainUrl.Replace("png", "jpg"), tempStoragePath, "jpg", _DocInfo.PAGE_COUNT);
340
                await this.pageNavigator.SetPageNaviAsync(CurrentDoc.docInfo.DOCPAGE.ToList(), MainUrl);
341
            }
342
        }
343

    
344
        private void pageNavigator_ThumbInitialized(object sender,EventArgs e)
345
        {
346
            BaseClient.GetMarkupInfoItemsAsync(_ViewInfo.ProjectNO, _DocInfo.ID);
347

    
348
            ViewerDataModel.Instance.MarkupControls_USER.Clear();
349
            //ViewerDataModel.Instance.SystemMain.dzMainMenu.TempLoad();
350

    
351
            /// 기존 임시파일 정리
352
            #region 단어 검색용 파일 다운로드
353

    
354
            DownloadOriginalFile();
355

    
356
            #endregion
357

    
358
            //Logger.sendReqLog("GetVPRevisionHistoryAsync", CurrentDoc.ProjectNo + "," + CurrentDoc.Document_NO + "," + CurrentDoc.Document_Id, 1);
359
            BaseClient.GetVPRevisionHistoryAsync(CurrentDoc.ProjectNo, CurrentDoc.Document_NO, CurrentDoc.Document_Id);
360

    
361
        }
362

    
363

    
364
        /// <summary>
365
        /// get markupinfo and markupitem from database
366
        ///  - 1. called when document is loaded
367
        ///  - 2. called when user do consolidation
368
        /// </summary>
369
        /// <param name="sender"></param>
370
        /// <param name="e"></param>
371
        private void BaseClient_GetMarkupInfoItemsCompleted(object sender, GetMarkupInfoItemsCompletedEventArgs e)
372
        {
373
            //Logger.sendResLog("GetMarkupInfoItemsCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.Count + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
374

    
375
            ViewerDataModel.Instance.MarkupControls_USER.Clear();
376
            ViewerDataModel.Instance.MarkupControls.Clear();
377

    
378
            try
379
            {
380

    
381
                if (e.Result != null)
382
                {
383
                    ViewerDataModel.Instance._markupInfoList.Clear();
384
                    if (e.Result.Any()) ViewerDataModel.Instance.MyMarkupList.Clear();
385

    
386
                    foreach (var info in e.Result)
387
                    {
388
                        if (info.Depatment == null) info.Depatment = "Unknown";
389

    
390
                        else if (info.UserID == App.ViewInfo.UserID)
391
                        {
392
                            if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission) //조회모드는 delete 버튼 모두 비활성화
393
                            {
394
                                info.userDelete = false;
395
                            }
396
                            else if (!App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission && e.Result.Where(x => x.UserID == App.ViewInfo.UserID && x.PartConsolidate == 1).Count() > 0) //Team Consolidation Mode이고 Team Consolidation Layer가 있을 경우
397
                            {
398
                                if(App.ViewInfo.NewCommentPermission && e.Result.Where(x => x.UserID == App.ViewInfo.UserID && x.PartConsolidate == 1 && x.MarkupInfoID == info.MarkupInfoID).Count() > 0)                                
399
                                    info.userDelete = true;                                
400
                            }
401
                            else if(App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission) //Consolidation Mode 일 때는 해당 Comment Layer의 Status가 Avoid or Consolidation인 것만 Delete 버튼 활성화
402
                            {
403
                                if(info.AvoidConsolidate == 1 || info.Consolidate == 1)
404
                                    info.userDelete = true;
405
                            }
406
                            else
407
                            {
408
                                info.userDelete = true;
409
                            }                               
410
                            info.DisplayColor = "#FFFF0000";
411
                        }
412
                        else
413
                        {
414
                            info.userDelete = false;
415
                        }
416

    
417
                        ViewerDataModel.Instance._markupInfoList.Add(info);
418
                    }
419

    
420
                    var userInfoList = ViewerDataModel.Instance._markupInfoList.GroupBy(f => f.UserID).Select(f => new MarkupUserInfo { UserId = f.Key, UserName = f.First().UserName });
421

    
422
                    userInfoList.ToList().ForEach(x =>
423
                    {
424
                        ViewerDataModel.Instance._markupUserList.Add(x);
425

    
426
                        if (MarkupToPDF.MarkupContext.GetUserSignItem(x.UserId) == null)
427
                        {
428
                            string signData = BaseClient.GetSignData(App.ViewInfo.ProjectNO, x.UserId);
429
                            string signStrokes = BaseClient.GetSignStrokes(App.ViewInfo.ProjectNO, x.UserId);
430

    
431
                            if (signData != null && signStrokes != null)
432
                            {
433
                                MarkupToPDF.MarkupContext.SetUserSignItem(x.UserId, signData, signStrokes);
434
                            }
435
                        }
436
                    });
437

    
438
                    e.Result.ToList().ForEach(d =>
439
                    {
440
                        if (d.MarkupList != null)
441
                        {
442
                            d.MarkupList.ForEach(p =>
443
                            {
444
                                if (d.UserID == App.ViewInfo.UserID)
445
                                {
446
                                    if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission) //조회모드는 delete 버튼 모두 비활성화
447
                                    {
448
                                        d.userDelete = false;
449
                                    }
450
                                    else if (!App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission && e.Result.Where(x => x.UserID == App.ViewInfo.UserID && x.PartConsolidate == 1).Count() > 0)//Team Consolidation Mode이고 Team Consolidation Layer가 있을 경우
451
                                    {
452
                                        if (App.ViewInfo.NewCommentPermission && e.Result.Where(x => x.UserID == App.ViewInfo.UserID && x.PartConsolidate == 1 && x.MarkupInfoID == d.MarkupInfoID).Count() > 0)
453
                                            d.userDelete = true;
454
                                    }
455
                                    else if (App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission) //Consolidation Mode 일 때는 해당 Comment Layer의 Status가 Avoid or Consolidation인 것만 Delete 버튼 활성화
456
                                    {
457
                                        if (d.AvoidConsolidate == 1 || d.Consolidate == 1)
458
                                            d.userDelete = true;
459
                                    }
460
                                    else
461
                                    {
462
                                        d.userDelete = true;
463
                                    }
464
                                    d.DisplayColor = "#FFFF0000";
465
                                    MarkupItemEx markup = new MarkupItemEx
466
                                    {
467
                                        Data = p.Data,
468
                                        Data_Type = p.Data_Type,
469
                                        ID = p.ID,
470
                                        IsUpdate = false,
471
                                        MarkupInfoID = d.MarkupInfoID,
472
                                        PageNumber = p.PageNumber,
473
                                        Symbol_ID = p.Symbol_ID,
474
                                        //Group_ID = p.Group_ID
475
                                    };
476
                                    ViewerDataModel.Instance.MyMarkupList.Add(markup);
477
                                }
478
                                else
479
                                {
480
                                    MarkupItemEx markup = new MarkupItemEx
481
                                    {
482
                                        Data = p.Data,
483
                                        Data_Type = p.Data_Type,
484
                                        ID = p.ID,
485
                                        IsUpdate = false,
486
                                        MarkupInfoID = d.MarkupInfoID,
487
                                        PageNumber = p.PageNumber,
488
                                        Symbol_ID = p.Symbol_ID,
489
                                        //Group_ID = p.Group_ID
490
                                    };
491
                                    ViewerDataModel.Instance.MarkupList_Pre.Add(markup);
492
                                }
493
                            });
494
                        }
495
                    });
496

    
497
                    var currentUser = e.Result.Find(data => data.UserID == App.ViewInfo.UserID && data.AvoidConsolidate == 0);
498
                    if (currentUser == null)
499
                    {
500
                        /// create a new markupinfo to do comments
501
                        if (App.ViewInfo.NewCommentPermission)
502
                        {
503
                            var infoId = Commons.ShortGuid();
504
                            PreviewUserMarkupInfoItem = new MarkupInfoItem
505
                            {
506
                                CreateTime = DateTime.Now,
507
                                UpdateTime = DateTime.Now,
508
                                Depatment = userData.DEPARTMENT,
509
                                DisplayColor = "#FFFF0000",
510
                                UserID = userData.ID,
511
                                UserName = userData.NAME,
512
                                PageCount = 1,
513
                                Description = "",
514
                                MarkupInfoID = infoId,
515
                                MarkupList = null,
516
                                MarkupVersionID = Commons.ShortGuid(),
517
                                Consolidate = 0,
518
                                PartConsolidate = 0,
519
                                userDelete = true,
520
                                AvoidConsolidate = 0,
521
                                IsPreviewUser = false
522
                            };
523

    
524
                            App.Custom_ViewInfoId = infoId;
525

    
526
                            ViewerDataModel.Instance._markupInfoList.Insert(0, PreviewUserMarkupInfoItem);
527
                        }
528
                    }
529
                    else
530
                    {
531
                        App.Custom_ViewInfoId = currentUser.MarkupInfoID;
532
                    }
533

    
534
                    ViewerDataModel.Instance.SyncPageNumber = 1;
535

    
536
                    /// Consolidation 된 데이터가 최상단에 올 수 있도록 변경
537
                    //var markupItem = ViewerDataModel.Instance._markupInfoList.OrderByDescending(p => p.Consolidate == Convert.ToInt32(true)).ToList();
538

    
539
                    gridViewMarkup.ItemsSource = ViewerDataModel.Instance._markupInfoList;
540

    
541
                    SetCommentPages(null);
542

    
543
                    // GRIDVIEW에서 팀별 GROUPING
544
                    // 효성은 안함
545
#if (Hyosung)
546
#else
547
                    /// create a group descriptor
548
                    gridViewMarkup.GroupDescriptors.Clear();
549
                    GroupDescriptor descriptor = new GroupDescriptor();
550
                    descriptor.Member = "Depatment";
551
                    descriptor.DisplayContent = "DEPT";
552
                    //descriptor.SortDirection = ListSortDirection.Ascending;
553
                    gridViewMarkup.GroupDescriptors.Add(descriptor);
554
#endif
555

    
556
                    GridViewMarkup_Sorting(gridViewMarkup, new GridViewSortingEventArgs(gridViewMarkup.Columns[0], SortingState.None, SortingState.None));
557

    
558
                    SelectInitialMarkupInfo();
559
                }
560
            }
561
            catch (Exception ex) 
562
            {
563
                App.FileLogger.Fatal(ex);
564
            }
565
            finally
566
            {
567
                if(!ViewerDataModel.Instance.SystemMain.dzMainMenu.btnFinalPDF.IsEnabled)
568
                {
569
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.btnFinalPDF.IsEnabled = true;
570
                }
571

    
572
                if (!ViewerDataModel.Instance.SystemMain.dzMainMenu.btnConsolidate.IsEnabled)
573
                {
574
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.btnConsolidate.IsEnabled = true;
575
                }
576
            }
577
        }
578

    
579
        /// <summary>
580
        /// 프로그램이 로딩되고 난 후 맨처음으로 MarkupInfo를 선택한다. 
581
        /// </summary>
582
        private void SelectInitialMarkupInfo()
583
        {
584
            if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission)
585
            {
586
                #region Consolidate 항목이 있으면 Consolidate 항목만 추가
587
                if (ViewerDataModel.Instance._markupInfoList.Any(x => x.Consolidate == 1 && x.AvoidConsolidate == 0))
588
                {
589
                    var Consolidates = ViewerDataModel.Instance._markupInfoList.Where(x => x.Consolidate == 1 && x.AvoidConsolidate == 0).ToList();
590
                    Consolidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
591
                }
592
                #endregion
593
                #region Consolidate 항목이 없을 경우에는 사용자 별로 AvoidConsolidate를 제외한 우선 순위가 높은(Team,Comment)항목들을 선택
594
                else
595
                {
596
                    var MarkupInfoColl = ViewerDataModel.Instance._markupInfoList.Where(x => x.AvoidConsolidate == 0).ToList();
597

    
598
                    #region Team consolidate 항목 선택
599
                    var Candidates = MarkupInfoColl.Where(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0).ToList();
600
                    MarkupInfoColl.RemoveAll(x => Candidates.Exists(y => y.UserID == x.UserID));
601
                    #endregion
602

    
603
                    #region 추가되지 않은 사용자들을 추가
604
                    foreach (var item in MarkupInfoColl.Where(x => !Candidates.Exists(y => y.UserID == x.UserID)))
605
                    {
606
                        Candidates.Add(item);
607
                    }
608
                    #endregion
609

    
610
                    Candidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
611
                }
612
                #endregion
613
            }
614
            else if (!App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission)   /// Eng'r Comment Mode
615
            {
616
                var MarkupInfoColl = ViewerDataModel.Instance._markupInfoList.Where(x => x.AvoidConsolidate == 0).ToList();
617

    
618
                #region Team consolidate 항목 선택
619
                var Candidates = MarkupInfoColl.Where(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0).ToList();
620
                MarkupInfoColl.RemoveAll(x => Candidates.Exists(y => y.UserID == x.UserID));
621
                #endregion
622

    
623
                #region 추가되지 않은 사용자들을 추가
624
                foreach (var item in MarkupInfoColl.Where(x => !Candidates.Exists(y => y.UserID == x.UserID)))
625
                {
626
                    Candidates.Add(item);
627
                }
628
                #endregion
629

    
630
                Candidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
631
            }
632
            else if (App.ViewInfo.CreateFinalPDFPermission)    /// Orig Comment Model
633
            {
634
                if (ViewerDataModel.Instance._markupInfoList.Any(x => x.Consolidate == 1 && x.AvoidConsolidate == 0))
635
                {
636
                    var Consolidates = ViewerDataModel.Instance._markupInfoList.Where(x => x.Consolidate == 1 && x.AvoidConsolidate == 0).ToList();
637
                    Consolidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
638
                }
639
                else if (ViewerDataModel.Instance._markupInfoList.Any(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0))
640
                {
641
                    var MarkupInfoColl = ViewerDataModel.Instance._markupInfoList.Where(x => x.AvoidConsolidate == 0).ToList();
642

    
643
                    #region Team consolidate 항목 선택
644
                    var Candidates = MarkupInfoColl.Where(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0).ToList();
645
                    MarkupInfoColl.RemoveAll(x => Candidates.Exists(y => y.UserID == x.UserID));
646
                    #endregion
647

    
648
                    #region 추가되지 않은 사용자들을 추가
649
                    foreach (var item in MarkupInfoColl.Where(x => !Candidates.Exists(y => y.UserID == x.UserID)))
650
                    {
651
                        Candidates.Add(item);
652
                    }
653
                    #endregion
654

    
655
                    Candidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
656
                }
657
                else
658
                {
659
                    var Comments = ViewerDataModel.Instance._markupInfoList.Where(x => x.Consolidate == 0 && x.AvoidConsolidate == 0).ToList();
660
                    Comments.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
661
                }
662
            }
663

    
664
            if (!gridViewMarkup.SelectedItems.Any())
665
            {
666
                var SelectedItem = ViewerDataModel.Instance._markupInfoList.Where(info => info.UserID == App.ViewInfo.UserID).OrderByDescending(order => order.UpdateTime).FirstOrDefault();
667

    
668
                if (PreviewUserMarkupInfoItem != null)
669
                {
670
                    this.gridViewMarkup.SelectedItem = PreviewUserMarkupInfoItem;
671
                }
672
                else if (SelectedItem != null)
673
                {
674
                    this.gridViewMarkup.SelectedItem = SelectedItem;
675
                }
676
                else if (ViewerDataModel.Instance._markupInfoList.Any())
677
                {
678
                    this.gridViewMarkup.SelectedItem = ViewerDataModel.Instance._markupInfoList[0];
679
                }
680
            }
681
        }
682

    
683
        private void GridViewMarkup_Sorting(object sender, GridViewSortingEventArgs e)
684
        {
685
            IEnumerable<IKCOM.MarkupInfoItem> markuplist = e.DataControl.ItemsSource as IEnumerable<IKCOM.MarkupInfoItem>;
686

    
687
            if(markuplist == null)
688
            {
689
                e.Cancel = true;
690
                return;
691
            }
692

    
693
            if(e.NewSortingState == SortingState.None)
694
            {
695
                markuplist = markuplist.OrderByDescending(x => SortIndex(x))
696
                                            .ThenBy(x => x.Depatment)
697
                                            .ThenBy(x => x.UserID);
698

    
699
                e.DataControl.ItemsSource = markuplist.ToList();
700
            }
701
        }
702

    
703

    
704
        // 마크업 리스트 정렬
705
        private int SortIndex(IKCOM.MarkupInfoItem markupInfoItem)
706
        {
707
            int result = 0;
708

    
709
            // Consolidate은 최상단
710
            if (markupInfoItem.Consolidate == 1)
711
            {
712
                result += 2;
713
            }
714

    
715
            /// Consolidate 다음으로 우선순위
716
            if (markupInfoItem.UserID == App.ViewInfo.UserID)
717
            {
718
                result += 1;
719
            }
720

    
721
            return result;
722
        }
723

    
724

    
725
        private void GridViewMarkup_Sorted(object sender, GridViewSortedEventArgs e)
726
        {
727

    
728
        }
729

    
730
        private async void gridViewRevMarkup_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
731
        {
732
            List<MarkupInfoItem> gridSelectionItem = gridViewRevMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
733
            //if (ViewerDataModel.Instance.PageBalanceNumber == 0)
734
            //{
735
            //    ViewerDataModel.Instance.PageBalanceNumber = 1;
736
            //}
737

    
738
            if (ViewerDataModel.Instance.SyncPageNumber == 0)
739
            {
740
                ViewerDataModel.Instance.SyncPageNumber = 1;
741
            }
742
            if (e.AddedItems.Any())
743
            {
744
                foreach (var item in gridSelectionItem)
745
                {
746
                    //item.MarkupList.Where(pageItem => pageItem.PageNumber == ViewerDataModel.Instance.PageBalanceNumber).ToList().ForEach(delegate (MarkupItem markupitem)
747
                    //{
748
                    //    layerControl.markupParse(markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_Sync, item.DisplayColor, "", item.MarkupInfoID);
749
                    //});
750

    
751
                    var pageItems = item.MarkupList.Where(pageItem => pageItem.PageNumber == ViewerDataModel.Instance.SyncPageNumber).ToList();
752

    
753
                    foreach (var markupitem in pageItems)
754
                    {
755
                       await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_Sync, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "", item.MarkupInfoID,
756
                           STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
757
                    }
758
                }
759
            }
760
            else if (e.RemovedItems.Any())
761
            {
762
                var _infoItem = e.RemovedItems.Cast<MarkupInfoItem>().ToList();
763

    
764
                (from A in _infoItem
765
                 from B in Common.ViewerDataModel.Instance.MarkupControls_Sync
766
                 where A.MarkupInfoID == B.MarkupInfoID
767
                 select B).ToList().ForEach(data =>
768
                 {
769
                     Common.ViewerDataModel.Instance.MarkupControls_Sync.Remove(data);
770
                 });
771
            }
772
        }
773

    
774
        /// <summary>
775
        /// 선택한 항목은 Visibility = Visible, 해제한 항목은 Visibility = Hidden 처리한다.
776
        /// </summary>
777
        /// <param name="sender"></param>
778
        /// <param name="e"></param>
779
        private async void gridViewMarkup_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
780
        {
781

    
782
            foreach (var item in e.AddedItems)
783
            {
784
                var cellToSelect = new GridViewCellInfo(item, this.gridViewMarkup.Columns["color"], this.gridViewMarkup);
785

    
786
                if(cellToSelect != null)
787
                {
788

    
789
                }
790
            }
791

    
792
            SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
793

    
794
            var dataSet = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
795
            var dataSet_User = gridViewMarkup.Items.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
796
            var resultA = (from item_Select in dataSet
797
                           from item_Non in dataSet_User
798
                           where item_Select == item_Non
799
                           select item_Non).ToList();
800

    
801
            if (resultA.Count() >= 2)
802
            {
803
                // 동일한 사용자 데이터가 두개 이상 선택됩니다. Consolidation을 선택할까요?
804
                RadWindow.Confirm(new DialogParameters
805
                {
806
                    Owner = Application.Current.MainWindow,
807
                    Header = "Info",
808
                    Content = "Selected more than two identical user data. Do you want to select consolidation?",
809
                    Closed = new EventHandler<WindowClosedEventArgs>((sen, ea) =>
810
                    {
811
                        if(ea.DialogResult == null)
812
                        {
813
                            return;
814
                        }
815
                        if (e.AddedItems.Count() == 1)
816
                        {
817
                            MarkupInfoItem instanceItem = e.AddedItems.FirstOrDefault() as MarkupInfoItem;
818
                            gridViewMarkup.SelectedItem = null;
819

    
820
                        
821
                            if (ea.DialogResult.Value)
822
                            {
823
                                if (instanceItem.Consolidate == 1 || instanceItem.PartConsolidate == 1)
824
                                {
825
                                    gridViewMarkup.SelectedItem = instanceItem;
826
                                }
827
                                else
828
                                {
829
                                    //1. Consolidations이 있다면 하나 선택
830
                                    var Consolidations = resultA.Where(item => (item.Consolidate == 1 || item.PartConsolidate == 1));
831

    
832
                                    if (Consolidations.Count() > 0)
833
                                    {
834
                                        gridViewMarkup.SelectedItem = Consolidations.First();
835
                                    }
836
                                }
837
                              
838
                            }
839
                            else {
840
                                //1. Consolidations 아닌게 있다면 Change
841
                                var notConsolidations = resultA.Where(item => !(item.Consolidate == 1 || item.PartConsolidate == 1));
842

    
843
                                if(notConsolidations.Count() > 0) {
844
                                    gridViewMarkup.SelectedItem = notConsolidations.First();
845
                                }
846
                                else {//1. Consolidations 아닌게 없다면 그대로
847
                                    gridViewMarkup.SelectedItem = instanceItem;
848
                                }
849
                                
850
                            }
851
                        }
852
                    }),
853
                    Theme = new Windows8Theme(),
854
                    ModalBackground = new System.Windows.Media.SolidColorBrush { Color = System.Windows.Media.Colors.Black, Opacity = 0.6 },
855
                });
856
            }
857
            else //파라미터로 넘어온 사용자가 걸리지 않은 경우
858
            {
859
                List<MarkupInfoItem> gridItem = gridViewMarkup.Items.Cast<MarkupInfoItem>().ToList(); //전체 마크업
860
                List<MarkupInfoItem> gridSelectionItem = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
861
                List<MarkupInfoItem> gridNonSelectionItem = gridItem.Except(gridSelectionItem).ToList(); //선택 되지 않은 마크업
862
#region 코멘트 보기
863
                if (e.AddedItems.Count() > 0 && this.pageNavigator.CurrentPage != null)
864
                {
865
                    foreach (var item in gridSelectionItem)
866
                    {
867
                        if (item.UserID == App.ViewInfo.UserID)
868
                        {
869
                            var controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
870
                            if (controls.Count == 0)
871
                            {
872
                                var instance = ViewerDataModel.Instance.MyMarkupList.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
873

    
874
                                foreach (var markup in instance)
875
                                {
876
                                    await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "", 
877
                                        item.MarkupInfoID, markup.ID, STAMP_Contents:App.SystemInfo.STAMP_CONTENTS);
878
                                }
879
                            }
880

    
881
                            controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
882
                            foreach (var control in controls)
883
                            {
884
                                Logger.sendCheckLog(String.Format("=={0}", control), 1);
885
                                control.Visibility = Visibility.Visible;
886
                            }
887
                        }
888
                        else
889
                        {
890
                            var controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
891
                            if (controls.Count == 0)
892
                            {
893
                                var instance = ViewerDataModel.Instance.MarkupList_Pre.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
894
                                foreach (var markup in instance)
895
                                {
896
                                    await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "",
897
                                        item.MarkupInfoID, markup.ID, STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
898
                                }
899
                            }
900

    
901
                            controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
902
                            foreach (var control in controls)
903
                            {
904
                                control.Visibility = Visibility.Visible;
905
                            }
906
                        }
907
                    }
908
                }
909
#endregion
910
#region 코멘트 숨기기
911
                else if (e.RemovedItems.Count > 0)
912
                {
913
                    var _infoItem = e.RemovedItems.Cast<MarkupInfoItem>().ToList();
914

    
915
                    (from A in _infoItem
916
                     from B in Common.ViewerDataModel.Instance.MarkupControls
917
                     where A.MarkupInfoID == B.MarkupInfoID
918
                     select B).ToList().ForEach(data =>
919
                     {
920
                         data.Visibility = Visibility.Hidden;                         
921
                     });
922

    
923

    
924
                    var myComment = _infoItem.Where(d => d.UserID == App.ViewInfo.UserID).FirstOrDefault();
925
                    if (myComment != null)
926
                    {
927
                        Common.ViewerDataModel.Instance.MarkupControls_USER.ToList().ForEach(delegate (MarkupToPDF.Common.CommentUserInfo markupitem)
928
                        {
929
                            markupitem.Visibility = Visibility.Hidden;
930
                        });
931
                    }
932
                }
933
#endregion
934
            }
935
        }
936

    
937
        private async void gridViewMarkup_SelectedCellsChanged(object sender, Telerik.Windows.Controls.GridView.GridViewSelectedCellsChangedEventArgs e)
938
        {
939
            if (e.AddedCells.Count() > 0)
940
            {
941
                if(e.AddedCells[0].Column.Name == "color")
942
                {
943

    
944
                }
945
                else
946
                {
947
                    List<MarkupInfoItem> removeItems = new List<MarkupInfoItem>();
948

    
949
                    if (!gridViewMarkup.SelectedItems.Contains(e.AddedCells[0].Item))
950
                    {
951
                        gridViewMarkup.SelectedItems.Add(e.AddedCells[0].Item);
952
                    }
953
                    else
954
                    {
955
                        gridViewMarkup.Unselect(new[] { e.AddedCells[0].Item });
956

    
957
                        removeItems.Add(e.AddedCells[0].Item as MarkupInfoItem);
958
                    }
959

    
960
                    SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
961

    
962
                    var dataSet = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
963
                    var dataSet_User = gridViewMarkup.Items.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
964
                    var resultA = (from item_Select in dataSet
965
                                   from item_Non in dataSet_User
966
                                   where item_Select == item_Non
967
                                   select item_Non).ToList();
968

    
969
                    if (resultA.Count() >= 2)
970
                    {
971
                        // 동일한 사용자 데이터가 두개 이상 선택됩니다. Consolidation을 선택할까요?
972
                        RadWindow.Confirm(new DialogParameters
973
                        {
974
                            Owner = Application.Current.MainWindow,
975
                            Header = "Info",
976
                            Content = "Selected more than two identical user data. Do you want to select consolidation?",
977
                            Closed = new EventHandler<WindowClosedEventArgs>((sen, ea) =>
978
                            {
979
                                if (ea.DialogResult == null)
980
                                {
981
                                    return;
982
                                }
983
                                if (gridViewMarkup.SelectedItems.Count() == 1)
984
                                {
985
                                    MarkupInfoItem instanceItem = gridViewMarkup.SelectedItems.FirstOrDefault() as MarkupInfoItem;
986
                                    gridViewMarkup.SelectedItem = null;
987

    
988

    
989
                                    if (ea.DialogResult.Value)
990
                                    {
991
                                        if (instanceItem.Consolidate == 1 || instanceItem.PartConsolidate == 1)
992
                                        {
993
                                            gridViewMarkup.SelectedItem = instanceItem;
994
                                        }
995
                                        else
996
                                        {
997
                                            //1. Consolidations이 있다면 하나 선택
998
                                            var Consolidations = resultA.Where(item => (item.Consolidate == 1 || item.PartConsolidate == 1));
999

    
1000
                                            if (Consolidations.Count() > 0)
1001
                                            {
1002
                                                gridViewMarkup.SelectedItem = Consolidations.First();
1003
                                            }
1004
                                        }
1005

    
1006
                                    }
1007
                                    else
1008
                                    {
1009
                                        //1. Consolidations 아닌게 있다면 Change
1010
                                        var notConsolidations = resultA.Where(item => !(item.Consolidate == 1 || item.PartConsolidate == 1));
1011

    
1012
                                        if (notConsolidations.Count() > 0)
1013
                                        {
1014
                                            gridViewMarkup.SelectedItem = notConsolidations.First();
1015
                                        }
1016
                                        else
1017
                                        {//1. Consolidations 아닌게 없다면 그대로
1018
                                            gridViewMarkup.SelectedItem = instanceItem;
1019
                                        }
1020

    
1021
                                    }
1022
                                }
1023
                            }),
1024
                            Theme = new Windows8Theme(),
1025
                            ModalBackground = new System.Windows.Media.SolidColorBrush { Color = System.Windows.Media.Colors.Black, Opacity = 0.6 },
1026
                        });
1027
                    }
1028
                    else //파라미터로 넘어온 사용자가 걸리지 않은 경우
1029
                    {
1030
                        List<MarkupInfoItem> gridItem = gridViewMarkup.Items.Cast<MarkupInfoItem>().ToList(); //전체 마크업
1031
                        List<MarkupInfoItem> gridSelectionItem = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
1032
                        List<MarkupInfoItem> gridNonSelectionItem = gridItem.Except(gridSelectionItem).ToList(); //선택 되지 않은 마크업
1033
                        #region 코멘트 보기
1034
                        if (gridViewMarkup.SelectedItems.Count() > 0 && this.pageNavigator.CurrentPage != null)
1035
                        {
1036
                            foreach (var item in gridSelectionItem)
1037
                            {
1038
                                if (item.UserID == App.ViewInfo.UserID)
1039
                                {
1040
                                    var controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1041
                                    if (controls.Count == 0)
1042
                                    {
1043
                                        var instance = ViewerDataModel.Instance.MyMarkupList.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
1044

    
1045
                                        foreach (var markup in instance)
1046
                                        {
1047
                                            await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "",
1048
                                                item.MarkupInfoID, markup.ID, STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
1049
                                        }
1050
                                    }
1051

    
1052
                                    controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1053
                                    foreach (var control in controls)
1054
                                    {
1055
                                        Logger.sendCheckLog(String.Format("=={0}", control), 1);
1056
                                        control.Visibility = Visibility.Visible;
1057
                                    }
1058
                                }
1059
                                else
1060
                                {
1061
                                    var controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1062
                                    if (controls.Count == 0)
1063
                                    {
1064
                                        var instance = ViewerDataModel.Instance.MarkupList_Pre.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
1065
                                        foreach (var markup in instance)
1066
                                        {
1067
                                            await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "",
1068
                                                item.MarkupInfoID, markup.ID, STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
1069
                                        }
1070
                                    }
1071

    
1072
                                    controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1073
                                    foreach (var control in controls)
1074
                                    {
1075
                                        control.Visibility = Visibility.Visible;
1076
                                    }
1077
                                }
1078
                            }
1079
                        }
1080
                        #endregion
1081
                        #region 코멘트 숨기기
1082
                        else if (removeItems.Count > 0)
1083
                        {
1084
                            (from A in removeItems
1085
                             from B in Common.ViewerDataModel.Instance.MarkupControls
1086
                             where A.MarkupInfoID == B.MarkupInfoID
1087
                             select B).ToList().ForEach(data =>
1088
                             {
1089
                                 data.Visibility = Visibility.Hidden;
1090
                             });
1091

    
1092

    
1093
                            var myComment = removeItems.Where(d => d.UserID == App.ViewInfo.UserID).FirstOrDefault();
1094
                            if (myComment != null)
1095
                            {
1096
                                Common.ViewerDataModel.Instance.MarkupControls_USER.ToList().ForEach(delegate (MarkupToPDF.Common.CommentUserInfo markupitem)
1097
                                {
1098
                                    markupitem.Visibility = Visibility.Hidden;
1099
                                });
1100
                            }
1101
                        }
1102
                        #endregion
1103
                    }
1104
                }
1105
            }
1106
        }
1107

    
1108
        private void BaseClient_GetDocumentItemInfoCompleted(object sender, GetDocumentItemInfoCompletedEventArgs e)
1109
        {
1110
            //Logger.sendResLog("GetDocumentItemInfoCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.DOCUMENT_ID + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
1111

    
1112
            if (e.Result != null)
1113
            {
1114
                _DocItem = e.Result;
1115

    
1116
                if (e.Result.DOCUMENT_NO == "" && e.Result.DOCUMENT_NAME == "" && e.Result.GROUP_NO == "0")
1117
                {
1118
                    _ViewInfo.UserID = _ViewInfo.UserID.Replace(@"DAELIM\", "");
1119
                }
1120
                ////Logger.sendReqLog("GetDocInfoAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID, 1);
1121
                BaseClient.GetDocInfoAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID });
1122
            }
1123
            else
1124
            {
1125
                DialogMessage_Alert("Document Information Not Found.", "Error");
1126

    
1127
                BaseClient.GetCheckSystemAdminCompleted += (sen, ea) =>
1128
                {
1129
                    //Logger.sendResLog("GetCheckSystemAdminCompleted", "UserState : " + ea.UserState + "\r Result :" + ea.Result + "\r Cancelled :" + ea.Cancelled + "\r Error :" + ea.Error, 1);
1130

    
1131
                    if (ea.Error == null)
1132
                    {
1133
                        if (ea.Result)
1134
                        {
1135
                            this._ViewInfo.isAdmin = true;
1136
                            //Logger.sendReqLog("GetDocInfoAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID, 1);
1137
                            BaseClient.GetDocInfoAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID });
1138
                        }
1139
                        else
1140
                        {
1141
                            //System.Windows.Forms.MessageBox.Show("해당 프로젝트에 가입되지 않은 유저입니다. 관리자에게 등록신청을 해주세요", "안내");
1142
                            DialogMessage_Alert("You are not belong to this project. Please ask admin for an authority.", "Info");
1143
                            //this.ParentOfType<MainPage>().DialogMessage_Alert("해당 프로젝트에 가입되지 않은 유저입니다. 관리자에게 등록신청을 해주세요", "안내");
1144
                        }
1145

    
1146
                    }
1147
                    else
1148
                    {
1149
                        //System.Windows.Browser.HtmlPage.Window.Invoke("close");
1150
                    }
1151
                };
1152
                //Logger.sendReqLog("GetCheckSystemAdminAsync", _ViewInfo.UserID, 1);
1153
                BaseClient.GetCheckSystemAdminAsync(this._ViewInfo.UserID);
1154
            }
1155
        }
1156

    
1157
        private void BaseClient_GetSystemDataCompleted(object sender, GetSystemDataCompletedEventArgs e)
1158
        {
1159
            //Logger.sendResLog("GetSystemDataCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
1160

    
1161
            if (e.Error == null && e.Result != null)
1162
            {
1163
                App.SystemInfo = e.Result;
1164

    
1165
                //App.urlPort_DB = App.SystemInfo.HostPort;
1166
                //App.urlHost_DB = App.SystemInfo.HostName;
1167
                //Logger.sendReqLog("GetConversionStateAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID, 1);
1168
                BaseClient.GetConversionStateAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID });
1169

    
1170
                //if (App.urlHost.Contains("localhost"))
1171
                //{
1172
                //    App.urlHost = App.urlHost_DB;
1173
                //}
1174
            }
1175
        }
1176

    
1177
        private void BaseClient_GetConversionStateCompleted(object sender, GetConversionStateCompletedEventArgs e)
1178
        {
1179
            if (e.Error == null && e.Result)
1180
            {
1181
                //Logger.sendReqLog("GetDocumentItemInfoAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID + "," + _ViewInfo.UserID, 1);
1182

    
1183
                BaseClient.GetDocumentItemInfoAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID, userID = _ViewInfo.UserID });
1184

    
1185
                if (App.ViewInfo != null && App.ViewInfo.ProjectNO != "")
1186
                {
1187
                    //Logger.sendReqLog("GetMember", _ViewInfo.ProjectNO + "," + _ViewInfo.UserID, 1);
1188
                    userData = BaseClient.GetMember(App.ViewInfo.ProjectNO, App.ViewInfo.UserID);
1189
                    if (userData != null)
1190
                    {
1191
                        //Logger.sendReqLog("GetDeptDataAsync", userData.DEPARTMENT, 1);
1192
                        BaseClient.GetDeptDataAsync(userData.DEPARTMENT);
1193
                    }
1194
                    else
1195
                    {
1196
                        userData = new MEMBER();
1197
                        userData.DEPARTMENT = "ALL";
1198
                        //Logger.sendReqLog("GetDeptDataAsync", userData.DEPARTMENT, 1);
1199
                        BaseClient.GetDeptDataAsync(userData.DEPARTMENT);
1200
                    }
1201
                }
1202
            }
1203
            else
1204
            {
1205
                string failedmsg = CommonLib.Common.GetAlertMessageString("GetConversionStateFailed", "MSG", "Too Many V/P Files are uploading instantaneously, This V/P file can not be open now. Please feel free to re-open wait a moment again!\n\n현재 일시적으로 많은 양의 V/P가 등록되고 있어 이 문서를 열람할 수 없습니다.\n잠시만 기다려 주신 후 다시 열람하여 주시기 바랍니다");
1206
                DialogMessage_Alert(failedmsg, "Warning");
1207
            }
1208
        }
1209

    
1210
        public void SetView(ViewInfo info)
1211
        { 
1212
            this._ViewInfo = info;
1213
            try
1214
            {
1215
                /// 대림의 경우 EnsembleID를 가지고 DocumentItemID를 구함
1216
                /// 다른 Site를 대비하여 에러 처리함
1217
                string docid = BaseClient.GetDocItemID(info.EnsembleID);
1218
                if (!string.IsNullOrEmpty(docid))
1219
                {
1220
                    this._ViewInfo.DocumentItemID = docid;
1221
                }
1222
            }
1223
            catch (Exception ex)
1224
            {
1225

    
1226
                //App.FileLogger.Fatal(ex);
1227
            }
1228

    
1229
            //Logger.sendReqLog("GetSystemDataAsync", "", 1);
1230

    
1231
            BaseClient.GetSystemDataAsync();
1232
        }
1233

    
1234
        public void HubSet()
1235
        {
1236
            // 허브 연결 구성
1237
            var hubConnection = new HubConnection(CommonLib.Common.GetConfigString("HubAddress", "URL", "", App.isExternal));
1238
            IHubProxy MarkusLicenseProxy = hubConnection.CreateHubProxy("MarkusLicenseHub");
1239

    
1240

    
1241
            // 허브 연결 
1242
            hubConnection.Start().ContinueWith(task =>
1243
            {
1244
                if (task.IsFaulted)
1245
                {
1246
                    Console.WriteLine("There was an error opening the connection:{0}",
1247
                                      task.Exception.GetBaseException());
1248
                    //throw task.Exception.GetBaseException();
1249
                }
1250
                else
1251
                {
1252
                    Console.WriteLine("Connected :: " + task.Id);
1253
                }
1254

    
1255
            }).Wait();
1256

    
1257

    
1258
            // [ 프로그램 시작 ]
1259
            // 클라이언트에서 서버를 호출 ( 접속 시 )  : 라이센스 체크
1260
            //( "method name", arg1, arg2 )
1261
            //MarkusLicenseProxy.Invoke<string>("ConnectionMarkus", "H2009115", "고동균").ContinueWith(task =>
1262
            //{
1263
            //    if (task.IsFaulted)
1264
            //    {
1265
            //        Console.WriteLine("ConnectionMarkus :: There was an error calling send: {0}", task.Exception.GetBaseException());
1266
            //    }
1267
            //    else
1268
            //    {
1269
            //        Console.WriteLine(task.Result);
1270
            //    }
1271
            //});
1272
            MarkusLicenseProxy.Invoke<string>("ConnectionMarkus", App.ViewInfo.UserID,App.ViewInfo.ProjectNO).ContinueWith(task =>
1273
            {
1274
                if (task.IsFaulted)
1275
                {
1276
                    Console.WriteLine("ConnectionMarkus :: There was an error calling send: {0}", task.Exception.GetBaseException());
1277
                    //throw task.Exception.GetBaseException();
1278
                }
1279
                else
1280
                {
1281
                    switch (task.Result)
1282
                    {
1283
                        case "2":
1284
                            {
1285
                                var result = MessageBox.Show("권한이 없습니다.");
1286
                                if (result == MessageBoxResult.OK)
1287
                                    System.Diagnostics.Process.GetCurrentProcess().Kill();
1288
                            }
1289
                            break;
1290
                        case "404":
1291
                            {
1292
                                var result = MessageBox.Show("등록된 사용자가 아닙니다.");
1293
                                if(result == MessageBoxResult.OK)
1294
                                    System.Diagnostics.Process.GetCurrentProcess().Kill();
1295
                            }
1296
                            break;
1297
                    }
1298
                }
1299
            });
1300

    
1301
            // 서버에서 클라이언트 호출 ( 프로그램 구동여부 ) : 라이센스 체크 후 응답 ( 반환값 : true, false ) 
1302
            //MarkusLicenseProxy.On<bool>("IsConnection", status =>
1303
            //{
1304

    
1305
            //    if (status)
1306
            //    {
1307
            //        // 프로그램 시작 
1308
            //        Console.WriteLine("connection status : " + status);
1309
            //    }
1310
            //    else
1311
            //    {
1312
            //        // 프로그램 종료 ( signalr 접속 끊기 )  
1313
            //        hubConnection.Stop();
1314
            //    }
1315
            //});
1316

    
1317
            // 공지 메세지 ( 서버에서 클라이언트 호출 ) 
1318
            MarkusLicenseProxy.On<string>("MarkusNotification", msg =>
1319
                Console.WriteLine("Noficiation Message : " + msg)
1320
            );
1321

    
1322

    
1323
            // 서버 메서드 호출 
1324
            //MarkusLicenseProxy.Invoke<string>("DoSomething", "I'm doing something!!!").Wait();
1325

    
1326
            //Console.ReadKey();
1327

    
1328
            //hubConnection.Stop();
1329
        }
1330

    
1331
        public async void MarkupUserListDisplay()
1332
        {
1333
            List<MarkupInfoItem> gridItem = gridViewMarkup.Items.Cast<MarkupInfoItem>().ToList(); //전체 마크업
1334
            List<MarkupInfoItem> gridSelectionItem = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
1335
            List<MarkupInfoItem> gridNonSelectionItem = gridItem.Except(gridSelectionItem).ToList(); //선택 되지 않은 마크업
1336
                                                                                                     //MarkupToPDF.Controls.Parsing.LayerControl layerControl = new MarkupToPDF.Controls.Parsing.LayerControl();
1337
            Common.ViewerDataModel.Instance.MarkupControls_USER.Clear();  //전체 제거
1338
            Common.ViewerDataModel.Instance.MarkupControls.Clear();  //전체 제거
1339
            //foreach (var item in gridSelectionItem)
1340
            //{
1341
            //    if (item.UserID == App.ViewInfo.UserID)
1342
            //    {
1343
            //        ViewerDataModel.Instance.MyMarkupList.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList().ForEach(delegate (MarkupItemEx markupitem)
1344
            //        {
1345
            //            layerControl.markupParseEx(markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, item.DisplayColor, "", item.MarkupInfoID, markupitem.ID);
1346
            //        });
1347
            //    }
1348
            //    else
1349
            //    {
1350
            //        ViewerDataModel.Instance.MarkupList_Pre.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList().ForEach(delegate (MarkupItemEx markupitem)
1351
            //        {
1352
            //            layerControl.markupParse(markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls, item.DisplayColor, "", item.MarkupInfoID);
1353
            //        });
1354
            //    }
1355
            //}
1356
                (from A in gridSelectionItem
1357
                 from B in Common.ViewerDataModel.Instance.MarkupControls_USER
1358
                 where A.MarkupInfoID == B.MarkupInfoID
1359
                 select B).ToList().ForEach(data =>
1360
                 {
1361
                     Common.ViewerDataModel.Instance.MarkupControls_USER.Remove(data);
1362
                 });
1363
            (from A in gridSelectionItem
1364
             from B in Common.ViewerDataModel.Instance.MarkupControls
1365
             where A.MarkupInfoID == B.MarkupInfoID
1366
             select B).ToList().ForEach(data =>
1367
             {
1368
                 Common.ViewerDataModel.Instance.MarkupControls.Remove(data);
1369
             });
1370

    
1371
            foreach (var item in gridSelectionItem)
1372
            {
1373

    
1374
                if (item.UserID == App.ViewInfo.UserID)
1375
                {
1376
                    var markupItems = ViewerDataModel.Instance.MyMarkupList.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList();
1377

    
1378
                    foreach (var markupitem in markupItems)
1379
                    {
1380
                        await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "", 
1381
                                item.MarkupInfoID, markupitem.ID, STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
1382
                    }
1383
                }
1384
                else
1385
                {
1386
                    var markupItems = ViewerDataModel.Instance.MarkupList_Pre.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList();
1387

    
1388
                    foreach (var markupitem in markupItems)
1389
                    {
1390
                        await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "", item.MarkupInfoID,
1391
                            STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
1392
                    }
1393
                }
1394
            }
1395
        }
1396
    }
1397
}
클립보드 이미지 추가 (최대 크기: 500 MB)