프로젝트

일반

사용자정보

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

markus / FinalService / KCOM_FinalService / UploadFinal / UploadPDF.cs @ 400a6bcc

이력 | 보기 | 이력해설 | 다운로드 (10.3 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>" + @"\\172.20.121.220\comment3\finalPDF\" + 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
                    string _result = webClient.UploadString(new Uri(UploadServiceUrl), data);
99
                    XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(_result));
100

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

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

    
114
                                if (reader.Name == "Message")
115
                                {
116
                                    reader.Read();
117

    
118
                                    if (!string.IsNullOrWhiteSpace(reader.Value))
119
                                        _ResultMsg = reader.Value;
120
                                }
121

    
122
                                if (reader.Name == "FinalPDFUrl")
123
                                {
124
                                    reader.Read();
125

    
126
                                    if (!string.IsNullOrWhiteSpace(reader.Value))
127
                                        _ResultMsg = reader.Value;
128
                                }
129

    
130
                                break;                                
131
                        }
132
                    }
133
                    return new KeyValuePair<bool, string>(_ResultFlag, _ResultMsg);
134
                }
135
                else
136
                {
137
                    data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ens=\"http://EnsemblePlus.Webservice\"> <soapenv:Header/> <soapenv:Body> <ens:fnFinalPDFCheckInService>"
138
                    + "<ens:ProjectNo>" + FinalPDF.PROJECT_NO + "</ens:ProjectNo>"
139
                    + "<ens:ObjectId>" + _objid + "</ens:ObjectId>"
140
                    + "<ens:SlipNumber>" + _slipNO + "</ens:SlipNumber>"
141
                    + "<ens:filePath>" + PdfFilePath + "</ens:filePath>"
142
                    + "<ens:OriginalFileName>" + OriginFileName + "</ens:OriginalFileName>"
143
                    + "</ens:fnFinalPDFCheckInService> </soapenv:Body></soapenv:Envelope>";
144

    
145
                    webClient.Headers.Add(HttpRequestHeader.ContentType, "text/xml");
146
                    webClient.Headers.Add("SOAPAction", "http://EnsemblePlus.Webservice");
147

    
148
                    var result = webClient.UploadString(new Uri(UploadServiceUrl), data);
149
                    XmlDocument xmlDoc = new XmlDocument();
150
                    xmlDoc.LoadXml(result);
151
                    XmlNodeList list = xmlDoc.GetElementsByTagName("fnFinalPDFCheckInServiceReturn");
152
                    if (list.Count > 0)
153
                    {
154
                        if (list[0].InnerText == "Success")
155
                        {
156
                            return new KeyValuePair<bool, string>(true, "Success");
157
                        }
158
                        else
159
                        {
160
                            return new KeyValuePair<bool, string>(false, "Fail");
161
                        }
162
                    }
163
                    else
164
                    {
165
                        return new KeyValuePair<bool, string>(false, "Not Completed");
166
                    }
167
                }
168
               
169
               
170
                
171
                
172
            }
173
            catch (Exception ex)
174
            {
175
                return new KeyValuePair<bool, string>(false, ex.Message);
176
            }
177

    
178
            //return new KeyValuePair<bool, string>(_ResultFlag,_ResultMsg);
179
        }
180

    
181
        static void webClient_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
182
        {
183
            Console.WriteLine("UploadStringCompleted: {0}", e.Result);
184
        }
185
        public static void SendOnMessage(string subject, string content)
186
        {
187

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

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

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