프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / ConvertionWebService / Conversion.asmx.cs @ 06f13e11

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

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Web;
5
using System.Web.Services;
6
using System.Runtime.Remoting.Channels;
7
using System.Runtime.Remoting.Channels.Tcp;
8
using IConverterPDF;
9
using System.Text;
10
using DeepViewDataModel.DataModel;
11
using DeepViewDataModel.Common;
12
using DeepView.Toolkit.GuidGenerator;
13
using MarkupToPDF;
14
using System.IO;
15
using Newtonsoft.Json;
16
using Newtonsoft.Json.Linq;
17
using log4net;
18

    
19
namespace ConvertionWebService
20
{
21
    /// <summary>
22
    /// Summary description for Conversio
23
    /// </summary>
24
    [WebService(Namespace = "http://tempuri.org/")]
25
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
26
    [System.ComponentModel.ToolboxItem(false)]
27
    public class Conversion : System.Web.Services.WebService
28
    {
29

    
30
        RemConverterPDFObject remObj = null;
31
        protected ILog logger = LogManager.GetLogger(typeof(Conversion));
32
        public Conversion()
33
        {
34
            try
35
            {
36
                System.Runtime.Remoting.Channels.IChannel _ch = ChannelServices.GetChannel("tcp");
37

    
38
                if(_ch == null)
39
                {
40
                    TcpChannel chan = new TcpChannel();
41
                    ChannelServices.RegisterChannel(chan, false);
42
                }
43
                // Create an instance of the remote object
44
                remObj = (RemConverterPDFObject)Activator.GetObject(typeof(RemConverterPDFObject),
45
                                                            Properties.Settings.Default.ConverterRemotingUrl);
46

    
47
            }
48
            catch (Exception ex)
49
            {
50
                logger.Error("Conversion Web Service Conversion Error", ex);
51
                SendNotice(ex.ToString());
52
            }
53
        }
54

    
55
        private void SendNotice(string ex)
56
        {
57
            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.ErrorNoticeID))
58
            {
59
                var _lstID = Properties.Settings.Default.ErrorNoticeID.Split(';').ToList();
60
                //EmailClient.EmailClient _client = new EmailClient.EmailClient(_lstID.First());
61
                StringBuilder _bl = new StringBuilder();
62
                _bl.AppendLine("Conversion Web Service Error");
63
                _bl.AppendLine(ex);
64
                //var _emailResult = _client.SendEmail(_lstID, _lstID, "<Conversion Web Service Error>", _bl.ToString(), false);
65
            }
66
            else
67
            {
68
                logger.Error("Conversion Web Service Error",new Exception(ex));
69
            }
70
        }
71

    
72
        [WebMethod]
73
        public string ConvertRun(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
74
        {
75
            string _result = null;
76
            try
77
            {
78
                logger.Info($"Conversion Web Service ConvertRun call rev_No :{rev_No} document_No : {document_No}  document_Name : {document_Name}  group_No : {group_No}  prj_No : {prj_No}  document_Id : {document_Id}  document_Url : {document_Url}");
79

    
80
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
81
                {
82
                    //_result = ConnectStringBuilder.DeepViewConnectionString().ToString();
83
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now);
84
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber);
85
                    var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null);
86

    
87
                    if (_RunProjects.Count() > 0)
88
                    {
89
                        _result = SendKcom(rev_No, document_No, document_Name, group_No, prj_No, document_Id, document_Url);
90
                    }
91
                    else
92
                    {
93
                        _result = false.ToString();
94
                    }
95
                }
96
            }
97
            catch (Exception ex)
98
            {
99
                logger.Error($"Conversion Web Service ConvertRun Error rev_No :{rev_No} document_No : {document_No}  document_Name : {document_Name}  group_No : {group_No}  prj_No : {prj_No}  document_Id : {document_Id}  document_Url : {document_Url}", ex);
100
                _result = ex.Message.ToString();
101
                SendNotice("Project NO : " + prj_No + "\r\n  DocumentUrl : " + document_Url + "\r\n Error" + ex.ToString());
102
            }
103
            return _result;
104
        }
105

    
106
        [WebMethod]
107
        public string ConvertRunIgnoreComment(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url, string ignoreComment)
108
        {
109
            string _result = null;
110
            try
111
            {
112
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
113
                {
114
                    //_result = ConnectStringBuilder.DeepViewConnectionString().ToString();
115
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now);
116
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber);
117
                    var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null);
118

    
119
                    if (_RunProjects.Count() > 0)
120
                    {
121
                        _result = SendKcom(rev_No, document_No, document_Name, group_No, prj_No, document_Id, document_Url,ignoreComment);
122
                    }
123
                    else
124
                    {
125
                        _result = false.ToString();
126
                    }
127
                }
128
            }
129
            catch (Exception ex)
130
            {
131
                _result = ex.Message.ToString();
132
                SendNotice("Project NO : " + prj_No + "\r\n  DocumentUrl : " + document_Url + "\r\n Error" + ex.ToString());
133
            }
134
            return _result;
135
        }
136

    
137
        private string SendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url, string ignoreComment)
138
        {
139
            string result = false.ToString();
140

    
141
            if (remObj == null)
142
            {
143
                result = "Window Service Connection Error";
144
            }
145
            else
146
            {
147
                //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString();
148
                string _id = shortGuid();
149
                string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString();
150
                
151
                using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
152
                {
153
                    if (string.IsNullOrEmpty(group_No))
154
                    {
155
                        group_No = "0";
156
                    }
157
                    if (!prj_No.Equals("150128"))
158
                    {
159
                        //Omsk 는 웹서비스 호출 시 인코딩
160
                        //Omsk 제외는 Markus 에서 인코딩
161
                        document_Url = Base64Decode(document_Url);
162
                    }
163
                    var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault();
164
                    if (doc != null)
165
                    {
166
                        if (bool.Parse(ignoreComment))
167
                        {
168
                            try
169
                            {
170
                                var docinfo = _entity.DOCINFO.Where(x => x.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
171
                                var markupinfos = _entity.MARKUP_INFO.Where(x => x.DOCINFO_ID == docinfo.ID).ToList();
172
                                foreach (var markupinfo in markupinfos)
173
                                {
174
                                    var markupinfoversions = _entity.MARKUP_INFO_VERSION.Where(x => x.MARKUPINFO_ID == markupinfo.ID).ToList();
175
                                    foreach (var markupinfoversion in markupinfoversions)
176
                                    {
177
                                        var markupdatas = _entity.MARKUP_DATA.Where(x => x.MARKUPINFO_VERSION_ID == markupinfoversion.ID).ToList();
178
                                        foreach (var markupdata in markupdatas)
179
                                        {
180
                                            _entity.DeleteObject(markupdata);
181
                                        }
182
                                        _entity.DeleteObject(markupinfoversion);
183
                                    }
184
                                    _entity.DeleteObject(markupinfo);
185
                                }
186
                                _entity.SaveChanges();
187
                            }
188
                            catch (Exception ex)
189
                            {
190
                                result = "deleteobject error:"+ex.ToString();
191
                            }
192
                                                    
193
                        }else
194
                        {
195
                            doc.REVISION = rev_No;
196
                            doc.ORIGINAL_FILE = document_Url;
197
                            doc.GROUP_NO = group_No;
198
                            doc.DOCUMENT_NO = document_No;
199
                            doc.DOCUMENT_NAME = document_Name;
200
                        }                        
201
                    }else
202
                    {
203
                        _entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM
204
                        {
205
                            ID = document_Id,
206
                            REVISION = rev_No,
207
                            DOCUMENT_NO = document_No,
208
                            DOCUMENT_NAME = document_Name,
209
                            GROUP_NO = group_No,
210
                            ORIGINAL_FILE = document_Url,
211
                            DOCUMENT_ID = _doc_id,
212
                            PROJECT_NO = prj_No,
213
                        });                        
214
                    }                    
215
                    
216
                    _entity.AddToCONVERTER_DOC(new CONVERTER_DOC
217
                    {
218
                        ID = _id,
219
                        CREATE_DATETIME = DateTime.Now,
220
                        DOCUMENT_URL = document_Url,
221
                        PROJECT_NO = prj_No,
222
                        DOCUMENT_ID = _doc_id,
223
                    });
224
                    _entity.SaveChanges();
225
                }
226

    
227
                if (Properties.Settings.Default.MARKUS_V3_PROJECTS.Split(',').Contains(prj_No))
228
                {
229
                    try
230
                    {
231
                        System.Net.WebClient client = new System.Net.WebClient();
232
                        var convertResult = client.DownloadString($"{Properties.Settings.Default.MARKUS_V3_ADDRESS}/Rest/ConvertAdd?ProjectNo={prj_No}&DocumentID={_id}");
233

    
234
                        JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings());
235
                        result = jObject["ConvertAddResult"].ToString();
236
                    }
237
                    catch (Exception ex)
238
                    {
239
                        result = $"Markus V3 Connect Error {ex.Message}";
240
                    }
241
                }
242
                else
243
                {
244
                    var convertResult = remObj.SetConverterPDF(prj_No, _id);
245

    
246
                    if (convertResult.Exception != null)
247
                    {
248
                        result = false.ToString();
249
                    }
250
                    else
251
                    {
252
                        result = true.ToString();
253
                    }
254
                }
255

    
256
            }
257

    
258
            return result;
259
        }
260
        [WebMethod]
261
        public string ManualConvert(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
262
        {
263
            string _result = null;
264
            try
265
            {
266
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
267
                {
268
                    //_result = ConnectStringBuilder.DeepViewConnectionString().ToString();
269
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now);
270
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber);
271
                    var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null);
272

    
273
                    if (_RunProjects.Count() > 0)
274
                    {
275
                        _result = ManualSendKcom(rev_No, document_No, document_Name, group_No, prj_No, document_Id, document_Url);
276
                    }
277
                    else
278
                    {
279
                        _result = false.ToString();
280
                    }
281
                }
282
            }
283
            catch (Exception ex)
284
            {
285
                logger.Error("Conversion Web Service ManualConvert Error", ex);
286
                _result = ex.Message.ToString();
287
                SendNotice("Project NO : " + prj_No + "\r\n  DocumentUrl : " + document_Url + "\r\n Error" + ex.ToString());
288
            }
289
            return _result;
290
        }
291
        [WebMethod]
292
        public string UpdateUrlEncode(string EnsembleId)
293
        {
294
            string _result = null;
295
            try
296
            {
297
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
298
                {
299
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
300
                    string url = doc.ORIGINAL_FILE;
301
                    if (url.Contains("http://"))
302
                    {
303
                        //기존 url 이 인코딩 안되 있으면 인코딩 작업.
304
                        url = HttpUtility.UrlEncodeUnicode(url);
305
                        doc.ORIGINAL_FILE = url;
306

    
307
                        var convertdoc = deepViewEntity.CONVERTER_DOC.Where(d => d.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
308
                        if(convertdoc != null)
309
                            convertdoc.DOCUMENT_URL = url;
310
                        var docinfo = deepViewEntity.DOCINFO.Where(d => d.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
311
                        if(docinfo != null)
312
                            docinfo.ORIGINAL_FILE = url;
313
                    }
314
                        
315
                    deepViewEntity.SaveChanges();
316
                }
317
            }
318
            catch (Exception ex)
319
            {
320
                logger.Error("Conversion Web Service UpdateUrlEncode Error", ex);
321
                _result = ex.Message.ToString();
322
            }
323
            return _result;
324
        }
325
        public string Base64Decode(string data)
326
        {
327
            try
328
            {
329

    
330
                System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
331
                System.Text.Decoder utf8Decode = encoder.GetDecoder();
332

    
333
                byte[] todecode_byte = Convert.FromBase64String(data);
334

    
335
                int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
336

    
337
                char[] decoded_char = new char[charCount];
338

    
339
                utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
340

    
341
                string result = new String(decoded_char);
342

    
343
                return result;
344

    
345
            }
346

    
347
            catch (Exception e)
348
            {
349
                throw new Exception("Error in Base64Decode: " + e.Message);
350
            }
351
        }
352
        [WebMethod]
353
        public string UpdateSlip(string EnsembleId, string SlipNo, string slipLink)
354
        {
355
            string _result = null;
356
            try
357
            {
358
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
359
                {
360
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
361
                    if(!string.IsNullOrEmpty(slipLink))
362
                        doc.GROUP_NO = SlipNo;
363
                    if(!string.IsNullOrEmpty(slipLink))
364
                    {
365
                        if (!slipLink.Contains("http://"))
366
                            slipLink = Base64Decode(slipLink);
367
                        throw new Exception("doc.ENSEMBLEINFO_URL not support");
368
                        //doc.ENSEMBLEINFO_URL = slipLink;
369
                    }
370
                    
371
                    deepViewEntity.SaveChanges();
372
                }
373
            }
374
            catch (Exception ex)
375
            {
376
                logger.Error($"Conversion Web Service UpdateSlip Error EnsembleId : {EnsembleId} SlipNo : {SlipNo}   slipLink: {slipLink}", ex);
377
                _result = ex.Message.ToString();                
378
            }
379
            return _result;
380
        }
381
        [WebMethod]
382
        public string UpdateResult(string EnsembleId, string Result, string FinalPDFUrl)
383
        {
384
            string _result = null;
385
            try
386
            {
387
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
388
                {
389
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
390
                    doc.RESULT = Result;
391
                    doc.RESULT_FILE = FinalPDFUrl;
392
                    deepViewEntity.SaveChanges();
393
                }
394
            }
395
            catch (Exception ex)
396
            {
397
                logger.Error("Conversion Web Service UpdateResult Error", ex);
398
                _result = ex.Message.ToString();
399
            }
400
            return _result;
401
        }
402
        [WebMethod]
403
        public string UpdateVP(string EnsembleId, string rev_No, string document_No, string document_Name, string pdf_url)
404
        {
405
            string _result = null;
406
            try
407
            {
408
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
409
                {
410
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
411
                    if(!string.IsNullOrEmpty(rev_No))
412
                        doc.REVISION = rev_No;
413
                    if (!string.IsNullOrEmpty(document_No))
414
                        doc.DOCUMENT_NO = document_No;
415
                    if (!string.IsNullOrEmpty(document_Name))
416
                        doc.DOCUMENT_NAME = document_Name;
417
                    if (!string.IsNullOrEmpty(pdf_url))
418
                    {
419
                        string url = pdf_url;
420
                        if (!doc.PROJECT_NO.Equals("150128"))
421
                        {   
422
                            url = HttpUtility.UrlEncodeUnicode(url);
423
                        }
424
                        doc.ORIGINAL_FILE = url;
425
                    }                        
426
                    deepViewEntity.SaveChanges();
427
                }
428
            }
429
            catch (Exception ex)
430
            {
431
                logger.Error("Conversion Web Service UpdateVP Error", ex);
432
                _result = ex.Message.ToString();
433
            }
434
            return _result;
435
        }
436
        [WebMethod]
437
        public string CoverConvert(string prj_No, string _id)
438
        {
439
            string _result = null;
440
            try
441
            {
442
                SendCoverConvert(prj_No, _id);
443
            }
444
            catch (Exception ex)
445
            {
446
                logger.Error("Conversion Web Service CoverConvert Error", ex);
447
                _result = ex.Message.ToString();
448
            }
449
            return _result;
450
        }
451
        private string SendCoverConvert(string prj_No, string _id)
452
        {
453
            if (remObj == null)
454
            {
455
                return "Window Service Connection Error";
456
            }
457
            else
458
            {
459
                var _result = remObj.SetConverterCoverPDF(prj_No, _id);
460

    
461
                if (_result.Exception != null)
462
                {
463
                    return false.ToString();
464
                }
465
                else
466
                {
467
                    return true.ToString();
468
                }
469
            }
470
        }
471
        private string SendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
472
        {
473
            string result = false.ToString();
474

    
475
            if (remObj == null)
476
            {
477
                result  = "Window Service Connection Error";
478
            }
479
            else
480
            {
481
                //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString();
482
                string _id = shortGuid();
483
                string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString();
484
                using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
485
                {
486
                    if (string.IsNullOrEmpty(group_No))
487
                    {
488
                        group_No = "0";
489
                    }
490
                    if (!prj_No.Equals("150128"))
491
                    {
492
                        //Omsk 는 웹서비스 호출 시 인코딩
493
                        //Omsk 제외는 Markus 에서 인코딩
494
                        document_Url = Base64Decode(document_Url);
495
                    }
496
                    var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault();
497
                    if(doc != null)
498
                    {
499
                        doc.REVISION = rev_No;
500
                        doc.ORIGINAL_FILE = document_Url;
501
                        doc.GROUP_NO = group_No;
502
                        doc.DOCUMENT_NO = document_No;
503
                        doc.DOCUMENT_NAME = document_Name;                        
504
                    }else
505
                    {
506
                        _entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM
507
                        {
508
                            ID = document_Id,
509
                            REVISION = rev_No,
510
                            DOCUMENT_NO = document_No,
511
                            DOCUMENT_NAME = document_Name,
512
                            GROUP_NO = group_No,
513
                            ORIGINAL_FILE = document_Url,
514
                            DOCUMENT_ID = _doc_id,
515
                            PROJECT_NO = prj_No,
516
                        });
517
                    }
518
                    
519
                    _entity.AddToCONVERTER_DOC(new CONVERTER_DOC
520
                    {
521
                        ID = _id,
522
                        CREATE_DATETIME = DateTime.Now,
523
                        DOCUMENT_URL = document_Url,
524
                        PROJECT_NO = prj_No,
525
                        DOCUMENT_ID = _doc_id,
526
                    });
527
                    _entity.SaveChanges();
528
                }
529

    
530
                if (Properties.Settings.Default.MARKUS_V3_PROJECTS.Split(',').Contains(prj_No))
531
                {
532
                    try
533
                    {
534
                        System.Net.WebClient client = new System.Net.WebClient();
535
                        var convertResult = client.DownloadString($"{Properties.Settings.Default.MARKUS_V3_ADDRESS}/Rest/ConvertAdd?ProjectNo={prj_No}&DocumentID={_id}");
536

    
537
                        JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings());
538
                        result = jObject["ConvertAddResult"].ToString();
539
                    }
540
                    catch (Exception ex)
541
                    {
542
                        logger.Error("Conversion Web Service SendKcom Error", ex);
543
                        result = $"Markus V3 Connect Error {ex.Message}";
544
                    }
545
                }
546
                else
547
                {
548
                    var convertResult = remObj.SetConverterPDF(prj_No, _id);
549

    
550
                    if (convertResult.Exception != null)
551
                    {
552
                        result = false.ToString();
553
                    }
554
                    else
555
                    {
556
                        result = true.ToString();
557
                    }
558
                }
559

    
560
            }
561

    
562
            return result;
563
        }
564
                
565
        private string ManualSendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
566
        {
567
            if (remObj == null)
568
            {
569
                return "Window Service Connection Error";
570
            }
571
            else
572
            {
573
                //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString();
574
                string _id = shortGuid();
575
                string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString();
576
                using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
577
                {
578
                    var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault();
579
                    if (doc != null)
580
                    {
581
                        var converterdoc = _entity.CONVERTER_DOC.Where(c => c.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
582
                        _entity.DeleteObject(converterdoc);
583
                        _entity.DeleteObject(doc);
584
                        _entity.SaveChanges();
585
                        document_Url = HttpUtility.UrlDecode(document_Url);
586
                    }
587
                    int cnt = _entity.DOCUMENT_ITEM.ToList().Count;
588
                    if (string.IsNullOrEmpty(group_No))
589
                    {
590
                        group_No = "0";
591
                    }
592
                    
593
                    _entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM
594
                    {
595
                        ID = document_Id,
596
                        REVISION = rev_No,
597
                        DOCUMENT_NO = document_No,
598
                        DOCUMENT_NAME = document_Name,
599
                        GROUP_NO = group_No,
600
                        ORIGINAL_FILE = HttpUtility.UrlEncodeUnicode(document_Url),
601
                        DOCUMENT_ID = _doc_id,
602
                        PROJECT_NO = prj_No,
603
                    });
604
                    _entity.AddToCONVERTER_DOC(new CONVERTER_DOC
605
                    {
606
                        ID = _id,
607
                        CREATE_DATETIME = DateTime.Now,
608
                        DOCUMENT_URL = HttpUtility.UrlEncodeUnicode(document_Url),
609
                        PROJECT_NO = prj_No,
610
                        DOCUMENT_ID = _doc_id,
611
                    });
612
                    _entity.SaveChanges();
613
                }
614
                var _result = remObj.SetConverterPDF(prj_No, _id);
615

    
616
                if (_result.Exception != null)
617
                {
618
                    return false.ToString();
619
                }
620
                else
621
                {
622
                    return true.ToString();
623
                }
624
            }
625
        }
626

    
627
        //private Guid GetGuid(int Count,Guid ID)
628
        //{
629
        //    Guid _ID = ID;
630
        //    string _id = _ID.ToString();
631
        //    DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString());
632

    
633
        //    if (_entity.CONVERTER_DOC.Where(c => c.ID == _id).Count() > 0)
634
        //    {
635
        //        _entity.Dispose();
636

    
637
        //        if (Count > 10)
638
        //        {
639
        //            new Exception("GetGuid : Not Generator");
640
        //        }
641

    
642
        //        if (Count < 3)
643
        //        {
644
        //            System.Threading.Thread.Sleep(3);
645
        //        }
646

    
647
        //        GetGuid(Count++,GuidGenerator.GetUniqueGuid());
648
        //    }
649

    
650
        //    return ID;
651
        //}
652

    
653
        //GUID생성(최민수 사원 수정)
654
        public string shortGuid()
655
        {
656
            byte[] bytes = new byte[16];
657
            using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create())
658
            {
659
                provider.GetBytes(bytes);
660
            }
661

    
662
            var guid = new Guid(bytes);
663

    
664
            return Convert.ToBase64String(guid.ToByteArray())
665
                .Substring(0, 10)
666
                .Replace("/", "")
667
                .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
668
        }
669

    
670
        [WebMethod]
671
        public string ExcelExport(string project_no, string slip_no)
672
        {
673
            string _result = "false";
674
            //FileInfo fileInfo2 = new FileInfo(Path.GetTempFileName());
675
            //fileInfo2.FullName
676
            try
677
            {
678
                // Excel 첫번째 워크시트 가져오기                
679
                //application = new Excel.Application();
680
                //workbook = application.Workbooks.Open(xlsxfilepath);
681
                //worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item("Sheet1");
682
                string xlsxfilepath = @"C:\WebSite\LogView\Doc_Manager\sample.xlsx";
683
                GemBox.Spreadsheet.SpreadsheetInfo.SetLicense("EXK0-W4HZ-N518-IMEW");
684
                GemBox.Spreadsheet.ExcelFile excelFile = new GemBox.Spreadsheet.ExcelFile();
685
                excelFile.LoadXlsx(xlsxfilepath, GemBox.Spreadsheet.XlsxOptions.PreserveMakeCopy);
686
                GemBox.Spreadsheet.ExcelWorksheet ws = excelFile.Worksheets[0];
687
                FileInfo fileInfo2 = new FileInfo(Path.GetTempFileName().Replace(".tmp", ".xlsx"));
688

    
689
                string fileout = @"C:\WebSite\LogView\Doc_Manager\commentexcel_" + DateTime.Now.ToString() + ".xlsx";
690
                string naspath = Properties.Settings.Default.Excelfilepath;
691
                    //@"\\172.20.121.220\comment3\TileSource\Excelexport";
692

    
693
                // 데이타 넣기
694
                int h = 6;
695
                int w = 1;
696

    
697

    
698
                //필터 기능 추가
699
                //Excel.Range Filter_Range = worksheet.Range["B9:" + Ran + "9"];
700
                //Filter_Range.AutoFilter(1, Type.Missing, Excel.XlAutoFilterOperator.xlAnd, Type.Missing, true);
701

    
702

    
703
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
704
                {
705
                    var docs = deepViewEntity.DOCUMENT_ITEM.Where(doc => doc.GROUP_NO == slip_no && doc.PROJECT_NO == project_no).ToList();
706
                    if (docs.Count > 0)
707
                    {
708
                        foreach (var doc in docs)
709
                        {
710
                            var commentlist = deepViewEntity.MARKUP_DATA.Where(d => d.MARKUP_INFO_VERSION.MARKUP_INFO.DOCINFO.DOCUMENT_ID == doc.DOCUMENT_ID
711
                            && d.MARKUP_INFO_VERSION.MARKUP_INFO.CONSOLIDATE == 1).ToList();
712

    
713
                            string docNo = doc.DOCUMENT_NO;
714
                            string docDesc = doc.DOCUMENT_NAME;
715
                            string docRev = doc.REVISION;
716
                            foreach (var comment in commentlist)
717
                            {
718
                                var member = deepViewEntity.MEMBER.Where(m => m.ID == comment.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID).FirstOrDefault();
719
                                string docdept = member.DEPARTMENT;
720
                                string doccomment = string.Empty;
721
                                var data = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressString(comment.DATA.ToString());
722
                                switch (Enum.Parse(typeof(MarkupToPDF.Controls.Common.ControlType), comment.DATA_TYPE.ToString()))
723
                                {
724
                                    case MarkupToPDF.Controls.Common.ControlType.TextControl:
725
                                    case MarkupToPDF.Controls.Common.ControlType.TextBorder:
726
                                    case MarkupToPDF.Controls.Common.ControlType.TextCloud:
727
                                        {
728
                                            MarkupToPDF.Serialize.S_Control.S_TextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_TextControl>(data);
729
                                            doccomment = instance.Text;
730
                                        }
731
                                        break;
732
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTextBorderControl:
733
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTextCloudControl:
734
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTextControl:
735
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextBorderControl:
736
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextCloudControl:
737
                                    case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextControl:
738
                                        {
739
                                            MarkupToPDF.Serialize.S_Control.S_ArrowTextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_ArrowTextControl>(data);
740
                                            doccomment = instance.ArrowText;
741
                                        }
742
                                        break;
743
                                }
744
                                ws.Cells[h, w].Value = string.Format("{0}\n({1})", docNo, docDesc);
745
                                ws.Cells[h, w + 1].Value = docRev;
746
                                ws.Cells[h, w + 2].Value = docdept;
747
                                ws.Cells[h, w + 3].Value = doccomment;
748
                                h++;
749
                            }
750
                        }
751
                    }
752
                    else
753
                    {
754
                        _result = "ERROR : 해당 Slip 의 데이터가 없습니다.";
755
                    }
756

    
757

    
758
                }
759

    
760
                int columnCount = ws.CalculateMaxUsedColumns();
761
                for (int i = 0; i < columnCount; i++)
762
                    ws.Columns[i].AutoFit();
763
                //worksheet.Columns.AutoFit();
764
                // 엑셀파일 저장
765

    
766
                excelFile.Save(fileInfo2.FullName);
767
                fileInfo2.MoveTo(naspath + "\\" + fileInfo2.Name);
768
                //workbook.SaveAs(fileout);
769
                ////workbook.Save();
770
                //workbook.Close(true);
771
                //application.Quit();
772
                _result = Properties.Settings.Default.Excelresulturl + fileInfo2.Name;
773
            }
774
            catch (Exception e)
775
            {
776
                _result = "ERROR : " + e.ToString();
777
            }
778
            return _result;
779
        }
780

    
781
        private static void ReleaseExcelObject(object obj)
782
        {
783
            try
784
            {
785
                if (obj != null)
786
                {
787
                    obj = null;
788
                }
789
            }
790
            catch (Exception ex)
791
            {
792
                obj = null;
793
                throw ex;
794
            }
795
            finally
796
            {
797
                GC.Collect();
798
            }
799
        }
800
    }
801
}
클립보드 이미지 추가 (최대 크기: 500 MB)