Example #1
0
        void Global_ExecuteTask(object sender, System.Timers.ElapsedEventArgs e)
        {
            TesheContext db = new TesheContext();
            string strweek = e.SignalTime.DayOfWeek.ToString();
            DateTime date = e.SignalTime.Date;

            int inthour = e.SignalTime.Hour;
            int intminute = e.SignalTime.Minute;
            //int intSecond = e.SignalTime.Second;
            //int isecond = 00;
            log4net.ILog log = log4net.LogManager.GetLogger("MyLogger");
            List<Device> devicelist = db.Devices.ToList();
            List<UserInfo> userlist = db.UserInfoes.Where<UserInfo>(u => u.UserType.Name != "客户").ToList();

            foreach (var i in devicelist)
            {
                TimeSpan ts = i.CheckTime.AddDays(i.CheckCycle) - DateTime.Now;
                List<UserInfo> userDistrict = userlist.Where<UserInfo>(u => u.District == i.District && u.UserType.Name == "区(县)级管理员").ToList();
                List<UserInfo> userCity = userlist.Where<UserInfo>(u => u.City == i.City && u.UserType.Name == "市级管理员").ToList();
                List<UserInfo> userProvince = userlist.Where<UserInfo>(u => u.Province == i.Province && u.UserType.Name == "省级管理员").ToList();
                List<UserInfo> userSystem = userlist.Where<UserInfo>(u => u.UserType.Name == "系统管理员").ToList();
                if (ts.Days == 7 || ts.Days == 15)
                //if (true)
                {
                    foreach (var j in userDistrict)
                    {
                        Mail mail = new Mail();
                        mail.Contents = i.Company + "的" + i.Name + "(" + i.Model + ")" + "设备需要在" + i.CheckTime.AddDays(i.CheckCycle) + "前检查";
                        mail.IsRead = 0;
                        mail.ReceivedUser = j;
                        db.Mails.Add(mail);
                        db.SaveChanges();
                    }
                    foreach (var j in userCity)
                    {
                        Mail mail = new Mail();
                        mail.Contents = i.Company + "的" + i.Name + "(" + i.Model + ")" + "设备需要在" + i.CheckTime.AddDays(i.CheckCycle) + "前检查";
                        mail.IsRead = 0;
                        mail.ReceivedUser = j;
                        db.Mails.Add(mail);
                        db.SaveChanges();
                    }
                    foreach (var j in userProvince)
                    {
                        Mail mail = new Mail();
                        mail.Contents = i.City + i.District + i.Company + "的" + i.Name + "(" + i.Model + ")" + "设备需要在" + i.CheckTime.AddDays(i.CheckCycle) + "前检查";
                        mail.IsRead = 0;
                        mail.ReceivedUser = j;
                        db.Mails.Add(mail);
                        db.SaveChanges();
                    }
                    foreach (var j in userSystem)
                    {
                        Mail mail = new Mail();
                        mail.Contents = i.Company + "的" + i.Name + "(" + i.Model + ")" + "设备需要在" + i.CheckTime.AddDays(i.CheckCycle) + "前检查";
                        mail.IsRead = 0;
                        mail.ReceivedUser = j;
                        db.Mails.Add(mail);
                        db.SaveChanges();
                    }
                }
            }
            //if (inthour == ihour && intminute == iminute)
            //{

            //}
        }
Example #2
0
 void MvcApplication_AuthorizeRequest(object sender, EventArgs e)
 {
     IIdentity id = Context.User.Identity;
     if (id.IsAuthenticated)
     {
         string[] roles = new string[1];
         roles[0] = new TesheContext().UserInfoes.FirstOrDefault<UserInfo>(u => u.Name == id.Name).UserType.Name;
         Context.User = new GenericPrincipal(id, roles);
     }
 }