예제 #1
0
        public static int Update(EmailLog o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[6];

            arrParams[0] = new SqlParameter("@EID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EID, o.EID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@SentDateTime", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SentDateTime, o.SentDateTime.GetTypeCode()));
            arrParams[2] = new SqlParameter("@SentFrom", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SentFrom, o.SentFrom.GetTypeCode()));
            arrParams[3] = new SqlParameter("@SentTo", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SentTo, o.SentTo.GetTypeCode()));
            arrParams[4] = new SqlParameter("@Subject", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Subject, o.Subject.GetTypeCode()));
            arrParams[5] = new SqlParameter("@Body", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Body, o.Body.GetTypeCode()));

            try
            {
                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_SentEmailLog_Update", arrParams);
            }

            catch (SqlException exx)
            {
                System.Diagnostics.Debug.Write(exx.Message);
            }

            return(iReturn);
        }
예제 #2
0
        public static int Insert(EmailLog o)
        {
            SqlParameter[] arrParams = new SqlParameter[6];

            arrParams[0]           = new SqlParameter("@SentDateTime", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SentDateTime, o.SentDateTime.GetTypeCode()));
            arrParams[1]           = new SqlParameter("@SentFrom", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SentFrom, o.SentFrom.GetTypeCode()));
            arrParams[2]           = new SqlParameter("@SentTo", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SentTo, o.SentTo.GetTypeCode()));
            arrParams[3]           = new SqlParameter("@Subject", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Subject, o.Subject.GetTypeCode()));
            arrParams[4]           = new SqlParameter("@Body", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Body, o.Body.GetTypeCode()));
            arrParams[5]           = new SqlParameter("@EID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EID, o.EID.GetTypeCode()));
            arrParams[5].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_SentEmailLog_Insert", arrParams);

            return(int.Parse(arrParams[5].Value.ToString()));
        }
예제 #3
0
        public EmailLog GetEmailLog(int EID)
        {
            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@EID", EID);

            dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "app_SentEmailLog_GetByID", arrParams);

            try
            {
                dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "app_SentEmailLog_GetByID", arrParams);
            }

            catch (SqlException exx)
            {
                System.Diagnostics.Debug.Write(exx.Message);
            }

            if (dr.Read())
            {
                // declare return value

                EmailLog result = new EmailLog();

                //DateTime _datetime;

                //int _int;

                //decimal _decimal;


                dr.Close();

                return(result);
            }

            dr.Close();

            return(null);
        }
예제 #4
0
        public static int Delete(EmailLog o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@EID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EID, o.EID.GetTypeCode()));

            try
            {
                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_SentEmailLog_Delete", arrParams);
            }

            catch (SqlException exx)
            {
                System.Diagnostics.Debug.Write(exx.Message);
            }

            return(iReturn);
        }
        public bool SendEmail(string fromAddress,
                              string toAddress,
                              string subject,
                              string body) {
            this.ErrorException = null;
            if(this.TestEmailDuringSetup) {
                UseTemplates = false;
                _logEmails = false;
            }
            try {
                string mailBody;
                using(var mm = new MailMessage(fromAddress, toAddress)) {
                    if(UseTemplates) {
                        mailBody = EmailTemplate.FormatWith(new {
                            Subject = subject,
                            Content = body
                        });
                    } else {
                        mailBody = body;
                    }

                    mm.Subject = subject;
                    mm.Body = mailBody;
                    mm.IsBodyHtml = true;

                    NetworkCredential credentials = null;
                    if(!string.IsNullOrEmpty(this.Login)
                       && !string.IsNullOrEmpty(this.Password)) {
                        //smtp.Credentials
                        credentials = new NetworkCredential(this.Login, this.Password);
                    }


                    if(string.IsNullOrEmpty(this.Server)) {
                        using(var smtp = new SmtpClient()) {
                            if(credentials != null) {
                                smtp.Credentials = credentials;
                            }
                            smtp.Send(mm);
                        }
                    } else {
                        using(var smtp = new SmtpClient(this.Server, this.Port)) {
                            if(credentials != null) {
                                smtp.Credentials = credentials;
                            }
                            smtp.Send(mm);
                        }
                    }
                }
                if(_logEmails) {

                    var l = new EmailLog {
                        SentDateTime = DateTime.Now,
                        SentFrom = fromAddress,
                        SentTo = toAddress,
                        Subject = subject,
                        Body = mailBody
                    };
                    l.Insert();
                }
            } catch(Exception ex) {
                this.Log().Error("Unable to send email: {0}", ex.Message);
                this.ErrorException = ex;
                return false;
            }
            return true;
        }
예제 #6
0
        public EmailLog GetEmailLog(int EID)
        {

            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@EID", EID);

            dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "app_SentEmailLog_GetByID", arrParams);

            try
            {

                dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "app_SentEmailLog_GetByID", arrParams);

            }

            catch (SqlException exx)
            {

                System.Diagnostics.Debug.Write(exx.Message);

            }

            if (dr.Read())
            {

                // declare return value

                EmailLog result = new EmailLog();

                //DateTime _datetime;

                //int _int;

                //decimal _decimal;


                dr.Close();

                return result;

            }

            dr.Close();

            return null;

        }
예제 #7
0
        public static int Delete(EmailLog o)
        {

            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@EID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EID, o.EID.GetTypeCode()));

            try
            {

                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_SentEmailLog_Delete", arrParams);

            }

            catch (SqlException exx)
            {

                System.Diagnostics.Debug.Write(exx.Message);

            }

            return iReturn;

        }
예제 #8
0
        public static int Update(EmailLog o)
        {

            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[6];

            arrParams[0] = new SqlParameter("@EID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EID, o.EID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@SentDateTime", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SentDateTime, o.SentDateTime.GetTypeCode()));
            arrParams[2] = new SqlParameter("@SentFrom", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SentFrom, o.SentFrom.GetTypeCode()));
            arrParams[3] = new SqlParameter("@SentTo", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SentTo, o.SentTo.GetTypeCode()));
            arrParams[4] = new SqlParameter("@Subject", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Subject, o.Subject.GetTypeCode()));
            arrParams[5] = new SqlParameter("@Body", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Body, o.Body.GetTypeCode()));

            try
            {

                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_SentEmailLog_Update", arrParams);

            }

            catch (SqlException exx)
            {

                System.Diagnostics.Debug.Write(exx.Message);

            }

            return iReturn;

        }
예제 #9
0
        public static int Insert(EmailLog o)
        {

            SqlParameter[] arrParams = new SqlParameter[6];

            arrParams[0] = new SqlParameter("@SentDateTime", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SentDateTime, o.SentDateTime.GetTypeCode()));
            arrParams[1] = new SqlParameter("@SentFrom", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SentFrom, o.SentFrom.GetTypeCode()));
            arrParams[2] = new SqlParameter("@SentTo", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.SentTo, o.SentTo.GetTypeCode()));
            arrParams[3] = new SqlParameter("@Subject", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Subject, o.Subject.GetTypeCode()));
            arrParams[4] = new SqlParameter("@Body", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Body, o.Body.GetTypeCode()));
            arrParams[5] = new SqlParameter("@EID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EID, o.EID.GetTypeCode()));
            arrParams[5].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_SentEmailLog_Insert", arrParams);

            return int.Parse(arrParams[5].Value.ToString());

        }