프로젝트

일반

사용자정보

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

markus / KCOM_API / ServiceDeepView.svc.cs @ ac91e747

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

1
using IFinalPDF;
2
using IKCOM;
3
using KCOMDataModel.Common;
4
using KCOMDataModel.DataModel;
5
using System;
6
using System.Collections.Generic;
7
using System.Collections.ObjectModel;
8
using System.Configuration;
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.Web.Services;
17
using System.Windows;
18
using System.Xml;
19

    
20
namespace KCOM_API
21
{
22
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ServiceDeepView" in code, svc and config file together.
23
    // 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.
24
    [ServiceContract(Namespace = "")]
25
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
26
    public partial class ServiceDeepView : System.Web.Services.WebService
27
    {
28
        /// <summary>
29
        /// Client Version 과 Server Version 을 비교하여 Server Version 이 최신이면 다운로드 url 리턴.
30
        /// </summary>
31
        /// <param name="is64BitProcess">64bit = true, 32bit = false</param>
32
        /// <param name="markusVer">client version</param>
33
        /// <returns></returns>
34
        [OperationContract]
35
        public string GetVersionData(bool is64BitProcess, string markusVer)
36
        {
37
            string url = null;
38

    
39
            try
40
            {
41
                Version client_version = new Version(markusVer);
42
                
43
                //DB에서 version 정보와 다운로드 url 을 Select
44
                PROPERTIES dbvalue = null;
45
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
46
                using (KCOMEntities uc = new KCOMEntities(sConnString))
47
                {
48
                    string wherestr = string.Empty;
49
                    if (is64BitProcess)
50
                    {
51
                        wherestr = "Update_x64";                        
52
                    }
53
                    else
54
                    {
55
                        wherestr = "Update_x84";                        
56
                    }
57
                    dbvalue = uc.PROPERTIES.Where(data => data.TYPE == wherestr).FirstOrDefault();
58
                }
59

    
60
                //서버 버전이 최신이면 0보다 큰값 리턴
61
                Version server_version = new Version(dbvalue.PROPERTY);
62
                int result = server_version.CompareTo(client_version);  
63
                if (result > 0)
64
                {
65
                    url = dbvalue.VALUE;
66
                }
67
            }
68
            catch (Exception)
69
            {
70
                url = null;
71
            }
72
            return url;
73
        }
74
    
75

    
76
        [OperationContract]
77
        public KCOM_SystemInfo GetSystemData()
78
        {
79
            try
80
            {
81
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
82
                using (KCOMEntities uc = new KCOMEntities(sConnString))
83
                {
84
                    var SystemInfoSet = uc.PROPERTIES.Where(data => data.TYPE == "SystemInfo").ToList();
85

    
86
                    KCOM_SystemInfo sysInfo = new KCOM_SystemInfo();
87

    
88
                    var url = SystemInfoSet.Where(data => data.PROPERTY == "Url").FirstOrDefault();
89
                    if (url != null)
90
                    {
91
                        sysInfo.HostName = url.VALUE;
92
                    }
93

    
94
                    url = SystemInfoSet.Where(data => data.PROPERTY == "Port").FirstOrDefault();
95
                    if (url != null)
96
                    {
97
                        sysInfo.HostPort = url.VALUE;
98
                    }
99

    
100
                    url = uc.PROPERTIES.Where(data => data.TYPE == "STAMP").FirstOrDefault();
101
                    if(url != null)
102
                    {
103
                        sysInfo.STAMP = url.VALUE;
104
                    }
105
                    return sysInfo;
106
                }
107
            }
108
            catch (Exception ex)
109
            {
110
            }
111
            return null;
112
            GC.Collect(2);
113
        }
114

    
115
        private static string shortGuid()
116
        {
117
            byte[] bytes = new byte[16];
118
            using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create())
119
            {
120
                provider.GetBytes(bytes);
121
            }
122

    
123
            var guid = new Guid(bytes);
124

    
125
            return Convert.ToBase64String(guid.ToByteArray())
126
                .Substring(0, 10)
127
                .Replace("/", "")
128
                .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
129
        }
130

    
131

    
132
        [OperationContract]
133
        public List<FAVORITE_DOC> GetFavoriteVP(string PrjNo, string userID, string sharepointItemID)
134
        {
135
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
136
            using (KCOMEntities dc = new KCOMEntities(sConnString))
137
            {
138

    
139
                int flagString = Convert.ToInt32(FAVORITE_FLAG.Personal);
140
                List<FAVORITE_DOC> favoriteListSet = new List<FAVORITE_DOC>();
141
                //dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == PrjNo && data.DOCUMENT_ID == sharepointItemID && data.FLAG !=
142
                //    flagString).ToList().ForEach(data => favoriteListSet.Add(data));
143

    
144

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

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

    
149
                //favoriteListSet = favoriteListSet.Distinct().ToList();
150
                return favoriteListSet;
151
            }
152
        }
153
        [OperationContract]
154
        public bool EditFavoriteVP(string prjNo, string userID, string docID, int state, string description)
155
        {
156
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
157
            using (KCOMEntities dc = new KCOMEntities(sConnString))
158
            {
159
                //List<FAVORITE_DOC> favoriteSet = dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == prjNo && data.MEMBER_USER_ID == userID
160
                //    && data.PAGE_NO == SavePageNo && data.CREATE_TIME == createTime).ToList();
161
                List<FAVORITE_DOC> favoriteSet = dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == prjNo && data.MEMBER_USER_ID == userID
162
                    && data.ID == docID).ToList();
163
                try
164
                {
165

    
166
                    if (favoriteSet.Count > 0)
167
                    {
168
                        var FavoriteVP_Instance = favoriteSet.First();
169

    
170
                        FavoriteVP_Instance.DESCRIPTION = description;
171
                        FavoriteVP_Instance.FLAG = state;
172

    
173
                        dc.SaveChanges();
174

    
175
                        return true;
176
                    }
177
                    else
178
                    {
179
                        return false;
180
                    }
181
                }
182
                catch (Exception)
183
                {
184
                    return false;
185
                }
186
            }
187
        }
188

    
189
        [OperationContract]
190
        public bool DelFavoriteVP(string prjNo, string userID, int SavePageNo, string docID)
191
        {
192
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
193
            using (KCOMEntities dc = new KCOMEntities(sConnString))
194
            {
195

    
196
                List<FAVORITE_DOC> favoriteSet = dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == prjNo && data.MEMBER_USER_ID == userID
197
                    && data.ID == docID).ToList();
198

    
199
                try
200
                {
201
                    if (favoriteSet.Count > 0)
202
                    {
203
                        favoriteSet.ForEach(data => dc.FAVORITE_DOC.DeleteObject(data));
204
                        dc.SaveChanges();
205
                        return true;
206
                    }
207
                    else
208
                    {
209
                        return false;
210
                    }
211
                }
212
                catch (Exception)
213
                {
214
                    return false;
215
                }
216
            }
217
        }
218

    
219
        /// <summary>
220
        /// 두 페이지를 비교하여 결과를 리턴한다
221
        /// </summary>
222
        /// <param name="projectNo"></param>
223
        /// <param name="originDocItem_ID"></param>
224
        /// <param name="targetDocItem_ID"></param>
225
        /// <param name="originPageNo"></param>
226
        /// <param name="targetPageNo"></param>
227
        /// <param name="isInternalAddress"></param>
228
        /// <returns></returns>
229
        [OperationContract]
230
        public List<Rect> GetCompareRect(string projectNo, string originDocItem_ID, string targetDocItem_ID, string originPageNo, string targetPageNo, string isInternalAddress)
231
        {
232
      
233
            List<Rect> result = new List<Rect>();
234

    
235
            string originFile = "";
236
            string targetFile = "";
237

    
238
            string sFolder = originDocItem_ID.All(char.IsDigit) ? (Convert.ToUInt32(originDocItem_ID) / 100).ToString() : (originDocItem_ID.Length >= 5 ? originDocItem_ID.Substring(0, 5) : originDocItem_ID);
239
            if (Boolean.Parse(isInternalAddress))
240
            {
241
                originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sFolder, originDocItem_ID, originPageNo);
242
                targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sFolder, targetDocItem_ID, targetPageNo);
243
            }
244
            else
245
            {
246
                originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo,  originDocItem_ID, originPageNo);
247
                targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo,  targetDocItem_ID, targetPageNo);
248
            }
249

    
250
            using (Markus.Image.ImageComparer compareLib = new Markus.Image.ImageComparer())
251
            {
252
                result = compareLib.CompareReturnRects(originFile, targetFile, new System.Drawing.Size(20, 20));
253
            }
254

    
255
            return result;
256
        }
257

    
258
        //[OperationContract]
259
        //public List<Rect> GetCompareRect_old(string projectNo, string originDocItem_ID, string targetDocItem_ID, string originPageNo, string targetPageNo, string isInternalAddress)
260
        //{
261
        //    System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
262

    
263
        //    stopwatch.Start();
264

    
265
        //    string originFile = "";
266
        //    string targetFile = "";
267

    
268
        //    string sFolder = originDocItem_ID.All(char.IsDigit) ? (Convert.ToUInt32(originDocItem_ID) / 100).ToString() : (originDocItem_ID.Length >= 5 ? originDocItem_ID.Substring(0, 5) : originDocItem_ID);
269
        //    if (Boolean.Parse(isInternalAddress))
270
        //    {
271
        //        originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sFolder, originDocItem_ID, originPageNo);
272
        //        targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sFolder, targetDocItem_ID, targetPageNo);
273
        //    }
274
        //    else
275
        //    {
276
        //        originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo, originDocItem_ID, originPageNo);
277
        //        targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo, targetDocItem_ID, targetPageNo);
278
        //    }
279

    
280
        //    CompareLib compareLib = new CompareLib();
281

    
282
        //    var resultOrigin = compareLib.ChangeCmpUrlToPng_File(originFile);
283
        //    var resultTarget = compareLib.ChangeCmpUrlToPng_File(targetFile);
284

    
285
        //    string outPutFile = compareLib.ImageCompare_File(resultOrigin, resultTarget);
286
        //    var result = compareLib.GetBoundBoxInImage(outPutFile);
287

    
288
        //    System.Diagnostics.Debug.WriteLine(new TimeSpan(stopwatch.ElapsedTicks));
289

    
290
        //    return result;
291
        //}
292

    
293

    
294
        #region Final PDF
295
        private string _ChanID = null;
296
        TcpChannel chan = null;
297
        [OperationContract]
298
        public FinalPDFResult SetFinalPDF(string ProjectNo, string DocInfoID, string MarkupInfoID, string CreateUserID)
299
        {
300
            #region 임시보관
301
            #endregion
302
            FinalPDFResult _result = new FinalPDFResult();
303
            RemFinalPDFObject remObj = null;
304
            try
305
            {
306
                string _finalID = shortGuid();
307
                int _DocTotalPages = -1;
308
                string docItemId;
309

    
310
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
311
                using (CIEntities _ci = new CIEntities(sCIConnString))
312
                {
313
                    var _doc = _ci.DOCINFO.Where(info => info.ID == DocInfoID);
314

    
315
                    if (_doc.Count() > 0)
316
                    {
317
                        _DocTotalPages = _doc.First().PAGE_COUNT;
318
                        docItemId = _doc.First().DOCUMENT_ID;
319
                    }
320
                    else
321
                    {
322
                        _result.Status = FinalStatus.Error;
323
                        _result.Exception = "페이지 정보를 가져올 수 없습니다.";
324
                        return _result;
325
                    }
326
                }
327
                if (_DocTotalPages > 0)
328
                {
329
                    FINAL_PDF fm = new FINAL_PDF()
330
                    {
331
                        ID = _finalID,
332
                        PROJECT_NO = ProjectNo,
333
                        DOCINFO_ID = DocInfoID,
334
                        DOCUMENT_ID = docItemId,
335
                        MARKUPINFO_ID = MarkupInfoID,
336
                        CREATE_USER_ID = CreateUserID,
337
                        TOTAL_PAGE = _DocTotalPages,
338
                        CREATE_DATETIME = DateTime.Now,
339
                        STATUS = (int)IFinalPDF.FinalStatus.Insert
340
                    };
341

    
342
                    string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
343
                    using (KCOMEntities _entity = new KCOMEntities(sConnString))
344
                    {
345
                        _entity.AddToFINAL_PDF(fm);
346
                        _entity.SaveChanges(System.Data.Objects.SaveOptions.AcceptAllChangesAfterSave);
347
                    };
348

    
349
                    System.Runtime.Remoting.Channels.IChannel _ch = System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp");
350
                    if (_ch == null)
351
                    {
352
                        chan = new TcpChannel();
353
                        _ChanID = chan.ChannelName;
354
                        System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan, false);
355
                        // Create an instance of the remote object
356

    
357
                        using (KCOMEntities ec = new KCOMEntities(sConnString))
358
                        {
359

    
360
                            //remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
361
                            //                          "tcp://localhost:9092/remFinalPDF");
362
                            remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
363
                                                      //"tcp://192.168.0.67:9092/remFinalPDF");
364
                                                      "tcp://localhost:9092/remFinalPDF");
365
                        }
366

    
367
                        //"tcp://localhost:8080/remFinalPDF");
368

    
369
                        _result = remObj.SetFinalPDF(ProjectNo, _finalID);
370
                        _result.FinalID = _finalID;
371
                        _result.Status = FinalStatus.Success;
372

    
373
                        //MarkupToPDF.MarkupToPDF fa = new MarkupToPDF.MarkupToPDF();
374
                        //fa.MakeFinalPDF(fm);
375
                    }
376
                    else
377
                    {
378
                        _ChanID = _ch.ChannelName;
379
                    }
380
                }
381
            }
382
            catch (Exception ex)
383
            {
384
                _result.Status = FinalStatus.Error;
385

    
386
                if (ex.GetType() == typeof(System.Net.Sockets.SocketException))
387
                    _result.Exception = "Final Server Not Connection";
388
                else _result.Exception = ex.ToString();
389
            }
390
            finally
391
            {
392
                remObj = null;
393
                if (System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp") != null)
394
                    System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(chan);
395

    
396
                GC.Collect(2);
397
            }
398
            return _result;
399
        }
400
        #endregion
401

    
402

    
403
        [OperationContract]
404
        public bool GetConversionState(KCOM_BasicParam param)
405
        {
406
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
407
            using (CIEntities entity = new CIEntities(sCIConnString))
408
            {
409
                var doc = entity.DOCINFO.Where(data => data.DOCUMENT_ID == param.documentID).FirstOrDefault();
410
                if (doc != null)
411
                {
412
                    var count = doc.DOCPAGE.Where(data => data.DOCINFO_ID == doc.ID).Count();
413
                    if (doc.PAGE_COUNT == count)  //페이지 수가 일치하는지
414
                    {
415
                        return true;
416
                    }
417
                    else //페이지 수가 일치하지 않는 경우
418
                    {
419
                        string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
420
                        KCOMEntities entity_kcom = new KCOMEntities(sConnString);
421
                        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();
422

    
423
                        if (lst != null || lst.Count >= 1)
424
                        {
425
                            //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_PAGECOUNT"), param.documentID, param.projectNo);
426
                            //이메일 클라이언트를 구현해야함
427
                        }
428
                        return false;
429
                    }
430
                }
431
                else
432
                {
433
                    //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_CONVERTFAILED"), param.documentID, param.projectNo);
434
                    //이메일 클라이언트를 구현해야함
435
                    return false;
436
                }
437
            }
438
        }
439

    
440
        [OperationContract]
441
        public List<VPRevision> GetVPRevisionHistory(string ProjectNo, string vpNo, string DocumentId)
442
        {
443
            List<VPRevision> _result = new List<VPRevision>();
444
            try
445
            {
446
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
447
                using (CIEntities entity = new CIEntities(sCIConnString))
448
                {
449
                    var _vpList = (from docitem in entity.DOCUMENT_ITEM
450
                                   where docitem.DOCUMENT_NO == vpNo
451
                                   select new VPRevision
452
                                   {
453
                                       RevNo = docitem.REVISION,
454
                                       GroupNo = docitem.GROUP_NO,
455
                                       FROM_VENDOR = docitem.ORIGINAL_FILE,
456
                                       DOCUMENT_ID = docitem.DOCUMENT_ID,
457
                                       TO_VENDOR = docitem.RESULT_FILE,
458
                                       RESULT = docitem.RESULT,
459
                                       DocNo = docitem.DOCUMENT_NO,
460
                                       EnsembleLink = docitem.ENSEMBLEINFO_URL,
461
                                       //IsSyncPossible = docitem.DOCUMENT_ID == DocumentId ? false : entity.DOCINFO.Where(d => d.DOCUMENT_ID == docitem.DOCUMENT_ID).ToList().Count > 0 ? true : false
462
                                   });
463
                    _result = _vpList.ToList();
464
                    foreach (var vp in _result)
465
                    {
466
                        if (entity.DOCINFO.Where(d => d.DOCUMENT_ID == vp.DOCUMENT_ID).ToList().Count > 0)
467
                            vp.IsSyncPossible = true;
468
                        else
469
                            vp.IsSyncPossible = false;
470
                    }
471

    
472
                    //_result = _result.OrderByDescending(r => UInt64.Parse(System.Text.RegularExpressions.Regex.Replace(r.GroupNo, @"\D", ""))).ToList();
473
                    _result = _result.OrderByDescending(r => r.GroupNo).ToList();
474
                }
475
            }
476
            catch (Exception ex)
477
            {
478

    
479
                throw ex;
480
            }
481
            finally
482
            {
483
                GC.Collect(2);
484
            }
485
            return _result;
486
        }
487

    
488
        [OperationContract]
489
        public VPRevision GetVPRevisionFirstOrDefault(string ProjectNo, string DocumentId)
490
        {
491
            VPRevision _result = null;
492
            try
493
            {
494
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
495
                using (CIEntities entity = new CIEntities(sCIConnString))
496
                {
497
                    _result = (from docitem in entity.DOCUMENT_ITEM
498
                     where docitem.DOCUMENT_ID == DocumentId
499
                     select new VPRevision
500
                     {
501
                         RevNo = docitem.REVISION,
502
                         GroupNo = docitem.GROUP_NO,
503
                         FROM_VENDOR = docitem.ORIGINAL_FILE,
504
                         DOCUMENT_ID = docitem.DOCUMENT_ID,
505
                         TO_VENDOR = docitem.RESULT_FILE,
506
                         RESULT = docitem.RESULT
507
                     }).FirstOrDefault();
508
                }
509
            }
510
            catch (Exception)
511
            {
512
                throw;
513
            }
514
            finally
515
            {
516
                GC.Collect(2);
517
            }
518
            return _result;
519
        }
520

    
521
        [OperationContract]
522
        public DOCINFO GetDocInfo(KCOM_BasicParam param)
523
        {
524
            DOCINFO _result = null;
525
            try
526
            {
527
                // 차후 아래의 코드로 변경
528
                //using (CI_Entities ModelDeeview = new CI_Entities(DaelimCiConnectionString.ToString()))
529
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
530
                CIEntities ModelDeeview = new CIEntities(sCIConnString);
531

    
532
                var docinfo = ModelDeeview.DOCINFO.Where(doc => doc.DOCUMENT_ID == param.documentID && doc.PROJECT_NO == param.projectNo);
533
                if (docinfo.Count() > 0)
534
                {
535
                    _result = docinfo.First();
536
                    _result.MARKUP_INFO.Clear();
537

    
538
                }
539
                return _result;
540

    
541
            }
542
            catch (Exception ex)
543
            {
544
                System.Diagnostics.Trace.WriteLine("GetDocInfo Error : " + ex);
545
            }
546
            finally
547
            {
548
                GC.Collect(2);
549
            }
550
            return null;
551
        }
552

    
553
        [OperationContract]
554
        public bool GetCheckSystemAdmin(string UserID)
555
        {
556
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
557
            using (KCOMEntities uc = new KCOMEntities(sConnString))
558
            {
559
                var user = uc.PROPERTIES.Where(data => data.TYPE == "Administrator" && data.PROPERTY.Contains(UserID)).FirstOrDefault();
560
                if (user != null)
561
                {
562
                    return true;
563
                }
564
                else
565
                {
566
                    return false;
567
                }
568
            }
569
            GC.Collect(2);
570
        }
571

    
572
        [OperationContract]
573
        public DOCUMENT_ITEM GetDocumentItemInfo(KCOM_BasicParam param)
574
        {
575
            ///param : prjNo, documentId, userId
576
            DOCUMENT_ITEM _result = null;
577

    
578
            try
579
            {
580
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
581
                CIEntities entity = new CIEntities(sCIConnString);
582
               
583
                var _items = entity.DOCUMENT_ITEM.Where(data => data.DOCUMENT_ID == param.documentID);
584

    
585
                if (_items.Count() > 0)
586
                {
587
                    _result = _items.First();
588

    
589
                    return _result;
590
                }
591
                //else
592
                //{
593
                //    Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_DOCUMENTNOTFOUND"), param.documentID, param.projectNo);
594
                //}
595
            }
596
            catch (Exception ex)
597
            {
598
                System.Diagnostics.Trace.WriteLine("GetDocumentItemInfo Error : " + ex);
599

    
600
                new FaultException("GetDocumentItemInfo Error - "  + ex.ToString());
601
                //throw new FaultException(ex.ToString());
602
                //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, "GetDocumentItemInfo / " + ex.Message, param.documentID, param.projectNo);
603
            }
604

    
605
            return _result;
606
        }
607
        /// <summary>
608
        /// DOCUMENT_ITEM Table 의 ID 로 Item 을 Select
609
        /// </summary>
610
        /// 대림의 경우 Interface ID(Document 의 ID) 를 parameter 로 전달
611
        /// 넘어온 ID를 통해 document id 를 확인하는 과정이 필요
612
        /// <param name="ensemble_id"></param>
613
        /// <returns></returns>
614
        [OperationContract]
615
        public string GetDocItemID(string ensemble_id)
616
        {
617
            ///param : prjNo, documentId, userId
618
            string _result = string.Empty;
619

    
620
            try
621
            {
622
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
623
                CIEntities entity = new CIEntities(sCIConnString);
624

    
625
                var _items = entity.DOCUMENT_ITEM.Where(data => data.ID == ensemble_id).FirstOrDefault();
626
                if(_items != null)
627
                    _result = _items.DOCUMENT_ID;
628
            }
629
            catch (Exception ex)
630
            {
631
                //System.Diagnostics.Trace.WriteLine("GetVendorItemInfo Error : " + ex);
632
                //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, "GetDocumentItemInfo / " + ex.Message, param.documentID, param.projectNo);
633
            }
634

    
635
            return _result;
636
        }
637
        public string UserGO(MARKUP_INFO item)
638
        {
639
            if (item != null)
640
            {
641
                return item.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID;
642
            }
643
            return null;
644
        }
645
        
646
        [OperationContract]
647
        public List<MarkupInfoItem> GetMarkupInfoItems(string ProjectNo, string DocInfoId)
648
        {
649
            List<MarkupInfoItem> _result = new List<MarkupInfoItem>();
650
            try
651
            {
652
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
653
                using (CIEntities entity = new CIEntities(sCIConnString))
654
                {
655
                    var markupListData = entity.MARKUP_INFO.Where(data => data.DOCINFO_ID == DocInfoId).ToList();
656

    
657
                    var markupList = from markup in markupListData
658
                                     orderby markup.CREATE_TIME descending
659
                                     select new MarkupInfoItem
660
                                     {
661
                                         MarkupInfoID = markup.ID,
662
                                         UserID = markup.USER_ID,
663
                                         MarkupVersionID = markup.MARKUP_INFO_VERSION.Count() == 0 ? null : markup.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID,
664
                                         CreateTime = markup.CREATE_TIME,
665
                                         Consolidate = markup.CONSOLIDATE,
666
                                         Description = markup.DESCRIPTION,
667
                                         AvoidConsolidate = markup.AVOID_CONSOLIDATE,
668
                                         PartConsolidate = markup.PART_CONSOLIDATE,
669
                                         UpdateTime = DateTime.Parse(markup.UPDATE_TIME.ToString()),
670
                                     };
671

    
672
                    if (markupList.Count() > 0)
673
                    {
674
                        _result = markupList.ToList();
675
                    }
676

    
677
                    _result.ForEach(r =>
678
                    {
679

    
680
                        r.MarkupList = (from markupData in entity.MARKUP_DATA
681
                                        where markupData.MARKUPINFO_VERSION_ID == r.MarkupVersionID
682
                                        orderby markupData.PAGENUMBER
683
                                        select new MarkupItem { ID = markupData.ID, PageNumber = markupData.PAGENUMBER, Data = markupData.DATA, Data_Type = markupData.DATA_TYPE, Symbol_ID = markupData.SYMBOL_ID}).ToList();
684
                    });
685

    
686
                    List<PROPERTIES> _ColorsProperties = new List<PROPERTIES>();
687
                    Random random = new Random();
688

    
689
                    string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
690
                    using (KCOMEntities kcomEntity = new KCOMEntities(sConnString))
691
                    {
692
                        _ColorsProperties = (from property in kcomEntity.PROPERTIES
693
                                             where property.TYPE == "DisplayColor"
694
                                             select property).ToList();
695
                    }                    
696

    
697
                    foreach (var item in _result)
698
                    {
699
                        var _member = entity.MEMBER.Where(member => member.ID == item.UserID && member.PROJECT_NO == ProjectNo).FirstOrDefault();
700
                        
701
                        if (_member != null)
702
                        {
703
                            item.UserName = _member.NAME;
704
                            item.Depatment = _member.DEPARTMENT;
705
                        }
706

    
707
                        if (_ColorsProperties.Count > 0)
708
                        {
709
                            int colorIdx = random.Next(0, _ColorsProperties.Count() - 1);
710
                            #region 부서별로 색상을 지정하고자 할때
711
                            /// 일단 의견을 들어보자구!
712
                            #endregion
713
                            item.DisplayColor = "#FF" + _ColorsProperties[colorIdx].VALUE;
714
                            _ColorsProperties.Remove(_ColorsProperties[colorIdx]);
715
                        }
716
                        else
717
                        {
718
                            item.DisplayColor = String.Format("#FF{0:X6}", random.Next(0x1000000));
719
                        }
720
                    }
721
                }
722
            }
723
            catch (Exception EX)
724
            {
725
                System.Diagnostics.Debug.WriteLine(this.GetType().ToString() + " " + EX);
726
                return _result;
727
            }
728
            finally
729
            {
730
                GC.Collect(2);
731
            }
732

    
733
            return _result;
734
        }
735

    
736
        [OperationContract]
737
        public List<MarkupInfoItem> GetSyncMarkupInfoItems(string ProjectNo, string DocInfoId, string currentUser)
738
        {
739
            List<MarkupInfoItem> _result = new List<MarkupInfoItem>();
740
            try
741
            {
742
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
743
                using (CIEntities entity = new CIEntities(sCIConnString))
744
                {
745
                    var docItem = entity.DOCINFO.Where(data => data.DOCUMENT_ID == DocInfoId).FirstOrDefault();
746
                    if (docItem == null)
747
                    {
748
                        return null;
749
                    }
750
                    var markupListData = entity.MARKUP_INFO.Where(data => data.DOCINFO_ID == docItem.ID).ToList();
751

    
752
                    var markupList = from markup in markupListData
753
                                     where markup.USER_ID == currentUser || markup.CONSOLIDATE == 1
754
                                     orderby markup.CREATE_TIME descending
755
                                     select new MarkupInfoItem
756
                                     {
757
                                         MarkupInfoID = markup.ID,
758
                                         UserID = markup.USER_ID,
759
                                         MarkupVersionID = markup.MARKUP_INFO_VERSION.Count() == 0 ? null : markup.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID,
760
                                         CreateTime = markup.CREATE_TIME,
761
                                         Consolidate = markup.CONSOLIDATE,
762
                                         Description = markup.DESCRIPTION,
763
                                         AvoidConsolidate = markup.AVOID_CONSOLIDATE,
764
                                         PartConsolidate = markup.PART_CONSOLIDATE,
765
                                     };
766

    
767

    
768

    
769
                    if (markupList.Count() > 0)
770
                    {
771
                        _result = markupList.ToList();
772
                    }
773

    
774

    
775

    
776
                    _result.ForEach(r =>
777
                    {
778

    
779
                        r.MarkupList = (from markupData in entity.MARKUP_DATA
780
                                        where markupData.MARKUPINFO_VERSION_ID == r.MarkupVersionID
781
                                        orderby markupData.PAGENUMBER
782
                                        select new MarkupItem { ID = markupData.ID, PageNumber = markupData.PAGENUMBER, Data = markupData.DATA, Data_Type = markupData.DATA_TYPE, Symbol_ID = markupData.SYMBOL_ID}).ToList();
783
                    });
784

    
785
                    List<PROPERTIES> _ColorsProperties = new List<PROPERTIES>();
786
                    Random random = new Random();
787

    
788
                    string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
789
                    using (KCOMEntities kcomEntity = new KCOMEntities(sConnString))
790
                    {
791
                        _ColorsProperties = (from property in kcomEntity.PROPERTIES
792
                                             where property.TYPE == "DisplayColor"
793
                                             select property).ToList();
794
                    }
795

    
796
                    foreach (var item in _result)
797
                    {
798
                        var _member = entity.MEMBER.Where(member => member.ID == item.UserID);
799

    
800
                        if (_member.Count() > 0)
801
                        {
802
                            item.UserName = _member.First().NAME;
803
                            item.Depatment = _member.First().DEPARTMENT;
804
                        }
805

    
806
                        if (_ColorsProperties.Count > 0)
807
                        {
808
                            int colorIdx = random.Next(1, _ColorsProperties.Count());
809
                            #region 부서별로 색상을 지정하고자 할때
810
                            /// 일단 의견을 들어보자구!
811
                            #endregion
812
                            item.DisplayColor = "#FF" + _ColorsProperties[colorIdx].VALUE;
813
                            _ColorsProperties.Remove(_ColorsProperties[colorIdx]);
814
                            //item.DisplayColor = "#FF" + _Colors.First();
815
                            //_Colors.Remove(_Colors.First());
816
                        }
817
                        else
818
                        {
819
                            item.DisplayColor = String.Format("#FF{0:X6}", random.Next(0x1000000));
820
                        }
821
                    }
822
                }
823
            }
824
            catch (Exception EX)
825
            {
826
                System.Diagnostics.Debug.WriteLine(this.GetType().ToString() + " " + EX);
827
                return _result;
828
            }
829
            finally
830
            {
831
                GC.Collect(2);
832
            }
833

    
834
            return _result;
835
        }
836

    
837

    
838
        //[OperationContract]
839
        //[ServiceKnownType(typeof(MEMBER))]
840
        //public List<MEMBER> GetUserData(string ProjectNo, string UserID)
841
        //{
842
        //    List<MEMBER> _result = new List<MEMBER>();
843

    
844
        //    using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
845
        //    {
846
        //        var _UserList = from member in entity.MEMBER
847
        //                        where member.ID == UserID
848
        //                        select member;
849
        //        _result = _UserList.ToList();
850
        //    }
851
        //    //GC.Collect(2);
852
        //    return _result;
853
        //}
854

    
855
        [OperationContract]
856
        [ServiceKnownType(typeof(MEMBER))]
857
        public List<MEMBER> GetUserData(string ProjectNo, string UserID)
858
        {
859
            List<MEMBER> _result = new List<MEMBER>();
860

    
861
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
862
            using (CIEntities entity = new CIEntities(sCIConnString))
863
            {
864
                var _UserList = from member in entity.MEMBER
865
                                where member.ID == UserID
866
                                select member;
867
                _result = _UserList.ToList();
868
            }
869
            //GC.Collect(2);
870
            return _result;
871
        }
872

    
873

    
874
        [OperationContract]
875
        public List<string> GetDeptData(string UserDept) //그룹 추가 옵션 부여 예정
876
        {
877
            List<string> _result = new List<string>();
878

    
879
            try
880
            {
881
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
882
                KCOMEntities entity = new KCOMEntities(sConnString);
883
                var YourEnginner = (from dept in entity.PROPERTIES
884
                                    where dept.TYPE == "DeptName" && UserDept.Contains(dept.VALUE)
885
                                    select dept).FirstOrDefault();
886

    
887
                if (YourEnginner != null)
888
                {
889
                    _result = (from dept in entity.PROPERTIES
890
                               where dept.PROPERTY == YourEnginner.PROPERTY
891
                               select dept.VALUE).ToList();
892
                    return _result;
893
                }
894
                else
895
                {
896
                    return null;
897
                }
898
            }
899
            catch (Exception ex)
900
            {
901
                System.Diagnostics.Debug.WriteLine(ex.Message);
902
            }
903
            finally
904
            {
905
                GC.Collect(2);
906
            }
907
            return _result;
908
        }
909

    
910
        [OperationContract]
911
        public bool DeleteMarkup(string ProjectNo, string MarkupInfoID)
912
        {
913
            bool _result = false;
914
            try
915
            {
916
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
917
                using (KCOMDataModel.DataModel.CIEntities Entity = new KCOMDataModel.DataModel.CIEntities(sCIConnString))
918
                {
919

    
920
                    MARKUP_INFO instance = Entity.MARKUP_INFO.Where(root => root.ID == MarkupInfoID).FirstOrDefault();
921

    
922
                    if (instance == null)
923
                    {
924
                        return false;
925
                    }
926
                    MARKUP_INFO_VERSION version = instance.MARKUP_INFO_VERSION.FirstOrDefault();
927

    
928

    
929
                    version.MARKUP_DATA.ToList().ForEach(data =>
930
                    {
931
                        Entity.MARKUP_DATA.DeleteObject(data);
932
                        Entity.SaveChanges();
933
                    });
934

    
935
                    Entity.MARKUP_INFO_VERSION.DeleteObject(version);
936
                    Entity.SaveChanges();
937

    
938
                    Entity.MARKUP_INFO.DeleteObject(instance);
939
                    Entity.SaveChanges();
940

    
941
                }
942
                _result = true;
943
            }
944
            catch (Exception ex)
945
            {
946
                System.Diagnostics.Trace.WriteLine(ex, "SaveMarkup");
947
            }
948
            finally
949
            {
950
                GC.Collect(2);
951
            }
952
            return _result;
953
        }
954

    
955
        #region Favorite
956
        [OperationContract]
957
        public bool SetFavoriteVP(string prjNo, string userID, string groupNo, string docNo, string rev, int SavePageNo, string documentItemID, string VPDescription, IKCOM.FAVORITE_FLAG flag)
958
        {
959
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
960
            using (KCOMEntities entity = new KCOMEntities(sConnString))
961
            {
962
                try
963
                {
964
                    entity.FAVORITE_DOC.AddObject(new FAVORITE_DOC
965
                    {
966
                        ID = shortGuid(),
967
                        PROJECT_NO = prjNo,
968
                        DOCUMENT_ID = documentItemID,
969
                        GROUP_NO = groupNo,
970
                        DOCUMENT_NO = docNo,
971
                        MEMBER_USER_ID = userID,
972
                        DESCRIPTION = VPDescription,
973
                        CREATE_TIME = DateTime.Now,
974
                        REVISION = rev,
975
                        FLAG = (int)flag,
976
                        PAGE_NO = SavePageNo,
977
                    });
978
                    entity.SaveChanges();
979
                }
980
                catch (Exception)
981
                {
982
                    return false;
983
                }
984

    
985
                return true;
986
            }
987
        }
988

    
989
        //[OperationContract]
990
        //public List<FAVORITE_DOC> GetFavoriteVP(string PrjNo, string userID, string sharepointItemID)
991
        //{
992
        //    using (KCOMEntities entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
993
        //    {
994

    
995
        //        int flagString = Convert.ToInt32(IKCOM.FAVORITE_FLAG.Personal);                
996
        //        List<FAVORITE_DOC> favoriteListSet = new List<FAVORITE_DOC>();
997
        //        entity.FAVORITE_DOC.Where(data => data.PROJECT_NO == PrjNo && data.DOCUMENT_ID == sharepointItemID && data.FLAG !=
998
        //            flagString).ToList().ForEach(data => favoriteListSet.Add(data));
999
        //        entity.FAVORITE_DOC.Where(data => data.PROJECT_NO == PrjNo && data.MEMBER_USER_ID == userID).ToList().ForEach(data => favoriteListSet.Add(data));
1000
        //        favoriteListSet = favoriteListSet.Distinct().ToList();
1001
        //        return favoriteListSet;
1002
        //    }
1003
        //}
1004
        //[OperationContract]
1005
        //public bool EditFavoriteVP(string prjNo, string userID, int SavePageNo, string sharepointItemID, DateTime createTime, int state, string description)
1006
        //{
1007
        //    using (DeepViewEntities dc = new DeepViewEntities(ConnectStringBuilder.DeepViewConnectionString().ToString()))
1008
        //    {
1009
        //        List<FavoriteVP> favoriteSet = dc.FavoriteVP.Where(data => data.ProjectNo == prjNo && data.CreateUserID == userID
1010
        //            && data.PageNo == SavePageNo && data.CreateTime == createTime).ToList();
1011

    
1012
        //        try
1013
        //        {
1014

    
1015

    
1016
        //            if (favoriteSet.Count > 0)
1017
        //            {
1018
        //                var FavoriteVP_Instance = favoriteSet.First();
1019

    
1020
        //                FavoriteVP_Instance.Description = description;
1021
        //                FavoriteVP_Instance.Flag = state;
1022

    
1023
        //                dc.SaveChanges();
1024

    
1025
        //                return true;
1026
        //            }
1027
        //            else
1028
        //            {
1029
        //                return false;
1030
        //            }
1031
        //        }
1032
        //        catch (Exception)
1033
        //        {
1034
        //            return false;
1035
        //        }
1036
        //    }
1037
        //}
1038
        //[OperationContract]
1039
        //public bool DelFavoriteVP(string prjNo, string userID, int SavePageNo, string sharepointItemID, DateTime createTime)
1040
        //{
1041

    
1042
        //    using (DeepViewEntities dc = new DeepViewEntities(ConnectStringBuilder.DeepViewConnectionString().ToString()))
1043
        //    {
1044
        //        List<FavoriteVP> favoriteSet = dc.FavoriteVP.Where(data => data.ProjectNo == prjNo && data.CreateUserID == userID
1045
        //            && data.PageNo == SavePageNo && data.CreateTime == createTime).ToList();
1046

    
1047
        //        try
1048
        //        {
1049

    
1050

    
1051
        //            if (favoriteSet.Count > 0)
1052
        //            {
1053
        //                favoriteSet.ForEach(data => dc.FavoriteVP.DeleteObject(data));
1054
        //                dc.SaveChanges();
1055
        //                return true;
1056
        //            }
1057
        //            else
1058
        //            {
1059
        //                return false;
1060
        //            }
1061
        //        }
1062
        //        catch (Exception)
1063
        //        {
1064
        //            return false;
1065
        //        }
1066
        //    }
1067
        //}
1068
        #endregion
1069

    
1070
        [OperationContract]
1071
        public bool SaveMarkupData(MarkupInfoItem UserState,string project_no,string doc_id, string user_id, List<MARKUP_DATA> mlmarkup_data)
1072
        {
1073
            
1074
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1075
            using (CIEntities Entity = new CIEntities(sCIConnString))
1076
            {     
1077
                #region Docinfo 정보 가져오기
1078

    
1079
                string docinfoid_ = (from info in Entity.DOCINFO
1080
                                     where info.DOCUMENT_ID == doc_id
1081
                                     && info.PROJECT_NO == project_no
1082
                                     select info.ID
1083
                                     ).First().ToString();
1084
                #endregion
1085

    
1086
                #region Markup_Info 저장
1087

    
1088
                MARKUP_INFO markup_info = new MARKUP_INFO();
1089
                try
1090
                {
1091
                    markup_info = (from info in Entity.MARKUP_INFO
1092
                                   where info.ID == UserState.MarkupInfoID && info.USER_ID == user_id
1093
                                   select info).FirstOrDefault();
1094
                }
1095
                catch (Exception)
1096
                {
1097
                    markup_info = null;
1098
                }
1099

    
1100
                //markup_info가 없을 경우 생성
1101
                if (markup_info == null)
1102
                {
1103
                    //MarkupInfo 저장
1104
                    markup_info = new MARKUP_INFO
1105
                    {
1106
                        ID = UserState.MarkupInfoID,
1107
                        DOCINFO_ID = docinfoid_,
1108
                        USER_ID = user_id,
1109
                        CREATE_TIME = DateTime.Now,
1110
                        CONSOLIDATE = UserState.Consolidate,
1111
                        AVOID_CONSOLIDATE = UserState.AvoidConsolidate,
1112
                        PART_CONSOLIDATE = UserState.PartConsolidate,
1113
                        DESCRIPTION = UserState.Description,
1114
                        UPDATE_TIME = DateTime.Now
1115
                    };
1116
                    Entity.MARKUP_INFO.AddObject(markup_info);
1117
                }
1118
                //markup_info가 있을 경우 업데이트
1119
                else
1120
                {
1121
                    markup_info.UPDATE_TIME = DateTime.Now;
1122
                }
1123
                Entity.SaveChanges();
1124
                #endregion
1125

    
1126
                #region Markup_Info_Version 저장
1127

    
1128
                MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1129

    
1130
                try
1131
                {
1132
                    markup_info_version = (from info in Entity.MARKUP_INFO_VERSION
1133
                                           where info.MARKUPINFO_ID == markup_info.ID
1134
                                           select info).FirstOrDefault();
1135
                }
1136
                catch (Exception)
1137
                {
1138
                    markup_info_version = null;
1139
                }
1140

    
1141
                //markup_info_version 없을 경우 생성
1142
                if (markup_info_version == null)
1143
                {
1144
                    //MarkupInfo_version 저장
1145
                    markup_info_version = new MARKUP_INFO_VERSION()
1146
                    {
1147
                        ID = UserState.MarkupVersionID,
1148
                        MARKUPINFO_ID = markup_info.ID,
1149
                        CREATE_DATE = DateTime.Now
1150
                    };
1151
                    Entity.MARKUP_INFO_VERSION.AddObject(markup_info_version);
1152
                    Entity.SaveChanges();
1153
                }
1154
                #endregion
1155

    
1156
                
1157
                Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == markup_info_version.ID).ToList().ForEach(item =>
1158
                {
1159
                    Entity.MARKUP_DATA.DeleteObject(item);
1160
                });
1161
                Entity.SaveChanges();
1162

    
1163
                try
1164
                {
1165
                    mlmarkup_data.ForEach(value =>
1166
                    {
1167
                        Entity.MARKUP_DATA.AddObject(new MARKUP_DATA
1168
                        {
1169
                            ID = value.ID,
1170
                            DATA = value.DATA,
1171
                            DATA_TYPE = value.DATA_TYPE,
1172
                            PAGENUMBER = value.PAGENUMBER,
1173
                            MARKUPINFO_VERSION_ID = markup_info_version.ID,
1174
                            SYMBOL_ID = value.SYMBOL_ID,
1175
                            //GROUP_ID = value.GROUP_ID
1176
                        });
1177
                    });
1178
                    Entity.SaveChanges();
1179
                }
1180
                catch (Exception)
1181
                {
1182
                    return false;
1183
                }
1184
            }
1185
            return true;
1186
        }
1187

    
1188
        [OperationContract]
1189
        public bool SavePageMarkupData(MarkupInfoItem UserState,int PageNo, string project_no, string doc_id, string user_id, List<MARKUP_DATA> mlmarkup_data)
1190
        {
1191

    
1192
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1193
            using (CIEntities Entity = new CIEntities(sCIConnString))
1194
            {
1195
                #region Docinfo 정보 가져오기
1196

    
1197
                string docinfoid_ = (from info in Entity.DOCINFO
1198
                                     where info.DOCUMENT_ID == doc_id
1199
                                     && info.PROJECT_NO == project_no
1200
                                     select info.ID
1201
                                     ).First().ToString();
1202
                #endregion
1203

    
1204
                #region Markup_Info 저장
1205

    
1206
                MARKUP_INFO markup_info = new MARKUP_INFO();
1207
                try
1208
                {
1209
                    markup_info = (from info in Entity.MARKUP_INFO
1210
                                   where info.ID == UserState.MarkupInfoID && info.USER_ID == user_id
1211
                                   select info).FirstOrDefault();
1212
                }
1213
                catch (Exception)
1214
                {
1215
                    markup_info = null;
1216
                }
1217

    
1218
                //markup_info가 없을 경우 생성
1219
                if (markup_info == null)
1220
                {
1221
                    //MarkupInfo 저장
1222
                    markup_info = new MARKUP_INFO
1223
                    {
1224
                        ID = UserState.MarkupInfoID,
1225
                        DOCINFO_ID = docinfoid_,
1226
                        USER_ID = user_id,
1227
                        CREATE_TIME = DateTime.Now,
1228
                        CONSOLIDATE = UserState.Consolidate,
1229
                        AVOID_CONSOLIDATE = UserState.AvoidConsolidate,
1230
                        PART_CONSOLIDATE = UserState.PartConsolidate,
1231
                        DESCRIPTION = UserState.Description,
1232
                        UPDATE_TIME = DateTime.Now
1233
                    };
1234
                    Entity.MARKUP_INFO.AddObject(markup_info);
1235
                }
1236
                //markup_info가 있을 경우 업데이트
1237
                else
1238
                {
1239
                    markup_info.UPDATE_TIME = DateTime.Now;
1240
                }
1241
                Entity.SaveChanges();
1242
                #endregion
1243

    
1244
                #region Markup_Info_Version 저장
1245

    
1246
                MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1247

    
1248
                try
1249
                {
1250
                    markup_info_version = (from info in Entity.MARKUP_INFO_VERSION
1251
                                           where info.MARKUPINFO_ID == markup_info.ID
1252
                                           select info).FirstOrDefault();
1253
                }
1254
                catch (Exception)
1255
                {
1256
                    markup_info_version = null;
1257
                }
1258

    
1259
                //markup_info_version 없을 경우 생성
1260
                if (markup_info_version == null)
1261
                {
1262
                    //MarkupInfo_version 저장
1263
                    markup_info_version = new MARKUP_INFO_VERSION()
1264
                    {
1265
                        ID = UserState.MarkupVersionID,
1266
                        MARKUPINFO_ID = markup_info.ID,
1267
                        CREATE_DATE = DateTime.Now
1268
                    };
1269
                    Entity.MARKUP_INFO_VERSION.AddObject(markup_info_version);
1270
                    Entity.SaveChanges();
1271
                }
1272
                #endregion
1273

    
1274

    
1275
                Entity.MARKUP_DATA.Where(data =>  data.PAGENUMBER == PageNo && data.MARKUPINFO_VERSION_ID == markup_info_version.ID).ToList().ForEach(item =>
1276
                {
1277
                    Entity.MARKUP_DATA.DeleteObject(item);
1278
                });
1279
                Entity.SaveChanges();
1280

    
1281
                try
1282
                {
1283
                    mlmarkup_data.ForEach(value =>
1284
                    {
1285
                        Entity.MARKUP_DATA.AddObject(new MARKUP_DATA
1286
                        {
1287
                            ID = value.ID,
1288
                            DATA = value.DATA,
1289
                            DATA_TYPE = value.DATA_TYPE,
1290
                            PAGENUMBER = value.PAGENUMBER,
1291
                            MARKUPINFO_VERSION_ID = markup_info_version.ID,
1292
                            SYMBOL_ID = value.SYMBOL_ID,
1293
                            //GROUP_ID = value.GROUP_ID
1294
                        });
1295
                    });
1296
                    Entity.SaveChanges();
1297
                }
1298
                catch (Exception)
1299
                {
1300
                    return false;
1301
                }
1302
            }
1303
            return true;
1304
        }
1305

    
1306
        //[OperationContract]
1307
        //public long AddMarkupDataGroup(MARKUP_DATA_GROUP mARKUP_DATA_GROUP, string ProjectNo)
1308
        //{
1309
        //    try
1310
        //    {
1311
        //        using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1312
        //        {
1313
        //            Entity.AddToMARKUP_DATA_GROUP(mARKUP_DATA_GROUP);
1314
        //            //MARKUP_DATA_GROUP tt = Entity.MARKUP_DATA_GROUP.Where(info => info.ID == id).FirstOrDefault();
1315
        //            Entity.SaveChanges();
1316

    
1317
        //            return Entity.MARKUP_DATA_GROUP.ToList().LastOrDefault().ID;
1318
        //        }
1319
        //    }
1320
        //    catch (Exception)
1321
        //    {
1322
        //        return 0;
1323
        //    }
1324
        //}
1325
        //[OperationContract]
1326
        //public bool UpdateMarkupDataGroup(long Group_ID, string ProjectNo)
1327
        //{
1328
        //    try
1329
        //    {
1330
        //        using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1331
        //        {
1332
        //            var UpdateItem = Entity.MARKUP_DATA_GROUP.Where(info => info.ID == Group_ID).FirstOrDefault();
1333
        //            UpdateItem.STATE = 1;
1334
        //            Entity.SaveChanges();
1335
        //        }
1336
        //    }
1337
        //    catch (Exception)
1338
        //    {
1339
        //        return false;
1340
        //    }
1341
        //    return true;
1342
        //}
1343
        [OperationContract]
1344
        public bool UpdateMarkupData(string CommentID, long Group_ID, string ProjectNo)
1345
        {
1346
            try
1347
            {
1348
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1349
                using (CIEntities Entity = new CIEntities(sCIConnString))
1350
                {
1351
                    var UpdateItem = Entity.MARKUP_DATA.Where(info => info.ID == CommentID).FirstOrDefault();
1352
                    //UpdateItem.GROUP_ID = Group_ID;
1353
                    Entity.SaveChanges();
1354
                }
1355
            }
1356
            catch (Exception)
1357
            {
1358
                return false;
1359
            }
1360
            return true;
1361
        }
1362

    
1363
        [OperationContract]
1364
        public bool SaveSymbol(SYMBOL_PRIVATE symbol_private)
1365
        {
1366
            try
1367
            {
1368
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1369
                using (KCOMDataModel.DataModel.KCOMEntities uc = new KCOMDataModel.DataModel.KCOMEntities(sConnString))
1370
                {
1371
                    uc.AddToSYMBOL_PRIVATE(symbol_private);
1372
                    uc.SaveChanges();
1373
                }
1374
            }
1375
            catch(Exception)
1376
            {
1377
                return false;
1378
            }
1379
            return true;
1380
        }
1381
        [OperationContract]
1382
        public bool AddPublicSymbol(SYMBOL_PUBLIC symbol)
1383
        {
1384
            try
1385
            {
1386
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1387
                using (KCOMDataModel.DataModel.KCOMEntities uc = new KCOMDataModel.DataModel.KCOMEntities(sConnString))
1388
                {
1389
                    uc.AddToSYMBOL_PUBLIC(symbol);
1390
                    uc.SaveChanges();
1391
                }
1392
            }
1393
            catch (Exception)
1394
            {
1395
                return false;
1396
            }
1397
            return true;
1398
        }
1399
        [OperationContract]
1400
        public bool DeleteSymbol(string symbol_id, int type)
1401
        {
1402
            try
1403
            {
1404
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1405
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
1406
                {
1407
                    if (type == 0)
1408
                    {
1409
                        string delItem_ID = symbol_id;
1410
                        var delitem = Entity.SYMBOL_PRIVATE.Where(data => data.ID == delItem_ID).FirstOrDefault();
1411
                        Entity.SYMBOL_PRIVATE.DeleteObject(delitem);
1412
                        Entity.SaveChanges();
1413
                    }
1414
                    else
1415
                    {
1416
                        string delItem_ID = symbol_id;
1417
                        var delitem = Entity.SYMBOL_PUBLIC.Where(data => data.ID == delItem_ID).FirstOrDefault();
1418
                        Entity.SYMBOL_PUBLIC.DeleteObject(delitem);
1419
                        Entity.SaveChanges();
1420
                    }
1421
                }
1422
            }
1423
            catch(Exception)
1424
            {
1425
                return false;
1426
            }
1427
            return true;
1428
        }
1429

    
1430
        [OperationContract]
1431
        public bool RenameSymbol(string symbol_id, string name, int type)
1432
        {
1433
            try
1434
            {
1435
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1436
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
1437
                {
1438
                    if (type == 0)
1439
                    {
1440
                        var UpdateItem = Entity.SYMBOL_PRIVATE.Where(info => info.ID == symbol_id).FirstOrDefault();
1441
                        UpdateItem.NAME = name;
1442
                        Entity.SaveChanges();
1443
                    }
1444
                    else
1445
                    {
1446
                        var UpdateItem = Entity.SYMBOL_PUBLIC.Where(info => info.ID == symbol_id).FirstOrDefault();
1447
                        UpdateItem.NAME = name;
1448
                        Entity.SaveChanges();
1449
                    }
1450
                }
1451
            }
1452
            catch (Exception)
1453
            {
1454
                return false;
1455
            }
1456
            return true;
1457
        }
1458

    
1459
        [OperationContract]
1460
        public bool AddCheckListHistory(string project_no, CHECK_LIST_HISTORY Check_History)
1461
        {
1462
            try
1463
            {
1464
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1465
                using (CIEntities Entity = new CIEntities(sCIConnString))
1466
                {
1467
                    Entity.CHECK_LIST_HISTORY.AddObject(Check_History);
1468
                    Entity.SaveChanges();  
1469
                }
1470
            }
1471
            catch (Exception)
1472
            {
1473
                return false;
1474
            }
1475
            return true;
1476
        }
1477
        [OperationContract]
1478
        public bool SaveCheckListHistory(string project_no, string rev, CHECK_LIST_HISTORY Check_History)
1479
        {
1480
            try
1481
            {
1482
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1483
                using (CIEntities Entity = new CIEntities(sCIConnString))
1484
                {
1485
                    var item = Entity.CHECK_LIST_HISTORY.Where(info => info.REVISION == rev).FirstOrDefault();
1486
                    item = Check_History;
1487
                    Entity.SaveChanges();
1488
                }
1489
            }
1490
            catch (Exception)
1491
            {
1492
                return false;
1493
            }
1494
            return true;
1495
        }
1496
        [OperationContract]
1497
        public bool SaveCheckList(string project_no, string _id, CHECK_LIST Check_value)
1498
        {
1499
            try
1500
            {
1501
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1502
                using (CIEntities Entity = new CIEntities(sCIConnString))
1503
                {
1504
                    var item = Entity.CHECK_LIST.Where(info => info.ID == _id).FirstOrDefault();
1505
                    item.TODOLIST = Check_value.TODOLIST;
1506
                    item.REMARK = Check_value.REMARK;
1507
                    item.STATUS = Check_value.STATUS;
1508
                    item.VENDOR = Check_value.VENDOR;
1509
                    item.REPLY = Check_value.REPLY;
1510
                    item.IMAGE_URL = Check_value.IMAGE_URL;
1511
                    item.IMAGE_ANCHOR = Check_value.IMAGE_ANCHOR;
1512
                    item.UPDATE_TIME = Check_value.UPDATE_TIME;
1513
                    if(Check_value.STATUS == "False")
1514
                    {
1515
                        item.STATUS_DESC_OPEN = Check_value.STATUS_DESC_OPEN;
1516
                    }
1517
                    else
1518
                    {
1519
                        item.STATUS_DESC_CLOSE = Check_value.STATUS_DESC_CLOSE;
1520
                    }                     
1521
                    Entity.SaveChanges();
1522
                }
1523
            }
1524
            catch (Exception)
1525
            {
1526
                return false;
1527
            }
1528
            return true;
1529
        }
1530
        [OperationContract]
1531
        public bool AddCheckList(string project_no, CHECK_LIST Check_value)
1532
        {
1533
            try
1534
            {
1535
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1536
                using (CIEntities Entity = new CIEntities(sCIConnString))
1537
                {
1538
                    Entity.CHECK_LIST.AddObject(Check_value);
1539
                    Entity.SaveChanges();
1540
                }
1541
            }
1542
            catch (Exception)
1543
            {
1544
                return false;
1545
            }
1546
            return true;
1547
        }
1548

    
1549
        [OperationContract]
1550
        public CHECK_LIST GetCheckList(string project_no, string _id)
1551
        {
1552
            CHECK_LIST Check_value = new CHECK_LIST();
1553
            try
1554
            {
1555
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1556
                using (CIEntities Entity = new CIEntities(sCIConnString))
1557
                {
1558
                    Check_value = Entity.CHECK_LIST.Where(info => info.ID == _id).FirstOrDefault();
1559
                }
1560
            }
1561
            catch (Exception)
1562
            {
1563
                return null;
1564
            }
1565
            return Check_value;
1566
        }
1567
        [OperationContract]
1568
        public List<CHECK_LIST> GetUserCheckList(string project_no, string user_id, string doc_no)
1569
        {
1570
            List<CHECK_LIST> list = new List<CHECK_LIST>();
1571
            try
1572
            {
1573
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1574
                using (CIEntities Entity = new CIEntities(sCIConnString))
1575
                {
1576
                    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();
1577
                }
1578
            }
1579
            catch (Exception)
1580
            {
1581
                return null;
1582
            }
1583
            return list;
1584
        }
1585
        [OperationContract]
1586
        public List<CHECK_LIST_HISTORY> GetCheckListHistory(string project_no, string _id)
1587
        {
1588
            List<CHECK_LIST_HISTORY> history = new List<CHECK_LIST_HISTORY>();
1589
            try
1590
            {
1591
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1592
                using (CIEntities Entity = new CIEntities(sCIConnString))
1593
                {
1594
                    history = Entity.CHECK_LIST_HISTORY.Where(data => data.CHECKLIST_ID == _id).ToList();
1595
                }
1596
            }
1597
            catch (Exception)
1598
            {
1599
                return null;
1600
            }
1601
            return history;
1602
        }
1603
        [OperationContract]
1604
        public CHECK_LIST_HISTORY GetCheckListHistoryFirstOrDefault(string project_no, string checklist_id, string rev)
1605
        {
1606
            CHECK_LIST_HISTORY Check_Item = new CHECK_LIST_HISTORY();
1607
            try
1608
            {
1609
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1610
                using (CIEntities Entity = new CIEntities(sCIConnString))
1611
                {   
1612
                    Check_Item = Entity.CHECK_LIST_HISTORY.Where(info => info.CHECKLIST_ID == checklist_id && info.REVISION == rev).FirstOrDefault();
1613
                }
1614
            }
1615
            catch (Exception)
1616
            {
1617
                return null;
1618
            }
1619
            return Check_Item;
1620
        }
1621
        [OperationContract]
1622
        public bool SavePageAngle(string project_no, List<DOCPAGE> _mldocpage)
1623
        {
1624
            try
1625
            {
1626
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1627
                using (CIEntities Entity = new CIEntities(sCIConnString))
1628
                {
1629
                    KCOMDataModel.DataModel.DOCPAGE _docpage = new KCOMDataModel.DataModel.DOCPAGE();
1630
                    _mldocpage.ForEach(data =>
1631
                    {
1632
                        _docpage = (from info in Entity.DOCPAGE
1633
                                    where info.ID == data.ID
1634
                                    select info).FirstOrDefault();
1635

    
1636
                        if (_docpage.PAGE_ANGLE != data.PAGE_ANGLE)
1637
                        {
1638
                            _docpage.PAGE_ANGLE = data.PAGE_ANGLE;
1639
                        }
1640
                    });
1641

    
1642
                    Entity.SaveChanges();
1643
                }
1644
            }
1645
            catch (Exception)
1646
            {
1647
                return false;
1648
            }
1649
            return true;
1650
        }
1651

    
1652
        [OperationContract]
1653
        public MARKUP_INFO GetMarkupInfo(string project_no, string _id)
1654
        {
1655
            MARKUP_INFO markupInfo = new MARKUP_INFO();
1656

    
1657
            try
1658
            {
1659
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1660
                using (CIEntities Entity = new CIEntities(sCIConnString))
1661
                {
1662
                    markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1663
                }
1664
            }
1665
            catch (Exception)
1666
            {
1667
                return null;
1668
            }
1669
            return markupInfo;
1670
        }
1671

    
1672
        [OperationContract]
1673
        public List<string> GetMarkupDataListperPage(string project_no, string _markupinfoid, int _pageNo)
1674
        {
1675
            List<string> markupdata = new List<string>();
1676
            MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1677
            try
1678
            {
1679
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1680
                using (CIEntities Entity = new CIEntities(sCIConnString))
1681
                {
1682
                    markup_info_version = (from version in Entity.MARKUP_INFO_VERSION
1683
                                           where version.MARKUPINFO_ID == _markupinfoid
1684
                                           orderby version.CREATE_DATE descending
1685
                                           select version).First();
1686
                    markupdata = (from data in Entity.MARKUP_DATA
1687
                                  where data.MARKUPINFO_VERSION_ID == markup_info_version.ID && data.PAGENUMBER == _pageNo
1688
                                  select data.DATA).ToList();
1689
                }
1690
            }
1691
            catch (Exception)
1692
            {
1693
                return null;
1694
            }
1695
            return markupdata;
1696
        }
1697

    
1698
        [OperationContract]
1699
        public bool AddMarkupInfo(string project_no, MARKUP_INFO value)
1700
        {
1701
            try
1702
            {
1703
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1704
                using (CIEntities Entity = new CIEntities(sCIConnString))
1705
                {
1706
                    Entity.MARKUP_INFO.AddObject(value);
1707
                    Entity.SaveChanges();
1708
                }
1709
            }
1710
            catch (Exception)
1711
            {
1712
                return false;
1713
            }
1714
            return true;
1715
        }
1716

    
1717
        [OperationContract]
1718
        public bool AddMarkupInfoVersion(string project_no, MARKUP_INFO_VERSION value)
1719
        {
1720
            try
1721
            {
1722
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1723
                using (CIEntities Entity = new CIEntities(sCIConnString))
1724
                {
1725
                    Entity.MARKUP_INFO_VERSION.AddObject(value);
1726
                    Entity.SaveChanges();
1727
                }
1728
            }
1729
            catch (Exception)
1730
            {
1731
                return false;
1732
            }
1733
            return true;
1734
        }
1735

    
1736
        [OperationContract]
1737
        public bool AddMarkupData(string project_no, MARKUP_DATA value)
1738
        {
1739
            try
1740
            {
1741
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1742
                using (CIEntities Entity = new CIEntities(sCIConnString))
1743
                {
1744
                    Entity.MARKUP_DATA.AddObject(value);
1745
                    Entity.SaveChanges();
1746
                }
1747
            }
1748
            catch (Exception)
1749
            {
1750
                return false;
1751
            }
1752
            return true;
1753
        }
1754

    
1755
        [OperationContract]
1756
        public bool AvoidMarkupInfo(string project_no, string _doc_id)
1757
        {
1758
            try
1759
            {
1760
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1761
                using (CIEntities Entity = new CIEntities(sCIConnString))
1762
                {
1763
                    var item = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1764
                    item.AVOID_CONSOLIDATE = 1;
1765
                    Entity.SaveChanges();
1766
                }
1767
            }
1768
            catch (Exception)
1769
            {
1770
                return false;
1771
            }
1772
            return true;
1773
        }
1774

    
1775
        [OperationContract]
1776
        public bool SaveMarkupInfo(string project_no, string _id, MARKUP_INFO value)
1777
        {
1778
            try
1779
            {
1780
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1781
                using (CIEntities Entity = new CIEntities(sCIConnString))
1782
                {
1783
                    var item = Entity.MARKUP_INFO.Where(info => info.ID == _id).FirstOrDefault();
1784
                    item = value;                    
1785
                    Entity.SaveChanges();
1786
                }
1787
            }
1788
            catch (Exception)
1789
            {
1790
                return false;
1791
            }
1792
            return true;
1793
        }
1794
        [OperationContract]
1795
        public List<MARKUP_DATA> GetMarkupDataList(string project_no, string _versionid)
1796
        {
1797
            List<MARKUP_DATA> mlresult = new List<MARKUP_DATA>();
1798

    
1799
            try
1800
            {
1801
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1802
                using (CIEntities Entity = new CIEntities(sCIConnString))
1803
                {
1804
                    mlresult = Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == _versionid).ToList();
1805
                }
1806
            }
1807
            catch (Exception)
1808
            {
1809
                return null;
1810
            }
1811
            return mlresult;
1812
        }
1813

    
1814
        [OperationContract]
1815
        public bool Consolidate(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems)
1816
        {
1817
            try
1818
            {
1819
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
1820
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1821
                using (CIEntities Entity = new CIEntities(sCIConnString))
1822
                {
1823
                    var markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id && entity.CONSOLIDATE == 1).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1824
                    if (markupInfo != null)
1825
                    {
1826
                        markupInfo.AVOID_CONSOLIDATE = 1;
1827
                    }
1828

    
1829
                    foreach (MarkupInfoItem item in markupInfoItems)
1830
                    {
1831
                        Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == item.MarkupVersionID).ToList().ForEach(d =>
1832
                        {
1833
                            instanceDataSet.Add(d);
1834
                        });
1835
                    }
1836

    
1837
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
1838
                    info.ID = shortGuid();
1839
                    info.CONSOLIDATE = 1;
1840
                    info.CREATE_TIME = DateTime.Now;
1841
                    info.DOCINFO_ID = _doc_id;
1842
                    info.UPDATE_TIME = DateTime.Now;
1843
                    info.USER_ID = _user_id;
1844
                    info.AVOID_CONSOLIDATE = 0;
1845

    
1846
                    Entity.MARKUP_INFO.AddObject(info);
1847
                    Entity.SaveChanges();
1848

    
1849

    
1850
                    KCOMDataModel.DataModel.MARKUP_INFO_VERSION info2 = new KCOMDataModel.DataModel.MARKUP_INFO_VERSION
1851
                    {
1852
                        ID = shortGuid(),
1853
                        CREATE_DATE = DateTime.Now,
1854
                        MARKUP_INFO = info,
1855
                    };
1856
                    Entity.SaveChanges();
1857

    
1858
                    foreach (var item in instanceDataSet)
1859
                    {
1860
                        Entity.MARKUP_DATA.AddObject(new KCOMDataModel.DataModel.MARKUP_DATA
1861
                        {
1862
                            ID = shortGuid(),
1863
                            DATA = item.DATA,
1864
                            DATA_TYPE = item.DATA_TYPE,
1865
                            PAGENUMBER = item.PAGENUMBER,
1866
                            MARKUP_INFO_VERSION = info2,
1867
                            SYMBOL_ID = item.SYMBOL_ID,
1868
                            //GROUP_ID = item.GROUP_ID
1869
                        });
1870
                    }
1871
                    Entity.SaveChanges();
1872

    
1873

    
1874
                }
1875
            }
1876
            catch (Exception)
1877
            {
1878
                return false;
1879
            }
1880
            return true;
1881
        }
1882

    
1883

    
1884
        [OperationContract]
1885
        public FinalPDFResult ConsolidateMergedPDF(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems, string ProjectNo, string DocInfoID, string CreateUserID)
1886
        {
1887
            bool consolidate = false;
1888
            try
1889
            {
1890
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
1891
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1892
                using (CIEntities Entity = new CIEntities(sCIConnString))
1893
                {
1894
                    var markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1895
                    if (markupInfo.CONSOLIDATE == 1)
1896
                    {
1897
                        markupInfo.AVOID_CONSOLIDATE = 1;
1898
                    }
1899

    
1900
                    foreach (MarkupInfoItem item in markupInfoItems)
1901
                    {
1902
                        Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == item.MarkupVersionID).ToList().ForEach(d =>
1903
                        {
1904
                            instanceDataSet.Add(d);
1905
                        });
1906
                    }
1907

    
1908
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
1909
                    info.ID = shortGuid();
1910
                    info.CONSOLIDATE = 1;
1911
                    info.CREATE_TIME = DateTime.Now;
1912
                    info.DOCINFO_ID = _doc_id;
1913
                    info.UPDATE_TIME = DateTime.Now;
1914
                    info.USER_ID = _user_id;
1915
                    info.AVOID_CONSOLIDATE = 0;
1916

    
1917
                    Entity.MARKUP_INFO.AddObject(info);
1918
                    Entity.SaveChanges();
1919

    
1920

    
1921
                    KCOMDataModel.DataModel.MARKUP_INFO_VERSION info2 = new KCOMDataModel.DataModel.MARKUP_INFO_VERSION
1922
                    {
1923
                        ID = shortGuid(),
1924
                        CREATE_DATE = DateTime.Now,
1925
                        MARKUP_INFO = info,
1926
                    };
1927
                    Entity.SaveChanges();
1928

    
1929
                    foreach (var item in instanceDataSet)
1930
                    {
1931
                        Entity.MARKUP_DATA.AddObject(new KCOMDataModel.DataModel.MARKUP_DATA
1932
                        {
1933
                            ID = shortGuid(),
1934
                            DATA = item.DATA,
1935
                            DATA_TYPE = item.DATA_TYPE,
1936
                            PAGENUMBER = item.PAGENUMBER,
1937
                            MARKUP_INFO_VERSION = info2,
1938
                            SYMBOL_ID = item.SYMBOL_ID,
1939
                            //GROUP_ID = item.GROUP_ID
1940
                        });
1941
                    }
1942
                    Entity.SaveChanges();
1943

    
1944

    
1945
                }
1946
                consolidate = true;
1947
            }
1948
            catch (Exception)
1949
            {
1950
                consolidate = false;
1951
            }
1952
            FinalPDFResult _result = new FinalPDFResult();
1953
            if (consolidate == true)
1954
            {
1955
                RemFinalPDFObject remObj = null;
1956
                try
1957
                {
1958
                    string _finalID = shortGuid();
1959
                    int _DocTotalPages = -1;
1960
                    string docItemId;
1961

    
1962
                    string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1963
                    using (CIEntities _ci = new CIEntities(sCIConnString))
1964
                    {
1965
                        var _doc = _ci.DOCINFO.Where(info => info.ID == DocInfoID);
1966

    
1967
                        if (_doc.Count() > 0)
1968
                        {
1969
                            _DocTotalPages = _doc.First().PAGE_COUNT;
1970
                            docItemId = _doc.First().DOCUMENT_ID;
1971
                        }
1972
                        else
1973
                        {
1974
                            _result.Status = FinalStatus.Error;
1975
                            _result.Exception = "페이지 정보를 가져올 수 없습니다.";
1976
                            return _result;
1977
                        }
1978
                    }
1979

    
1980
                    var Items = GetMarkupInfoItems(ProjectNo, DocInfoID);
1981
                    if (_DocTotalPages > 0)
1982
                    {
1983
                        var item2 = Items.Cast<MarkupInfoItem>().Where(d => d.Consolidate == 1 && d.AvoidConsolidate == 0).FirstOrDefault();
1984
                        FINAL_PDF fm = new FINAL_PDF()
1985
                        {
1986
                            ID = _finalID,
1987
                            PROJECT_NO = ProjectNo,
1988
                            DOCINFO_ID = DocInfoID,
1989
                            DOCUMENT_ID = docItemId,
1990
                            MARKUPINFO_ID = item2.MarkupInfoID,
1991
                            CREATE_USER_ID = CreateUserID,
1992
                            TOTAL_PAGE = _DocTotalPages,
1993
                            CREATE_DATETIME = DateTime.Now,
1994
                            STATUS = (int)IFinalPDF.FinalStatus.Insert
1995
                        };
1996

    
1997
                        string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1998
                        using (KCOMEntities _entity = new KCOMEntities(sConnString))
1999
                        {
2000
                            _entity.AddToFINAL_PDF(fm);
2001
                            _entity.SaveChanges(System.Data.Objects.SaveOptions.AcceptAllChangesAfterSave);
2002
                        };
2003

    
2004
                        System.Runtime.Remoting.Channels.IChannel _ch = System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp");
2005
                        if (_ch == null)
2006
                        {
2007
                            chan = new TcpChannel();
2008
                            _ChanID = chan.ChannelName;
2009
                            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan, false);
2010
                            // Create an instance of the remote object
2011

    
2012
                            using (KCOMEntities ec = new KCOMEntities(sConnString))
2013
                            {
2014

    
2015
                                //remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
2016
                                //                          "tcp://localhost:9092/remFinalPDF");
2017
                                remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
2018
                                                          //"tcp://192.168.0.67:9092/remFinalPDF");
2019
                                                          "tcp://192.168.0.67:9092/remFinalPDF");
2020
                            }
2021

    
2022
                            //"tcp://localhost:8080/remFinalPDF");
2023

    
2024
                            _result = remObj.SetFinalPDF(ProjectNo, _finalID);
2025
                            _result.FinalID = _finalID;
2026
                            _result.Status = FinalStatus.Success;
2027

    
2028
                            //MarkupToPDF.MarkupToPDF fa = new MarkupToPDF.MarkupToPDF();
2029
                            //fa.MakeFinalPDF(fm);
2030
                        }
2031
                        else
2032
                        {
2033
                            _ChanID = _ch.ChannelName;
2034
                        }
2035
                    }
2036
                }
2037
                catch (Exception ex)
2038
                {
2039
                    _result.Status = FinalStatus.Error;
2040

    
2041
                    if (ex.GetType() == typeof(System.Net.Sockets.SocketException))
2042
                        _result.Exception = "Final Server Not Connection";
2043
                }
2044
                finally
2045
                {
2046
                    remObj = null;
2047
                    if (System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp") != null)
2048
                        System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(chan);
2049

    
2050
                    GC.Collect(2);
2051
                }
2052
            }
2053
            return _result;
2054
        }
2055
        [OperationContract]
2056
        public bool TeamConsolidate(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems)
2057
        {
2058
            try
2059
            {
2060
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
2061
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2062
                using (CIEntities Entity = new CIEntities(sCIConnString))
2063
                {
2064
                    string user_dept = Entity.MEMBER.Where(m => m.ID == _user_id).FirstOrDefault().DEPARTMENT;
2065
                    var markupInfos = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id
2066
                    && entity.PART_CONSOLIDATE == 1
2067
                    ).OrderByDescending(j => j.CREATE_TIME).ToList();
2068
                    foreach (var markupinfo in markupInfos)
2069
                    {
2070
                        string markupdept = Entity.MEMBER.Where(m => m.ID == markupinfo.USER_ID).FirstOrDefault().DEPARTMENT;
2071
                        if (user_dept == markupdept)
2072
                        {
2073
                            markupinfo.AVOID_CONSOLIDATE = 1;
2074
                        }
2075
                    }
2076

    
2077
                    foreach (MarkupInfoItem item in markupInfoItems)
2078
                    {
2079
                        Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == item.MarkupVersionID).ToList().ForEach(d =>
2080
                        {
2081
                            instanceDataSet.Add(d);
2082
                        });
2083
                    }
2084

    
2085
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
2086
                    info.ID = shortGuid();
2087
                    info.PART_CONSOLIDATE = 1;
2088
                    info.CREATE_TIME = DateTime.Now;
2089
                    info.DOCINFO_ID = _doc_id;
2090
                    info.UPDATE_TIME = DateTime.Now;
2091
                    info.USER_ID = _user_id;
2092
                    info.AVOID_CONSOLIDATE = 0;
2093

    
2094
                    Entity.MARKUP_INFO.AddObject(info);
2095
                    Entity.SaveChanges();
2096

    
2097

    
2098
                    KCOMDataModel.DataModel.MARKUP_INFO_VERSION info2 = new KCOMDataModel.DataModel.MARKUP_INFO_VERSION
2099
                    {
2100
                        ID = shortGuid(),
2101
                        CREATE_DATE = DateTime.Now,
2102
                        MARKUP_INFO = info,
2103
                    };
2104
                    Entity.SaveChanges();
2105

    
2106
                    foreach (var item in instanceDataSet)
2107
                    {
2108
                        Entity.MARKUP_DATA.AddObject(new KCOMDataModel.DataModel.MARKUP_DATA
2109
                        {
2110
                            ID = shortGuid(),
2111
                            DATA = item.DATA,
2112
                            DATA_TYPE = item.DATA_TYPE,
2113
                            PAGENUMBER = item.PAGENUMBER,
2114
                            MARKUP_INFO_VERSION = info2,
2115
                            SYMBOL_ID = item.SYMBOL_ID,
2116
                            //GROUP_ID = item.GROUP_ID
2117
                        });
2118
                    }
2119
                    Entity.SaveChanges();
2120

    
2121

    
2122
                }
2123
            }
2124
            catch (Exception)
2125
            {
2126
                return false;
2127
            }
2128
            return true;
2129
        }
2130

    
2131
        [OperationContract]
2132
        [ServiceKnownType(typeof(MEMBER))]
2133
        public MEMBER GetMember(string project_no, string user_id)
2134
        {
2135
            MEMBER rstmember = new MEMBER();
2136
            try
2137
            {
2138
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2139
                using (CIEntities Entity = new CIEntities(sCIConnString))
2140
                {
2141
                    var tmp = (from member in Entity.MEMBER
2142
                                    where member.ID == user_id && member.PROJECT_NO == project_no
2143
                                    select member).FirstOrDefault();
2144
                    rstmember.DEPARTMENT = tmp.DEPARTMENT;
2145
                    rstmember.ID = tmp.ID;
2146
                    rstmember.NAME = tmp.NAME;
2147
                }
2148
            }
2149
            catch (Exception ex)
2150
            {
2151
                return null;
2152
            }
2153
            return rstmember;
2154
        }
2155

    
2156
        [WebMethod]
2157
        [OperationContract]
2158
        public List<SYMBOL_PRIVATE> GetSymbolList(string user_id)
2159
        {
2160
            List<SYMBOL_PRIVATE> Custom_List = new List<SYMBOL_PRIVATE>();
2161
            try
2162
            {
2163
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2164
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2165
                {
2166
                    Custom_List = Entity.SYMBOL_PRIVATE.Where(data => data.MEMBER_USER_ID == user_id).ToList();
2167
                }
2168
            }
2169
            catch (Exception ex)
2170
            {
2171
                return null;
2172
            }
2173
            return Custom_List;
2174
        }
2175
        [OperationContract]
2176
        public List<string> GetPublicSymbolDeptList()
2177
        {
2178
            List<string> Custom_List = new List<string>();
2179
            try
2180
            {
2181
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2182
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2183
                {
2184
                    Custom_List = Entity.SYMBOL_PUBLIC.Select(data => data.DEPARTMENT).Distinct().ToList();
2185
                }
2186
            }
2187
            catch (Exception)
2188
            {
2189
                return null;
2190
            }
2191
            return Custom_List;
2192
        }
2193
        [OperationContract]
2194
        public List<SYMBOL_PUBLIC> GetPublicSymbolList(string dept)
2195
        {
2196
            List<SYMBOL_PUBLIC> Custom_List = new List<SYMBOL_PUBLIC>();
2197
            try
2198
            {
2199
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2200
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2201
                {
2202
                    if(!string.IsNullOrEmpty(dept))
2203
                    {
2204
                        Custom_List = Entity.SYMBOL_PUBLIC.Where(data => data.DEPARTMENT == dept).ToList();
2205
                    }
2206
                    else
2207
                    {
2208
                        Custom_List = Entity.SYMBOL_PUBLIC.ToList();
2209
                    }
2210
                    
2211
                }
2212
            }
2213
            catch (Exception)
2214
            {
2215
                return null;
2216
            }
2217
            return Custom_List;
2218
        }
2219

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

    
2308
            }
2309
            catch (Exception)
2310
            {
2311
                return null;
2312
            }
2313
            return result;
2314
        }
2315

    
2316
        [OperationContract]        
2317
        public string GetProjectName(string project_no)
2318
        {
2319
            string result = null;
2320

    
2321
            try
2322
            {
2323
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2324
                using (KCOMDataModel.DataModel.KCOMEntities Entity = new KCOMDataModel.DataModel.KCOMEntities(sConnString))
2325
                {
2326
                    result = Entity.RUN_PROJECTS.Where(i => i.PROJECT_NO == project_no).FirstOrDefault().PROJECT_NAME.ToString();
2327
                }
2328
            }
2329
            catch (Exception)
2330
            {
2331
                return null;
2332
            }
2333
            return result;
2334
        }
2335

    
2336
        [OperationContract]
2337
        public List<DOCUMENT_ITEM> GetPreRevSelect(string project_no, string doc_no, string current_rev)
2338
        {
2339
            List<DOCUMENT_ITEM> result = new List<DOCUMENT_ITEM>();
2340
            
2341
            try
2342
            {
2343
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2344
                using (CIEntities Entity = new CIEntities(sCIConnString))
2345
                {
2346
                    result = Entity.DOCUMENT_ITEM.Where(i => i.PROJECT_NO == project_no
2347
                    && i.DOCUMENT_NO == doc_no
2348
                    && i.REVISION != current_rev).OrderByDescending(i => i.GROUP_NO).ToList();
2349
                }
2350
            }
2351
            catch (Exception)
2352
            {
2353
                return null;
2354
            }
2355
            return result;
2356
        }
2357

    
2358
        [OperationContract]
2359
        public DOCINFO GetDocInfoOneSelect(string project_no, string doc_id)
2360
        {
2361
            DOCINFO docinfo = null;
2362

    
2363
            try
2364
            {
2365
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2366
                using (CIEntities Entity = new CIEntities(sCIConnString))
2367
                {
2368
                    docinfo = (from info in Entity.DOCINFO
2369
                              where info.DOCUMENT_ID == doc_id
2370
                              && info.PROJECT_NO == project_no
2371
                              select info).First();
2372
                }
2373
            }
2374
            catch (Exception)
2375
            {
2376
                return null;
2377
            }
2378
            return docinfo;
2379
        }
2380

    
2381
        [OperationContract]
2382
        public List<MarkupInfoItem> GetPrintDocItemList(string project_no, string doc_id, List<MarkupInfoItem> _markupInfoList)
2383
        {
2384
            MarkupInfoItem _result = null;
2385
            List<MarkupInfoItem> markupinfo = new List<MarkupInfoItem>();
2386
            try
2387
            {
2388
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2389
                using (CIEntities Entity = new CIEntities(sCIConnString))
2390
                {
2391
                    var docitem = (from info in Entity.DOCINFO
2392
                               where info.DOCUMENT_ID == doc_id
2393
                               && info.PROJECT_NO == project_no
2394
                               select info).First();
2395

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

    
2422
                        _result.MarkupList = new List<IKCOM.MarkupItem>();
2423
                        var markup_Version = markinfo.MARKUP_INFO_VERSION.OrderByDescending(p => p.CREATE_DATE).First();
2424

    
2425
                        foreach (MARKUP_DATA markdata in markup_Version.MARKUP_DATA)
2426
                        {
2427
                            MarkupItem markitem = new MarkupItem()
2428
                            {
2429
                                ID = markdata.ID,
2430
                                PageNumber = markdata.PAGENUMBER,
2431
                            };
2432
                            _result.MarkupList.Add(markitem);
2433
                        }
2434

    
2435
                        _result.PageCount = _result.MarkupList.GroupBy(i => i.PageNumber).Count();
2436

    
2437
                        markupinfo.Add(_result);
2438
                    }
2439
                }
2440
            }
2441
            catch (Exception)
2442
            {
2443
                return null;
2444
            }
2445
            return markupinfo;
2446
        }
2447

    
2448
        [OperationContract]
2449
        public bool AddMessage(string project_no, TALK value)
2450
        {
2451
            try
2452
            {
2453
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2454
                using (CIEntities entity = new CIEntities(sCIConnString))
2455
                {                    
2456
                    entity.TALK.AddObject(value);
2457
                    entity.SaveChanges();
2458
                }
2459
            }
2460
            catch (Exception)
2461
            {
2462
                return false;
2463
            }
2464
            return true;
2465
        }
2466

    
2467
        [OperationContract]
2468
        public List<TALK> GetMessage(string project_no, string doc_id)
2469
        {
2470
            List<TALK> result = new List<TALK>();
2471
            try
2472
            {
2473
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2474
                using (CIEntities entity = new CIEntities(sCIConnString))
2475
                {
2476
                    result = entity.TALK.Where(data => data.DOCUMENT_ID == doc_id).ToList();                        
2477
                }
2478
            }
2479
            catch (Exception ex)
2480
            {
2481
                return result;
2482
            }
2483
            return result;
2484
        }
2485

    
2486

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

    
2533

    
2534
        }
2535
        #endregion
2536

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

    
2544
            try
2545
            {
2546
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2547
                using (CIEntities _entity = new CIEntities(sCIConnString))
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
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2578
                using (CIEntities _entity = new CIEntities(sCIConnString))
2579
                {
2580
                    var doc = _entity.DOCUMENT_ITEM.Where(x => x.DOCUMENT_ID == document_id).FirstOrDefault();
2581
                    if(doc != null)
2582
                    {
2583
                        item = new DOCUMENT_ITEM()
2584
                        {
2585
                            ID = doc.ID,
2586
                            ORIGINAL_FILE = doc.ORIGINAL_FILE,
2587
                            PROJECT_NO = doc.PROJECT_NO,
2588
                            DOCUMENT_ID = doc.DOCUMENT_ID,
2589
                            DOCUMENT_NO = doc.DOCUMENT_NO,
2590
                            DOCUMENT_NAME = doc.DOCUMENT_NAME,
2591
                            ENSEMBLEINFO_URL = doc.ENSEMBLEINFO_URL,
2592
                            GROUP_NO = doc.GROUP_NO,
2593
                            RESULT = doc.RESULT,
2594
                            REVISION = doc.REVISION,
2595
                            RESULT_FILE = doc.RESULT_FILE
2596
                        };
2597
                    }
2598
                    
2599
                }
2600
            }
2601
            catch (Exception)
2602
            {
2603
                throw;
2604
            }
2605
            return item;
2606
        }
2607
        [OperationContract]
2608
        [ServiceKnownType(typeof(MARKUP_DATA))]
2609
        public List<MARKUP_DATA> FinalPDF_GetMarkupdata(string project_no, string docinfo_id)
2610
        {
2611
            List<MARKUP_DATA> results = new List<MARKUP_DATA>();
2612

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

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

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

    
2720
            try
2721
            {
2722
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2723
                using (CIEntities _entity = new CIEntities(sCIConnString))
2724
                {
2725
                    var pages = _entity.DOCPAGE.Where(x => x.DOCINFO_ID == docinfo_id).OrderBy(x => x.PAGE_NUMBER).ToList();
2726
                    foreach(var page in pages)
2727
                    {
2728
                        DOCPAGE p = new DOCPAGE()
2729
                        {
2730
                            PAGE_ANGLE = page.PAGE_ANGLE,
2731
                            PAGE_NUMBER = page.PAGE_NUMBER,
2732
                            PAGE_HEIGHT = page.PAGE_HEIGHT,
2733
                            PAGE_WIDTH = page.PAGE_WIDTH,
2734
                            DOCINFO_ID = page.DOCINFO_ID                            
2735
                        };
2736
                        results.Add(p);
2737
                    }                    
2738
                }
2739
            }
2740
            catch (Exception)
2741
            {
2742
                throw;
2743
            }
2744
            return results;
2745
        }
2746
        [OperationContract]        
2747
        public bool FinalPDF_SetFinalPDFStatus(string final_id, FinalStatus status)
2748
        {
2749
            bool result = false;
2750

    
2751
            try
2752
            {
2753
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2754
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
2755
                {
2756
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
2757
                    if(tmp != null)
2758
                    {
2759
                        switch(status)
2760
                        {
2761
                            case FinalStatus.Create:
2762
                                tmp.START_DATETIME = DateTime.Now;
2763
                                break;
2764
                            case FinalStatus.Success:
2765
                                tmp.END_DATETIME = DateTime.Now;
2766
                                tmp.EXCEPTION = string.Empty;
2767
                                break;                                
2768
                        }
2769
                        tmp.STATUS = (int)status;
2770
                        _entity.SaveChanges();
2771
                        result = true;                        
2772
                    }
2773
                }                    
2774
            }
2775
            catch (Exception)
2776
            {
2777
                throw;
2778
            }
2779
            return result;
2780
        }
2781

    
2782
        /// <summary>
2783
        /// 현재 진행중인 Final PDF 가 없거나 Success 일 경우에만 true return
2784
        /// </summary>
2785
        /// <param name="DocInfoID"></param>
2786
        /// <param name="MarkupInfoID"></param>
2787
        /// <param name="CreateUserID"></param>
2788
        /// <returns></returns>
2789
        [OperationContract]
2790
        public bool FinalPDF_GetFinalPDFStatus(string DocInfoID, string MarkupInfoID, string CreateUserID)
2791
        {
2792
            bool result = false;
2793

    
2794
            try
2795
            {
2796
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2797
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
2798
                {
2799
                    var finalpdf = _entity.FINAL_PDF.Where(x => x.DOCINFO_ID == DocInfoID && x.MARKUPINFO_ID == MarkupInfoID && x.CREATE_USER_ID == CreateUserID && x.STATUS != (int)FinalStatus.Error).FirstOrDefault();
2800
                    if (finalpdf != null)
2801
                    {
2802
                        if (finalpdf.STATUS == (int)FinalStatus.Success)
2803
                        {
2804
                            result = true;
2805
                        }
2806
                    }
2807
                    else
2808
                        result = true;
2809
                }
2810
            }
2811
            catch (Exception)
2812
            {
2813
                throw;
2814
            }
2815
            return result;
2816
        }
2817

    
2818
        [OperationContract]
2819
        public bool FinalPDF_SetCurrentPage(string final_id, int currentpage)
2820
        {
2821
            bool result = false;
2822

    
2823
            try
2824
            {
2825
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2826
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
2827
                {
2828
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
2829
                    if (tmp != null)
2830
                    {
2831
                        tmp.CURRENT_PAGE = currentpage;
2832
                        _entity.SaveChanges();
2833
                        result = true;
2834
                    }
2835
                }
2836
            }
2837
            catch (Exception)
2838
            {
2839
                throw;
2840
            }
2841
            return result;
2842
        }
2843
        [OperationContract]
2844
        public bool FinalPDF_SetError(string final_id, string msg)
2845
        {
2846
            bool result = false;
2847

    
2848
            try
2849
            {
2850
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2851
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
2852
                {
2853
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
2854
                    if (tmp != null)
2855
                    {                        
2856
                        tmp.STATUS = (int)FinalStatus.Error;
2857
                        tmp.EXCEPTION = DateTime.Now.ToShortDateString() + " " + msg;                        
2858
                        _entity.SaveChanges();
2859
                        result = true;
2860
                    }
2861
                }
2862
            }
2863
            catch (Exception)
2864
            {
2865
                throw;
2866
            }
2867
            return result;
2868
        }
2869

    
2870
        [OperationContract]
2871
        public bool FinalPDF_SetFinalResultPath(string project_no, string document_id, string url)
2872
        {
2873
            bool result = false;
2874

    
2875
            try
2876
            {
2877
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2878
                using (CIEntities _entity = new CIEntities(sCIConnString))
2879
                {
2880
                    var item = _entity.DOCUMENT_ITEM.Where(d => d.DOCUMENT_ID == document_id).FirstOrDefault();
2881
                    if (item != null)
2882
                    {
2883
                        item.RESULT_FILE = url;
2884
                        _entity.SaveChanges();
2885
                        result = true;
2886
                    }
2887
                }
2888
            }
2889
            catch (Exception)
2890
            {
2891
                throw;
2892
            }
2893
            return result;
2894
        }
2895
        [OperationContract]
2896
        [ServiceKnownType(typeof(MEMBER))]
2897
        public MEMBER FinalPDF_GetCommentMember(string project_no, string markupdata_id)
2898
        {
2899
            MEMBER member = null;
2900
            try
2901
            {
2902
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2903
                using (CIEntities _entity = new CIEntities(sCIConnString))
2904
                {
2905
                    var data = _entity.MARKUP_DATA.Where(x => x.ID == markupdata_id).FirstOrDefault();
2906
                    string user_id = data.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID;
2907
                    var person = _entity.MEMBER.Where(p => p.ID == user_id).FirstOrDefault();
2908
                    if(person != null)
2909
                    {
2910
                        member = new MEMBER()
2911
                        {
2912
                            ID = user_id,
2913
                            NAME = person.NAME,
2914
                            DEPARTMENT = person.DEPARTMENT
2915
                        };
2916
                    }
2917
                }
2918
            }
2919
            catch (Exception)
2920
            {
2921
                throw;
2922
            }
2923
            return member;
2924
        }
2925

    
2926
        [OperationContract]
2927
        [ServiceKnownType(typeof(PROPERTIES))]
2928
        public List<PROPERTIES> FinalPDF_GetProperties(string project_no)
2929
        {
2930
            List<PROPERTIES> results = new List<PROPERTIES>();
2931
            try
2932
            {
2933
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2934
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
2935
                {
2936
                    var _items = _entity.PROPERTIES.Where(x => x.PROPERTY == project_no).ToList();
2937
                    foreach(var item in _items)
2938
                    {
2939
                        PROPERTIES pROPERTIES = new PROPERTIES()
2940
                        {
2941
                            ID = item.ID,
2942
                            PROPERTY = item.PROPERTY,
2943
                            TYPE = item.TYPE,
2944
                            VALUE = item.VALUE
2945
                        };
2946
                        results.Add(pROPERTIES);
2947
                    }
2948
                }
2949

    
2950
            }
2951
            catch (Exception)
2952
            {
2953
                throw;
2954
            }
2955
            return results;
2956
        }
2957
        #endregion
2958
    }    
2959
}
클립보드 이미지 추가 (최대 크기: 500 MB)