프로젝트

일반

사용자정보

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

markus / KCOM_API / ServiceDeepView.svc.cs @ 8295a079

이력 | 보기 | 이력해설 | 다운로드 (139 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
using ColorSelector;
20
using Newtonsoft.Json.Linq;
21

    
22
namespace KCOM_API
23
{
24
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ServiceDeepView" in code, svc and config file together.
25
    // 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.
26
    [ServiceContract(Namespace = "")]
27
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
28
    public partial class ServiceDeepView : System.Web.Services.WebService
29
    {
30
        public ServiceDeepView()
31
        {
32
            //System.Diagnostics.Trace.WriteLine(OperationContext.Current.RequestContext.RequestMessage.Headers.Action.ToString());
33
        }
34

    
35
        /// <summary>
36
        /// Client Version 과 Server Version 을 비교하여 Server Version 이 최신이면 다운로드 url 리턴.
37
        /// </summary>
38
        /// <param name="is64BitProcess">64bit = true, 32bit = false</param>
39
        /// <param name="markusVer">client version</param>
40
        /// <returns></returns>
41
        [OperationContract]
42
        public string GetVersionData(bool is64BitProcess, string markusVer)
43
        {
44
            string url = null;
45

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

    
67
                //서버 버전이 최신이면 0보다 큰값 리턴
68
                Version server_version = new Version(dbvalue.PROPERTY);
69
                int result = server_version.CompareTo(client_version);  
70
                if (result > 0)
71
                {
72
                    url = dbvalue.VALUE;
73
                }
74
            }
75
            catch (Exception ex)
76
            {
77
                System.Diagnostics.Trace.WriteLine("KCOM_API - GetVersionData : " + ex.ToString());
78

    
79
                url = null;
80
            }
81
            return url;
82
        }
83
    
84

    
85
        [OperationContract]
86
        public KCOM_SystemInfo GetSystemData()
87
        {
88
            try
89
            {
90
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
91
                using (KCOMEntities uc = new KCOMEntities(sConnString))
92
                {
93
                    var SystemInfoSet = uc.PROPERTIES.Where(data => data.TYPE == "SystemInfo").ToList();
94

    
95
                    KCOM_SystemInfo sysInfo = new KCOM_SystemInfo();
96

    
97
                    var url = SystemInfoSet.Where(data => data.PROPERTY == "Url").FirstOrDefault();
98
                    if (url != null)
99
                    {
100
                        sysInfo.HostName = url.VALUE;
101
                    }
102

    
103
                    var port = SystemInfoSet.Where(data => data.PROPERTY == "Port").FirstOrDefault();
104
                    if (port != null)
105
                    {
106
                        sysInfo.HostPort = port.VALUE;
107
                    }
108

    
109
                    var stamp = uc.PROPERTIES.Where(data => data.TYPE == "STAMP").FirstOrDefault();
110
                    if(stamp != null)
111
                    {
112
                        sysInfo.STAMP = stamp.VALUE;
113

    
114
                    }
115

    
116
                    var stampContents = uc.PROPERTIES.Where(data => data.TYPE == "STAMP_CONTENTS");
117

    
118
                    if (stampContents?.Count() > 0)
119
                    {
120
                        sysInfo.STAMP_CONTENTS = stampContents.ToDictionary(x => x.PROPERTY, x => x.VALUE);
121
                    }
122

    
123
                    return sysInfo;
124
                }
125
            }
126
            catch (Exception ex)
127
            {
128
                System.Diagnostics.Trace.WriteLine("KCOM_API - GetSystemData : " + ex.ToString());
129

    
130
            }
131
            return null;
132
            //GC.Collect(2);
133
        }
134

    
135
        private static string shortGuid()
136
        { 
137
            byte[] bytes = new byte[16];
138
            using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create())
139
            {
140
                provider.GetBytes(bytes);
141
            }
142

    
143
            var guid = new Guid(bytes);
144

    
145
            return Convert.ToBase64String(guid.ToByteArray())
146
                .Substring(0, 10)
147
                .Replace("/", "")
148
                .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
149
        }
150

    
151

    
152
        [OperationContract]
153
        public List<FAVORITE_DOC> GetFavoriteVP(string PrjNo, string userID, string sharepointItemID)
154
        {
155
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
156
            using (KCOMEntities dc = new KCOMEntities(sConnString))
157
            {
158

    
159
                int flagString = Convert.ToInt32(FAVORITE_FLAG.Personal);
160
                List<FAVORITE_DOC> favoriteListSet = new List<FAVORITE_DOC>();
161
                //dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == PrjNo && data.DOCUMENT_ID == sharepointItemID && data.FLAG !=
162
                //    flagString).ToList().ForEach(data => favoriteListSet.Add(data));
163

    
164

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

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

    
169
                //favoriteListSet = favoriteListSet.Distinct().ToList();
170
                return favoriteListSet;
171
            }
172
        }
173

    
174
        [OperationContract]
175
        public bool EditFavoriteVP(string prjNo, string userID, string docID, int state, string description)
176
        {
177
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
178
            using (KCOMEntities dc = new KCOMEntities(sConnString))
179
            {
180
                //List<FAVORITE_DOC> favoriteSet = dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == prjNo && data.MEMBER_USER_ID == userID
181
                //    && data.PAGE_NO == SavePageNo && data.CREATE_TIME == createTime).ToList();
182
                List<FAVORITE_DOC> favoriteSet = dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == prjNo && data.MEMBER_USER_ID == userID
183
                    && data.ID == docID).ToList();
184
                try
185
                {
186

    
187
                    if (favoriteSet.Count > 0)
188
                    {
189
                        var FavoriteVP_Instance = favoriteSet.First();
190

    
191
                        FavoriteVP_Instance.DESCRIPTION = description;
192
                        FavoriteVP_Instance.FLAG = state;
193

    
194
                        dc.SaveChanges();
195

    
196
                        return true;
197
                    }
198
                    else
199
                    {
200
                        return false;
201
                    }
202
                }
203
                catch (Exception ex)
204
                {
205
                    System.Diagnostics.Trace.WriteLine("KCOM_API - EditFavoriteVP : " + ex.ToString());
206

    
207
                    return false;
208
                }
209
            }
210
        }
211

    
212
        [OperationContract]
213
        public bool DelFavoriteVP(string prjNo, string userID, int SavePageNo, string docID)
214
        {
215
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
216
            using (KCOMEntities dc = new KCOMEntities(sConnString))
217
            {
218

    
219
                List<FAVORITE_DOC> favoriteSet = dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == prjNo && data.MEMBER_USER_ID == userID
220
                    && data.ID == docID).ToList();
221

    
222
                try
223
                {
224
                    if (favoriteSet.Count > 0)
225
                    {
226
                        favoriteSet.ForEach(data => dc.FAVORITE_DOC.DeleteObject(data));
227
                        dc.SaveChanges();
228
                        return true;
229
                    }
230
                    else
231
                    {
232
                        return false;
233
                    }
234
                }
235
                catch (Exception ex)
236
                {
237
                    System.Diagnostics.Trace.WriteLine("KCOM_API - DelFavoriteVP : " + ex.ToString());
238

    
239
                    return false;
240
                }
241
            }
242
        }
243

    
244
        /// <summary>
245
        /// 두 페이지를 비교하여 결과를 리턴한다
246
        /// </summary>
247
        /// <param name="projectNo"></param>
248
        /// <param name="originDocItem_ID"></param>
249
        /// <param name="targetDocItem_ID"></param>
250
        /// <param name="originPageNo"></param>
251
        /// <param name="targetPageNo"></param>
252
        /// <param name="isInternalAddress"></param>
253
        /// <returns></returns>
254
        [OperationContract]
255
        public List<Rect> GetCompareRect(string projectNo, string originDocItem_ID, string targetDocItem_ID, string originPageNo, string targetPageNo, string isInternalAddress)
256
        {
257
            List<Rect> result = new List<Rect>();
258

    
259
            string originFile = "";
260
            string targetFile = "";
261

    
262
            try
263
            {
264
                string sOriginFolder = originDocItem_ID.All(char.IsDigit) ? (Convert.ToInt64(originDocItem_ID) / 100).ToString() : (originDocItem_ID.Length >= 5 ? originDocItem_ID.Substring(0, 5) : originDocItem_ID);
265
                string sTagetFolder = targetDocItem_ID.All(char.IsDigit) ? (Convert.ToInt64(targetDocItem_ID) / 100).ToString() : (targetDocItem_ID.Length >= 5 ? targetDocItem_ID.Substring(0, 5) : targetDocItem_ID);
266

    
267
                if (Boolean.Parse(isInternalAddress))
268
                {
269
                    originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sOriginFolder, originDocItem_ID, originPageNo);
270
                    targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sTagetFolder, targetDocItem_ID, targetPageNo);
271
                }
272
                else
273
                {
274
                    originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo, originDocItem_ID, originPageNo);
275
                    targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo, targetDocItem_ID, targetPageNo);
276
                }
277

    
278
                using (Markus.Image.ImageCompare compareLib = new Markus.Image.ImageCompare())
279
                {
280
                    result = compareLib.CompareReturnRects(originFile, targetFile, new System.Drawing.Size(20, 20));
281
                }
282
            }
283
            catch (Exception ex)
284
            {
285
                System.Diagnostics.Trace.WriteLine("KCOM_API - GetCompareRect : " + ex.ToString());
286
                throw new FaultException($"{originFile} {targetFile}  " + ex.ToString() + " Inner Exception : " + ex.InnerException?.ToString());
287
            }
288

    
289

    
290
            return result;
291
        }
292

    
293

    
294

    
295
        /// <summary>
296
        /// 두 페이지를 비교하여 결과를 리턴한다
297
        /// </summary>
298
        /// <param name="projectNo"></param>
299
        /// <param name="originDocItem_ID"></param>
300
        /// <param name="targetDocItem_ID"></param>
301
        /// <param name="originPageNo"></param>
302
        /// <param name="targetPageNo"></param>
303
        /// <param name="isInternalAddress"></param>
304
        /// <returns></returns>
305
        [OperationContract]
306
        public List<Rect> GetComparefixSize(string projectNo, string originDocItem_ID, string targetDocItem_ID, string originPageNo, string targetPageNo,Size FixSize, string isInternalAddress)
307
        {
308
            List<Rect> result = new List<Rect>();
309

    
310
            try
311
            {
312
                string originFile = "";
313
                string targetFile = "";
314

    
315
                string sOriginFolder = originDocItem_ID.All(char.IsDigit) ? (Convert.ToInt64(originDocItem_ID) / 100).ToString() : (originDocItem_ID.Length >= 5 ? originDocItem_ID.Substring(0, 5) : originDocItem_ID);
316
                string sTagetFolder = targetDocItem_ID.All(char.IsDigit) ? (Convert.ToInt64(targetDocItem_ID) / 100).ToString() : (targetDocItem_ID.Length >= 5 ? targetDocItem_ID.Substring(0, 5) : targetDocItem_ID);
317

    
318
                if (Boolean.Parse(isInternalAddress))
319
                {
320
                    originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sOriginFolder, originDocItem_ID, originPageNo);
321
                    targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sTagetFolder, targetDocItem_ID, targetPageNo);
322
                }
323
                else
324
                {
325
                    originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo, originDocItem_ID, originPageNo);
326
                    targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo, targetDocItem_ID, targetPageNo);
327
                }
328

    
329
                using (Markus.Image.ImageCompare compareLib = new Markus.Image.ImageCompare())
330
                {
331

    
332
                    result = compareLib.CompareReturnRects(originFile, targetFile, new System.Drawing.Size(20, 20));
333
                }
334
            }
335
            catch (Exception ex)
336
            {
337
                System.Diagnostics.Trace.WriteLine("KCOM_API - GetCompareRect : " + ex.ToString());
338
                //throw new FaultException(ex.ToString() + " Inner Exception : " + ex.InnerException?.ToString());
339
            }
340

    
341

    
342
            return result;
343
        }
344

    
345
        //[OperationContract]
346
        //public List<Rect> GetCompareRect_old(string projectNo, string originDocItem_ID, string targetDocItem_ID, string originPageNo, string targetPageNo, string isInternalAddress)
347
        //{
348
        //    System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
349

    
350
        //    stopwatch.Start();
351

    
352
        //    string originFile = "";
353
        //    string targetFile = "";
354

    
355
        //    string sFolder = originDocItem_ID.All(char.IsDigit) ? (Convert.ToUInt32(originDocItem_ID) / 100).ToString() : (originDocItem_ID.Length >= 5 ? originDocItem_ID.Substring(0, 5) : originDocItem_ID);
356
        //    if (Boolean.Parse(isInternalAddress))
357
        //    {
358
        //        originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sFolder, originDocItem_ID, originPageNo);
359
        //        targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sFolder, targetDocItem_ID, targetPageNo);
360
        //    }
361
        //    else
362
        //    {
363
        //        originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo, originDocItem_ID, originPageNo);
364
        //        targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo, targetDocItem_ID, targetPageNo);
365
        //    }
366

    
367
        //    CompareLib compareLib = new CompareLib();
368

    
369
        //    var resultOrigin = compareLib.ChangeCmpUrlToPng_File(originFile);
370
        //    var resultTarget = compareLib.ChangeCmpUrlToPng_File(targetFile);
371

    
372
        //    string outPutFile = compareLib.ImageCompare_File(resultOrigin, resultTarget);
373
        //    var result = compareLib.GetBoundBoxInImage(outPutFile);
374

    
375
        //    System.Diagnostics.Trace.WriteLine(new TimeSpan(stopwatch.ElapsedTicks));
376

    
377
        //    return result;
378
        //}
379

    
380

    
381
        #region Final PDF
382
        private string _ChanID = null;
383
        TcpChannel chan = null;
384
        [OperationContract]
385
        public FinalPDFResult SetFinalPDF(string ProjectNo, string DocInfoID, string MarkupInfoID, string CreateUserID)
386
        {
387
            #region 임시보관
388
            #endregion
389
            FinalPDFResult _result = new FinalPDFResult();
390
            RemFinalPDFObject remObj = null;
391
            try
392
            {
393
                string _finalID = shortGuid();
394
                int _DocTotalPages = -1;
395
                string docItemId;
396

    
397
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
398
                using (CIEntities _ci = new CIEntities(sCIConnString))
399
                {
400
                    var _doc = _ci.DOCINFO.Where(info => info.ID == DocInfoID);
401

    
402
                    if (_doc.Count() > 0)
403
                    {
404
                        _DocTotalPages = _doc.First().PAGE_COUNT;
405
                        docItemId = _doc.First().DOCUMENT_ID;
406
                    }
407
                    else
408
                    {
409
                        _result.Status = FinalStatus.Error;
410
                        _result.Exception = "페이지 정보를 가져올 수 없습니다.";
411
                        return _result;
412
                    }
413
                }
414
                if (_DocTotalPages > 0)
415
                {
416
                    FINAL_PDF fm = new FINAL_PDF()
417
                    {
418
                        ID = _finalID,
419
                        PROJECT_NO = ProjectNo,
420
                        DOCINFO_ID = DocInfoID,
421
                        DOCUMENT_ID = docItemId,
422
                        MARKUPINFO_ID = MarkupInfoID,
423
                        CREATE_USER_ID = CreateUserID,
424
                        TOTAL_PAGE = _DocTotalPages,
425
                        CREATE_DATETIME = DateTime.Now,
426
                        STATUS = (int)IFinalPDF.FinalStatus.Insert
427
                    };
428

    
429
                    string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
430
                    using (KCOMEntities _entity = new KCOMEntities(sConnString))
431
                    {
432
                        _entity.AddToFINAL_PDF(fm);
433
                        _entity.SaveChanges(System.Data.Objects.SaveOptions.AcceptAllChangesAfterSave);
434
                    };
435

    
436
                    if(KCOM_API.Properties.Settings.Default.FinalService.StartsWith("tcp"))
437
                    {
438
                        System.Runtime.Remoting.Channels.IChannel _ch = System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp");
439
                        if (_ch == null)
440
                        {
441
                            chan = new TcpChannel();
442
                            _ChanID = chan.ChannelName;
443
                            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan, false);
444
                            // Create an instance of the remote object
445

    
446
                            using (KCOMEntities ec = new KCOMEntities(sConnString))
447
                            {
448

    
449
                                //remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
450
                                //                          "tcp://localhost:9092/remFinalPDF");
451
                                remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
452
                                                          //"tcp://192.168.0.67:9092/remFinalPDF");
453
                                                          KCOM_API.Properties.Settings.Default.FinalService);
454
                            }
455

    
456
                            //"tcp://localhost:8080/remFinalPDF");
457

    
458
                            _result = remObj.SetFinalPDF(ProjectNo, _finalID);
459
                            _result.FinalID = _finalID;
460
                            _result.Status = FinalStatus.Success;
461

    
462
                            //MarkupToPDF.MarkupToPDF fa = new MarkupToPDF.MarkupToPDF();
463
                            //fa.MakeFinalPDF(fm);
464
                        }
465
                        else
466
                        {
467
                            _ChanID = _ch.ChannelName;
468
                        }
469
                    }
470
                    else
471
                    {
472
                        System.Net.WebClient client = new System.Net.WebClient();
473
                        var convertResult = client.DownloadString($"{KCOM_API.Properties.Settings.Default.FinalService}/Rest/FinalAdd?ProjectNo={ProjectNo}&FinalID={_finalID}");
474

    
475
                        JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings());
476
                        
477
                        if(jObject["FinalAddResult"].ToString() == true.ToString())
478
                        {
479
                            _result.FinalID = _finalID;
480
                            _result.Status = FinalStatus.Success;
481
                        }
482
                    }
483

    
484
                }
485
            }
486
            catch (Exception ex)
487
            {
488
                System.Diagnostics.Trace.WriteLine("KCOM_API - SetFinalPDF : " + ex.ToString());
489

    
490
                _result.Status = FinalStatus.Error;
491

    
492
                if (ex.GetType() == typeof(System.Net.Sockets.SocketException))
493
                    _result.Exception = "Final Server Not Connection";
494
                else _result.Exception = ex.ToString();
495
            }
496
            finally
497
            {
498
                remObj = null;
499
                if (System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp") != null)
500
                    System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(chan);
501

    
502
                GC.Collect(2);
503
            }
504
            return _result;
505
        }
506
        #endregion
507

    
508

    
509
        [OperationContract]
510
        public bool GetConversionState(KCOM_BasicParam param)
511
        {
512
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
513
            using (CIEntities entity = new CIEntities(sCIConnString))
514
            {
515
                var doc = entity.DOCINFO.Where(data => data.DOCUMENT_ID == param.documentID).FirstOrDefault();
516
                if (doc != null)
517
                {
518
                    var count = doc.DOCPAGE.Where(data => data.DOCINFO_ID == doc.ID).Count();
519
                    if (doc.PAGE_COUNT == count)  //페이지 수가 일치하는지
520
                    {
521
                        return true;
522
                    }
523
                    else //페이지 수가 일치하지 않는 경우
524
                    {
525
                        string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
526
                        KCOMEntities entity_kcom = new KCOMEntities(sConnString);
527
                        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();
528

    
529
                        if (lst != null || lst.Count >= 1)
530
                        {
531
                            //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_PAGECOUNT"), param.documentID, param.projectNo);
532
                            //이메일 클라이언트를 구현해야함
533
                        }
534
                        return false;
535
                    }
536
                }
537
                else
538
                {
539
                    //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_CONVERTFAILED"), param.documentID, param.projectNo);
540
                    //이메일 클라이언트를 구현해야함
541
                    return false;
542
                }
543
            }
544
        }
545

    
546
        [OperationContract]
547
        public List<VPRevision> GetVPRevisionHistory(string ProjectNo, string vpNo, string DocumentId)
548
        {
549
            List<VPRevision> _result = new List<VPRevision>();
550
            try
551
            {
552
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
553
                using (CIEntities entity = new CIEntities(sCIConnString))
554
                {
555
                    var _vpList = (from docitem in entity.DOCUMENT_ITEM
556
                                   where docitem.PROJECT_NO == ProjectNo && docitem.DOCUMENT_NO == vpNo
557
                                   select new VPRevision
558
                                   {
559
                                       RevNo = docitem.REVISION,
560
                                       GroupNo = docitem.GROUP_NO,
561
                                       FROM_VENDOR = docitem.ORIGINAL_FILE,
562
                                       DOCUMENT_ID = docitem.DOCUMENT_ID,
563
                                       TO_VENDOR = docitem.RESULT_FILE,
564
                                       RESULT = docitem.RESULT,
565
                                       DocNo = docitem.DOCUMENT_NO,
566
                                       EnsembleLink = docitem.Link
567
                                       //EnsembleLink = docitem.ENSEMBLEINFO_URL,
568
                                       //IsSyncPossible = docitem.DOCUMENT_ID == DocumentId ? false : entity.DOCINFO.Where(d => d.DOCUMENT_ID == docitem.DOCUMENT_ID).ToList().Count > 0 ? true : false
569
                                   });
570
                    _result = _vpList.ToList();
571
                    foreach (var vp in _result)
572
                    {
573
                        if (entity.DOCINFO.Where(d => d.DOCUMENT_ID == vp.DOCUMENT_ID).ToList().Count > 0)
574
                            vp.IsSyncPossible = true;
575
                        else
576
                            vp.IsSyncPossible = false;
577
                    }
578

    
579
                    //_result = _result.OrderByDescending(r => UInt64.Parse(System.Text.RegularExpressions.Regex.Replace(r.GroupNo, @"\D", ""))).ToList();
580
                    _result =  _result.OrderByDescending(r => r.GroupNo).ToList();
581
                }
582
            }
583
            catch (Exception ex)
584
            {
585
                System.Diagnostics.Trace.WriteLine("KCOM_API - GetVPRevisionHistory : " + ex.ToString());
586
            }
587
            finally
588
            {
589
                //GC.Collect(2);
590
            }
591

    
592
            return _result;
593
        }
594

    
595
        [OperationContract]
596
        public VPRevision GetVPRevisionFirstOrDefault(string ProjectNo, string DocumentId)
597
        {
598
            VPRevision _result = null;
599
            try
600
            {
601
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
602
                using (CIEntities entity = new CIEntities(sCIConnString))
603
                {
604
                    _result = (from docitem in entity.DOCUMENT_ITEM
605
                     where docitem.PROJECT_NO == ProjectNo && docitem.DOCUMENT_ID == DocumentId
606
                     select new VPRevision
607
                     {
608
                         RevNo = docitem.REVISION,
609
                         GroupNo = docitem.GROUP_NO,
610
                         FROM_VENDOR = docitem.ORIGINAL_FILE,
611
                         DOCUMENT_ID = docitem.DOCUMENT_ID,
612
                         TO_VENDOR = docitem.RESULT_FILE,
613
                         RESULT = docitem.RESULT
614
                     }).FirstOrDefault();
615
                }
616
            }
617
            catch (Exception ex)
618
            {
619
                System.Diagnostics.Trace.WriteLine("KCOM_API - GetVPRevisionFirstOrDefault : " + ex.ToString());
620
            }
621
            finally
622
            {
623
                //GC.Collect(2);
624
            }
625
            return _result;
626
        }
627

    
628
        [OperationContract]
629
        public DOCINFO GetDocInfo(KCOM_BasicParam param)
630
        {
631
            DOCINFO _result = null;
632
            try
633
            {
634
                // 차후 아래의 코드로 변경
635
                //using (CI_Entities ModelDeeview = new CI_Entities(DaelimCiConnectionString.ToString()))
636
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
637
                CIEntities ModelDeeview = new CIEntities(sCIConnString);
638

    
639
                var docinfo = ModelDeeview.DOCINFO.Where(doc => doc.DOCUMENT_ID == param.documentID && doc.PROJECT_NO == param.projectNo);
640
                if (docinfo.Count() > 0)
641
                {
642
                    _result = docinfo.First();
643
                    _result.MARKUP_INFO.Clear();
644

    
645
                }
646
                return _result;
647

    
648
            }
649
            catch (Exception ex)
650
            {
651
                System.Diagnostics.Trace.WriteLine("KCOM_API - GetDocInfo : " + ex.ToString());
652
            }
653
            finally
654
            {
655
                //GC.Collect(2);
656
            }
657
            return null;
658
        }
659

    
660
        [OperationContract]
661
        public bool GetCheckSystemAdmin(string UserID)
662
        {
663
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
664
            using (KCOMEntities uc = new KCOMEntities(sConnString))
665
            {
666
                var user = uc.PROPERTIES.Where(data => data.TYPE == "Administrator" && data.PROPERTY.Contains(UserID)).FirstOrDefault();
667
                if (user != null)
668
                {
669
                    return true;
670
                }
671
                else
672
                {
673
                    return false;
674
                }
675
            }
676
            //GC.Collect(2);
677
        }
678

    
679
        [OperationContract]
680
        public DOCUMENT_ITEM GetDocumentItemInfo(KCOM_BasicParam param)
681
        {
682
            ///param : prjNo, documentId, userId
683
            DOCUMENT_ITEM _result = null;
684

    
685
            try
686
            {
687
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
688
                CIEntities entity = new CIEntities(sCIConnString);
689
               
690
                var _items = entity.DOCUMENT_ITEM.Where(data => data.PROJECT_NO == param.projectNo && data.DOCUMENT_ID == param.documentID);
691

    
692
                if (_items.Count() > 0)
693
                {
694
                    _result = _items.First();
695

    
696
                    return _result;
697
                }
698
                //else
699
                //{
700
                //    Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_DOCUMENTNOTFOUND"), param.documentID, param.projectNo);
701
                //}
702
            }
703
            catch (Exception ex)
704
            {
705
                System.Diagnostics.Trace.WriteLine("KCOM_API - GetDocumentItemInfo : " + ex.ToString());
706

    
707
                new FaultException("GetDocumentItemInfo Error - "  + ex.ToString());
708
                //throw new FaultException(ex.ToString());
709
                //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, "GetDocumentItemInfo / " + ex.Message, param.documentID, param.projectNo);
710
            }
711

    
712
            return _result;
713
        }
714
        /// <summary>
715
        /// DOCUMENT_ITEM Table 의 ID 로 Item 을 Select
716
        /// </summary>
717
        /// 대림의 경우 Interface ID(Document 의 ID) 를 parameter 로 전달
718
        /// 넘어온 ID를 통해 document id 를 확인하는 과정이 필요
719
        /// <param name="ensemble_id"></param>
720
        /// <returns></returns>
721
        [OperationContract]
722
        public string GetDocItemID(string ensemble_id)
723
        {
724
            ///param : prjNo, documentId, userId
725
            string _result = string.Empty;
726

    
727
            try
728
            {
729
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
730
                CIEntities entity = new CIEntities(sCIConnString);
731

    
732
                var _items = entity.DOCUMENT_ITEM.Where(data => data.ID == ensemble_id).FirstOrDefault();
733
                if(_items != null)
734
                    _result = _items.DOCUMENT_ID;
735
            }
736
            catch (Exception ex)
737
            {
738
                System.Diagnostics.Trace.WriteLine("KCOM_API - GetDocItemID : " + ex.ToString());
739
                //System.Diagnostics.Trace.WriteLine("GetVendorItemInfo Error : " + ex);
740
                //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, "GetDocumentItemInfo / " + ex.Message, param.documentID, param.projectNo);
741
            }
742

    
743
            return _result;
744
        }
745
        public string UserGO(MARKUP_INFO item)
746
        {
747
            if (item != null)
748
            {
749
                return item.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID;
750
            }
751
            return null;
752
        }
753
        
754
        [OperationContract]
755
        public List<MarkupInfoItem> GetMarkupInfoItems(string ProjectNo, string DocInfoId)
756
        {
757
            List<MarkupInfoItem> _result = new List<MarkupInfoItem>();
758
            try
759
            {
760
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
761
                using (CIEntities entity = new CIEntities(sCIConnString))
762
                {
763
                    var markupListData = entity.MARKUP_INFO.Where(data => data.DOCINFO_ID == DocInfoId).ToList();
764

    
765
                    var markupList = from markup in markupListData
766
                                     orderby markup.CREATE_TIME descending
767
                                     select new MarkupInfoItem
768
                                     {
769
                                         MarkupInfoID = markup.ID,
770
                                         UserID = markup.USER_ID,
771
                                         MarkupVersionID = markup.MARKUP_INFO_VERSION.Count() == 0 ? null : markup.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID,
772
                                         CreateTime = markup.CREATE_TIME,
773
                                         Consolidate = markup.CONSOLIDATE,
774
                                         Description = markup.DESCRIPTION,
775
                                         AvoidConsolidate = markup.AVOID_CONSOLIDATE,
776
                                         PartConsolidate = markup.PART_CONSOLIDATE,
777
                                         UpdateTime = DateTime.Parse(markup.UPDATE_TIME.ToString()),
778
                                     };
779

    
780
                    if (markupList.Count() > 0)
781
                    {
782
                        _result = markupList.ToList();
783
                    }
784

    
785
                    _result.ForEach(r =>
786
                    {
787

    
788
                        r.MarkupList = (from markupData in entity.MARKUP_DATA
789
                                        where markupData.MARKUPINFO_VERSION_ID == r.MarkupVersionID
790
                                        orderby markupData.PAGENUMBER
791
                                        select new MarkupItem { ID = markupData.ID, PageNumber = markupData.PAGENUMBER, Data = markupData.DATA, Data_Type = markupData.DATA_TYPE, Symbol_ID = markupData.SYMBOL_ID}).ToList();
792
                    });
793

    
794
                    List<PROPERTIES> _ColorsProperties = new List<PROPERTIES>();
795
                    Random random = new Random();
796

    
797
                    string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
798
                    using (KCOMEntities kcomEntity = new KCOMEntities(sConnString))
799
                    {
800
                        _ColorsProperties = (from property in kcomEntity.PROPERTIES
801
                                             where property.TYPE == "DisplayColor"
802
                                             select property).ToList();
803

    
804
                    }
805

    
806
                    if (_ColorsProperties.Count() != _result.GroupBy(x=>x.UserID).Count())
807
                    {
808
                        ColorGenerator uniqueColorGenerator = new ColorGenerator(System.Drawing.Color.Red); // 2303 = (int)Color.Red
809

    
810
                        uniqueColorGenerator.GetEnumerator(_result.Count());
811

    
812
                        for (int i = 0; i < _result.Count(); i++)
813
                        {
814
                             var c = uniqueColorGenerator.GetNext();
815
                            _ColorsProperties.Add(new PROPERTIES { VALUE = String.Format("{0:X2}{1:X2}{2:X2}",c.R, c.G,c.B) });
816
                        }
817
                    }
818

    
819
                    bool IsProjectNoPass = Properties.Settings.Default.IsProjectNoPass;
820

    
821
                    foreach (var item in _result.GroupBy(x=>x.UserID))
822
                    {
823
                        string query = "SELECT members.ID,members.NAME,members.DEPARTMENT FROM CIEntities.MEMBER as members where members.ID = @userId";
824

    
825
                        System.Data.Objects.ObjectQuery<System.Data.Common.DbDataRecord> memberQuery 
826
                                      = entity.CreateQuery<System.Data.Common.DbDataRecord>(query,new System.Data.Objects.ObjectParameter("userId",item.Key));
827

    
828
                        if (memberQuery.Count() > 0)
829
                        {
830
                            string userName = memberQuery.First()["NAME"]?.ToString().Trim();
831
                            string depatment = memberQuery.First()["DEPARTMENT"]?.ToString().Trim();
832

    
833
                            PROPERTIES deptColor = _ColorsProperties[0];
834

    
835
                            _ColorsProperties.RemoveAt(0);
836
                            //PROPERTIES deptColor = _ColorsProperties.Find(c => c.PROPERTY == depatment);
837

    
838
                            //if (_ColorsProperties.Count > 0)
839
                            //{
840
                            //    if (deptColor == null)
841
                            //    {
842
                            //        item.DisplayColor = "#FF" + _ColorsProperties[0].VALUE;
843
                            //        _ColorsProperties.RemoveAt(0);
844
                            //    }
845
                            //    else
846
                            //    {
847
                            //        item.DisplayColor = "#FF" + deptColor.VALUE;
848
                            //        _ColorsProperties.Remove(deptColor);
849
                            //    }
850
                            //}
851

    
852
                            foreach (var markupInfo in item)
853
                            {
854
                                markupInfo.DisplayColor = "#FF" + deptColor.VALUE;
855
                                markupInfo.UserName = userName;
856
                                markupInfo.Depatment = depatment;
857
                            }
858
                        }
859
                    }
860

    
861
                       
862
                    //else
863
                    //{
864
                    //    item.DisplayColor = String.Format("#FF{0:X6}", random.Next(0x1000000));
865
                    //}
866
                }
867
            }
868
            catch (Exception ex)
869
            {
870
                System.Diagnostics.Trace.WriteLine("KCOM_API - GetMarkupInfoItems : " + ex.ToString());
871

    
872
                return _result;
873
            }
874
            finally
875
            {
876
                //GC.Collect(2);
877
            }
878

    
879
            return _result;
880
        }
881

    
882
        [OperationContract]
883
        public List<MarkupInfoItem> GetSyncMarkupInfoItems(string ProjectNo, string DocInfoId, string currentUser)
884
        {
885
            List<MarkupInfoItem> _result = new List<MarkupInfoItem>();
886
            try
887
            {
888
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
889
                using (CIEntities entity = new CIEntities(sCIConnString))
890
                {
891
                    var docItem = entity.DOCINFO.Where(data => data.DOCUMENT_ID == DocInfoId).FirstOrDefault();
892
                    if (docItem == null)
893
                    {
894
                        return null;
895
                    }
896
                    var markupListData = entity.MARKUP_INFO.Where(data => data.DOCINFO_ID == docItem.ID).ToList();
897

    
898
                    var markupList = from markup in markupListData
899
                                     where markup.USER_ID == currentUser || markup.CONSOLIDATE == 1
900
                                     orderby markup.CREATE_TIME descending
901
                                     select new MarkupInfoItem
902
                                     {
903
                                         MarkupInfoID = markup.ID,
904
                                         UserID = markup.USER_ID,
905
                                         MarkupVersionID = markup.MARKUP_INFO_VERSION.Count() == 0 ? null : markup.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID,
906
                                         CreateTime = markup.CREATE_TIME,
907
                                         Consolidate = markup.CONSOLIDATE,
908
                                         Description = markup.DESCRIPTION,
909
                                         AvoidConsolidate = markup.AVOID_CONSOLIDATE,
910
                                         PartConsolidate = markup.PART_CONSOLIDATE,
911
                                     };
912

    
913

    
914

    
915
                    if (markupList.Count() > 0)
916
                    {
917
                        _result = markupList.ToList();
918
                    }
919

    
920

    
921

    
922
                    _result.ForEach(r =>
923
                    {
924

    
925
                        r.MarkupList = (from markupData in entity.MARKUP_DATA
926
                                        where markupData.MARKUPINFO_VERSION_ID == r.MarkupVersionID
927
                                        orderby markupData.PAGENUMBER
928
                                        select new MarkupItem
929
                                        {
930
                                            ID = markupData.ID,
931
                                            PageNumber = markupData.PAGENUMBER,
932
                                            Data = markupData.DATA,
933
                                            Data_Type = markupData.DATA_TYPE,
934
                                            Symbol_ID = markupData.SYMBOL_ID
935
                                        }).ToList();
936
                    });
937

    
938
                    List<PROPERTIES> _ColorsProperties = new List<PROPERTIES>();
939
                    Random random = new Random();
940

    
941
                    string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
942
                    using (KCOMEntities kcomEntity = new KCOMEntities(sConnString))
943
                    {
944
                        _ColorsProperties = (from property in kcomEntity.PROPERTIES
945
                                             where property.TYPE == "DisplayColor"
946
                                             select property).ToList();
947
                    }
948

    
949
                    foreach (var item in _result)
950
                    {
951
                        string query = "SELECT members.ID,members.NAME,members.DEPARTMENT FROM CIEntities.MEMBER as members where members.ID = @userId";
952

    
953
                        System.Data.Objects.ObjectQuery<System.Data.Common.DbDataRecord> memberQuery
954
                                      = entity.CreateQuery<System.Data.Common.DbDataRecord>(query, new System.Data.Objects.ObjectParameter("userId", item.UserID));
955

    
956
                        if (memberQuery.Count() > 0)
957
                        {
958

    
959
                            string userName = memberQuery.First()["NAME"]?.ToString().Trim();
960
                            string depatment = memberQuery.First()["DEPARTMENT"]?.ToString().Trim();
961

    
962
                            item.UserName = userName;
963
                            item.Depatment = depatment;
964
                        }
965

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

    
994
            return _result;
995
        }
996

    
997

    
998
        //[OperationContract]
999
        //[ServiceKnownType(typeof(MEMBER))]
1000
        //public List<MEMBER> GetUserData(string ProjectNo, string UserID)
1001
        //{
1002
        //    List<MEMBER> _result = new List<MEMBER>();
1003

    
1004
        //    using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1005
        //    {
1006
        //        var _UserList = from member in entity.MEMBER
1007
        //                        where member.ID == UserID
1008
        //                        select member;
1009
        //        _result = _UserList.ToList();
1010
        //    }
1011
        //    //GC.Collect(2);
1012
        //    return _result;
1013
        //}
1014

    
1015
        [OperationContract]
1016
        [ServiceKnownType(typeof(MEMBER))]
1017
        public List<MEMBER> GetUserData(string ProjectNo, string UserID)
1018
        {
1019
            List<MEMBER> _result = new List<MEMBER>();
1020

    
1021
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1022

    
1023
            using (CIEntities entity = new CIEntities(sCIConnString))
1024
            {
1025
                _result = GetMemberQuery(entity, UserID);
1026
            }
1027
            //GC.Collect(2);
1028
            return _result;
1029
        }
1030

    
1031

    
1032
        [OperationContract]
1033
        public List<string> GetDeptData(string UserDept) //그룹 추가 옵션 부여 예정
1034
        {
1035
            List<string> _result = new List<string>();
1036

    
1037
            try
1038
            {
1039
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1040
                KCOMEntities entity = new KCOMEntities(sConnString);
1041
                var YourEnginner = (from dept in entity.PROPERTIES
1042
                                    where dept.TYPE == "DeptName" && UserDept.Contains(dept.VALUE)
1043
                                    select dept).FirstOrDefault();
1044

    
1045
                if (YourEnginner != null)
1046
                {
1047
                    _result = (from dept in entity.PROPERTIES
1048
                               where dept.PROPERTY == YourEnginner.PROPERTY
1049
                               select dept.VALUE).ToList();
1050
                    return _result;
1051
                }
1052
                else
1053
                {
1054
                    return null;
1055
                }
1056
            }
1057
            catch (Exception ex)
1058
            {
1059
                System.Diagnostics.Trace.WriteLine("KCOM_API - GetDeptData : " + ex.ToString());
1060
            }
1061
            finally
1062
            {
1063
                //GC.Collect(2);
1064
            }
1065
            return _result;
1066
        }
1067

    
1068
        [OperationContract]
1069
        public bool DeleteMarkup(string ProjectNo, string MarkupInfoID)
1070
        {
1071
            bool _result = false;
1072
            try
1073
            {
1074
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1075
                using (KCOMDataModel.DataModel.CIEntities Entity = new KCOMDataModel.DataModel.CIEntities(sCIConnString))
1076
                {
1077

    
1078
                    MARKUP_INFO instance = Entity.MARKUP_INFO.Where(root => root.ID == MarkupInfoID).FirstOrDefault();
1079

    
1080
                    if (instance == null)
1081
                    {
1082
                        return false;
1083
                    }
1084
                    MARKUP_INFO_VERSION version = instance.MARKUP_INFO_VERSION.FirstOrDefault();
1085

    
1086

    
1087
                    version.MARKUP_DATA.ToList().ForEach(data =>
1088
                    {
1089
                        Entity.MARKUP_DATA.DeleteObject(data);
1090
                        Entity.SaveChanges();
1091
                    });
1092

    
1093
                    Entity.MARKUP_INFO_VERSION.DeleteObject(version);
1094
                    Entity.SaveChanges();
1095

    
1096
                    Entity.MARKUP_INFO.DeleteObject(instance);
1097
                    Entity.SaveChanges();
1098

    
1099
                }
1100
                _result = true;
1101
            }
1102
            catch (Exception ex)
1103
            {
1104
                System.Diagnostics.Trace.WriteLine("KCOM_API - DeleteMarkup : " + ex.ToString());
1105
            }
1106
            finally
1107
            {
1108
                //GC.Collect(2);
1109
            }
1110
            return _result;
1111
        }
1112

    
1113
        #region Favorite
1114
        [OperationContract]
1115
        public bool SetFavoriteVP(string prjNo, string userID, string groupNo, string docNo, string rev, int SavePageNo, string documentItemID, string VPDescription, IKCOM.FAVORITE_FLAG flag)
1116
        {
1117
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1118
            using (KCOMEntities entity = new KCOMEntities(sConnString))
1119
            {
1120
                try
1121
                {
1122
                    entity.FAVORITE_DOC.AddObject(new FAVORITE_DOC
1123
                    {
1124
                        ID = shortGuid(),
1125
                        PROJECT_NO = prjNo,
1126
                        DOCUMENT_ID = documentItemID,
1127
                        GROUP_NO = groupNo,
1128
                        DOCUMENT_NO = docNo,
1129
                        MEMBER_USER_ID = userID,
1130
                        DESCRIPTION = VPDescription,
1131
                        CREATE_TIME = DateTime.Now,
1132
                        REVISION = rev,
1133
                        FLAG = (int)flag,
1134
                        PAGE_NO = SavePageNo,
1135
                    });
1136
                    entity.SaveChanges();
1137
                }
1138
                catch (Exception ex)
1139
                {
1140
                    System.Diagnostics.Trace.WriteLine("KCOM_API - SetFavoriteVP : " + ex.ToString());
1141
                    return false;
1142
                }
1143

    
1144
                return true;
1145
            }
1146
        }
1147

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

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

    
1171
        //        try
1172
        //        {
1173

    
1174

    
1175
        //            if (favoriteSet.Count > 0)
1176
        //            {
1177
        //                var FavoriteVP_Instance = favoriteSet.First();
1178

    
1179
        //                FavoriteVP_Instance.Description = description;
1180
        //                FavoriteVP_Instance.Flag = state;
1181

    
1182
        //                dc.SaveChanges();
1183

    
1184
        //                return true;
1185
        //            }
1186
        //            else
1187
        //            {
1188
        //                return false;
1189
        //            }
1190
        //        }
1191
        //        catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1192
        //        {
1193
        //            return false;
1194
        //        }
1195
        //    }
1196
        //}
1197
        //[OperationContract]
1198
        //public bool DelFavoriteVP(string prjNo, string userID, int SavePageNo, string sharepointItemID, DateTime createTime)
1199
        //{
1200

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

    
1206
        //        try
1207
        //        {
1208

    
1209

    
1210
        //            if (favoriteSet.Count > 0)
1211
        //            {
1212
        //                favoriteSet.ForEach(data => dc.FavoriteVP.DeleteObject(data));
1213
        //                dc.SaveChanges();
1214
        //                return true;
1215
        //            }
1216
        //            else
1217
        //            {
1218
        //                return false;
1219
        //            }
1220
        //        }
1221
        //        catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1222
        //        {
1223
        //            return false;
1224
        //        }
1225
        //    }
1226
        //}
1227
        #endregion
1228

    
1229
        [OperationContract]
1230
        public bool SaveMarkupData(MarkupInfoItem UserState,string project_no,string doc_id, string user_id, List<MARKUP_DATA> mlmarkup_data)
1231
        {
1232
            
1233
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1234
            using (CIEntities Entity = new CIEntities(sCIConnString))
1235
            {     
1236
                #region Docinfo 정보 가져오기
1237

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

    
1245
                #region Markup_Info 저장
1246

    
1247
                MARKUP_INFO markup_info = new MARKUP_INFO();
1248
                try
1249
                {
1250
                    markup_info = (from info in Entity.MARKUP_INFO
1251
                                   where info.ID == UserState.MarkupInfoID && info.USER_ID == user_id
1252
                                   select info).FirstOrDefault();
1253
                }
1254
                catch (Exception ex)
1255
                {
1256
                    System.Diagnostics.Trace.WriteLine("KCOM_API - SaveMarkupData Get markup_info: " + ex.ToString());
1257
                    markup_info = null;
1258
                }
1259

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

    
1286
                #region Markup_Info_Version 저장
1287

    
1288
                MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1289

    
1290
                try
1291
                {
1292
                    markup_info_version = (from info in Entity.MARKUP_INFO_VERSION
1293
                                           where info.MARKUPINFO_ID == markup_info.ID
1294
                                           select info).FirstOrDefault();
1295
                }
1296
                catch (Exception ex)
1297
                {
1298
                    System.Diagnostics.Trace.WriteLine("KCOM_API - SaveMarkupData  Get markup_info_version : " + ex.ToString());
1299
                    markup_info_version = null;
1300
                }
1301

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

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

    
1323
                Entity.SaveChanges();
1324

    
1325
                try
1326
                {
1327
                    mlmarkup_data.ForEach(value =>
1328
                    {
1329
                        Entity.MARKUP_DATA.AddObject(new MARKUP_DATA
1330
                        {
1331
                            ID = value.ID,
1332
                            DATA = value.DATA,
1333
                            DATA_TYPE = value.DATA_TYPE,
1334
                            PAGENUMBER = value.PAGENUMBER,
1335
                            MARKUPINFO_VERSION_ID = markup_info_version.ID,
1336
                            SYMBOL_ID = value.SYMBOL_ID,
1337
                            //GROUP_ID = value.GROUP_ID
1338
                        });
1339

    
1340
                        
1341
                    });
1342
                    Entity.SaveChanges();
1343

    
1344
                    if (Properties.Settings.Default.Properties["CLIENT_VERSION"] != null)
1345
                    {
1346
                        string sql = $"UPDATE MARKUP_DATA SET REMARK = '{Properties.Settings.Default.CLIENT_VERSION} {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }' WHERE ID = @ID";
1347

    
1348
                        mlmarkup_data.ForEach(value =>
1349
                        {
1350
                            var param = new System.Data.Common.DbParameter[] { new System.Data.SqlClient.SqlParameter { ParameterName = "ID", Value = value.ID } };
1351
                            var result = Entity.ExecuteStoreCommand(sql, param);
1352
                        });
1353

    
1354
                        Entity.SaveChanges();
1355
                    }
1356
                }
1357
                catch (Exception ex)
1358
                {
1359
                    System.Diagnostics.Trace.WriteLine("KCOM_API - SaveMarkupData  set mlmarkup_data : " + ex.ToString());
1360
                    return false;
1361
                }
1362
            }
1363
            return true;
1364
        }
1365

    
1366
        [OperationContract]
1367
        public bool SavePageMarkupData(MarkupInfoItem UserState,int PageNo, string project_no, string doc_id, string user_id, List<MARKUP_DATA> mlmarkup_data)
1368
        {
1369

    
1370
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1371
            using (CIEntities Entity = new CIEntities(sCIConnString))
1372
            {
1373
                #region Docinfo 정보 가져오기
1374

    
1375
                string docinfoid_ = (from info in Entity.DOCINFO
1376
                                     where info.DOCUMENT_ID == doc_id
1377
                                     && info.PROJECT_NO == project_no
1378
                                     select info.ID
1379
                                     ).First().ToString();
1380
                #endregion
1381

    
1382
                #region Markup_Info 저장
1383

    
1384
                MARKUP_INFO markup_info = new MARKUP_INFO();
1385
                try
1386
                {
1387
                    markup_info = (from info in Entity.MARKUP_INFO
1388
                                   where info.ID == UserState.MarkupInfoID && info.USER_ID == user_id
1389
                                   select info).FirstOrDefault();
1390
                }
1391
                catch (Exception ex)
1392
                {
1393
                    System.Diagnostics.Trace.WriteLine("KCOM_API - SavePageMarkupData : " + ex.ToString());
1394

    
1395
                    markup_info = null;
1396
                }
1397

    
1398
                //markup_info가 없을 경우 생성
1399
                if (markup_info == null)
1400
                {
1401
                    //MarkupInfo 저장
1402
                    markup_info = new MARKUP_INFO
1403
                    {
1404
                        ID = UserState.MarkupInfoID,
1405
                        DOCINFO_ID = docinfoid_,
1406
                        USER_ID = user_id,
1407
                        CREATE_TIME = DateTime.Now,
1408
                        CONSOLIDATE = UserState.Consolidate,
1409
                        AVOID_CONSOLIDATE = UserState.AvoidConsolidate,
1410
                        PART_CONSOLIDATE = UserState.PartConsolidate,
1411
                        DESCRIPTION = UserState.Description,
1412
                        UPDATE_TIME = DateTime.Now
1413
                    };
1414
                    Entity.MARKUP_INFO.AddObject(markup_info);
1415
                }
1416
                //markup_info가 있을 경우 업데이트
1417
                else
1418
                {
1419
                    markup_info.UPDATE_TIME = DateTime.Now;
1420
                }
1421
                Entity.SaveChanges();
1422
                #endregion
1423

    
1424
                #region Markup_Info_Version 저장
1425

    
1426
                MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1427

    
1428
                try
1429
                {
1430
                    markup_info_version = (from info in Entity.MARKUP_INFO_VERSION
1431
                                           where info.MARKUPINFO_ID == markup_info.ID
1432
                                           select info).FirstOrDefault();
1433
                }
1434
                catch (Exception ex)
1435
                {
1436
                    System.Diagnostics.Trace.WriteLine("KCOM_API - SavePageMarkupData get markup_info_version : " + ex.ToString());
1437
                    markup_info_version = null;
1438
                }
1439

    
1440
                //markup_info_version 없을 경우 생성
1441
                if (markup_info_version == null)
1442
                {
1443
                    //MarkupInfo_version 저장
1444
                    markup_info_version = new MARKUP_INFO_VERSION()
1445
                    {
1446
                        ID = UserState.MarkupVersionID,
1447
                        MARKUPINFO_ID = markup_info.ID,
1448
                        CREATE_DATE = DateTime.Now
1449
                    };
1450
                    Entity.MARKUP_INFO_VERSION.AddObject(markup_info_version);
1451
                    Entity.SaveChanges();
1452
                }
1453
                #endregion
1454

    
1455

    
1456
                Entity.MARKUP_DATA.Where(data =>  data.PAGENUMBER == PageNo && data.MARKUPINFO_VERSION_ID == markup_info_version.ID).ToList().ForEach(item =>
1457
                {
1458
                    Entity.MARKUP_DATA.DeleteObject(item);
1459
                });
1460
                Entity.SaveChanges();
1461

    
1462
                try
1463
                {
1464
                    mlmarkup_data.ForEach(value =>
1465
                    {
1466
                        Entity.MARKUP_DATA.AddObject(new MARKUP_DATA
1467
                        {
1468
                            ID = value.ID,
1469
                            DATA = value.DATA,
1470
                            DATA_TYPE = value.DATA_TYPE,
1471
                            PAGENUMBER = value.PAGENUMBER,
1472
                            MARKUPINFO_VERSION_ID = markup_info_version.ID,
1473
                            SYMBOL_ID = value.SYMBOL_ID,
1474
                            //GROUP_ID = value.GROUP_ID
1475
                        });
1476
                    });
1477
                    Entity.SaveChanges();
1478
                }
1479
                catch (Exception ex)
1480
                {
1481
                    System.Diagnostics.Trace.WriteLine("KCOM_API - SavePageMarkupData set mlmarkup_data : " + ex.ToString());
1482
                    return false;
1483
                }
1484
            }
1485
            return true;
1486
        }
1487

    
1488
        //[OperationContract]
1489
        //public long AddMarkupDataGroup(MARKUP_DATA_GROUP mARKUP_DATA_GROUP, string ProjectNo)
1490
        //{
1491
        //    try
1492
        //    {
1493
        //        using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1494
        //        {
1495
        //            Entity.AddToMARKUP_DATA_GROUP(mARKUP_DATA_GROUP);
1496
        //            //MARKUP_DATA_GROUP tt = Entity.MARKUP_DATA_GROUP.Where(info => info.ID == id).FirstOrDefault();
1497
        //            Entity.SaveChanges();
1498

    
1499
        //            return Entity.MARKUP_DATA_GROUP.ToList().LastOrDefault().ID;
1500
        //        }
1501
        //    }
1502
        //    catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1503
        //    {
1504
        //        return 0;
1505
        //    }
1506
        //}
1507
        //[OperationContract]
1508
        //public bool UpdateMarkupDataGroup(long Group_ID, string ProjectNo)
1509
        //{
1510
        //    try
1511
        //    {
1512
        //        using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1513
        //        {
1514
        //            var UpdateItem = Entity.MARKUP_DATA_GROUP.Where(info => info.ID == Group_ID).FirstOrDefault();
1515
        //            UpdateItem.STATE = 1;
1516
        //            Entity.SaveChanges();
1517
        //        }
1518
        //    }
1519
        //    catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1520
        //    {
1521
        //        return false;
1522
        //    }
1523
        //    return true;
1524
        //}
1525
        [OperationContract]
1526
        public bool UpdateMarkupData(string CommentID, long Group_ID, string ProjectNo)
1527
        {
1528
            try
1529
            {
1530
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1531
                using (CIEntities Entity = new CIEntities(sCIConnString))
1532
                {
1533
                    var UpdateItem = Entity.MARKUP_DATA.Where(info => info.ID == CommentID).FirstOrDefault();
1534
                    //UpdateItem.GROUP_ID = Group_ID;
1535
                    Entity.SaveChanges();
1536
                }
1537
            }
1538
            catch (Exception ex)
1539
            {
1540
                System.Diagnostics.Trace.WriteLine("KCOM_API - UpdateMarkupData: " + ex.ToString());
1541
                return false;
1542
            }
1543
            return true;
1544
        }
1545

    
1546
        [OperationContract]
1547
        public bool SaveSymbol(SYMBOL_PRIVATE symbol_private)
1548
        {
1549
            try
1550
            {
1551
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1552
                using (KCOMDataModel.DataModel.KCOMEntities uc = new KCOMDataModel.DataModel.KCOMEntities(sConnString))
1553
                {
1554
                    uc.AddToSYMBOL_PRIVATE(symbol_private);
1555
                    uc.SaveChanges();
1556
                }
1557
            }
1558
            catch (Exception ex)
1559
            {
1560
                System.Diagnostics.Trace.WriteLine("KCOM_API - SaveSymbol: " + ex.ToString());
1561
                return false;
1562
            }
1563
            return true;
1564
        }
1565
        [OperationContract]
1566
        public bool AddPublicSymbol(SYMBOL_PUBLIC symbol)
1567
        {
1568
            try
1569
            {
1570
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1571
                using (KCOMDataModel.DataModel.KCOMEntities uc = new KCOMDataModel.DataModel.KCOMEntities(sConnString))
1572
                {
1573
                    uc.AddToSYMBOL_PUBLIC(symbol);
1574
                    uc.SaveChanges();
1575
                }
1576
            }
1577
            catch (Exception ex)
1578
            {
1579
                System.Diagnostics.Trace.WriteLine("KCOM_API - AddPublicSymbol: " + ex.ToString());
1580
                return false;
1581
            }
1582
            return true;
1583
        }
1584
        [OperationContract]
1585
        public bool DeleteSymbol(string symbol_id, int type)
1586
        {
1587
            try
1588
            {
1589
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1590
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
1591
                {
1592
                    if (type == 0)
1593
                    {
1594
                        string delItem_ID = symbol_id;
1595
                        var delitem = Entity.SYMBOL_PRIVATE.Where(data => data.ID == delItem_ID).FirstOrDefault();
1596
                        Entity.SYMBOL_PRIVATE.DeleteObject(delitem);
1597
                        Entity.SaveChanges();
1598
                    }
1599
                    else
1600
                    {
1601
                        string delItem_ID = symbol_id;
1602
                        var delitem = Entity.SYMBOL_PUBLIC.Where(data => data.ID == delItem_ID).FirstOrDefault();
1603
                        Entity.SYMBOL_PUBLIC.DeleteObject(delitem);
1604
                        Entity.SaveChanges();
1605
                    }
1606
                }
1607
            }
1608
            catch (Exception ex)
1609
            {
1610
                System.Diagnostics.Trace.WriteLine("KCOM_API - DeleteSymbol : " + ex.ToString());
1611

    
1612
                return false;
1613
            }
1614
            return true;
1615
        }
1616

    
1617
        [OperationContract]
1618
        public bool RenameSymbol(string symbol_id, string name, int type)
1619
        {
1620
            try
1621
            {
1622
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1623
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
1624
                {
1625
                    if (type == 0)
1626
                    {
1627
                        var UpdateItem = Entity.SYMBOL_PRIVATE.Where(info => info.ID == symbol_id).FirstOrDefault();
1628
                        UpdateItem.NAME = name;
1629
                        Entity.SaveChanges();
1630
                    }
1631
                    else
1632
                    {
1633
                        var UpdateItem = Entity.SYMBOL_PUBLIC.Where(info => info.ID == symbol_id).FirstOrDefault();
1634
                        UpdateItem.NAME = name;
1635
                        Entity.SaveChanges();
1636
                    }
1637
                }
1638
            }
1639
            catch (Exception ex)
1640
            {
1641
                System.Diagnostics.Trace.WriteLine("KCOM_API - RenameSymbol: " + ex.ToString());
1642
                return false;
1643
            }
1644
            return true;
1645
        }
1646

    
1647
        [OperationContract]
1648
        public bool AddCheckListHistory(string project_no, CHECK_LIST_HISTORY Check_History)
1649
        {
1650
            try
1651
            {
1652
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1653
                using (CIEntities Entity = new CIEntities(sCIConnString))
1654
                {
1655
                    Entity.CHECK_LIST_HISTORY.AddObject(Check_History);
1656
                    Entity.SaveChanges();  
1657
                }
1658
            }
1659
            catch (Exception ex)
1660
            {
1661
                System.Diagnostics.Trace.WriteLine("KCOM_API - AddCheckListHistory: " + ex.ToString());
1662
                return false;
1663
            }
1664
            return true;
1665
        }
1666
        [OperationContract]
1667
        public bool SaveCheckListHistory(string project_no, string rev, CHECK_LIST_HISTORY Check_History)
1668
        {
1669
            try
1670
            {
1671
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1672
                using (CIEntities Entity = new CIEntities(sCIConnString))
1673
                {
1674
                    var item = Entity.CHECK_LIST_HISTORY.Where(info => info.REVISION == rev).FirstOrDefault();
1675
                    item = Check_History;
1676
                    Entity.SaveChanges();
1677
                }
1678
            }
1679
            catch (Exception ex)
1680
            {
1681
                System.Diagnostics.Trace.WriteLine("KCOM_API - SaveCheckListHistory: " + ex.ToString());
1682
                return false;
1683
            }
1684
            return true;
1685
        }
1686
        [OperationContract]
1687
        public bool SaveCheckList(string project_no, string _id, CHECK_LIST Check_value)
1688
        {
1689
            try
1690
            {
1691
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1692
                using (CIEntities Entity = new CIEntities(sCIConnString))
1693
                {
1694
                    var item = Entity.CHECK_LIST.Where(info => info.ID == _id).FirstOrDefault();
1695
                    item.TODOLIST = Check_value.TODOLIST;
1696
                    item.REMARK = Check_value.REMARK;
1697
                    item.STATUS = Check_value.STATUS;
1698
                    item.VENDOR = Check_value.VENDOR;
1699
                    item.REPLY = Check_value.REPLY;
1700
                    item.IMAGE_URL = Check_value.IMAGE_URL;
1701
                    item.IMAGE_ANCHOR = Check_value.IMAGE_ANCHOR;
1702
                    item.UPDATE_TIME = Check_value.UPDATE_TIME;
1703
                    if(Check_value.STATUS == "False")
1704
                    {
1705
                        item.STATUS_DESC_OPEN = Check_value.STATUS_DESC_OPEN;
1706
                    }
1707
                    else
1708
                    {
1709
                        item.STATUS_DESC_CLOSE = Check_value.STATUS_DESC_CLOSE;
1710
                    }                     
1711
                    Entity.SaveChanges();
1712
                }
1713
            }
1714
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1715
                return false;
1716
            }
1717
            return true;
1718
        }
1719
        [OperationContract]
1720
        public bool AddCheckList(string project_no, CHECK_LIST Check_value)
1721
        {
1722
            try
1723
            {
1724
               
1725
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1726
                using (CIEntities Entity = new CIEntities(sCIConnString))
1727
                {
1728
                    Entity.CHECK_LIST.AddObject(Check_value);
1729
                    Entity.SaveChanges();
1730
                }
1731
            }
1732
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1733
                return false;
1734
            }
1735
            return true;
1736
        }
1737

    
1738
        [OperationContract]
1739
        public CHECK_LIST GetCheckList(string project_no, string _id)
1740
        {
1741
            CHECK_LIST Check_value = new CHECK_LIST();
1742
            try
1743
            {
1744
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1745
                using (CIEntities Entity = new CIEntities(sCIConnString))
1746
                {
1747
                    Check_value = Entity.CHECK_LIST.Where(info => info.ID == _id).FirstOrDefault();
1748
                }
1749
            }
1750
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1751
                return null;
1752
            }
1753
            return Check_value;
1754
        }
1755
        [OperationContract]
1756
        public List<CHECK_LIST> GetUserCheckList(string project_no, string user_id, string doc_no)
1757
        {
1758
            List<CHECK_LIST> list = new List<CHECK_LIST>();
1759
            try
1760
            {
1761
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1762
                using (CIEntities Entity = new CIEntities(sCIConnString))
1763
                {
1764
                    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();
1765
                }
1766
            }
1767
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1768
                return null;
1769
            }
1770
            return list;
1771
        }
1772
        [OperationContract]
1773
        public List<CHECK_LIST_HISTORY> GetCheckListHistory(string project_no, string _id)
1774
        {
1775
            List<CHECK_LIST_HISTORY> history = new List<CHECK_LIST_HISTORY>();
1776
            try
1777
            {
1778
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1779
                using (CIEntities Entity = new CIEntities(sCIConnString))
1780
                {
1781
                    history = Entity.CHECK_LIST_HISTORY.Where(data => data.CHECKLIST_ID == _id).ToList();
1782
                }
1783
            }
1784
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1785
                return null;
1786
            }
1787
            return history;
1788
        }
1789
        [OperationContract]
1790
        public CHECK_LIST_HISTORY GetCheckListHistoryFirstOrDefault(string project_no, string checklist_id, string rev)
1791
        {
1792
            CHECK_LIST_HISTORY Check_Item = new CHECK_LIST_HISTORY();
1793
            try
1794
            {
1795
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1796
                using (CIEntities Entity = new CIEntities(sCIConnString))
1797
                {   
1798
                    Check_Item = Entity.CHECK_LIST_HISTORY.Where(info => info.CHECKLIST_ID == checklist_id && info.REVISION == rev).FirstOrDefault();
1799
                }
1800
            }
1801
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1802
                return null;
1803
            }
1804
            return Check_Item;
1805
        }
1806
        [OperationContract]
1807
        public bool SavePageAngle(string project_no, List<DOCPAGE> _mldocpage)
1808
        {
1809
            try
1810
            {
1811
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1812
                using (CIEntities Entity = new CIEntities(sCIConnString))
1813
                {
1814
                    KCOMDataModel.DataModel.DOCPAGE _docpage = new KCOMDataModel.DataModel.DOCPAGE();
1815
                    _mldocpage.ForEach(data =>
1816
                    {
1817
                        _docpage = (from info in Entity.DOCPAGE
1818
                                    where info.ID == data.ID
1819
                                    select info).FirstOrDefault();
1820

    
1821
                        if (_docpage.PAGE_ANGLE != data.PAGE_ANGLE)
1822
                        {
1823
                            _docpage.PAGE_ANGLE = data.PAGE_ANGLE;
1824
                        }
1825
                    });
1826

    
1827
                    Entity.SaveChanges();
1828
                }
1829
            }
1830
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1831
                return false;
1832
            }
1833
            return true;
1834
        }
1835

    
1836
        [OperationContract]
1837
        public MARKUP_INFO GetMarkupInfo(string project_no, string _id)
1838
        {
1839
            MARKUP_INFO markupInfo = new MARKUP_INFO();
1840

    
1841
            try
1842
            {
1843
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1844
                using (CIEntities Entity = new CIEntities(sCIConnString))
1845
                {
1846
                    markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1847
                }
1848
            }
1849
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1850
                return null;
1851
            }
1852
            return markupInfo;
1853
        }
1854

    
1855
        [OperationContract]
1856
        public List<string> GetMarkupDataListperPage(string project_no, string _markupinfoid, int _pageNo)
1857
        {
1858
            List<string> markupdata = new List<string>();
1859
            MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1860
            try
1861
            {
1862
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1863
                using (CIEntities Entity = new CIEntities(sCIConnString))
1864
                {
1865
                    markup_info_version = (from version in Entity.MARKUP_INFO_VERSION
1866
                                           where version.MARKUPINFO_ID == _markupinfoid
1867
                                           orderby version.CREATE_DATE descending
1868
                                           select version).First();
1869
                    markupdata = (from data in Entity.MARKUP_DATA
1870
                                  where data.MARKUPINFO_VERSION_ID == markup_info_version.ID && data.PAGENUMBER == _pageNo
1871
                                  select data.DATA).ToList();
1872
                }
1873
            }
1874
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1875
                return null;
1876
            }
1877
            return markupdata;
1878
        }
1879

    
1880
        [OperationContract]
1881
        public bool AddMarkupInfo(string project_no, MARKUP_INFO value)
1882
        {
1883
            try
1884
            {
1885
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1886
                using (CIEntities Entity = new CIEntities(sCIConnString))
1887
                {
1888
                    Entity.MARKUP_INFO.AddObject(value);
1889
                    Entity.SaveChanges();
1890
                }
1891
            }
1892
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1893
                return false;
1894
            }
1895
            return true;
1896
        }
1897

    
1898
        [OperationContract]
1899
        public bool AddMarkupInfoVersion(string project_no, MARKUP_INFO_VERSION value)
1900
        {
1901
            try
1902
            {
1903
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1904
                using (CIEntities Entity = new CIEntities(sCIConnString))
1905
                {
1906
                    Entity.MARKUP_INFO_VERSION.AddObject(value);
1907
                    Entity.SaveChanges();
1908
                }
1909
            }
1910
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1911
                return false;
1912
            }
1913
            return true;
1914
        }
1915

    
1916
        [OperationContract]
1917
        public bool AddMarkupData(string project_no, MARKUP_DATA value)
1918
        {
1919
            try
1920
            {
1921
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1922
                using (CIEntities Entity = new CIEntities(sCIConnString))
1923
                {
1924
                    Entity.MARKUP_DATA.AddObject(value);
1925
                    Entity.SaveChanges();
1926
                }
1927
            }
1928
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1929
                return false;
1930
            }
1931
            return true;
1932
        }
1933

    
1934
        [OperationContract]
1935
        public bool AvoidMarkupInfo(string project_no, string _doc_id)
1936
        {
1937
            try
1938
            {
1939
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1940
                using (CIEntities Entity = new CIEntities(sCIConnString))
1941
                {
1942
                    var item = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1943
                    item.AVOID_CONSOLIDATE = 1;
1944
                    Entity.SaveChanges();
1945
                }
1946
            }
1947
            catch (Exception ex) {
1948
                System.Diagnostics.Trace.WriteLine(ex);
1949
                return false;
1950
            }
1951
            return true;
1952
        }
1953

    
1954
        [OperationContract]
1955
        public bool SaveMarkupInfo(string project_no, string _id, MARKUP_INFO value)
1956
        {
1957
            try
1958
            {
1959
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1960
                using (CIEntities Entity = new CIEntities(sCIConnString))
1961
                {
1962
                    var item = Entity.MARKUP_INFO.Where(info => info.ID == _id).FirstOrDefault();
1963
                    item = value;                    
1964
                    Entity.SaveChanges();
1965
                }
1966
            }
1967
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1968
                return false;
1969
            }
1970
            return true;
1971
        }
1972
        [OperationContract]
1973
        public List<MARKUP_DATA> GetMarkupDataList(string project_no, string _versionid)
1974
        {
1975
            List<MARKUP_DATA> mlresult = new List<MARKUP_DATA>();
1976

    
1977
            try
1978
            {
1979
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1980
                using (CIEntities Entity = new CIEntities(sCIConnString))
1981
                {
1982
                    mlresult = Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == _versionid).ToList();
1983
                }
1984
            }
1985
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
1986
                return null;
1987
            }
1988
            return mlresult;
1989
        }
1990

    
1991
        [OperationContract]
1992
        public bool Consolidate(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems)
1993
        {
1994
            try
1995
            {
1996
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
1997
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1998
                using (CIEntities Entity = new CIEntities(sCIConnString))
1999
                {
2000
                    var markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id && entity.CONSOLIDATE == 1).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
2001
                    if (markupInfo != null)
2002
                    {
2003
                        markupInfo.AVOID_CONSOLIDATE = 1;
2004
                    }
2005

    
2006
                    foreach (MarkupInfoItem item in markupInfoItems)
2007
                    {
2008
                        Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == item.MarkupVersionID).ToList().ForEach(d =>
2009
                        {
2010
                            instanceDataSet.Add(d);
2011
                        });
2012
                    }
2013

    
2014
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
2015
                    info.ID = shortGuid();
2016
                    info.CONSOLIDATE = 1;
2017
                    info.CREATE_TIME = DateTime.Now;
2018
                    info.DOCINFO_ID = _doc_id;
2019
                    info.UPDATE_TIME = DateTime.Now;
2020
                    info.USER_ID = _user_id;
2021
                    info.AVOID_CONSOLIDATE = 0;
2022

    
2023
                    Entity.MARKUP_INFO.AddObject(info);
2024
         
2025

    
2026
                    KCOMDataModel.DataModel.MARKUP_INFO_VERSION info2 = new KCOMDataModel.DataModel.MARKUP_INFO_VERSION
2027
                    {
2028
                        ID = shortGuid(),
2029
                        CREATE_DATE = DateTime.Now,
2030
                        MARKUP_INFO = info,
2031
                    };
2032

    
2033
                    foreach (var item in instanceDataSet)
2034
                    {
2035
                        Entity.MARKUP_DATA.AddObject(new KCOMDataModel.DataModel.MARKUP_DATA
2036
                        {
2037
                            ID = shortGuid(),
2038
                            DATA = item.DATA,
2039
                            DATA_TYPE = item.DATA_TYPE,
2040
                            PAGENUMBER = item.PAGENUMBER,
2041
                            MARKUP_INFO_VERSION = info2,
2042
                            SYMBOL_ID = item.SYMBOL_ID,
2043
                            //GROUP_ID = item.GROUP_ID
2044
                        });
2045
                    }
2046

    
2047
                    Entity.SaveChanges();
2048
                }
2049
            }
2050
            catch (Exception ex) {
2051
                System.Diagnostics.Trace.WriteLine(ex);
2052
                return false;
2053
            }
2054
            return true;
2055
        }
2056

    
2057

    
2058
        [OperationContract]
2059
        public FinalPDFResult ConsolidateMergedPDF(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems, string ProjectNo, string DocInfoID, string CreateUserID)
2060
        {
2061
            bool consolidate = false;
2062
            try
2063
            {
2064
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
2065
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2066
                using (CIEntities Entity = new CIEntities(sCIConnString))
2067
                {
2068
                    var markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
2069
                    if (markupInfo.CONSOLIDATE == 1)
2070
                    {
2071
                        markupInfo.AVOID_CONSOLIDATE = 1;
2072
                    }
2073

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

    
2082
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
2083
                    info.ID = shortGuid();
2084
                    info.CONSOLIDATE = 1;
2085
                    info.CREATE_TIME = DateTime.Now;
2086
                    info.DOCINFO_ID = _doc_id;
2087
                    info.UPDATE_TIME = DateTime.Now;
2088
                    info.USER_ID = _user_id;
2089
                    info.AVOID_CONSOLIDATE = 0;
2090

    
2091
                    Entity.MARKUP_INFO.AddObject(info);
2092
                    Entity.SaveChanges();
2093

    
2094

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

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

    
2118

    
2119
                }
2120
                consolidate = true;
2121
            }
2122
            catch (Exception ex)
2123
            {
2124
                System.Diagnostics.Trace.WriteLine(ex);
2125
                consolidate = false;
2126
            }
2127

    
2128
            FinalPDFResult _result = new FinalPDFResult();
2129
            if (consolidate == true)
2130
            {
2131
                RemFinalPDFObject remObj = null;
2132
                try
2133
                {
2134
                    string _finalID = shortGuid();
2135
                    int _DocTotalPages = -1;
2136
                    string docItemId;
2137

    
2138
                    string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2139
                    using (CIEntities _ci = new CIEntities(sCIConnString))
2140
                    {
2141
                        var _doc = _ci.DOCINFO.Where(info => info.ID == DocInfoID);
2142

    
2143
                        if (_doc.Count() > 0)
2144
                        {
2145
                            _DocTotalPages = _doc.First().PAGE_COUNT;
2146
                            docItemId = _doc.First().DOCUMENT_ID;
2147
                        }
2148
                        else
2149
                        {
2150
                            _result.Status = FinalStatus.Error;
2151
                            _result.Exception = "페이지 정보를 가져올 수 없습니다.";
2152
                            return _result;
2153
                        }
2154
                    }
2155

    
2156
                    var Items = GetMarkupInfoItems(ProjectNo, DocInfoID);
2157
                    if (_DocTotalPages > 0)
2158
                    {
2159
                        var item2 = Items.Cast<MarkupInfoItem>().Where(d => d.Consolidate == 1 && d.AvoidConsolidate == 0).FirstOrDefault();
2160
                        FINAL_PDF fm = new FINAL_PDF()
2161
                        {
2162
                            ID = _finalID,
2163
                            PROJECT_NO = ProjectNo,
2164
                            DOCINFO_ID = DocInfoID,
2165
                            DOCUMENT_ID = docItemId,
2166
                            MARKUPINFO_ID = item2.MarkupInfoID,
2167
                            CREATE_USER_ID = CreateUserID,
2168
                            TOTAL_PAGE = _DocTotalPages,
2169
                            CREATE_DATETIME = DateTime.Now,
2170
                            STATUS = (int)IFinalPDF.FinalStatus.Insert
2171
                        };
2172

    
2173
                        string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2174
                        using (KCOMEntities _entity = new KCOMEntities(sConnString))
2175
                        {
2176
                            _entity.AddToFINAL_PDF(fm);
2177
                            _entity.SaveChanges(System.Data.Objects.SaveOptions.AcceptAllChangesAfterSave);
2178
                        };
2179

    
2180
                        System.Runtime.Remoting.Channels.IChannel _ch = System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp");
2181
                        if (_ch == null)
2182
                        {
2183
                            chan = new TcpChannel();
2184
                            _ChanID = chan.ChannelName;
2185
                            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan, false);
2186
                            // Create an instance of the remote object
2187

    
2188
                            using (KCOMEntities ec = new KCOMEntities(sConnString))
2189
                            {
2190

    
2191
                                //remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
2192
                                //                          "tcp://localhost:9092/remFinalPDF");
2193
                                remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
2194
                                                          //"tcp://192.168.0.67:9092/remFinalPDF");
2195
                                                          "tcp://192.168.0.67:9092/remFinalPDF");
2196
                            }
2197

    
2198
                            //"tcp://localhost:8080/remFinalPDF");
2199

    
2200
                            _result = remObj.SetFinalPDF(ProjectNo, _finalID);
2201
                            _result.FinalID = _finalID;
2202
                            _result.Status = FinalStatus.Success;
2203

    
2204
                            //MarkupToPDF.MarkupToPDF fa = new MarkupToPDF.MarkupToPDF();
2205
                            //fa.MakeFinalPDF(fm);
2206
                        }
2207
                        else
2208
                        {
2209
                            _ChanID = _ch.ChannelName;
2210
                        }
2211
                    }
2212
                }
2213
                catch (Exception ex)
2214
                {
2215
                    _result.Status = FinalStatus.Error;
2216

    
2217
                    if (ex.GetType() == typeof(System.Net.Sockets.SocketException))
2218
                        _result.Exception = "Final Server Not Connection";
2219
                }
2220
                finally
2221
                {
2222
                    remObj = null;
2223
                    if (System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp") != null)
2224
                        System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(chan);
2225

    
2226
                    GC.Collect(2);
2227
                }
2228
            }
2229
            return _result;
2230
        }
2231
        [OperationContract]
2232
        public bool TeamConsolidate(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems)
2233
        {
2234
            try
2235
            {
2236
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
2237
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2238
                using (CIEntities Entity = new CIEntities(sCIConnString))
2239
                {
2240
                    var members = GetMemberQuery(Entity, _user_id);
2241

    
2242
                    string user_dept = "";
2243

    
2244
                    if(members.Count() > 0)
2245
                    {
2246
                        user_dept = members.First().DEPARTMENT;
2247
                    }
2248
                    
2249
                    var markupInfos = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id && entity.PART_CONSOLIDATE == 1)
2250
                                        .OrderByDescending(j => j.CREATE_TIME).ToList();
2251

    
2252
                    foreach (var markupinfo in markupInfos)
2253
                    {
2254
                        string markupdept = "";
2255

    
2256
                        var markupMembers = GetMemberQuery(Entity, markupinfo.USER_ID);
2257

    
2258
                        if (markupMembers.Count() > 0)
2259
                        {
2260
                            markupdept = markupMembers.First().DEPARTMENT;
2261
                        }
2262

    
2263
                        if (user_dept == markupdept)
2264
                        {
2265
                            markupinfo.AVOID_CONSOLIDATE = 1;
2266
                        }
2267
                    }
2268

    
2269
                    foreach (MarkupInfoItem item in markupInfoItems)
2270
                    {
2271
                        Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == item.MarkupVersionID).ToList().ForEach(d =>
2272
                        {
2273
                            instanceDataSet.Add(d);
2274
                        });
2275
                    }
2276

    
2277
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
2278
                    info.ID = shortGuid();
2279
                    info.PART_CONSOLIDATE = 1;
2280
                    info.CREATE_TIME = DateTime.Now;
2281
                    info.DOCINFO_ID = _doc_id;
2282
                    info.UPDATE_TIME = DateTime.Now;
2283
                    info.USER_ID = _user_id;
2284
                    info.AVOID_CONSOLIDATE = 0;
2285

    
2286
                    Entity.MARKUP_INFO.AddObject(info);
2287
                    Entity.SaveChanges();
2288

    
2289

    
2290
                    KCOMDataModel.DataModel.MARKUP_INFO_VERSION info2 = new KCOMDataModel.DataModel.MARKUP_INFO_VERSION
2291
                    {
2292
                        ID = shortGuid(),
2293
                        CREATE_DATE = DateTime.Now,
2294
                        MARKUP_INFO = info,
2295
                    };
2296
                    Entity.SaveChanges();
2297

    
2298
                    foreach (var item in instanceDataSet)
2299
                    {
2300
                        Entity.MARKUP_DATA.AddObject(new KCOMDataModel.DataModel.MARKUP_DATA
2301
                        {
2302
                            ID = shortGuid(),
2303
                            DATA = item.DATA,
2304
                            DATA_TYPE = item.DATA_TYPE,
2305
                            PAGENUMBER = item.PAGENUMBER,
2306
                            MARKUP_INFO_VERSION = info2,
2307
                            SYMBOL_ID = item.SYMBOL_ID,
2308
                            //GROUP_ID = item.GROUP_ID
2309
                        });
2310
                    }
2311
                    Entity.SaveChanges();
2312

    
2313

    
2314
                }
2315
            }
2316
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
2317
                return false;
2318
            }
2319
            return true;
2320
        }
2321

    
2322
        [OperationContract]
2323
        [ServiceKnownType(typeof(MEMBER))]
2324
        public MEMBER GetMember(string project_no, string user_id)
2325
        {
2326
            MEMBER rstmember = null;
2327
            try
2328
            {
2329
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2330
                using (CIEntities Entity = new CIEntities(sCIConnString))
2331
                {
2332
                    var members = GetMemberQuery(Entity, user_id);
2333

    
2334
                    if(members.Count() > 0)
2335
                    {
2336
                        rstmember = members.First();
2337
                    }
2338
                }
2339
            }
2340
            catch (Exception ex)
2341
            {
2342
                return null;
2343
            }
2344
            return rstmember;
2345
        }
2346

    
2347
        private  List<MEMBER> GetMemberQuery(System.Data.Objects.ObjectContext context, string UserID)
2348
        {
2349
            List<MEMBER> result = new List<MEMBER>();
2350

    
2351
            try
2352
            {
2353
                string query = "SELECT members.ID,members.NAME,members.DEPARTMENT FROM CIEntities.MEMBER as members where members.ID = @userId";
2354

    
2355
                var param = new[] { new System.Data.Objects.ObjectParameter("userId", UserID) };
2356

    
2357
                System.Data.Objects.ObjectQuery<System.Data.Common.DbDataRecord> memberQuery
2358
                              = context.CreateQuery<System.Data.Common.DbDataRecord>(query, param);
2359

    
2360
                if (memberQuery.Count() > 0)
2361
                {
2362
                    foreach (var dataRecord in memberQuery)
2363
                    {
2364
                        MEMBER member = new MEMBER();
2365

    
2366
                        string userName = dataRecord["NAME"]?.ToString().Trim();
2367
                        string ID = dataRecord["ID"]?.ToString().Trim();
2368
                        string depatment = dataRecord["DEPARTMENT"]?.ToString().Trim();
2369

    
2370
                        member.NAME = userName;
2371
                        member.ID = ID;
2372
                        member.DEPARTMENT = depatment;
2373

    
2374
                        result.Add(member);
2375
                    }
2376
                }
2377
            }
2378
            catch (Exception ex)
2379
            {
2380
                throw new Exception("GetMember(System.Data.Objects.ObjectContext context, string UserID) " , ex);
2381
            }
2382

    
2383
            return result;
2384
        }
2385

    
2386
        [WebMethod]
2387
        [OperationContract]
2388
        public List<SYMBOL_PRIVATE> GetSymbolList(string user_id)
2389
        {
2390
            List<SYMBOL_PRIVATE> Custom_List = new List<SYMBOL_PRIVATE>();
2391
            try
2392
            {
2393
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2394
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2395
                {
2396
                    Custom_List = Entity.SYMBOL_PRIVATE.Where(data => data.MEMBER_USER_ID == user_id).ToList();
2397
                }
2398
            }
2399
            catch (Exception ex)
2400
            {
2401
                return null;
2402
            }
2403
            return Custom_List;
2404
        }
2405
        [OperationContract]
2406
        public List<string> GetPublicSymbolDeptList()
2407
        {
2408
            List<string> Custom_List = new List<string>();
2409
            try
2410
            {
2411
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2412
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2413
                {
2414
                    Custom_List = Entity.SYMBOL_PUBLIC.Select(data => data.DEPARTMENT).Distinct().ToList();
2415
                }
2416
            }
2417
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
2418
                return null;
2419
            }
2420
            return Custom_List;
2421
        }
2422
        [OperationContract]
2423
        public List<SYMBOL_PUBLIC> GetPublicSymbolList(string dept)
2424
        {
2425
            List<SYMBOL_PUBLIC> Custom_List = new List<SYMBOL_PUBLIC>();
2426
            try
2427
            {
2428
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2429
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2430
                {
2431
                    if(!string.IsNullOrEmpty(dept))
2432
                    {
2433
                        Custom_List = Entity.SYMBOL_PUBLIC.Where(data => data.DEPARTMENT == dept).ToList();
2434
                    }
2435
                    else
2436
                    {
2437
                        Custom_List = Entity.SYMBOL_PUBLIC.ToList();
2438
                    }
2439
                    
2440
                }
2441
            }
2442
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
2443
                return null;
2444
            }
2445
            return Custom_List;
2446
        }
2447

    
2448
        /// <summary>
2449
        /// 
2450
        /// </summary>
2451
        /// <param name="id">symbol id</param>
2452
        /// <param name="type"> 0 : PRIVATE, 1 : PUBLIC</param>
2453
        /// <returns></returns>
2454
        [OperationContract]
2455
        public string GetSymbolData(string id, int type)
2456
        {
2457
            string result;
2458
            try
2459
            {
2460
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2461
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2462
                {
2463
                    if(type == 0)
2464
                    {
2465
                        result = Entity.SYMBOL_PRIVATE.Where(data => data.ID == id).FirstOrDefault().DATA;
2466
                    }
2467
                    else
2468
                    {
2469
                        result = Entity.SYMBOL_PUBLIC.Where(data => data.ID == id).FirstOrDefault().DATA;
2470
                    }
2471
                }
2472
            }
2473
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
2474
                return null;
2475
            }
2476
            return result;
2477
        }
2478
        [OperationContract]
2479
        public string GetSymbolImageURL(string id, int type)
2480
        {
2481
            string result;
2482
            try
2483
            {
2484
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2485
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2486
                {
2487
                    if (type == 0)
2488
                    {
2489
                        result = Entity.SYMBOL_PRIVATE.Where(data => data.ID == id).FirstOrDefault().IMAGE_URL;
2490
                    }
2491
                    else
2492
                    {
2493
                        result = Entity.SYMBOL_PUBLIC.Where(data => data.ID == id).FirstOrDefault().IMAGE_URL;
2494
                    }
2495
                }
2496
            }
2497
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
2498
                return null;
2499
            }
2500
            return result;
2501
        }
2502

    
2503
        [OperationContract]
2504
        public string GetSignData(string project_no, string user_id)
2505
        {
2506
            string result = null;
2507
            try
2508
            {
2509
                string ifsign = getEnsembleSign(user_id);
2510
                if (string.IsNullOrEmpty(ifsign))
2511
                {
2512
                    string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2513
                    var ModelWFConnectionString = sCIConnString;
2514
                    if (null != ModelWFConnectionString)
2515
                    {
2516
                        using (CIEntities entity = new CIEntities(ModelWFConnectionString))
2517
                        {
2518
                            var _sign = entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == user_id);
2519
                            if (_sign.Count() > 0)
2520
                            {
2521
                                result = _sign.First().SIGN_STR;
2522
                            }
2523
                            else
2524
                            {
2525
                                return null;
2526
                            }
2527
                        }
2528
                    }
2529
                }
2530
                else
2531
                {
2532
                    result = ifsign;
2533
                }
2534

    
2535
            }
2536
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
2537
                return null;
2538
            }
2539
            return result;
2540
        }
2541

    
2542
        [OperationContract]
2543
        public string GetSignStrokes(string project_no, string user_id)
2544
        {
2545
            string result = null;
2546
            try
2547
            {
2548
                string ifsign = getEnsembleSign(user_id);
2549
                if (string.IsNullOrEmpty(ifsign))
2550
                {
2551
                    string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2552
                    var ModelWFConnectionString = sCIConnString;
2553
                    if (null != ModelWFConnectionString)
2554
                    {
2555
                        using (CIEntities entity = new CIEntities(ModelWFConnectionString))
2556
                        {
2557
                            var _sign = entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == user_id);
2558
                            if (_sign.Count() > 0)
2559
                            {
2560
                                result = _sign.First().SIGN_STROKES;
2561
                            }
2562
                            else
2563
                            {
2564
                                return null;
2565
                            }
2566
                        }
2567
                    }
2568
                }
2569
                else
2570
                {
2571
                    result = ifsign;
2572
                }
2573

    
2574
            }
2575
            catch (Exception ex)
2576
            {
2577
                System.Diagnostics.Trace.WriteLine(ex);
2578
                return null;
2579
            }
2580
            return result;
2581
        }
2582

    
2583
        [OperationContract]
2584
        public int SetSignData(string user_id,string SignStr,int CropX,int CropY,int CropWidth,int CropHeight)
2585
        {
2586
            int result = -1;
2587

    
2588
            try
2589
            {
2590
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2591
                   
2592
                using (CIEntities entity = new CIEntities(sCIConnString))
2593
                {
2594
                    var _sign = entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == user_id);
2595

    
2596
                    var cropImg = Convert.ToBase64String(SignatureCrop(SignStr, CropX, CropY, CropWidth, CropHeight));
2597

    
2598
                    if (_sign.Count() > 0)
2599
                    {
2600
                        _sign.First().SIGN_STR = cropImg;
2601
                        _sign.First().MODIFY_DATE = DateTime.Now;
2602
                    }
2603
                    else
2604
                    {
2605
                        entity.SIGN_INFO.AddObject(new SIGN_INFO
2606
                        {
2607
                            ID = shortGuid(),
2608
                            MEMBER_USER_ID = user_id,
2609
                            CREATE_DATE = DateTime.Now,
2610
                            SIGN_STR = cropImg
2611
                        });
2612
                    }
2613

    
2614
                    result = entity.SaveChanges();
2615
                }
2616
            }
2617
            catch (Exception ex)
2618
            {
2619
                System.Diagnostics.Trace.WriteLine(ex);
2620
            }
2621
            return result;
2622
        }
2623

    
2624

    
2625
        [OperationContract]
2626
        public int SetSignStrokes(string user_id, string strokesData)
2627
        {
2628
            int result = -1;
2629

    
2630
            try
2631
            {
2632
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2633

    
2634
                using (CIEntities entity = new CIEntities(sCIConnString))
2635
                {
2636
                    var _sign = entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == user_id);
2637

    
2638
                    if (_sign.Count() > 0)
2639
                    {
2640
                        _sign.First().SIGN_STROKES = strokesData;
2641
                        _sign.First().MODIFY_DATE = DateTime.Now;
2642
                    }
2643
                    else
2644
                    {
2645
                        entity.SIGN_INFO.AddObject(new SIGN_INFO
2646
                        {
2647
                            ID = shortGuid(),
2648
                            MEMBER_USER_ID = user_id,
2649
                            CREATE_DATE = DateTime.Now,
2650
                            SIGN_STROKES = strokesData
2651
                    });
2652
                    }
2653

    
2654
                    result = entity.SaveChanges();
2655
                }
2656
            }
2657
            catch (Exception ex)
2658
            {
2659
                System.Diagnostics.Trace.WriteLine(ex);
2660
            }
2661
            return result;
2662
        }
2663

    
2664
        private byte[] SignatureCrop(string imgStr,int X,int Y,int Width,int Height)
2665
        {
2666
            using (System.IO.MemoryStream readStream = new System.IO.MemoryStream(Convert.FromBase64String(imgStr)))
2667
            {
2668
                using (System.Drawing.Image OriginalImage = System.Drawing.Image.FromStream(readStream))
2669
                {
2670
                    using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(Width, Height))
2671
                    {
2672
                        bmp.SetResolution(OriginalImage.HorizontalResolution, OriginalImage.VerticalResolution);
2673
                        using (System.Drawing.Graphics Graphic = System.Drawing.Graphics.FromImage(bmp))
2674
                        {
2675
                            Graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
2676
                            Graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
2677
                            Graphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
2678
                            Graphic.DrawImage(OriginalImage, new System.Drawing.Rectangle(0, 0, Width, Height), X, Y, Width, Height, System.Drawing.GraphicsUnit.Pixel);
2679
                            System.IO.MemoryStream ms = new System.IO.MemoryStream();
2680
                            bmp.Save(ms, OriginalImage.RawFormat);
2681
                            return ms.GetBuffer();
2682
                        }
2683
                    }
2684
                }
2685
            }
2686
        }
2687

    
2688
        [OperationContract]        
2689
        public string GetProjectName(string project_no)
2690
        {
2691
            string result = null;
2692

    
2693
            try
2694
            {
2695
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2696
                using (KCOMDataModel.DataModel.KCOMEntities Entity = new KCOMDataModel.DataModel.KCOMEntities(sConnString))
2697
                {
2698
                    result = Entity.RUN_PROJECTS.Where(i => i.PROJECT_NO == project_no).FirstOrDefault().PROJECT_NAME.ToString();
2699
                }
2700
            }
2701
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
2702
                return null;
2703
            }
2704
            return result;
2705
        }
2706

    
2707
        [OperationContract]
2708
        public List<DOCUMENT_ITEM> GetPreRevSelect(string project_no, string doc_no, string current_rev)
2709
        {
2710
            List<DOCUMENT_ITEM> result = new List<DOCUMENT_ITEM>();
2711
            
2712
            try
2713
            {
2714
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2715
                using (CIEntities Entity = new CIEntities(sCIConnString))
2716
                {
2717
                    result = Entity.DOCUMENT_ITEM.Where(i => i.PROJECT_NO == project_no
2718
                    && i.DOCUMENT_NO == doc_no
2719
                    && i.REVISION != current_rev).OrderByDescending(i => i.GROUP_NO).ToList();
2720
                }
2721
            }
2722
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
2723
                return null;
2724
            }
2725
            return result;
2726
        }
2727

    
2728
        [OperationContract]
2729
        public DOCINFO GetDocInfoOneSelect(string project_no, string doc_id)
2730
        {
2731
            DOCINFO docinfo = null;
2732

    
2733
            try
2734
            {
2735
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2736
                using (CIEntities Entity = new CIEntities(sCIConnString))
2737
                {
2738
                    docinfo = (from info in Entity.DOCINFO
2739
                              where info.DOCUMENT_ID == doc_id
2740
                              && info.PROJECT_NO == project_no
2741
                              select info).First();
2742
                }
2743
            }
2744
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
2745
                return null;
2746
            }
2747
            return docinfo;
2748
        }
2749

    
2750
        [OperationContract]
2751
        public List<MarkupInfoItem> GetPrintDocItemList(string project_no, string doc_id, List<MarkupInfoItem> _markupInfoList)
2752
        {
2753
            MarkupInfoItem _result = null;
2754
            List<MarkupInfoItem> markupinfo = new List<MarkupInfoItem>();
2755
            try
2756
            {
2757
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2758
                using (CIEntities Entity = new CIEntities(sCIConnString))
2759
                {
2760
                    var docitem = (from info in Entity.DOCINFO
2761
                               where info.DOCUMENT_ID == doc_id
2762
                               && info.PROJECT_NO == project_no
2763
                               select info).First();
2764

    
2765
                    foreach (MARKUP_INFO markinfo in docitem.MARKUP_INFO)
2766
                    {
2767
                        var members = GetMemberQuery(Entity, markinfo.USER_ID);
2768

    
2769
                        MEMBER member = new MEMBER();
2770

    
2771
                        if (members.Count() > 0)
2772
                        {
2773
                            member = members.First();
2774
                        }
2775

    
2776
                        string displaycolor = null;
2777

    
2778
                        try
2779
                        {
2780
                            displaycolor = _markupInfoList.Where(info => info.MarkupInfoID == markinfo.ID).First().DisplayColor;
2781
                        }
2782
                        catch (Exception ex)
2783
                        {
2784
                            System.Diagnostics.Trace.WriteLine("KCOM_API - GetPrintDocItemList displaycolor : " + ex.ToString());
2785

    
2786
                            displaycolor = "#FFFFFF";
2787
                        }
2788
                        
2789
                        _result = new MarkupInfoItem
2790
                        {
2791
                            MarkupInfoID = markinfo.ID,
2792
                            Consolidate = markinfo.CONSOLIDATE,
2793
                            CreateTime = markinfo.UPDATE_TIME.HasValue ? markinfo.UPDATE_TIME.Value : markinfo.CREATE_TIME,
2794
                            DisplayColor = displaycolor,
2795
                            UserID = markinfo.USER_ID,
2796
                            UserName = member.NAME,
2797
                            Depatment = member.DEPARTMENT,
2798
                        };
2799

    
2800
                        _result.MarkupList = new List<IKCOM.MarkupItem>();
2801
                        var markup_Version = markinfo.MARKUP_INFO_VERSION.OrderByDescending(p => p.CREATE_DATE).First();
2802

    
2803
                        foreach (MARKUP_DATA markdata in markup_Version.MARKUP_DATA)
2804
                        {
2805
                            MarkupItem markitem = new MarkupItem()
2806
                            {
2807
                                ID = markdata.ID,
2808
                                PageNumber = markdata.PAGENUMBER,
2809
                            };
2810
                            _result.MarkupList.Add(markitem);
2811
                        }
2812

    
2813
                        _result.PageCount = _result.MarkupList.GroupBy(i => i.PageNumber).Count();
2814

    
2815
                        markupinfo.Add(_result);
2816
                    }
2817
                }
2818
            }
2819
            catch (Exception ex)
2820
            {
2821
                return null;
2822
            }
2823
            return markupinfo;
2824
        }
2825

    
2826
        [OperationContract]
2827
        public bool AddMessage(string project_no, TALK value)
2828
        {
2829
            try
2830
            {
2831
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2832
                using (CIEntities entity = new CIEntities(sCIConnString))
2833
                {                    
2834
                    entity.TALK.AddObject(value);
2835
                    entity.SaveChanges();
2836
                }
2837
            }
2838
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
2839
                return false;
2840
            }
2841
            return true;
2842
        }
2843

    
2844
        [OperationContract]
2845
        public List<TALK> GetMessage(string project_no, string doc_id)
2846
        {
2847
            List<TALK> result = new List<TALK>();
2848
            try
2849
            {
2850
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2851
                using (CIEntities entity = new CIEntities(sCIConnString))
2852
                {
2853
                    result = entity.TALK.Where(data => data.DOCUMENT_ID == doc_id).ToList();                        
2854
                }
2855
            }
2856
            catch (Exception ex)
2857
            {
2858
                return result;
2859
            }
2860
            return result;
2861
        }
2862

    
2863

    
2864
        #region Legacy System I/F
2865
        /// <summary>
2866
        /// Ensemble+ Sign Data Return
2867
        /// </summary>
2868
        /// <param name="user_id"></param>
2869
        /// <returns></returns>
2870
        private string getEnsembleSign(string user_id)
2871
        {
2872
            string result = null;
2873
            string soapurl = string.Empty;
2874

    
2875
            try
2876
            {
2877
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2878
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2879
                {
2880
                    var item = Entity.PROPERTIES.Where(d => d.TYPE == "UpLoadServiceUrl").FirstOrDefault();
2881

    
2882
                    if (item != null)
2883
                    {
2884
                        soapurl = item.VALUE;
2885

    
2886
                        WebClient webClient = new WebClient();
2887
                        string data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ens=\"http://EnsemblePlus.Webservice\"> <soapenv:Header/> <soapenv:Body> <ens:checkoutSignImage>"
2888
                            + "<ens:sUserNo>" + user_id + "</ens:sUserNo>"
2889
                            + "</ens:checkoutSignImage> </soapenv:Body></soapenv:Envelope>";
2890
                        webClient.Headers.Add(HttpRequestHeader.ContentType, "text/xml");
2891
                        webClient.Headers.Add("SOAPAction", "http://EnsemblePlus.Webservice");
2892
                        var _result = webClient.UploadString(new Uri(soapurl), data);
2893
                        XmlDocument xmlDoc = new XmlDocument();
2894
                        xmlDoc.LoadXml(_result);
2895
                        XmlNodeList list = xmlDoc.GetElementsByTagName("checkoutSignImageResponse");
2896

    
2897
                        foreach (XmlNode xn in list)
2898
                        {
2899
                            result = xn["checkoutSignImageReturn"].InnerText;
2900
                        }
2901

    
2902
                        if (result.Contains("No business object"))
2903
                        {
2904
                            result = null;
2905
                        }
2906
                    }
2907
                    else
2908
                    {
2909
                        result = null;
2910
                    }
2911
                }
2912
             
2913
            }
2914
            catch (Exception ex)
2915
            {   
2916
                result = null;
2917
            }
2918

    
2919
            return result;
2920
        }
2921
        #endregion
2922

    
2923
        #region Final Service
2924
        [OperationContract]
2925
        [ServiceKnownType(typeof(DOCINFO))]                
2926
        public DOCINFO FinalPDF_GetDocinfo(string project_no, string docinfo_id)
2927
        {
2928
            DOCINFO docinfo = null;
2929

    
2930
            try
2931
            {
2932
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2933
                using (CIEntities _entity = new CIEntities(sCIConnString))
2934
                {
2935
                    var doc = _entity.DOCINFO.Where(x => x.ID == docinfo_id).FirstOrDefault();
2936
                    if(doc != null)
2937
                    {
2938
                        docinfo = new DOCINFO()
2939
                        {
2940
                            ID = doc.ID,
2941
                            DOCUMENT_ID = doc.DOCUMENT_ID,
2942
                            PAGE_COUNT = doc.PAGE_COUNT,
2943
                            ORIGINAL_FILE = doc.ORIGINAL_FILE,
2944
                            PROJECT_NO = doc.PROJECT_NO
2945
                        };
2946
                    }                    
2947
                }
2948
            }
2949
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
2950
                throw;
2951
            }
2952
            return docinfo;
2953
        }
2954
        [OperationContract]
2955
        [ServiceKnownType(typeof(DOCUMENT_ITEM))]
2956
        public DOCUMENT_ITEM FinalPDF_GetDocumentItem(string project_no, string document_id)
2957
        {
2958
            DOCUMENT_ITEM item = null;
2959

    
2960
            try
2961
            {
2962
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2963
                using (CIEntities _entity = new CIEntities(sCIConnString))
2964
                {
2965
                    var doc = _entity.DOCUMENT_ITEM.Where(x => x.PROJECT_NO == project_no &&  x.DOCUMENT_ID == document_id).FirstOrDefault();
2966
                    if(doc != null)
2967
                    {
2968
                        item = new DOCUMENT_ITEM()
2969
                        {
2970
                            ID = doc.ID,
2971
                            ORIGINAL_FILE = doc.ORIGINAL_FILE,
2972
                            PROJECT_NO = doc.PROJECT_NO,
2973
                            DOCUMENT_ID = doc.DOCUMENT_ID,
2974
                            DOCUMENT_NO = doc.DOCUMENT_NO,
2975
                            DOCUMENT_NAME = doc.DOCUMENT_NAME,
2976
                            //ENSEMBLEINFO_URL = doc.ENSEMBLEINFO_URL,
2977
                            GROUP_NO = doc.GROUP_NO,
2978
                            RESULT = doc.RESULT,
2979
                            REVISION = doc.REVISION,
2980
                            RESULT_FILE = doc.RESULT_FILE
2981
                        };
2982
                    }
2983
                    
2984
                }
2985
            }
2986
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
2987
                throw;
2988
            }
2989
            return item;
2990
        }
2991
        [OperationContract]
2992
        [ServiceKnownType(typeof(MARKUP_DATA))]
2993
        public List<MARKUP_DATA> FinalPDF_GetMarkupdata(string project_no, string docinfo_id)
2994
        {
2995
            List<MARKUP_DATA> results = new List<MARKUP_DATA>();
2996

    
2997
            try
2998
            {
2999
                //using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
3000
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
3001
                using (CIEntities _entity = new CIEntities(sCIConnString))
3002
                {
3003
                    var datas = _entity.MARKUP_DATA.Where(x => x.MARKUP_INFO_VERSION.MARKUP_INFO.DOCINFO_ID == docinfo_id
3004
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.CONSOLIDATE == 1
3005
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.AVOID_CONSOLIDATE == 0
3006
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.PART_CONSOLIDATE == 0).ToList();
3007
                    foreach (var data in datas)
3008
                    {
3009
                        MARKUP_DATA d = new MARKUP_DATA()
3010
                        {
3011
                            ID = data.ID,
3012
                            //GROUP_ID = data.GROUP_ID,
3013
                            SYMBOL_ID = data.SYMBOL_ID,
3014
                            DATA = data.DATA,
3015
                            DATA_TYPE = data.DATA_TYPE,
3016
                            MARKUPINFO_VERSION_ID = data.MARKUPINFO_VERSION_ID,
3017
                            PAGENUMBER = data.PAGENUMBER
3018
                        };
3019
                        results.Add(d);
3020
                    }
3021
                }
3022
            }
3023
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
3024
                throw;
3025
            }
3026
            return results;
3027
        }
3028
        [OperationContract]
3029
        [ServiceKnownType(typeof(MARKUP_INFO))]
3030
        public MARKUP_INFO FinalPDF_GetMarkupinfo(string project_no, string docinfo_id)
3031
        {
3032
            MARKUP_INFO markupInfo = null;
3033

    
3034
            try
3035
            {
3036
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
3037
                using (CIEntities _entity = new CIEntities(sCIConnString))
3038
                {
3039
                    var tmp = _entity.MARKUP_INFO.Where(x => x.DOCINFO_ID == docinfo_id && x.CONSOLIDATE == 1 && x.AVOID_CONSOLIDATE == 0 && x.PART_CONSOLIDATE == 0).FirstOrDefault();
3040
                    if (tmp != null)
3041
                    {
3042
                        markupInfo = new MARKUP_INFO()
3043
                        {
3044
                            ID = tmp.ID,
3045
                            DOCINFO_ID = tmp.DOCINFO_ID,
3046
                            USER_ID = tmp.USER_ID
3047
                        };
3048
                    }                    
3049
                }
3050
            }
3051
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
3052
                throw;
3053
            }
3054
            return markupInfo;
3055
        }
3056
        [OperationContract]
3057
        [ServiceKnownType(typeof(FINAL_PDF))]
3058
        public List<FINAL_PDF> FinalPDF_GetFinalPDFs(string final_id)
3059
        {
3060
            List<FINAL_PDF> results = new List<FINAL_PDF>();
3061

    
3062
            try
3063
            {
3064
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3065
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3066
                {
3067
                    var finalList = _entity.FINAL_PDF.Where(final => final.ID == final_id).ToList();
3068
                    foreach(var final in finalList)
3069
                    {
3070
                        FINAL_PDF pdf = new FINAL_PDF()
3071
                        {
3072
                            ID = final.ID,
3073
                            DOCINFO_ID = final.DOCINFO_ID,
3074
                            DOCUMENT_ID = final.DOCUMENT_ID,
3075
                            STATUS = final.STATUS,
3076
                            CURRENT_PAGE = final.CURRENT_PAGE,
3077
                            CREATE_DATETIME = final.CREATE_DATETIME,
3078
                            START_DATETIME = final.START_DATETIME,
3079
                            END_DATETIME = final.END_DATETIME,
3080
                            EXCEPTION = final.EXCEPTION,
3081
                            PROJECT_NO = final.PROJECT_NO,
3082
                            TOTAL_PAGE = final.TOTAL_PAGE,
3083
                            MARKUPINFO_ID = final.MARKUPINFO_ID,
3084
                            CREATE_USER_ID = final.CREATE_USER_ID
3085
                        };
3086
                        results.Add(pdf);
3087
                    }
3088
                }
3089
            }
3090
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
3091
                throw;
3092
            }
3093
            return results;
3094
        }
3095
        [OperationContract]
3096
        [ServiceKnownType(typeof(DOCPAGE))]
3097
        public List<DOCPAGE> FinalPDF_GetDocpage(string project_no, string docinfo_id)
3098
        {
3099
            List<DOCPAGE> results = new List<DOCPAGE>();
3100

    
3101
            try
3102
            {
3103
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
3104
                using (CIEntities _entity = new CIEntities(sCIConnString))
3105
                {
3106
                    var pages = _entity.DOCPAGE.Where(x => x.DOCINFO_ID == docinfo_id).OrderBy(x => x.PAGE_NUMBER).ToList();
3107
                    foreach(var page in pages)
3108
                    {
3109
                        DOCPAGE p = new DOCPAGE()
3110
                        {
3111
                            PAGE_ANGLE = page.PAGE_ANGLE,
3112
                            PAGE_NUMBER = page.PAGE_NUMBER,
3113
                            PAGE_HEIGHT = page.PAGE_HEIGHT,
3114
                            PAGE_WIDTH = page.PAGE_WIDTH,
3115
                            DOCINFO_ID = page.DOCINFO_ID                            
3116
                        };
3117
                        results.Add(p);
3118
                    }                    
3119
                }
3120
            }
3121
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
3122
                throw;
3123
            }
3124
            return results;
3125
        }
3126
        [OperationContract]        
3127
        public bool FinalPDF_SetFinalPDFStatus(string final_id, FinalStatus status)
3128
        {
3129
            bool result = false;
3130

    
3131
            try
3132
            {
3133
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3134
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3135
                {
3136
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
3137
                    if(tmp != null)
3138
                    {
3139
                        switch(status)
3140
                        {
3141
                            case FinalStatus.Create:
3142
                                tmp.START_DATETIME = DateTime.Now;
3143
                                break;
3144
                            case FinalStatus.Success:
3145
                                tmp.END_DATETIME = DateTime.Now;
3146
                                tmp.EXCEPTION = string.Empty;
3147
                                break;                                
3148
                        }
3149
                        tmp.STATUS = (int)status;
3150
                        _entity.SaveChanges();
3151
                        result = true;                        
3152
                    }
3153
                }                    
3154
            }
3155
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
3156
                throw;
3157
            }
3158
            return result;
3159
        }
3160

    
3161
        /// <summary>
3162
        /// 현재 진행중인 Final PDF 가 없거나 Success 일 경우에만 true return
3163
        /// </summary>
3164
        /// <param name="DocInfoID"></param>
3165
        /// <param name="MarkupInfoID"></param>
3166
        /// <param name="CreateUserID"></param>
3167
        /// <returns></returns>
3168
        [OperationContract]
3169
        public bool FinalPDF_GetFinalPDFStatus(string DocInfoID, string MarkupInfoID, string CreateUserID)
3170
        {
3171
            bool result = false;
3172

    
3173
            try
3174
            {
3175
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3176
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3177
                {
3178
                    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();
3179
                    if (finalpdf != null)
3180
                    {
3181
                        if (finalpdf.STATUS == (int)FinalStatus.Success)
3182
                        {
3183
                            result = true;
3184
                        }
3185
                    }
3186
                    else
3187
                        result = true;
3188
                }
3189
            }
3190
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
3191
                throw;
3192
            }
3193
            return result;
3194
        }
3195

    
3196
        [OperationContract]
3197
        public bool FinalPDF_SetCurrentPage(string final_id, int currentpage)
3198
        {
3199
            bool result = false;
3200

    
3201
            try
3202
            {
3203
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3204
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3205
                {
3206
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
3207
                    if (tmp != null)
3208
                    {
3209
                        tmp.CURRENT_PAGE = currentpage;
3210
                        _entity.SaveChanges();
3211
                        result = true;
3212
                    }
3213
                }
3214
            }
3215
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
3216
                throw;
3217
            }
3218
            return result;
3219
        }
3220
        [OperationContract]
3221
        public bool FinalPDF_SetError(string final_id, string msg)
3222
        {
3223
            bool result = false;
3224

    
3225
            try
3226
            {
3227
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3228
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3229
                {
3230
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
3231
                    if (tmp != null)
3232
                    {                        
3233
                        tmp.STATUS = (int)FinalStatus.Error;
3234
                        tmp.EXCEPTION = DateTime.Now.ToShortDateString() + " " + msg;                        
3235
                        _entity.SaveChanges();
3236
                        result = true;
3237
                    }
3238
                }
3239
            }
3240
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
3241
                throw;
3242
            }
3243
            return result;
3244
        }
3245

    
3246
        [OperationContract]
3247
        public bool FinalPDF_SetFinalResultPath(string project_no, string document_id, string url)
3248
        {
3249
            bool result = false;
3250

    
3251
            try
3252
            {
3253
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
3254
                using (CIEntities _entity = new CIEntities(sCIConnString))
3255
                {
3256
                    var item = _entity.DOCUMENT_ITEM.Where(d =>d.PROJECT_NO == project_no && d.DOCUMENT_ID == document_id).FirstOrDefault();
3257
                    if (item != null)
3258
                    {
3259
                        item.RESULT_FILE = url;
3260
                        _entity.SaveChanges();
3261
                        result = true;
3262
                    }
3263
                }
3264
            }
3265
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
3266
                throw;
3267
            }
3268
            return result;
3269
        }
3270

    
3271
        [OperationContract]
3272
        public bool SaveLog(string project_no, string document_id, string Log)
3273
        {
3274
            bool result = false;
3275

    
3276
            try
3277
            {
3278
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3279
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3280
                {
3281
                    _entity.AddToERROR_LOG(new ERROR_LOG
3282
                    {
3283
                        PROJECT_NO = project_no,
3284
                        DOCUMENT_ID = document_id,
3285
                        CONTENTS = Log,
3286
                        CREATE_DATETIME = DateTime.Now.ToString("yyMMddssmm"),
3287
                        CODE = "",
3288
                        TYPE = "Markus Log",
3289
                        LEVEL = "",
3290
                        SERVICE_NAME = "Markus",
3291
                    });
3292

    
3293
                    _entity.SaveChanges();
3294
                }
3295
            }
3296
            catch (Exception ex)
3297
            {
3298
            }
3299

    
3300
            return result;
3301
        }
3302

    
3303
        [OperationContract]
3304
        [ServiceKnownType(typeof(MEMBER))]
3305
        public MEMBER FinalPDF_GetCommentMember(string project_no, string markupdata_id)
3306
        {
3307
            MEMBER member = null;
3308
            try
3309
            {
3310
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
3311
                using (CIEntities _entity = new CIEntities(sCIConnString))
3312
                {
3313
                    var data = _entity.MARKUP_DATA.Where(x => x.ID == markupdata_id).FirstOrDefault();
3314
                    string user_id = data.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID;
3315

    
3316
                    var person = GetMemberQuery(_entity,user_id);
3317

    
3318
                    if(person.Count() > 0)
3319
                    {
3320
                        member = person.First();
3321
                    }
3322
                }
3323
            }
3324
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
3325
                throw;
3326
            }
3327

    
3328
            return member;
3329
        }
3330

    
3331
        [OperationContract]
3332
        [ServiceKnownType(typeof(PROPERTIES))]
3333
        public List<PROPERTIES> FinalPDF_GetProperties(string project_no)
3334
        {
3335
            List<PROPERTIES> results = new List<PROPERTIES>();
3336
            try
3337
            {
3338
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3339
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3340
                {
3341
                    var _items = _entity.PROPERTIES.Where(x => x.PROPERTY == project_no).ToList();
3342
                    foreach(var item in _items)
3343
                    {
3344
                        PROPERTIES pROPERTIES = new PROPERTIES()
3345
                        {
3346
                            ID = item.ID,
3347
                            PROPERTY = item.PROPERTY,
3348
                            TYPE = item.TYPE,
3349
                            VALUE = item.VALUE
3350
                        };
3351
                        results.Add(pROPERTIES);
3352
                    }
3353
                }
3354

    
3355
            }
3356
            catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex);
3357
                throw;
3358
            }
3359
            return results;
3360
        }
3361
        #endregion
3362
    }    
3363
}
클립보드 이미지 추가 (최대 크기: 500 MB)