프로젝트

일반

사용자정보

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

markus / KCOM_API / ServiceDeepView.svc.cs @ 77cdac33

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

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

    
21
namespace KCOM_API
22
{
23
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ServiceDeepView" in code, svc and config file together.
24
    // NOTE: In order to launch WCF Test Client for testing this service, please select ServiceDeepView.svc or ServiceDeepView.svc.cs at the Solution Explorer and start debugging.
25
    [ServiceContract(Namespace = "")]
26
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
27
    public partial class ServiceDeepView : System.Web.Services.WebService
28
    {
29
        public ServiceDeepView()
30
        {
31
            //System.Diagnostics.Debug.WriteLine(OperationContext.Current.RequestContext.RequestMessage.Headers.Action.ToString());
32
        }
33

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

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

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

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

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

    
94
                    KCOM_SystemInfo sysInfo = new KCOM_SystemInfo();
95

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

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

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

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

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

    
133
            var guid = new Guid(bytes);
134

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

    
141

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

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

    
154

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

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

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

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

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

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

    
184
                        dc.SaveChanges();
185

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

    
197
                    return false;
198
                }
199
            }
200
        }
201

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

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

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

    
229
                    return false;
230
                }
231
            }
232
        }
233

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

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

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

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

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

    
279

    
280
            return result;
281
        }
282

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

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

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

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

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

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

    
329

    
330
            return result;
331
        }
332

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

    
338
        //    stopwatch.Start();
339

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

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

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

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

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

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

    
365
        //    return result;
366
        //}
367

    
368

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

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

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

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

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

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

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

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

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

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

    
461
                _result.Status = FinalStatus.Error;
462

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

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

    
479

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

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

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

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

    
562
            return _result;
563
        }
564

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

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

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

    
615
                }
616
                return _result;
617

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

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

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

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

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

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

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

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

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

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

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

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

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

    
755
                    _result.ForEach(r =>
756
                    {
757

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

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

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

    
774
                    }
775

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

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

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

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

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

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

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

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

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

    
834
            return _result;
835
        }
836

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

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

    
868

    
869

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

    
875

    
876

    
877
                    _result.ForEach(r =>
878
                    {
879

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

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

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

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

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

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

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

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

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

    
949
            return _result;
950
        }
951

    
952

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

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

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

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

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

    
986

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

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

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

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

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

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

    
1041

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

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

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

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

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

    
1099
                return true;
1100
            }
1101
        }
1102

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

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

    
1126
        //        try
1127
        //        {
1128

    
1129

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

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

    
1137
        //                dc.SaveChanges();
1138

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

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

    
1161
        //        try
1162
        //        {
1163

    
1164

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

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

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

    
1200
                #region Markup_Info 저장
1201

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

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

    
1241
                #region Markup_Info_Version 저장
1242

    
1243
                MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1244

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

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

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

    
1278
                Entity.SaveChanges();
1279

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

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

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

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

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

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

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

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

    
1337
                #region Markup_Info 저장
1338

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

    
1350
                    markup_info = null;
1351
                }
1352

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

    
1379
                #region Markup_Info_Version 저장
1380

    
1381
                MARKUP_INFO_VERSION markup_info_version = new MARKUP_INFO_VERSION();
1382

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

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

    
1410

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1980

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

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

    
2004

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

    
2013

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

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

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

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

    
2050

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

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

    
2074

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2198
                    string user_dept = "";
2199

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

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

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

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

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

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

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

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

    
2245

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

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

    
2269

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

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

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

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

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

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

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

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

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

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

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

    
2339
            return result;
2340
        }
2341

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

    
2404
        /// <summary>
2405
        /// 
2406
        /// </summary>
2407
        /// <param name="id">symbol id</param>
2408
        /// <param name="type"> 0 : PRIVATE, 1 : PUBLIC</param>
2409
        /// <returns></returns>
2410
        [OperationContract]
2411
        public string GetSymbolData(string id, int type)
2412
        {
2413
            string result;
2414
            try
2415
            {
2416
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2417
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2418
                {
2419
                    if(type == 0)
2420
                    {
2421
                        result = Entity.SYMBOL_PRIVATE.Where(data => data.ID == id).FirstOrDefault().DATA;
2422
                    }
2423
                    else
2424
                    {
2425
                        result = Entity.SYMBOL_PUBLIC.Where(data => data.ID == id).FirstOrDefault().DATA;
2426
                    }
2427
                }
2428
            }
2429
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2430
                return null;
2431
            }
2432
            return result;
2433
        }
2434
        [OperationContract]
2435
        public string GetSymbolImageURL(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().IMAGE_URL;
2446
                    }
2447
                    else
2448
                    {
2449
                        result = Entity.SYMBOL_PUBLIC.Where(data => data.ID == id).FirstOrDefault().IMAGE_URL;
2450
                    }
2451
                }
2452
            }
2453
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2454
                return null;
2455
            }
2456
            return result;
2457
        }
2458

    
2459
        [OperationContract]
2460
        public string GetSignData(string project_no, string user_id)
2461
        {
2462
            string result = null;
2463
            try
2464
            {
2465
                string ifsign = getEnsembleSign(user_id);
2466
                if (string.IsNullOrEmpty(ifsign))
2467
                {
2468
                    string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2469
                    var ModelWFConnectionString = sCIConnString;
2470
                    if (null != ModelWFConnectionString)
2471
                    {
2472
                        using (CIEntities entity = new CIEntities(ModelWFConnectionString))
2473
                        {
2474
                            var _sign = entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == user_id);
2475
                            if (_sign.Count() > 0)
2476
                            {
2477
                                result = _sign.First().SIGN_STR;
2478
                            }
2479
                            else
2480
                            {
2481
                                return null;
2482
                            }
2483
                        }
2484
                    }
2485
                }
2486
                else
2487
                {
2488
                    result = ifsign;
2489
                }
2490

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

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

    
2530
            }
2531
            catch (Exception ex)
2532
            {
2533
                System.Diagnostics.Debug.WriteLine(ex);
2534
                return null;
2535
            }
2536
            return result;
2537
        }
2538

    
2539
        [OperationContract]
2540
        public int SetSignData(string user_id,string SignStr,int CropX,int CropY,int CropWidth,int CropHeight)
2541
        {
2542
            int result = -1;
2543

    
2544
            try
2545
            {
2546
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2547
                   
2548
                using (CIEntities entity = new CIEntities(sCIConnString))
2549
                {
2550
                    var _sign = entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == user_id);
2551

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

    
2554
                    if (_sign.Count() > 0)
2555
                    {
2556
                        _sign.First().SIGN_STR = cropImg;
2557
                        _sign.First().MODIFY_DATE = DateTime.Now;
2558
                    }
2559
                    else
2560
                    {
2561
                        entity.SIGN_INFO.AddObject(new SIGN_INFO
2562
                        {
2563
                            ID = shortGuid(),
2564
                            MEMBER_USER_ID = user_id,
2565
                            CREATE_DATE = DateTime.Now,
2566
                            SIGN_STR = cropImg
2567
                        });
2568
                    }
2569

    
2570
                    result = entity.SaveChanges();
2571
                }
2572
            }
2573
            catch (Exception ex)
2574
            {
2575
                System.Diagnostics.Debug.WriteLine(ex);
2576
            }
2577
            return result;
2578
        }
2579

    
2580

    
2581
        [OperationContract]
2582
        public int SetSignStrokes(string user_id, string strokesData)
2583
        {
2584
            int result = -1;
2585

    
2586
            try
2587
            {
2588
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2589

    
2590
                using (CIEntities entity = new CIEntities(sCIConnString))
2591
                {
2592
                    var _sign = entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == user_id);
2593

    
2594
                    if (_sign.Count() > 0)
2595
                    {
2596
                        _sign.First().SIGN_STROKES = strokesData;
2597
                        _sign.First().MODIFY_DATE = DateTime.Now;
2598
                    }
2599
                    else
2600
                    {
2601
                        entity.SIGN_INFO.AddObject(new SIGN_INFO
2602
                        {
2603
                            ID = shortGuid(),
2604
                            MEMBER_USER_ID = user_id,
2605
                            CREATE_DATE = DateTime.Now,
2606
                            SIGN_STROKES = strokesData
2607
                    });
2608
                    }
2609

    
2610
                    result = entity.SaveChanges();
2611
                }
2612
            }
2613
            catch (Exception ex)
2614
            {
2615
                System.Diagnostics.Debug.WriteLine(ex);
2616
            }
2617
            return result;
2618
        }
2619

    
2620
        private byte[] SignatureCrop(string imgStr,int X,int Y,int Width,int Height)
2621
        {
2622
            using (System.IO.MemoryStream readStream = new System.IO.MemoryStream(Convert.FromBase64String(imgStr)))
2623
            {
2624
                using (System.Drawing.Image OriginalImage = System.Drawing.Image.FromStream(readStream))
2625
                {
2626
                    using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(Width, Height))
2627
                    {
2628
                        bmp.SetResolution(OriginalImage.HorizontalResolution, OriginalImage.VerticalResolution);
2629
                        using (System.Drawing.Graphics Graphic = System.Drawing.Graphics.FromImage(bmp))
2630
                        {
2631
                            Graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
2632
                            Graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
2633
                            Graphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
2634
                            Graphic.DrawImage(OriginalImage, new System.Drawing.Rectangle(0, 0, Width, Height), X, Y, Width, Height, System.Drawing.GraphicsUnit.Pixel);
2635
                            System.IO.MemoryStream ms = new System.IO.MemoryStream();
2636
                            bmp.Save(ms, OriginalImage.RawFormat);
2637
                            return ms.GetBuffer();
2638
                        }
2639
                    }
2640
                }
2641
            }
2642
        }
2643

    
2644
        [OperationContract]        
2645
        public string GetProjectName(string project_no)
2646
        {
2647
            string result = null;
2648

    
2649
            try
2650
            {
2651
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2652
                using (KCOMDataModel.DataModel.KCOMEntities Entity = new KCOMDataModel.DataModel.KCOMEntities(sConnString))
2653
                {
2654
                    result = Entity.RUN_PROJECTS.Where(i => i.PROJECT_NO == project_no).FirstOrDefault().PROJECT_NAME.ToString();
2655
                }
2656
            }
2657
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2658
                return null;
2659
            }
2660
            return result;
2661
        }
2662

    
2663
        [OperationContract]
2664
        public List<DOCUMENT_ITEM> GetPreRevSelect(string project_no, string doc_no, string current_rev)
2665
        {
2666
            List<DOCUMENT_ITEM> result = new List<DOCUMENT_ITEM>();
2667
            
2668
            try
2669
            {
2670
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2671
                using (CIEntities Entity = new CIEntities(sCIConnString))
2672
                {
2673
                    result = Entity.DOCUMENT_ITEM.Where(i => i.PROJECT_NO == project_no
2674
                    && i.DOCUMENT_NO == doc_no
2675
                    && i.REVISION != current_rev).OrderByDescending(i => i.GROUP_NO).ToList();
2676
                }
2677
            }
2678
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2679
                return null;
2680
            }
2681
            return result;
2682
        }
2683

    
2684
        [OperationContract]
2685
        public DOCINFO GetDocInfoOneSelect(string project_no, string doc_id)
2686
        {
2687
            DOCINFO docinfo = null;
2688

    
2689
            try
2690
            {
2691
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2692
                using (CIEntities Entity = new CIEntities(sCIConnString))
2693
                {
2694
                    docinfo = (from info in Entity.DOCINFO
2695
                              where info.DOCUMENT_ID == doc_id
2696
                              && info.PROJECT_NO == project_no
2697
                              select info).First();
2698
                }
2699
            }
2700
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2701
                return null;
2702
            }
2703
            return docinfo;
2704
        }
2705

    
2706
        [OperationContract]
2707
        public List<MarkupInfoItem> GetPrintDocItemList(string project_no, string doc_id, List<MarkupInfoItem> _markupInfoList)
2708
        {
2709
            MarkupInfoItem _result = null;
2710
            List<MarkupInfoItem> markupinfo = new List<MarkupInfoItem>();
2711
            try
2712
            {
2713
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2714
                using (CIEntities Entity = new CIEntities(sCIConnString))
2715
                {
2716
                    var docitem = (from info in Entity.DOCINFO
2717
                               where info.DOCUMENT_ID == doc_id
2718
                               && info.PROJECT_NO == project_no
2719
                               select info).First();
2720

    
2721
                    foreach (MARKUP_INFO markinfo in docitem.MARKUP_INFO)
2722
                    {
2723
                        var members = GetMemberQuery(Entity, markinfo.USER_ID);
2724

    
2725
                        MEMBER member = new MEMBER();
2726

    
2727
                        if (members.Count() > 0)
2728
                        {
2729
                            member = members.First();
2730
                        }
2731

    
2732
                        string displaycolor = null;
2733

    
2734
                        try
2735
                        {
2736
                            displaycolor = _markupInfoList.Where(info => info.MarkupInfoID == markinfo.ID).First().DisplayColor;
2737
                        }
2738
                        catch (Exception ex)
2739
                        {
2740
                            System.Diagnostics.Debug.WriteLine("KCOM_API - GetPrintDocItemList displaycolor : " + ex.ToString());
2741

    
2742
                            displaycolor = "#FFFFFF";
2743
                        }
2744
                        
2745
                        _result = new MarkupInfoItem
2746
                        {
2747
                            MarkupInfoID = markinfo.ID,
2748
                            Consolidate = markinfo.CONSOLIDATE,
2749
                            CreateTime = markinfo.UPDATE_TIME.HasValue ? markinfo.UPDATE_TIME.Value : markinfo.CREATE_TIME,
2750
                            DisplayColor = displaycolor,
2751
                            UserID = markinfo.USER_ID,
2752
                            UserName = member.NAME,
2753
                            Depatment = member.DEPARTMENT,
2754
                        };
2755

    
2756
                        _result.MarkupList = new List<IKCOM.MarkupItem>();
2757
                        var markup_Version = markinfo.MARKUP_INFO_VERSION.OrderByDescending(p => p.CREATE_DATE).First();
2758

    
2759
                        foreach (MARKUP_DATA markdata in markup_Version.MARKUP_DATA)
2760
                        {
2761
                            MarkupItem markitem = new MarkupItem()
2762
                            {
2763
                                ID = markdata.ID,
2764
                                PageNumber = markdata.PAGENUMBER,
2765
                            };
2766
                            _result.MarkupList.Add(markitem);
2767
                        }
2768

    
2769
                        _result.PageCount = _result.MarkupList.GroupBy(i => i.PageNumber).Count();
2770

    
2771
                        markupinfo.Add(_result);
2772
                    }
2773
                }
2774
            }
2775
            catch (Exception ex)
2776
            {
2777
                return null;
2778
            }
2779
            return markupinfo;
2780
        }
2781

    
2782
        [OperationContract]
2783
        public bool AddMessage(string project_no, TALK value)
2784
        {
2785
            try
2786
            {
2787
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2788
                using (CIEntities entity = new CIEntities(sCIConnString))
2789
                {                    
2790
                    entity.TALK.AddObject(value);
2791
                    entity.SaveChanges();
2792
                }
2793
            }
2794
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2795
                return false;
2796
            }
2797
            return true;
2798
        }
2799

    
2800
        [OperationContract]
2801
        public List<TALK> GetMessage(string project_no, string doc_id)
2802
        {
2803
            List<TALK> result = new List<TALK>();
2804
            try
2805
            {
2806
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2807
                using (CIEntities entity = new CIEntities(sCIConnString))
2808
                {
2809
                    result = entity.TALK.Where(data => data.DOCUMENT_ID == doc_id).ToList();                        
2810
                }
2811
            }
2812
            catch (Exception ex)
2813
            {
2814
                return result;
2815
            }
2816
            return result;
2817
        }
2818

    
2819

    
2820
        #region Legacy System I/F
2821
        /// <summary>
2822
        /// Ensemble+ Sign Data Return
2823
        /// </summary>
2824
        /// <param name="user_id"></param>
2825
        /// <returns></returns>
2826
        private string getEnsembleSign(string user_id)
2827
        {
2828
            string result = null;
2829
            string soapurl = string.Empty;
2830

    
2831
            try
2832
            {
2833
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
2834
                using (KCOMEntities Entity = new KCOMEntities(sConnString))
2835
                {
2836
                    var item = Entity.PROPERTIES.Where(d => d.TYPE == "UpLoadServiceUrl").FirstOrDefault();
2837

    
2838
                    if (item != null)
2839
                    {
2840
                        soapurl = item.VALUE;
2841

    
2842
                        WebClient webClient = new WebClient();
2843
                        string data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ens=\"http://EnsemblePlus.Webservice\"> <soapenv:Header/> <soapenv:Body> <ens:checkoutSignImage>"
2844
                            + "<ens:sUserNo>" + user_id + "</ens:sUserNo>"
2845
                            + "</ens:checkoutSignImage> </soapenv:Body></soapenv:Envelope>";
2846
                        webClient.Headers.Add(HttpRequestHeader.ContentType, "text/xml");
2847
                        webClient.Headers.Add("SOAPAction", "http://EnsemblePlus.Webservice");
2848
                        var _result = webClient.UploadString(new Uri(soapurl), data);
2849
                        XmlDocument xmlDoc = new XmlDocument();
2850
                        xmlDoc.LoadXml(_result);
2851
                        XmlNodeList list = xmlDoc.GetElementsByTagName("checkoutSignImageResponse");
2852

    
2853
                        foreach (XmlNode xn in list)
2854
                        {
2855
                            result = xn["checkoutSignImageReturn"].InnerText;
2856
                        }
2857

    
2858
                        if (result.Contains("No business object"))
2859
                        {
2860
                            result = null;
2861
                        }
2862
                    }
2863
                    else
2864
                    {
2865
                        result = null;
2866
                    }
2867
                }
2868
             
2869
            }
2870
            catch (Exception ex)
2871
            {   
2872
                result = null;
2873
            }
2874

    
2875
            return result;
2876
        }
2877
        #endregion
2878

    
2879
        #region Final Service
2880
        [OperationContract]
2881
        [ServiceKnownType(typeof(DOCINFO))]                
2882
        public DOCINFO FinalPDF_GetDocinfo(string project_no, string docinfo_id)
2883
        {
2884
            DOCINFO docinfo = null;
2885

    
2886
            try
2887
            {
2888
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2889
                using (CIEntities _entity = new CIEntities(sCIConnString))
2890
                {
2891
                    var doc = _entity.DOCINFO.Where(x => x.ID == docinfo_id).FirstOrDefault();
2892
                    if(doc != null)
2893
                    {
2894
                        docinfo = new DOCINFO()
2895
                        {
2896
                            ID = doc.ID,
2897
                            DOCUMENT_ID = doc.DOCUMENT_ID,
2898
                            PAGE_COUNT = doc.PAGE_COUNT,
2899
                            ORIGINAL_FILE = doc.ORIGINAL_FILE,
2900
                            PROJECT_NO = doc.PROJECT_NO
2901
                        };
2902
                    }                    
2903
                }
2904
            }
2905
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2906
                throw;
2907
            }
2908
            return docinfo;
2909
        }
2910
        [OperationContract]
2911
        [ServiceKnownType(typeof(DOCUMENT_ITEM))]
2912
        public DOCUMENT_ITEM FinalPDF_GetDocumentItem(string project_no, string document_id)
2913
        {
2914
            DOCUMENT_ITEM item = null;
2915

    
2916
            try
2917
            {
2918
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2919
                using (CIEntities _entity = new CIEntities(sCIConnString))
2920
                {
2921
                    var doc = _entity.DOCUMENT_ITEM.Where(x => x.PROJECT_NO == project_no &&  x.DOCUMENT_ID == document_id).FirstOrDefault();
2922
                    if(doc != null)
2923
                    {
2924
                        item = new DOCUMENT_ITEM()
2925
                        {
2926
                            ID = doc.ID,
2927
                            ORIGINAL_FILE = doc.ORIGINAL_FILE,
2928
                            PROJECT_NO = doc.PROJECT_NO,
2929
                            DOCUMENT_ID = doc.DOCUMENT_ID,
2930
                            DOCUMENT_NO = doc.DOCUMENT_NO,
2931
                            DOCUMENT_NAME = doc.DOCUMENT_NAME,
2932
                            //ENSEMBLEINFO_URL = doc.ENSEMBLEINFO_URL,
2933
                            GROUP_NO = doc.GROUP_NO,
2934
                            RESULT = doc.RESULT,
2935
                            REVISION = doc.REVISION,
2936
                            RESULT_FILE = doc.RESULT_FILE
2937
                        };
2938
                    }
2939
                    
2940
                }
2941
            }
2942
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2943
                throw;
2944
            }
2945
            return item;
2946
        }
2947
        [OperationContract]
2948
        [ServiceKnownType(typeof(MARKUP_DATA))]
2949
        public List<MARKUP_DATA> FinalPDF_GetMarkupdata(string project_no, string docinfo_id)
2950
        {
2951
            List<MARKUP_DATA> results = new List<MARKUP_DATA>();
2952

    
2953
            try
2954
            {
2955
                //using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString()))
2956
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2957
                using (CIEntities _entity = new CIEntities(sCIConnString))
2958
                {
2959
                    var datas = _entity.MARKUP_DATA.Where(x => x.MARKUP_INFO_VERSION.MARKUP_INFO.DOCINFO_ID == docinfo_id
2960
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.CONSOLIDATE == 1
2961
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.AVOID_CONSOLIDATE == 0
2962
                    && x.MARKUP_INFO_VERSION.MARKUP_INFO.PART_CONSOLIDATE == 0).ToList();
2963
                    foreach (var data in datas)
2964
                    {
2965
                        MARKUP_DATA d = new MARKUP_DATA()
2966
                        {
2967
                            ID = data.ID,
2968
                            //GROUP_ID = data.GROUP_ID,
2969
                            SYMBOL_ID = data.SYMBOL_ID,
2970
                            DATA = data.DATA,
2971
                            DATA_TYPE = data.DATA_TYPE,
2972
                            MARKUPINFO_VERSION_ID = data.MARKUPINFO_VERSION_ID,
2973
                            PAGENUMBER = data.PAGENUMBER
2974
                        };
2975
                        results.Add(d);
2976
                    }
2977
                }
2978
            }
2979
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
2980
                throw;
2981
            }
2982
            return results;
2983
        }
2984
        [OperationContract]
2985
        [ServiceKnownType(typeof(MARKUP_INFO))]
2986
        public MARKUP_INFO FinalPDF_GetMarkupinfo(string project_no, string docinfo_id)
2987
        {
2988
            MARKUP_INFO markupInfo = null;
2989

    
2990
            try
2991
            {
2992
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
2993
                using (CIEntities _entity = new CIEntities(sCIConnString))
2994
                {
2995
                    var tmp = _entity.MARKUP_INFO.Where(x => x.DOCINFO_ID == docinfo_id && x.CONSOLIDATE == 1 && x.AVOID_CONSOLIDATE == 0 && x.PART_CONSOLIDATE == 0).FirstOrDefault();
2996
                    if (tmp != null)
2997
                    {
2998
                        markupInfo = new MARKUP_INFO()
2999
                        {
3000
                            ID = tmp.ID,
3001
                            DOCINFO_ID = tmp.DOCINFO_ID,
3002
                            USER_ID = tmp.USER_ID
3003
                        };
3004
                    }                    
3005
                }
3006
            }
3007
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3008
                throw;
3009
            }
3010
            return markupInfo;
3011
        }
3012
        [OperationContract]
3013
        [ServiceKnownType(typeof(FINAL_PDF))]
3014
        public List<FINAL_PDF> FinalPDF_GetFinalPDFs(string final_id)
3015
        {
3016
            List<FINAL_PDF> results = new List<FINAL_PDF>();
3017

    
3018
            try
3019
            {
3020
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3021
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3022
                {
3023
                    var finalList = _entity.FINAL_PDF.Where(final => final.ID == final_id).ToList();
3024
                    foreach(var final in finalList)
3025
                    {
3026
                        FINAL_PDF pdf = new FINAL_PDF()
3027
                        {
3028
                            ID = final.ID,
3029
                            DOCINFO_ID = final.DOCINFO_ID,
3030
                            DOCUMENT_ID = final.DOCUMENT_ID,
3031
                            STATUS = final.STATUS,
3032
                            CURRENT_PAGE = final.CURRENT_PAGE,
3033
                            CREATE_DATETIME = final.CREATE_DATETIME,
3034
                            START_DATETIME = final.START_DATETIME,
3035
                            END_DATETIME = final.END_DATETIME,
3036
                            EXCEPTION = final.EXCEPTION,
3037
                            PROJECT_NO = final.PROJECT_NO,
3038
                            TOTAL_PAGE = final.TOTAL_PAGE,
3039
                            MARKUPINFO_ID = final.MARKUPINFO_ID,
3040
                            CREATE_USER_ID = final.CREATE_USER_ID
3041
                        };
3042
                        results.Add(pdf);
3043
                    }
3044
                }
3045
            }
3046
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3047
                throw;
3048
            }
3049
            return results;
3050
        }
3051
        [OperationContract]
3052
        [ServiceKnownType(typeof(DOCPAGE))]
3053
        public List<DOCPAGE> FinalPDF_GetDocpage(string project_no, string docinfo_id)
3054
        {
3055
            List<DOCPAGE> results = new List<DOCPAGE>();
3056

    
3057
            try
3058
            {
3059
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
3060
                using (CIEntities _entity = new CIEntities(sCIConnString))
3061
                {
3062
                    var pages = _entity.DOCPAGE.Where(x => x.DOCINFO_ID == docinfo_id).OrderBy(x => x.PAGE_NUMBER).ToList();
3063
                    foreach(var page in pages)
3064
                    {
3065
                        DOCPAGE p = new DOCPAGE()
3066
                        {
3067
                            PAGE_ANGLE = page.PAGE_ANGLE,
3068
                            PAGE_NUMBER = page.PAGE_NUMBER,
3069
                            PAGE_HEIGHT = page.PAGE_HEIGHT,
3070
                            PAGE_WIDTH = page.PAGE_WIDTH,
3071
                            DOCINFO_ID = page.DOCINFO_ID                            
3072
                        };
3073
                        results.Add(p);
3074
                    }                    
3075
                }
3076
            }
3077
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3078
                throw;
3079
            }
3080
            return results;
3081
        }
3082
        [OperationContract]        
3083
        public bool FinalPDF_SetFinalPDFStatus(string final_id, FinalStatus status)
3084
        {
3085
            bool result = false;
3086

    
3087
            try
3088
            {
3089
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3090
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3091
                {
3092
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
3093
                    if(tmp != null)
3094
                    {
3095
                        switch(status)
3096
                        {
3097
                            case FinalStatus.Create:
3098
                                tmp.START_DATETIME = DateTime.Now;
3099
                                break;
3100
                            case FinalStatus.Success:
3101
                                tmp.END_DATETIME = DateTime.Now;
3102
                                tmp.EXCEPTION = string.Empty;
3103
                                break;                                
3104
                        }
3105
                        tmp.STATUS = (int)status;
3106
                        _entity.SaveChanges();
3107
                        result = true;                        
3108
                    }
3109
                }                    
3110
            }
3111
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3112
                throw;
3113
            }
3114
            return result;
3115
        }
3116

    
3117
        /// <summary>
3118
        /// 현재 진행중인 Final PDF 가 없거나 Success 일 경우에만 true return
3119
        /// </summary>
3120
        /// <param name="DocInfoID"></param>
3121
        /// <param name="MarkupInfoID"></param>
3122
        /// <param name="CreateUserID"></param>
3123
        /// <returns></returns>
3124
        [OperationContract]
3125
        public bool FinalPDF_GetFinalPDFStatus(string DocInfoID, string MarkupInfoID, string CreateUserID)
3126
        {
3127
            bool result = false;
3128

    
3129
            try
3130
            {
3131
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3132
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3133
                {
3134
                    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();
3135
                    if (finalpdf != null)
3136
                    {
3137
                        if (finalpdf.STATUS == (int)FinalStatus.Success)
3138
                        {
3139
                            result = true;
3140
                        }
3141
                    }
3142
                    else
3143
                        result = true;
3144
                }
3145
            }
3146
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3147
                throw;
3148
            }
3149
            return result;
3150
        }
3151

    
3152
        [OperationContract]
3153
        public bool FinalPDF_SetCurrentPage(string final_id, int currentpage)
3154
        {
3155
            bool result = false;
3156

    
3157
            try
3158
            {
3159
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3160
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3161
                {
3162
                    var tmp = _entity.FINAL_PDF.Where(x => x.ID == final_id).FirstOrDefault();
3163
                    if (tmp != null)
3164
                    {
3165
                        tmp.CURRENT_PAGE = currentpage;
3166
                        _entity.SaveChanges();
3167
                        result = true;
3168
                    }
3169
                }
3170
            }
3171
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3172
                throw;
3173
            }
3174
            return result;
3175
        }
3176
        [OperationContract]
3177
        public bool FinalPDF_SetError(string final_id, string msg)
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.STATUS = (int)FinalStatus.Error;
3190
                        tmp.EXCEPTION = DateTime.Now.ToShortDateString() + " " + msg;                        
3191
                        _entity.SaveChanges();
3192
                        result = true;
3193
                    }
3194
                }
3195
            }
3196
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3197
                throw;
3198
            }
3199
            return result;
3200
        }
3201

    
3202
        [OperationContract]
3203
        public bool FinalPDF_SetFinalResultPath(string project_no, string document_id, string url)
3204
        {
3205
            bool result = false;
3206

    
3207
            try
3208
            {
3209
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
3210
                using (CIEntities _entity = new CIEntities(sCIConnString))
3211
                {
3212
                    var item = _entity.DOCUMENT_ITEM.Where(d =>d.PROJECT_NO == project_no && d.DOCUMENT_ID == document_id).FirstOrDefault();
3213
                    if (item != null)
3214
                    {
3215
                        item.RESULT_FILE = url;
3216
                        _entity.SaveChanges();
3217
                        result = true;
3218
                    }
3219
                }
3220
            }
3221
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3222
                throw;
3223
            }
3224
            return result;
3225
        }
3226

    
3227
        [OperationContract]
3228
        public bool SaveLog(string project_no, string document_id, string Log)
3229
        {
3230
            bool result = false;
3231

    
3232
            try
3233
            {
3234
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3235
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3236
                {
3237
                    _entity.AddToERROR_LOG(new ERROR_LOG
3238
                    {
3239
                        PROJECT_NO = project_no,
3240
                        DOCUMENT_ID = document_id,
3241
                        CONTENTS = Log,
3242
                        CREATE_DATETIME = DateTime.Now.ToString("yyMMddssmm"),
3243
                        CODE = "",
3244
                        TYPE = "Markus Log",
3245
                        LEVEL = "",
3246
                        SERVICE_NAME = "Markus",
3247
                    });
3248

    
3249
                    _entity.SaveChanges();
3250
                }
3251
            }
3252
            catch (Exception ex)
3253
            {
3254
            }
3255

    
3256
            return result;
3257
        }
3258

    
3259
        [OperationContract]
3260
        [ServiceKnownType(typeof(MEMBER))]
3261
        public MEMBER FinalPDF_GetCommentMember(string project_no, string markupdata_id)
3262
        {
3263
            MEMBER member = null;
3264
            try
3265
            {
3266
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
3267
                using (CIEntities _entity = new CIEntities(sCIConnString))
3268
                {
3269
                    var data = _entity.MARKUP_DATA.Where(x => x.ID == markupdata_id).FirstOrDefault();
3270
                    string user_id = data.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID;
3271

    
3272
                    var person = GetMemberQuery(_entity,user_id);
3273

    
3274
                    if(person.Count() > 0)
3275
                    {
3276
                        member = person.First();
3277
                    }
3278
                }
3279
            }
3280
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3281
                throw;
3282
            }
3283

    
3284
            return member;
3285
        }
3286

    
3287
        [OperationContract]
3288
        [ServiceKnownType(typeof(PROPERTIES))]
3289
        public List<PROPERTIES> FinalPDF_GetProperties(string project_no)
3290
        {
3291
            List<PROPERTIES> results = new List<PROPERTIES>();
3292
            try
3293
            {
3294
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
3295
                using (KCOMEntities _entity = new KCOMEntities(sConnString))
3296
                {
3297
                    var _items = _entity.PROPERTIES.Where(x => x.PROPERTY == project_no).ToList();
3298
                    foreach(var item in _items)
3299
                    {
3300
                        PROPERTIES pROPERTIES = new PROPERTIES()
3301
                        {
3302
                            ID = item.ID,
3303
                            PROPERTY = item.PROPERTY,
3304
                            TYPE = item.TYPE,
3305
                            VALUE = item.VALUE
3306
                        };
3307
                        results.Add(pROPERTIES);
3308
                    }
3309
                }
3310

    
3311
            }
3312
            catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex);
3313
                throw;
3314
            }
3315
            return results;
3316
        }
3317
        #endregion
3318
    }    
3319
}
클립보드 이미지 추가 (최대 크기: 500 MB)