프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (10.2 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, CommonLib.MARKUS_API.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

    
31
                using (CIEntities dc = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(FinalPDF.PROJECT_NO).ToString()))
32
                {
33
                    var _docInfoList = dc.DOCINFO.Where(doc => doc.ID == FinalPDF.DOCINFO_ID);
34

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

    
38
                    var _vendoritems = dc.DOCUMENT_ITEM.Where(item => item.DOCUMENT_ID == _SharepointItemID);
39

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

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

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

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

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

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

    
87
                    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\">"
88
                                     + "<ProjectNo>" + FinalPDF.PROJECT_NO + "</ProjectNo>"
89
                                     + "<VendorItemID>" + _objid + "</VendorItemID>"
90
                                     + "<SlipNumber>" + _slipNO + "</SlipNumber>"
91
                                     + "<filePath>" + @"\\172.20.121.220\comment3\finalPDF\" + PdfFilePath + "</filePath>"
92
                                     + "<OriginFileName>" + OriginFileName + "</OriginFileName></UploadFinalPDF></soap12:Body></soap12:Envelope>";
93
                                       
94
                    //WriteLog(data);
95
                    webClient.Headers.Add(HttpRequestHeader.ContentType, "application/soap+xml; charset=utf-8");
96
                    webClient.Headers.Add("SOAPAction", "http://FinalPDFUpload/UploadFinalPDF");
97
                    string _result = webClient.UploadString(new Uri(UploadServiceUrl), data);
98
                    XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(_result));
99

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

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

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

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

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

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

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

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

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

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

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

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

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

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