프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / ConvertionWebService / Conversion.asmx.cs @ dbc1e5b6

이력 | 보기 | 이력해설 | 다운로드 (25.8 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
                logger.Error("Conversion Web Service Conversion Error", ex);
52
                SendNotice(ex.ToString());
53
            }
54
        }
55

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

    
73
        [WebMethod]
74
        public string ConvertRun(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
75
        {
76
            string _result = null;
77
            try
78
            {
79
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
80
                {
81
                    //_result = ConnectStringBuilder.DeepViewConnectionString().ToString();
82
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now);
83
                    //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber);
84
                    var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null);
85

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

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

    
118
                    if (_RunProjects.Count() > 0)
119
                    {
120
                        _result = ManualSendKcom(rev_No, document_No, document_Name, group_No, prj_No, document_Id, document_Url);
121
                    }
122
                    else
123
                    {
124
                        _result = false.ToString();
125
                    }
126
                }
127
            }
128
            catch (Exception ex)
129
            {
130
                logger.Error("Conversion Web Service ManualConvert Error", ex);
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
        [WebMethod]
137
        public string UpdateUrlEncode(string EnsembleId)
138
        {
139
            string _result = null;
140
            try
141
            {
142
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
143
                {
144
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
145
                    string url = doc.ORIGINAL_FILE;
146
                    if (url.Contains("http://"))
147
                    {
148
                        //기존 url 이 인코딩 안되 있으면 인코딩 작업.
149
                        url = HttpUtility.UrlEncodeUnicode(url);
150
                        doc.ORIGINAL_FILE = url;
151

    
152
                        var convertdoc = deepViewEntity.CONVERTER_DOC.Where(d => d.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
153
                        if(convertdoc != null)
154
                            convertdoc.DOCUMENT_URL = url;
155
                        var docinfo = deepViewEntity.DOCINFO.Where(d => d.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
156
                        if(docinfo != null)
157
                            docinfo.ORIGINAL_FILE = url;
158
                    }
159
                        
160
                    deepViewEntity.SaveChanges();
161
                }
162
            }
163
            catch (Exception ex)
164
            {
165
                logger.Error("Conversion Web Service UpdateUrlEncode Error", ex);
166
                _result = ex.Message.ToString();
167
            }
168
            return _result;
169
        }
170
        public string Base64Decode(string data)
171
        {
172
            try
173
            {
174

    
175
                System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
176
                System.Text.Decoder utf8Decode = encoder.GetDecoder();
177

    
178
                byte[] todecode_byte = Convert.FromBase64String(data);
179

    
180
                int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
181

    
182
                char[] decoded_char = new char[charCount];
183

    
184
                utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
185

    
186
                string result = new String(decoded_char);
187

    
188
                return result;
189

    
190
            }
191

    
192
            catch (Exception e)
193
            {
194
                throw new Exception("Error in Base64Decode: " + e.Message);
195
            }
196
        }
197
        [WebMethod]
198
        public string UpdateSlip(string EnsembleId, string SlipNo, string slipLink)
199
        {
200
            string _result = null;
201
            try
202
            {
203
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
204
                {
205
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
206
                    if(!string.IsNullOrEmpty(slipLink))
207
                        doc.GROUP_NO = SlipNo;
208
                    if(!string.IsNullOrEmpty(slipLink))
209
                    {
210
                        if (!slipLink.Contains("http://"))
211
                            slipLink = Base64Decode(slipLink);
212
                        doc.ENSEMBLEINFO_URL = slipLink;
213
                    }
214
                    
215
                    deepViewEntity.SaveChanges();
216
                }
217
            }
218
            catch (Exception ex)
219
            {
220
                logger.Error("Conversion Web Service UpdateSlip Error", ex);
221
                _result = ex.Message.ToString();                
222
            }
223
            return _result;
224
        }
225
        [WebMethod]
226
        public string UpdateResult(string EnsembleId, string Result, string FinalPDFUrl)
227
        {
228
            string _result = null;
229
            try
230
            {
231
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
232
                {
233
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
234
                    doc.RESULT = Result;
235
                    doc.RESULT_FILE = FinalPDFUrl;
236
                    deepViewEntity.SaveChanges();
237
                }
238
            }
239
            catch (Exception ex)
240
            {
241
                logger.Error("Conversion Web Service UpdateResult Error", ex);
242
                _result = ex.Message.ToString();
243
            }
244
            return _result;
245
        }
246
        [WebMethod]
247
        public string UpdateVP(string EnsembleId, string rev_No, string document_No, string document_Name)
248
        {
249
            string _result = null;
250
            try
251
            {
252
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
253
                {
254
                    var doc = deepViewEntity.DOCUMENT_ITEM.Where(data => data.ID == EnsembleId).FirstOrDefault();
255
                    if(!string.IsNullOrEmpty(rev_No))
256
                        doc.REVISION = rev_No;
257
                    if (!string.IsNullOrEmpty(document_No))
258
                        doc.DOCUMENT_NO = document_No;
259
                    if (!string.IsNullOrEmpty(document_Name))
260
                        doc.DOCUMENT_NAME = document_Name;
261
                    deepViewEntity.SaveChanges();
262
                }
263
            }
264
            catch (Exception ex)
265
            {
266
                logger.Error("Conversion Web Service UpdateVP Error", ex);
267
                _result = ex.Message.ToString();
268
            }
269
            return _result;
270
        }
271
        [WebMethod]
272
        public string CoverConvert(string prj_No, string _id)
273
        {
274
            string _result = null;
275
            try
276
            {
277
                SendCoverConvert(prj_No, _id);
278
            }
279
            catch (Exception ex)
280
            {
281
                logger.Error("Conversion Web Service CoverConvert Error", ex);
282
                _result = ex.Message.ToString();
283
            }
284
            return _result;
285
        }
286
        private string SendCoverConvert(string prj_No, string _id)
287
        {
288
            if (remObj == null)
289
            {
290
                return "Window Service Connection Error";
291
            }
292
            else
293
            {
294
                var _result = remObj.SetConverterCoverPDF(prj_No, _id);
295

    
296
                if (_result.Exception != null)
297
                {
298
                    return false.ToString();
299
                }
300
                else
301
                {
302
                    return true.ToString();
303
                }
304
            }
305
        }
306
        private string SendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
307
        {
308
            string result = false.ToString();
309

    
310
            if (remObj == null)
311
            {
312
                result  = "Window Service Connection Error";
313
            }
314
            else
315
            {
316
                //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString();
317
                string _id = shortGuid();
318
                string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString();
319
                using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
320
                {                    
321
                    var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault();
322
                    if(doc != null)
323
                    {
324
                        var converterdoc = _entity.CONVERTER_DOC.Where(c => c.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
325
                        _entity.DeleteObject(converterdoc);
326
                        _entity.DeleteObject(doc);
327
                        _entity.SaveChanges();
328
                        document_Url = HttpUtility.UrlDecode(document_Url);
329
                    }
330
                    int cnt = _entity.DOCUMENT_ITEM.ToList().Count;
331
                    if(string.IsNullOrEmpty(group_No))
332
                    {
333
                        group_No = "0";
334
                    }
335
                    if (!prj_No.Equals("150128"))
336
                    {
337
                        //Omsk 는 웹서비스 호출 시 인코딩
338
                        //Omsk 제외는 Markus 에서 인코딩
339
                        document_Url = HttpUtility.UrlEncodeUnicode(document_Url);
340
                    }
341
                    _entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM
342
                    {
343
                        ID = document_Id,
344
                        REVISION = rev_No,
345
                        DOCUMENT_NO = document_No,
346
                        DOCUMENT_NAME = document_Name,
347
                        GROUP_NO = group_No,
348
                        ORIGINAL_FILE = document_Url,
349
                        DOCUMENT_ID = _doc_id,
350
                        PROJECT_NO = prj_No,
351
                    });
352
                    _entity.AddToCONVERTER_DOC(new CONVERTER_DOC
353
                    {
354
                        ID = _id,
355
                        CREATE_DATETIME = DateTime.Now,
356
                        DOCUMENT_URL = document_Url,
357
                        PROJECT_NO = prj_No,
358
                        DOCUMENT_ID = _doc_id,
359
                    });
360
                    _entity.SaveChanges();
361
                }
362

    
363
                if (Properties.Settings.Default.MARKUS_V3_PROJECTS.Split(',').Contains(prj_No))
364
                {
365
                    try
366
                    {
367
                        System.Net.WebClient client = new System.Net.WebClient();
368
                        var convertResult = client.DownloadString($"{Properties.Settings.Default.MARKUS_V3_ADDRESS}/Rest/ConvertAdd?ProjectNo={prj_No}&DocumentID={_id}");
369

    
370
                        JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings());
371
                        result = jObject["ConvertAddResult"].ToString();
372
                    }
373
                    catch (Exception ex)
374
                    {
375
                        logger.Error("Conversion Web Service SendKcom Error", ex);
376
                        result = $"Markus V3 Connect Error {ex.Message}";
377
                    }
378
                }
379
                else
380
                {
381
                    var convertResult = remObj.SetConverterPDF(prj_No, _id);
382

    
383
                    if (convertResult.Exception != null)
384
                    {
385
                        result = false.ToString();
386
                    }
387
                    else
388
                    {
389
                        result = true.ToString();
390
                    }
391
                }
392

    
393
            }
394

    
395
            return result;
396
        }
397
        private string ManualSendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
398
        {
399
            if (remObj == null)
400
            {
401
                return "Window Service Connection Error";
402
            }
403
            else
404
            {
405
                //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString();
406
                string _id = shortGuid();
407
                string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString();
408
                using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
409
                {
410
                    var doc = _entity.DOCUMENT_ITEM.Where(d => d.ID == document_Id).FirstOrDefault();
411
                    if (doc != null)
412
                    {
413
                        var converterdoc = _entity.CONVERTER_DOC.Where(c => c.DOCUMENT_ID == doc.DOCUMENT_ID).FirstOrDefault();
414
                        _entity.DeleteObject(converterdoc);
415
                        _entity.DeleteObject(doc);
416
                        _entity.SaveChanges();
417
                        document_Url = HttpUtility.UrlDecode(document_Url);
418
                    }
419
                    int cnt = _entity.DOCUMENT_ITEM.ToList().Count;
420
                    if (string.IsNullOrEmpty(group_No))
421
                    {
422
                        group_No = "0";
423
                    }
424
                    
425
                    _entity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM
426
                    {
427
                        ID = document_Id,
428
                        REVISION = rev_No,
429
                        DOCUMENT_NO = document_No,
430
                        DOCUMENT_NAME = document_Name,
431
                        GROUP_NO = group_No,
432
                        ORIGINAL_FILE = HttpUtility.UrlEncodeUnicode(document_Url),
433
                        DOCUMENT_ID = _doc_id,
434
                        PROJECT_NO = prj_No,
435
                    });
436
                    _entity.AddToCONVERTER_DOC(new CONVERTER_DOC
437
                    {
438
                        ID = _id,
439
                        CREATE_DATETIME = DateTime.Now,
440
                        DOCUMENT_URL = HttpUtility.UrlEncodeUnicode(document_Url),
441
                        PROJECT_NO = prj_No,
442
                        DOCUMENT_ID = _doc_id,
443
                    });
444
                    _entity.SaveChanges();
445
                }
446
                var _result = remObj.SetConverterPDF(prj_No, _id);
447

    
448
                if (_result.Exception != null)
449
                {
450
                    return false.ToString();
451
                }
452
                else
453
                {
454
                    return true.ToString();
455
                }
456
            }
457
        }
458

    
459
        //private Guid GetGuid(int Count,Guid ID)
460
        //{
461
        //    Guid _ID = ID;
462
        //    string _id = _ID.ToString();
463
        //    DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString());
464

    
465
        //    if (_entity.CONVERTER_DOC.Where(c => c.ID == _id).Count() > 0)
466
        //    {
467
        //        _entity.Dispose();
468

    
469
        //        if (Count > 10)
470
        //        {
471
        //            new Exception("GetGuid : Not Generator");
472
        //        }
473

    
474
        //        if (Count < 3)
475
        //        {
476
        //            System.Threading.Thread.Sleep(3);
477
        //        }
478

    
479
        //        GetGuid(Count++,GuidGenerator.GetUniqueGuid());
480
        //    }
481

    
482
        //    return ID;
483
        //}
484

    
485
        //GUID생성(최민수 사원 수정)
486
        public string shortGuid()
487
        {
488
            byte[] bytes = new byte[16];
489
            using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create())
490
            {
491
                provider.GetBytes(bytes);
492
            }
493

    
494
            var guid = new Guid(bytes);
495

    
496
            return Convert.ToBase64String(guid.ToByteArray())
497
                .Substring(0, 10)
498
                .Replace("/", "")
499
                .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
500
        }
501

    
502
        [WebMethod]
503
        public string ExcelExport(string project_no,string slip_no)
504
        {
505
            string _result = "false";
506
            Excel.Application application = null;
507
            Excel.Workbook workbook = null;
508
            Excel.Worksheet worksheet = null;
509
            string xlsxfilepath = @"D:\sample.xlsx";
510
            
511
            string fileout = @"D:\CommentExport_" + DateTime.Now.ToString() + ".xlsx";
512
            
513
            try
514
            {
515
                // Excel 첫번째 워크시트 가져오기                
516
                application = new Excel.Application();
517
                workbook = application.Workbooks.Open(xlsxfilepath);
518
                worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item("Sheet1");
519

    
520
                // 데이타 넣기
521
                int h = 6;
522
                int w = 2;
523

    
524

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

    
529
                
530
                using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()))
531
                {
532
                    var docs = deepViewEntity.DOCUMENT_ITEM.Where(doc => doc.GROUP_NO == slip_no && doc.PROJECT_NO == project_no).ToList();
533
                    foreach(var doc in docs)
534
                    {
535
                        var commentlist = deepViewEntity.MARKUP_DATA.Where(d => d.MARKUP_INFO_VERSION.MARKUP_INFO.DOCINFO.DOCUMENT_ID == doc.DOCUMENT_ID
536
                        && d.MARKUP_INFO_VERSION.MARKUP_INFO.CONSOLIDATE == 1).ToList();
537

    
538
                        string docNo = doc.DOCUMENT_NO;
539
                        string docDesc = doc.DOCUMENT_NAME;
540
                        string docRev = doc.REVISION;
541
                        foreach(var comment in commentlist)
542
                        {
543
                            var member = deepViewEntity.MEMBER.Where(m => m.ID == comment.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID).FirstOrDefault();
544
                            string docdept = member.DEPARTMENT;
545
                            string doccomment = string.Empty;
546
                            var data = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressString(comment.DATA.ToString());
547
                            switch (Enum.Parse(typeof(MarkupToPDF.Controls.Common.ControlType), comment.DATA_TYPE.ToString()))
548
                            {
549
                                case MarkupToPDF.Controls.Common.ControlType.TextControl:
550
                                case MarkupToPDF.Controls.Common.ControlType.TextBorder:
551
                                case MarkupToPDF.Controls.Common.ControlType.TextCloud:
552
                                    {
553
                                        MarkupToPDF.Serialize.S_Control.S_TextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_TextControl>(data);
554
                                        doccomment = instance.Text;
555
                                    }
556
                                    break;
557
                                case MarkupToPDF.Controls.Common.ControlType.ArrowTextBorderControl:
558
                                case MarkupToPDF.Controls.Common.ControlType.ArrowTextCloudControl:
559
                                case MarkupToPDF.Controls.Common.ControlType.ArrowTextControl:
560
                                case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextBorderControl:
561
                                case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextCloudControl:
562
                                case MarkupToPDF.Controls.Common.ControlType.ArrowTransTextControl:
563
                                    {
564
                                        MarkupToPDF.Serialize.S_Control.S_ArrowTextControl instance = MarkupToPDF.Serialize.Core.JsonSerializerHelper.JsonDeserialize<MarkupToPDF.Serialize.S_Control.S_ArrowTextControl>(data);
565
                                        doccomment = instance.ArrowText;
566
                                    }
567
                                    break;
568
                            }
569
                            worksheet.Cells[h, w] = string.Format("{0}\n({1})",docNo,docDesc);
570
                            worksheet.Cells[h, w + 1] = docRev;
571
                            worksheet.Cells[h, w + 2] = docdept;
572
                            worksheet.Cells[h, w + 3] = doccomment;
573
                            h++;
574
                        }
575
                    }
576
                    
577
                }
578

    
579

    
580
                worksheet.Columns.AutoFit();
581
                // 엑셀파일 저장
582
                
583
                
584
                workbook.SaveAs(fileout);
585
                //workbook.Save();
586
                workbook.Close(true);
587
                application.Quit();
588
                _result = fileout;
589
            }
590
            catch(Exception e)
591
            {
592
                _result = e.Message;
593
            }
594
            finally
595
            {
596
                System.Diagnostics.Process[] ExCel = System.Diagnostics.Process.GetProcessesByName("EXCEL");
597
                if (ExCel.Count() != 0)
598
                {
599
                    ExCel[0].Kill();
600
                }
601

    
602
                // Clean up
603
                ReleaseExcelObject(worksheet);
604
                ReleaseExcelObject(workbook);
605
                ReleaseExcelObject(application);
606
                
607
            }
608
            return _result;
609
        }
610

    
611
        private static void ReleaseExcelObject(object obj)
612
        {
613
            try
614
            {
615
                if (obj != null)
616
                {
617
                    obj = null;
618
                }
619
            }
620
            catch (Exception ex)
621
            {
622
                obj = null;
623
                throw ex;
624
            }
625
            finally
626
            {
627
                GC.Collect();
628
            }
629
        }
630
    }
631
}
클립보드 이미지 추가 (최대 크기: 500 MB)