示例#1
0
        void triggerTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            triggerTimer.Stop();
            try
            {
                DateTime   dtNow = DateTime.Now;
                AlertLogic al    = AlertLogic.GetInstance();
                //发短信
                List <Alert> alerts = al.GetAlertsByType((int)提醒方式.员工短信);//Configs.SmsAlertTypeStaff);
                foreach (Alert a in alerts)
                {
                    if (a.Flag == 0 && a.提醒时间 > dtNow)
                    {
                        string[]      dest    = a.提醒对象.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        List <string> mobiles = new List <string>();
                        List <string> greets  = new List <string>();
                        StaffLogic    sl      = StaffLogic.GetInstance();
                        foreach (string d in dest)
                        {
                            Staff s = sl.GetStaff(Convert.ToInt32(d));
                            mobiles.Add(s.电话);
                            greets.Add(s.姓名);
                        }
                        if (SMSLogic.SendSMS(a.提醒项目, mobiles, greets))
                        {
                            al.SetFlag(a.ID, 1);
                        }
                    }
                }
                List <Alert> alerts2 = al.GetAlertsByType((int)提醒方式.会员短信);//Configs.SmsAlertTypeMember);
                foreach (Alert a in alerts2)
                {
                    if (a.Flag == 0 && a.提醒时间 > dtNow)
                    {
                        string[]      dest    = a.提醒对象.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        List <string> mobiles = new List <string>();
                        List <string> greets  = new List <string>();
                        foreach (string d in dest)
                        {
                            Member m = MemberLogic.GetInstance().GetMember(Convert.ToInt32(d));
                            mobiles.Add(m.电话);
                            greets.Add(m.姓名);
                        }
                        if (SMSLogic.SendSMS(a.提醒项目, mobiles, greets))
                        {
                            al.SetFlag(a.ID, 1);
                        }
                    }
                }
                //int hour = dtNow.Hour;
                //if (hour == 2)  //凌晨2点钟计算财务
                //{
                //    WriteLog.CreateLog("定时服务", "log", "执行任务开始...");


                //    WriteLog.CreateLog("定时服务", "log", dtNow.ToString() + "执行任务完毕.");
                //}
            }
            catch (Exception ex)
            {
                WriteLog.CreateLog("服务程序", "MyService.triggerTimer_Elapsed", "error", ex.ToString());
            }
            finally
            {
                triggerTimer.Start();
            }
        }