프로젝트

일반

사용자정보

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

markus / KCOM_API / ServiceDeepView.svc.cs @ d0eda156

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

1
using IFinalPDF;
2
using IKCOM;
3
using KCOMDataModel.Common;
4
using KCOMDataModel.DataModel;
5
using MARKUS;
6
using System;
7
using System.Collections.Generic;
8
using System.Collections.ObjectModel;
9
using System.Linq;
10
using System.Net;
11
using System.Runtime.Remoting.Channels.Tcp;
12
using System.Runtime.Serialization;
13
using System.ServiceModel;
14
using System.ServiceModel.Activation;
15
using System.Text;
16
using System.Windows;
17
using System.Xml;
18

    
19
namespace KCOM_API
20
{
21
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ServiceDeepView" in code, svc and config file together.
22
    // NOTE: In order to launch WCF Test Client for testing this service, please select ServiceDeepView.svc or ServiceDeepView.svc.cs at the Solution Explorer and start debugging.
23
    [ServiceContract(Namespace = "")]
24
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
25
    public partial class ServiceDeepView : System.Web.Services.WebService
26
    {
27
        //[OperationContract]
28
        //public List<HoneyheadTEXT> GetSearchText(int pageNo, string filePath,bool IsAllPage) //0아 아니면 지정 페이지
29
        //{
30

    
31
        //    return null;
32
        //}
33

    
34

    
35
        [OperationContract]
36
        public KCOM_SystemInfo GetSystemData()
37
        {
38
            try
39
            {
40
                using (KCOMEntities uc = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
41
                {
42
                    var SystemInfoSet = uc.PROPERTIES.Where(data => data.TYPE == "SystemInfo").ToList();
43

    
44
                    KCOM_SystemInfo sysInfo = new KCOM_SystemInfo();
45

    
46
                    var url = SystemInfoSet.Where(data => data.PROPERTY == "Url").FirstOrDefault();
47
                    if (url != null)
48
                    {
49
                        sysInfo.HostName = url.VALUE;
50
                    }
51

    
52
                    url = SystemInfoSet.Where(data => data.PROPERTY == "Port").FirstOrDefault();
53
                    if (url != null)
54
                    {
55
                        sysInfo.HostPort = url.VALUE;
56
                    }
57

    
58
                    url = uc.PROPERTIES.Where(data => data.TYPE == "STAMP").FirstOrDefault();
59
                    if(url != null)
60
                    {
61
                        sysInfo.STAMP = url.VALUE;
62
                    }
63
                    return sysInfo;
64
                }
65
            }
66
            catch (Exception ex)
67
            {
68
            }
69
            return null;
70
            GC.Collect(2);
71
        }
72

    
73
        private static string shortGuid()
74
        {
75
            byte[] bytes = new byte[16];
76
            using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create())
77
            {
78
                provider.GetBytes(bytes);
79
            }
80

    
81
            var guid = new Guid(bytes);
82

    
83
            return Convert.ToBase64String(guid.ToByteArray())
84
                .Substring(0, 10)
85
                .Replace("/", "")
86
                .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
87
        }
88

    
89

    
90
        [OperationContract]
91
        public List<FAVORITE_DOC> GetFavoriteVP(string PrjNo, string userID, string sharepointItemID)
92
        {
93

    
94

    
95
            using (KCOMEntities dc = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
96
            {
97

    
98
                int flagString = Convert.ToInt32(FAVORITE_FLAG.Personal);
99
                List<FAVORITE_DOC> favoriteListSet = new List<FAVORITE_DOC>();
100
                //dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == PrjNo && data.DOCUMENT_ID == sharepointItemID && data.FLAG !=
101
                //    flagString).ToList().ForEach(data => favoriteListSet.Add(data));
102

    
103

    
104
                //dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == PrjNo && data.MEMBER_USER_ID == userID).ToList().ForEach(data => favoriteListSet.Add(data));
105

    
106
                favoriteListSet = dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == PrjNo && data.MEMBER_USER_ID == userID && data.DOCUMENT_ID == sharepointItemID).ToList();
107

    
108
                //favoriteListSet = favoriteListSet.Distinct().ToList();
109
                return favoriteListSet;
110
            }
111
        }
112
        [OperationContract]
113
        public bool EditFavoriteVP(string prjNo, string userID, string docID, int state, string description)
114
        {
115
            using (KCOMEntities dc = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
116
            {
117
                //List<FAVORITE_DOC> favoriteSet = dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == prjNo && data.MEMBER_USER_ID == userID
118
                //    && data.PAGE_NO == SavePageNo && data.CREATE_TIME == createTime).ToList();
119
                List<FAVORITE_DOC> favoriteSet = dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == prjNo && data.MEMBER_USER_ID == userID
120
                    && data.ID == docID).ToList();
121
                try
122
                {
123

    
124
                    if (favoriteSet.Count > 0)
125
                    {
126
                        var FavoriteVP_Instance = favoriteSet.First();
127

    
128
                        FavoriteVP_Instance.DESCRIPTION = description;
129
                        FavoriteVP_Instance.FLAG = state;
130

    
131
                        dc.SaveChanges();
132

    
133
                        return true;
134
                    }
135
                    else
136
                    {
137
                        return false;
138
                    }
139
                }
140
                catch (Exception)
141
                {
142
                    return false;
143
                }
144
            }
145
        }
146

    
147
        [OperationContract]
148
        public bool DelFavoriteVP(string prjNo, string userID, int SavePageNo, string docID)
149
        {
150

    
151
            using (KCOMEntities dc = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
152
            {
153

    
154
                List<FAVORITE_DOC> favoriteSet = dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == prjNo && data.MEMBER_USER_ID == userID
155
                    && data.ID == docID).ToList();
156

    
157
                try
158
                {
159
                    if (favoriteSet.Count > 0)
160
                    {
161
                        favoriteSet.ForEach(data => dc.FAVORITE_DOC.DeleteObject(data));
162
                        dc.SaveChanges();
163
                        return true;
164
                    }
165
                    else
166
                    {
167
                        return false;
168
                    }
169
                }
170
                catch (Exception)
171
                {
172
                    return false;
173
                }
174
            }
175
        }
176

    
177

    
178
        [OperationContract]
179
        public List<Rect> GetCompareRect(string projectNo, string originDocItem_ID, string targetDocItem_ID, string originPageNo, string targetPageNo, string isInternalAddress)
180
        {
181
            //string originFile = String.Format(@"http://cloud.devdoftech.co.kr:5977/TileSource/{0}_Tile/{1}/{2}/{3}.cmp", projectNo, (Convert.ToInt32(originDocItem_ID) / 100).ToString(), originDocItem_ID, originPageNo);
182
            //string targetFile = String.Format(@"http://cloud.devdoftech.co.kr:5977/TileSource/{0}_Tile/{1}/{2}/{3}.cmp", projectNo, (Convert.ToInt32(targetDocItem_ID) / 100).ToString(), targetDocItem_ID, targetPageNo);
183

    
184
            string originFile = "";
185
            string targetFile = "";
186

    
187
            if (Boolean.Parse(isInternalAddress))
188
            {
189
                originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, (Convert.ToUInt32(originDocItem_ID) / 100).ToString(), originDocItem_ID, originPageNo);
190
                targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, (Convert.ToUInt32(targetDocItem_ID) / 100).ToString(), targetDocItem_ID, targetPageNo);
191
            }
192
            else
193
            {
194
                originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo,  originDocItem_ID, originPageNo);
195
                targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo,  targetDocItem_ID, targetPageNo);
196
            }
197

    
198
            CompareLib compareLib = new CompareLib();
199
            //System.IO.Stream resultOrigin = compareLib.ChangeCmpUrlToPng(originFile);
200
            //System.IO.Stream resultTarget = compareLib.ChangeCmpUrlToPng(targetFile);
201

    
202
            var resultOrigin = compareLib.ChangeCmpUrlToPng_File(originFile);
203
            var resultTarget = compareLib.ChangeCmpUrlToPng_File(targetFile);
204

    
205
            string outPutFile = compareLib.ImageCompare_File(resultOrigin, resultTarget);
206
            var result = compareLib.GetBoundBoxInImage(outPutFile);
207

    
208
            return result;
209
        }
210

    
211

    
212

    
213
        #region Final PDF
214
        private string _ChanID = null;
215
        TcpChannel chan = null;
216
        [OperationContract]
217
        public FinalPDFResult SetFinalPDF(string ProjectNo, string DocInfoID, string MarkupInfoID, string CreateUserID)
218
        {
219
            #region 임시보관
220
            #endregion
221
            FinalPDFResult _result = new FinalPDFResult();
222
            RemFinalPDFObject remObj = null;
223
            try
224
            {
225
                string _finalID = shortGuid();
226
                int _DocTotalPages = -1;
227
                string docItemId;
228

    
229

    
230
                using (CIEntities _ci = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
231
                {
232
                    var _doc = _ci.DOCINFO.Where(info => info.ID == DocInfoID);
233

    
234
                    if (_doc.Count() > 0)
235
                    {
236
                        _DocTotalPages = _doc.First().PAGE_COUNT;
237
                        docItemId = _doc.First().DOCUMENT_ID;
238
                    }
239
                    else
240
                    {
241
                        _result.Status = FinalStatus.Error;
242
                        _result.Exception = "페이지 정보를 가져올 수 없습니다.";
243
                        return _result;
244
                    }
245
                }
246
                if (_DocTotalPages > 0)
247
                {
248
                    FINAL_PDF fm = new FINAL_PDF()
249
                    {
250
                        ID = _finalID,
251
                        PROJECT_NO = ProjectNo,
252
                        DOCINFO_ID = DocInfoID,
253
                        DOCUMENT_ID = docItemId,
254
                        MARKUPINFO_ID = MarkupInfoID,
255
                        CREATE_USER_ID = CreateUserID,
256
                        TOTAL_PAGE = _DocTotalPages,
257
                        CREATE_DATETIME = DateTime.Now,
258
                        STATUS = (int)IFinalPDF.FinalStatus.Insert
259
                    };
260
                    using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
261
                    {
262
                        _entity.AddToFINAL_PDF(fm);
263
                        _entity.SaveChanges(System.Data.Objects.SaveOptions.AcceptAllChangesAfterSave);
264
                    };
265

    
266
                    System.Runtime.Remoting.Channels.IChannel _ch = System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp");
267
                    if (_ch == null)
268
                    {
269
                        chan = new TcpChannel();
270
                        _ChanID = chan.ChannelName;
271
                        System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan, false);
272
                        // Create an instance of the remote object
273

    
274

    
275
                        using (KCOMEntities ec = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
276
                        {
277

    
278
                            //remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
279
                            //                          "tcp://localhost:9092/remFinalPDF");
280
                            remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
281
                                                      //"tcp://192.168.0.67:9092/remFinalPDF");
282
                                                      "tcp://localhost:9092/remFinalPDF");
283
                        }
284

    
285
                        //"tcp://localhost:8080/remFinalPDF");
286

    
287
                        _result = remObj.SetFinalPDF(ProjectNo, _finalID);
288
                        _result.FinalID = _finalID;
289
                        _result.Status = FinalStatus.Success;
290

    
291
                        //MarkupToPDF.MarkupToPDF fa = new MarkupToPDF.MarkupToPDF();
292
                        //fa.MakeFinalPDF(fm);
293
                    }
294
                    else
295
                    {
296
                        _ChanID = _ch.ChannelName;
297
                    }
298
                }
299
            }
300
            catch (Exception ex)
301
            {
302
                _result.Status = FinalStatus.Error;
303

    
304
                if (ex.GetType() == typeof(System.Net.Sockets.SocketException))
305
                    _result.Exception = "Final Server Not Connection";
306
            }
307
            finally
308
            {
309
                remObj = null;
310
                if (System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp") != null)
311
                    System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(chan);
312

    
313
                GC.Collect(2);
314
            }
315
            return _result;
316
        }
317
        #endregion
318

    
319

    
320
        [OperationContract]
321
        public bool GetConversionState(KCOM_BasicParam param)
322
        {
323
            using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(param.projectNo).ToString()))
324
            {
325
                var doc = entity.DOCINFO.Where(data => data.DOCUMENT_ID == param.documentID).FirstOrDefault();
326
                if (doc != null)
327
                {
328
                    var count = doc.DOCPAGE.Where(data => data.DOCINFO_ID == doc.ID).Count();
329
                    if (doc.PAGE_COUNT == count)  //페이지 수가 일치하는지
330
                    {
331
                        return true;
332
                    }
333
                    else //페이지 수가 일치하지 않는 경우
334
                    {
335
                        KCOMEntities entity_kcom = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString());
336
                        var lst = entity_kcom.CONVERTER_DOC.Where(data => data.PROJECT_NO == param.projectNo && data.DOCUMENT_ID == param.documentID && data.TOTAL_PAGE != doc.PAGE_COUNT).ToList();
337

    
338
                        if (lst != null || lst.Count >= 1)
339
                        {
340
                            //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_PAGECOUNT"), param.documentID, param.projectNo);
341
                            //이메일 클라이언트를 구현해야함
342
                        }
343
                        return false;
344
                    }
345
                }
346
                else
347
                {
348
                    //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_CONVERTFAILED"), param.documentID, param.projectNo);
349
                    //이메일 클라이언트를 구현해야함
350
                    return false;
351
                }
352
            }
353
        }
354

    
355
        [OperationContract]
356
        public List<VPRevision> GetVPRevisionHistory(string ProjectNo, string vpNo, string DocumentId)
357
        {
358
            List<VPRevision> _result = new List<VPRevision>();
359
            try
360
            {
361
                using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
362
                {
363
                    var _vpList = (from docitem in entity.DOCUMENT_ITEM
364
                                   where docitem.DOCUMENT_NO == vpNo
365
                                   select new VPRevision
366
                                   {
367
                                       RevNo = docitem.REVISION,
368
                                       GroupNo = docitem.GROUP_NO,
369
                                       FROM_VENDOR = docitem.ORIGINAL_FILE,
370
                                       DOCUMENT_ID = docitem.DOCUMENT_ID,
371
                                       TO_VENDOR = docitem.RESULT_FILE,
372
                                       RESULT = docitem.RESULT,
373
                                       DocNo = docitem.DOCUMENT_NO,
374
                                       EnsembleLink = docitem.ENSEMBLEINFO_URL,
375
                                       //IsSyncPossible = docitem.DOCUMENT_ID == DocumentId ? false : entity.DOCINFO.Where(d => d.DOCUMENT_ID == docitem.DOCUMENT_ID).ToList().Count > 0 ? true : false
376
                                   });
377
                    _result = _vpList.ToList();
378
                    foreach (var vp in _result)
379
                    {
380
                        if (entity.DOCINFO.Where(d => d.DOCUMENT_ID == vp.DOCUMENT_ID).ToList().Count > 0)
381
                            vp.IsSyncPossible = true;
382
                        else
383
                            vp.IsSyncPossible = false;
384
                    }
385
                    _result = _result.OrderByDescending(r => UInt64.Parse(System.Text.RegularExpressions.Regex.Replace(r.GroupNo, @"\D", ""))).ToList();
386
                }
387
            }
388
            catch (Exception)
389
            {
390

    
391
                throw;
392
            }
393
            finally
394
            {
395
                GC.Collect(2);
396
            }
397
            return _result;
398
        }
399

    
400
        [OperationContract]
401
        public VPRevision GetVPRevisionFirstOrDefault(string ProjectNo, string DocumentId)
402
        {
403
            VPRevision _result = null;
404
            try
405
            {
406
                using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
407
                {
408
                    _result = (from docitem in entity.DOCUMENT_ITEM
409
                     where docitem.DOCUMENT_ID == DocumentId
410
                     select new VPRevision
411
                     {
412
                         RevNo = docitem.REVISION,
413
                         GroupNo = docitem.GROUP_NO,
414
                         FROM_VENDOR = docitem.ORIGINAL_FILE,
415
                         DOCUMENT_ID = docitem.DOCUMENT_ID,
416
                         TO_VENDOR = docitem.RESULT_FILE,
417
                         RESULT = docitem.RESULT
418
                     }).FirstOrDefault();
419
                }
420
            }
421
            catch (Exception)
422
            {
423
                throw;
424
            }
425
            finally
426
            {
427
                GC.Collect(2);
428
            }
429
            return _result;
430
        }
431

    
432
        [OperationContract]
433
        public DOCINFO GetDocInfo(KCOM_BasicParam param)
434
        {
435
            DOCINFO _result = null;
436
            try
437
            {
438
                // 차후 아래의 코드로 변경
439
                //using (CI_Entities ModelDeeview = new CI_Entities(DaelimCiConnectionString.ToString()))
440
                CIEntities ModelDeeview = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(param.projectNo).ToString());
441

    
442
                var docinfo = ModelDeeview.DOCINFO.Where(doc => doc.DOCUMENT_ID == param.documentID);
443
                if (docinfo.Count() > 0)
444
                {
445
                    _result = docinfo.First();
446
                    _result.MARKUP_INFO.Clear();
447

    
448
                }
449
                return _result;
450

    
451
            }
452
            catch (Exception ex)
453
            {
454
                System.Diagnostics.Trace.WriteLine("GetDocInfo Error : " + ex);
455
            }
456
            finally
457
            {
458
                GC.Collect(2);
459
            }
460
            return null;
461
        }
462

    
463
        [OperationContract]
464
        public bool GetCheckSystemAdmin(string UserID)
465
        {
466
            using (KCOMEntities uc = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
467
            {
468
                var user = uc.PROPERTIES.Where(data => data.TYPE == "Administrator" && data.PROPERTY.Contains(UserID)).FirstOrDefault();
469
                if (user != null)
470
                {
471
                    return true;
472
                }
473
                else
474
                {
475
                    return false;
476
                }
477
            }
478
            GC.Collect(2);
479
        }
480

    
481
        [OperationContract]
482
        public DOCUMENT_ITEM GetDocumentItemInfo(KCOM_BasicParam param)
483
        {
484
            ///param : prjNo, documentId, userId
485
            DOCUMENT_ITEM _result = null;
486

    
487
            try
488
            {
489
                CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(param.projectNo).ToString());
490

    
491
                var _items = entity.DOCUMENT_ITEM.Where(data => data.DOCUMENT_ID == param.documentID);
492

    
493
                if (_items.Count() > 0)
494
                {
495
                    _result = _items.First();
496

    
497
                    return _result;
498
                }
499
                //else
500
                //{
501
                //    Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_DOCUMENTNOTFOUND"), param.documentID, param.projectNo);
502
                //}
503
            }
504
            catch (Exception ex)
505
            {
506
                System.Diagnostics.Trace.WriteLine("GetVendorItemInfo Error : " + ex);
507
                //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, "GetDocumentItemInfo / " + ex.Message, param.documentID, param.projectNo);
508
            }
509

    
510
            return _result;
511
        }
512
        /// <summary>
513
        /// DOCUMENT_ITEM Table 의 ID 로 Item 을 Select
514
        /// </summary>
515
        /// <param name="ensemble_id"></param>
516
        /// <returns></returns>
517
        [OperationContract]
518
        public string GetDocItemID(string ensemble_id)
519
        {
520
            ///param : prjNo, documentId, userId
521
            string _result = string.Empty;
522

    
523
            try
524
            {
525
                CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString("markus").ToString());
526

    
527
                var _items = entity.DOCUMENT_ITEM.Where(data => data.ID == ensemble_id).FirstOrDefault();
528
                if(_items != null)
529
                    _result = _items.DOCUMENT_ID;
530
            }
531
            catch (Exception ex)
532
            {
533
                //System.Diagnostics.Trace.WriteLine("GetVendorItemInfo Error : " + ex);
534
                //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, "GetDocumentItemInfo / " + ex.Message, param.documentID, param.projectNo);
535
            }
536

    
537
            return _result;
538
        }
539
        public string UserGO(MARKUP_INFO item)
540
        {
541
            if (item != null)
542
            {
543
                return item.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID;
544
            }
545
            return null;
546
        }
547
        
548
        [OperationContract]
549
        public List<MarkupInfoItem> GetMarkupInfoItems(string ProjectNo, string DocInfoId)
550
        {
551
            List<MarkupInfoItem> _result = new List<MarkupInfoItem>();
552
            try
553
            {
554
                using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
555
                {
556
                    var markupListData = entity.MARKUP_INFO.Where(data => data.DOCINFO_ID == DocInfoId).ToList();
557

    
558
                    var markupList = from markup in markupListData
559
                                     orderby markup.CREATE_TIME descending
560
                                     select new MarkupInfoItem
561
                                     {
562
                                         MarkupInfoID = markup.ID,
563
                                         UserID = markup.USER_ID,
564
                                         MarkupVersionID = markup.MARKUP_INFO_VERSION.Count() == 0 ? null : markup.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID,
565
                                         CreateTime = markup.CREATE_TIME,
566
                                         Consolidate = markup.CONSOLIDATE,
567
                                         Description = markup.DESCRIPTION,
568
                                         AvoidConsolidate = markup.AVOID_CONSOLIDATE,
569
                                         PartConsolidate = markup.PART_CONSOLIDATE,
570
                                         UpdateTime = DateTime.Parse(markup.UPDATE_TIME.ToString()),
571
                                     };
572

    
573
                    if (markupList.Count() > 0)
574
                    {
575
                        _result = markupList.ToList();
576
                    }
577

    
578
                    _result.ForEach(r =>
579
                    {
580

    
581
                        r.MarkupList = (from markupData in entity.MARKUP_DATA
582
                                        where markupData.MARKUPINFO_VERSION_ID == r.MarkupVersionID
583
                                        orderby markupData.PAGENUMBER
584
                                        select new MarkupItem { ID = markupData.ID, PageNumber = markupData.PAGENUMBER, Data = markupData.DATA, Data_Type = markupData.DATA_TYPE, Symbol_ID = markupData.SYMBOL_ID}).ToList();
585
                    });
586

    
587
                    List<PROPERTIES> _ColorsProperties = new List<PROPERTIES>();
588
                    Random random = new Random();
589
                    
590
                    using (KCOMEntities kcomEntity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
591
                    {
592
                        _ColorsProperties = (from property in kcomEntity.PROPERTIES
593
                                             where property.TYPE == "DisplayColor"
594
                                             select property).ToList();
595
                    }                    
596

    
597
                    foreach (var item in _result)
598
                    {
599
                        var _member = entity.MEMBER.Where(member => member.ID == item.UserID).FirstOrDefault();
600
                        
601
                        if (_member != null)
602
                        {
603
                            item.UserName = _member.NAME;
604
                            item.Depatment = _member.DEPARTMENT;
605
                        }
606

    
607
                        if (_ColorsProperties.Count > 0)
608
                        {
609
                            int colorIdx = random.Next(0, _ColorsProperties.Count() - 1);
610
                            #region 부서별로 색상을 지정하고자 할때
611
                            /// 일단 의견을 들어보자구!
612
                            #endregion
613
                            item.DisplayColor = "#FF" + _ColorsProperties[colorIdx].VALUE;
614
                            _ColorsProperties.Remove(_ColorsProperties[colorIdx]);
615
                        }
616
                        else
617
                        {
618
                            item.DisplayColor = String.Format("#FF{0:X6}", random.Next(0x1000000));
619
                        }
620
                    }
621
                }
622
            }
623
            catch (Exception EX)
624
            {
625
                System.Diagnostics.Debug.WriteLine(this.GetType().ToString() + " " + EX);
626
                return _result;
627
            }
628
            finally
629
            {
630
                GC.Collect(2);
631
            }
632

    
633
            return _result;
634
        }
635

    
636

    
637
        /*
638
        [OperationContract]
639
        public List<MarkupInfoItem> GetMarkupInfoItems(string ProjectNo, string DocInfoId)
640
        {
641
            List<MarkupInfoItem> _result = new List<MarkupInfoItem>();
642
            try
643
            {
644
                using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
645
                {
646
                    var markupListData = entity.MARKUP_INFO.Where(data => data.DOCINFO_ID == DocInfoId).ToList();
647

    
648
                    var markupList = from markup in markupListData
649
                                     orderby markup.CREATE_TIME descending
650
                                     select new MarkupInfoItem
651
                                     {
652
                                         MarkupInfoID = markup.ID,
653
                                         UserID = markup.USER_ID,
654
                                         MarkupVersionID = markup.MARKUP_INFO_VERSION.Count() == 0 ? null : markup.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID,
655
                                         CreateTime = markup.CREATE_TIME,
656
                                         Consolidate = markup.CONSOLIDATE,
657
                                         Description = markup.DESCRIPTION,
658
                                         AvoidConsolidate = markup.AVOID_CONSOLIDATE,
659
                                         PartConsolidate = markup.PART_CONSOLIDATE,
660
                                         UpdateTime = DateTime.Parse(markup.UPDATE_TIME.ToString()),
661
                                     };
662

    
663
                    if (markupList.Count() > 0)
664
                    {
665
                        _result = markupList.ToList();
666
                    }
667

    
668
                    _result.ForEach(r =>
669
                    {
670

    
671
                        r.MarkupList = (from markupData in entity.MARKUP_DATA
672
                                        where markupData.MARKUPINFO_VERSION_ID == r.MarkupVersionID
673
                                        orderby markupData.PAGENUMBER
674
                                        select new MarkupItem { ID = markupData.ID, PageNumber = markupData.PAGENUMBER, Data = markupData.DATA, Data_Type = markupData.DATA_TYPE, Symbol_ID = markupData.SYMBOL_ID }).ToList();
675
                    });
676

    
677
                    Random random = new Random();
678

    
679
                    _MemberDeptColors memberDeptColors = new _MemberDeptColors();
680
                    _MemberDeptColorsInfo memberDeptColorsInfo = new _MemberDeptColorsInfo();
681

    
682

    
683
                    memberDeptColors._memberDeptColors = (from memberdeptcolor in entity.MEMBER_DEPT_COLOR
684
                                                              //where memberdeptcolor.DEPARTMENT == "DisplayColor"
685
                                                          select memberdeptcolor).ToList();
686
                    memberDeptColorsInfo._memberDeptColorsInfo = (from memberdeptcolorinfo in entity.MEMBER_DEPT_COLORINFO
687
                                                                      //where memberdeptcolor.DEPARTMENT == "DisplayColor"
688
                                                                  select memberdeptcolorinfo).ToList();
689

    
690

    
691
                    foreach (var item in _result)
692
                    {
693
                        var _member = entity.MEMBER.Where(member => member.ID == item.UserID);
694

    
695
                        if (_member.Count() > 0)
696
                        {
697
                            item.UserName = _member.First().NAME;
698
                            item.Depatment = _member.First().DEPARTMENT;
699
                        }
700

    
701
                        foreach (var dept in memberDeptColors._memberDeptColors)
702
                        {//dept 지정  색상 
703
                            if (dept.DEPARTMENT == item.Depatment)
704
                            {
705
                                var colorlist = memberDeptColorsInfo._memberDeptColorsInfo.Where(d => d.COLORID == dept.COLORID).ToList();
706

    
707
                                int colorIdx = random.Next(1, colorlist.Count());
708
                                if (colorlist.Count > 0)
709
                                {
710
                                    item.DisplayColor = "#FF" + colorlist[colorIdx].DISPLAYCOLOR;
711
                                    memberDeptColorsInfo._memberDeptColorsInfo.Remove(colorlist[colorIdx]);
712
                                    break;
713
                                }
714
                                else
715
                                {
716
                                    item.DisplayColor = String.Format("#FF{0:X6}", random.Next(0x1000000));
717
                                    break;
718
                                }
719
                            }
720
                        }
721

    
722

    
723
                        if (item.DisplayColor == null)
724
                        {
725
                            foreach (var dept in memberDeptColors._memberDeptColors)
726
                            {
727
                                if (dept.DEPARTMENT == null)
728
                                {
729
                                    dept.DEPARTMENT = item.Depatment;
730
                                    var colorlist = memberDeptColorsInfo._memberDeptColorsInfo.Where(d => d.COLORID == dept.COLORID).ToList();
731
                                    int colorIdx = random.Next(1, colorlist.Count());
732
                                    if (colorlist.Count > 0)
733
                                    {
734
                                        item.DisplayColor = "#FF" + colorlist[colorIdx].DISPLAYCOLOR;
735
                                        memberDeptColorsInfo._memberDeptColorsInfo.Remove(colorlist[colorIdx]);
736
                                        break;
737
                                    }
738
                                    else
739
                                    {
740
                                        item.DisplayColor = String.Format("#FF{0:X6}", random.Next(0x1000000));
741
                                        break;
742
                                    }
743
                                }
744
                            }
745
                        }
746

    
747
                        if (item.DisplayColor == null)
748
                        {
749
                            item.DisplayColor = String.Format("#FF{0:X6}", random.Next(0x1000000));
750
                        }
751
                    }
752
                }
753
            }
754
            catch (Exception EX)
755
            {
756
                System.Diagnostics.Debug.WriteLine(this.GetType().ToString() + " " + EX);
757
                return _result;
758
            }
759
            finally
760
            {
761
                GC.Collect(2);
762
            }
763

    
764
            return _result;
765
        }
766

    
767
        /*
768
        [OperationContract]
769
        public List<MarkupInfoItem> GetMarkupInfoItems(string ProjectNo, string DocInfoId)
770
        {
771
            List<MarkupInfoItem> _result = new List<MarkupInfoItem>();
772
            try
773
            {
774
                using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
775
                {
776
                    var markupListData = entity.MARKUP_INFO.Where(data => data.DOCINFO_ID == DocInfoId).ToList();
777
                    //foreach (var item in markupListData)
778
                    //{
779
                    //    if (!item.AVOID_CONSOLIDATE.HasValue)
780
                    //    {
781
                    //        item.AVOID_CONSOLIDATE = 0;
782
                    //    }
783
                    //}
784

    
785
                    var markupList = from markup in markupListData
786
                                     orderby markup.CREATE_TIME descending
787
                                     select new MarkupInfoItem
788
                                     {
789
                                         MarkupInfoID = markup.ID,
790
                                         UserID = markup.USER_ID,
791
                                         MarkupVersionID = markup.MARKUP_INFO_VERSION.Count() == 0 ? null : markup.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID,
792
                                         CreateTime = markup.CREATE_TIME,
793
                                         Consolidate = markup.CONSOLIDATE,
794
                                         Description = markup.DESCRIPTION,
795
                                         AvoidConsolidate = markup.AVOID_CONSOLIDATE,
796
                                         PartConsolidate = markup.PART_CONSOLIDATE,
797
                                         UpdateTime = DateTime.Parse(markup.UPDATE_TIME.ToString()),
798
                                     };
799

    
800

    
801

    
802
                    if (markupList.Count() > 0)
803
                    {
804
                        _result = markupList.ToList();
805
                    }
806

    
807

    
808

    
809
                    _result.ForEach(r =>
810
                    {
811

    
812
                        r.MarkupList = (from markupData in entity.MARKUP_DATA
813
                                        where markupData.MARKUPINFO_VERSION_ID == r.MarkupVersionID
814
                                        orderby markupData.PAGENUMBER
815
                                        select new MarkupItem { ID = markupData.ID, PageNumber = markupData.PAGENUMBER, Data = markupData.DATA, Data_Type = markupData.DATA_TYPE, Symbol_ID = markupData.SYMBOL_ID, Group_ID = markupData.GROUP_ID ?? 0 }).ToList();
816
                    });
817

    
818
                    _ColorsProperties colors = new _ColorsProperties();
819
                    Random random = new Random();
820

    
821
                    using (KCOMEntities kcomEntity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
822
                    {
823
                        colors._colorsProperties = (from property in kcomEntity.PROPERTIES
824
                                             where property.TYPE == "DisplayColor"
825
                                             select property).ToList();
826
                    }
827
                    List<DeptColor> deptColor = new List<DeptColor>();
828

    
829
                    List<DeptColor> listTest = new List<DeptColor>();
830
                    //Dictionary<string, string> d = new Dictionary<string, string>();
831
                    var list = new List<KeyValuePair<string, string>>();
832
                    foreach (var test in colors._colorsProperties)
833
                    {
834
                        list.Add(new KeyValuePair<string, string>(test.PROPERTY, test.VALUE));
835
                        //d.Add(test.PROPERTY, test.VALUE);
836
                        listTest.Add(new DeptColor { Property = test.PROPERTY,DisplayColor = test.VALUE});
837
                    }
838
                    
839

    
840
                    foreach (var item in _result)
841
                    {
842
                        var _member = entity.MEMBER.Where(member => member.ID == item.UserID);
843

    
844
                        if (_member.Count() > 0)
845
                        {
846
                            item.UserName = _member.First().NAME;
847
                            item.Depatment = _member.First().DEPARTMENT;
848
                        }
849

    
850
                        if (colors._colorsProperties.Count > 0)
851
                        {
852
                            int colorIdx = random.Next(1, colors._colorsProperties.Count());
853
                            #region 부서별로 색상을 지정하고자 할때
854

    
855
                            if(deptColor.Count > 0)
856
                            {
857
                                foreach (var dept in deptColor)
858
                                {
859
                                    if (dept.Depatment == item.Depatment)
860
                                    {
861
                                        //list에서 deptColor.Property의 값 중 상위의 데이터를 뽑아서 지정하고 list에서 삭제 
862
                                        item.DisplayColor = "#FF" + list.Where(p => p.Key == dept.Property).FirstOrDefault().Value;
863
                                        list.Remove(new KeyValuePair<string, string>(dept.Property, dept.DisplayColor));
864
                                        break;
865
                                    }
866
                                    else
867
                                    {
868
                                        item.DisplayColor = "#FF" + colors._colorsProperties[colorIdx].VALUE;
869
                                        deptColor.Add(new DeptColor { DisplayColor = item.DisplayColor, Depatment = item.Depatment, Property = colors._colorsProperties[colorIdx].PROPERTY });
870
                                        colors._colorsProperties.RemoveAll(p => p.PROPERTY.Equals(colors._colorsProperties[colorIdx].PROPERTY)); //같은 계열의 색상은 지운다
871
                                        break;
872
                                    }
873
                                }
874
                            }
875
                            else
876
                            {
877
                                item.DisplayColor = "#FF" + colors._colorsProperties[colorIdx].VALUE;
878
                                deptColor.Add(new DeptColor { DisplayColor = item.DisplayColor, Depatment = item.Depatment, Property = colors._colorsProperties[colorIdx].PROPERTY });
879
                                colors._colorsProperties.RemoveAll(p => p.PROPERTY.Equals(colors._colorsProperties[colorIdx].PROPERTY)); //같은 계열의 색상은 지운다
880
                            }                                                     
881
                            #endregion
882
                        }
883
                        else
884
                        {
885
                            item.DisplayColor = String.Format("#FF{0:X6}", random.Next(0x1000000));
886
                        }
887
                    }
888
                }
889
            }
890
            catch (Exception EX)
891
            {
892
                System.Diagnostics.Debug.WriteLine(this.GetType().ToString() + " " + EX);
893
                return _result;
894
            }
895
            finally
896
            {
897
                GC.Collect(2);
898
            }
899

    
900
            return _result;
901
        }
902
        */
903
        [OperationContract]
904
        public List<MarkupInfoItem> GetSyncMarkupInfoItems(string ProjectNo, string DocInfoId, string currentUser)
905
        {
906
            List<MarkupInfoItem> _result = new List<MarkupInfoItem>();
907
            try
908
            {
909
                using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
910
                {
911
                    var docItem = entity.DOCINFO.Where(data => data.DOCUMENT_ID == DocInfoId).FirstOrDefault();
912
                    if (docItem == null)
913
                    {
914
                        return null;
915
                    }
916
                    var markupListData = entity.MARKUP_INFO.Where(data => data.DOCINFO_ID == docItem.ID).ToList();
917

    
918
                    var markupList = from markup in markupListData
919
                                     where markup.USER_ID == currentUser || markup.CONSOLIDATE == 1
920
                                     orderby markup.CREATE_TIME descending
921
                                     select new MarkupInfoItem
922
                                     {
923
                                         MarkupInfoID = markup.ID,
924
                                         UserID = markup.USER_ID,
925
                                         MarkupVersionID = markup.MARKUP_INFO_VERSION.Count() == 0 ? null : markup.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID,
926
                                         CreateTime = markup.CREATE_TIME,
927
                                         Consolidate = markup.CONSOLIDATE,
928
                                         Description = markup.DESCRIPTION,
929
                                         AvoidConsolidate = markup.AVOID_CONSOLIDATE,
930
                                         PartConsolidate = markup.PART_CONSOLIDATE,
931
                                     };
932

    
933

    
934

    
935
                    if (markupList.Count() > 0)
936
                    {
937
                        _result = markupList.ToList();
938
                    }
939

    
940

    
941

    
942
                    _result.ForEach(r =>
943
                    {
944

    
945
                        r.MarkupList = (from markupData in entity.MARKUP_DATA
946
                                        where markupData.MARKUPINFO_VERSION_ID == r.MarkupVersionID
947
                                        orderby markupData.PAGENUMBER
948
                                        select new MarkupItem { ID = markupData.ID, PageNumber = markupData.PAGENUMBER, Data = markupData.DATA, Data_Type = markupData.DATA_TYPE, Symbol_ID = markupData.SYMBOL_ID}).ToList();
949
                    });
950

    
951
                    List<PROPERTIES> _ColorsProperties = new List<PROPERTIES>();
952
                    Random random = new Random();
953

    
954
                    using (KCOMEntities kcomEntity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
955
                    {
956
                        _ColorsProperties = (from property in kcomEntity.PROPERTIES
957
                                             where property.TYPE == "DisplayColor"
958
                                             select property).ToList();
959
                    }
960

    
961
                    foreach (var item in _result)
962
                    {
963
                        var _member = entity.MEMBER.Where(member => member.ID == item.UserID);
964

    
965
                        if (_member.Count() > 0)
966
                        {
967
                            item.UserName = _member.First().NAME;
968
                            item.Depatment = _member.First().DEPARTMENT;
969
                        }
970

    
971
                        if (_ColorsProperties.Count > 0)
972
                        {
973
                            int colorIdx = random.Next(1, _ColorsProperties.Count());
974
                            #region 부서별로 색상을 지정하고자 할때
975
                            /// 일단 의견을 들어보자구!
976
                            #endregion
977
                            item.DisplayColor = "#FF" + _ColorsProperties[colorIdx].VALUE;
978
                            _ColorsProperties.Remove(_ColorsProperties[colorIdx]);
979
                            //item.DisplayColor = "#FF" + _Colors.First();
980
                            //_Colors.Remove(_Colors.First());
981
                        }
982
                        else
983
                        {
984
                            item.DisplayColor = String.Format("#FF{0:X6}", random.Next(0x1000000));
985
                        }
986
                    }
987
                }
988
            }
989
            catch (Exception EX)
990
            {
991
                System.Diagnostics.Debug.WriteLine(this.GetType().ToString() + " " + EX);
992
                return _result;
993
            }
994
            finally
995
            {
996
                GC.Collect(2);
997
            }
998

    
999
            return _result;
1000
        }
1001

    
1002

    
1003
        //[OperationContract]
1004
        //[ServiceKnownType(typeof(MEMBER))]
1005
        //public List<MEMBER> GetUserData(string ProjectNo, string UserID)
1006
        //{
1007
        //    List<MEMBER> _result = new List<MEMBER>();
1008

    
1009
        //    using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1010
        //    {
1011
        //        var _UserList = from member in entity.MEMBER
1012
        //                        where member.ID == UserID
1013
        //                        select member;
1014
        //        _result = _UserList.ToList();
1015
        //    }
1016
        //    //GC.Collect(2);
1017
        //    return _result;
1018
        //}
1019

    
1020
        [OperationContract]
1021
        [ServiceKnownType(typeof(MEMBER))]
1022
        public List<MEMBER> GetUserData(string ProjectNo, string UserID)
1023
        {
1024
            List<MEMBER> _result = new List<MEMBER>();
1025

    
1026
            using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1027
            {
1028
                var _UserList = from member in entity.MEMBER
1029
                                where member.ID == UserID
1030
                                select member;
1031
                _result = _UserList.ToList();
1032
            }
1033
            //GC.Collect(2);
1034
            return _result;
1035
        }
1036

    
1037

    
1038
        [OperationContract]
1039
        public List<string> GetDeptData(string UserDept) //그룹 추가 옵션 부여 예정
1040
        {
1041
            List<string> _result = new List<string>();
1042

    
1043
            try
1044
            {
1045
                KCOMEntities entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString());
1046
                var YourEnginner = (from dept in entity.PROPERTIES
1047
                                    where dept.TYPE == "DeptName" && UserDept.Contains(dept.VALUE)
1048
                                    select dept).FirstOrDefault();
1049

    
1050
                if (YourEnginner != null)
1051
                {
1052
                    _result = (from dept in entity.PROPERTIES
1053
                               where dept.PROPERTY == YourEnginner.PROPERTY
1054
                               select dept.VALUE).ToList();
1055
                    return _result;
1056
                }
1057
                else
1058
                {
1059
                    return null;
1060
                }
1061
            }
1062
            catch (Exception ex)
1063
            {
1064
                System.Diagnostics.Debug.WriteLine(ex.Message);
1065
            }
1066
            finally
1067
            {
1068
                GC.Collect(2);
1069
            }
1070
            return _result;
1071
        }
1072

    
1073
        [OperationContract]
1074
        public bool DeleteMarkup(string ProjectNo, string MarkupInfoID)
1075
        {
1076
            bool _result = false;
1077
            try
1078
            {
1079
                using (KCOMDataModel.DataModel.CIEntities Entity = new KCOMDataModel.DataModel.CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1080
                {
1081

    
1082
                    MARKUP_INFO instance = Entity.MARKUP_INFO.Where(root => root.ID == MarkupInfoID).FirstOrDefault();
1083

    
1084
                    if (instance == null)
1085
                    {
1086
                        return false;
1087
                    }
1088
                    MARKUP_INFO_VERSION version = instance.MARKUP_INFO_VERSION.FirstOrDefault();
1089

    
1090

    
1091
                    version.MARKUP_DATA.ToList().ForEach(data =>
1092
                    {
1093
                        Entity.MARKUP_DATA.DeleteObject(data);
1094
                        Entity.SaveChanges();
1095
                    });
1096

    
1097
                    Entity.MARKUP_INFO_VERSION.DeleteObject(version);
1098
                    Entity.SaveChanges();
1099

    
1100
                    Entity.MARKUP_INFO.DeleteObject(instance);
1101
                    Entity.SaveChanges();
1102

    
1103
                }
1104
                _result = true;
1105
            }
1106
            catch (Exception ex)
1107
            {
1108
                System.Diagnostics.Trace.WriteLine(ex, "SaveMarkup");
1109
            }
1110
            finally
1111
            {
1112
                GC.Collect(2);
1113
            }
1114
            return _result;
1115
        }
1116

    
1117
        #region Favorite
1118
        [OperationContract]
1119
        public bool SetFavoriteVP(string prjNo, string userID, string groupNo, string docNo, string rev, int SavePageNo, string documentItemID, string VPDescription, IKCOM.FAVORITE_FLAG flag)
1120
        {
1121

    
1122
            using (KCOMEntities entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
1123
            {
1124
                try
1125
                {
1126
                    entity.FAVORITE_DOC.AddObject(new FAVORITE_DOC
1127
                    {
1128
                        ID = shortGuid(),
1129
                        PROJECT_NO = prjNo,
1130
                        DOCUMENT_ID = documentItemID,
1131
                        GROUP_NO = groupNo,
1132
                        DOCUMENT_NO = docNo,
1133
                        MEMBER_USER_ID = userID,
1134
                        DESCRIPTION = VPDescription,
1135
                        CREATE_TIME = DateTime.Now,
1136
                        REVISION = rev,
1137
                        FLAG = (int)flag,
1138
                        PAGE_NO = SavePageNo,
1139
                    });
1140
                    entity.SaveChanges();
1141
                }
1142
                catch (Exception)
1143
                {
1144
                    return false;
1145
                }
1146

    
1147
                return true;
1148
            }
1149
        }
1150

    
1151
        //[OperationContract]
1152
        //public List<FAVORITE_DOC> GetFavoriteVP(string PrjNo, string userID, string sharepointItemID)
1153
        //{
1154
        //    using (KCOMEntities entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
1155
        //    {
1156

    
1157
        //        int flagString = Convert.ToInt32(IKCOM.FAVORITE_FLAG.Personal);                
1158
        //        List<FAVORITE_DOC> favoriteListSet = new List<FAVORITE_DOC>();
1159
        //        entity.FAVORITE_DOC.Where(data => data.PROJECT_NO == PrjNo && data.DOCUMENT_ID == sharepointItemID && data.FLAG !=
1160
        //            flagString).ToList().ForEach(data => favoriteListSet.Add(data));
1161
        //        entity.FAVORITE_DOC.Where(data => data.PROJECT_NO == PrjNo && data.MEMBER_USER_ID == userID).ToList().ForEach(data => favoriteListSet.Add(data));
1162
        //        favoriteListSet = favoriteListSet.Distinct().ToList();
1163
        //        return favoriteListSet;
1164
        //    }
1165
        //}
1166
        //[OperationContract]
1167
        //public bool EditFavoriteVP(string prjNo, string userID, int SavePageNo, string sharepointItemID, DateTime createTime, int state, string description)
1168
        //{
1169
        //    using (DeepViewEntities dc = new DeepViewEntities(ConnectStringBuilder.DeepViewConnectionString().ToString()))
1170
        //    {
1171
        //        List<FavoriteVP> favoriteSet = dc.FavoriteVP.Where(data => data.ProjectNo == prjNo && data.CreateUserID == userID
1172
        //            && data.PageNo == SavePageNo && data.CreateTime == createTime).ToList();
1173

    
1174
        //        try
1175
        //        {
1176

    
1177

    
1178
        //            if (favoriteSet.Count > 0)
1179
        //            {
1180
        //                var FavoriteVP_Instance = favoriteSet.First();
1181

    
1182
        //                FavoriteVP_Instance.Description = description;
1183
        //                FavoriteVP_Instance.Flag = state;
1184

    
1185
        //                dc.SaveChanges();
1186

    
1187
        //                return true;
1188
        //            }
1189
        //            else
1190
        //            {
1191
        //                return false;
1192
        //            }
1193
        //        }
1194
        //        catch (Exception)
1195
        //        {
1196
        //            return false;
1197
        //        }
1198
        //    }
1199
        //}
1200
        //[OperationContract]
1201
        //public bool DelFavoriteVP(string prjNo, string userID, int SavePageNo, string sharepointItemID, DateTime createTime)
1202
        //{
1203

    
1204
        //    using (DeepViewEntities dc = new DeepViewEntities(ConnectStringBuilder.DeepViewConnectionString().ToString()))
1205
        //    {
1206
        //        List<FavoriteVP> favoriteSet = dc.FavoriteVP.Where(data => data.ProjectNo == prjNo && data.CreateUserID == userID
1207
        //            && data.PageNo == SavePageNo && data.CreateTime == createTime).ToList();
1208

    
1209
        //        try
1210
        //        {
1211

    
1212

    
1213
        //            if (favoriteSet.Count > 0)
1214
        //            {
1215
        //                favoriteSet.ForEach(data => dc.FavoriteVP.DeleteObject(data));
1216
        //                dc.SaveChanges();
1217
        //                return true;
1218
        //            }
1219
        //            else
1220
        //            {
1221
        //                return false;
1222
        //            }
1223
        //        }
1224
        //        catch (Exception)
1225
        //        {
1226
        //            return false;
1227
        //        }
1228
        //    }
1229
        //}
1230
        #endregion
1231

    
1232
        [OperationContract]
1233
        public bool SaveMarkupData(MarkupInfoItem UserState,string project_no,string doc_id, string user_id, List<MARKUP_DATA> mlmarkup_data)
1234
        {
1235
            using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1236
            {     
1237
                #region Docinfo 정보 가져오기
1238

    
1239
                string docinfoid_ = (from info in Entity.DOCINFO
1240
                                     where info.DOCUMENT_ID == doc_id
1241
                                     && info.PROJECT_NO == project_no
1242
                                     select info.ID
1243
                                     ).First().ToString();
1244
                #endregion
1245

    
1246
                #region Markup_Info 저장
1247

    
1248
                MARKUP_INFO markup_info = new MARKUP_INFO();
1249
                try
1250
                {
1251
                    markup_info = (from info in Entity.MARKUP_INFO
1252
                                   where info.ID == UserState.MarkupInfoID && info.USER_ID == user_id
1253
                                   select info).FirstOrDefault();
1254
                }
1255
                catch (Exception)
1256
                {
1257
                    markup_info = null;
1258
                }
1259

    
1260
                //markup_info가 없을 경우 생성
1261
                if (markup_info == null)
1262
                {
1263
                    //MarkupInfo 저장
1264
                    markup_info = new MARKUP_INFO
1265
                    {
1266
                        ID = UserState.MarkupInfoID,
1267
                        DOCINFO_ID = docinfoid_,
1268
                        USER_ID = user_id,
1269
                        CREATE_TIME = DateTime.Now,
1270
                        CONSOLIDATE = UserState.Consolidate,
1271
                        AVOID_CONSOLIDATE = UserState.AvoidConsolidate,
1272
                        PART_CONSOLIDATE = UserState.PartConsolidate,
1273
                        DESCRIPTION = UserState.Description,
1274
                        UPDATE_TIME = DateTime.Now
1275
                    };
1276
                    Entity.MARKUP_INFO.AddObject(markup_info);
1277
                }
1278
                //markup_info가 있을 경우 업데이트
1279
                else
1280
                {
1281
                    markup_info.UPDATE_TIME = DateTime.Now;
1282
                }
1283
                Entity.SaveChanges();
1284
                #endregion
1285

    
1286
                #region Markup_Info_Version 저장
1287

    
1288
                MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1289

    
1290
                try
1291
                {
1292
                    markup_info_version = (from info in Entity.MARKUP_INFO_VERSION
1293
                                           where info.MARKUPINFO_ID == markup_info.ID
1294
                                           select info).FirstOrDefault();
1295
                }
1296
                catch (Exception)
1297
                {
1298
                    markup_info_version = null;
1299
                }
1300

    
1301
                //markup_info_version 없을 경우 생성
1302
                if (markup_info_version == null)
1303
                {
1304
                    //MarkupInfo_version 저장
1305
                    markup_info_version = new MARKUP_INFO_VERSION()
1306
                    {
1307
                        ID = UserState.MarkupVersionID,
1308
                        MARKUPINFO_ID = markup_info.ID,
1309
                        CREATE_DATE = DateTime.Now
1310
                    };
1311
                    Entity.MARKUP_INFO_VERSION.AddObject(markup_info_version);
1312
                    Entity.SaveChanges();
1313
                }
1314
                #endregion
1315

    
1316
                
1317
                Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == markup_info_version.ID).ToList().ForEach(item =>
1318
                {
1319
                    Entity.MARKUP_DATA.DeleteObject(item);
1320
                });
1321
                Entity.SaveChanges();
1322

    
1323
                try
1324
                {
1325
                    mlmarkup_data.ForEach(value =>
1326
                    {
1327
                        Entity.MARKUP_DATA.AddObject(new MARKUP_DATA
1328
                        {
1329
                            ID = value.ID,
1330
                            DATA = value.DATA,
1331
                            DATA_TYPE = value.DATA_TYPE,
1332
                            PAGENUMBER = value.PAGENUMBER,
1333
                            MARKUPINFO_VERSION_ID = markup_info_version.ID,
1334
                            SYMBOL_ID = value.SYMBOL_ID,
1335
                            //GROUP_ID = value.GROUP_ID
1336
                        });
1337
                    });
1338
                    Entity.SaveChanges();
1339
                }
1340
                catch (Exception)
1341
                {
1342
                    return false;
1343
                }
1344
            }
1345
            return true;
1346
        }
1347

    
1348
        //[OperationContract]
1349
        //public long AddMarkupDataGroup(MARKUP_DATA_GROUP mARKUP_DATA_GROUP, string ProjectNo)
1350
        //{
1351
        //    try
1352
        //    {
1353
        //        using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1354
        //        {
1355
        //            Entity.AddToMARKUP_DATA_GROUP(mARKUP_DATA_GROUP);
1356
        //            //MARKUP_DATA_GROUP tt = Entity.MARKUP_DATA_GROUP.Where(info => info.ID == id).FirstOrDefault();
1357
        //            Entity.SaveChanges();
1358

    
1359
        //            return Entity.MARKUP_DATA_GROUP.ToList().LastOrDefault().ID;
1360
        //        }
1361
        //    }
1362
        //    catch (Exception)
1363
        //    {
1364
        //        return 0;
1365
        //    }
1366
        //}
1367
        //[OperationContract]
1368
        //public bool UpdateMarkupDataGroup(long Group_ID, string ProjectNo)
1369
        //{
1370
        //    try
1371
        //    {
1372
        //        using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1373
        //        {
1374
        //            var UpdateItem = Entity.MARKUP_DATA_GROUP.Where(info => info.ID == Group_ID).FirstOrDefault();
1375
        //            UpdateItem.STATE = 1;
1376
        //            Entity.SaveChanges();
1377
        //        }
1378
        //    }
1379
        //    catch (Exception)
1380
        //    {
1381
        //        return false;
1382
        //    }
1383
        //    return true;
1384
        //}
1385
        [OperationContract]
1386
        public bool UpdateMarkupData(string CommentID, long Group_ID, string ProjectNo)
1387
        {
1388
            try
1389
            {
1390
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1391
                {
1392
                    var UpdateItem = Entity.MARKUP_DATA.Where(info => info.ID == CommentID).FirstOrDefault();
1393
                    //UpdateItem.GROUP_ID = Group_ID;
1394
                    Entity.SaveChanges();
1395
                }
1396
            }
1397
            catch (Exception)
1398
            {
1399
                return false;
1400
            }
1401
            return true;
1402
        }
1403

    
1404
        [OperationContract]
1405
        public bool SaveSymbol(SYMBOL_PRIVATE symbol_private)
1406
        {
1407
            try
1408
            {
1409
                using (KCOMDataModel.DataModel.KCOMEntities uc = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
1410
                {
1411
                    uc.AddToSYMBOL_PRIVATE(symbol_private);
1412
                    uc.SaveChanges();
1413
                }
1414
            }
1415
            catch(Exception)
1416
            {
1417
                return false;
1418
            }
1419
            return true;
1420
        }
1421
        [OperationContract]
1422
        public bool AddPublicSymbol(SYMBOL_PUBLIC symbol)
1423
        {
1424
            try
1425
            {
1426
                using (KCOMDataModel.DataModel.KCOMEntities uc = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
1427
                {
1428
                    uc.AddToSYMBOL_PUBLIC(symbol);
1429
                    uc.SaveChanges();
1430
                }
1431
            }
1432
            catch (Exception)
1433
            {
1434
                return false;
1435
            }
1436
            return true;
1437
        }
1438
        [OperationContract]
1439
        public bool DeleteSymbol(string symbol_id, int type)
1440
        {
1441
            try
1442
            {
1443
                using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
1444
                {
1445
                    if (type == 0)
1446
                    {
1447
                        string delItem_ID = symbol_id;
1448
                        var delitem = Entity.SYMBOL_PRIVATE.Where(data => data.ID == delItem_ID).FirstOrDefault();
1449
                        Entity.SYMBOL_PRIVATE.DeleteObject(delitem);
1450
                        Entity.SaveChanges();
1451
                    }
1452
                    else
1453
                    {
1454
                        string delItem_ID = symbol_id;
1455
                        var delitem = Entity.SYMBOL_PUBLIC.Where(data => data.ID == delItem_ID).FirstOrDefault();
1456
                        Entity.SYMBOL_PUBLIC.DeleteObject(delitem);
1457
                        Entity.SaveChanges();
1458
                    }
1459
                }
1460
            }
1461
            catch(Exception)
1462
            {
1463
                return false;
1464
            }
1465
            return true;
1466
        }
1467

    
1468
        [OperationContract]
1469
        public bool RenameSymbol(string symbol_id, string name, int type)
1470
        {
1471
            try
1472
            {
1473
                using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
1474
                {
1475
                    if (type == 0)
1476
                    {
1477
                        var UpdateItem = Entity.SYMBOL_PRIVATE.Where(info => info.ID == symbol_id).FirstOrDefault();
1478
                        UpdateItem.NAME = name;
1479
                        Entity.SaveChanges();
1480
                    }
1481
                    else
1482
                    {
1483
                        var UpdateItem = Entity.SYMBOL_PUBLIC.Where(info => info.ID == symbol_id).FirstOrDefault();
1484
                        UpdateItem.NAME = name;
1485
                        Entity.SaveChanges();
1486
                    }
1487
                }
1488
            }
1489
            catch (Exception)
1490
            {
1491
                return false;
1492
            }
1493
            return true;
1494
        }
1495

    
1496
        [OperationContract]
1497
        public bool AddCheckListHistory(string project_no, CHECK_LIST_HISTORY Check_History)
1498
        {
1499
            try
1500
            {                
1501
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1502
                {
1503
                    Entity.CHECK_LIST_HISTORY.AddObject(Check_History);
1504
                    Entity.SaveChanges();  
1505
                }
1506
            }
1507
            catch (Exception)
1508
            {
1509
                return false;
1510
            }
1511
            return true;
1512
        }
1513
        [OperationContract]
1514
        public bool SaveCheckListHistory(string project_no, string rev, CHECK_LIST_HISTORY Check_History)
1515
        {
1516
            try
1517
            {
1518
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1519
                {
1520
                    var item = Entity.CHECK_LIST_HISTORY.Where(info => info.REVISION == rev).FirstOrDefault();
1521
                    item = Check_History;
1522
                    Entity.SaveChanges();
1523
                }
1524
            }
1525
            catch (Exception)
1526
            {
1527
                return false;
1528
            }
1529
            return true;
1530
        }
1531
        [OperationContract]
1532
        public bool SaveCheckList(string project_no, string _id, CHECK_LIST Check_value)
1533
        {
1534
            try
1535
            {
1536
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1537
                {
1538
                    var item = Entity.CHECK_LIST.Where(info => info.ID == _id).FirstOrDefault();
1539
                    item.TODOLIST = Check_value.TODOLIST;
1540
                    item.REMARK = Check_value.REMARK;
1541
                    item.STATUS = Check_value.STATUS;
1542
                    item.VENDOR = Check_value.VENDOR;
1543
                    item.REPLY = Check_value.REPLY;
1544
                    item.IMAGE_URL = Check_value.IMAGE_URL;
1545
                    item.IMAGE_ANCHOR = Check_value.IMAGE_ANCHOR;
1546
                    item.UPDATE_TIME = Check_value.UPDATE_TIME;
1547
                    if(Check_value.STATUS == "False")
1548
                    {
1549
                        item.STATUS_DESC_OPEN = Check_value.STATUS_DESC_OPEN;
1550
                    }
1551
                    else
1552
                    {
1553
                        item.STATUS_DESC_CLOSE = Check_value.STATUS_DESC_CLOSE;
1554
                    }                     
1555
                    Entity.SaveChanges();
1556
                }
1557
            }
1558
            catch (Exception)
1559
            {
1560
                return false;
1561
            }
1562
            return true;
1563
        }
1564
        [OperationContract]
1565
        public bool AddCheckList(string project_no, CHECK_LIST Check_value)
1566
        {
1567
            try
1568
            {
1569
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1570
                {
1571
                    Entity.CHECK_LIST.AddObject(Check_value);
1572
                    Entity.SaveChanges();
1573
                }
1574
            }
1575
            catch (Exception)
1576
            {
1577
                return false;
1578
            }
1579
            return true;
1580
        }
1581

    
1582
        [OperationContract]
1583
        public CHECK_LIST GetCheckList(string project_no, string _id)
1584
        {
1585
            CHECK_LIST Check_value = new CHECK_LIST();
1586
            try
1587
            {
1588
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1589
                {
1590
                    Check_value = Entity.CHECK_LIST.Where(info => info.ID == _id).FirstOrDefault();
1591
                }
1592
            }
1593
            catch (Exception)
1594
            {
1595
                return null;
1596
            }
1597
            return Check_value;
1598
        }
1599
        [OperationContract]
1600
        public List<CHECK_LIST> GetUserCheckList(string project_no, string user_id, string doc_no)
1601
        {
1602
            List<CHECK_LIST> list = new List<CHECK_LIST>();
1603
            try
1604
            {
1605
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1606
                {
1607
                    list = Entity.CHECK_LIST.Where(i => i.PROJECT_NO == project_no && i.DOCUMENT_NO == doc_no && i.USER_ID == user_id).OrderBy(p => p.CREATE_TIME).ToList();
1608
                }
1609
            }
1610
            catch (Exception)
1611
            {
1612
                return null;
1613
            }
1614
            return list;
1615
        }
1616
        [OperationContract]
1617
        public List<CHECK_LIST_HISTORY> GetCheckListHistory(string project_no, string _id)
1618
        {
1619
            List<CHECK_LIST_HISTORY> history = new List<CHECK_LIST_HISTORY>();
1620
            try
1621
            {
1622
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1623
                {
1624
                    history = Entity.CHECK_LIST_HISTORY.Where(data => data.CHECKLIST_ID == _id).ToList();
1625
                }
1626
            }
1627
            catch (Exception)
1628
            {
1629
                return null;
1630
            }
1631
            return history;
1632
        }
1633
        [OperationContract]
1634
        public CHECK_LIST_HISTORY GetCheckListHistoryFirstOrDefault(string project_no, string checklist_id, string rev)
1635
        {
1636
            CHECK_LIST_HISTORY Check_Item = new CHECK_LIST_HISTORY();
1637
            try
1638
            {
1639
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1640
                {   
1641
                    Check_Item = Entity.CHECK_LIST_HISTORY.Where(info => info.CHECKLIST_ID == checklist_id && info.REVISION == rev).FirstOrDefault();
1642
                }
1643
            }
1644
            catch (Exception)
1645
            {
1646
                return null;
1647
            }
1648
            return Check_Item;
1649
        }
1650
        [OperationContract]
1651
        public bool SavePageAngle(string project_no, List<DOCPAGE> _mldocpage)
1652
        {
1653
            try
1654
            {
1655
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1656
                {
1657
                    KCOMDataModel.DataModel.DOCPAGE _docpage = new KCOMDataModel.DataModel.DOCPAGE();
1658
                    _mldocpage.ForEach(data =>
1659
                    {
1660
                        _docpage = (from info in Entity.DOCPAGE
1661
                                    where info.ID == data.ID
1662
                                    select info).FirstOrDefault();
1663

    
1664
                        if (_docpage.PAGE_ANGLE != data.PAGE_ANGLE)
1665
                        {
1666
                            _docpage.PAGE_ANGLE = data.PAGE_ANGLE;
1667
                        }
1668
                    });
1669

    
1670
                    Entity.SaveChanges();
1671
                }
1672
            }
1673
            catch (Exception)
1674
            {
1675
                return false;
1676
            }
1677
            return true;
1678
        }
1679

    
1680
        [OperationContract]
1681
        public MARKUP_INFO GetMarkupInfo(string project_no, string _id)
1682
        {
1683
            MARKUP_INFO markupInfo = new MARKUP_INFO();
1684

    
1685
            try
1686
            {
1687
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1688
                {
1689
                    markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1690
                }
1691
            }
1692
            catch (Exception)
1693
            {
1694
                return null;
1695
            }
1696
            return markupInfo;
1697
        }
1698

    
1699
        [OperationContract]
1700
        public List<string> GetMarkupDataListperPage(string project_no, string _markupinfoid, int _pageNo)
1701
        {
1702
            List<string> markupdata = new List<string>();
1703
            MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1704
            try
1705
            {
1706
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1707
                {
1708
                    markup_info_version = (from version in Entity.MARKUP_INFO_VERSION
1709
                                           where version.MARKUPINFO_ID == _markupinfoid
1710
                                           orderby version.CREATE_DATE descending
1711
                                           select version).First();
1712
                    markupdata = (from data in Entity.MARKUP_DATA
1713
                                  where data.MARKUPINFO_VERSION_ID == markup_info_version.ID && data.PAGENUMBER == _pageNo
1714
                                  select data.DATA).ToList();
1715
                }
1716
            }
1717
            catch (Exception)
1718
            {
1719
                return null;
1720
            }
1721
            return markupdata;
1722
        }
1723

    
1724
        [OperationContract]
1725
        public bool AddMarkupInfo(string project_no, MARKUP_INFO value)
1726
        {
1727
            try
1728
            {
1729
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1730
                {
1731
                    Entity.MARKUP_INFO.AddObject(value);
1732
                    Entity.SaveChanges();
1733
                }
1734
            }
1735
            catch (Exception)
1736
            {
1737
                return false;
1738
            }
1739
            return true;
1740
        }
1741

    
1742
        [OperationContract]
1743
        public bool AddMarkupInfoVersion(string project_no, MARKUP_INFO_VERSION value)
1744
        {
1745
            try
1746
            {
1747
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1748
                {
1749
                    Entity.MARKUP_INFO_VERSION.AddObject(value);
1750
                    Entity.SaveChanges();
1751
                }
1752
            }
1753
            catch (Exception)
1754
            {
1755
                return false;
1756
            }
1757
            return true;
1758
        }
1759

    
1760
        [OperationContract]
1761
        public bool AddMarkupData(string project_no, MARKUP_DATA value)
1762
        {
1763
            try
1764
            {
1765
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1766
                {
1767
                    Entity.MARKUP_DATA.AddObject(value);
1768
                    Entity.SaveChanges();
1769
                }
1770
            }
1771
            catch (Exception)
1772
            {
1773
                return false;
1774
            }
1775
            return true;
1776
        }
1777

    
1778
        [OperationContract]
1779
        public bool AvoidMarkupInfo(string project_no, string _doc_id)
1780
        {
1781
            try
1782
            {
1783
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1784
                {
1785
                    var item = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1786
                    item.AVOID_CONSOLIDATE = 1;
1787
                    Entity.SaveChanges();
1788
                }
1789
            }
1790
            catch (Exception)
1791
            {
1792
                return false;
1793
            }
1794
            return true;
1795
        }
1796

    
1797
        [OperationContract]
1798
        public bool SaveMarkupInfo(string project_no, string _id, MARKUP_INFO value)
1799
        {
1800
            try
1801
            {
1802
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1803
                {
1804
                    var item = Entity.MARKUP_INFO.Where(info => info.ID == _id).FirstOrDefault();
1805
                    item = value;                    
1806
                    Entity.SaveChanges();
1807
                }
1808
            }
1809
            catch (Exception)
1810
            {
1811
                return false;
1812
            }
1813
            return true;
1814
        }
1815
        [OperationContract]
1816
        public List<MARKUP_DATA> GetMarkupDataList(string project_no, string _versionid)
1817
        {
1818
            List<MARKUP_DATA> mlresult = new List<MARKUP_DATA>();
1819

    
1820
            try
1821
            {
1822
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1823
                {
1824
                    mlresult = Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == _versionid).ToList();
1825
                }
1826
            }
1827
            catch (Exception)
1828
            {
1829
                return null;
1830
            }
1831
            return mlresult;
1832
        }
1833

    
1834
        [OperationContract]
1835
        public bool Consolidate(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems)
1836
        {
1837
            try
1838
            {
1839
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
1840
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1841
                {
1842
                    var markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id && entity.CONSOLIDATE == 1).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1843
                    if (markupInfo != null)
1844
                    {
1845
                        markupInfo.AVOID_CONSOLIDATE = 1;
1846
                    }
1847

    
1848
                    foreach (MarkupInfoItem item in markupInfoItems)
1849
                    {
1850
                        Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == item.MarkupVersionID).ToList().ForEach(d =>
1851
                        {
1852
                            instanceDataSet.Add(d);
1853
                        });
1854
                    }
1855

    
1856
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
1857
                    info.ID = shortGuid();
1858
                    info.CONSOLIDATE = 1;
1859
                    info.CREATE_TIME = DateTime.Now;
1860
                    info.DOCINFO_ID = _doc_id;
1861
                    info.UPDATE_TIME = DateTime.Now;
1862
                    info.USER_ID = _user_id;
1863
                    info.AVOID_CONSOLIDATE = 0;
1864

    
1865
                    Entity.MARKUP_INFO.AddObject(info);
1866
                    Entity.SaveChanges();
1867

    
1868

    
1869
                    KCOMDataModel.DataModel.MARKUP_INFO_VERSION info2 = new KCOMDataModel.DataModel.MARKUP_INFO_VERSION
1870
                    {
1871
                        ID = shortGuid(),
1872
                        CREATE_DATE = DateTime.Now,
1873
                        MARKUP_INFO = info,
1874
                    };
1875
                    Entity.SaveChanges();
1876

    
1877
                    foreach (var item in instanceDataSet)
1878
                    {
1879
                        Entity.MARKUP_DATA.AddObject(new KCOMDataModel.DataModel.MARKUP_DATA
1880
                        {
1881
                            ID = shortGuid(),
1882
                            DATA = item.DATA,
1883
                            DATA_TYPE = item.DATA_TYPE,
1884
                            PAGENUMBER = item.PAGENUMBER,
1885
                            MARKUP_INFO_VERSION = info2,
1886
                            SYMBOL_ID = item.SYMBOL_ID,
1887
                            //GROUP_ID = item.GROUP_ID
1888
                        });
1889
                    }
1890
                    Entity.SaveChanges();
1891

    
1892

    
1893
                }
1894
            }
1895
            catch (Exception)
1896
            {
1897
                return false;
1898
            }
1899
            return true;
1900
        }
1901

    
1902

    
1903
        [OperationContract]
1904
        public FinalPDFResult ConsolidateMergedPDF(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems, string ProjectNo, string DocInfoID, string CreateUserID)
1905
        {
1906
            bool consolidate = false;
1907
            try
1908
            {
1909
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
1910
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
1911
                {
1912
                    var markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1913
                    if (markupInfo.CONSOLIDATE == 1)
1914
                    {
1915
                        markupInfo.AVOID_CONSOLIDATE = 1;
1916
                    }
1917

    
1918
                    foreach (MarkupInfoItem item in markupInfoItems)
1919
                    {
1920
                        Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == item.MarkupVersionID).ToList().ForEach(d =>
1921
                        {
1922
                            instanceDataSet.Add(d);
1923
                        });
1924
                    }
1925

    
1926
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
1927
                    info.ID = shortGuid();
1928
                    info.CONSOLIDATE = 1;
1929
                    info.CREATE_TIME = DateTime.Now;
1930
                    info.DOCINFO_ID = _doc_id;
1931
                    info.UPDATE_TIME = DateTime.Now;
1932
                    info.USER_ID = _user_id;
1933
                    info.AVOID_CONSOLIDATE = 0;
1934

    
1935
                    Entity.MARKUP_INFO.AddObject(info);
1936
                    Entity.SaveChanges();
1937

    
1938

    
1939
                    KCOMDataModel.DataModel.MARKUP_INFO_VERSION info2 = new KCOMDataModel.DataModel.MARKUP_INFO_VERSION
1940
                    {
1941
                        ID = shortGuid(),
1942
                        CREATE_DATE = DateTime.Now,
1943
                        MARKUP_INFO = info,
1944
                    };
1945
                    Entity.SaveChanges();
1946

    
1947
                    foreach (var item in instanceDataSet)
1948
                    {
1949
                        Entity.MARKUP_DATA.AddObject(new KCOMDataModel.DataModel.MARKUP_DATA
1950
                        {
1951
                            ID = shortGuid(),
1952
                            DATA = item.DATA,
1953
                            DATA_TYPE = item.DATA_TYPE,
1954
                            PAGENUMBER = item.PAGENUMBER,
1955
                            MARKUP_INFO_VERSION = info2,
1956
                            SYMBOL_ID = item.SYMBOL_ID,
1957
                            //GROUP_ID = item.GROUP_ID
1958
                        });
1959
                    }
1960
                    Entity.SaveChanges();
1961

    
1962

    
1963
                }
1964
                consolidate = true;
1965
            }
1966
            catch (Exception)
1967
            {
1968
                consolidate = false;
1969
            }
1970
            FinalPDFResult _result = new FinalPDFResult();
1971
            if (consolidate == true)
1972
            {
1973
                RemFinalPDFObject remObj = null;
1974
                try
1975
                {
1976
                    string _finalID = shortGuid();
1977
                    int _DocTotalPages = -1;
1978
                    string docItemId;
1979

    
1980

    
1981
                    using (CIEntities _ci = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1982
                    {
1983
                        var _doc = _ci.DOCINFO.Where(info => info.ID == DocInfoID);
1984

    
1985
                        if (_doc.Count() > 0)
1986
                        {
1987
                            _DocTotalPages = _doc.First().PAGE_COUNT;
1988
                            docItemId = _doc.First().DOCUMENT_ID;
1989
                        }
1990
                        else
1991
                        {
1992
                            _result.Status = FinalStatus.Error;
1993
                            _result.Exception = "페이지 정보를 가져올 수 없습니다.";
1994
                            return _result;
1995
                        }
1996
                    }
1997

    
1998
                    var Items = GetMarkupInfoItems(ProjectNo, DocInfoID);
1999
                    if (_DocTotalPages > 0)
2000
                    {
2001
                        var item2 = Items.Cast<MarkupInfoItem>().Where(d => d.Consolidate == 1 && d.AvoidConsolidate == 0).FirstOrDefault();
2002
                        FINAL_PDF fm = new FINAL_PDF()
2003
                        {
2004
                            ID = _finalID,
2005
                            PROJECT_NO = ProjectNo,
2006
                            DOCINFO_ID = DocInfoID,
2007
                            DOCUMENT_ID = docItemId,
2008
                            MARKUPINFO_ID = item2.MarkupInfoID,
2009
                            CREATE_USER_ID = CreateUserID,
2010
                            TOTAL_PAGE = _DocTotalPages,
2011
                            CREATE_DATETIME = DateTime.Now,
2012
                            STATUS = (int)IFinalPDF.FinalStatus.Insert
2013
                        };
2014
                        using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
2015
                        {
2016
                            _entity.AddToFINAL_PDF(fm);
2017
                            _entity.SaveChanges(System.Data.Objects.SaveOptions.AcceptAllChangesAfterSave);
2018
                        };
2019

    
2020
                        System.Runtime.Remoting.Channels.IChannel _ch = System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp");
2021
                        if (_ch == null)
2022
                        {
2023
                            chan = new TcpChannel();
2024
                            _ChanID = chan.ChannelName;
2025
                            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan, false);
2026
                            // Create an instance of the remote object
2027

    
2028

    
2029
                            using (KCOMEntities ec = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
2030
                            {
2031

    
2032
                                //remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
2033
                                //                          "tcp://localhost:9092/remFinalPDF");
2034
                                remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
2035
                                                          //"tcp://192.168.0.67:9092/remFinalPDF");
2036
                                                          "tcp://192.168.0.67:9092/remFinalPDF");
2037
                            }
2038

    
2039
                            //"tcp://localhost:8080/remFinalPDF");
2040

    
2041
                            _result = remObj.SetFinalPDF(ProjectNo, _finalID);
2042
                            _result.FinalID = _finalID;
2043
                            _result.Status = FinalStatus.Success;
2044

    
2045
                            //MarkupToPDF.MarkupToPDF fa = new MarkupToPDF.MarkupToPDF();
2046
                            //fa.MakeFinalPDF(fm);
2047
                        }
2048
                        else
2049
                        {
2050
                            _ChanID = _ch.ChannelName;
2051
                        }
2052
                    }
2053
                }
2054
                catch (Exception ex)
2055
                {
2056
                    _result.Status = FinalStatus.Error;
2057

    
2058
                    if (ex.GetType() == typeof(System.Net.Sockets.SocketException))
2059
                        _result.Exception = "Final Server Not Connection";
2060
                }
2061
                finally
2062
                {
2063
                    remObj = null;
2064
                    if (System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp") != null)
2065
                        System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(chan);
2066

    
2067
                    GC.Collect(2);
2068
                }
2069
            }
2070
            return _result;
2071
        }
2072
        [OperationContract]
2073
        public bool TeamConsolidate(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems)
2074
        {
2075
            try
2076
            {
2077
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
2078
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2079
                {
2080
                    string user_dept = Entity.MEMBER.Where(m => m.ID == _user_id).FirstOrDefault().DEPARTMENT;
2081
                    var markupInfos = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id
2082
                    && entity.PART_CONSOLIDATE == 1
2083
                    ).OrderByDescending(j => j.CREATE_TIME).ToList();
2084
                    foreach (var markupinfo in markupInfos)
2085
                    {
2086
                        string markupdept = Entity.MEMBER.Where(m => m.ID == markupinfo.USER_ID).FirstOrDefault().DEPARTMENT;
2087
                        if (user_dept == markupdept)
2088
                        {
2089
                            markupinfo.AVOID_CONSOLIDATE = 1;
2090
                        }
2091
                    }
2092

    
2093
                    foreach (MarkupInfoItem item in markupInfoItems)
2094
                    {
2095
                        Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == item.MarkupVersionID).ToList().ForEach(d =>
2096
                        {
2097
                            instanceDataSet.Add(d);
2098
                        });
2099
                    }
2100

    
2101
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
2102
                    info.ID = shortGuid();
2103
                    info.PART_CONSOLIDATE = 1;
2104
                    info.CREATE_TIME = DateTime.Now;
2105
                    info.DOCINFO_ID = _doc_id;
2106
                    info.UPDATE_TIME = DateTime.Now;
2107
                    info.USER_ID = _user_id;
2108
                    info.AVOID_CONSOLIDATE = 0;
2109

    
2110
                    Entity.MARKUP_INFO.AddObject(info);
2111
                    Entity.SaveChanges();
2112

    
2113

    
2114
                    KCOMDataModel.DataModel.MARKUP_INFO_VERSION info2 = new KCOMDataModel.DataModel.MARKUP_INFO_VERSION
2115
                    {
2116
                        ID = shortGuid(),
2117
                        CREATE_DATE = DateTime.Now,
2118
                        MARKUP_INFO = info,
2119
                    };
2120
                    Entity.SaveChanges();
2121

    
2122
                    foreach (var item in instanceDataSet)
2123
                    {
2124
                        Entity.MARKUP_DATA.AddObject(new KCOMDataModel.DataModel.MARKUP_DATA
2125
                        {
2126
                            ID = shortGuid(),
2127
                            DATA = item.DATA,
2128
                            DATA_TYPE = item.DATA_TYPE,
2129
                            PAGENUMBER = item.PAGENUMBER,
2130
                            MARKUP_INFO_VERSION = info2,
2131
                            SYMBOL_ID = item.SYMBOL_ID,
2132
                            //GROUP_ID = item.GROUP_ID
2133
                        });
2134
                    }
2135
                    Entity.SaveChanges();
2136

    
2137

    
2138
                }
2139
            }
2140
            catch (Exception)
2141
            {
2142
                return false;
2143
            }
2144
            return true;
2145
        }
2146

    
2147
        [OperationContract]
2148
        [ServiceKnownType(typeof(MEMBER))]
2149
        public MEMBER GetMember(string project_no, string user_id)
2150
        {
2151
            MEMBER rstmember = new MEMBER();
2152
            try
2153
            {
2154
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2155
                {
2156
                    var tmp = (from member in Entity.MEMBER
2157
                                    where member.ID == user_id
2158
                                    select member).FirstOrDefault();
2159
                    rstmember.DEPARTMENT = tmp.DEPARTMENT;
2160
                    rstmember.ID = tmp.ID;
2161
                    rstmember.NAME = tmp.NAME;
2162
                }
2163
            }
2164
            catch (Exception)
2165
            {
2166
                return null;
2167
            }
2168
            return rstmember;
2169
        }
2170

    
2171
        [OperationContract]
2172
        public List<SYMBOL_PRIVATE> GetSymbolList(string user_id)
2173
        {
2174
            List<SYMBOL_PRIVATE> Custom_List = new List<SYMBOL_PRIVATE>();
2175
            try
2176
            {
2177
                using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
2178
                {
2179
                    Custom_List = Entity.SYMBOL_PRIVATE.Where(data => data.MEMBER_USER_ID == user_id).ToList();
2180
                }
2181
            }
2182
            catch (Exception)
2183
            {
2184
                return null;
2185
            }
2186
            return Custom_List;
2187
        }
2188
        [OperationContract]
2189
        public List<string> GetPublicSymbolDeptList()
2190
        {
2191
            List<string> Custom_List = new List<string>();
2192
            try
2193
            {
2194
                using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
2195
                {
2196
                    Custom_List = Entity.SYMBOL_PUBLIC.Select(data => data.DEPARTMENT).Distinct().ToList();
2197
                }
2198
            }
2199
            catch (Exception)
2200
            {
2201
                return null;
2202
            }
2203
            return Custom_List;
2204
        }
2205
        [OperationContract]
2206
        public List<SYMBOL_PUBLIC> GetPublicSymbolList(string dept)
2207
        {
2208
            List<SYMBOL_PUBLIC> Custom_List = new List<SYMBOL_PUBLIC>();
2209
            try
2210
            {
2211
                using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
2212
                {
2213
                    if(!string.IsNullOrEmpty(dept))
2214
                    {
2215
                        Custom_List = Entity.SYMBOL_PUBLIC.Where(data => data.DEPARTMENT == dept).ToList();
2216
                    }
2217
                    else
2218
                    {
2219
                        Custom_List = Entity.SYMBOL_PUBLIC.ToList();
2220
                    }
2221
                    
2222
                }
2223
            }
2224
            catch (Exception)
2225
            {
2226
                return null;
2227
            }
2228
            return Custom_List;
2229
        }
2230

    
2231
        /// <summary>
2232
        /// 
2233
        /// </summary>
2234
        /// <param name="id">symbol id</param>
2235
        /// <param name="type"> 0 : PRIVATE, 1 : PUBLIC</param>
2236
        /// <returns></returns>
2237
        [OperationContract]
2238
        public string GetSymbolData(string id, int type)
2239
        {
2240
            string result;
2241
            try
2242
            {
2243
                using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
2244
                {
2245
                    if(type == 0)
2246
                    {
2247
                        result = Entity.SYMBOL_PRIVATE.Where(data => data.ID == id).FirstOrDefault().DATA;
2248
                    }
2249
                    else
2250
                    {
2251
                        result = Entity.SYMBOL_PUBLIC.Where(data => data.ID == id).FirstOrDefault().DATA;
2252
                    }
2253
                }
2254
            }
2255
            catch (Exception)
2256
            {
2257
                return null;
2258
            }
2259
            return result;
2260
        }
2261
        [OperationContract]
2262
        public string GetSymbolImageURL(string id, int type)
2263
        {
2264
            string result;
2265
            try
2266
            {
2267
                using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
2268
                {
2269
                    if (type == 0)
2270
                    {
2271
                        result = Entity.SYMBOL_PRIVATE.Where(data => data.ID == id).FirstOrDefault().IMAGE_URL;
2272
                    }
2273
                    else
2274
                    {
2275
                        result = Entity.SYMBOL_PUBLIC.Where(data => data.ID == id).FirstOrDefault().IMAGE_URL;
2276
                    }
2277
                }
2278
            }
2279
            catch (Exception)
2280
            {
2281
                return null;
2282
            }
2283
            return result;
2284
        }
2285
        [OperationContract]
2286
        public string GetSignData(string project_no, string user_id)
2287
        {
2288
            string result = null;
2289
            try
2290
            {
2291
                string ifsign = getEnsembleSign(user_id);
2292
                if (string.IsNullOrEmpty(ifsign))
2293
                {
2294
                    var ModelWFConnectionString = ConnectStringBuilder.ProjectCIConnectString(project_no).ToString();
2295
                    if (null != ModelWFConnectionString)
2296
                    {
2297
                        using (CIEntities entity = new CIEntities(ModelWFConnectionString))
2298
                        {
2299
                            var _sign = entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == user_id);
2300
                            if (_sign.Count() > 0)
2301
                            {
2302
                                result = _sign.First().SIGN_STR;
2303
                            }
2304
                            else
2305
                            {
2306
                                return null;
2307
                            }
2308
                        }
2309
                    }
2310
                }
2311
                else
2312
                {
2313
                    result = ifsign;
2314
                }
2315

    
2316
            }
2317
            catch (Exception)
2318
            {
2319
                return null;
2320
            }
2321
            return result;
2322
        }
2323

    
2324
        [OperationContract]        
2325
        public string GetProjectName(string project_no)
2326
        {
2327
            string result = null;
2328

    
2329
            try
2330
            {
2331
                using (KCOMDataModel.DataModel.KCOMEntities Entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
2332
                {
2333
                    result = Entity.RUN_PROJECTS.Where(i => i.PROJECT_NO == project_no).FirstOrDefault().PROJECT_NAME.ToString();
2334
                }
2335
            }
2336
            catch (Exception)
2337
            {
2338
                return null;
2339
            }
2340
            return result;
2341
        }
2342

    
2343
        [OperationContract]
2344
        public List<DOCUMENT_ITEM> GetPreRevSelect(string project_no, string doc_no, string current_rev)
2345
        {
2346
            List<DOCUMENT_ITEM> result = new List<DOCUMENT_ITEM>();
2347
            
2348
            try
2349
            {
2350
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2351
                {
2352
                    result = Entity.DOCUMENT_ITEM.Where(i => i.PROJECT_NO == project_no
2353
                    && i.DOCUMENT_NO == doc_no
2354
                    && i.REVISION != current_rev).OrderByDescending(i => i.GROUP_NO).ToList();
2355
                }
2356
            }
2357
            catch (Exception)
2358
            {
2359
                return null;
2360
            }
2361
            return result;
2362
        }
2363

    
2364
        [OperationContract]
2365
        public DOCINFO GetDocInfoOneSelect(string project_no, string doc_id)
2366
        {
2367
            DOCINFO docinfo = null;
2368

    
2369
            try
2370
            {
2371
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2372
                {
2373
                    docinfo = (from info in Entity.DOCINFO
2374
                              where info.DOCUMENT_ID == doc_id
2375
                              && info.PROJECT_NO == project_no
2376
                              select info).First();
2377
                }
2378
            }
2379
            catch (Exception)
2380
            {
2381
                return null;
2382
            }
2383
            return docinfo;
2384
        }
2385

    
2386
        [OperationContract]
2387
        public List<MarkupInfoItem> GetPrintDocItemList(string project_no, string doc_id, List<MarkupInfoItem> _markupInfoList)
2388
        {
2389
            MarkupInfoItem _result = null;
2390
            List<MarkupInfoItem> markupinfo = new List<MarkupInfoItem>();
2391
            try
2392
            {
2393
                using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2394
                {
2395
                    var docitem = (from info in Entity.DOCINFO
2396
                               where info.DOCUMENT_ID == doc_id
2397
                               && info.PROJECT_NO == project_no
2398
                               select info).First();
2399

    
2400
                    foreach (MARKUP_INFO markinfo in docitem.MARKUP_INFO)
2401
                    {
2402
                        var member = (from mem in Entity.MEMBER
2403
                                     where mem.ID == markinfo.USER_ID
2404
                                     select mem).First();
2405
                        string displaycolor = null;
2406
                        try
2407
                        {
2408
                            displaycolor = _markupInfoList.Where(info => info.MarkupInfoID == markinfo.ID).First().DisplayColor;
2409
                        }
2410
                        catch(Exception)
2411
                        {
2412
                            displaycolor = "#FFFFFF";
2413
                        }
2414
                        
2415
                        _result = new MarkupInfoItem
2416
                        {
2417
                            MarkupInfoID = markinfo.ID,
2418
                            Consolidate = markinfo.CONSOLIDATE,
2419
                            CreateTime = markinfo.UPDATE_TIME.HasValue ? markinfo.UPDATE_TIME.Value : markinfo.CREATE_TIME,
2420
                            DisplayColor = displaycolor,
2421
                            UserID = markinfo.USER_ID,
2422
                            UserName = member.NAME,
2423
                            Depatment = member.DEPARTMENT,
2424
                        };
2425

    
2426
                        _result.MarkupList = new List<IKCOM.MarkupItem>();
2427
                        var markup_Version = markinfo.MARKUP_INFO_VERSION.OrderByDescending(p => p.CREATE_DATE).First();
2428

    
2429
                        foreach (MARKUP_DATA markdata in markup_Version.MARKUP_DATA)
2430
                        {
2431
                            MarkupItem markitem = new MarkupItem()
2432
                            {
2433
                                ID = markdata.ID,
2434
                                PageNumber = markdata.PAGENUMBER,
2435
                            };
2436
                            _result.MarkupList.Add(markitem);
2437
                        }
2438

    
2439
                        _result.PageCount = _result.MarkupList.GroupBy(i => i.PageNumber).Count();
2440

    
2441
                        markupinfo.Add(_result);
2442
                    }
2443
                }
2444
            }
2445
            catch (Exception)
2446
            {
2447
                return null;
2448
            }
2449
            return markupinfo;
2450
        }
2451

    
2452
        [OperationContract]
2453
        public bool AddMessage(string project_no, TALK value)
2454
        {
2455
            try
2456
            {
2457
                using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2458
                {                    
2459
                    entity.TALK.AddObject(value);
2460
                    entity.SaveChanges();
2461
                }
2462
            }
2463
            catch (Exception)
2464
            {
2465
                return false;
2466
            }
2467
            return true;
2468
        }
2469

    
2470
        [OperationContract]
2471
        public List<TALK> GetMessage(string project_no, string doc_id)
2472
        {
2473
            List<TALK> result = new List<TALK>();
2474
            try
2475
            {
2476
                using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2477
                {
2478
                    result = entity.TALK.Where(data => data.DOCUMENT_ID == doc_id).ToList();                        
2479
                }
2480
            }
2481
            catch (Exception)
2482
            {
2483
                return result;
2484
            }
2485
            return result;
2486
        }
2487

    
2488

    
2489
        #region Legacy System I/F
2490
        /// <summary>
2491
        /// Ensemble+ Sign Data Return
2492
        /// </summary>
2493
        /// <param name="user_id"></param>
2494
        /// <returns></returns>
2495
        private string getEnsembleSign(string user_id)
2496
        {
2497
            string result = string.Empty;
2498
            string soapurl = string.Empty;
2499
            try
2500
            {
2501
                using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
2502
                {
2503
                    var item = Entity.PROPERTIES.Where(d => d.TYPE == "UpLoadServiceUrl").FirstOrDefault();
2504
                    soapurl = item.VALUE;
2505
                }
2506
                WebClient webClient = new WebClient();
2507
                string data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ens=\"http://EnsemblePlus.Webservice\"> <soapenv:Header/> <soapenv:Body> <ens:checkoutSignImage>"
2508
                    + "<ens:sUserNo>" + user_id + "</ens:sUserNo>"
2509
                    + "</ens:checkoutSignImage> </soapenv:Body></soapenv:Envelope>";
2510
                webClient.Headers.Add(HttpRequestHeader.ContentType, "text/xml");
2511
                webClient.Headers.Add("SOAPAction", "http://EnsemblePlus.Webservice");
2512
                var _result = webClient.UploadString(new Uri(soapurl), data);
2513
                XmlDocument xmlDoc = new XmlDocument();
2514
                xmlDoc.LoadXml(_result);
2515
                XmlNodeList list = xmlDoc.GetElementsByTagName("checkoutSignImageResponse");
2516
                foreach (XmlNode xn in list)
2517
                {
2518
                    result = xn["checkoutSignImageReturn"].InnerText;
2519
                }
2520
                if (!result.Contains("No business object"))
2521
                {
2522
                    return result;
2523
                }
2524
                else
2525
                {
2526
                    return null;
2527
                }
2528
            }
2529
            catch (Exception ex)
2530
            {
2531
                return null;
2532
            }
2533

    
2534

    
2535
        }
2536
        #endregion
2537

    
2538
        #region Final Service
2539
        [OperationContract]
2540
        [ServiceKnownType(typeof(DOCINFO))]                
2541
        public DOCINFO FinalPDF_GetDocinfo(string project_no, string docinfo_id)
2542
        {
2543
            DOCINFO docinfo = null;
2544

    
2545
            try
2546
            {
2547
                using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2548
                {
2549
                    var doc = _entity.DOCINFO.Where(x => x.ID == docinfo_id).FirstOrDefault();
2550
                    if(doc != null)
2551
                    {
2552
                        docinfo = new DOCINFO()
2553
                        {
2554
                            ID = doc.ID,
2555
                            DOCUMENT_ID = doc.DOCUMENT_ID,
2556
                            PAGE_COUNT = doc.PAGE_COUNT,
2557
                            ORIGINAL_FILE = doc.ORIGINAL_FILE,
2558
                            PROJECT_NO = doc.PROJECT_NO
2559
                        };
2560
                    }                    
2561
                }
2562
            }
2563
            catch (Exception)
2564
            {
2565
                throw;
2566
            }
2567
            return docinfo;
2568
        }
2569
        [OperationContract]
2570
        [ServiceKnownType(typeof(DOCUMENT_ITEM))]
2571
        public DOCUMENT_ITEM FinalPDF_GetDocumentItem(string project_no, string document_id)
2572
        {
2573
            DOCUMENT_ITEM item = null;
2574

    
2575
            try
2576
            {
2577
                using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2578
                {
2579
                    var doc = _entity.DOCUMENT_ITEM.Where(x => x.DOCUMENT_ID == document_id).FirstOrDefault();
2580
                    if(doc != null)
2581
                    {
2582
                        item = new DOCUMENT_ITEM()
2583
                        {
2584
                            ID = doc.ID,
2585
                            ORIGINAL_FILE = doc.ORIGINAL_FILE,
2586
                            PROJECT_NO = doc.PROJECT_NO,
2587
                            DOCUMENT_ID = doc.DOCUMENT_ID,
2588
                            DOCUMENT_NO = doc.DOCUMENT_NO,
2589
                            DOCUMENT_NAME = doc.DOCUMENT_NAME,
2590
                            ENSEMBLEINFO_URL = doc.ENSEMBLEINFO_URL,
2591
                            GROUP_NO = doc.GROUP_NO,
2592
                            RESULT = doc.RESULT,
2593
                            REVISION = doc.REVISION,
2594
                            RESULT_FILE = doc.RESULT_FILE
2595
                        };
2596
                    }
2597
                    
2598
                }
2599
            }
2600
            catch (Exception)
2601
            {
2602
                throw;
2603
            }
2604
            return item;
2605
        }
2606
        [OperationContract]
2607
        [ServiceKnownType(typeof(MARKUP_DATA))]
2608
        public List<MARKUP_DATA> FinalPDF_GetMarkupdata(string project_no, string docinfo_id)
2609
        {
2610
            List<MARKUP_DATA> results = new List<MARKUP_DATA>();
2611

    
2612
            try
2613
            {
2614
                //using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2615
                using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2616
                {
2617
                    var datas = _entity.MARKUP_DATA.Where(x => x.MARKUP_INFO_VERSION.MARKUP_INFO.DOCINFO_ID == docinfo_id
2618
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.CONSOLIDATE == 1
2619
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.AVOID_CONSOLIDATE == 0
2620
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.PART_CONSOLIDATE == 0).ToList();
2621
                    foreach (var data in datas)
2622
                    {
2623
                        MARKUP_DATA d = new MARKUP_DATA()
2624
                        {
2625
                            ID = data.ID,
2626
                            //GROUP_ID = data.GROUP_ID,
2627
                            SYMBOL_ID = data.SYMBOL_ID,
2628
                            DATA = data.DATA,
2629
                            DATA_TYPE = data.DATA_TYPE,
2630
                            MARKUPINFO_VERSION_ID = data.MARKUPINFO_VERSION_ID,
2631
                            PAGENUMBER = data.PAGENUMBER
2632
                        };
2633
                        results.Add(d);
2634
                    }
2635
                }
2636
            }
2637
            catch (Exception)
2638
            {
2639
                throw;
2640
            }
2641
            return results;
2642
        }
2643
        [OperationContract]
2644
        [ServiceKnownType(typeof(MARKUP_INFO))]
2645
        public MARKUP_INFO FinalPDF_GetMarkupinfo(string project_no, string docinfo_id)
2646
        {
2647
            MARKUP_INFO markupInfo = null;
2648

    
2649
            try
2650
            {
2651
                using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2652
                {
2653
                    var tmp = _entity.MARKUP_INFO.Where(x => x.DOCINFO_ID == docinfo_id && x.CONSOLIDATE == 1 && x.AVOID_CONSOLIDATE == 0 && x.PART_CONSOLIDATE == 0).FirstOrDefault();
2654
                    if (tmp != null)
2655
                    {
2656
                        markupInfo = new MARKUP_INFO()
2657
                        {
2658
                            ID = tmp.ID,
2659
                            DOCINFO_ID = tmp.DOCINFO_ID,
2660
                            USER_ID = tmp.USER_ID
2661
                        };
2662
                    }                    
2663
                }
2664
            }
2665
            catch (Exception)
2666
            {
2667
                throw;
2668
            }
2669
            return markupInfo;
2670
        }
2671
        [OperationContract]
2672
        [ServiceKnownType(typeof(FINAL_PDF))]
2673
        public List<FINAL_PDF> FinalPDF_GetFinalPDFs(string final_id)
2674
        {
2675
            List<FINAL_PDF> results = new List<FINAL_PDF>();
2676

    
2677
            try
2678
            {
2679
                using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
2680
                {
2681
                    var finalList = _entity.FINAL_PDF.Where(final => final.ID == final_id).ToList();
2682
                    foreach(var final in finalList)
2683
                    {
2684
                        FINAL_PDF pdf = new FINAL_PDF()
2685
                        {
2686
                            ID = final.ID,
2687
                            DOCINFO_ID = final.DOCINFO_ID,
2688
                            DOCUMENT_ID = final.DOCUMENT_ID,
2689
                            STATUS = final.STATUS,
2690
                            CURRENT_PAGE = final.CURRENT_PAGE,
2691
                            CREATE_DATETIME = final.CREATE_DATETIME,
2692
                            START_DATETIME = final.START_DATETIME,
2693
                            END_DATETIME = final.END_DATETIME,
2694
                            EXCEPTION = final.EXCEPTION,
2695
                            PROJECT_NO = final.PROJECT_NO,
2696
                            TOTAL_PAGE = final.TOTAL_PAGE,
2697
                            MARKUPINFO_ID = final.MARKUPINFO_ID,
2698
                            CREATE_USER_ID = final.CREATE_USER_ID
2699
                        };
2700
                        results.Add(pdf);
2701
                    }
2702
                }
2703
            }
2704
            catch (Exception)
2705
            {
2706
                throw;
2707
            }
2708
            return results;
2709
        }
2710
        [OperationContract]
2711
        [ServiceKnownType(typeof(DOCPAGE))]
2712
        public List<DOCPAGE> FinalPDF_GetDocpage(string project_no, string docinfo_id)
2713
        {
2714
            List<DOCPAGE> results = new List<DOCPAGE>();
2715

    
2716
            try
2717
            {
2718
                using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2719
                {
2720
                    var pages = _entity.DOCPAGE.Where(x => x.DOCINFO_ID == docinfo_id).OrderBy(x => x.PAGE_NUMBER).ToList();
2721
                    foreach(var page in pages)
2722
                    {
2723
                        DOCPAGE p = new DOCPAGE()
2724
                        {
2725
                            PAGE_ANGLE = page.PAGE_ANGLE,
2726
                            PAGE_NUMBER = page.PAGE_NUMBER,
2727
                            PAGE_HEIGHT = page.PAGE_HEIGHT,
2728
                            PAGE_WIDTH = page.PAGE_WIDTH,
2729
                            DOCINFO_ID = page.DOCINFO_ID                            
2730
                        };
2731
                        results.Add(p);
2732
                    }                    
2733
                }
2734
            }
2735
            catch (Exception)
2736
            {
2737
                throw;
2738
            }
2739
            return results;
2740
        }
2741
        [OperationContract]        
2742
        public bool FinalPDF_SetFinalPDFStatus(string final_id, FinalStatus status)
2743
        {
2744
            bool result = false;
2745

    
2746
            try
2747
            {
2748
                using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
2749
                {
2750
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
2751
                    if(tmp != null)
2752
                    {
2753
                        switch(status)
2754
                        {
2755
                            case FinalStatus.Create:
2756
                                tmp.START_DATETIME = DateTime.Now;
2757
                                break;
2758
                            case FinalStatus.Success:
2759
                                tmp.END_DATETIME = DateTime.Now;
2760
                                tmp.EXCEPTION = string.Empty;
2761
                                break;                                
2762
                        }
2763
                        tmp.STATUS = (int)status;
2764
                        _entity.SaveChanges();
2765
                        result = true;                        
2766
                    }
2767
                }                    
2768
            }
2769
            catch (Exception)
2770
            {
2771
                throw;
2772
            }
2773
            return result;
2774
        }
2775

    
2776
        [OperationContract]
2777
        public bool FinalPDF_SetCurrentPage(string final_id, int currentpage)
2778
        {
2779
            bool result = false;
2780

    
2781
            try
2782
            {
2783
                using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
2784
                {
2785
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
2786
                    if (tmp != null)
2787
                    {
2788
                        tmp.CURRENT_PAGE = currentpage;
2789
                        _entity.SaveChanges();
2790
                        result = true;
2791
                    }
2792
                }
2793
            }
2794
            catch (Exception)
2795
            {
2796
                throw;
2797
            }
2798
            return result;
2799
        }
2800
        [OperationContract]
2801
        public bool FinalPDF_SetError(string final_id, string msg)
2802
        {
2803
            bool result = false;
2804

    
2805
            try
2806
            {
2807
                using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
2808
                {
2809
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
2810
                    if (tmp != null)
2811
                    {                        
2812
                        tmp.STATUS = (int)FinalStatus.Error;
2813
                        tmp.EXCEPTION = DateTime.Now.ToShortDateString() + " " + msg;                        
2814
                        _entity.SaveChanges();
2815
                        result = true;
2816
                    }
2817
                }
2818
            }
2819
            catch (Exception)
2820
            {
2821
                throw;
2822
            }
2823
            return result;
2824
        }
2825

    
2826
        [OperationContract]
2827
        public bool FinalPDF_SetFinalResultPath(string project_no, string document_id, string url)
2828
        {
2829
            bool result = false;
2830

    
2831
            try
2832
            {
2833
                using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2834
                {
2835
                    var item = _entity.DOCUMENT_ITEM.Where(d => d.DOCUMENT_ID == document_id).FirstOrDefault();
2836
                    if (item != null)
2837
                    {
2838
                        item.RESULT_FILE = url;
2839
                        _entity.SaveChanges();
2840
                        result = true;
2841
                    }
2842
                }
2843
            }
2844
            catch (Exception)
2845
            {
2846
                throw;
2847
            }
2848
            return result;
2849
        }
2850
        [OperationContract]
2851
        [ServiceKnownType(typeof(MEMBER))]
2852
        public MEMBER FinalPDF_GetCommentMember(string project_no, string markupdata_id)
2853
        {
2854
            MEMBER member = null;
2855
            try
2856
            {
2857
                using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2858
                {
2859
                    var data = _entity.MARKUP_DATA.Where(x => x.ID == markupdata_id).FirstOrDefault();
2860
                    string user_id = data.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID;
2861
                    var person = _entity.MEMBER.Where(p => p.ID == user_id).FirstOrDefault();
2862
                    if(person != null)
2863
                    {
2864
                        member = new MEMBER()
2865
                        {
2866
                            ID = user_id,
2867
                            NAME = person.NAME,
2868
                            DEPARTMENT = person.DEPARTMENT
2869
                        };
2870
                    }
2871
                }
2872
            }
2873
            catch (Exception)
2874
            {
2875
                throw;
2876
            }
2877
            return member;
2878
        }
2879

    
2880
        [OperationContract]
2881
        [ServiceKnownType(typeof(PROPERTIES))]
2882
        public List<PROPERTIES> FinalPDF_GetProperties(string project_no)
2883
        {
2884
            List<PROPERTIES> results = new List<PROPERTIES>();
2885
            try
2886
            {
2887
                using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
2888
                {
2889
                    var _items = _entity.PROPERTIES.Where(x => x.PROPERTY == project_no).ToList();
2890
                    foreach(var item in _items)
2891
                    {
2892
                        PROPERTIES pROPERTIES = new PROPERTIES()
2893
                        {
2894
                            ID = item.ID,
2895
                            PROPERTY = item.PROPERTY,
2896
                            TYPE = item.TYPE,
2897
                            VALUE = item.VALUE
2898
                        };
2899
                        results.Add(pROPERTIES);
2900
                    }
2901
                }
2902

    
2903
            }
2904
            catch (Exception)
2905
            {
2906
                throw;
2907
            }
2908
            return results;
2909
        }
2910
        #endregion
2911
    }
2912
}
클립보드 이미지 추가 (최대 크기: 500 MB)