프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / ConvertionWebService / Conversion.asmx.cs @ 41fa3d98

이력 | 보기 | 이력해설 | 다운로드 (32.6 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 Excel = Microsoft.Office.Interop.Excel;
14
using MarkupToPDF;
15
using System.IO;
16
using Newtonsoft.Json;
17
using Newtonsoft.Json.Linq;
18
using log4net;
19

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

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

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

    
48
            }
49
            catch (Exception ex)
50
            {
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
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
79
                {
80
                    //_result = ConnectStringBuilder.DeepViewConnectionString().ToString();
81
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now);
82
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber);
83
                    var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null);
84

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

    
103
        [WebMethod]
104
        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)
105
        {
106
            string _result = null;
107
            try
108
            {
109
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
110
                {
111
                    //_result = ConnectStringBuilder.DeepViewConnectionString().ToString();
112
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now);
113
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber);
114
                    var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null);
115

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

    
134
        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)
135
        {
136
            string result = false.ToString();
137

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

    
220
                if (Properties.Settings.Default.MARKUS_V3_PROJECTS.Split(',').Contains(prj_No))
221
                {
222
                    try
223
                    {
224
                        System.Net.WebClient client = new System.Net.WebClient();
225
                        var convertResult = client.DownloadString($"{Properties.Settings.Default.MARKUS_V3_ADDRESS}/Rest/ConvertAdd?ProjectNo={prj_No}&DocumentID={_id}");
226

    
227
                        JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings());
228
                        result = jObject["ConvertAddResult"].ToString();
229
                    }
230
                    catch (Exception ex)
231
                    {
232
                        result = $"Markus V3 Connect Error {ex.Message}";
233
                    }
234
                }
235
                else
236
                {
237
                    var convertResult = remObj.SetConverterPDF(prj_No, _id);
238

    
239
                    if (convertResult.Exception != null)
240
                    {
241
                        result = false.ToString();
242
                    }
243
                    else
244
                    {
245
                        result = true.ToString();
246
                    }
247
                }
248

    
249
            }
250

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

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

    
299
                        var convertdoc = deepViewEntity.CONVERTER_DOC.Where(d => d.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
300
                        if(convertdoc != null)
301
                            convertdoc.DOCUMENT_URL = url;
302
                        var docinfo = deepViewEntity.DOCINFO.Where(d => d.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
303
                        if(docinfo != null)
304
                            docinfo.ORIGINAL_FILE = url;
305
                    }
306
                        
307
                    deepViewEntity.SaveChanges();
308
                }
309
            }
310
            catch (Exception ex)
311
            {
312
                _result = ex.Message.ToString();
313
            }
314
            return _result;
315
        }
316
        public string Base64Decode(string data)
317
        {
318
            try
319
            {
320

    
321
                System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
322
                System.Text.Decoder utf8Decode = encoder.GetDecoder();
323

    
324
                byte[] todecode_byte = Convert.FromBase64String(data);
325

    
326
                int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
327

    
328
                char[] decoded_char = new char[charCount];
329

    
330
                utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
331

    
332
                string result = new String(decoded_char);
333

    
334
                return result;
335

    
336
            }
337

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

    
447
                if (_result.Exception != null)
448
                {
449
                    return false.ToString();
450
                }
451
                else
452
                {
453
                    return true.ToString();
454
                }
455
            }
456
        }
457
        private string SendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
458
        {
459
            string result = false.ToString();
460

    
461
            if (remObj == null)
462
            {
463
                result  = "Window Service Connection Error";
464
            }
465
            else
466
            {
467
                //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString();
468
                string _id = shortGuid();
469
                string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString();
470
                using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
471
                {                    
472
                    var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault();
473
                    if(doc != null)
474
                    {
475
                        var converterdoc = _entity.CONVERTER_DOC.Where(c => c.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
476
                        _entity.DeleteObject(converterdoc);
477
                        _entity.DeleteObject(doc);
478
                        _entity.SaveChanges();
479
                        document_Url = HttpUtility.UrlDecode(document_Url);
480
                    }
481
                    int cnt = _entity.DOCUMENT_ITEM.ToList().Count;
482
                    if(string.IsNullOrEmpty(group_No))
483
                    {
484
                        group_No = "0";
485
                    }
486
                    if (!prj_No.Equals("150128"))
487
                    {
488
                        //Omsk 는 웹서비스 호출 시 인코딩
489
                        //Omsk 제외는 Markus 에서 인코딩
490
                        document_Url = HttpUtility.UrlEncodeUnicode(document_Url);
491
                    }
492
                    _entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM
493
                    {
494
                        ID = document_Id,
495
                        REVISION = rev_No,
496
                        DOCUMENT_NO = document_No,
497
                        DOCUMENT_NAME = document_Name,
498
                        GROUP_NO = group_No,
499
                        ORIGINAL_FILE = document_Url,
500
                        DOCUMENT_ID = _doc_id,
501
                        PROJECT_NO = prj_No,
502
                    });
503
                    _entity.AddToCONVERTER_DOC(new CONVERTER_DOC
504
                    {
505
                        ID = _id,
506
                        CREATE_DATETIME = DateTime.Now,
507
                        DOCUMENT_URL = document_Url,
508
                        PROJECT_NO = prj_No,
509
                        DOCUMENT_ID = _doc_id,
510
                    });
511
                    _entity.SaveChanges();
512
                }
513

    
514
                if (Properties.Settings.Default.MARKUS_V3_PROJECTS.Split(',').Contains(prj_No))
515
                {
516
                    try
517
                    {
518
                        System.Net.WebClient client = new System.Net.WebClient();
519
                        var convertResult = client.DownloadString($"{Properties.Settings.Default.MARKUS_V3_ADDRESS}/Rest/ConvertAdd?ProjectNo={prj_No}&DocumentID={_id}");
520

    
521
                        JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings());
522
                        result = jObject["ConvertAddResult"].ToString();
523
                    }
524
                    catch (Exception ex)
525
                    {
526
                        result = $"Markus V3 Connect Error {ex.Message}";
527
                    }
528
                }
529
                else
530
                {
531
                    var convertResult = remObj.SetConverterPDF(prj_No, _id);
532

    
533
                    if (convertResult.Exception != null)
534
                    {
535
                        result = false.ToString();
536
                    }
537
                    else
538
                    {
539
                        result = true.ToString();
540
                    }
541
                }
542

    
543
            }
544

    
545
            return result;
546
        }
547
                
548
        private string ManualSendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
549
        {
550
            if (remObj == null)
551
            {
552
                return "Window Service Connection Error";
553
            }
554
            else
555
            {
556
                //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString();
557
                string _id = shortGuid();
558
                string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString();
559
                using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
560
                {
561
                    var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault();
562
                    if (doc != null)
563
                    {
564
                        var converterdoc = _entity.CONVERTER_DOC.Where(c => c.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
565
                        _entity.DeleteObject(converterdoc);
566
                        _entity.DeleteObject(doc);
567
                        _entity.SaveChanges();
568
                        document_Url = HttpUtility.UrlDecode(document_Url);
569
                    }
570
                    int cnt = _entity.DOCUMENT_ITEM.ToList().Count;
571
                    if (string.IsNullOrEmpty(group_No))
572
                    {
573
                        group_No = "0";
574
                    }
575
                    
576
                    _entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM
577
                    {
578
                        ID = document_Id,
579
                        REVISION = rev_No,
580
                        DOCUMENT_NO = document_No,
581
                        DOCUMENT_NAME = document_Name,
582
                        GROUP_NO = group_No,
583
                        ORIGINAL_FILE = HttpUtility.UrlEncodeUnicode(document_Url),
584
                        DOCUMENT_ID = _doc_id,
585
                        PROJECT_NO = prj_No,
586
                    });
587
                    _entity.AddToCONVERTER_DOC(new CONVERTER_DOC
588
                    {
589
                        ID = _id,
590
                        CREATE_DATETIME = DateTime.Now,
591
                        DOCUMENT_URL = HttpUtility.UrlEncodeUnicode(document_Url),
592
                        PROJECT_NO = prj_No,
593
                        DOCUMENT_ID = _doc_id,
594
                    });
595
                    _entity.SaveChanges();
596
                }
597
                var _result = remObj.SetConverterPDF(prj_No, _id);
598

    
599
                if (_result.Exception != null)
600
                {
601
                    return false.ToString();
602
                }
603
                else
604
                {
605
                    return true.ToString();
606
                }
607
            }
608
        }
609

    
610
        //private Guid GetGuid(int Count,Guid ID)
611
        //{
612
        //    Guid _ID = ID;
613
        //    string _id = _ID.ToString();
614
        //    DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString());
615

    
616
        //    if (_entity.CONVERTER_DOC.Where(c => c.ID == _id).Count() > 0)
617
        //    {
618
        //        _entity.Dispose();
619

    
620
        //        if (Count > 10)
621
        //        {
622
        //            new Exception("GetGuid : Not Generator");
623
        //        }
624

    
625
        //        if (Count < 3)
626
        //        {
627
        //            System.Threading.Thread.Sleep(3);
628
        //        }
629

    
630
        //        GetGuid(Count++,GuidGenerator.GetUniqueGuid());
631
        //    }
632

    
633
        //    return ID;
634
        //}
635

    
636
        //GUID생성(최민수 사원 수정)
637
        public string shortGuid()
638
        {
639
            byte[] bytes = new byte[16];
640
            using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create())
641
            {
642
                provider.GetBytes(bytes);
643
            }
644

    
645
            var guid = new Guid(bytes);
646

    
647
            return Convert.ToBase64String(guid.ToByteArray())
648
                .Substring(0, 10)
649
                .Replace("/", "")
650
                .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
651
        }
652

    
653
        [WebMethod]
654
        public string ExcelExport(string project_no,string slip_no)
655
        {
656
            string _result = "false";
657
            Excel.Application application = null;
658
            Excel.Workbook workbook = null;
659
            Excel.Worksheet worksheet = null;
660
            string xlsxfilepath = @"D:\sample.xlsx";
661
            
662
            string fileout = @"D:\CommentExport_" + DateTime.Now.ToString() + ".xlsx";
663
            
664
            try
665
            {
666
                // Excel 첫번째 워크시트 가져오기                
667
                application = new Excel.Application();
668
                workbook = application.Workbooks.Open(xlsxfilepath);
669
                worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item("Sheet1");
670

    
671
                // 데이타 넣기
672
                int h = 6;
673
                int w = 2;
674

    
675

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

    
680
                
681
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
682
                {
683
                    var docs = deepViewEntity.DOCUMENT_ITEM.Where(doc => doc.GROUP_NO == slip_no && doc.PROJECT_NO == project_no).ToList();
684
                    foreach(var doc in docs)
685
                    {
686
                        var commentlist = deepViewEntity.MARKUP_DATA.Where(d => d.MARKUP_INFO_VERSION.MARKUP_INFO.DOCINFO.DOCUMENT_ID == doc.DOCUMENT_ID
687
                        && d.MARKUP_INFO_VERSION.MARKUP_INFO.CONSOLIDATE == 1).ToList();
688

    
689
                        string docNo = doc.DOCUMENT_NO;
690
                        string docDesc = doc.DOCUMENT_NAME;
691
                        string docRev = doc.REVISION;
692
                        foreach(var comment in commentlist)
693
                        {
694
                            var member = deepViewEntity.MEMBER.Where(m => m.ID == comment.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID).FirstOrDefault();
695
                            string docdept = member.DEPARTMENT;
696
                            string doccomment = string.Empty;
697
                            var data = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressString(comment.DATA.ToString());
698
                            switch (Enum.Parse(typeof(MarkupToPDF.Controls.Common.ControlType), comment.DATA_TYPE.ToString()))
699
                            {
700
                                case MarkupToPDF.Controls.Common.ControlType.TextControl:
701
                                case MarkupToPDF.Controls.Common.ControlType.TextBorder:
702
                                case MarkupToPDF.Controls.Common.ControlType.TextCloud:
703
                                    {
704
                                        MarkupToPDF.Serialize.S_Control.S_TextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_TextControl>(data);
705
                                        doccomment = instance.Text;
706
                                    }
707
                                    break;
708
                                case MarkupToPDF.Controls.Common.ControlType.ArrowTextBorderControl:
709
                                case MarkupToPDF.Controls.Common.ControlType.ArrowTextCloudControl:
710
                                case MarkupToPDF.Controls.Common.ControlType.ArrowTextControl:
711
                                case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextBorderControl:
712
                                case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextCloudControl:
713
                                case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextControl:
714
                                    {
715
                                        MarkupToPDF.Serialize.S_Control.S_ArrowTextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_ArrowTextControl>(data);
716
                                        doccomment = instance.ArrowText;
717
                                    }
718
                                    break;
719
                            }
720
                            worksheet.Cells[h, w] = string.Format("{0}\n({1})",docNo,docDesc);
721
                            worksheet.Cells[h, w + 1] = docRev;
722
                            worksheet.Cells[h, w + 2] = docdept;
723
                            worksheet.Cells[h, w + 3] = doccomment;
724
                            h++;
725
                        }
726
                    }
727
                    
728
                }
729

    
730

    
731
                worksheet.Columns.AutoFit();
732
                // 엑셀파일 저장
733
                
734
                
735
                workbook.SaveAs(fileout);
736
                //workbook.Save();
737
                workbook.Close(true);
738
                application.Quit();
739
                _result = fileout;
740
            }
741
            catch(Exception e)
742
            {
743
                _result = e.Message;
744
            }
745
            finally
746
            {
747
                System.Diagnostics.Process[] ExCel = System.Diagnostics.Process.GetProcessesByName("EXCEL");
748
                if (ExCel.Count() != 0)
749
                {
750
                    ExCel[0].Kill();
751
                }
752

    
753
                // Clean up
754
                ReleaseExcelObject(worksheet);
755
                ReleaseExcelObject(workbook);
756
                ReleaseExcelObject(application);
757
                
758
            }
759
            return _result;
760
        }
761

    
762
        private static void ReleaseExcelObject(object obj)
763
        {
764
            try
765
            {
766
                if (obj != null)
767
                {
768
                    obj = null;
769
                }
770
            }
771
            catch (Exception ex)
772
            {
773
                obj = null;
774
                throw ex;
775
            }
776
            finally
777
            {
778
                GC.Collect();
779
            }
780
        }
781
    }
782
}
클립보드 이미지 추가 (최대 크기: 500 MB)