프로젝트

일반

사용자정보

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

markus / FinalService / KCOM_FinalService / UploadFinal / UploadPDF.cs @ fc4e50f2

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

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.IO;
6
using System.Net;
7
using System.Xml;
8
using System.Xml.Linq;
9
using System.Net.Mail;
10
using System.Data.SqlClient;
11
using KCOMDataModel.DataModel;
12
using KCOMDataModel.Common;
13
namespace UploadFinal
14
{
15
    public class UploadFinal
16
    {
17
        
18
        public static KeyValuePair<bool, string> UploadFinalPDF(string PdfFilePath, string OriginFileName, FINAL_PDF FinalPDF, string UploadServiceUrl)
19
        {            
20
            string _vendorItemId = null;
21
            string _objid = null;
22
            string _SharepointItemID = null;
23
            string _slipNO = null;
24
            bool _ResultFlag = false;
25
            string _ResultMsg = "";
26

    
27
            try
28
            {
29
                string docurl = string.Empty;
30
                //XML escape & 치환
31
                OriginFileName = OriginFileName.Replace("&","&amp;");
32
                using (CIEntities dc = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(FinalPDF.PROJECT_NO).ToString()))
33
                {
34
                    var _docInfoList = dc.DOCINFO.Where(doc => doc.ID == FinalPDF.DOCINFO_ID);
35

    
36
                    if (_docInfoList.Count() > 0)
37
                        _SharepointItemID = _docInfoList.First().DOCUMENT_ID;
38

    
39
                    var _vendoritems = dc.DOCUMENT_ITEM.Where(item => item.DOCUMENT_ID == _SharepointItemID && item.PROJECT_NO == FinalPDF.PROJECT_NO);
40

    
41
                    if (_vendoritems.Count() > 0)
42
                    {
43
                        _objid = _vendoritems.First().ID;
44
                        _slipNO = _vendoritems.First().GROUP_NO;
45
                        docurl = _vendoritems.First().ORIGINAL_FILE;
46
                    }
47
                }
48

    
49
                //EnsemblePlusWebService.DLMWebServiceClient client = new EnsemblePlusWebService.DLMWebServiceClient();
50
                //var result = client.fnFinalPDFCheckInService(FinalPDF.PROJECT_NO, _objid, _slipNO, PdfFilePath);
51

    
52
                WebClient webClient = new WebClient();
53
                string data = string.Empty;
54
                if (docurl.ToUpper().Contains("VPCS_DOCLIB"))
55
                {
56
                    string connectionString = "data source=ESB-DB;Initial Catalog=markus;uid=ProjectPortalDBConn;password=ProjectPortalDBConn";
57
                    SqlConnection sqlConn = new SqlConnection(connectionString);
58
                    SqlCommand sqlComm = new SqlCommand();
59
                    sqlComm.Connection = sqlConn;
60
                    sqlComm.CommandText = string.Format("SELECT [DBConnectString]  FROM [PortalEV].[dbo].[Setting]  where [ProjectNumber] = '{0}'", FinalPDF.PROJECT_NO);
61
                    string ciconnectionStr = string.Empty;
62

    
63
                    sqlConn.Open();
64
                    using (SqlDataReader SqlRs = sqlComm.ExecuteReader())
65
                    {
66

    
67
                        while (SqlRs.Read())
68
                        {
69
                            ciconnectionStr = SqlRs[0].ToString();
70
                        }
71
                    }
72
                    sqlConn.Close();
73
                    sqlConn = new SqlConnection(ciconnectionStr);
74
                    sqlComm.Connection = sqlConn;
75
                    sqlComm.CommandText = string.Format("SELECT [vendor_item_id]  FROM [vendor_item]  where [sharepoint_itemid] = '{0}'", _objid);
76
                    sqlConn.Open();
77
                    using (SqlDataReader SqlRs = sqlComm.ExecuteReader())
78
                    {
79

    
80
                        while (SqlRs.Read())
81
                        {
82
                            _objid = SqlRs[0].ToString();
83
                        }
84
                    }
85
                    sqlConn.Close();
86
                    UploadServiceUrl = "http://esb-vpcs-new.daelimplant.com/ProjectPortal/UserControls/DaelimCI2/FinalPDFUpload/UploadVpcsFile.asmx";
87

    
88
                    data = "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\" ><soap12:Body><UploadFinalPDF xmlns=\"http://FinalPDFUpload\">"
89
                                     + "<ProjectNo>" + FinalPDF.PROJECT_NO + "</ProjectNo>"
90
                                     + "<VendorItemID>" + _objid + "</VendorItemID>"
91
                                     + "<SlipNumber>" + _slipNO + "</SlipNumber>"
92
                                     + "<filePath>" + PdfFilePath + "</filePath>"
93
                                     + "<OriginFileName>" + OriginFileName + "</OriginFileName></UploadFinalPDF></soap12:Body></soap12:Envelope>";
94
                                       
95
                    //WriteLog(data);
96
                    webClient.Headers.Add(HttpRequestHeader.ContentType, "application/soap+xml; charset=utf-8");
97
                    webClient.Headers.Add("SOAPAction", "http://FinalPDFUpload/UploadFinalPDF");
98
                    webClient.Encoding = System.Text.Encoding.UTF8;
99

    
100
                    string _result = webClient.UploadString(new Uri(UploadServiceUrl), data);
101
                    XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(_result));
102

    
103
                    while (reader.Read())
104
                    {
105
                        switch (reader.NodeType)
106
                        {
107
                            case XmlNodeType.Element:
108
                                if (reader.Name == "Seccess")
109
                                {
110
                                    reader.Read();
111

    
112
                                    if (!string.IsNullOrWhiteSpace(reader.Value))
113
                                        _ResultFlag = Convert.ToBoolean(reader.Value);
114
                                }
115

    
116
                                if (reader.Name == "Message")
117
                                {
118
                                    reader.Read();
119

    
120
                                    if (!string.IsNullOrWhiteSpace(reader.Value))
121
                                        _ResultMsg = reader.Value;
122
                                }
123

    
124
                                if (reader.Name == "FinalPDFUrl")
125
                                {
126
                                    reader.Read();
127

    
128
                                    if (!string.IsNullOrWhiteSpace(reader.Value))
129
                                        _ResultMsg = reader.Value;
130
                                }
131

    
132
                                break;                                
133
                        }
134
                    }
135
                    return new KeyValuePair<bool, string>(_ResultFlag, _ResultMsg);
136
                }
137
                else
138
                {
139
                    // 앙상블+는 파일명만 전달함
140
                    PdfFilePath = PdfFilePath.Split('/').Last();
141

    
142
                    data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ens=\"http://EnsemblePlus.Webservice\"> <soapenv:Header/> <soapenv:Body> <ens:fnFinalPDFCheckInService>"
143
                    + "<ens:ProjectNo>" + FinalPDF.PROJECT_NO + "</ens:ProjectNo>"
144
                    + "<ens:ObjectId>" + _objid + "</ens:ObjectId>"
145
                    + "<ens:SlipNumber>" + _slipNO + "</ens:SlipNumber>"
146
                    + "<ens:filePath>" + PdfFilePath + "</ens:filePath>"
147
                    + "<ens:OriginalFileName>" + OriginFileName + "</ens:OriginalFileName>"
148
                    + "</ens:fnFinalPDFCheckInService> </soapenv:Body></soapenv:Envelope>";
149

    
150
                    webClient.Headers.Add(HttpRequestHeader.ContentType, "text/xml");
151
                    webClient.Headers.Add("SOAPAction", "http://EnsemblePlus.Webservice");
152
                    webClient.Encoding = System.Text.Encoding.UTF8;
153
                    var result = webClient.UploadString(new Uri(UploadServiceUrl), data);
154
                    XmlDocument xmlDoc = new XmlDocument();
155
                    xmlDoc.LoadXml(result);
156
                    XmlNodeList list = xmlDoc.GetElementsByTagName("fnFinalPDFCheckInServiceReturn");
157
                    if (list.Count > 0)
158
                    {
159
                        if (list[0].InnerText == "Success")
160
                        {
161
                            return new KeyValuePair<bool, string>(true, "Success");
162
                        }
163
                        else
164
                        {
165
                            return new KeyValuePair<bool, string>(false, "Fail - " + data);
166
                        }
167
                    }
168
                    else
169
                    {
170
                        return new KeyValuePair<bool, string>(false, "Not Completed");
171
                    }
172
                }
173
               
174
               
175
                
176
                
177
            }
178
            catch (Exception ex)
179
            {
180
                return new KeyValuePair<bool, string>(false, ex.Message);
181
            }
182

    
183
            //return new KeyValuePair<bool, string>(_ResultFlag,_ResultMsg);
184
        }
185

    
186
        static void webClient_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
187
        {
188
            Console.WriteLine("UploadStringCompleted: {0}", e.Result);
189
        }
190
        public static void SendOnMessage(string subject, string content)
191
        {
192

    
193
            //MailMessage mail = new MailMessage();
194
            //mail.From = new MailAddress("h2011357@daelim.co.kr", "시스템관리자", System.Text.Encoding.UTF8);
195
            //mail.To.Add("h2011357@daelim.co.kr");
196
            //mail.Subject = subject;
197
            //mail.Body = content;
198
            //mail.BodyEncoding = System.Text.Encoding.UTF8;//한글이 안깨지기 위해서 사용
199
            //mail.SubjectEncoding = System.Text.Encoding.UTF8;//한글이 안깨지기 위해서 사용
200

    
201
            //SmtpClient SmtpServer = new SmtpClient("any.daelim.co.kr");
202
            //SmtpServer.Send(mail); // 메일 발송
203
            //mail.Dispose();
204
        }
205
        public static void WriteLog(string strLog)
206
        {
207
            StreamWriter log;
208
            FileStream fileStream = null;
209
            DirectoryInfo logDirInfo = null;
210
            FileInfo logFileInfo;
211

    
212
            string logFilePath = "C:\\Logs\\";
213
            logFilePath = logFilePath + "Log-" + System.DateTime.Today.ToString("MM-dd-yyyy") + "." + "txt";
214
            logFileInfo = new FileInfo(logFilePath);
215
            logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName);
216
            if (!logDirInfo.Exists) logDirInfo.Create();
217
            if (!logFileInfo.Exists)
218
            {
219
                fileStream = logFileInfo.Create();
220
            }
221
            else
222
            {
223
                fileStream = new FileStream(logFilePath, FileMode.Append);
224
            }
225
            log = new StreamWriter(fileStream);
226
            log.WriteLine(strLog);
227
            log.Close();
228
        }
229
    }
230
}
클립보드 이미지 추가 (최대 크기: 500 MB)