From b0c18d369abd06075c83759b0e19823c2a11d716 Mon Sep 17 00:00:00 2001
From: ulysseskao <ulysseskao@gmail.com>
Date: Fri, 29 Apr 2016 18:45:41 +0800
Subject: [PATCH] update for new model

---
 CCSTrace/CCS/Function/MailService.cs |   67 ++++++++++++++++-----------------
 1 files changed, 33 insertions(+), 34 deletions(-)

diff --git a/CCSTrace/CCS/Function/MailService.cs b/CCSTrace/CCS/Function/MailService.cs
index a08eb3a..4b78991 100644
--- a/CCSTrace/CCS/Function/MailService.cs
+++ b/CCSTrace/CCS/Function/MailService.cs
@@ -1,50 +1,53 @@
 using System;
 using System.Data.OracleClient;
+using System.Net;
 using System.Net.Mail;
 
 namespace CCSTrace.CCS.Function
 {
     public class MailService
     {
-        private SmtpClient smtpClient = null;
-        private string SMTP_IP;
-        private int SMTP_Port;
-        private string EMailAddr;
-        private string EMailPass;
-        private string ToEMail;
+        private SmtpClient _smtpClient;
+        private string _smtpIp;
+        private int _smtpPort;
+        private string _eMailAddr;
+        private string _eMailPass;
+        private string _toEMail;
 
-        public MailService(OracleConnection _Conn)
+        public MailService(OracleConnection conn)
         {
-            InitialSmtpClient(_Conn);
+            InitialSmtpClient(conn);
         }
 
-        public void InitialSmtpClient(OracleConnection _Conn)
+        public void InitialSmtpClient(OracleConnection conn)
         {
-            getMailSetting(_Conn);
-            smtpClient = new SmtpClient(SMTP_IP, SMTP_Port);
-            smtpClient.Credentials = new System.Net.NetworkCredential(EMailAddr, EMailPass);
-            smtpClient.EnableSsl = false;
+            GetMailSetting(conn);
+            _smtpClient = new SmtpClient(_smtpIp, _smtpPort)
+            {
+                Credentials = new NetworkCredential(_eMailAddr, _eMailPass),
+                EnableSsl = false
+            };
         }
 
-        public bool SendMail(String CCSID)
+        public bool SendMail(string ccsid)
         {
-            Attachment objAttFle = new Attachment(CCS.LocalVariable.CCS_ListPath + CCSID + ".txt");
+            Attachment objAttFle = new Attachment(GlobalVariable.CcsListPath + ccsid + ".txt");
             MailMessage objMail = new MailMessage();
 
             try
             {
-                objMail.From = new MailAddress(EMailAddr);
-                objMail.To.Add(ToEMail);
+                objMail.From = new MailAddress(_eMailAddr);
+                objMail.To.Add(_toEMail);
 
                 objMail.BodyEncoding = System.Text.Encoding.UTF8;
                 objMail.Subject = "CCS事故案件追蹤失敗";
-                //objMail.Body = "測試收件者"; 
+                //objMail.Body = "測試收件者";
                 objMail.IsBodyHtml = true;
 
-                if ( objAttFle != null )
+                if (objAttFle != null)
                     objMail.Attachments.Add(objAttFle);
 
-                smtpClient.Send(objMail);
+                _smtpClient.Send(objMail);
                 return true;
             }
             catch
@@ -53,24 +56,22 @@
             }
         }
 
-        private void getMailSetting(OracleConnection _Conn)
+        private void GetMailSetting(OracleConnection conn)
         {
-            String SqlStmt;
+            var sqlStmt = "SELECT MAIL_ACCOUNT,MAIL_PASSWORD,MAIL_HOST,MAIL_PORT,WOS_MAIL FROM USRADMIN.SYS_MAIL";
 
-            SqlStmt = "SELECT MAIL_ACCOUNT,MAIL_PASSWORD,MAIL_HOST,MAIL_PORT,WOS_MAIL FROM USRADMIN.SYS_MAIL";
+            OracleCommand command = new OracleCommand(sqlStmt, conn);
+            OracleDataReader reader = command.ExecuteReader();
 
-            OracleCommand Command = new OracleCommand(SqlStmt, _Conn);
-            OracleDataReader reader = Command.ExecuteReader();
-            
             try
             {
                 if (reader.Read())
                 {
-                    SMTP_IP = reader["MAIL_HOST"].ToString();
-                    SMTP_Port = Convert.ToInt32(reader["MAIL_PORT"].ToString());
-                    EMailAddr = reader["MAIL_ACCOUNT"].ToString();
-                    EMailPass = reader["MAIL_PASSWORD"].ToString();
-                    ToEMail = reader["CCS_MAIL"].ToString();
+                    _smtpIp = reader["MAIL_HOST"].ToString();
+                    _smtpPort = Convert.ToInt32(reader["MAIL_PORT"].ToString());
+                    _eMailAddr = reader["MAIL_ACCOUNT"].ToString();
+                    _eMailPass = reader["MAIL_PASSWORD"].ToString();
+                    _toEMail = reader["CCS_MAIL"].ToString();
                 }
             }
             catch (Exception e)
@@ -81,10 +82,8 @@
             finally
             {
                 reader.Close();
-                Command.Dispose();
+                command.Dispose();
             }
-            
         }
-
     }
 }
\ No newline at end of file

--
Gitblit v0.0.0-SNAPSHOT