Beispiel #1
0
        private void TimeSendSms_Tick(object sender, EventArgs e)
        {
            TimeSendSms.Enabled = false;
            TimeSms();

            var warndetailbll = new WarnDetailBll();
            var dtemail       = warndetailbll.FindByEmail();

            if (dtemail != null && dtemail.Rows.Count > 0)
            {
                var count     = dtemail.Rows.Count;
                var modellist = new List <EmailAndSmsModel>();
                for (var i = 0; i < count; i++)
                {
                    Service.Sms smsService = new Service.Sms();
                    var         model      = new EmailAndSmsModel()
                    {
                        Id      = dtemail.Rows[i]["id"].ToString(),
                        Address = dtemail.Rows[i]["address"].ToString(),
                        Title   = "充电桩告警邮件", //dtemail.Rows[i]["title"].ToString(),
                        Body    = smsService.ResplaceTemplateStr(dtemail.Rows[i]["body"].ToString(), dtemail.Rows[i]["warnrecid"].ToString())
                    };
                    modellist.Add(model);
                }
                var email = new Emails();
                email.SendMailtoDes(modellist);//发送邮件
            }
            TimeSendSms.Enabled = true;
        }
Beispiel #2
0
        public void Send()
        {
            while (true)
            {
                try
                {
                    var warndetailbll = new WarnDetailBll();
                    var dtemail       = warndetailbll.FindByEmail();
                    if (dtemail != null && dtemail.Rows.Count > 0)
                    {
                        var count     = dtemail.Rows.Count;
                        var modellist = new List <EmailAndSmsModel>();
                        for (var i = 0; i < count; i++)
                        {
                            var model = new EmailAndSmsModel()
                            {
                                Id      = dtemail.Rows[i]["id"].ToString(),
                                Address = dtemail.Rows[i]["address"].ToString(),
                                Title   = dtemail.Rows[i]["title"].ToString(),
                                Body    = dtemail.Rows[i]["body"].ToString()
                            };
                            modellist.Add(model);
                        }
                        var email = new Emails();
                        email.SendMailtoDes(modellist);//发送邮件
                    }



                    var dtsms = warndetailbll.FindBySms();
                    if (dtsms != null && dtsms.Rows.Count > 0)
                    {
                        var count     = dtsms.Rows.Count;
                        var modellist = new List <EmailAndSmsModel>();
                        for (var i = 0; i < count; i++)
                        {
                            var model = new EmailAndSmsModel()
                            {
                                Address = dtsms.Rows[i]["address"].ToString(),
                                Title   = dtsms.Rows[i]["title"].ToString(),
                                Body    = dtsms.Rows[i]["body"].ToString()
                            };
                            modellist.Add(model);
                        }
                        var sms = new Sms();
                        //sms.SendSms(modellist);//发送短信
                    }
                }
                catch (Exception e)
                {
                }
                Thread.Sleep(60 * 1000);//线程睡眠60秒
            }
        }