프로젝트

일반

사용자정보

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

markus / KCOM_API / ServiceDeepView.svc.cs @ 43e1d368

이력 | 보기 | 이력해설 | 다운로드 (138 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
                    var port = SystemInfoSet.Where(data => data.PROPERTY == "Port").FirstOrDefault();
103
                    if (port != null)
104
                    {
105
                        sysInfo.HostPort = port.VALUE;
106
                    }
107

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

    
113
                    }
114

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

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

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

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

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

    
142
            var guid = new Guid(bytes);
143

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

    
150

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

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

    
163

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

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

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

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

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

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

    
193
                        dc.SaveChanges();
194

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

    
206
                    return false;
207
                }
208
            }
209
        }
210

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

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

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

    
238
                    return false;
239
                }
240
            }
241
        }
242

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

    
258
            try
259
            {
260
                string originFile = "";
261
                string targetFile = "";
262

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

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

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

    
288

    
289
            return result;
290
        }
291

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

    
307
            try
308
            {
309
                string originFile = "";
310
                string targetFile = "";
311

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

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

    
326
                using (Markus.Image.ImageCompare compareLib = new Markus.Image.ImageCompare())
327
                {
328

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

    
338

    
339
            return result;
340
        }
341

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

    
347
        //    stopwatch.Start();
348

    
349
        //    string originFile = "";
350
        //    string targetFile = "";
351

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

    
364
        //    CompareLib compareLib = new CompareLib();
365

    
366
        //    var resultOrigin = compareLib.ChangeCmpUrlToPng_File(originFile);
367
        //    var resultTarget = compareLib.ChangeCmpUrlToPng_File(targetFile);
368

    
369
        //    string outPutFile = compareLib.ImageCompare_File(resultOrigin, resultTarget);
370
        //    var result = compareLib.GetBoundBoxInImage(outPutFile);
371

    
372
        //    System.Diagnostics.Debug.WriteLine(new TimeSpan(stopwatch.ElapsedTicks));
373

    
374
        //    return result;
375
        //}
376

    
377

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

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

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

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

    
433
                    System.Runtime.Remoting.Channels.IChannel _ch = System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp");
434
                    if (_ch == null)
435
                    {
436
                        chan = new TcpChannel();
437
                        _ChanID = chan.ChannelName;
438
                        System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan, false);
439
                        // Create an instance of the remote object
440

    
441
                        using (KCOMEntities ec = new KCOMEntities(sConnString))
442
                        {
443

    
444
                            //remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
445
                            //                          "tcp://localhost:9092/remFinalPDF");
446
                            remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
447
                                                      //"tcp://192.168.0.67:9092/remFinalPDF");
448
                                                      KCOM_API.Properties.Settings.Default.FinalService);
449
                        }
450

    
451
                        //"tcp://localhost:8080/remFinalPDF");
452

    
453
                        _result = remObj.SetFinalPDF(ProjectNo, _finalID);
454
                        _result.FinalID = _finalID;
455
                        _result.Status = FinalStatus.Success;
456

    
457
                        //MarkupToPDF.MarkupToPDF fa = new MarkupToPDF.MarkupToPDF();
458
                        //fa.MakeFinalPDF(fm);
459
                    }
460
                    else
461
                    {
462
                        _ChanID = _ch.ChannelName;
463
                    }
464
                }
465
            }
466
            catch (Exception ex)
467
            {
468
                System.Diagnostics.Debug.WriteLine("KCOM_API - SetFinalPDF : " + ex.ToString());
469

    
470
                _result.Status = FinalStatus.Error;
471

    
472
                if (ex.GetType() == typeof(System.Net.Sockets.SocketException))
473
                    _result.Exception = "Final Server Not Connection";
474
                else _result.Exception = ex.ToString();
475
            }
476
            finally
477
            {
478
                remObj = null;
479
                if (System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp") != null)
480
                    System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(chan);
481

    
482
                GC.Collect(2);
483
            }
484
            return _result;
485
        }
486
        #endregion
487

    
488

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

    
509
                        if (lst != null || lst.Count >= 1)
510
                        {
511
                            //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_PAGECOUNT"), param.documentID, param.projectNo);
512
                            //이메일 클라이언트를 구현해야함
513
                        }
514
                        return false;
515
                    }
516
                }
517
                else
518
                {
519
                    //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_CONVERTFAILED"), param.documentID, param.projectNo);
520
                    //이메일 클라이언트를 구현해야함
521
                    return false;
522
                }
523
            }
524
        }
525

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

    
558
                    //_result = _result.OrderByDescending(r => UInt64.Parse(System.Text.RegularExpressions.Regex.Replace(r.GroupNo, @"\D", ""))).ToList();
559
                    _result =  _result.OrderByDescending(r => r.GroupNo).ToList();
560
                }
561
            }
562
            catch (Exception ex)
563
            {
564
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetVPRevisionHistory : " + ex.ToString());
565
            }
566
            finally
567
            {
568
                //GC.Collect(2);
569
            }
570

    
571
            return _result;
572
        }
573

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

    
607
        [OperationContract]
608
        public DOCINFO GetDocInfo(KCOM_BasicParam param)
609
        {
610
            DOCINFO _result = null;
611
            try
612
            {
613
                // 차후 아래의 코드로 변경
614
                //using (CI_Entities ModelDeeview = new CI_Entities(DaelimCiConnectionString.ToString()))
615
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
616
                CIEntities ModelDeeview = new CIEntities(sCIConnString);
617

    
618
                var docinfo = ModelDeeview.DOCINFO.Where(doc => doc.DOCUMENT_ID == param.documentID && doc.PROJECT_NO == param.projectNo);
619
                if (docinfo.Count() > 0)
620
                {
621
                    _result = docinfo.First();
622
                    _result.MARKUP_INFO.Clear();
623

    
624
                }
625
                return _result;
626

    
627
            }
628
            catch (Exception ex)
629
            {
630
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetDocInfo : " + ex.ToString());
631
            }
632
            finally
633
            {
634
                //GC.Collect(2);
635
            }
636
            return null;
637
        }
638

    
639
        [OperationContract]
640
        public bool GetCheckSystemAdmin(string UserID)
641
        {
642
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
643
            using (KCOMEntities uc = new KCOMEntities(sConnString))
644
            {
645
                var user = uc.PROPERTIES.Where(data => data.TYPE == "Administrator" && data.PROPERTY.Contains(UserID)).FirstOrDefault();
646
                if (user != null)
647
                {
648
                    return true;
649
                }
650
                else
651
                {
652
                    return false;
653
                }
654
            }
655
            //GC.Collect(2);
656
        }
657

    
658
        [OperationContract]
659
        public DOCUMENT_ITEM GetDocumentItemInfo(KCOM_BasicParam param)
660
        {
661
            ///param : prjNo, documentId, userId
662
            DOCUMENT_ITEM _result = null;
663

    
664
            try
665
            {
666
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
667
                CIEntities entity = new CIEntities(sCIConnString);
668
               
669
                var _items = entity.DOCUMENT_ITEM.Where(data => data.PROJECT_NO == param.projectNo && data.DOCUMENT_ID == param.documentID);
670

    
671
                if (_items.Count() > 0)
672
                {
673
                    _result = _items.First();
674

    
675
                    return _result;
676
                }
677
                //else
678
                //{
679
                //    Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, Resources.ResourceManager.GetString("MSG_ERROR_DOCUMENTNOTFOUND"), param.documentID, param.projectNo);
680
                //}
681
            }
682
            catch (Exception ex)
683
            {
684
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetDocumentItemInfo : " + ex.ToString());
685

    
686
                new FaultException("GetDocumentItemInfo Error - "  + ex.ToString());
687
                //throw new FaultException(ex.ToString());
688
                //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, "GetDocumentItemInfo / " + ex.Message, param.documentID, param.projectNo);
689
            }
690

    
691
            return _result;
692
        }
693
        /// <summary>
694
        /// DOCUMENT_ITEM Table 의 ID 로 Item 을 Select
695
        /// </summary>
696
        /// 대림의 경우 Interface ID(Document 의 ID) 를 parameter 로 전달
697
        /// 넘어온 ID를 통해 document id 를 확인하는 과정이 필요
698
        /// <param name="ensemble_id"></param>
699
        /// <returns></returns>
700
        [OperationContract]
701
        public string GetDocItemID(string ensemble_id)
702
        {
703
            ///param : prjNo, documentId, userId
704
            string _result = string.Empty;
705

    
706
            try
707
            {
708
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
709
                CIEntities entity = new CIEntities(sCIConnString);
710

    
711
                var _items = entity.DOCUMENT_ITEM.Where(data => data.ID == ensemble_id).FirstOrDefault();
712
                if(_items != null)
713
                    _result = _items.DOCUMENT_ID;
714
            }
715
            catch (Exception ex)
716
            {
717
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetDocItemID : " + ex.ToString());
718
                //System.Diagnostics.Trace.WriteLine("GetVendorItemInfo Error : " + ex);
719
                //Common.Helper.SystemErrorNotify(SERVICE_NAME.API, LEVEL.MEDIUM, ERROR_TYPE.CONVERT, "GetDocumentItemInfo / " + ex.Message, param.documentID, param.projectNo);
720
            }
721

    
722
            return _result;
723
        }
724
        public string UserGO(MARKUP_INFO item)
725
        {
726
            if (item != null)
727
            {
728
                return item.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID;
729
            }
730
            return null;
731
        }
732
        
733
        [OperationContract]
734
        public List<MarkupInfoItem> GetMarkupInfoItems(string ProjectNo, string DocInfoId)
735
        {
736
            List<MarkupInfoItem> _result = new List<MarkupInfoItem>();
737
            try
738
            {
739
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
740
                using (CIEntities entity = new CIEntities(sCIConnString))
741
                {
742
                    var markupListData = entity.MARKUP_INFO.Where(data => data.DOCINFO_ID == DocInfoId).ToList();
743

    
744
                    var markupList = from markup in markupListData
745
                                     orderby markup.CREATE_TIME descending
746
                                     select new MarkupInfoItem
747
                                     {
748
                                         MarkupInfoID = markup.ID,
749
                                         UserID = markup.USER_ID,
750
                                         MarkupVersionID = markup.MARKUP_INFO_VERSION.Count() == 0 ? null : markup.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID,
751
                                         CreateTime = markup.CREATE_TIME,
752
                                         Consolidate = markup.CONSOLIDATE,
753
                                         Description = markup.DESCRIPTION,
754
                                         AvoidConsolidate = markup.AVOID_CONSOLIDATE,
755
                                         PartConsolidate = markup.PART_CONSOLIDATE,
756
                                         UpdateTime = DateTime.Parse(markup.UPDATE_TIME.ToString()),
757
                                     };
758

    
759
                    if (markupList.Count() > 0)
760
                    {
761
                        _result = markupList.ToList();
762
                    }
763

    
764
                    _result.ForEach(r =>
765
                    {
766

    
767
                        r.MarkupList = (from markupData in entity.MARKUP_DATA
768
                                        where markupData.MARKUPINFO_VERSION_ID == r.MarkupVersionID
769
                                        orderby markupData.PAGENUMBER
770
                                        select new MarkupItem { ID = markupData.ID, PageNumber = markupData.PAGENUMBER, Data = markupData.DATA, Data_Type = markupData.DATA_TYPE, Symbol_ID = markupData.SYMBOL_ID}).ToList();
771
                    });
772

    
773
                    List<PROPERTIES> _ColorsProperties = new List<PROPERTIES>();
774
                    Random random = new Random();
775

    
776
                    string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
777
                    using (KCOMEntities kcomEntity = new KCOMEntities(sConnString))
778
                    {
779
                        _ColorsProperties = (from property in kcomEntity.PROPERTIES
780
                                             where property.TYPE == "DisplayColor"
781
                                             select property).ToList();
782

    
783
                    }
784

    
785
                    if (_ColorsProperties.Count() != _result.GroupBy(x=>x.UserID).Count())
786
                    {
787
                        ColorGenerator uniqueColorGenerator = new ColorGenerator(System.Drawing.Color.Red); // 2303 = (int)Color.Red
788

    
789
                        uniqueColorGenerator.GetEnumerator(_result.Count());
790

    
791
                        for (int i = 0; i < _result.Count(); i++)
792
                        {
793
                             var c = uniqueColorGenerator.GetNext();
794
                            _ColorsProperties.Add(new PROPERTIES { VALUE = String.Format("{0:X2}{1:X2}{2:X2}",c.R, c.G,c.B) });
795
                        }
796
                    }
797

    
798
                    bool IsProjectNoPass = Properties.Settings.Default.IsProjectNoPass;
799

    
800
                    foreach (var item in _result.GroupBy(x=>x.UserID))
801
                    {
802
                        string query = "SELECT members.ID,members.NAME,members.DEPARTMENT FROM CIEntities.MEMBER as members where members.ID = @userId";
803

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

    
807
                        if (memberQuery.Count() > 0)
808
                        {
809
                            string userName = memberQuery.First()["NAME"]?.ToString().Trim();
810
                            string depatment = memberQuery.First()["DEPARTMENT"]?.ToString().Trim();
811

    
812
                            PROPERTIES deptColor = _ColorsProperties[0];
813

    
814
                            _ColorsProperties.RemoveAt(0);
815
                            //PROPERTIES deptColor = _ColorsProperties.Find(c => c.PROPERTY == depatment);
816

    
817
                            //if (_ColorsProperties.Count > 0)
818
                            //{
819
                            //    if (deptColor == null)
820
                            //    {
821
                            //        item.DisplayColor = "#FF" + _ColorsProperties[0].VALUE;
822
                            //        _ColorsProperties.RemoveAt(0);
823
                            //    }
824
                            //    else
825
                            //    {
826
                            //        item.DisplayColor = "#FF" + deptColor.VALUE;
827
                            //        _ColorsProperties.Remove(deptColor);
828
                            //    }
829
                            //}
830

    
831
                            foreach (var markupInfo in item)
832
                            {
833
                                markupInfo.DisplayColor = "#FF" + deptColor.VALUE;
834
                                markupInfo.UserName = userName;
835
                                markupInfo.Depatment = depatment;
836
                            }
837
                        }
838
                    }
839

    
840
                       
841
                    //else
842
                    //{
843
                    //    item.DisplayColor = String.Format("#FF{0:X6}", random.Next(0x1000000));
844
                    //}
845
                }
846
            }
847
            catch (Exception ex)
848
            {
849
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetMarkupInfoItems : " + ex.ToString());
850

    
851
                return _result;
852
            }
853
            finally
854
            {
855
                //GC.Collect(2);
856
            }
857

    
858
            return _result;
859
        }
860

    
861
        [OperationContract]
862
        public List<MarkupInfoItem> GetSyncMarkupInfoItems(string ProjectNo, string DocInfoId, string currentUser)
863
        {
864
            List<MarkupInfoItem> _result = new List<MarkupInfoItem>();
865
            try
866
            {
867
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
868
                using (CIEntities entity = new CIEntities(sCIConnString))
869
                {
870
                    var docItem = entity.DOCINFO.Where(data => data.DOCUMENT_ID == DocInfoId).FirstOrDefault();
871
                    if (docItem == null)
872
                    {
873
                        return null;
874
                    }
875
                    var markupListData = entity.MARKUP_INFO.Where(data => data.DOCINFO_ID == docItem.ID).ToList();
876

    
877
                    var markupList = from markup in markupListData
878
                                     where markup.USER_ID == currentUser || markup.CONSOLIDATE == 1
879
                                     orderby markup.CREATE_TIME descending
880
                                     select new MarkupInfoItem
881
                                     {
882
                                         MarkupInfoID = markup.ID,
883
                                         UserID = markup.USER_ID,
884
                                         MarkupVersionID = markup.MARKUP_INFO_VERSION.Count() == 0 ? null : markup.MARKUP_INFO_VERSION.OrderByDescending(data => data.CREATE_DATE).FirstOrDefault().ID,
885
                                         CreateTime = markup.CREATE_TIME,
886
                                         Consolidate = markup.CONSOLIDATE,
887
                                         Description = markup.DESCRIPTION,
888
                                         AvoidConsolidate = markup.AVOID_CONSOLIDATE,
889
                                         PartConsolidate = markup.PART_CONSOLIDATE,
890
                                     };
891

    
892

    
893

    
894
                    if (markupList.Count() > 0)
895
                    {
896
                        _result = markupList.ToList();
897
                    }
898

    
899

    
900

    
901
                    _result.ForEach(r =>
902
                    {
903

    
904
                        r.MarkupList = (from markupData in entity.MARKUP_DATA
905
                                        where markupData.MARKUPINFO_VERSION_ID == r.MarkupVersionID
906
                                        orderby markupData.PAGENUMBER
907
                                        select new MarkupItem
908
                                        {
909
                                            ID = markupData.ID,
910
                                            PageNumber = markupData.PAGENUMBER,
911
                                            Data = markupData.DATA,
912
                                            Data_Type = markupData.DATA_TYPE,
913
                                            Symbol_ID = markupData.SYMBOL_ID
914
                                        }).ToList();
915
                    });
916

    
917
                    List<PROPERTIES> _ColorsProperties = new List<PROPERTIES>();
918
                    Random random = new Random();
919

    
920
                    string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
921
                    using (KCOMEntities kcomEntity = new KCOMEntities(sConnString))
922
                    {
923
                        _ColorsProperties = (from property in kcomEntity.PROPERTIES
924
                                             where property.TYPE == "DisplayColor"
925
                                             select property).ToList();
926
                    }
927

    
928
                    foreach (var item in _result)
929
                    {
930
                        string query = "SELECT members.ID,members.NAME,members.DEPARTMENT FROM CIEntities.MEMBER as members where members.ID = @userId";
931

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

    
935
                        if (memberQuery.Count() > 0)
936
                        {
937

    
938
                            string userName = memberQuery.First()["NAME"]?.ToString().Trim();
939
                            string depatment = memberQuery.First()["DEPARTMENT"]?.ToString().Trim();
940

    
941
                            item.UserName = userName;
942
                            item.Depatment = depatment;
943
                        }
944

    
945
                        if (_ColorsProperties.Count > 0)
946
                        {
947
                            int colorIdx = random.Next(1, _ColorsProperties.Count());
948
                            #region 부서별로 색상을 지정하고자 할때
949
                            /// 일단 의견을 들어보자구!
950
                            #endregion
951
                            item.DisplayColor = "#FF" + _ColorsProperties[colorIdx].VALUE;
952
                            _ColorsProperties.Remove(_ColorsProperties[colorIdx]);
953
                            //item.DisplayColor = "#FF" + _Colors.First();
954
                            //_Colors.Remove(_Colors.First());
955
                        }
956
                        else
957
                        {
958
                            item.DisplayColor = String.Format("#FF{0:X6}", random.Next(0x1000000));
959
                        }
960
                    }
961
                }
962
            }
963
            catch (Exception ex)
964
            {
965
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetSyncMarkupInfoItems : " + ex.ToString());
966
                return _result;
967
            }
968
            finally
969
            {
970
                //GC.Collect(2);
971
            }
972

    
973
            return _result;
974
        }
975

    
976

    
977
        //[OperationContract]
978
        //[ServiceKnownType(typeof(MEMBER))]
979
        //public List<MEMBER> GetUserData(string ProjectNo, string UserID)
980
        //{
981
        //    List<MEMBER> _result = new List<MEMBER>();
982

    
983
        //    using (CIEntities entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
984
        //    {
985
        //        var _UserList = from member in entity.MEMBER
986
        //                        where member.ID == UserID
987
        //                        select member;
988
        //        _result = _UserList.ToList();
989
        //    }
990
        //    //GC.Collect(2);
991
        //    return _result;
992
        //}
993

    
994
        [OperationContract]
995
        [ServiceKnownType(typeof(MEMBER))]
996
        public List<MEMBER> GetUserData(string ProjectNo, string UserID)
997
        {
998
            List<MEMBER> _result = new List<MEMBER>();
999

    
1000
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1001

    
1002
            using (CIEntities entity = new CIEntities(sCIConnString))
1003
            {
1004
                _result = GetMemberQuery(entity, UserID);
1005
            }
1006
            //GC.Collect(2);
1007
            return _result;
1008
        }
1009

    
1010

    
1011
        [OperationContract]
1012
        public List<string> GetDeptData(string UserDept) //그룹 추가 옵션 부여 예정
1013
        {
1014
            List<string> _result = new List<string>();
1015

    
1016
            try
1017
            {
1018
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1019
                KCOMEntities entity = new KCOMEntities(sConnString);
1020
                var YourEnginner = (from dept in entity.PROPERTIES
1021
                                    where dept.TYPE == "DeptName" && UserDept.Contains(dept.VALUE)
1022
                                    select dept).FirstOrDefault();
1023

    
1024
                if (YourEnginner != null)
1025
                {
1026
                    _result = (from dept in entity.PROPERTIES
1027
                               where dept.PROPERTY == YourEnginner.PROPERTY
1028
                               select dept.VALUE).ToList();
1029
                    return _result;
1030
                }
1031
                else
1032
                {
1033
                    return null;
1034
                }
1035
            }
1036
            catch (Exception ex)
1037
            {
1038
                System.Diagnostics.Debug.WriteLine("KCOM_API - GetDeptData : " + ex.ToString());
1039
            }
1040
            finally
1041
            {
1042
                //GC.Collect(2);
1043
            }
1044
            return _result;
1045
        }
1046

    
1047
        [OperationContract]
1048
        public bool DeleteMarkup(string ProjectNo, string MarkupInfoID)
1049
        {
1050
            bool _result = false;
1051
            try
1052
            {
1053
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1054
                using (KCOMDataModel.DataModel.CIEntities Entity = new KCOMDataModel.DataModel.CIEntities(sCIConnString))
1055
                {
1056

    
1057
                    MARKUP_INFO instance = Entity.MARKUP_INFO.Where(root => root.ID == MarkupInfoID).FirstOrDefault();
1058

    
1059
                    if (instance == null)
1060
                    {
1061
                        return false;
1062
                    }
1063
                    MARKUP_INFO_VERSION version = instance.MARKUP_INFO_VERSION.FirstOrDefault();
1064

    
1065

    
1066
                    version.MARKUP_DATA.ToList().ForEach(data =>
1067
                    {
1068
                        Entity.MARKUP_DATA.DeleteObject(data);
1069
                        Entity.SaveChanges();
1070
                    });
1071

    
1072
                    Entity.MARKUP_INFO_VERSION.DeleteObject(version);
1073
                    Entity.SaveChanges();
1074

    
1075
                    Entity.MARKUP_INFO.DeleteObject(instance);
1076
                    Entity.SaveChanges();
1077

    
1078
                }
1079
                _result = true;
1080
            }
1081
            catch (Exception ex)
1082
            {
1083
                System.Diagnostics.Debug.WriteLine("KCOM_API - DeleteMarkup : " + ex.ToString());
1084
            }
1085
            finally
1086
            {
1087
                //GC.Collect(2);
1088
            }
1089
            return _result;
1090
        }
1091

    
1092
        #region Favorite
1093
        [OperationContract]
1094
        public bool SetFavoriteVP(string prjNo, string userID, string groupNo, string docNo, string rev, int SavePageNo, string documentItemID, string VPDescription, IKCOM.FAVORITE_FLAG flag)
1095
        {
1096
            string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1097
            using (KCOMEntities entity = new KCOMEntities(sConnString))
1098
            {
1099
                try
1100
                {
1101
                    entity.FAVORITE_DOC.AddObject(new FAVORITE_DOC
1102
                    {
1103
                        ID = shortGuid(),
1104
                        PROJECT_NO = prjNo,
1105
                        DOCUMENT_ID = documentItemID,
1106
                        GROUP_NO = groupNo,
1107
                        DOCUMENT_NO = docNo,
1108
                        MEMBER_USER_ID = userID,
1109
                        DESCRIPTION = VPDescription,
1110
                        CREATE_TIME = DateTime.Now,
1111
                        REVISION = rev,
1112
                        FLAG = (int)flag,
1113
                        PAGE_NO = SavePageNo,
1114
                    });
1115
                    entity.SaveChanges();
1116
                }
1117
                catch (Exception ex)
1118
                {
1119
                    System.Diagnostics.Debug.WriteLine("KCOM_API - SetFavoriteVP : " + ex.ToString());
1120
                    return false;
1121
                }
1122

    
1123
                return true;
1124
            }
1125
        }
1126

    
1127
        //[OperationContract]
1128
        //public List<FAVORITE_DOC> GetFavoriteVP(string PrjNo, string userID, string sharepointItemID)
1129
        //{
1130
        //    using (KCOMEntities entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
1131
        //    {
1132

    
1133
        //        int flagString = Convert.ToInt32(IKCOM.FAVORITE_FLAG.Personal);                
1134
        //        List<FAVORITE_DOC> favoriteListSet = new List<FAVORITE_DOC>();
1135
        //        entity.FAVORITE_DOC.Where(data => data.PROJECT_NO == PrjNo && data.DOCUMENT_ID == sharepointItemID && data.FLAG !=
1136
        //            flagString).ToList().ForEach(data => favoriteListSet.Add(data));
1137
        //        entity.FAVORITE_DOC.Where(data => data.PROJECT_NO == PrjNo && data.MEMBER_USER_ID == userID).ToList().ForEach(data => favoriteListSet.Add(data));
1138
        //        favoriteListSet = favoriteListSet.Distinct().ToList();
1139
        //        return favoriteListSet;
1140
        //    }
1141
        //}
1142
        //[OperationContract]
1143
        //public bool EditFavoriteVP(string prjNo, string userID, int SavePageNo, string sharepointItemID, DateTime createTime, int state, string description)
1144
        //{
1145
        //    using (DeepViewEntities dc = new DeepViewEntities(ConnectStringBuilder.DeepViewConnectionString().ToString()))
1146
        //    {
1147
        //        List<FavoriteVP> favoriteSet = dc.FavoriteVP.Where(data => data.ProjectNo == prjNo && data.CreateUserID == userID
1148
        //            && data.PageNo == SavePageNo && data.CreateTime == createTime).ToList();
1149

    
1150
        //        try
1151
        //        {
1152

    
1153

    
1154
        //            if (favoriteSet.Count > 0)
1155
        //            {
1156
        //                var FavoriteVP_Instance = favoriteSet.First();
1157

    
1158
        //                FavoriteVP_Instance.Description = description;
1159
        //                FavoriteVP_Instance.Flag = state;
1160

    
1161
        //                dc.SaveChanges();
1162

    
1163
        //                return true;
1164
        //            }
1165
        //            else
1166
        //            {
1167
        //                return false;
1168
        //            }
1169
        //        }
1170
        //        catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1171
        //        {
1172
        //            return false;
1173
        //        }
1174
        //    }
1175
        //}
1176
        //[OperationContract]
1177
        //public bool DelFavoriteVP(string prjNo, string userID, int SavePageNo, string sharepointItemID, DateTime createTime)
1178
        //{
1179

    
1180
        //    using (DeepViewEntities dc = new DeepViewEntities(ConnectStringBuilder.DeepViewConnectionString().ToString()))
1181
        //    {
1182
        //        List<FavoriteVP> favoriteSet = dc.FavoriteVP.Where(data => data.ProjectNo == prjNo && data.CreateUserID == userID
1183
        //            && data.PageNo == SavePageNo && data.CreateTime == createTime).ToList();
1184

    
1185
        //        try
1186
        //        {
1187

    
1188

    
1189
        //            if (favoriteSet.Count > 0)
1190
        //            {
1191
        //                favoriteSet.ForEach(data => dc.FavoriteVP.DeleteObject(data));
1192
        //                dc.SaveChanges();
1193
        //                return true;
1194
        //            }
1195
        //            else
1196
        //            {
1197
        //                return false;
1198
        //            }
1199
        //        }
1200
        //        catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1201
        //        {
1202
        //            return false;
1203
        //        }
1204
        //    }
1205
        //}
1206
        #endregion
1207

    
1208
        [OperationContract]
1209
        public bool SaveMarkupData(MarkupInfoItem UserState,string project_no,string doc_id, string user_id, List<MARKUP_DATA> mlmarkup_data)
1210
        {
1211
            
1212
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1213
            using (CIEntities Entity = new CIEntities(sCIConnString))
1214
            {     
1215
                #region Docinfo 정보 가져오기
1216

    
1217
                string docinfoid_ = (from info in Entity.DOCINFO
1218
                                     where info.DOCUMENT_ID == doc_id
1219
                                     && info.PROJECT_NO == project_no
1220
                                     select info.ID
1221
                                     ).First().ToString();
1222
                #endregion
1223

    
1224
                #region Markup_Info 저장
1225

    
1226
                MARKUP_INFO markup_info = new MARKUP_INFO();
1227
                try
1228
                {
1229
                    markup_info = (from info in Entity.MARKUP_INFO
1230
                                   where info.ID == UserState.MarkupInfoID && info.USER_ID == user_id
1231
                                   select info).FirstOrDefault();
1232
                }
1233
                catch (Exception ex)
1234
                {
1235
                    System.Diagnostics.Debug.WriteLine("KCOM_API - SaveMarkupData Get markup_info: " + ex.ToString());
1236
                    markup_info = null;
1237
                }
1238

    
1239
                //markup_info가 없을 경우 생성
1240
                if (markup_info == null)
1241
                {
1242
                    //MarkupInfo 저장
1243
                    markup_info = new MARKUP_INFO
1244
                    {
1245
                        ID = UserState.MarkupInfoID,
1246
                        DOCINFO_ID = docinfoid_,
1247
                        USER_ID = user_id,
1248
                        CREATE_TIME = DateTime.Now,
1249
                        CONSOLIDATE = UserState.Consolidate,
1250
                        AVOID_CONSOLIDATE = UserState.AvoidConsolidate,
1251
                        PART_CONSOLIDATE = UserState.PartConsolidate,
1252
                        DESCRIPTION = UserState.Description,
1253
                        UPDATE_TIME = DateTime.Now
1254
                    };
1255
                    Entity.MARKUP_INFO.AddObject(markup_info);
1256
                }
1257
                //markup_info가 있을 경우 업데이트
1258
                else
1259
                {
1260
                    markup_info.UPDATE_TIME = DateTime.Now;
1261
                }
1262
                Entity.SaveChanges();
1263
                #endregion
1264

    
1265
                #region Markup_Info_Version 저장
1266

    
1267
                MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1268

    
1269
                try
1270
                {
1271
                    markup_info_version = (from info in Entity.MARKUP_INFO_VERSION
1272
                                           where info.MARKUPINFO_ID == markup_info.ID
1273
                                           select info).FirstOrDefault();
1274
                }
1275
                catch (Exception ex)
1276
                {
1277
                    System.Diagnostics.Debug.WriteLine("KCOM_API - SaveMarkupData  Get markup_info_version : " + ex.ToString());
1278
                    markup_info_version = null;
1279
                }
1280

    
1281
                //markup_info_version 없을 경우 생성
1282
                if (markup_info_version == null)
1283
                {
1284
                    //MarkupInfo_version 저장
1285
                    markup_info_version = new MARKUP_INFO_VERSION()
1286
                    {
1287
                        ID = UserState.MarkupVersionID,
1288
                        MARKUPINFO_ID = markup_info.ID,
1289
                        CREATE_DATE = DateTime.Now
1290
                    };
1291
                    Entity.MARKUP_INFO_VERSION.AddObject(markup_info_version);
1292
                    Entity.SaveChanges();
1293
                }
1294
                #endregion
1295

    
1296
                
1297
                Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == markup_info_version.ID).ToList().ForEach(item =>
1298
                {
1299
                    Entity.MARKUP_DATA.DeleteObject(item);
1300
                });
1301

    
1302
                Entity.SaveChanges();
1303

    
1304
                try
1305
                {
1306
                    mlmarkup_data.ForEach(value =>
1307
                    {
1308
                        Entity.MARKUP_DATA.AddObject(new MARKUP_DATA
1309
                        {
1310
                            ID = value.ID,
1311
                            DATA = value.DATA,
1312
                            DATA_TYPE = value.DATA_TYPE,
1313
                            PAGENUMBER = value.PAGENUMBER,
1314
                            MARKUPINFO_VERSION_ID = markup_info_version.ID,
1315
                            SYMBOL_ID = value.SYMBOL_ID,
1316
                            //GROUP_ID = value.GROUP_ID
1317
                        });
1318

    
1319
                        
1320
                    });
1321
                    Entity.SaveChanges();
1322

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

    
1327
                        mlmarkup_data.ForEach(value =>
1328
                        {
1329
                            var param = new System.Data.Common.DbParameter[] { new System.Data.SqlClient.SqlParameter { ParameterName = "ID", Value = value.ID } };
1330
                            var result = Entity.ExecuteStoreCommand(sql, param);
1331
                        });
1332

    
1333
                        Entity.SaveChanges();
1334
                    }
1335
                }
1336
                catch (Exception ex)
1337
                {
1338
                    System.Diagnostics.Debug.WriteLine("KCOM_API - SaveMarkupData  set mlmarkup_data : " + ex.ToString());
1339
                    return false;
1340
                }
1341
            }
1342
            return true;
1343
        }
1344

    
1345
        [OperationContract]
1346
        public bool SavePageMarkupData(MarkupInfoItem UserState,int PageNo, string project_no, string doc_id, string user_id, List<MARKUP_DATA> mlmarkup_data)
1347
        {
1348

    
1349
            string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1350
            using (CIEntities Entity = new CIEntities(sCIConnString))
1351
            {
1352
                #region Docinfo 정보 가져오기
1353

    
1354
                string docinfoid_ = (from info in Entity.DOCINFO
1355
                                     where info.DOCUMENT_ID == doc_id
1356
                                     && info.PROJECT_NO == project_no
1357
                                     select info.ID
1358
                                     ).First().ToString();
1359
                #endregion
1360

    
1361
                #region Markup_Info 저장
1362

    
1363
                MARKUP_INFO markup_info = new MARKUP_INFO();
1364
                try
1365
                {
1366
                    markup_info = (from info in Entity.MARKUP_INFO
1367
                                   where info.ID == UserState.MarkupInfoID && info.USER_ID == user_id
1368
                                   select info).FirstOrDefault();
1369
                }
1370
                catch (Exception ex)
1371
                {
1372
                    System.Diagnostics.Debug.WriteLine("KCOM_API - SavePageMarkupData : " + ex.ToString());
1373

    
1374
                    markup_info = null;
1375
                }
1376

    
1377
                //markup_info가 없을 경우 생성
1378
                if (markup_info == null)
1379
                {
1380
                    //MarkupInfo 저장
1381
                    markup_info = new MARKUP_INFO
1382
                    {
1383
                        ID = UserState.MarkupInfoID,
1384
                        DOCINFO_ID = docinfoid_,
1385
                        USER_ID = user_id,
1386
                        CREATE_TIME = DateTime.Now,
1387
                        CONSOLIDATE = UserState.Consolidate,
1388
                        AVOID_CONSOLIDATE = UserState.AvoidConsolidate,
1389
                        PART_CONSOLIDATE = UserState.PartConsolidate,
1390
                        DESCRIPTION = UserState.Description,
1391
                        UPDATE_TIME = DateTime.Now
1392
                    };
1393
                    Entity.MARKUP_INFO.AddObject(markup_info);
1394
                }
1395
                //markup_info가 있을 경우 업데이트
1396
                else
1397
                {
1398
                    markup_info.UPDATE_TIME = DateTime.Now;
1399
                }
1400
                Entity.SaveChanges();
1401
                #endregion
1402

    
1403
                #region Markup_Info_Version 저장
1404

    
1405
                MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1406

    
1407
                try
1408
                {
1409
                    markup_info_version = (from info in Entity.MARKUP_INFO_VERSION
1410
                                           where info.MARKUPINFO_ID == markup_info.ID
1411
                                           select info).FirstOrDefault();
1412
                }
1413
                catch (Exception ex)
1414
                {
1415
                    System.Diagnostics.Debug.WriteLine("KCOM_API - SavePageMarkupData get markup_info_version : " + ex.ToString());
1416
                    markup_info_version = null;
1417
                }
1418

    
1419
                //markup_info_version 없을 경우 생성
1420
                if (markup_info_version == null)
1421
                {
1422
                    //MarkupInfo_version 저장
1423
                    markup_info_version = new MARKUP_INFO_VERSION()
1424
                    {
1425
                        ID = UserState.MarkupVersionID,
1426
                        MARKUPINFO_ID = markup_info.ID,
1427
                        CREATE_DATE = DateTime.Now
1428
                    };
1429
                    Entity.MARKUP_INFO_VERSION.AddObject(markup_info_version);
1430
                    Entity.SaveChanges();
1431
                }
1432
                #endregion
1433

    
1434

    
1435
                Entity.MARKUP_DATA.Where(data =>  data.PAGENUMBER == PageNo && data.MARKUPINFO_VERSION_ID == markup_info_version.ID).ToList().ForEach(item =>
1436
                {
1437
                    Entity.MARKUP_DATA.DeleteObject(item);
1438
                });
1439
                Entity.SaveChanges();
1440

    
1441
                try
1442
                {
1443
                    mlmarkup_data.ForEach(value =>
1444
                    {
1445
                        Entity.MARKUP_DATA.AddObject(new MARKUP_DATA
1446
                        {
1447
                            ID = value.ID,
1448
                            DATA = value.DATA,
1449
                            DATA_TYPE = value.DATA_TYPE,
1450
                            PAGENUMBER = value.PAGENUMBER,
1451
                            MARKUPINFO_VERSION_ID = markup_info_version.ID,
1452
                            SYMBOL_ID = value.SYMBOL_ID,
1453
                            //GROUP_ID = value.GROUP_ID
1454
                        });
1455
                    });
1456
                    Entity.SaveChanges();
1457
                }
1458
                catch (Exception ex)
1459
                {
1460
                    System.Diagnostics.Debug.WriteLine("KCOM_API - SavePageMarkupData set mlmarkup_data : " + ex.ToString());
1461
                    return false;
1462
                }
1463
            }
1464
            return true;
1465
        }
1466

    
1467
        //[OperationContract]
1468
        //public long AddMarkupDataGroup(MARKUP_DATA_GROUP mARKUP_DATA_GROUP, string ProjectNo)
1469
        //{
1470
        //    try
1471
        //    {
1472
        //        using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1473
        //        {
1474
        //            Entity.AddToMARKUP_DATA_GROUP(mARKUP_DATA_GROUP);
1475
        //            //MARKUP_DATA_GROUP tt = Entity.MARKUP_DATA_GROUP.Where(info => info.ID == id).FirstOrDefault();
1476
        //            Entity.SaveChanges();
1477

    
1478
        //            return Entity.MARKUP_DATA_GROUP.ToList().LastOrDefault().ID;
1479
        //        }
1480
        //    }
1481
        //    catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1482
        //    {
1483
        //        return 0;
1484
        //    }
1485
        //}
1486
        //[OperationContract]
1487
        //public bool UpdateMarkupDataGroup(long Group_ID, string ProjectNo)
1488
        //{
1489
        //    try
1490
        //    {
1491
        //        using (CIEntities Entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
1492
        //        {
1493
        //            var UpdateItem = Entity.MARKUP_DATA_GROUP.Where(info => info.ID == Group_ID).FirstOrDefault();
1494
        //            UpdateItem.STATE = 1;
1495
        //            Entity.SaveChanges();
1496
        //        }
1497
        //    }
1498
        //    catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1499
        //    {
1500
        //        return false;
1501
        //    }
1502
        //    return true;
1503
        //}
1504
        [OperationContract]
1505
        public bool UpdateMarkupData(string CommentID, long Group_ID, string ProjectNo)
1506
        {
1507
            try
1508
            {
1509
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1510
                using (CIEntities Entity = new CIEntities(sCIConnString))
1511
                {
1512
                    var UpdateItem = Entity.MARKUP_DATA.Where(info => info.ID == CommentID).FirstOrDefault();
1513
                    //UpdateItem.GROUP_ID = Group_ID;
1514
                    Entity.SaveChanges();
1515
                }
1516
            }
1517
            catch (Exception ex)
1518
            {
1519
                System.Diagnostics.Debug.WriteLine("KCOM_API - UpdateMarkupData: " + ex.ToString());
1520
                return false;
1521
            }
1522
            return true;
1523
        }
1524

    
1525
        [OperationContract]
1526
        public bool SaveSymbol(SYMBOL_PRIVATE symbol_private)
1527
        {
1528
            try
1529
            {
1530
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1531
                using (KCOMDataModel.DataModel.KCOMEntities uc = new KCOMDataModel.DataModel.KCOMEntities(sConnString))
1532
                {
1533
                    uc.AddToSYMBOL_PRIVATE(symbol_private);
1534
                    uc.SaveChanges();
1535
                }
1536
            }
1537
            catch (Exception ex)
1538
            {
1539
                System.Diagnostics.Debug.WriteLine("KCOM_API - SaveSymbol: " + ex.ToString());
1540
                return false;
1541
            }
1542
            return true;
1543
        }
1544
        [OperationContract]
1545
        public bool AddPublicSymbol(SYMBOL_PUBLIC symbol)
1546
        {
1547
            try
1548
            {
1549
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1550
                using (KCOMDataModel.DataModel.KCOMEntities uc = new KCOMDataModel.DataModel.KCOMEntities(sConnString))
1551
                {
1552
                    uc.AddToSYMBOL_PUBLIC(symbol);
1553
                    uc.SaveChanges();
1554
                }
1555
            }
1556
            catch (Exception ex)
1557
            {
1558
                System.Diagnostics.Debug.WriteLine("KCOM_API - AddPublicSymbol: " + ex.ToString());
1559
                return false;
1560
            }
1561
            return true;
1562
        }
1563
        [OperationContract]
1564
        public bool DeleteSymbol(string symbol_id, int type)
1565
        {
1566
            try
1567
            {
1568
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1569
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
1570
                {
1571
                    if (type == 0)
1572
                    {
1573
                        string delItem_ID = symbol_id;
1574
                        var delitem = Entity.SYMBOL_PRIVATE.Where(data => data.ID == delItem_ID).FirstOrDefault();
1575
                        Entity.SYMBOL_PRIVATE.DeleteObject(delitem);
1576
                        Entity.SaveChanges();
1577
                    }
1578
                    else
1579
                    {
1580
                        string delItem_ID = symbol_id;
1581
                        var delitem = Entity.SYMBOL_PUBLIC.Where(data => data.ID == delItem_ID).FirstOrDefault();
1582
                        Entity.SYMBOL_PUBLIC.DeleteObject(delitem);
1583
                        Entity.SaveChanges();
1584
                    }
1585
                }
1586
            }
1587
            catch (Exception ex)
1588
            {
1589
                System.Diagnostics.Debug.WriteLine("KCOM_API - DeleteSymbol : " + ex.ToString());
1590

    
1591
                return false;
1592
            }
1593
            return true;
1594
        }
1595

    
1596
        [OperationContract]
1597
        public bool RenameSymbol(string symbol_id, string name, int type)
1598
        {
1599
            try
1600
            {
1601
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
1602
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
1603
                {
1604
                    if (type == 0)
1605
                    {
1606
                        var UpdateItem = Entity.SYMBOL_PRIVATE.Where(info => info.ID == symbol_id).FirstOrDefault();
1607
                        UpdateItem.NAME = name;
1608
                        Entity.SaveChanges();
1609
                    }
1610
                    else
1611
                    {
1612
                        var UpdateItem = Entity.SYMBOL_PUBLIC.Where(info => info.ID == symbol_id).FirstOrDefault();
1613
                        UpdateItem.NAME = name;
1614
                        Entity.SaveChanges();
1615
                    }
1616
                }
1617
            }
1618
            catch (Exception ex)
1619
            {
1620
                System.Diagnostics.Debug.WriteLine("KCOM_API - RenameSymbol: " + ex.ToString());
1621
                return false;
1622
            }
1623
            return true;
1624
        }
1625

    
1626
        [OperationContract]
1627
        public bool AddCheckListHistory(string project_no, CHECK_LIST_HISTORY Check_History)
1628
        {
1629
            try
1630
            {
1631
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1632
                using (CIEntities Entity = new CIEntities(sCIConnString))
1633
                {
1634
                    Entity.CHECK_LIST_HISTORY.AddObject(Check_History);
1635
                    Entity.SaveChanges();  
1636
                }
1637
            }
1638
            catch (Exception ex)
1639
            {
1640
                System.Diagnostics.Debug.WriteLine("KCOM_API - AddCheckListHistory: " + ex.ToString());
1641
                return false;
1642
            }
1643
            return true;
1644
        }
1645
        [OperationContract]
1646
        public bool SaveCheckListHistory(string project_no, string rev, CHECK_LIST_HISTORY Check_History)
1647
        {
1648
            try
1649
            {
1650
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1651
                using (CIEntities Entity = new CIEntities(sCIConnString))
1652
                {
1653
                    var item = Entity.CHECK_LIST_HISTORY.Where(info => info.REVISION == rev).FirstOrDefault();
1654
                    item = Check_History;
1655
                    Entity.SaveChanges();
1656
                }
1657
            }
1658
            catch (Exception ex)
1659
            {
1660
                System.Diagnostics.Debug.WriteLine("KCOM_API - SaveCheckListHistory: " + ex.ToString());
1661
                return false;
1662
            }
1663
            return true;
1664
        }
1665
        [OperationContract]
1666
        public bool SaveCheckList(string project_no, string _id, CHECK_LIST Check_value)
1667
        {
1668
            try
1669
            {
1670
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1671
                using (CIEntities Entity = new CIEntities(sCIConnString))
1672
                {
1673
                    var item = Entity.CHECK_LIST.Where(info => info.ID == _id).FirstOrDefault();
1674
                    item.TODOLIST = Check_value.TODOLIST;
1675
                    item.REMARK = Check_value.REMARK;
1676
                    item.STATUS = Check_value.STATUS;
1677
                    item.VENDOR = Check_value.VENDOR;
1678
                    item.REPLY = Check_value.REPLY;
1679
                    item.IMAGE_URL = Check_value.IMAGE_URL;
1680
                    item.IMAGE_ANCHOR = Check_value.IMAGE_ANCHOR;
1681
                    item.UPDATE_TIME = Check_value.UPDATE_TIME;
1682
                    if(Check_value.STATUS == "False")
1683
                    {
1684
                        item.STATUS_DESC_OPEN = Check_value.STATUS_DESC_OPEN;
1685
                    }
1686
                    else
1687
                    {
1688
                        item.STATUS_DESC_CLOSE = Check_value.STATUS_DESC_CLOSE;
1689
                    }                     
1690
                    Entity.SaveChanges();
1691
                }
1692
            }
1693
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1694
                return false;
1695
            }
1696
            return true;
1697
        }
1698
        [OperationContract]
1699
        public bool AddCheckList(string project_no, CHECK_LIST Check_value)
1700
        {
1701
            try
1702
            {
1703
               
1704
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1705
                using (CIEntities Entity = new CIEntities(sCIConnString))
1706
                {
1707
                    Entity.CHECK_LIST.AddObject(Check_value);
1708
                    Entity.SaveChanges();
1709
                }
1710
            }
1711
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1712
                return false;
1713
            }
1714
            return true;
1715
        }
1716

    
1717
        [OperationContract]
1718
        public CHECK_LIST GetCheckList(string project_no, string _id)
1719
        {
1720
            CHECK_LIST Check_value = new CHECK_LIST();
1721
            try
1722
            {
1723
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1724
                using (CIEntities Entity = new CIEntities(sCIConnString))
1725
                {
1726
                    Check_value = Entity.CHECK_LIST.Where(info => info.ID == _id).FirstOrDefault();
1727
                }
1728
            }
1729
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1730
                return null;
1731
            }
1732
            return Check_value;
1733
        }
1734
        [OperationContract]
1735
        public List<CHECK_LIST> GetUserCheckList(string project_no, string user_id, string doc_no)
1736
        {
1737
            List<CHECK_LIST> list = new List<CHECK_LIST>();
1738
            try
1739
            {
1740
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1741
                using (CIEntities Entity = new CIEntities(sCIConnString))
1742
                {
1743
                    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();
1744
                }
1745
            }
1746
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1747
                return null;
1748
            }
1749
            return list;
1750
        }
1751
        [OperationContract]
1752
        public List<CHECK_LIST_HISTORY> GetCheckListHistory(string project_no, string _id)
1753
        {
1754
            List<CHECK_LIST_HISTORY> history = new List<CHECK_LIST_HISTORY>();
1755
            try
1756
            {
1757
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1758
                using (CIEntities Entity = new CIEntities(sCIConnString))
1759
                {
1760
                    history = Entity.CHECK_LIST_HISTORY.Where(data => data.CHECKLIST_ID == _id).ToList();
1761
                }
1762
            }
1763
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1764
                return null;
1765
            }
1766
            return history;
1767
        }
1768
        [OperationContract]
1769
        public CHECK_LIST_HISTORY GetCheckListHistoryFirstOrDefault(string project_no, string checklist_id, string rev)
1770
        {
1771
            CHECK_LIST_HISTORY Check_Item = new CHECK_LIST_HISTORY();
1772
            try
1773
            {
1774
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1775
                using (CIEntities Entity = new CIEntities(sCIConnString))
1776
                {   
1777
                    Check_Item = Entity.CHECK_LIST_HISTORY.Where(info => info.CHECKLIST_ID == checklist_id && info.REVISION == rev).FirstOrDefault();
1778
                }
1779
            }
1780
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1781
                return null;
1782
            }
1783
            return Check_Item;
1784
        }
1785
        [OperationContract]
1786
        public bool SavePageAngle(string project_no, List<DOCPAGE> _mldocpage)
1787
        {
1788
            try
1789
            {
1790
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1791
                using (CIEntities Entity = new CIEntities(sCIConnString))
1792
                {
1793
                    KCOMDataModel.DataModel.DOCPAGE _docpage = new KCOMDataModel.DataModel.DOCPAGE();
1794
                    _mldocpage.ForEach(data =>
1795
                    {
1796
                        _docpage = (from info in Entity.DOCPAGE
1797
                                    where info.ID == data.ID
1798
                                    select info).FirstOrDefault();
1799

    
1800
                        if (_docpage.PAGE_ANGLE != data.PAGE_ANGLE)
1801
                        {
1802
                            _docpage.PAGE_ANGLE = data.PAGE_ANGLE;
1803
                        }
1804
                    });
1805

    
1806
                    Entity.SaveChanges();
1807
                }
1808
            }
1809
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1810
                return false;
1811
            }
1812
            return true;
1813
        }
1814

    
1815
        [OperationContract]
1816
        public MARKUP_INFO GetMarkupInfo(string project_no, string _id)
1817
        {
1818
            MARKUP_INFO markupInfo = new MARKUP_INFO();
1819

    
1820
            try
1821
            {
1822
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1823
                using (CIEntities Entity = new CIEntities(sCIConnString))
1824
                {
1825
                    markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1826
                }
1827
            }
1828
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1829
                return null;
1830
            }
1831
            return markupInfo;
1832
        }
1833

    
1834
        [OperationContract]
1835
        public List<string> GetMarkupDataListperPage(string project_no, string _markupinfoid, int _pageNo)
1836
        {
1837
            List<string> markupdata = new List<string>();
1838
            MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1839
            try
1840
            {
1841
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1842
                using (CIEntities Entity = new CIEntities(sCIConnString))
1843
                {
1844
                    markup_info_version = (from version in Entity.MARKUP_INFO_VERSION
1845
                                           where version.MARKUPINFO_ID == _markupinfoid
1846
                                           orderby version.CREATE_DATE descending
1847
                                           select version).First();
1848
                    markupdata = (from data in Entity.MARKUP_DATA
1849
                                  where data.MARKUPINFO_VERSION_ID == markup_info_version.ID && data.PAGENUMBER == _pageNo
1850
                                  select data.DATA).ToList();
1851
                }
1852
            }
1853
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1854
                return null;
1855
            }
1856
            return markupdata;
1857
        }
1858

    
1859
        [OperationContract]
1860
        public bool AddMarkupInfo(string project_no, MARKUP_INFO value)
1861
        {
1862
            try
1863
            {
1864
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1865
                using (CIEntities Entity = new CIEntities(sCIConnString))
1866
                {
1867
                    Entity.MARKUP_INFO.AddObject(value);
1868
                    Entity.SaveChanges();
1869
                }
1870
            }
1871
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1872
                return false;
1873
            }
1874
            return true;
1875
        }
1876

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

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

    
1913
        [OperationContract]
1914
        public bool AvoidMarkupInfo(string project_no, string _doc_id)
1915
        {
1916
            try
1917
            {
1918
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1919
                using (CIEntities Entity = new CIEntities(sCIConnString))
1920
                {
1921
                    var item = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1922
                    item.AVOID_CONSOLIDATE = 1;
1923
                    Entity.SaveChanges();
1924
                }
1925
            }
1926
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1927
                return false;
1928
            }
1929
            return true;
1930
        }
1931

    
1932
        [OperationContract]
1933
        public bool SaveMarkupInfo(string project_no, string _id, MARKUP_INFO value)
1934
        {
1935
            try
1936
            {
1937
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1938
                using (CIEntities Entity = new CIEntities(sCIConnString))
1939
                {
1940
                    var item = Entity.MARKUP_INFO.Where(info => info.ID == _id).FirstOrDefault();
1941
                    item = value;                    
1942
                    Entity.SaveChanges();
1943
                }
1944
            }
1945
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1946
                return false;
1947
            }
1948
            return true;
1949
        }
1950
        [OperationContract]
1951
        public List<MARKUP_DATA> GetMarkupDataList(string project_no, string _versionid)
1952
        {
1953
            List<MARKUP_DATA> mlresult = new List<MARKUP_DATA>();
1954

    
1955
            try
1956
            {
1957
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1958
                using (CIEntities Entity = new CIEntities(sCIConnString))
1959
                {
1960
                    mlresult = Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == _versionid).ToList();
1961
                }
1962
            }
1963
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
1964
                return null;
1965
            }
1966
            return mlresult;
1967
        }
1968

    
1969
        [OperationContract]
1970
        public bool Consolidate(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems)
1971
        {
1972
            try
1973
            {
1974
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
1975
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
1976
                using (CIEntities Entity = new CIEntities(sCIConnString))
1977
                {
1978
                    var markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id && entity.CONSOLIDATE == 1).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
1979
                    if (markupInfo != null)
1980
                    {
1981
                        markupInfo.AVOID_CONSOLIDATE = 1;
1982
                    }
1983

    
1984
                    foreach (MarkupInfoItem item in markupInfoItems)
1985
                    {
1986
                        Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == item.MarkupVersionID).ToList().ForEach(d =>
1987
                        {
1988
                            instanceDataSet.Add(d);
1989
                        });
1990
                    }
1991

    
1992
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
1993
                    info.ID = shortGuid();
1994
                    info.CONSOLIDATE = 1;
1995
                    info.CREATE_TIME = DateTime.Now;
1996
                    info.DOCINFO_ID = _doc_id;
1997
                    info.UPDATE_TIME = DateTime.Now;
1998
                    info.USER_ID = _user_id;
1999
                    info.AVOID_CONSOLIDATE = 0;
2000

    
2001
                    Entity.MARKUP_INFO.AddObject(info);
2002
                    Entity.SaveChanges();
2003

    
2004

    
2005
                    KCOMDataModel.DataModel.MARKUP_INFO_VERSION info2 = new KCOMDataModel.DataModel.MARKUP_INFO_VERSION
2006
                    {
2007
                        ID = shortGuid(),
2008
                        CREATE_DATE = DateTime.Now,
2009
                        MARKUP_INFO = info,
2010
                    };
2011
                    Entity.SaveChanges();
2012

    
2013
                    foreach (var item in instanceDataSet)
2014
                    {
2015
                        Entity.MARKUP_DATA.AddObject(new KCOMDataModel.DataModel.MARKUP_DATA
2016
                        {
2017
                            ID = shortGuid(),
2018
                            DATA = item.DATA,
2019
                            DATA_TYPE = item.DATA_TYPE,
2020
                            PAGENUMBER = item.PAGENUMBER,
2021
                            MARKUP_INFO_VERSION = info2,
2022
                            SYMBOL_ID = item.SYMBOL_ID,
2023
                            //GROUP_ID = item.GROUP_ID
2024
                        });
2025
                    }
2026
                    Entity.SaveChanges();
2027

    
2028

    
2029
                }
2030
            }
2031
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2032
                return false;
2033
            }
2034
            return true;
2035
        }
2036

    
2037

    
2038
        [OperationContract]
2039
        public FinalPDFResult ConsolidateMergedPDF(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems, string ProjectNo, string DocInfoID, string CreateUserID)
2040
        {
2041
            bool consolidate = false;
2042
            try
2043
            {
2044
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
2045
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2046
                using (CIEntities Entity = new CIEntities(sCIConnString))
2047
                {
2048
                    var markupInfo = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id).OrderByDescending(i => i.CONSOLIDATE).OrderByDescending(j => j.CREATE_TIME).FirstOrDefault();
2049
                    if (markupInfo.CONSOLIDATE == 1)
2050
                    {
2051
                        markupInfo.AVOID_CONSOLIDATE = 1;
2052
                    }
2053

    
2054
                    foreach (MarkupInfoItem item in markupInfoItems)
2055
                    {
2056
                        Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == item.MarkupVersionID).ToList().ForEach(d =>
2057
                        {
2058
                            instanceDataSet.Add(d);
2059
                        });
2060
                    }
2061

    
2062
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
2063
                    info.ID = shortGuid();
2064
                    info.CONSOLIDATE = 1;
2065
                    info.CREATE_TIME = DateTime.Now;
2066
                    info.DOCINFO_ID = _doc_id;
2067
                    info.UPDATE_TIME = DateTime.Now;
2068
                    info.USER_ID = _user_id;
2069
                    info.AVOID_CONSOLIDATE = 0;
2070

    
2071
                    Entity.MARKUP_INFO.AddObject(info);
2072
                    Entity.SaveChanges();
2073

    
2074

    
2075
                    KCOMDataModel.DataModel.MARKUP_INFO_VERSION info2 = new KCOMDataModel.DataModel.MARKUP_INFO_VERSION
2076
                    {
2077
                        ID = shortGuid(),
2078
                        CREATE_DATE = DateTime.Now,
2079
                        MARKUP_INFO = info,
2080
                    };
2081
                    Entity.SaveChanges();
2082

    
2083
                    foreach (var item in instanceDataSet)
2084
                    {
2085
                        Entity.MARKUP_DATA.AddObject(new KCOMDataModel.DataModel.MARKUP_DATA
2086
                        {
2087
                            ID = shortGuid(),
2088
                            DATA = item.DATA,
2089
                            DATA_TYPE = item.DATA_TYPE,
2090
                            PAGENUMBER = item.PAGENUMBER,
2091
                            MARKUP_INFO_VERSION = info2,
2092
                            SYMBOL_ID = item.SYMBOL_ID,
2093
                            //GROUP_ID = item.GROUP_ID
2094
                        });
2095
                    }
2096
                    Entity.SaveChanges();
2097

    
2098

    
2099
                }
2100
                consolidate = true;
2101
            }
2102
            catch (Exception ex)
2103
            {
2104
                System.Diagnostics.Debug.WriteLine(ex);
2105
                consolidate = false;
2106
            }
2107

    
2108
            FinalPDFResult _result = new FinalPDFResult();
2109
            if (consolidate == true)
2110
            {
2111
                RemFinalPDFObject remObj = null;
2112
                try
2113
                {
2114
                    string _finalID = shortGuid();
2115
                    int _DocTotalPages = -1;
2116
                    string docItemId;
2117

    
2118
                    string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2119
                    using (CIEntities _ci = new CIEntities(sCIConnString))
2120
                    {
2121
                        var _doc = _ci.DOCINFO.Where(info => info.ID == DocInfoID);
2122

    
2123
                        if (_doc.Count() > 0)
2124
                        {
2125
                            _DocTotalPages = _doc.First().PAGE_COUNT;
2126
                            docItemId = _doc.First().DOCUMENT_ID;
2127
                        }
2128
                        else
2129
                        {
2130
                            _result.Status = FinalStatus.Error;
2131
                            _result.Exception = "페이지 정보를 가져올 수 없습니다.";
2132
                            return _result;
2133
                        }
2134
                    }
2135

    
2136
                    var Items = GetMarkupInfoItems(ProjectNo, DocInfoID);
2137
                    if (_DocTotalPages > 0)
2138
                    {
2139
                        var item2 = Items.Cast<MarkupInfoItem>().Where(d => d.Consolidate == 1 && d.AvoidConsolidate == 0).FirstOrDefault();
2140
                        FINAL_PDF fm = new FINAL_PDF()
2141
                        {
2142
                            ID = _finalID,
2143
                            PROJECT_NO = ProjectNo,
2144
                            DOCINFO_ID = DocInfoID,
2145
                            DOCUMENT_ID = docItemId,
2146
                            MARKUPINFO_ID = item2.MarkupInfoID,
2147
                            CREATE_USER_ID = CreateUserID,
2148
                            TOTAL_PAGE = _DocTotalPages,
2149
                            CREATE_DATETIME = DateTime.Now,
2150
                            STATUS = (int)IFinalPDF.FinalStatus.Insert
2151
                        };
2152

    
2153
                        string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2154
                        using (KCOMEntities _entity = new KCOMEntities(sConnString))
2155
                        {
2156
                            _entity.AddToFINAL_PDF(fm);
2157
                            _entity.SaveChanges(System.Data.Objects.SaveOptions.AcceptAllChangesAfterSave);
2158
                        };
2159

    
2160
                        System.Runtime.Remoting.Channels.IChannel _ch = System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp");
2161
                        if (_ch == null)
2162
                        {
2163
                            chan = new TcpChannel();
2164
                            _ChanID = chan.ChannelName;
2165
                            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan, false);
2166
                            // Create an instance of the remote object
2167

    
2168
                            using (KCOMEntities ec = new KCOMEntities(sConnString))
2169
                            {
2170

    
2171
                                //remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
2172
                                //                          "tcp://localhost:9092/remFinalPDF");
2173
                                remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject),
2174
                                                          //"tcp://192.168.0.67:9092/remFinalPDF");
2175
                                                          "tcp://192.168.0.67:9092/remFinalPDF");
2176
                            }
2177

    
2178
                            //"tcp://localhost:8080/remFinalPDF");
2179

    
2180
                            _result = remObj.SetFinalPDF(ProjectNo, _finalID);
2181
                            _result.FinalID = _finalID;
2182
                            _result.Status = FinalStatus.Success;
2183

    
2184
                            //MarkupToPDF.MarkupToPDF fa = new MarkupToPDF.MarkupToPDF();
2185
                            //fa.MakeFinalPDF(fm);
2186
                        }
2187
                        else
2188
                        {
2189
                            _ChanID = _ch.ChannelName;
2190
                        }
2191
                    }
2192
                }
2193
                catch (Exception ex)
2194
                {
2195
                    _result.Status = FinalStatus.Error;
2196

    
2197
                    if (ex.GetType() == typeof(System.Net.Sockets.SocketException))
2198
                        _result.Exception = "Final Server Not Connection";
2199
                }
2200
                finally
2201
                {
2202
                    remObj = null;
2203
                    if (System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp") != null)
2204
                        System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(chan);
2205

    
2206
                    GC.Collect(2);
2207
                }
2208
            }
2209
            return _result;
2210
        }
2211
        [OperationContract]
2212
        public bool TeamConsolidate(string project_no, string _user_id, string _doc_id, List<MarkupInfoItem> markupInfoItems)
2213
        {
2214
            try
2215
            {
2216
                List<KCOMDataModel.DataModel.MARKUP_DATA> instanceDataSet = new List<KCOMDataModel.DataModel.MARKUP_DATA>();
2217
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2218
                using (CIEntities Entity = new CIEntities(sCIConnString))
2219
                {
2220
                    var members = GetMemberQuery(Entity, _user_id);
2221

    
2222
                    string user_dept = "";
2223

    
2224
                    if(members.Count() > 0)
2225
                    {
2226
                        user_dept = members.First().DEPARTMENT;
2227
                    }
2228
                    
2229
                    var markupInfos = Entity.MARKUP_INFO.Where(entity => entity.DOCINFO_ID == _doc_id && entity.PART_CONSOLIDATE == 1)
2230
                                        .OrderByDescending(j => j.CREATE_TIME).ToList();
2231

    
2232
                    foreach (var markupinfo in markupInfos)
2233
                    {
2234
                        string markupdept = "";
2235

    
2236
                        var markupMembers = GetMemberQuery(Entity, markupinfo.USER_ID);
2237

    
2238
                        if (markupMembers.Count() > 0)
2239
                        {
2240
                            markupdept = markupMembers.First().DEPARTMENT;
2241
                        }
2242

    
2243
                        if (user_dept == markupdept)
2244
                        {
2245
                            markupinfo.AVOID_CONSOLIDATE = 1;
2246
                        }
2247
                    }
2248

    
2249
                    foreach (MarkupInfoItem item in markupInfoItems)
2250
                    {
2251
                        Entity.MARKUP_DATA.Where(data => data.MARKUPINFO_VERSION_ID == item.MarkupVersionID).ToList().ForEach(d =>
2252
                        {
2253
                            instanceDataSet.Add(d);
2254
                        });
2255
                    }
2256

    
2257
                    KCOMDataModel.DataModel.MARKUP_INFO info = new KCOMDataModel.DataModel.MARKUP_INFO();
2258
                    info.ID = shortGuid();
2259
                    info.PART_CONSOLIDATE = 1;
2260
                    info.CREATE_TIME = DateTime.Now;
2261
                    info.DOCINFO_ID = _doc_id;
2262
                    info.UPDATE_TIME = DateTime.Now;
2263
                    info.USER_ID = _user_id;
2264
                    info.AVOID_CONSOLIDATE = 0;
2265

    
2266
                    Entity.MARKUP_INFO.AddObject(info);
2267
                    Entity.SaveChanges();
2268

    
2269

    
2270
                    KCOMDataModel.DataModel.MARKUP_INFO_VERSION info2 = new KCOMDataModel.DataModel.MARKUP_INFO_VERSION
2271
                    {
2272
                        ID = shortGuid(),
2273
                        CREATE_DATE = DateTime.Now,
2274
                        MARKUP_INFO = info,
2275
                    };
2276
                    Entity.SaveChanges();
2277

    
2278
                    foreach (var item in instanceDataSet)
2279
                    {
2280
                        Entity.MARKUP_DATA.AddObject(new KCOMDataModel.DataModel.MARKUP_DATA
2281
                        {
2282
                            ID = shortGuid(),
2283
                            DATA = item.DATA,
2284
                            DATA_TYPE = item.DATA_TYPE,
2285
                            PAGENUMBER = item.PAGENUMBER,
2286
                            MARKUP_INFO_VERSION = info2,
2287
                            SYMBOL_ID = item.SYMBOL_ID,
2288
                            //GROUP_ID = item.GROUP_ID
2289
                        });
2290
                    }
2291
                    Entity.SaveChanges();
2292

    
2293

    
2294
                }
2295
            }
2296
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2297
                return false;
2298
            }
2299
            return true;
2300
        }
2301

    
2302
        [OperationContract]
2303
        [ServiceKnownType(typeof(MEMBER))]
2304
        public MEMBER GetMember(string project_no, string user_id)
2305
        {
2306
            MEMBER rstmember = null;
2307
            try
2308
            {
2309
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2310
                using (CIEntities Entity = new CIEntities(sCIConnString))
2311
                {
2312
                    var members = GetMemberQuery(Entity, user_id);
2313

    
2314
                    if(members.Count() > 0)
2315
                    {
2316
                        rstmember = members.First();
2317
                    }
2318
                }
2319
            }
2320
            catch (Exception ex)
2321
            {
2322
                return null;
2323
            }
2324
            return rstmember;
2325
        }
2326

    
2327
        private  List<MEMBER> GetMemberQuery(System.Data.Objects.ObjectContext context, string UserID)
2328
        {
2329
            List<MEMBER> result = new List<MEMBER>();
2330

    
2331
            try
2332
            {
2333
                string query = "SELECT members.ID,members.NAME,members.DEPARTMENT FROM CIEntities.MEMBER as members where members.ID = @userId";
2334

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

    
2337
                System.Data.Objects.ObjectQuery<System.Data.Common.DbDataRecord> memberQuery
2338
                              = context.CreateQuery<System.Data.Common.DbDataRecord>(query, param);
2339

    
2340
                if (memberQuery.Count() > 0)
2341
                {
2342
                    foreach (var dataRecord in memberQuery)
2343
                    {
2344
                        MEMBER member = new MEMBER();
2345

    
2346
                        string userName = dataRecord["NAME"]?.ToString().Trim();
2347
                        string ID = dataRecord["ID"]?.ToString().Trim();
2348
                        string depatment = dataRecord["DEPARTMENT"]?.ToString().Trim();
2349

    
2350
                        member.NAME = userName;
2351
                        member.ID = ID;
2352
                        member.DEPARTMENT = depatment;
2353

    
2354
                        result.Add(member);
2355
                    }
2356
                }
2357
            }
2358
            catch (Exception ex)
2359
            {
2360
                throw new Exception("GetMember(System.Data.Objects.ObjectContext context, string UserID) " , ex);
2361
            }
2362

    
2363
            return result;
2364
        }
2365

    
2366
        [WebMethod]
2367
        [OperationContract]
2368
        public List<SYMBOL_PRIVATE> GetSymbolList(string user_id)
2369
        {
2370
            List<SYMBOL_PRIVATE> Custom_List = new List<SYMBOL_PRIVATE>();
2371
            try
2372
            {
2373
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2374
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2375
                {
2376
                    Custom_List = Entity.SYMBOL_PRIVATE.Where(data => data.MEMBER_USER_ID == user_id).ToList();
2377
                }
2378
            }
2379
            catch (Exception ex)
2380
            {
2381
                return null;
2382
            }
2383
            return Custom_List;
2384
        }
2385
        [OperationContract]
2386
        public List<string> GetPublicSymbolDeptList()
2387
        {
2388
            List<string> Custom_List = new List<string>();
2389
            try
2390
            {
2391
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2392
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2393
                {
2394
                    Custom_List = Entity.SYMBOL_PUBLIC.Select(data => data.DEPARTMENT).Distinct().ToList();
2395
                }
2396
            }
2397
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2398
                return null;
2399
            }
2400
            return Custom_List;
2401
        }
2402
        [OperationContract]
2403
        public List<SYMBOL_PUBLIC> GetPublicSymbolList(string dept)
2404
        {
2405
            List<SYMBOL_PUBLIC> Custom_List = new List<SYMBOL_PUBLIC>();
2406
            try
2407
            {
2408
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2409
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2410
                {
2411
                    if(!string.IsNullOrEmpty(dept))
2412
                    {
2413
                        Custom_List = Entity.SYMBOL_PUBLIC.Where(data => data.DEPARTMENT == dept).ToList();
2414
                    }
2415
                    else
2416
                    {
2417
                        Custom_List = Entity.SYMBOL_PUBLIC.ToList();
2418
                    }
2419
                    
2420
                }
2421
            }
2422
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2423
                return null;
2424
            }
2425
            return Custom_List;
2426
        }
2427

    
2428
        /// <summary>
2429
        /// 
2430
        /// </summary>
2431
        /// <param name="id">symbol id</param>
2432
        /// <param name="type"> 0 : PRIVATE, 1 : PUBLIC</param>
2433
        /// <returns></returns>
2434
        [OperationContract]
2435
        public string GetSymbolData(string id, int type)
2436
        {
2437
            string result;
2438
            try
2439
            {
2440
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2441
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2442
                {
2443
                    if(type == 0)
2444
                    {
2445
                        result = Entity.SYMBOL_PRIVATE.Where(data => data.ID == id).FirstOrDefault().DATA;
2446
                    }
2447
                    else
2448
                    {
2449
                        result = Entity.SYMBOL_PUBLIC.Where(data => data.ID == id).FirstOrDefault().DATA;
2450
                    }
2451
                }
2452
            }
2453
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2454
                return null;
2455
            }
2456
            return result;
2457
        }
2458
        [OperationContract]
2459
        public string GetSymbolImageURL(string id, int type)
2460
        {
2461
            string result;
2462
            try
2463
            {
2464
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2465
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2466
                {
2467
                    if (type == 0)
2468
                    {
2469
                        result = Entity.SYMBOL_PRIVATE.Where(data => data.ID == id).FirstOrDefault().IMAGE_URL;
2470
                    }
2471
                    else
2472
                    {
2473
                        result = Entity.SYMBOL_PUBLIC.Where(data => data.ID == id).FirstOrDefault().IMAGE_URL;
2474
                    }
2475
                }
2476
            }
2477
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2478
                return null;
2479
            }
2480
            return result;
2481
        }
2482

    
2483
        [OperationContract]
2484
        public string GetSignData(string project_no, string user_id)
2485
        {
2486
            string result = null;
2487
            try
2488
            {
2489
                string ifsign = getEnsembleSign(user_id);
2490
                if (string.IsNullOrEmpty(ifsign))
2491
                {
2492
                    string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2493
                    var ModelWFConnectionString = sCIConnString;
2494
                    if (null != ModelWFConnectionString)
2495
                    {
2496
                        using (CIEntities entity = new CIEntities(ModelWFConnectionString))
2497
                        {
2498
                            var _sign = entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == user_id);
2499
                            if (_sign.Count() > 0)
2500
                            {
2501
                                result = _sign.First().SIGN_STR;
2502
                            }
2503
                            else
2504
                            {
2505
                                return null;
2506
                            }
2507
                        }
2508
                    }
2509
                }
2510
                else
2511
                {
2512
                    result = ifsign;
2513
                }
2514

    
2515
            }
2516
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2517
                return null;
2518
            }
2519
            return result;
2520
        }
2521

    
2522
        [OperationContract]
2523
        public string GetSignStrokes(string project_no, string user_id)
2524
        {
2525
            string result = null;
2526
            try
2527
            {
2528
                string ifsign = getEnsembleSign(user_id);
2529
                if (string.IsNullOrEmpty(ifsign))
2530
                {
2531
                    string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2532
                    var ModelWFConnectionString = sCIConnString;
2533
                    if (null != ModelWFConnectionString)
2534
                    {
2535
                        using (CIEntities entity = new CIEntities(ModelWFConnectionString))
2536
                        {
2537
                            var _sign = entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == user_id);
2538
                            if (_sign.Count() > 0)
2539
                            {
2540
                                result = _sign.First().SIGN_STROKES;
2541
                            }
2542
                            else
2543
                            {
2544
                                return null;
2545
                            }
2546
                        }
2547
                    }
2548
                }
2549
                else
2550
                {
2551
                    result = ifsign;
2552
                }
2553

    
2554
            }
2555
            catch (Exception ex)
2556
            {
2557
                System.Diagnostics.Debug.WriteLine(ex);
2558
                return null;
2559
            }
2560
            return result;
2561
        }
2562

    
2563
        [OperationContract]
2564
        public int SetSignData(string user_id,string SignStr,int CropX,int CropY,int CropWidth,int CropHeight)
2565
        {
2566
            int result = -1;
2567

    
2568
            try
2569
            {
2570
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2571
                   
2572
                using (CIEntities entity = new CIEntities(sCIConnString))
2573
                {
2574
                    var _sign = entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == user_id);
2575

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

    
2578
                    if (_sign.Count() > 0)
2579
                    {
2580
                        _sign.First().SIGN_STR = cropImg;
2581
                        _sign.First().MODIFY_DATE = DateTime.Now;
2582
                    }
2583
                    else
2584
                    {
2585
                        entity.SIGN_INFO.AddObject(new SIGN_INFO
2586
                        {
2587
                            ID = shortGuid(),
2588
                            MEMBER_USER_ID = user_id,
2589
                            CREATE_DATE = DateTime.Now,
2590
                            SIGN_STR = cropImg
2591
                        });
2592
                    }
2593

    
2594
                    result = entity.SaveChanges();
2595
                }
2596
            }
2597
            catch (Exception ex)
2598
            {
2599
                System.Diagnostics.Debug.WriteLine(ex);
2600
            }
2601
            return result;
2602
        }
2603

    
2604

    
2605
        [OperationContract]
2606
        public int SetSignStrokes(string user_id, string strokesData)
2607
        {
2608
            int result = -1;
2609

    
2610
            try
2611
            {
2612
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2613

    
2614
                using (CIEntities entity = new CIEntities(sCIConnString))
2615
                {
2616
                    var _sign = entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == user_id);
2617

    
2618
                    if (_sign.Count() > 0)
2619
                    {
2620
                        _sign.First().SIGN_STROKES = strokesData;
2621
                        _sign.First().MODIFY_DATE = DateTime.Now;
2622
                    }
2623
                    else
2624
                    {
2625
                        entity.SIGN_INFO.AddObject(new SIGN_INFO
2626
                        {
2627
                            ID = shortGuid(),
2628
                            MEMBER_USER_ID = user_id,
2629
                            CREATE_DATE = DateTime.Now,
2630
                            SIGN_STROKES = strokesData
2631
                    });
2632
                    }
2633

    
2634
                    result = entity.SaveChanges();
2635
                }
2636
            }
2637
            catch (Exception ex)
2638
            {
2639
                System.Diagnostics.Debug.WriteLine(ex);
2640
            }
2641
            return result;
2642
        }
2643

    
2644
        private byte[] SignatureCrop(string imgStr,int X,int Y,int Width,int Height)
2645
        {
2646
            using (System.IO.MemoryStream readStream = new System.IO.MemoryStream(Convert.FromBase64String(imgStr)))
2647
            {
2648
                using (System.Drawing.Image OriginalImage = System.Drawing.Image.FromStream(readStream))
2649
                {
2650
                    using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(Width, Height))
2651
                    {
2652
                        bmp.SetResolution(OriginalImage.HorizontalResolution, OriginalImage.VerticalResolution);
2653
                        using (System.Drawing.Graphics Graphic = System.Drawing.Graphics.FromImage(bmp))
2654
                        {
2655
                            Graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
2656
                            Graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
2657
                            Graphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
2658
                            Graphic.DrawImage(OriginalImage, new System.Drawing.Rectangle(0, 0, Width, Height), X, Y, Width, Height, System.Drawing.GraphicsUnit.Pixel);
2659
                            System.IO.MemoryStream ms = new System.IO.MemoryStream();
2660
                            bmp.Save(ms, OriginalImage.RawFormat);
2661
                            return ms.GetBuffer();
2662
                        }
2663
                    }
2664
                }
2665
            }
2666
        }
2667

    
2668
        [OperationContract]        
2669
        public string GetProjectName(string project_no)
2670
        {
2671
            string result = null;
2672

    
2673
            try
2674
            {
2675
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2676
                using (KCOMDataModel.DataModel.KCOMEntities Entity = new KCOMDataModel.DataModel.KCOMEntities(sConnString))
2677
                {
2678
                    result = Entity.RUN_PROJECTS.Where(i => i.PROJECT_NO == project_no).FirstOrDefault().PROJECT_NAME.ToString();
2679
                }
2680
            }
2681
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2682
                return null;
2683
            }
2684
            return result;
2685
        }
2686

    
2687
        [OperationContract]
2688
        public List<DOCUMENT_ITEM> GetPreRevSelect(string project_no, string doc_no, string current_rev)
2689
        {
2690
            List<DOCUMENT_ITEM> result = new List<DOCUMENT_ITEM>();
2691
            
2692
            try
2693
            {
2694
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2695
                using (CIEntities Entity = new CIEntities(sCIConnString))
2696
                {
2697
                    result = Entity.DOCUMENT_ITEM.Where(i => i.PROJECT_NO == project_no
2698
                    && i.DOCUMENT_NO == doc_no
2699
                    && i.REVISION != current_rev).OrderByDescending(i => i.GROUP_NO).ToList();
2700
                }
2701
            }
2702
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2703
                return null;
2704
            }
2705
            return result;
2706
        }
2707

    
2708
        [OperationContract]
2709
        public DOCINFO GetDocInfoOneSelect(string project_no, string doc_id)
2710
        {
2711
            DOCINFO docinfo = null;
2712

    
2713
            try
2714
            {
2715
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2716
                using (CIEntities Entity = new CIEntities(sCIConnString))
2717
                {
2718
                    docinfo = (from info in Entity.DOCINFO
2719
                              where info.DOCUMENT_ID == doc_id
2720
                              && info.PROJECT_NO == project_no
2721
                              select info).First();
2722
                }
2723
            }
2724
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2725
                return null;
2726
            }
2727
            return docinfo;
2728
        }
2729

    
2730
        [OperationContract]
2731
        public List<MarkupInfoItem> GetPrintDocItemList(string project_no, string doc_id, List<MarkupInfoItem> _markupInfoList)
2732
        {
2733
            MarkupInfoItem _result = null;
2734
            List<MarkupInfoItem> markupinfo = new List<MarkupInfoItem>();
2735
            try
2736
            {
2737
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2738
                using (CIEntities Entity = new CIEntities(sCIConnString))
2739
                {
2740
                    var docitem = (from info in Entity.DOCINFO
2741
                               where info.DOCUMENT_ID == doc_id
2742
                               && info.PROJECT_NO == project_no
2743
                               select info).First();
2744

    
2745
                    foreach (MARKUP_INFO markinfo in docitem.MARKUP_INFO)
2746
                    {
2747
                        var members = GetMemberQuery(Entity, markinfo.USER_ID);
2748

    
2749
                        MEMBER member = new MEMBER();
2750

    
2751
                        if (members.Count() > 0)
2752
                        {
2753
                            member = members.First();
2754
                        }
2755

    
2756
                        string displaycolor = null;
2757

    
2758
                        try
2759
                        {
2760
                            displaycolor = _markupInfoList.Where(info => info.MarkupInfoID == markinfo.ID).First().DisplayColor;
2761
                        }
2762
                        catch (Exception ex)
2763
                        {
2764
                            System.Diagnostics.Debug.WriteLine("KCOM_API - GetPrintDocItemList displaycolor : " + ex.ToString());
2765

    
2766
                            displaycolor = "#FFFFFF";
2767
                        }
2768
                        
2769
                        _result = new MarkupInfoItem
2770
                        {
2771
                            MarkupInfoID = markinfo.ID,
2772
                            Consolidate = markinfo.CONSOLIDATE,
2773
                            CreateTime = markinfo.UPDATE_TIME.HasValue ? markinfo.UPDATE_TIME.Value : markinfo.CREATE_TIME,
2774
                            DisplayColor = displaycolor,
2775
                            UserID = markinfo.USER_ID,
2776
                            UserName = member.NAME,
2777
                            Depatment = member.DEPARTMENT,
2778
                        };
2779

    
2780
                        _result.MarkupList = new List<IKCOM.MarkupItem>();
2781
                        var markup_Version = markinfo.MARKUP_INFO_VERSION.OrderByDescending(p => p.CREATE_DATE).First();
2782

    
2783
                        foreach (MARKUP_DATA markdata in markup_Version.MARKUP_DATA)
2784
                        {
2785
                            MarkupItem markitem = new MarkupItem()
2786
                            {
2787
                                ID = markdata.ID,
2788
                                PageNumber = markdata.PAGENUMBER,
2789
                            };
2790
                            _result.MarkupList.Add(markitem);
2791
                        }
2792

    
2793
                        _result.PageCount = _result.MarkupList.GroupBy(i => i.PageNumber).Count();
2794

    
2795
                        markupinfo.Add(_result);
2796
                    }
2797
                }
2798
            }
2799
            catch (Exception ex)
2800
            {
2801
                return null;
2802
            }
2803
            return markupinfo;
2804
        }
2805

    
2806
        [OperationContract]
2807
        public bool AddMessage(string project_no, TALK value)
2808
        {
2809
            try
2810
            {
2811
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2812
                using (CIEntities entity = new CIEntities(sCIConnString))
2813
                {                    
2814
                    entity.TALK.AddObject(value);
2815
                    entity.SaveChanges();
2816
                }
2817
            }
2818
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2819
                return false;
2820
            }
2821
            return true;
2822
        }
2823

    
2824
        [OperationContract]
2825
        public List<TALK> GetMessage(string project_no, string doc_id)
2826
        {
2827
            List<TALK> result = new List<TALK>();
2828
            try
2829
            {
2830
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2831
                using (CIEntities entity = new CIEntities(sCIConnString))
2832
                {
2833
                    result = entity.TALK.Where(data => data.DOCUMENT_ID == doc_id).ToList();                        
2834
                }
2835
            }
2836
            catch (Exception ex)
2837
            {
2838
                return result;
2839
            }
2840
            return result;
2841
        }
2842

    
2843

    
2844
        #region Legacy System I/F
2845
        /// <summary>
2846
        /// Ensemble+ Sign Data Return
2847
        /// </summary>
2848
        /// <param name="user_id"></param>
2849
        /// <returns></returns>
2850
        private string getEnsembleSign(string user_id)
2851
        {
2852
            string result = null;
2853
            string soapurl = string.Empty;
2854

    
2855
            try
2856
            {
2857
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2858
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2859
                {
2860
                    var item = Entity.PROPERTIES.Where(d => d.TYPE == "UpLoadServiceUrl").FirstOrDefault();
2861

    
2862
                    if (item != null)
2863
                    {
2864
                        soapurl = item.VALUE;
2865

    
2866
                        WebClient webClient = new WebClient();
2867
                        string data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ens=\"http://EnsemblePlus.Webservice\"> <soapenv:Header/> <soapenv:Body> <ens:checkoutSignImage>"
2868
                            + "<ens:sUserNo>" + user_id + "</ens:sUserNo>"
2869
                            + "</ens:checkoutSignImage> </soapenv:Body></soapenv:Envelope>";
2870
                        webClient.Headers.Add(HttpRequestHeader.ContentType, "text/xml");
2871
                        webClient.Headers.Add("SOAPAction", "http://EnsemblePlus.Webservice");
2872
                        var _result = webClient.UploadString(new Uri(soapurl), data);
2873
                        XmlDocument xmlDoc = new XmlDocument();
2874
                        xmlDoc.LoadXml(_result);
2875
                        XmlNodeList list = xmlDoc.GetElementsByTagName("checkoutSignImageResponse");
2876

    
2877
                        foreach (XmlNode xn in list)
2878
                        {
2879
                            result = xn["checkoutSignImageReturn"].InnerText;
2880
                        }
2881

    
2882
                        if (result.Contains("No business object"))
2883
                        {
2884
                            result = null;
2885
                        }
2886
                    }
2887
                    else
2888
                    {
2889
                        result = null;
2890
                    }
2891
                }
2892
             
2893
            }
2894
            catch (Exception ex)
2895
            {   
2896
                result = null;
2897
            }
2898

    
2899
            return result;
2900
        }
2901
        #endregion
2902

    
2903
        #region Final Service
2904
        [OperationContract]
2905
        [ServiceKnownType(typeof(DOCINFO))]                
2906
        public DOCINFO FinalPDF_GetDocinfo(string project_no, string docinfo_id)
2907
        {
2908
            DOCINFO docinfo = null;
2909

    
2910
            try
2911
            {
2912
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2913
                using (CIEntities _entity = new CIEntities(sCIConnString))
2914
                {
2915
                    var doc = _entity.DOCINFO.Where(x => x.ID == docinfo_id).FirstOrDefault();
2916
                    if(doc != null)
2917
                    {
2918
                        docinfo = new DOCINFO()
2919
                        {
2920
                            ID = doc.ID,
2921
                            DOCUMENT_ID = doc.DOCUMENT_ID,
2922
                            PAGE_COUNT = doc.PAGE_COUNT,
2923
                            ORIGINAL_FILE = doc.ORIGINAL_FILE,
2924
                            PROJECT_NO = doc.PROJECT_NO
2925
                        };
2926
                    }                    
2927
                }
2928
            }
2929
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2930
                throw;
2931
            }
2932
            return docinfo;
2933
        }
2934
        [OperationContract]
2935
        [ServiceKnownType(typeof(DOCUMENT_ITEM))]
2936
        public DOCUMENT_ITEM FinalPDF_GetDocumentItem(string project_no, string document_id)
2937
        {
2938
            DOCUMENT_ITEM item = null;
2939

    
2940
            try
2941
            {
2942
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2943
                using (CIEntities _entity = new CIEntities(sCIConnString))
2944
                {
2945
                    var doc = _entity.DOCUMENT_ITEM.Where(x => x.PROJECT_NO == project_no &&  x.DOCUMENT_ID == document_id).FirstOrDefault();
2946
                    if(doc != null)
2947
                    {
2948
                        item = new DOCUMENT_ITEM()
2949
                        {
2950
                            ID = doc.ID,
2951
                            ORIGINAL_FILE = doc.ORIGINAL_FILE,
2952
                            PROJECT_NO = doc.PROJECT_NO,
2953
                            DOCUMENT_ID = doc.DOCUMENT_ID,
2954
                            DOCUMENT_NO = doc.DOCUMENT_NO,
2955
                            DOCUMENT_NAME = doc.DOCUMENT_NAME,
2956
                            //ENSEMBLEINFO_URL = doc.ENSEMBLEINFO_URL,
2957
                            GROUP_NO = doc.GROUP_NO,
2958
                            RESULT = doc.RESULT,
2959
                            REVISION = doc.REVISION,
2960
                            RESULT_FILE = doc.RESULT_FILE
2961
                        };
2962
                    }
2963
                    
2964
                }
2965
            }
2966
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2967
                throw;
2968
            }
2969
            return item;
2970
        }
2971
        [OperationContract]
2972
        [ServiceKnownType(typeof(MARKUP_DATA))]
2973
        public List<MARKUP_DATA> FinalPDF_GetMarkupdata(string project_no, string docinfo_id)
2974
        {
2975
            List<MARKUP_DATA> results = new List<MARKUP_DATA>();
2976

    
2977
            try
2978
            {
2979
                //using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2980
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2981
                using (CIEntities _entity = new CIEntities(sCIConnString))
2982
                {
2983
                    var datas = _entity.MARKUP_DATA.Where(x => x.MARKUP_INFO_VERSION.MARKUP_INFO.DOCINFO_ID == docinfo_id
2984
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.CONSOLIDATE == 1
2985
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.AVOID_CONSOLIDATE == 0
2986
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.PART_CONSOLIDATE == 0).ToList();
2987
                    foreach (var data in datas)
2988
                    {
2989
                        MARKUP_DATA d = new MARKUP_DATA()
2990
                        {
2991
                            ID = data.ID,
2992
                            //GROUP_ID = data.GROUP_ID,
2993
                            SYMBOL_ID = data.SYMBOL_ID,
2994
                            DATA = data.DATA,
2995
                            DATA_TYPE = data.DATA_TYPE,
2996
                            MARKUPINFO_VERSION_ID = data.MARKUPINFO_VERSION_ID,
2997
                            PAGENUMBER = data.PAGENUMBER
2998
                        };
2999
                        results.Add(d);
3000
                    }
3001
                }
3002
            }
3003
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3004
                throw;
3005
            }
3006
            return results;
3007
        }
3008
        [OperationContract]
3009
        [ServiceKnownType(typeof(MARKUP_INFO))]
3010
        public MARKUP_INFO FinalPDF_GetMarkupinfo(string project_no, string docinfo_id)
3011
        {
3012
            MARKUP_INFO markupInfo = null;
3013

    
3014
            try
3015
            {
3016
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
3017
                using (CIEntities _entity = new CIEntities(sCIConnString))
3018
                {
3019
                    var tmp = _entity.MARKUP_INFO.Where(x => x.DOCINFO_ID == docinfo_id && x.CONSOLIDATE == 1 && x.AVOID_CONSOLIDATE == 0 && x.PART_CONSOLIDATE == 0).FirstOrDefault();
3020
                    if (tmp != null)
3021
                    {
3022
                        markupInfo = new MARKUP_INFO()
3023
                        {
3024
                            ID = tmp.ID,
3025
                            DOCINFO_ID = tmp.DOCINFO_ID,
3026
                            USER_ID = tmp.USER_ID
3027
                        };
3028
                    }                    
3029
                }
3030
            }
3031
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3032
                throw;
3033
            }
3034
            return markupInfo;
3035
        }
3036
        [OperationContract]
3037
        [ServiceKnownType(typeof(FINAL_PDF))]
3038
        public List<FINAL_PDF> FinalPDF_GetFinalPDFs(string final_id)
3039
        {
3040
            List<FINAL_PDF> results = new List<FINAL_PDF>();
3041

    
3042
            try
3043
            {
3044
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3045
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3046
                {
3047
                    var finalList = _entity.FINAL_PDF.Where(final => final.ID == final_id).ToList();
3048
                    foreach(var final in finalList)
3049
                    {
3050
                        FINAL_PDF pdf = new FINAL_PDF()
3051
                        {
3052
                            ID = final.ID,
3053
                            DOCINFO_ID = final.DOCINFO_ID,
3054
                            DOCUMENT_ID = final.DOCUMENT_ID,
3055
                            STATUS = final.STATUS,
3056
                            CURRENT_PAGE = final.CURRENT_PAGE,
3057
                            CREATE_DATETIME = final.CREATE_DATETIME,
3058
                            START_DATETIME = final.START_DATETIME,
3059
                            END_DATETIME = final.END_DATETIME,
3060
                            EXCEPTION = final.EXCEPTION,
3061
                            PROJECT_NO = final.PROJECT_NO,
3062
                            TOTAL_PAGE = final.TOTAL_PAGE,
3063
                            MARKUPINFO_ID = final.MARKUPINFO_ID,
3064
                            CREATE_USER_ID = final.CREATE_USER_ID
3065
                        };
3066
                        results.Add(pdf);
3067
                    }
3068
                }
3069
            }
3070
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3071
                throw;
3072
            }
3073
            return results;
3074
        }
3075
        [OperationContract]
3076
        [ServiceKnownType(typeof(DOCPAGE))]
3077
        public List<DOCPAGE> FinalPDF_GetDocpage(string project_no, string docinfo_id)
3078
        {
3079
            List<DOCPAGE> results = new List<DOCPAGE>();
3080

    
3081
            try
3082
            {
3083
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
3084
                using (CIEntities _entity = new CIEntities(sCIConnString))
3085
                {
3086
                    var pages = _entity.DOCPAGE.Where(x => x.DOCINFO_ID == docinfo_id).OrderBy(x => x.PAGE_NUMBER).ToList();
3087
                    foreach(var page in pages)
3088
                    {
3089
                        DOCPAGE p = new DOCPAGE()
3090
                        {
3091
                            PAGE_ANGLE = page.PAGE_ANGLE,
3092
                            PAGE_NUMBER = page.PAGE_NUMBER,
3093
                            PAGE_HEIGHT = page.PAGE_HEIGHT,
3094
                            PAGE_WIDTH = page.PAGE_WIDTH,
3095
                            DOCINFO_ID = page.DOCINFO_ID                            
3096
                        };
3097
                        results.Add(p);
3098
                    }                    
3099
                }
3100
            }
3101
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3102
                throw;
3103
            }
3104
            return results;
3105
        }
3106
        [OperationContract]        
3107
        public bool FinalPDF_SetFinalPDFStatus(string final_id, FinalStatus status)
3108
        {
3109
            bool result = false;
3110

    
3111
            try
3112
            {
3113
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3114
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3115
                {
3116
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
3117
                    if(tmp != null)
3118
                    {
3119
                        switch(status)
3120
                        {
3121
                            case FinalStatus.Create:
3122
                                tmp.START_DATETIME = DateTime.Now;
3123
                                break;
3124
                            case FinalStatus.Success:
3125
                                tmp.END_DATETIME = DateTime.Now;
3126
                                tmp.EXCEPTION = string.Empty;
3127
                                break;                                
3128
                        }
3129
                        tmp.STATUS = (int)status;
3130
                        _entity.SaveChanges();
3131
                        result = true;                        
3132
                    }
3133
                }                    
3134
            }
3135
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3136
                throw;
3137
            }
3138
            return result;
3139
        }
3140

    
3141
        /// <summary>
3142
        /// 현재 진행중인 Final PDF 가 없거나 Success 일 경우에만 true return
3143
        /// </summary>
3144
        /// <param name="DocInfoID"></param>
3145
        /// <param name="MarkupInfoID"></param>
3146
        /// <param name="CreateUserID"></param>
3147
        /// <returns></returns>
3148
        [OperationContract]
3149
        public bool FinalPDF_GetFinalPDFStatus(string DocInfoID, string MarkupInfoID, string CreateUserID)
3150
        {
3151
            bool result = false;
3152

    
3153
            try
3154
            {
3155
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3156
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3157
                {
3158
                    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();
3159
                    if (finalpdf != null)
3160
                    {
3161
                        if (finalpdf.STATUS == (int)FinalStatus.Success)
3162
                        {
3163
                            result = true;
3164
                        }
3165
                    }
3166
                    else
3167
                        result = true;
3168
                }
3169
            }
3170
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3171
                throw;
3172
            }
3173
            return result;
3174
        }
3175

    
3176
        [OperationContract]
3177
        public bool FinalPDF_SetCurrentPage(string final_id, int currentpage)
3178
        {
3179
            bool result = false;
3180

    
3181
            try
3182
            {
3183
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3184
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3185
                {
3186
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
3187
                    if (tmp != null)
3188
                    {
3189
                        tmp.CURRENT_PAGE = currentpage;
3190
                        _entity.SaveChanges();
3191
                        result = true;
3192
                    }
3193
                }
3194
            }
3195
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3196
                throw;
3197
            }
3198
            return result;
3199
        }
3200
        [OperationContract]
3201
        public bool FinalPDF_SetError(string final_id, string msg)
3202
        {
3203
            bool result = false;
3204

    
3205
            try
3206
            {
3207
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3208
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3209
                {
3210
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
3211
                    if (tmp != null)
3212
                    {                        
3213
                        tmp.STATUS = (int)FinalStatus.Error;
3214
                        tmp.EXCEPTION = DateTime.Now.ToShortDateString() + " " + msg;                        
3215
                        _entity.SaveChanges();
3216
                        result = true;
3217
                    }
3218
                }
3219
            }
3220
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3221
                throw;
3222
            }
3223
            return result;
3224
        }
3225

    
3226
        [OperationContract]
3227
        public bool FinalPDF_SetFinalResultPath(string project_no, string document_id, string url)
3228
        {
3229
            bool result = false;
3230

    
3231
            try
3232
            {
3233
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
3234
                using (CIEntities _entity = new CIEntities(sCIConnString))
3235
                {
3236
                    var item = _entity.DOCUMENT_ITEM.Where(d =>d.PROJECT_NO == project_no && d.DOCUMENT_ID == document_id).FirstOrDefault();
3237
                    if (item != null)
3238
                    {
3239
                        item.RESULT_FILE = url;
3240
                        _entity.SaveChanges();
3241
                        result = true;
3242
                    }
3243
                }
3244
            }
3245
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3246
                throw;
3247
            }
3248
            return result;
3249
        }
3250

    
3251
        [OperationContract]
3252
        public bool SaveLog(string project_no, string document_id, string Log)
3253
        {
3254
            bool result = false;
3255

    
3256
            try
3257
            {
3258
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3259
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3260
                {
3261
                    _entity.AddToERROR_LOG(new ERROR_LOG
3262
                    {
3263
                        PROJECT_NO = project_no,
3264
                        DOCUMENT_ID = document_id,
3265
                        CONTENTS = Log,
3266
                        CREATE_DATETIME = DateTime.Now.ToString("yyMMddssmm"),
3267
                        CODE = "",
3268
                        TYPE = "Markus Log",
3269
                        LEVEL = "",
3270
                        SERVICE_NAME = "Markus",
3271
                    });
3272

    
3273
                    _entity.SaveChanges();
3274
                }
3275
            }
3276
            catch (Exception ex)
3277
            {
3278
            }
3279

    
3280
            return result;
3281
        }
3282

    
3283
        [OperationContract]
3284
        [ServiceKnownType(typeof(MEMBER))]
3285
        public MEMBER FinalPDF_GetCommentMember(string project_no, string markupdata_id)
3286
        {
3287
            MEMBER member = null;
3288
            try
3289
            {
3290
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
3291
                using (CIEntities _entity = new CIEntities(sCIConnString))
3292
                {
3293
                    var data = _entity.MARKUP_DATA.Where(x => x.ID == markupdata_id).FirstOrDefault();
3294
                    string user_id = data.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID;
3295

    
3296
                    var person = GetMemberQuery(_entity,user_id);
3297

    
3298
                    if(person.Count() > 0)
3299
                    {
3300
                        member = person.First();
3301
                    }
3302
                }
3303
            }
3304
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3305
                throw;
3306
            }
3307

    
3308
            return member;
3309
        }
3310

    
3311
        [OperationContract]
3312
        [ServiceKnownType(typeof(PROPERTIES))]
3313
        public List<PROPERTIES> FinalPDF_GetProperties(string project_no)
3314
        {
3315
            List<PROPERTIES> results = new List<PROPERTIES>();
3316
            try
3317
            {
3318
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3319
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3320
                {
3321
                    var _items = _entity.PROPERTIES.Where(x => x.PROPERTY == project_no).ToList();
3322
                    foreach(var item in _items)
3323
                    {
3324
                        PROPERTIES pROPERTIES = new PROPERTIES()
3325
                        {
3326
                            ID = item.ID,
3327
                            PROPERTY = item.PROPERTY,
3328
                            TYPE = item.TYPE,
3329
                            VALUE = item.VALUE
3330
                        };
3331
                        results.Add(pROPERTIES);
3332
                    }
3333
                }
3334

    
3335
            }
3336
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3337
                throw;
3338
            }
3339
            return results;
3340
        }
3341
        #endregion
3342
    }    
3343
}
클립보드 이미지 추가 (최대 크기: 500 MB)