예제 #1
0
        public int sendEmail(string subject, string msgText)
        {
            int      li_return = 0;
            BaseMail msgMail   = new BaseMail()
            {
                strMailTo              = this.strMailTo,
                strMailPort            = this.strMailPort,
                strMailLogin           = this.strMailLogin,
                strMailPass            = this.strMailPass,
                strMailHost            = this.strMailHost,
                strMailFrom            = this.strMailFrom,
                isSendMail             = this.isSendMail,
                isSSLMail              = this.isSSLMail,
                strConnectionSource    = this.strConnectionSource,
                strConnectionTarget    = this.strConnectionTarget,
                strActionLogPath       = this.strActionLogPath,
                strActionLogDeleteDays = this.strActionLogDeleteDays
            };

            try
            {
                msgMail.sendDefaultEmail(subject, msgText);
                li_return = 1;
            }

            catch (Exception ex)
            {
                StackTrace st = new StackTrace(new StackFrame(true));
                this.actionLog("BaseClass:sendEmail(" + st.GetFrame(0).GetFileLineNumber().ToString() + "):", "Exception error: " + ex.ToString());
                li_return = -1;
            }
            finally
            {
                if (msgMail != null)
                {
                    msgMail = null;
                }
            }
            return(li_return);
        }
예제 #2
0
        public int sendEmail(string proName, ArrayList parmName, ArrayList parmType, ArrayList parmSize, ArrayList parmValue, string subject, string msgText)
        {
            ArrayList emailList = new ArrayList();
            ArrayList parmList  = new ArrayList();
            DataTable dt;
            DataTable dt1;

            dt  = new DataTable();
            dt1 = new DataTable();
            DbCommon dbcomm = new DbCommon()
            {
                OleConnectionStringSource = strConnectionSource,
                OleConnectionStringTarget = strConnectionTarget,
                strActionLogPath          = this.strActionLogPath,
                strActionLogDeleteDays    = this.strActionLogDeleteDays
            };
            BaseMail msgMail = new BaseMail()
            {
                strMailTo              = this.strMailTo,
                strMailPort            = this.strMailPort,
                strMailLogin           = this.strMailLogin,
                strMailPass            = this.strMailPass,
                strMailHost            = this.strMailHost,
                strMailFrom            = this.strMailFrom,
                isSendMail             = this.isSendMail,
                isSSLMail              = this.isSSLMail,
                strConnectionSource    = this.strConnectionSource,
                strConnectionTarget    = this.strConnectionTarget,
                strActionLogPath       = this.strActionLogPath,
                strActionLogDeleteDays = this.strActionLogDeleteDays
            };
            string ls_actscenario       = "";
            string ls_act_count         = "";
            int    li_return            = 0;
            int    li_no_email_timefrom = 0;
            int    li_no_email_timeto   = 0;
            int    li_curr_hour         = 0;
            int    li_num_extend        = 0;
            int    li_hour_limit_value  = 0;

            //1.get email address
            try
            {
                this.actionLog("BaseClass:sendEmail:", "Send Email Procedure Name: " + proName);
                OleDbConnection cnnSql = dbcomm.GetOleConnection("TARGET");
                parmList = dbcomm.MakeInParm(parmName, parmType, parmSize, parmValue);
                dt       = dbcomm.getOleProData(proName, parmList, cnnSql);
                dt1      = dbcomm.getOleTableData("select dsp_type,dsp_sub_type,dsp_act_desc,action_count,hour_count from Dsp_Est_Action_Count", cnnSql);
                if (cnnSql != null)
                {
                    cnnSql.Dispose();
                }
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow myRow in dt.Rows)
                    {
                        this.actionLog("BaseClass:sendEmail:", "get no email hours: " + myRow.ItemArray[3].ToString() + ";" + myRow.ItemArray[4].ToString() + ";" + parmValue[0].ToString());
                        //get numbr of extention and hour limit value
                        li_num_extend       = Int32.Parse(myRow.ItemArray[5].ToString());
                        li_hour_limit_value = Int32.Parse(myRow.ItemArray[6].ToString());
                        this.actionLog("BaseClass:sendEmail:", "get No. Extend: " + myRow.ItemArray[5].ToString() + ";" + myRow.ItemArray[6].ToString());
                        //check no email hours
                        li_curr_hour = DateTime.Now.Hour;
                        if (li_curr_hour == 0)
                        {
                            li_curr_hour = 24;
                        }
                        if (myRow.ItemArray[3].ToString() != "")
                        {
                            li_no_email_timefrom = Int32.Parse(myRow.ItemArray[3].ToString().Substring(0, 2));
                            if (li_no_email_timefrom == 0)
                            {
                                li_no_email_timefrom = 24;
                            }
                            if (myRow.ItemArray[4].ToString() != "")
                            {
                                li_no_email_timeto = Int32.Parse(myRow.ItemArray[4].ToString().Substring(0, 2));
                                if (li_no_email_timeto == 0)
                                {
                                    li_no_email_timeto = 24;
                                }
                                //----------------------------------------------------------
                                // check curr hour and no email time range to decide whether this
                                // email should added to list or not.
                                //NO EMAIL TIME RANGE ACROSS THE DAY!!!
                                if (li_no_email_timeto <= li_no_email_timefrom)
                                {
                                    //the curr time is out of no email time range, send email.
                                    if ((li_curr_hour < li_no_email_timefrom) & (li_curr_hour > li_no_email_timeto))
                                    {
                                        emailList.Add(myRow.ItemArray[2].ToString());
                                    }
                                    else
                                    {
                                        this.actionLog("BaseClass:sendEmail:", "Check DISPATCHON in no email time range across day");
                                        //NO EMAIL NEED TO BE SENT EXCEPT DISPATCHON AND TIMELIMIT
                                        if ((parmValue[0].ToString().ToUpper() == "DISPATCHON") & (parmValue[1].ToString().ToUpper() == "TIMELIMIT"))
                                        {
                                            if (dt1.Rows.Count > 0)
                                            {
                                                foreach (DataRow myRow1 in dt1.Rows)
                                                {
                                                    ls_actscenario = myRow1.ItemArray[0].ToString();
                                                    ls_act_count   = myRow1.ItemArray[3].ToString();
                                                    if (((myRow1.ItemArray[0].ToString()).ToUpper() == "BIDCHANGE") & ((myRow1.ItemArray[1].ToString()).ToUpper() == "BIDCHANGE"))
                                                    {
                                                        if ((Int32.Parse(myRow1.ItemArray[3].ToString()) > li_num_extend) ||
                                                            (Int32.Parse(myRow1.ItemArray[4].ToString()) > li_hour_limit_value))
                                                        {
                                                            emailList.Add(myRow.ItemArray[2].ToString());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //NO EMAIL TIME RNGE IN THE SAME DAY.
                                    //curr time is out of no email time range, send email.
                                    if ((li_curr_hour < li_no_email_timefrom) || (li_curr_hour > li_no_email_timeto))
                                    {
                                        //send email
                                        emailList.Add(myRow.ItemArray[2].ToString());
                                    }
                                    else
                                    {
                                        this.actionLog("BaseClass:sendEmail:", "Check DISPATCHON in no email time range in the same day");
                                        //there is should no email exception for "DISPATCHON AND TIMELIMIT"
                                        //check "DISPATCHON AND TIMELIMIT"
                                        if ((parmValue[0].ToString().ToUpper() == "DISPATCHON") & (parmValue[1].ToString().ToUpper() == "TIMELIMIT"))
                                        {
                                            if (dt1.Rows.Count > 0)
                                            {
                                                foreach (DataRow myRow1 in dt1.Rows)
                                                {
                                                    ls_actscenario = myRow1.ItemArray[0].ToString();
                                                    ls_act_count   = myRow1.ItemArray[3].ToString();
                                                    if (((myRow1.ItemArray[0].ToString()).ToUpper() == "BIDCHANGE") & ((myRow1.ItemArray[1].ToString()).ToUpper() == "BIDCHANGE"))
                                                    {
                                                        if ((Int32.Parse(myRow1.ItemArray[3].ToString()) > li_num_extend) ||
                                                            (Int32.Parse(myRow1.ItemArray[4].ToString()) > li_hour_limit_value))
                                                        {
                                                            emailList.Add(myRow.ItemArray[2].ToString());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            //there is no no email time range limit. send email
                            emailList.Add(myRow.ItemArray[2].ToString());
                        }
                        this.actionLog("BaseClass:sendEmail:", "Scenario Value: " + ls_actscenario + ";" + ls_act_count);
                        this.actionLog("BaseClass:sendEmail:", "no email hours: " + li_no_email_timefrom.ToString() + ";" + li_no_email_timeto.ToString());
                        this.actionLog("BaseClass:sendEmail:", "Get email address for type " + subject + ":" + myRow.ItemArray[2].ToString());
                    }
                }
                this.actionLog("BaseClass:sendEmail:", "The email list before sendemail: ");
                for (int i = 0; i < emailList.Count; i++)
                {
                    this.actionLog("BaseClass:sendEmail:", emailList[i].ToString());
                }
                if (emailList.Count > 0)
                {
                    li_return = msgMail.sendEmail(emailList, subject, msgText);
                }
                else
                {
                    this.actionLog("BaseClass:sendEmail:", "No email list, send default email.");
                    li_return = msgMail.sendEmail(subject, msgText);
                }
                this.actionLog("BaseClass:sendEmail:", "Email send out status value returned from msgMail: " + li_return.ToString());
            }
            catch (Exception ex)
            {
                li_return = -1;
                StackTrace st = new StackTrace(new StackFrame(true));
                this.actionLog("BaseClass:sendEmail(" + st.GetFrame(0).GetFileLineNumber().ToString() + "):", "Exception error: " + ex.ToString());
            }
            finally
            {
                if (dt != null)
                {
                    dt.Dispose();
                }
                dbcomm  = null;
                msgMail = null;
            }
            return(li_return);
        }