프로젝트

일반

사용자정보

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

markus / KCOM_API / ServiceDeepView.svc.cs @ b42dd24d

이력 | 보기 | 이력해설 | 다운로드 (130 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

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

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

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

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

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

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

    
94
                    KCOM_SystemInfo sysInfo = new KCOM_SystemInfo();
95

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

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

    
108
                    url = uc.PROPERTIES.Where(data => data.TYPE == "STAMP").FirstOrDefault();
109
                    if(url != null)
110
                    {
111
                        sysInfo.STAMP = url.VALUE;
112
                    }
113
                    return sysInfo;
114
                }
115
            }
116
            catch (Exception ex)
117
            {
118
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetSystemData : " + ex.ToString());
119

    
120
            }
121
            return null;
122
            //GC.Collect(2);
123
        }
124

    
125
        private static string shortGuid()
126
        { 
127
            byte[] bytes = new byte[16];
128
            using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create())
129
            {
130
                provider.GetBytes(bytes);
131
            }
132

    
133
            var guid = new Guid(bytes);
134

    
135
            return Convert.ToBase64String(guid.ToByteArray())
136
                .Substring(0, 10)
137
                .Replace("/", "")
138
                .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
139
        }
140

    
141

    
142
        [OperationContract]
143
        public List<FAVORITE_DOC> GetFavoriteVP(string PrjNo, string userID, string sharepointItemID)
144
        {
145
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
146
            using (KCOMEntities dc = new KCOMEntities(sConnString))
147
            {
148

    
149
                int flagString = Convert.ToInt32(FAVORITE_FLAG.Personal);
150
                List<FAVORITE_DOC> favoriteListSet = new List<FAVORITE_DOC>();
151
                //dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == PrjNo && data.DOCUMENT_ID == sharepointItemID && data.FLAG !=
152
                //    flagString).ToList().ForEach(data => favoriteListSet.Add(data));
153

    
154

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

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

    
159
                //favoriteListSet = favoriteListSet.Distinct().ToList();
160
                return favoriteListSet;
161
            }
162
        }
163

    
164
        [OperationContract]
165
        public bool EditFavoriteVP(string prjNo, string userID, string docID, int state, string description)
166
        {
167
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
168
            using (KCOMEntities dc = new KCOMEntities(sConnString))
169
            {
170
                //List<FAVORITE_DOC> favoriteSet = dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == prjNo && data.MEMBER_USER_ID == userID
171
                //    && data.PAGE_NO == SavePageNo && data.CREATE_TIME == createTime).ToList();
172
                List<FAVORITE_DOC> favoriteSet = dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == prjNo && data.MEMBER_USER_ID == userID
173
                    && data.ID == docID).ToList();
174
                try
175
                {
176

    
177
                    if (favoriteSet.Count > 0)
178
                    {
179
                        var FavoriteVP_Instance = favoriteSet.First();
180

    
181
                        FavoriteVP_Instance.DESCRIPTION = description;
182
                        FavoriteVP_Instance.FLAG = state;
183

    
184
                        dc.SaveChanges();
185

    
186
                        return true;
187
                    }
188
                    else
189
                    {
190
                        return false;
191
                    }
192
                }
193
                catch (Exception ex)
194
                {
195
                    System.Diagnostics.Debug.WriteLine("KCOM_API - EditFavoriteVP : " + ex.ToString());
196

    
197
                    return false;
198
                }
199
            }
200
        }
201

    
202
        [OperationContract]
203
        public bool DelFavoriteVP(string prjNo, string userID, int SavePageNo, string docID)
204
        {
205
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
206
            using (KCOMEntities dc = new KCOMEntities(sConnString))
207
            {
208

    
209
                List<FAVORITE_DOC> favoriteSet = dc.FAVORITE_DOC.Where(data => data.PROJECT_NO == prjNo && data.MEMBER_USER_ID == userID
210
                    && data.ID == docID).ToList();
211

    
212
                try
213
                {
214
                    if (favoriteSet.Count > 0)
215
                    {
216
                        favoriteSet.ForEach(data => dc.FAVORITE_DOC.DeleteObject(data));
217
                        dc.SaveChanges();
218
                        return true;
219
                    }
220
                    else
221
                    {
222
                        return false;
223
                    }
224
                }
225
                catch (Exception ex)
226
                {
227
                    System.Diagnostics.Debug.WriteLine("KCOM_API - DelFavoriteVP : " + ex.ToString());
228

    
229
                    return false;
230
                }
231
            }
232
        }
233

    
234
        /// <summary>
235
        /// 두 페이지를 비교하여 결과를 리턴한다
236
        /// </summary>
237
        /// <param name="projectNo"></param>
238
        /// <param name="originDocItem_ID"></param>
239
        /// <param name="targetDocItem_ID"></param>
240
        /// <param name="originPageNo"></param>
241
        /// <param name="targetPageNo"></param>
242
        /// <param name="isInternalAddress"></param>
243
        /// <returns></returns>
244
        [OperationContract]
245
        public List<Rect> GetCompareRect(string projectNo, string originDocItem_ID, string targetDocItem_ID, string originPageNo, string targetPageNo, string isInternalAddress)
246
        {
247
            List<Rect> result = new List<Rect>();
248

    
249
            try
250
            {
251
                string originFile = "";
252
                string targetFile = "";
253

    
254
                string sOriginFolder = originDocItem_ID.All(char.IsDigit) ? (Convert.ToUInt32(originDocItem_ID) / 100).ToString() : (originDocItem_ID.Length >= 5 ? originDocItem_ID.Substring(0, 5) : originDocItem_ID);
255
                string sTagetFolder = targetDocItem_ID.All(char.IsDigit) ? (Convert.ToUInt32(targetDocItem_ID) / 100).ToString() : (targetDocItem_ID.Length >= 5 ? targetDocItem_ID.Substring(0, 5) : targetDocItem_ID);
256

    
257
                if (Boolean.Parse(isInternalAddress))
258
                {
259
                    originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sOriginFolder, originDocItem_ID, originPageNo);
260
                    targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sTagetFolder, targetDocItem_ID, targetPageNo);
261
                }
262
                else
263
                {
264
                    originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo, originDocItem_ID, originPageNo);
265
                    targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo, targetDocItem_ID, targetPageNo);
266
                }
267

    
268
                using (Markus.Image.ImageCompare compareLib = new Markus.Image.ImageCompare())
269
                {
270
                    result = compareLib.CompareReturnRects(originFile, targetFile, new System.Drawing.Size(20, 20));
271
                }
272
            }
273
            catch (Exception ex)
274
            {
275
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetCompareRect : " + ex.ToString());
276
                //throw new FaultException(ex.ToString() + " Inner Exception : " + ex.InnerException?.ToString());
277
            }
278

    
279

    
280
            return result;
281
        }
282

    
283
        /// <summary>
284
        /// 두 페이지를 비교하여 결과를 리턴한다
285
        /// </summary>
286
        /// <param name="projectNo"></param>
287
        /// <param name="originDocItem_ID"></param>
288
        /// <param name="targetDocItem_ID"></param>
289
        /// <param name="originPageNo"></param>
290
        /// <param name="targetPageNo"></param>
291
        /// <param name="isInternalAddress"></param>
292
        /// <returns></returns>
293
        [OperationContract]
294
        public List<Rect> GetComparefixSize(string projectNo, string originDocItem_ID, string targetDocItem_ID, string originPageNo, string targetPageNo,Size FixSize, string isInternalAddress)
295
        {
296
            List<Rect> result = new List<Rect>();
297

    
298
            try
299
            {
300
                string originFile = "";
301
                string targetFile = "";
302

    
303
                string sOriginFolder = originDocItem_ID.All(char.IsDigit) ? (Convert.ToUInt32(originDocItem_ID) / 100).ToString() : (originDocItem_ID.Length >= 5 ? originDocItem_ID.Substring(0, 5) : originDocItem_ID);
304
                string sTagetFolder = targetDocItem_ID.All(char.IsDigit) ? (Convert.ToUInt32(targetDocItem_ID) / 100).ToString() : (targetDocItem_ID.Length >= 5 ? targetDocItem_ID.Substring(0, 5) : targetDocItem_ID);
305

    
306
                if (Boolean.Parse(isInternalAddress))
307
                {
308
                    originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sOriginFolder, originDocItem_ID, originPageNo);
309
                    targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sTagetFolder, targetDocItem_ID, targetPageNo);
310
                }
311
                else
312
                {
313
                    originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo, originDocItem_ID, originPageNo);
314
                    targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo, targetDocItem_ID, targetPageNo);
315
                }
316

    
317
                using (Markus.Image.ImageCompare compareLib = new Markus.Image.ImageCompare())
318
                {
319

    
320
                    result = compareLib.CompareReturnRects(originFile, targetFile, new System.Drawing.Size(20, 20));
321
                }
322
            }
323
            catch (Exception ex)
324
            {
325
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetCompareRect : " + ex.ToString());
326
                //throw new FaultException(ex.ToString() + " Inner Exception : " + ex.InnerException?.ToString());
327
            }
328

    
329

    
330
            return result;
331
        }
332

    
333
        //[OperationContract]
334
        //public List<Rect> GetCompareRect_old(string projectNo, string originDocItem_ID, string targetDocItem_ID, string originPageNo, string targetPageNo, string isInternalAddress)
335
        //{
336
        //    System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
337

    
338
        //    stopwatch.Start();
339

    
340
        //    string originFile = "";
341
        //    string targetFile = "";
342

    
343
        //    string sFolder = originDocItem_ID.All(char.IsDigit) ? (Convert.ToUInt32(originDocItem_ID) / 100).ToString() : (originDocItem_ID.Length >= 5 ? originDocItem_ID.Substring(0, 5) : originDocItem_ID);
344
        //    if (Boolean.Parse(isInternalAddress))
345
        //    {
346
        //        originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sFolder, originDocItem_ID, originPageNo);
347
        //        targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath, projectNo, sFolder, targetDocItem_ID, targetPageNo);
348
        //    }
349
        //    else
350
        //    {
351
        //        originFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo, originDocItem_ID, originPageNo);
352
        //        targetFile = String.Format(KCOM_API.Properties.Settings.Default.TileSoucePath_SUB, projectNo, targetDocItem_ID, targetPageNo);
353
        //    }
354

    
355
        //    CompareLib compareLib = new CompareLib();
356

    
357
        //    var resultOrigin = compareLib.ChangeCmpUrlToPng_File(originFile);
358
        //    var resultTarget = compareLib.ChangeCmpUrlToPng_File(targetFile);
359

    
360
        //    string outPutFile = compareLib.ImageCompare_File(resultOrigin, resultTarget);
361
        //    var result = compareLib.GetBoundBoxInImage(outPutFile);
362

    
363
        //    System.Diagnostics.Debug.WriteLine(new TimeSpan(stopwatch.ElapsedTicks));
364

    
365
        //    return result;
366
        //}
367

    
368

    
369
        #region Final PDF
370
        private string _ChanID = null;
371
        TcpChannel chan = null;
372
        [OperationContract]
373
        public FinalPDFResult SetFinalPDF(string ProjectNo, string DocInfoID, string MarkupInfoID, string CreateUserID)
374
        {
375
            #region 임시보관
376
            #endregion
377
            FinalPDFResult _result = new FinalPDFResult();
378
            RemFinalPDFObject remObj = null;
379
            try
380
            {
381
                string _finalID = shortGuid();
382
                int _DocTotalPages = -1;
383
                string docItemId;
384

    
385
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
386
                using (CIEntities _ci = new CIEntities(sCIConnString))
387
                {
388
                    var _doc = _ci.DOCINFO.Where(info => info.ID == DocInfoID);
389

    
390
                    if (_doc.Count() > 0)
391
                    {
392
                        _DocTotalPages = _doc.First().PAGE_COUNT;
393
                        docItemId = _doc.First().DOCUMENT_ID;
394
                    }
395
                    else
396
                    {
397
                        _result.Status = FinalStatus.Error;
398
                        _result.Exception = "페이지 정보를 가져올 수 없습니다.";
399
                        return _result;
400
                    }
401
                }
402
                if (_DocTotalPages > 0)
403
                {
404
                    FINAL_PDF fm = new FINAL_PDF()
405
                    {
406
                        ID = _finalID,
407
                        PROJECT_NO = ProjectNo,
408
                        DOCINFO_ID = DocInfoID,
409
                        DOCUMENT_ID = docItemId,
410
                        MARKUPINFO_ID = MarkupInfoID,
411
                        CREATE_USER_ID = CreateUserID,
412
                        TOTAL_PAGE = _DocTotalPages,
413
                        CREATE_DATETIME = DateTime.Now,
414
                        STATUS = (int)IFinalPDF.FinalStatus.Insert
415
                    };
416

    
417
                    string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
418
                    using (KCOMEntities _entity = new KCOMEntities(sConnString))
419
                    {
420
                        _entity.AddToFINAL_PDF(fm);
421
                        _entity.SaveChanges(System.Data.Objects.SaveOptions.AcceptAllChangesAfterSave);
422
                    };
423

    
424
                    System.Runtime.Remoting.Channels.IChannel _ch = System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp");
425
                    if (_ch == null)
426
                    {
427
                        chan = new TcpChannel();
428
                        _ChanID = chan.ChannelName;
429
                        System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan, false);
430
                        // Create an instance of the remote object
431

    
432
                        using (KCOMEntities ec = new KCOMEntities(sConnString))
433
                        {
434

    
435
                            //remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
436
                            //                          "tcp://localhost:9092/remFinalPDF");
437
                            remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
438
                                                      //"tcp://192.168.0.67:9092/remFinalPDF");
439
                                                      KCOM_API.Properties.Settings.Default.FinalService);
440
                        }
441

    
442
                        //"tcp://localhost:8080/remFinalPDF");
443

    
444
                        _result = remObj.SetFinalPDF(ProjectNo, _finalID);
445
                        _result.FinalID = _finalID;
446
                        _result.Status = FinalStatus.Success;
447

    
448
                        //MarkupToPDF.MarkupToPDF fa = new MarkupToPDF.MarkupToPDF();
449
                        //fa.MakeFinalPDF(fm);
450
                    }
451
                    else
452
                    {
453
                        _ChanID = _ch.ChannelName;
454
                    }
455
                }
456
            }
457
            catch (Exception ex)
458
            {
459
                System.Diagnostics.Debug.WriteLine("KCOM_API - SetFinalPDF : " + ex.ToString());
460

    
461
                _result.Status = FinalStatus.Error;
462

    
463
                if (ex.GetType() == typeof(System.Net.Sockets.SocketException))
464
                    _result.Exception = "Final Server Not Connection";
465
                else _result.Exception = ex.ToString();
466
            }
467
            finally
468
            {
469
                remObj = null;
470
                if (System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp") != null)
471
                    System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(chan);
472

    
473
                GC.Collect(2);
474
            }
475
            return _result;
476
        }
477
        #endregion
478

    
479

    
480
        [OperationContract]
481
        public bool GetConversionState(KCOM_BasicParam param)
482
        {
483
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
484
            using (CIEntities entity = new CIEntities(sCIConnString))
485
            {
486
                var doc = entity.DOCINFO.Where(data => data.DOCUMENT_ID == param.documentID).FirstOrDefault();
487
                if (doc != null)
488
                {
489
                    var count = doc.DOCPAGE.Where(data => data.DOCINFO_ID == doc.ID).Count();
490
                    if (doc.PAGE_COUNT == count)  //페이지 수가 일치하는지
491
                    {
492
                        return true;
493
                    }
494
                    else //페이지 수가 일치하지 않는 경우
495
                    {
496
                        string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
497
                        KCOMEntities entity_kcom = new KCOMEntities(sConnString);
498
                        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();
499

    
500
                        if (lst != null || lst.Count >= 1)
501
                        {
502
                            //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_PAGECOUNT"), param.documentID, param.projectNo);
503
                            //이메일 클라이언트를 구현해야함
504
                        }
505
                        return false;
506
                    }
507
                }
508
                else
509
                {
510
                    //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_CONVERTFAILED"), param.documentID, param.projectNo);
511
                    //이메일 클라이언트를 구현해야함
512
                    return false;
513
                }
514
            }
515
        }
516

    
517
        [OperationContract]
518
        public List<VPRevision> GetVPRevisionHistory(string ProjectNo, string vpNo, string DocumentId)
519
        {
520
            List<VPRevision> _result = new List<VPRevision>();
521
            try
522
            {
523
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
524
                using (CIEntities entity = new CIEntities(sCIConnString))
525
                {
526
                    var _vpList = (from docitem in entity.DOCUMENT_ITEM
527
                                   where docitem.PROJECT_NO == ProjectNo && docitem.DOCUMENT_NO == vpNo
528
                                   select new VPRevision
529
                                   {
530
                                       RevNo = docitem.REVISION,
531
                                       GroupNo = docitem.GROUP_NO,
532
                                       FROM_VENDOR = docitem.ORIGINAL_FILE,
533
                                       DOCUMENT_ID = docitem.DOCUMENT_ID,
534
                                       TO_VENDOR = docitem.RESULT_FILE,
535
                                       RESULT = docitem.RESULT,
536
                                       DocNo = docitem.DOCUMENT_NO,
537
                                       //EnsembleLink = docitem.ENSEMBLEINFO_URL,
538
                                       //IsSyncPossible = docitem.DOCUMENT_ID == DocumentId ? false : entity.DOCINFO.Where(d => d.DOCUMENT_ID == docitem.DOCUMENT_ID).ToList().Count > 0 ? true : false
539
                                   });
540
                    _result = _vpList.ToList();
541
                    foreach (var vp in _result)
542
                    {
543
                        if (entity.DOCINFO.Where(d => d.DOCUMENT_ID == vp.DOCUMENT_ID).ToList().Count > 0)
544
                            vp.IsSyncPossible = true;
545
                        else
546
                            vp.IsSyncPossible = false;
547
                    }
548

    
549
                    //_result = _result.OrderByDescending(r => UInt64.Parse(System.Text.RegularExpressions.Regex.Replace(r.GroupNo, @"\D", ""))).ToList();
550
                    _result =  _result.OrderByDescending(r => r.GroupNo).ToList();
551
                }
552
            }
553
            catch (Exception ex)
554
            {
555
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetVPRevisionHistory : " + ex.ToString());
556
            }
557
            finally
558
            {
559
                //GC.Collect(2);
560
            }
561

    
562
            return _result;
563
        }
564

    
565
        [OperationContract]
566
        public VPRevision GetVPRevisionFirstOrDefault(string ProjectNo, string DocumentId)
567
        {
568
            VPRevision _result = null;
569
            try
570
            {
571
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
572
                using (CIEntities entity = new CIEntities(sCIConnString))
573
                {
574
                    _result = (from docitem in entity.DOCUMENT_ITEM
575
                     where docitem.PROJECT_NO == ProjectNo && docitem.DOCUMENT_ID == DocumentId
576
                     select new VPRevision
577
                     {
578
                         RevNo = docitem.REVISION,
579
                         GroupNo = docitem.GROUP_NO,
580
                         FROM_VENDOR = docitem.ORIGINAL_FILE,
581
                         DOCUMENT_ID = docitem.DOCUMENT_ID,
582
                         TO_VENDOR = docitem.RESULT_FILE,
583
                         RESULT = docitem.RESULT
584
                     }).FirstOrDefault();
585
                }
586
            }
587
            catch (Exception ex)
588
            {
589
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetVPRevisionFirstOrDefault : " + ex.ToString());
590
            }
591
            finally
592
            {
593
                //GC.Collect(2);
594
            }
595
            return _result;
596
        }
597

    
598
        [OperationContract]
599
        public DOCINFO GetDocInfo(KCOM_BasicParam param)
600
        {
601
            DOCINFO _result = null;
602
            try
603
            {
604
                // 차후 아래의 코드로 변경
605
                //using (CI_Entities ModelDeeview = new CI_Entities(DaelimCiConnectionString.ToString()))
606
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
607
                CIEntities ModelDeeview = new CIEntities(sCIConnString);
608

    
609
                var docinfo = ModelDeeview.DOCINFO.Where(doc => doc.DOCUMENT_ID == param.documentID && doc.PROJECT_NO == param.projectNo);
610
                if (docinfo.Count() > 0)
611
                {
612
                    _result = docinfo.First();
613
                    _result.MARKUP_INFO.Clear();
614

    
615
                }
616
                return _result;
617

    
618
            }
619
            catch (Exception ex)
620
            {
621
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetDocInfo : " + ex.ToString());
622
            }
623
            finally
624
            {
625
                //GC.Collect(2);
626
            }
627
            return null;
628
        }
629

    
630
        [OperationContract]
631
        public bool GetCheckSystemAdmin(string UserID)
632
        {
633
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
634
            using (KCOMEntities uc = new KCOMEntities(sConnString))
635
            {
636
                var user = uc.PROPERTIES.Where(data => data.TYPE == "Administrator" && data.PROPERTY.Contains(UserID)).FirstOrDefault();
637
                if (user != null)
638
                {
639
                    return true;
640
                }
641
                else
642
                {
643
                    return false;
644
                }
645
            }
646
            //GC.Collect(2);
647
        }
648

    
649
        [OperationContract]
650
        public DOCUMENT_ITEM GetDocumentItemInfo(KCOM_BasicParam param)
651
        {
652
            ///param : prjNo, documentId, userId
653
            DOCUMENT_ITEM _result = null;
654

    
655
            try
656
            {
657
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
658
                CIEntities entity = new CIEntities(sCIConnString);
659
               
660
                var _items = entity.DOCUMENT_ITEM.Where(data => data.PROJECT_NO == param.projectNo && data.DOCUMENT_ID == param.documentID);
661

    
662
                if (_items.Count() > 0)
663
                {
664
                    _result = _items.First();
665

    
666
                    return _result;
667
                }
668
                //else
669
                //{
670
                //    Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_DOCUMENTNOTFOUND"), param.documentID, param.projectNo);
671
                //}
672
            }
673
            catch (Exception ex)
674
            {
675
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetDocumentItemInfo : " + ex.ToString());
676

    
677
                new FaultException("GetDocumentItemInfo Error - "  + ex.ToString());
678
                //throw new FaultException(ex.ToString());
679
                //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, "GetDocumentItemInfo / " + ex.Message, param.documentID, param.projectNo);
680
            }
681

    
682
            return _result;
683
        }
684
        /// <summary>
685
        /// DOCUMENT_ITEM Table 의 ID 로 Item 을 Select
686
        /// </summary>
687
        /// 대림의 경우 Interface ID(Document 의 ID) 를 parameter 로 전달
688
        /// 넘어온 ID를 통해 document id 를 확인하는 과정이 필요
689
        /// <param name="ensemble_id"></param>
690
        /// <returns></returns>
691
        [OperationContract]
692
        public string GetDocItemID(string ensemble_id)
693
        {
694
            ///param : prjNo, documentId, userId
695
            string _result = string.Empty;
696

    
697
            try
698
            {
699
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
700
                CIEntities entity = new CIEntities(sCIConnString);
701

    
702
                var _items = entity.DOCUMENT_ITEM.Where(data => data.ID == ensemble_id).FirstOrDefault();
703
                if(_items != null)
704
                    _result = _items.DOCUMENT_ID;
705
            }
706
            catch (Exception ex)
707
            {
708
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetDocItemID : " + ex.ToString());
709
                //System.Diagnostics.Trace.WriteLine("GetVendorItemInfo Error : " + ex);
710
                //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, "GetDocumentItemInfo / " + ex.Message, param.documentID, param.projectNo);
711
            }
712

    
713
            return _result;
714
        }
715
        public string UserGO(MARKUP_INFO item)
716
        {
717
            if (item != null)
718
            {
719
                return item.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID;
720
            }
721
            return null;
722
        }
723
        
724
        [OperationContract]
725
        public List<MarkupInfoItem> GetMarkupInfoItems(string ProjectNo, string DocInfoId)
726
        {
727
            List<MarkupInfoItem> _result = new List<MarkupInfoItem>();
728
            try
729
            {
730
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
731
                using (CIEntities entity = new CIEntities(sCIConnString))
732
                {
733
                    var markupListData = entity.MARKUP_INFO.Where(data => data.DOCINFO_ID == DocInfoId).ToList();
734

    
735
                    var markupList = from markup in markupListData
736
                                     orderby markup.CREATE_TIME descending
737
                                     select new MarkupInfoItem
738
                                     {
739
                                         MarkupInfoID = markup.ID,
740
                                         UserID = markup.USER_ID,
741
                                         MarkupVersionID = markup.MARKUP_INFO_VERSION.Count() == 0 ? null : markup.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID,
742
                                         CreateTime = markup.CREATE_TIME,
743
                                         Consolidate = markup.CONSOLIDATE,
744
                                         Description = markup.DESCRIPTION,
745
                                         AvoidConsolidate = markup.AVOID_CONSOLIDATE,
746
                                         PartConsolidate = markup.PART_CONSOLIDATE,
747
                                         UpdateTime = DateTime.Parse(markup.UPDATE_TIME.ToString()),
748
                                     };
749

    
750
                    if (markupList.Count() > 0)
751
                    {
752
                        _result = markupList.ToList();
753
                    }
754

    
755
                    _result.ForEach(r =>
756
                    {
757

    
758
                        r.MarkupList = (from markupData in entity.MARKUP_DATA
759
                                        where markupData.MARKUPINFO_VERSION_ID == r.MarkupVersionID
760
                                        orderby markupData.PAGENUMBER
761
                                        select new MarkupItem { ID = markupData.ID, PageNumber = markupData.PAGENUMBER, Data = markupData.DATA, Data_Type = markupData.DATA_TYPE, Symbol_ID = markupData.SYMBOL_ID}).ToList();
762
                    });
763

    
764
                    List<PROPERTIES> _ColorsProperties = new List<PROPERTIES>();
765
                    Random random = new Random();
766

    
767
                    string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
768
                    using (KCOMEntities kcomEntity = new KCOMEntities(sConnString))
769
                    {
770
                        _ColorsProperties = (from property in kcomEntity.PROPERTIES
771
                                             where property.TYPE == "DisplayColor"
772
                                             select property).ToList();
773

    
774
                    }
775

    
776
                    if (_ColorsProperties.Count() == 0)
777
                    {
778
                        ColorGenerator uniqueColorGenerator = new ColorGenerator(System.Drawing.Color.Red); // 2303 = (int)Color.Red
779

    
780
                        uniqueColorGenerator.GetEnumerator(_result.Count());
781

    
782
                        for (int i = 0; i < _result.Count(); i++)
783
                        {
784
                             var c = uniqueColorGenerator.GetNext();
785
                            _ColorsProperties.Add(new PROPERTIES { VALUE = String.Format("{0:X2}{1:X2}{2:X2}",c.R, c.G,c.B) });
786
                        }
787
                    }
788

    
789
                    bool IsProjectNoPass = Properties.Settings.Default.IsProjectNoPass;
790

    
791
                    foreach (var item in _result)
792
                    {
793
                        string query = "SELECT members.ID,members.NAME,members.DEPARTMENT FROM CIEntities.MEMBER as members where members.ID = @userId";
794

    
795
                        System.Data.Objects.ObjectQuery<System.Data.Common.DbDataRecord> memberQuery 
796
                                      = entity.CreateQuery<System.Data.Common.DbDataRecord>(query,new System.Data.Objects.ObjectParameter("userId",item.UserID));
797
                        
798
                        if (memberQuery.Count() > 0)
799
                        {
800
                            string userName = memberQuery.First()["NAME"]?.ToString().Trim();
801
                            string depatment = memberQuery.First()["DEPARTMENT"]?.ToString().Trim();
802

    
803
                            item.UserName = userName;
804
                            item.Depatment = depatment;
805
                        }
806

    
807
                        if (_ColorsProperties.Count > 0)
808
                        {
809
                            int colorIdx = random.Next(0, _ColorsProperties.Count() - 1);
810
                            #region 부서별로 색상을 지정하고자 할때
811
                            /// 일단 의견을 들어보자구!
812
                            #endregion
813
                            item.DisplayColor = "#FF" + _ColorsProperties[colorIdx].VALUE;
814
                            _ColorsProperties.Remove(_ColorsProperties[colorIdx]);
815
                        }
816
                        else
817
                        {
818
                            item.DisplayColor = String.Format("#FF{0:X6}", random.Next(0x1000000));
819
                        }
820
                    }
821
                }
822
            }
823
            catch (Exception ex)
824
            {
825
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetMarkupInfoItems : " + ex.ToString());
826

    
827
                return _result;
828
            }
829
            finally
830
            {
831
                //GC.Collect(2);
832
            }
833

    
834
            return _result;
835
        }
836

    
837
        [OperationContract]
838
        public List<MarkupInfoItem> GetSyncMarkupInfoItems(string ProjectNo, string DocInfoId, string currentUser)
839
        {
840
            List<MarkupInfoItem> _result = new List<MarkupInfoItem>();
841
            try
842
            {
843
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
844
                using (CIEntities entity = new CIEntities(sCIConnString))
845
                {
846
                    var docItem = entity.DOCINFO.Where(data => data.DOCUMENT_ID == DocInfoId).FirstOrDefault();
847
                    if (docItem == null)
848
                    {
849
                        return null;
850
                    }
851
                    var markupListData = entity.MARKUP_INFO.Where(data => data.DOCINFO_ID == docItem.ID).ToList();
852

    
853
                    var markupList = from markup in markupListData
854
                                     where markup.USER_ID == currentUser || markup.CONSOLIDATE == 1
855
                                     orderby markup.CREATE_TIME descending
856
                                     select new MarkupInfoItem
857
                                     {
858
                                         MarkupInfoID = markup.ID,
859
                                         UserID = markup.USER_ID,
860
                                         MarkupVersionID = markup.MARKUP_INFO_VERSION.Count() == 0 ? null : markup.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID,
861
                                         CreateTime = markup.CREATE_TIME,
862
                                         Consolidate = markup.CONSOLIDATE,
863
                                         Description = markup.DESCRIPTION,
864
                                         AvoidConsolidate = markup.AVOID_CONSOLIDATE,
865
                                         PartConsolidate = markup.PART_CONSOLIDATE,
866
                                     };
867

    
868

    
869

    
870
                    if (markupList.Count() > 0)
871
                    {
872
                        _result = markupList.ToList();
873
                    }
874

    
875

    
876

    
877
                    _result.ForEach(r =>
878
                    {
879

    
880
                        r.MarkupList = (from markupData in entity.MARKUP_DATA
881
                                        where markupData.MARKUPINFO_VERSION_ID == r.MarkupVersionID
882
                                        orderby markupData.PAGENUMBER
883
                                        select new MarkupItem
884
                                        {
885
                                            ID = markupData.ID,
886
                                            PageNumber = markupData.PAGENUMBER,
887
                                            Data = markupData.DATA,
888
                                            Data_Type = markupData.DATA_TYPE,
889
                                            Symbol_ID = markupData.SYMBOL_ID
890
                                        }).ToList();
891
                    });
892

    
893
                    List<PROPERTIES> _ColorsProperties = new List<PROPERTIES>();
894
                    Random random = new Random();
895

    
896
                    string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
897
                    using (KCOMEntities kcomEntity = new KCOMEntities(sConnString))
898
                    {
899
                        _ColorsProperties = (from property in kcomEntity.PROPERTIES
900
                                             where property.TYPE == "DisplayColor"
901
                                             select property).ToList();
902
                    }
903

    
904
                    foreach (var item in _result)
905
                    {
906
                        string query = "SELECT members.ID,members.NAME,members.DEPARTMENT FROM CIEntities.MEMBER as members where members.ID = @userId";
907

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

    
911
                        if (memberQuery.Count() > 0)
912
                        {
913

    
914
                            string userName = memberQuery.First()["NAME"]?.ToString().Trim();
915
                            string depatment = memberQuery.First()["DEPARTMENT"]?.ToString().Trim();
916

    
917
                            item.UserName = userName;
918
                            item.Depatment = depatment;
919
                        }
920

    
921
                        if (_ColorsProperties.Count > 0)
922
                        {
923
                            int colorIdx = random.Next(1, _ColorsProperties.Count());
924
                            #region 부서별로 색상을 지정하고자 할때
925
                            /// 일단 의견을 들어보자구!
926
                            #endregion
927
                            item.DisplayColor = "#FF" + _ColorsProperties[colorIdx].VALUE;
928
                            _ColorsProperties.Remove(_ColorsProperties[colorIdx]);
929
                            //item.DisplayColor = "#FF" + _Colors.First();
930
                            //_Colors.Remove(_Colors.First());
931
                        }
932
                        else
933
                        {
934
                            item.DisplayColor = String.Format("#FF{0:X6}", random.Next(0x1000000));
935
                        }
936
                    }
937
                }
938
            }
939
            catch (Exception ex)
940
            {
941
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetSyncMarkupInfoItems : " + ex.ToString());
942
                return _result;
943
            }
944
            finally
945
            {
946
                //GC.Collect(2);
947
            }
948

    
949
            return _result;
950
        }
951

    
952

    
953
        //[OperationContract]
954
        //[ServiceKnownType(typeof(MEMBER))]
955
        //public List<MEMBER> GetUserData(string ProjectNo, string UserID)
956
        //{
957
        //    List<MEMBER> _result = new List<MEMBER>();
958

    
959
        //    using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
960
        //    {
961
        //        var _UserList = from member in entity.MEMBER
962
        //                        where member.ID == UserID
963
        //                        select member;
964
        //        _result = _UserList.ToList();
965
        //    }
966
        //    //GC.Collect(2);
967
        //    return _result;
968
        //}
969

    
970
        [OperationContract]
971
        [ServiceKnownType(typeof(MEMBER))]
972
        public List<MEMBER> GetUserData(string ProjectNo, string UserID)
973
        {
974
            List<MEMBER> _result = new List<MEMBER>();
975

    
976
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
977

    
978
            using (CIEntities entity = new CIEntities(sCIConnString))
979
            {
980
                _result = GetMemberQuery(entity, UserID);
981
            }
982
            //GC.Collect(2);
983
            return _result;
984
        }
985

    
986

    
987
        [OperationContract]
988
        public List<string> GetDeptData(string UserDept) //그룹 추가 옵션 부여 예정
989
        {
990
            List<string> _result = new List<string>();
991

    
992
            try
993
            {
994
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
995
                KCOMEntities entity = new KCOMEntities(sConnString);
996
                var YourEnginner = (from dept in entity.PROPERTIES
997
                                    where dept.TYPE == "DeptName" && UserDept.Contains(dept.VALUE)
998
                                    select dept).FirstOrDefault();
999

    
1000
                if (YourEnginner != null)
1001
                {
1002
                    _result = (from dept in entity.PROPERTIES
1003
                               where dept.PROPERTY == YourEnginner.PROPERTY
1004
                               select dept.VALUE).ToList();
1005
                    return _result;
1006
                }
1007
                else
1008
                {
1009
                    return null;
1010
                }
1011
            }
1012
            catch (Exception ex)
1013
            {
1014
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetDeptData : " + ex.ToString());
1015
            }
1016
            finally
1017
            {
1018
                //GC.Collect(2);
1019
            }
1020
            return _result;
1021
        }
1022

    
1023
        [OperationContract]
1024
        public bool DeleteMarkup(string ProjectNo, string MarkupInfoID)
1025
        {
1026
            bool _result = false;
1027
            try
1028
            {
1029
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1030
                using (KCOMDataModel.DataModel.CIEntities Entity = new KCOMDataModel.DataModel.CIEntities(sCIConnString))
1031
                {
1032

    
1033
                    MARKUP_INFO instance = Entity.MARKUP_INFO.Where(root => root.ID == MarkupInfoID).FirstOrDefault();
1034

    
1035
                    if (instance == null)
1036
                    {
1037
                        return false;
1038
                    }
1039
                    MARKUP_INFO_VERSION version = instance.MARKUP_INFO_VERSION.FirstOrDefault();
1040

    
1041

    
1042
                    version.MARKUP_DATA.ToList().ForEach(data =>
1043
                    {
1044
                        Entity.MARKUP_DATA.DeleteObject(data);
1045
                        Entity.SaveChanges();
1046
                    });
1047

    
1048
                    Entity.MARKUP_INFO_VERSION.DeleteObject(version);
1049
                    Entity.SaveChanges();
1050

    
1051
                    Entity.MARKUP_INFO.DeleteObject(instance);
1052
                    Entity.SaveChanges();
1053

    
1054
                }
1055
                _result = true;
1056
            }
1057
            catch (Exception ex)
1058
            {
1059
                System.Diagnostics.Debug.WriteLine("KCOM_API - DeleteMarkup : " + ex.ToString());
1060
            }
1061
            finally
1062
            {
1063
                //GC.Collect(2);
1064
            }
1065
            return _result;
1066
        }
1067

    
1068
        #region Favorite
1069
        [OperationContract]
1070
        public bool SetFavoriteVP(string prjNo, string userID, string groupNo, string docNo, string rev, int SavePageNo, string documentItemID, string VPDescription, IKCOM.FAVORITE_FLAG flag)
1071
        {
1072
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1073
            using (KCOMEntities entity = new KCOMEntities(sConnString))
1074
            {
1075
                try
1076
                {
1077
                    entity.FAVORITE_DOC.AddObject(new FAVORITE_DOC
1078
                    {
1079
                        ID = shortGuid(),
1080
                        PROJECT_NO = prjNo,
1081
                        DOCUMENT_ID = documentItemID,
1082
                        GROUP_NO = groupNo,
1083
                        DOCUMENT_NO = docNo,
1084
                        MEMBER_USER_ID = userID,
1085
                        DESCRIPTION = VPDescription,
1086
                        CREATE_TIME = DateTime.Now,
1087
                        REVISION = rev,
1088
                        FLAG = (int)flag,
1089
                        PAGE_NO = SavePageNo,
1090
                    });
1091
                    entity.SaveChanges();
1092
                }
1093
                catch (Exception ex)
1094
                {
1095
                    System.Diagnostics.Debug.WriteLine("KCOM_API - SetFavoriteVP : " + ex.ToString());
1096
                    return false;
1097
                }
1098

    
1099
                return true;
1100
            }
1101
        }
1102

    
1103
        //[OperationContract]
1104
        //public List<FAVORITE_DOC> GetFavoriteVP(string PrjNo, string userID, string sharepointItemID)
1105
        //{
1106
        //    using (KCOMEntities entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
1107
        //    {
1108

    
1109
        //        int flagString = Convert.ToInt32(IKCOM.FAVORITE_FLAG.Personal);                
1110
        //        List<FAVORITE_DOC> favoriteListSet = new List<FAVORITE_DOC>();
1111
        //        entity.FAVORITE_DOC.Where(data => data.PROJECT_NO == PrjNo && data.DOCUMENT_ID == sharepointItemID && data.FLAG !=
1112
        //            flagString).ToList().ForEach(data => favoriteListSet.Add(data));
1113
        //        entity.FAVORITE_DOC.Where(data => data.PROJECT_NO == PrjNo && data.MEMBER_USER_ID == userID).ToList().ForEach(data => favoriteListSet.Add(data));
1114
        //        favoriteListSet = favoriteListSet.Distinct().ToList();
1115
        //        return favoriteListSet;
1116
        //    }
1117
        //}
1118
        //[OperationContract]
1119
        //public bool EditFavoriteVP(string prjNo, string userID, int SavePageNo, string sharepointItemID, DateTime createTime, int state, string description)
1120
        //{
1121
        //    using (DeepViewEntities dc = new DeepViewEntities(ConnectStringBuilder.DeepViewConnectionString().ToString()))
1122
        //    {
1123
        //        List<FavoriteVP> favoriteSet = dc.FavoriteVP.Where(data => data.ProjectNo == prjNo && data.CreateUserID == userID
1124
        //            && data.PageNo == SavePageNo && data.CreateTime == createTime).ToList();
1125

    
1126
        //        try
1127
        //        {
1128

    
1129

    
1130
        //            if (favoriteSet.Count > 0)
1131
        //            {
1132
        //                var FavoriteVP_Instance = favoriteSet.First();
1133

    
1134
        //                FavoriteVP_Instance.Description = description;
1135
        //                FavoriteVP_Instance.Flag = state;
1136

    
1137
        //                dc.SaveChanges();
1138

    
1139
        //                return true;
1140
        //            }
1141
        //            else
1142
        //            {
1143
        //                return false;
1144
        //            }
1145
        //        }
1146
        //        catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1147
        //        {
1148
        //            return false;
1149
        //        }
1150
        //    }
1151
        //}
1152
        //[OperationContract]
1153
        //public bool DelFavoriteVP(string prjNo, string userID, int SavePageNo, string sharepointItemID, DateTime createTime)
1154
        //{
1155

    
1156
        //    using (DeepViewEntities dc = new DeepViewEntities(ConnectStringBuilder.DeepViewConnectionString().ToString()))
1157
        //    {
1158
        //        List<FavoriteVP> favoriteSet = dc.FavoriteVP.Where(data => data.ProjectNo == prjNo && data.CreateUserID == userID
1159
        //            && data.PageNo == SavePageNo && data.CreateTime == createTime).ToList();
1160

    
1161
        //        try
1162
        //        {
1163

    
1164

    
1165
        //            if (favoriteSet.Count > 0)
1166
        //            {
1167
        //                favoriteSet.ForEach(data => dc.FavoriteVP.DeleteObject(data));
1168
        //                dc.SaveChanges();
1169
        //                return true;
1170
        //            }
1171
        //            else
1172
        //            {
1173
        //                return false;
1174
        //            }
1175
        //        }
1176
        //        catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1177
        //        {
1178
        //            return false;
1179
        //        }
1180
        //    }
1181
        //}
1182
        #endregion
1183

    
1184
        [OperationContract]
1185
        public bool SaveMarkupData(MarkupInfoItem UserState,string project_no,string doc_id, string user_id, List<MARKUP_DATA> mlmarkup_data)
1186
        {
1187
            
1188
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1189
            using (CIEntities Entity = new CIEntities(sCIConnString))
1190
            {     
1191
                #region Docinfo 정보 가져오기
1192

    
1193
                string docinfoid_ = (from info in Entity.DOCINFO
1194
                                     where info.DOCUMENT_ID == doc_id
1195
                                     && info.PROJECT_NO == project_no
1196
                                     select info.ID
1197
                                     ).First().ToString();
1198
                #endregion
1199

    
1200
                #region Markup_Info 저장
1201

    
1202
                MARKUP_INFO markup_info = new MARKUP_INFO();
1203
                try
1204
                {
1205
                    markup_info = (from info in Entity.MARKUP_INFO
1206
                                   where info.ID == UserState.MarkupInfoID && info.USER_ID == user_id
1207
                                   select info).FirstOrDefault();
1208
                }
1209
                catch (Exception ex)
1210
                {
1211
                    System.Diagnostics.Debug.WriteLine("KCOM_API - SaveMarkupData Get markup_info: " + ex.ToString());
1212
                    markup_info = null;
1213
                }
1214

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

    
1241
                #region Markup_Info_Version 저장
1242

    
1243
                MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1244

    
1245
                try
1246
                {
1247
                    markup_info_version = (from info in Entity.MARKUP_INFO_VERSION
1248
                                           where info.MARKUPINFO_ID == markup_info.ID
1249
                                           select info).FirstOrDefault();
1250
                }
1251
                catch (Exception ex)
1252
                {
1253
                    System.Diagnostics.Debug.WriteLine("KCOM_API - SaveMarkupData  Get markup_info_version : " + ex.ToString());
1254
                    markup_info_version = null;
1255
                }
1256

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

    
1272
                
1273
                Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == markup_info_version.ID).ToList().ForEach(item =>
1274
                {
1275
                    Entity.MARKUP_DATA.DeleteObject(item);
1276
                });
1277
                Entity.SaveChanges();
1278

    
1279
                try
1280
                {
1281
                    mlmarkup_data.ForEach(value =>
1282
                    {
1283
                        Entity.MARKUP_DATA.AddObject(new MARKUP_DATA
1284
                        {
1285
                            ID = value.ID,
1286
                            DATA = value.DATA,
1287
                            DATA_TYPE = value.DATA_TYPE,
1288
                            PAGENUMBER = value.PAGENUMBER,
1289
                            MARKUPINFO_VERSION_ID = markup_info_version.ID,
1290
                            SYMBOL_ID = value.SYMBOL_ID,
1291
                            //GROUP_ID = value.GROUP_ID
1292
                        });
1293

    
1294
                        
1295
                    });
1296
                    Entity.SaveChanges();
1297

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

    
1302
                        mlmarkup_data.ForEach(value =>
1303
                        {
1304
                            var param = new System.Data.Common.DbParameter[] { new System.Data.SqlClient.SqlParameter { ParameterName = "ID", Value = value.ID } };
1305
                            var result = Entity.ExecuteStoreCommand(sql, param);
1306
                        });
1307

    
1308
                        Entity.SaveChanges();
1309
                    }
1310
                }
1311
                catch (Exception ex)
1312
                {
1313
                    System.Diagnostics.Debug.WriteLine("KCOM_API - SaveMarkupData  set mlmarkup_data : " + ex.ToString());
1314
                    return false;
1315
                }
1316
            }
1317
            return true;
1318
        }
1319

    
1320
        [OperationContract]
1321
        public bool SavePageMarkupData(MarkupInfoItem UserState,int PageNo, string project_no, string doc_id, string user_id, List<MARKUP_DATA> mlmarkup_data)
1322
        {
1323

    
1324
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1325
            using (CIEntities Entity = new CIEntities(sCIConnString))
1326
            {
1327
                #region Docinfo 정보 가져오기
1328

    
1329
                string docinfoid_ = (from info in Entity.DOCINFO
1330
                                     where info.DOCUMENT_ID == doc_id
1331
                                     && info.PROJECT_NO == project_no
1332
                                     select info.ID
1333
                                     ).First().ToString();
1334
                #endregion
1335

    
1336
                #region Markup_Info 저장
1337

    
1338
                MARKUP_INFO markup_info = new MARKUP_INFO();
1339
                try
1340
                {
1341
                    markup_info = (from info in Entity.MARKUP_INFO
1342
                                   where info.ID == UserState.MarkupInfoID && info.USER_ID == user_id
1343
                                   select info).FirstOrDefault();
1344
                }
1345
                catch (Exception ex)
1346
                {
1347
                    System.Diagnostics.Debug.WriteLine("KCOM_API - SavePageMarkupData : " + ex.ToString());
1348

    
1349
                    markup_info = null;
1350
                }
1351

    
1352
                //markup_info가 없을 경우 생성
1353
                if (markup_info == null)
1354
                {
1355
                    //MarkupInfo 저장
1356
                    markup_info = new MARKUP_INFO
1357
                    {
1358
                        ID = UserState.MarkupInfoID,
1359
                        DOCINFO_ID = docinfoid_,
1360
                        USER_ID = user_id,
1361
                        CREATE_TIME = DateTime.Now,
1362
                        CONSOLIDATE = UserState.Consolidate,
1363
                        AVOID_CONSOLIDATE = UserState.AvoidConsolidate,
1364
                        PART_CONSOLIDATE = UserState.PartConsolidate,
1365
                        DESCRIPTION = UserState.Description,
1366
                        UPDATE_TIME = DateTime.Now
1367
                    };
1368
                    Entity.MARKUP_INFO.AddObject(markup_info);
1369
                }
1370
                //markup_info가 있을 경우 업데이트
1371
                else
1372
                {
1373
                    markup_info.UPDATE_TIME = DateTime.Now;
1374
                }
1375
                Entity.SaveChanges();
1376
                #endregion
1377

    
1378
                #region Markup_Info_Version 저장
1379

    
1380
                MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1381

    
1382
                try
1383
                {
1384
                    markup_info_version = (from info in Entity.MARKUP_INFO_VERSION
1385
                                           where info.MARKUPINFO_ID == markup_info.ID
1386
                                           select info).FirstOrDefault();
1387
                }
1388
                catch (Exception ex)
1389
                {
1390
                    System.Diagnostics.Debug.WriteLine("KCOM_API - SavePageMarkupData get markup_info_version : " + ex.ToString());
1391
                    markup_info_version = null;
1392
                }
1393

    
1394
                //markup_info_version 없을 경우 생성
1395
                if (markup_info_version == null)
1396
                {
1397
                    //MarkupInfo_version 저장
1398
                    markup_info_version = new MARKUP_INFO_VERSION()
1399
                    {
1400
                        ID = UserState.MarkupVersionID,
1401
                        MARKUPINFO_ID = markup_info.ID,
1402
                        CREATE_DATE = DateTime.Now
1403
                    };
1404
                    Entity.MARKUP_INFO_VERSION.AddObject(markup_info_version);
1405
                    Entity.SaveChanges();
1406
                }
1407
                #endregion
1408

    
1409

    
1410
                Entity.MARKUP_DATA.Where(data =>  data.PAGENUMBER == PageNo && data.MARKUPINFO_VERSION_ID == markup_info_version.ID).ToList().ForEach(item =>
1411
                {
1412
                    Entity.MARKUP_DATA.DeleteObject(item);
1413
                });
1414
                Entity.SaveChanges();
1415

    
1416
                try
1417
                {
1418
                    mlmarkup_data.ForEach(value =>
1419
                    {
1420
                        Entity.MARKUP_DATA.AddObject(new MARKUP_DATA
1421
                        {
1422
                            ID = value.ID,
1423
                            DATA = value.DATA,
1424
                            DATA_TYPE = value.DATA_TYPE,
1425
                            PAGENUMBER = value.PAGENUMBER,
1426
                            MARKUPINFO_VERSION_ID = markup_info_version.ID,
1427
                            SYMBOL_ID = value.SYMBOL_ID,
1428
                            //GROUP_ID = value.GROUP_ID
1429
                        });
1430
                    });
1431
                    Entity.SaveChanges();
1432
                }
1433
                catch (Exception ex)
1434
                {
1435
                    System.Diagnostics.Debug.WriteLine("KCOM_API - SavePageMarkupData set mlmarkup_data : " + ex.ToString());
1436
                    return false;
1437
                }
1438
            }
1439
            return true;
1440
        }
1441

    
1442
        //[OperationContract]
1443
        //public long AddMarkupDataGroup(MARKUP_DATA_GROUP mARKUP_DATA_GROUP, string ProjectNo)
1444
        //{
1445
        //    try
1446
        //    {
1447
        //        using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1448
        //        {
1449
        //            Entity.AddToMARKUP_DATA_GROUP(mARKUP_DATA_GROUP);
1450
        //            //MARKUP_DATA_GROUP tt = Entity.MARKUP_DATA_GROUP.Where(info => info.ID == id).FirstOrDefault();
1451
        //            Entity.SaveChanges();
1452

    
1453
        //            return Entity.MARKUP_DATA_GROUP.ToList().LastOrDefault().ID;
1454
        //        }
1455
        //    }
1456
        //    catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1457
        //    {
1458
        //        return 0;
1459
        //    }
1460
        //}
1461
        //[OperationContract]
1462
        //public bool UpdateMarkupDataGroup(long Group_ID, string ProjectNo)
1463
        //{
1464
        //    try
1465
        //    {
1466
        //        using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1467
        //        {
1468
        //            var UpdateItem = Entity.MARKUP_DATA_GROUP.Where(info => info.ID == Group_ID).FirstOrDefault();
1469
        //            UpdateItem.STATE = 1;
1470
        //            Entity.SaveChanges();
1471
        //        }
1472
        //    }
1473
        //    catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1474
        //    {
1475
        //        return false;
1476
        //    }
1477
        //    return true;
1478
        //}
1479
        [OperationContract]
1480
        public bool UpdateMarkupData(string CommentID, long Group_ID, string ProjectNo)
1481
        {
1482
            try
1483
            {
1484
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1485
                using (CIEntities Entity = new CIEntities(sCIConnString))
1486
                {
1487
                    var UpdateItem = Entity.MARKUP_DATA.Where(info => info.ID == CommentID).FirstOrDefault();
1488
                    //UpdateItem.GROUP_ID = Group_ID;
1489
                    Entity.SaveChanges();
1490
                }
1491
            }
1492
            catch (Exception ex)
1493
            {
1494
                System.Diagnostics.Debug.WriteLine("KCOM_API - UpdateMarkupData: " + ex.ToString());
1495
                return false;
1496
            }
1497
            return true;
1498
        }
1499

    
1500
        [OperationContract]
1501
        public bool SaveSymbol(SYMBOL_PRIVATE symbol_private)
1502
        {
1503
            try
1504
            {
1505
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1506
                using (KCOMDataModel.DataModel.KCOMEntities uc = new KCOMDataModel.DataModel.KCOMEntities(sConnString))
1507
                {
1508
                    uc.AddToSYMBOL_PRIVATE(symbol_private);
1509
                    uc.SaveChanges();
1510
                }
1511
            }
1512
            catch (Exception ex)
1513
            {
1514
                System.Diagnostics.Debug.WriteLine("KCOM_API - SaveSymbol: " + ex.ToString());
1515
                return false;
1516
            }
1517
            return true;
1518
        }
1519
        [OperationContract]
1520
        public bool AddPublicSymbol(SYMBOL_PUBLIC symbol)
1521
        {
1522
            try
1523
            {
1524
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1525
                using (KCOMDataModel.DataModel.KCOMEntities uc = new KCOMDataModel.DataModel.KCOMEntities(sConnString))
1526
                {
1527
                    uc.AddToSYMBOL_PUBLIC(symbol);
1528
                    uc.SaveChanges();
1529
                }
1530
            }
1531
            catch (Exception ex)
1532
            {
1533
                System.Diagnostics.Debug.WriteLine("KCOM_API - AddPublicSymbol: " + ex.ToString());
1534
                return false;
1535
            }
1536
            return true;
1537
        }
1538
        [OperationContract]
1539
        public bool DeleteSymbol(string symbol_id, int type)
1540
        {
1541
            try
1542
            {
1543
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1544
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
1545
                {
1546
                    if (type == 0)
1547
                    {
1548
                        string delItem_ID = symbol_id;
1549
                        var delitem = Entity.SYMBOL_PRIVATE.Where(data => data.ID == delItem_ID).FirstOrDefault();
1550
                        Entity.SYMBOL_PRIVATE.DeleteObject(delitem);
1551
                        Entity.SaveChanges();
1552
                    }
1553
                    else
1554
                    {
1555
                        string delItem_ID = symbol_id;
1556
                        var delitem = Entity.SYMBOL_PUBLIC.Where(data => data.ID == delItem_ID).FirstOrDefault();
1557
                        Entity.SYMBOL_PUBLIC.DeleteObject(delitem);
1558
                        Entity.SaveChanges();
1559
                    }
1560
                }
1561
            }
1562
            catch (Exception ex)
1563
            {
1564
                System.Diagnostics.Debug.WriteLine("KCOM_API - DeleteSymbol : " + ex.ToString());
1565

    
1566
                return false;
1567
            }
1568
            return true;
1569
        }
1570

    
1571
        [OperationContract]
1572
        public bool RenameSymbol(string symbol_id, string name, int type)
1573
        {
1574
            try
1575
            {
1576
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1577
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
1578
                {
1579
                    if (type == 0)
1580
                    {
1581
                        var UpdateItem = Entity.SYMBOL_PRIVATE.Where(info => info.ID == symbol_id).FirstOrDefault();
1582
                        UpdateItem.NAME = name;
1583
                        Entity.SaveChanges();
1584
                    }
1585
                    else
1586
                    {
1587
                        var UpdateItem = Entity.SYMBOL_PUBLIC.Where(info => info.ID == symbol_id).FirstOrDefault();
1588
                        UpdateItem.NAME = name;
1589
                        Entity.SaveChanges();
1590
                    }
1591
                }
1592
            }
1593
            catch (Exception ex)
1594
            {
1595
                System.Diagnostics.Debug.WriteLine("KCOM_API - RenameSymbol: " + ex.ToString());
1596
                return false;
1597
            }
1598
            return true;
1599
        }
1600

    
1601
        [OperationContract]
1602
        public bool AddCheckListHistory(string project_no, CHECK_LIST_HISTORY Check_History)
1603
        {
1604
            try
1605
            {
1606
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1607
                using (CIEntities Entity = new CIEntities(sCIConnString))
1608
                {
1609
                    Entity.CHECK_LIST_HISTORY.AddObject(Check_History);
1610
                    Entity.SaveChanges();  
1611
                }
1612
            }
1613
            catch (Exception ex)
1614
            {
1615
                System.Diagnostics.Debug.WriteLine("KCOM_API - AddCheckListHistory: " + ex.ToString());
1616
                return false;
1617
            }
1618
            return true;
1619
        }
1620
        [OperationContract]
1621
        public bool SaveCheckListHistory(string project_no, string rev, CHECK_LIST_HISTORY Check_History)
1622
        {
1623
            try
1624
            {
1625
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1626
                using (CIEntities Entity = new CIEntities(sCIConnString))
1627
                {
1628
                    var item = Entity.CHECK_LIST_HISTORY.Where(info => info.REVISION == rev).FirstOrDefault();
1629
                    item = Check_History;
1630
                    Entity.SaveChanges();
1631
                }
1632
            }
1633
            catch (Exception ex)
1634
            {
1635
                System.Diagnostics.Debug.WriteLine("KCOM_API - SaveCheckListHistory: " + ex.ToString());
1636
                return false;
1637
            }
1638
            return true;
1639
        }
1640
        [OperationContract]
1641
        public bool SaveCheckList(string project_no, string _id, CHECK_LIST Check_value)
1642
        {
1643
            try
1644
            {
1645
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1646
                using (CIEntities Entity = new CIEntities(sCIConnString))
1647
                {
1648
                    var item = Entity.CHECK_LIST.Where(info => info.ID == _id).FirstOrDefault();
1649
                    item.TODOLIST = Check_value.TODOLIST;
1650
                    item.REMARK = Check_value.REMARK;
1651
                    item.STATUS = Check_value.STATUS;
1652
                    item.VENDOR = Check_value.VENDOR;
1653
                    item.REPLY = Check_value.REPLY;
1654
                    item.IMAGE_URL = Check_value.IMAGE_URL;
1655
                    item.IMAGE_ANCHOR = Check_value.IMAGE_ANCHOR;
1656
                    item.UPDATE_TIME = Check_value.UPDATE_TIME;
1657
                    if(Check_value.STATUS == "False")
1658
                    {
1659
                        item.STATUS_DESC_OPEN = Check_value.STATUS_DESC_OPEN;
1660
                    }
1661
                    else
1662
                    {
1663
                        item.STATUS_DESC_CLOSE = Check_value.STATUS_DESC_CLOSE;
1664
                    }                     
1665
                    Entity.SaveChanges();
1666
                }
1667
            }
1668
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1669
                return false;
1670
            }
1671
            return true;
1672
        }
1673
        [OperationContract]
1674
        public bool AddCheckList(string project_no, CHECK_LIST Check_value)
1675
        {
1676
            try
1677
            {
1678
               
1679
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1680
                using (CIEntities Entity = new CIEntities(sCIConnString))
1681
                {
1682
                    Entity.CHECK_LIST.AddObject(Check_value);
1683
                    Entity.SaveChanges();
1684
                }
1685
            }
1686
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1687
                return false;
1688
            }
1689
            return true;
1690
        }
1691

    
1692
        [OperationContract]
1693
        public CHECK_LIST GetCheckList(string project_no, string _id)
1694
        {
1695
            CHECK_LIST Check_value = new CHECK_LIST();
1696
            try
1697
            {
1698
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1699
                using (CIEntities Entity = new CIEntities(sCIConnString))
1700
                {
1701
                    Check_value = Entity.CHECK_LIST.Where(info => info.ID == _id).FirstOrDefault();
1702
                }
1703
            }
1704
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1705
                return null;
1706
            }
1707
            return Check_value;
1708
        }
1709
        [OperationContract]
1710
        public List<CHECK_LIST> GetUserCheckList(string project_no, string user_id, string doc_no)
1711
        {
1712
            List<CHECK_LIST> list = new List<CHECK_LIST>();
1713
            try
1714
            {
1715
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1716
                using (CIEntities Entity = new CIEntities(sCIConnString))
1717
                {
1718
                    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();
1719
                }
1720
            }
1721
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1722
                return null;
1723
            }
1724
            return list;
1725
        }
1726
        [OperationContract]
1727
        public List<CHECK_LIST_HISTORY> GetCheckListHistory(string project_no, string _id)
1728
        {
1729
            List<CHECK_LIST_HISTORY> history = new List<CHECK_LIST_HISTORY>();
1730
            try
1731
            {
1732
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1733
                using (CIEntities Entity = new CIEntities(sCIConnString))
1734
                {
1735
                    history = Entity.CHECK_LIST_HISTORY.Where(data => data.CHECKLIST_ID == _id).ToList();
1736
                }
1737
            }
1738
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1739
                return null;
1740
            }
1741
            return history;
1742
        }
1743
        [OperationContract]
1744
        public CHECK_LIST_HISTORY GetCheckListHistoryFirstOrDefault(string project_no, string checklist_id, string rev)
1745
        {
1746
            CHECK_LIST_HISTORY Check_Item = new CHECK_LIST_HISTORY();
1747
            try
1748
            {
1749
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1750
                using (CIEntities Entity = new CIEntities(sCIConnString))
1751
                {   
1752
                    Check_Item = Entity.CHECK_LIST_HISTORY.Where(info => info.CHECKLIST_ID == checklist_id && info.REVISION == rev).FirstOrDefault();
1753
                }
1754
            }
1755
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1756
                return null;
1757
            }
1758
            return Check_Item;
1759
        }
1760
        [OperationContract]
1761
        public bool SavePageAngle(string project_no, List<DOCPAGE> _mldocpage)
1762
        {
1763
            try
1764
            {
1765
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1766
                using (CIEntities Entity = new CIEntities(sCIConnString))
1767
                {
1768
                    KCOMDataModel.DataModel.DOCPAGE _docpage = new KCOMDataModel.DataModel.DOCPAGE();
1769
                    _mldocpage.ForEach(data =>
1770
                    {
1771
                        _docpage = (from info in Entity.DOCPAGE
1772
                                    where info.ID == data.ID
1773
                                    select info).FirstOrDefault();
1774

    
1775
                        if (_docpage.PAGE_ANGLE != data.PAGE_ANGLE)
1776
                        {
1777
                            _docpage.PAGE_ANGLE = data.PAGE_ANGLE;
1778
                        }
1779
                    });
1780

    
1781
                    Entity.SaveChanges();
1782
                }
1783
            }
1784
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1785
                return false;
1786
            }
1787
            return true;
1788
        }
1789

    
1790
        [OperationContract]
1791
        public MARKUP_INFO GetMarkupInfo(string project_no, string _id)
1792
        {
1793
            MARKUP_INFO markupInfo = new MARKUP_INFO();
1794

    
1795
            try
1796
            {
1797
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1798
                using (CIEntities Entity = new CIEntities(sCIConnString))
1799
                {
1800
                    markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1801
                }
1802
            }
1803
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1804
                return null;
1805
            }
1806
            return markupInfo;
1807
        }
1808

    
1809
        [OperationContract]
1810
        public List<string> GetMarkupDataListperPage(string project_no, string _markupinfoid, int _pageNo)
1811
        {
1812
            List<string> markupdata = new List<string>();
1813
            MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1814
            try
1815
            {
1816
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1817
                using (CIEntities Entity = new CIEntities(sCIConnString))
1818
                {
1819
                    markup_info_version = (from version in Entity.MARKUP_INFO_VERSION
1820
                                           where version.MARKUPINFO_ID == _markupinfoid
1821
                                           orderby version.CREATE_DATE descending
1822
                                           select version).First();
1823
                    markupdata = (from data in Entity.MARKUP_DATA
1824
                                  where data.MARKUPINFO_VERSION_ID == markup_info_version.ID && data.PAGENUMBER == _pageNo
1825
                                  select data.DATA).ToList();
1826
                }
1827
            }
1828
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1829
                return null;
1830
            }
1831
            return markupdata;
1832
        }
1833

    
1834
        [OperationContract]
1835
        public bool AddMarkupInfo(string project_no, MARKUP_INFO value)
1836
        {
1837
            try
1838
            {
1839
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1840
                using (CIEntities Entity = new CIEntities(sCIConnString))
1841
                {
1842
                    Entity.MARKUP_INFO.AddObject(value);
1843
                    Entity.SaveChanges();
1844
                }
1845
            }
1846
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1847
                return false;
1848
            }
1849
            return true;
1850
        }
1851

    
1852
        [OperationContract]
1853
        public bool AddMarkupInfoVersion(string project_no, MARKUP_INFO_VERSION value)
1854
        {
1855
            try
1856
            {
1857
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1858
                using (CIEntities Entity = new CIEntities(sCIConnString))
1859
                {
1860
                    Entity.MARKUP_INFO_VERSION.AddObject(value);
1861
                    Entity.SaveChanges();
1862
                }
1863
            }
1864
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1865
                return false;
1866
            }
1867
            return true;
1868
        }
1869

    
1870
        [OperationContract]
1871
        public bool AddMarkupData(string project_no, MARKUP_DATA value)
1872
        {
1873
            try
1874
            {
1875
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1876
                using (CIEntities Entity = new CIEntities(sCIConnString))
1877
                {
1878
                    Entity.MARKUP_DATA.AddObject(value);
1879
                    Entity.SaveChanges();
1880
                }
1881
            }
1882
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1883
                return false;
1884
            }
1885
            return true;
1886
        }
1887

    
1888
        [OperationContract]
1889
        public bool AvoidMarkupInfo(string project_no, string _doc_id)
1890
        {
1891
            try
1892
            {
1893
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1894
                using (CIEntities Entity = new CIEntities(sCIConnString))
1895
                {
1896
                    var item = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1897
                    item.AVOID_CONSOLIDATE = 1;
1898
                    Entity.SaveChanges();
1899
                }
1900
            }
1901
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1902
                return false;
1903
            }
1904
            return true;
1905
        }
1906

    
1907
        [OperationContract]
1908
        public bool SaveMarkupInfo(string project_no, string _id, MARKUP_INFO value)
1909
        {
1910
            try
1911
            {
1912
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1913
                using (CIEntities Entity = new CIEntities(sCIConnString))
1914
                {
1915
                    var item = Entity.MARKUP_INFO.Where(info => info.ID == _id).FirstOrDefault();
1916
                    item = value;                    
1917
                    Entity.SaveChanges();
1918
                }
1919
            }
1920
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1921
                return false;
1922
            }
1923
            return true;
1924
        }
1925
        [OperationContract]
1926
        public List<MARKUP_DATA> GetMarkupDataList(string project_no, string _versionid)
1927
        {
1928
            List<MARKUP_DATA> mlresult = new List<MARKUP_DATA>();
1929

    
1930
            try
1931
            {
1932
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1933
                using (CIEntities Entity = new CIEntities(sCIConnString))
1934
                {
1935
                    mlresult = Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == _versionid).ToList();
1936
                }
1937
            }
1938
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1939
                return null;
1940
            }
1941
            return mlresult;
1942
        }
1943

    
1944
        [OperationContract]
1945
        public bool Consolidate(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems)
1946
        {
1947
            try
1948
            {
1949
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
1950
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1951
                using (CIEntities Entity = new CIEntities(sCIConnString))
1952
                {
1953
                    var markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id && entity.CONSOLIDATE == 1).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1954
                    if (markupInfo != null)
1955
                    {
1956
                        markupInfo.AVOID_CONSOLIDATE = 1;
1957
                    }
1958

    
1959
                    foreach (MarkupInfoItem item in markupInfoItems)
1960
                    {
1961
                        Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == item.MarkupVersionID).ToList().ForEach(d =>
1962
                        {
1963
                            instanceDataSet.Add(d);
1964
                        });
1965
                    }
1966

    
1967
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
1968
                    info.ID = shortGuid();
1969
                    info.CONSOLIDATE = 1;
1970
                    info.CREATE_TIME = DateTime.Now;
1971
                    info.DOCINFO_ID = _doc_id;
1972
                    info.UPDATE_TIME = DateTime.Now;
1973
                    info.USER_ID = _user_id;
1974
                    info.AVOID_CONSOLIDATE = 0;
1975

    
1976
                    Entity.MARKUP_INFO.AddObject(info);
1977
                    Entity.SaveChanges();
1978

    
1979

    
1980
                    KCOMDataModel.DataModel.MARKUP_INFO_VERSION info2 = new KCOMDataModel.DataModel.MARKUP_INFO_VERSION
1981
                    {
1982
                        ID = shortGuid(),
1983
                        CREATE_DATE = DateTime.Now,
1984
                        MARKUP_INFO = info,
1985
                    };
1986
                    Entity.SaveChanges();
1987

    
1988
                    foreach (var item in instanceDataSet)
1989
                    {
1990
                        Entity.MARKUP_DATA.AddObject(new KCOMDataModel.DataModel.MARKUP_DATA
1991
                        {
1992
                            ID = shortGuid(),
1993
                            DATA = item.DATA,
1994
                            DATA_TYPE = item.DATA_TYPE,
1995
                            PAGENUMBER = item.PAGENUMBER,
1996
                            MARKUP_INFO_VERSION = info2,
1997
                            SYMBOL_ID = item.SYMBOL_ID,
1998
                            //GROUP_ID = item.GROUP_ID
1999
                        });
2000
                    }
2001
                    Entity.SaveChanges();
2002

    
2003

    
2004
                }
2005
            }
2006
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2007
                return false;
2008
            }
2009
            return true;
2010
        }
2011

    
2012

    
2013
        [OperationContract]
2014
        public FinalPDFResult ConsolidateMergedPDF(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems, string ProjectNo, string DocInfoID, string CreateUserID)
2015
        {
2016
            bool consolidate = false;
2017
            try
2018
            {
2019
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
2020
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2021
                using (CIEntities Entity = new CIEntities(sCIConnString))
2022
                {
2023
                    var markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
2024
                    if (markupInfo.CONSOLIDATE == 1)
2025
                    {
2026
                        markupInfo.AVOID_CONSOLIDATE = 1;
2027
                    }
2028

    
2029
                    foreach (MarkupInfoItem item in markupInfoItems)
2030
                    {
2031
                        Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == item.MarkupVersionID).ToList().ForEach(d =>
2032
                        {
2033
                            instanceDataSet.Add(d);
2034
                        });
2035
                    }
2036

    
2037
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
2038
                    info.ID = shortGuid();
2039
                    info.CONSOLIDATE = 1;
2040
                    info.CREATE_TIME = DateTime.Now;
2041
                    info.DOCINFO_ID = _doc_id;
2042
                    info.UPDATE_TIME = DateTime.Now;
2043
                    info.USER_ID = _user_id;
2044
                    info.AVOID_CONSOLIDATE = 0;
2045

    
2046
                    Entity.MARKUP_INFO.AddObject(info);
2047
                    Entity.SaveChanges();
2048

    
2049

    
2050
                    KCOMDataModel.DataModel.MARKUP_INFO_VERSION info2 = new KCOMDataModel.DataModel.MARKUP_INFO_VERSION
2051
                    {
2052
                        ID = shortGuid(),
2053
                        CREATE_DATE = DateTime.Now,
2054
                        MARKUP_INFO = info,
2055
                    };
2056
                    Entity.SaveChanges();
2057

    
2058
                    foreach (var item in instanceDataSet)
2059
                    {
2060
                        Entity.MARKUP_DATA.AddObject(new KCOMDataModel.DataModel.MARKUP_DATA
2061
                        {
2062
                            ID = shortGuid(),
2063
                            DATA = item.DATA,
2064
                            DATA_TYPE = item.DATA_TYPE,
2065
                            PAGENUMBER = item.PAGENUMBER,
2066
                            MARKUP_INFO_VERSION = info2,
2067
                            SYMBOL_ID = item.SYMBOL_ID,
2068
                            //GROUP_ID = item.GROUP_ID
2069
                        });
2070
                    }
2071
                    Entity.SaveChanges();
2072

    
2073

    
2074
                }
2075
                consolidate = true;
2076
            }
2077
            catch (Exception ex)
2078
            {
2079
                System.Diagnostics.Debug.WriteLine(ex);
2080
                consolidate = false;
2081
            }
2082

    
2083
            FinalPDFResult _result = new FinalPDFResult();
2084
            if (consolidate == true)
2085
            {
2086
                RemFinalPDFObject remObj = null;
2087
                try
2088
                {
2089
                    string _finalID = shortGuid();
2090
                    int _DocTotalPages = -1;
2091
                    string docItemId;
2092

    
2093
                    string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2094
                    using (CIEntities _ci = new CIEntities(sCIConnString))
2095
                    {
2096
                        var _doc = _ci.DOCINFO.Where(info => info.ID == DocInfoID);
2097

    
2098
                        if (_doc.Count() > 0)
2099
                        {
2100
                            _DocTotalPages = _doc.First().PAGE_COUNT;
2101
                            docItemId = _doc.First().DOCUMENT_ID;
2102
                        }
2103
                        else
2104
                        {
2105
                            _result.Status = FinalStatus.Error;
2106
                            _result.Exception = "페이지 정보를 가져올 수 없습니다.";
2107
                            return _result;
2108
                        }
2109
                    }
2110

    
2111
                    var Items = GetMarkupInfoItems(ProjectNo, DocInfoID);
2112
                    if (_DocTotalPages > 0)
2113
                    {
2114
                        var item2 = Items.Cast<MarkupInfoItem>().Where(d => d.Consolidate == 1 && d.AvoidConsolidate == 0).FirstOrDefault();
2115
                        FINAL_PDF fm = new FINAL_PDF()
2116
                        {
2117
                            ID = _finalID,
2118
                            PROJECT_NO = ProjectNo,
2119
                            DOCINFO_ID = DocInfoID,
2120
                            DOCUMENT_ID = docItemId,
2121
                            MARKUPINFO_ID = item2.MarkupInfoID,
2122
                            CREATE_USER_ID = CreateUserID,
2123
                            TOTAL_PAGE = _DocTotalPages,
2124
                            CREATE_DATETIME = DateTime.Now,
2125
                            STATUS = (int)IFinalPDF.FinalStatus.Insert
2126
                        };
2127

    
2128
                        string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2129
                        using (KCOMEntities _entity = new KCOMEntities(sConnString))
2130
                        {
2131
                            _entity.AddToFINAL_PDF(fm);
2132
                            _entity.SaveChanges(System.Data.Objects.SaveOptions.AcceptAllChangesAfterSave);
2133
                        };
2134

    
2135
                        System.Runtime.Remoting.Channels.IChannel _ch = System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp");
2136
                        if (_ch == null)
2137
                        {
2138
                            chan = new TcpChannel();
2139
                            _ChanID = chan.ChannelName;
2140
                            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan, false);
2141
                            // Create an instance of the remote object
2142

    
2143
                            using (KCOMEntities ec = new KCOMEntities(sConnString))
2144
                            {
2145

    
2146
                                //remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
2147
                                //                          "tcp://localhost:9092/remFinalPDF");
2148
                                remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
2149
                                                          //"tcp://192.168.0.67:9092/remFinalPDF");
2150
                                                          "tcp://192.168.0.67:9092/remFinalPDF");
2151
                            }
2152

    
2153
                            //"tcp://localhost:8080/remFinalPDF");
2154

    
2155
                            _result = remObj.SetFinalPDF(ProjectNo, _finalID);
2156
                            _result.FinalID = _finalID;
2157
                            _result.Status = FinalStatus.Success;
2158

    
2159
                            //MarkupToPDF.MarkupToPDF fa = new MarkupToPDF.MarkupToPDF();
2160
                            //fa.MakeFinalPDF(fm);
2161
                        }
2162
                        else
2163
                        {
2164
                            _ChanID = _ch.ChannelName;
2165
                        }
2166
                    }
2167
                }
2168
                catch (Exception ex)
2169
                {
2170
                    _result.Status = FinalStatus.Error;
2171

    
2172
                    if (ex.GetType() == typeof(System.Net.Sockets.SocketException))
2173
                        _result.Exception = "Final Server Not Connection";
2174
                }
2175
                finally
2176
                {
2177
                    remObj = null;
2178
                    if (System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp") != null)
2179
                        System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(chan);
2180

    
2181
                    GC.Collect(2);
2182
                }
2183
            }
2184
            return _result;
2185
        }
2186
        [OperationContract]
2187
        public bool TeamConsolidate(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems)
2188
        {
2189
            try
2190
            {
2191
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
2192
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2193
                using (CIEntities Entity = new CIEntities(sCIConnString))
2194
                {
2195
                    var members = GetMemberQuery(Entity, _user_id);
2196

    
2197
                    string user_dept = "";
2198

    
2199
                    if(members.Count() > 0)
2200
                    {
2201
                        user_dept = members.First().DEPARTMENT;
2202
                    }
2203
                    
2204
                    var markupInfos = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id && entity.PART_CONSOLIDATE == 1)
2205
                                        .OrderByDescending(j => j.CREATE_TIME).ToList();
2206

    
2207
                    foreach (var markupinfo in markupInfos)
2208
                    {
2209
                        string markupdept = "";
2210

    
2211
                        var markupMembers = GetMemberQuery(Entity, markupinfo.USER_ID);
2212

    
2213
                        if (markupMembers.Count() > 0)
2214
                        {
2215
                            markupdept = markupMembers.First().DEPARTMENT;
2216
                        }
2217

    
2218
                        if (user_dept == markupdept)
2219
                        {
2220
                            markupinfo.AVOID_CONSOLIDATE = 1;
2221
                        }
2222
                    }
2223

    
2224
                    foreach (MarkupInfoItem item in markupInfoItems)
2225
                    {
2226
                        Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == item.MarkupVersionID).ToList().ForEach(d =>
2227
                        {
2228
                            instanceDataSet.Add(d);
2229
                        });
2230
                    }
2231

    
2232
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
2233
                    info.ID = shortGuid();
2234
                    info.PART_CONSOLIDATE = 1;
2235
                    info.CREATE_TIME = DateTime.Now;
2236
                    info.DOCINFO_ID = _doc_id;
2237
                    info.UPDATE_TIME = DateTime.Now;
2238
                    info.USER_ID = _user_id;
2239
                    info.AVOID_CONSOLIDATE = 0;
2240

    
2241
                    Entity.MARKUP_INFO.AddObject(info);
2242
                    Entity.SaveChanges();
2243

    
2244

    
2245
                    KCOMDataModel.DataModel.MARKUP_INFO_VERSION info2 = new KCOMDataModel.DataModel.MARKUP_INFO_VERSION
2246
                    {
2247
                        ID = shortGuid(),
2248
                        CREATE_DATE = DateTime.Now,
2249
                        MARKUP_INFO = info,
2250
                    };
2251
                    Entity.SaveChanges();
2252

    
2253
                    foreach (var item in instanceDataSet)
2254
                    {
2255
                        Entity.MARKUP_DATA.AddObject(new KCOMDataModel.DataModel.MARKUP_DATA
2256
                        {
2257
                            ID = shortGuid(),
2258
                            DATA = item.DATA,
2259
                            DATA_TYPE = item.DATA_TYPE,
2260
                            PAGENUMBER = item.PAGENUMBER,
2261
                            MARKUP_INFO_VERSION = info2,
2262
                            SYMBOL_ID = item.SYMBOL_ID,
2263
                            //GROUP_ID = item.GROUP_ID
2264
                        });
2265
                    }
2266
                    Entity.SaveChanges();
2267

    
2268

    
2269
                }
2270
            }
2271
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2272
                return false;
2273
            }
2274
            return true;
2275
        }
2276

    
2277
        [OperationContract]
2278
        [ServiceKnownType(typeof(MEMBER))]
2279
        public MEMBER GetMember(string project_no, string user_id)
2280
        {
2281
            MEMBER rstmember = null;
2282
            try
2283
            {
2284
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2285
                using (CIEntities Entity = new CIEntities(sCIConnString))
2286
                {
2287
                    var members = GetMemberQuery(Entity, user_id);
2288

    
2289
                    if(members.Count() > 0)
2290
                    {
2291
                        rstmember = members.First();
2292
                    }
2293
                }
2294
            }
2295
            catch (Exception ex)
2296
            {
2297
                return null;
2298
            }
2299
            return rstmember;
2300
        }
2301

    
2302
        private  List<MEMBER> GetMemberQuery(System.Data.Objects.ObjectContext context, string UserID)
2303
        {
2304
            List<MEMBER> result = new List<MEMBER>();
2305

    
2306
            try
2307
            {
2308
                string query = "SELECT members.ID,members.NAME,members.DEPARTMENT FROM CIEntities.MEMBER as members where members.ID = @userId";
2309

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

    
2312
                System.Data.Objects.ObjectQuery<System.Data.Common.DbDataRecord> memberQuery
2313
                              = context.CreateQuery<System.Data.Common.DbDataRecord>(query, param);
2314

    
2315
                if (memberQuery.Count() > 0)
2316
                {
2317
                    foreach (var dataRecord in memberQuery)
2318
                    {
2319
                        MEMBER member = new MEMBER();
2320

    
2321
                        string userName = dataRecord["NAME"]?.ToString().Trim();
2322
                        string ID = dataRecord["ID"]?.ToString().Trim();
2323
                        string depatment = dataRecord["DEPARTMENT"]?.ToString().Trim();
2324

    
2325
                        member.NAME = userName;
2326
                        member.ID = ID;
2327
                        member.DEPARTMENT = depatment;
2328

    
2329
                        result.Add(member);
2330
                    }
2331
                }
2332
            }
2333
            catch (Exception ex)
2334
            {
2335
                throw new Exception("GetMember(System.Data.Objects.ObjectContext context, string UserID) " , ex);
2336
            }
2337

    
2338
            return result;
2339
        }
2340

    
2341
        [WebMethod]
2342
        [OperationContract]
2343
        public List<SYMBOL_PRIVATE> GetSymbolList(string user_id)
2344
        {
2345
            List<SYMBOL_PRIVATE> Custom_List = new List<SYMBOL_PRIVATE>();
2346
            try
2347
            {
2348
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2349
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2350
                {
2351
                    Custom_List = Entity.SYMBOL_PRIVATE.Where(data => data.MEMBER_USER_ID == user_id).ToList();
2352
                }
2353
            }
2354
            catch (Exception ex)
2355
            {
2356
                return null;
2357
            }
2358
            return Custom_List;
2359
        }
2360
        [OperationContract]
2361
        public List<string> GetPublicSymbolDeptList()
2362
        {
2363
            List<string> Custom_List = new List<string>();
2364
            try
2365
            {
2366
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2367
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2368
                {
2369
                    Custom_List = Entity.SYMBOL_PUBLIC.Select(data => data.DEPARTMENT).Distinct().ToList();
2370
                }
2371
            }
2372
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2373
                return null;
2374
            }
2375
            return Custom_List;
2376
        }
2377
        [OperationContract]
2378
        public List<SYMBOL_PUBLIC> GetPublicSymbolList(string dept)
2379
        {
2380
            List<SYMBOL_PUBLIC> Custom_List = new List<SYMBOL_PUBLIC>();
2381
            try
2382
            {
2383
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2384
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2385
                {
2386
                    if(!string.IsNullOrEmpty(dept))
2387
                    {
2388
                        Custom_List = Entity.SYMBOL_PUBLIC.Where(data => data.DEPARTMENT == dept).ToList();
2389
                    }
2390
                    else
2391
                    {
2392
                        Custom_List = Entity.SYMBOL_PUBLIC.ToList();
2393
                    }
2394
                    
2395
                }
2396
            }
2397
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2398
                return null;
2399
            }
2400
            return Custom_List;
2401
        }
2402

    
2403
        /// <summary>
2404
        /// 
2405
        /// </summary>
2406
        /// <param name="id">symbol id</param>
2407
        /// <param name="type"> 0 : PRIVATE, 1 : PUBLIC</param>
2408
        /// <returns></returns>
2409
        [OperationContract]
2410
        public string GetSymbolData(string id, int type)
2411
        {
2412
            string result;
2413
            try
2414
            {
2415
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2416
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2417
                {
2418
                    if(type == 0)
2419
                    {
2420
                        result = Entity.SYMBOL_PRIVATE.Where(data => data.ID == id).FirstOrDefault().DATA;
2421
                    }
2422
                    else
2423
                    {
2424
                        result = Entity.SYMBOL_PUBLIC.Where(data => data.ID == id).FirstOrDefault().DATA;
2425
                    }
2426
                }
2427
            }
2428
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2429
                return null;
2430
            }
2431
            return result;
2432
        }
2433
        [OperationContract]
2434
        public string GetSymbolImageURL(string id, int type)
2435
        {
2436
            string result;
2437
            try
2438
            {
2439
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2440
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2441
                {
2442
                    if (type == 0)
2443
                    {
2444
                        result = Entity.SYMBOL_PRIVATE.Where(data => data.ID == id).FirstOrDefault().IMAGE_URL;
2445
                    }
2446
                    else
2447
                    {
2448
                        result = Entity.SYMBOL_PUBLIC.Where(data => data.ID == id).FirstOrDefault().IMAGE_URL;
2449
                    }
2450
                }
2451
            }
2452
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2453
                return null;
2454
            }
2455
            return result;
2456
        }
2457
        [OperationContract]
2458
        public string GetSignData(string project_no, string user_id)
2459
        {
2460
            string result = null;
2461
            try
2462
            {
2463
                string ifsign = getEnsembleSign(user_id);
2464
                if (string.IsNullOrEmpty(ifsign))
2465
                {
2466
                    string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2467
                    var ModelWFConnectionString = sCIConnString;
2468
                    if (null != ModelWFConnectionString)
2469
                    {
2470
                        using (CIEntities entity = new CIEntities(ModelWFConnectionString))
2471
                        {
2472
                            var _sign = entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == user_id);
2473
                            if (_sign.Count() > 0)
2474
                            {
2475
                                result = _sign.First().SIGN_STR;
2476
                            }
2477
                            else
2478
                            {
2479
                                return null;
2480
                            }
2481
                        }
2482
                    }
2483
                }
2484
                else
2485
                {
2486
                    result = ifsign;
2487
                }
2488

    
2489
            }
2490
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2491
                return null;
2492
            }
2493
            return result;
2494
        }
2495

    
2496
        [OperationContract]        
2497
        public string GetProjectName(string project_no)
2498
        {
2499
            string result = null;
2500

    
2501
            try
2502
            {
2503
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2504
                using (KCOMDataModel.DataModel.KCOMEntities Entity = new KCOMDataModel.DataModel.KCOMEntities(sConnString))
2505
                {
2506
                    result = Entity.RUN_PROJECTS.Where(i => i.PROJECT_NO == project_no).FirstOrDefault().PROJECT_NAME.ToString();
2507
                }
2508
            }
2509
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2510
                return null;
2511
            }
2512
            return result;
2513
        }
2514

    
2515
        [OperationContract]
2516
        public List<DOCUMENT_ITEM> GetPreRevSelect(string project_no, string doc_no, string current_rev)
2517
        {
2518
            List<DOCUMENT_ITEM> result = new List<DOCUMENT_ITEM>();
2519
            
2520
            try
2521
            {
2522
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2523
                using (CIEntities Entity = new CIEntities(sCIConnString))
2524
                {
2525
                    result = Entity.DOCUMENT_ITEM.Where(i => i.PROJECT_NO == project_no
2526
                    && i.DOCUMENT_NO == doc_no
2527
                    && i.REVISION != current_rev).OrderByDescending(i => i.GROUP_NO).ToList();
2528
                }
2529
            }
2530
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2531
                return null;
2532
            }
2533
            return result;
2534
        }
2535

    
2536
        [OperationContract]
2537
        public DOCINFO GetDocInfoOneSelect(string project_no, string doc_id)
2538
        {
2539
            DOCINFO docinfo = null;
2540

    
2541
            try
2542
            {
2543
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2544
                using (CIEntities Entity = new CIEntities(sCIConnString))
2545
                {
2546
                    docinfo = (from info in Entity.DOCINFO
2547
                              where info.DOCUMENT_ID == doc_id
2548
                              && info.PROJECT_NO == project_no
2549
                              select info).First();
2550
                }
2551
            }
2552
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2553
                return null;
2554
            }
2555
            return docinfo;
2556
        }
2557

    
2558
        [OperationContract]
2559
        public List<MarkupInfoItem> GetPrintDocItemList(string project_no, string doc_id, List<MarkupInfoItem> _markupInfoList)
2560
        {
2561
            MarkupInfoItem _result = null;
2562
            List<MarkupInfoItem> markupinfo = new List<MarkupInfoItem>();
2563
            try
2564
            {
2565
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2566
                using (CIEntities Entity = new CIEntities(sCIConnString))
2567
                {
2568
                    var docitem = (from info in Entity.DOCINFO
2569
                               where info.DOCUMENT_ID == doc_id
2570
                               && info.PROJECT_NO == project_no
2571
                               select info).First();
2572

    
2573
                    foreach (MARKUP_INFO markinfo in docitem.MARKUP_INFO)
2574
                    {
2575
                        var members = GetMemberQuery(Entity, markinfo.USER_ID);
2576

    
2577
                        MEMBER member = new MEMBER();
2578

    
2579
                        if (members.Count() > 0)
2580
                        {
2581
                            member = members.First();
2582
                        }
2583

    
2584
                        string displaycolor = null;
2585

    
2586
                        try
2587
                        {
2588
                            displaycolor = _markupInfoList.Where(info => info.MarkupInfoID == markinfo.ID).First().DisplayColor;
2589
                        }
2590
                        catch (Exception ex)
2591
                        {
2592
                            System.Diagnostics.Debug.WriteLine("KCOM_API - GetPrintDocItemList displaycolor : " + ex.ToString());
2593

    
2594
                            displaycolor = "#FFFFFF";
2595
                        }
2596
                        
2597
                        _result = new MarkupInfoItem
2598
                        {
2599
                            MarkupInfoID = markinfo.ID,
2600
                            Consolidate = markinfo.CONSOLIDATE,
2601
                            CreateTime = markinfo.UPDATE_TIME.HasValue ? markinfo.UPDATE_TIME.Value : markinfo.CREATE_TIME,
2602
                            DisplayColor = displaycolor,
2603
                            UserID = markinfo.USER_ID,
2604
                            UserName = member.NAME,
2605
                            Depatment = member.DEPARTMENT,
2606
                        };
2607

    
2608
                        _result.MarkupList = new List<IKCOM.MarkupItem>();
2609
                        var markup_Version = markinfo.MARKUP_INFO_VERSION.OrderByDescending(p => p.CREATE_DATE).First();
2610

    
2611
                        foreach (MARKUP_DATA markdata in markup_Version.MARKUP_DATA)
2612
                        {
2613
                            MarkupItem markitem = new MarkupItem()
2614
                            {
2615
                                ID = markdata.ID,
2616
                                PageNumber = markdata.PAGENUMBER,
2617
                            };
2618
                            _result.MarkupList.Add(markitem);
2619
                        }
2620

    
2621
                        _result.PageCount = _result.MarkupList.GroupBy(i => i.PageNumber).Count();
2622

    
2623
                        markupinfo.Add(_result);
2624
                    }
2625
                }
2626
            }
2627
            catch (Exception ex)
2628
            {
2629
                return null;
2630
            }
2631
            return markupinfo;
2632
        }
2633

    
2634
        [OperationContract]
2635
        public bool AddMessage(string project_no, TALK value)
2636
        {
2637
            try
2638
            {
2639
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2640
                using (CIEntities entity = new CIEntities(sCIConnString))
2641
                {                    
2642
                    entity.TALK.AddObject(value);
2643
                    entity.SaveChanges();
2644
                }
2645
            }
2646
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2647
                return false;
2648
            }
2649
            return true;
2650
        }
2651

    
2652
        [OperationContract]
2653
        public List<TALK> GetMessage(string project_no, string doc_id)
2654
        {
2655
            List<TALK> result = new List<TALK>();
2656
            try
2657
            {
2658
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2659
                using (CIEntities entity = new CIEntities(sCIConnString))
2660
                {
2661
                    result = entity.TALK.Where(data => data.DOCUMENT_ID == doc_id).ToList();                        
2662
                }
2663
            }
2664
            catch (Exception ex)
2665
            {
2666
                return result;
2667
            }
2668
            return result;
2669
        }
2670

    
2671

    
2672
        #region Legacy System I/F
2673
        /// <summary>
2674
        /// Ensemble+ Sign Data Return
2675
        /// </summary>
2676
        /// <param name="user_id"></param>
2677
        /// <returns></returns>
2678
        private string getEnsembleSign(string user_id)
2679
        {
2680
            string result = null;
2681
            string soapurl = string.Empty;
2682

    
2683
            try
2684
            {
2685
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2686
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2687
                {
2688
                    var item = Entity.PROPERTIES.Where(d => d.TYPE == "UpLoadServiceUrl").FirstOrDefault();
2689

    
2690
                    if (item != null)
2691
                    {
2692
                        soapurl = item.VALUE;
2693

    
2694
                        WebClient webClient = new WebClient();
2695
                        string data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ens=\"http://EnsemblePlus.Webservice\"> <soapenv:Header/> <soapenv:Body> <ens:checkoutSignImage>"
2696
                            + "<ens:sUserNo>" + user_id + "</ens:sUserNo>"
2697
                            + "</ens:checkoutSignImage> </soapenv:Body></soapenv:Envelope>";
2698
                        webClient.Headers.Add(HttpRequestHeader.ContentType, "text/xml");
2699
                        webClient.Headers.Add("SOAPAction", "http://EnsemblePlus.Webservice");
2700
                        var _result = webClient.UploadString(new Uri(soapurl), data);
2701
                        XmlDocument xmlDoc = new XmlDocument();
2702
                        xmlDoc.LoadXml(_result);
2703
                        XmlNodeList list = xmlDoc.GetElementsByTagName("checkoutSignImageResponse");
2704

    
2705
                        foreach (XmlNode xn in list)
2706
                        {
2707
                            result = xn["checkoutSignImageReturn"].InnerText;
2708
                        }
2709

    
2710
                        if (result.Contains("No business object"))
2711
                        {
2712
                            result = null;
2713
                        }
2714
                    }
2715
                    else
2716
                    {
2717
                        result = null;
2718
                    }
2719
                }
2720
             
2721
            }
2722
            catch (Exception ex)
2723
            {   
2724
                result = null;
2725
            }
2726

    
2727
            return result;
2728
        }
2729
        #endregion
2730

    
2731
        #region Final Service
2732
        [OperationContract]
2733
        [ServiceKnownType(typeof(DOCINFO))]                
2734
        public DOCINFO FinalPDF_GetDocinfo(string project_no, string docinfo_id)
2735
        {
2736
            DOCINFO docinfo = null;
2737

    
2738
            try
2739
            {
2740
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2741
                using (CIEntities _entity = new CIEntities(sCIConnString))
2742
                {
2743
                    var doc = _entity.DOCINFO.Where(x => x.ID == docinfo_id).FirstOrDefault();
2744
                    if(doc != null)
2745
                    {
2746
                        docinfo = new DOCINFO()
2747
                        {
2748
                            ID = doc.ID,
2749
                            DOCUMENT_ID = doc.DOCUMENT_ID,
2750
                            PAGE_COUNT = doc.PAGE_COUNT,
2751
                            ORIGINAL_FILE = doc.ORIGINAL_FILE,
2752
                            PROJECT_NO = doc.PROJECT_NO
2753
                        };
2754
                    }                    
2755
                }
2756
            }
2757
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2758
                throw;
2759
            }
2760
            return docinfo;
2761
        }
2762
        [OperationContract]
2763
        [ServiceKnownType(typeof(DOCUMENT_ITEM))]
2764
        public DOCUMENT_ITEM FinalPDF_GetDocumentItem(string project_no, string document_id)
2765
        {
2766
            DOCUMENT_ITEM item = null;
2767

    
2768
            try
2769
            {
2770
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2771
                using (CIEntities _entity = new CIEntities(sCIConnString))
2772
                {
2773
                    var doc = _entity.DOCUMENT_ITEM.Where(x => x.PROJECT_NO == project_no &&  x.DOCUMENT_ID == document_id).FirstOrDefault();
2774
                    if(doc != null)
2775
                    {
2776
                        item = new DOCUMENT_ITEM()
2777
                        {
2778
                            ID = doc.ID,
2779
                            ORIGINAL_FILE = doc.ORIGINAL_FILE,
2780
                            PROJECT_NO = doc.PROJECT_NO,
2781
                            DOCUMENT_ID = doc.DOCUMENT_ID,
2782
                            DOCUMENT_NO = doc.DOCUMENT_NO,
2783
                            DOCUMENT_NAME = doc.DOCUMENT_NAME,
2784
                            //ENSEMBLEINFO_URL = doc.ENSEMBLEINFO_URL,
2785
                            GROUP_NO = doc.GROUP_NO,
2786
                            RESULT = doc.RESULT,
2787
                            REVISION = doc.REVISION,
2788
                            RESULT_FILE = doc.RESULT_FILE
2789
                        };
2790
                    }
2791
                    
2792
                }
2793
            }
2794
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2795
                throw;
2796
            }
2797
            return item;
2798
        }
2799
        [OperationContract]
2800
        [ServiceKnownType(typeof(MARKUP_DATA))]
2801
        public List<MARKUP_DATA> FinalPDF_GetMarkupdata(string project_no, string docinfo_id)
2802
        {
2803
            List<MARKUP_DATA> results = new List<MARKUP_DATA>();
2804

    
2805
            try
2806
            {
2807
                //using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2808
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2809
                using (CIEntities _entity = new CIEntities(sCIConnString))
2810
                {
2811
                    var datas = _entity.MARKUP_DATA.Where(x => x.MARKUP_INFO_VERSION.MARKUP_INFO.DOCINFO_ID == docinfo_id
2812
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.CONSOLIDATE == 1
2813
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.AVOID_CONSOLIDATE == 0
2814
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.PART_CONSOLIDATE == 0).ToList();
2815
                    foreach (var data in datas)
2816
                    {
2817
                        MARKUP_DATA d = new MARKUP_DATA()
2818
                        {
2819
                            ID = data.ID,
2820
                            //GROUP_ID = data.GROUP_ID,
2821
                            SYMBOL_ID = data.SYMBOL_ID,
2822
                            DATA = data.DATA,
2823
                            DATA_TYPE = data.DATA_TYPE,
2824
                            MARKUPINFO_VERSION_ID = data.MARKUPINFO_VERSION_ID,
2825
                            PAGENUMBER = data.PAGENUMBER
2826
                        };
2827
                        results.Add(d);
2828
                    }
2829
                }
2830
            }
2831
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2832
                throw;
2833
            }
2834
            return results;
2835
        }
2836
        [OperationContract]
2837
        [ServiceKnownType(typeof(MARKUP_INFO))]
2838
        public MARKUP_INFO FinalPDF_GetMarkupinfo(string project_no, string docinfo_id)
2839
        {
2840
            MARKUP_INFO markupInfo = null;
2841

    
2842
            try
2843
            {
2844
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2845
                using (CIEntities _entity = new CIEntities(sCIConnString))
2846
                {
2847
                    var tmp = _entity.MARKUP_INFO.Where(x => x.DOCINFO_ID == docinfo_id && x.CONSOLIDATE == 1 && x.AVOID_CONSOLIDATE == 0 && x.PART_CONSOLIDATE == 0).FirstOrDefault();
2848
                    if (tmp != null)
2849
                    {
2850
                        markupInfo = new MARKUP_INFO()
2851
                        {
2852
                            ID = tmp.ID,
2853
                            DOCINFO_ID = tmp.DOCINFO_ID,
2854
                            USER_ID = tmp.USER_ID
2855
                        };
2856
                    }                    
2857
                }
2858
            }
2859
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2860
                throw;
2861
            }
2862
            return markupInfo;
2863
        }
2864
        [OperationContract]
2865
        [ServiceKnownType(typeof(FINAL_PDF))]
2866
        public List<FINAL_PDF> FinalPDF_GetFinalPDFs(string final_id)
2867
        {
2868
            List<FINAL_PDF> results = new List<FINAL_PDF>();
2869

    
2870
            try
2871
            {
2872
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2873
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
2874
                {
2875
                    var finalList = _entity.FINAL_PDF.Where(final => final.ID == final_id).ToList();
2876
                    foreach(var final in finalList)
2877
                    {
2878
                        FINAL_PDF pdf = new FINAL_PDF()
2879
                        {
2880
                            ID = final.ID,
2881
                            DOCINFO_ID = final.DOCINFO_ID,
2882
                            DOCUMENT_ID = final.DOCUMENT_ID,
2883
                            STATUS = final.STATUS,
2884
                            CURRENT_PAGE = final.CURRENT_PAGE,
2885
                            CREATE_DATETIME = final.CREATE_DATETIME,
2886
                            START_DATETIME = final.START_DATETIME,
2887
                            END_DATETIME = final.END_DATETIME,
2888
                            EXCEPTION = final.EXCEPTION,
2889
                            PROJECT_NO = final.PROJECT_NO,
2890
                            TOTAL_PAGE = final.TOTAL_PAGE,
2891
                            MARKUPINFO_ID = final.MARKUPINFO_ID,
2892
                            CREATE_USER_ID = final.CREATE_USER_ID
2893
                        };
2894
                        results.Add(pdf);
2895
                    }
2896
                }
2897
            }
2898
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2899
                throw;
2900
            }
2901
            return results;
2902
        }
2903
        [OperationContract]
2904
        [ServiceKnownType(typeof(DOCPAGE))]
2905
        public List<DOCPAGE> FinalPDF_GetDocpage(string project_no, string docinfo_id)
2906
        {
2907
            List<DOCPAGE> results = new List<DOCPAGE>();
2908

    
2909
            try
2910
            {
2911
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2912
                using (CIEntities _entity = new CIEntities(sCIConnString))
2913
                {
2914
                    var pages = _entity.DOCPAGE.Where(x => x.DOCINFO_ID == docinfo_id).OrderBy(x => x.PAGE_NUMBER).ToList();
2915
                    foreach(var page in pages)
2916
                    {
2917
                        DOCPAGE p = new DOCPAGE()
2918
                        {
2919
                            PAGE_ANGLE = page.PAGE_ANGLE,
2920
                            PAGE_NUMBER = page.PAGE_NUMBER,
2921
                            PAGE_HEIGHT = page.PAGE_HEIGHT,
2922
                            PAGE_WIDTH = page.PAGE_WIDTH,
2923
                            DOCINFO_ID = page.DOCINFO_ID                            
2924
                        };
2925
                        results.Add(p);
2926
                    }                    
2927
                }
2928
            }
2929
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2930
                throw;
2931
            }
2932
            return results;
2933
        }
2934
        [OperationContract]        
2935
        public bool FinalPDF_SetFinalPDFStatus(string final_id, FinalStatus status)
2936
        {
2937
            bool result = false;
2938

    
2939
            try
2940
            {
2941
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2942
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
2943
                {
2944
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
2945
                    if(tmp != null)
2946
                    {
2947
                        switch(status)
2948
                        {
2949
                            case FinalStatus.Create:
2950
                                tmp.START_DATETIME = DateTime.Now;
2951
                                break;
2952
                            case FinalStatus.Success:
2953
                                tmp.END_DATETIME = DateTime.Now;
2954
                                tmp.EXCEPTION = string.Empty;
2955
                                break;                                
2956
                        }
2957
                        tmp.STATUS = (int)status;
2958
                        _entity.SaveChanges();
2959
                        result = true;                        
2960
                    }
2961
                }                    
2962
            }
2963
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2964
                throw;
2965
            }
2966
            return result;
2967
        }
2968

    
2969
        /// <summary>
2970
        /// 현재 진행중인 Final PDF 가 없거나 Success 일 경우에만 true return
2971
        /// </summary>
2972
        /// <param name="DocInfoID"></param>
2973
        /// <param name="MarkupInfoID"></param>
2974
        /// <param name="CreateUserID"></param>
2975
        /// <returns></returns>
2976
        [OperationContract]
2977
        public bool FinalPDF_GetFinalPDFStatus(string DocInfoID, string MarkupInfoID, string CreateUserID)
2978
        {
2979
            bool result = false;
2980

    
2981
            try
2982
            {
2983
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2984
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
2985
                {
2986
                    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();
2987
                    if (finalpdf != null)
2988
                    {
2989
                        if (finalpdf.STATUS == (int)FinalStatus.Success)
2990
                        {
2991
                            result = true;
2992
                        }
2993
                    }
2994
                    else
2995
                        result = true;
2996
                }
2997
            }
2998
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2999
                throw;
3000
            }
3001
            return result;
3002
        }
3003

    
3004
        [OperationContract]
3005
        public bool FinalPDF_SetCurrentPage(string final_id, int currentpage)
3006
        {
3007
            bool result = false;
3008

    
3009
            try
3010
            {
3011
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3012
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3013
                {
3014
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
3015
                    if (tmp != null)
3016
                    {
3017
                        tmp.CURRENT_PAGE = currentpage;
3018
                        _entity.SaveChanges();
3019
                        result = true;
3020
                    }
3021
                }
3022
            }
3023
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3024
                throw;
3025
            }
3026
            return result;
3027
        }
3028
        [OperationContract]
3029
        public bool FinalPDF_SetError(string final_id, string msg)
3030
        {
3031
            bool result = false;
3032

    
3033
            try
3034
            {
3035
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3036
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3037
                {
3038
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
3039
                    if (tmp != null)
3040
                    {                        
3041
                        tmp.STATUS = (int)FinalStatus.Error;
3042
                        tmp.EXCEPTION = DateTime.Now.ToShortDateString() + " " + msg;                        
3043
                        _entity.SaveChanges();
3044
                        result = true;
3045
                    }
3046
                }
3047
            }
3048
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3049
                throw;
3050
            }
3051
            return result;
3052
        }
3053

    
3054
        [OperationContract]
3055
        public bool FinalPDF_SetFinalResultPath(string project_no, string document_id, string url)
3056
        {
3057
            bool result = false;
3058

    
3059
            try
3060
            {
3061
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
3062
                using (CIEntities _entity = new CIEntities(sCIConnString))
3063
                {
3064
                    var item = _entity.DOCUMENT_ITEM.Where(d =>d.PROJECT_NO == project_no && d.DOCUMENT_ID == document_id).FirstOrDefault();
3065
                    if (item != null)
3066
                    {
3067
                        item.RESULT_FILE = url;
3068
                        _entity.SaveChanges();
3069
                        result = true;
3070
                    }
3071
                }
3072
            }
3073
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3074
                throw;
3075
            }
3076
            return result;
3077
        }
3078
        [OperationContract]
3079
        [ServiceKnownType(typeof(MEMBER))]
3080
        public MEMBER FinalPDF_GetCommentMember(string project_no, string markupdata_id)
3081
        {
3082
            MEMBER member = null;
3083
            try
3084
            {
3085
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
3086
                using (CIEntities _entity = new CIEntities(sCIConnString))
3087
                {
3088
                    var data = _entity.MARKUP_DATA.Where(x => x.ID == markupdata_id).FirstOrDefault();
3089
                    string user_id = data.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID;
3090

    
3091
                    var person = GetMemberQuery(_entity,user_id);
3092

    
3093
                    if(person.Count() > 0)
3094
                    {
3095
                        member = person.First();
3096
                    }
3097
                }
3098
            }
3099
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3100
                throw;
3101
            }
3102

    
3103
            return member;
3104
        }
3105

    
3106
        [OperationContract]
3107
        [ServiceKnownType(typeof(PROPERTIES))]
3108
        public List<PROPERTIES> FinalPDF_GetProperties(string project_no)
3109
        {
3110
            List<PROPERTIES> results = new List<PROPERTIES>();
3111
            try
3112
            {
3113
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3114
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3115
                {
3116
                    var _items = _entity.PROPERTIES.Where(x => x.PROPERTY == project_no).ToList();
3117
                    foreach(var item in _items)
3118
                    {
3119
                        PROPERTIES pROPERTIES = new PROPERTIES()
3120
                        {
3121
                            ID = item.ID,
3122
                            PROPERTY = item.PROPERTY,
3123
                            TYPE = item.TYPE,
3124
                            VALUE = item.VALUE
3125
                        };
3126
                        results.Add(pROPERTIES);
3127
                    }
3128
                }
3129

    
3130
            }
3131
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3132
                throw;
3133
            }
3134
            return results;
3135
        }
3136
        #endregion
3137
    }    
3138
}
클립보드 이미지 추가 (최대 크기: 500 MB)