public ActionResult LichHopTuan() { if (KiemTraSession() == true) { return(RedirectToAction("DangNhap", "QuanTri")); } Tools tool = new Tools(); DateTime dtFirst = tool.FirstDayOfWeek(DateTime.Now); DateTime dtLast = tool.LastDayOfWeek(DateTime.Now); //xu ly lich hop ViewBag.lstPhong = db.PhongHops.Where(n => n.Status == true).OrderBy(n => n.Ordering); IEnumerable <LichHop> lstLichHop = db.LichHops.Where(n => n.Status == true && n.Start.Value >= dtFirst && n.End.Value <= dtLast); List <DuyetLichHop> lstDuyetLich = new List <DuyetLichHop>(); lstDuyetLich = DuyetLichHop.ThemLichDinhKy(dtFirst, dtLast); foreach (var item in lstLichHop.Where(n => n.RecurrenceRule == null)) { DuyetLichHop lichhop = new DuyetLichHop(item.Subject, item.RoomId.Value, item.Start.Value, item.End.Value, item.Start.Value, false); lstDuyetLich.Add(lichhop); } ViewBag.lstLichHop = lstDuyetLich; return(View()); }
public ActionResult Index(int?page, string TenVanBan, string SoHieu, string LoaiVanBan, string NoiBanHanh, string NguoiKy, string NgayBanHanhfrom, string NgayBanHanhto, string NgayHieuLucfrom, string NgayHieuLucto, string TinhTrang, string PhongBan) { if (KiemTraSession() == true) { return(RedirectToAction("DangNhap", "QuanTri")); } Tools tool = new Tools(); DateTime dtNow = DateTime.Now; ViewBag.LoaiVanBans = db.LoaiTaiLieux.OrderBy(n => n.ThuTu); ViewBag.VanBans = db.TaiLieux; int pageSize = 10; int pageNumber = (page ?? 1); IEnumerable <TaiLieu> lstTaiLieu = db.TaiLieux.Where(n => n.TenTaiLieu != null); ViewBag.DMTinTuc = db.DanhMucs.Where(n => n.DanhMucCha == Tools.MaDanhMucTin).OrderBy(n => n.ThuTu); ViewBag.TinTuc = db.TinTucs.Where(n => n.TrangThai == true && n.NgayDang <= dtNow).OrderByDescending(n => n.NgayDang).Take(4); ViewBag.dsTinTuc = db.TinTucs.Where(n => n.TrangThai == true && n.NgayDang <= dtNow).OrderByDescending(n => n.NgayDang); //xu ly lich hop ViewBag.lstPhong = db.PhongHops.Where(n => n.Status == true).OrderBy(n => n.Ordering); ViewBag.lstBanner = db.Banners.OrderBy(n => n.Order); IEnumerable <LichHop> lstLichHop = db.LichHops.Where(n => n.Status == true && n.Start.Value.Day == dtNow.Day && n.Start.Value.Month == dtNow.Month && n.Start.Value.Year == dtNow.Year); List <DuyetLichHop> lstDuyetLich = new List <DuyetLichHop>(); lstDuyetLich = DuyetLichHop.ThemLichDinhKy(DateTime.Now, DateTime.Now); foreach (var item in lstLichHop.Where(n => n.RecurrenceRule == null)) { DuyetLichHop lichhop = new DuyetLichHop(item.Subject, item.RoomId.Value, item.Start.Value, item.End.Value, item.Start.Value, false); lstDuyetLich.Add(lichhop); } ViewBag.lstLichHop = lstDuyetLich; //return View(lstTaiLieu.OrderByDescending(n=>n.NgayHieuLuc).ToList().ToPagedList(pageNumber, pageSize)); return(RedirectToAction("dsTinTuc", "TinTuc")); }
public string KiemTraLichTrung(string start, string end, string lichID, string recurrenceRule) { DateTime dtstart = DateTime.ParseExact(start, "d/M/yyyy H:m", null); DateTime dtend = DateTime.ParseExact(end, "d/M/yyyy H:m", null); int ilichID = int.Parse(lichID); int iKT = 1; //lich khong dinh ky if (string.IsNullOrEmpty(recurrenceRule)) { IEnumerable <LichHop> lstLichHop = db.LichHops.Where(n => n.Status == true && n.ID != ilichID && n.Start.Value.Day == dtstart.Day && n.Start.Value.Month == dtstart.Month && n.Start.Value.Year == dtstart.Year); List <DuyetLichHop> lstDuyetLich = new List <DuyetLichHop>(); lstDuyetLich = DuyetLichHop.ThemLichDinhKy(dtstart, dtend); foreach (var item in lstLichHop.Where(n => n.RecurrenceRule == null)) { DuyetLichHop lichhop = new DuyetLichHop(item.Subject, item.RoomId.Value, item.Start.Value, item.End.Value, item.Start.Value, false); lstDuyetLich.Add(lichhop); } //loc theo phong int iRoomID = int.Parse(Session["PhongHop"].ToString()); lstDuyetLich = lstDuyetLich.Where(n => n.MaPhong == iRoomID).ToList(); foreach (var item in lstDuyetLich) { if (item.BatDau.TimeOfDay <= dtstart.TimeOfDay && item.KetThuc.TimeOfDay > dtstart.TimeOfDay) { iKT = 0; } if (item.BatDau.TimeOfDay < dtend.TimeOfDay && item.KetThuc.TimeOfDay >= dtend.TimeOfDay) { iKT = 0; } if (item.BatDau.TimeOfDay > dtstart.TimeOfDay && item.KetThuc.TimeOfDay < dtend.TimeOfDay) { iKT = 0; } if (iKT == 0) { return(item.NgayDinhKy.ToString("dd/MM/yyyy") + " lúc " + item.BatDau.ToString("HH:mm") + " đến " + item.KetThuc.ToString("HH:mm") + "\n" + item.TieuDe); } } } else { Tools tool = new Tools(); DateTime dtFirst = tool.FirstDayOfWeek(dtstart); DateTime dtLast = tool.LastDayOfWeek(dtstart); //them tam lich tuan moi LichHop lichTuan = new LichHop(); lichTuan.Subject = ""; lichTuan.RoomId = int.Parse(Session["PhongHop"].ToString()); lichTuan.Start = dtstart; lichTuan.End = dtend; List <DuyetLichHop> lstLichTuan = new List <DuyetLichHop>(); DuyetLichHop.KiemTraDinhKy(dtFirst, dtLast, recurrenceRule, lstLichTuan, lichTuan); //lay lich tuan ViewBag.lstPhong = db.PhongHops.Where(n => n.Status == true).OrderBy(n => n.Ordering); IEnumerable <LichHop> lstLichHop = db.LichHops.Where(n => n.Status == true && n.ID != ilichID && n.Start.Value >= dtFirst && n.End.Value <= dtLast); List <DuyetLichHop> lstDuyetLich = new List <DuyetLichHop>(); foreach (var item in db.LichHops.Where(n => n.Status == true && n.ID != ilichID && n.RecurrenceRule != null)) { DuyetLichHop.KiemTraDinhKy(dtFirst, dtLast, item.RecurrenceRule, lstDuyetLich, item); } foreach (var item in lstLichHop.Where(n => n.RecurrenceRule == null)) { DuyetLichHop lichhop = new DuyetLichHop(item.Subject, item.RoomId.Value, item.Start.Value, item.End.Value, item.Start.Value, false); lstDuyetLich.Add(lichhop); } //loc theo phong int iRoomID = int.Parse(Session["PhongHop"].ToString()); lstDuyetLich = lstDuyetLich.Where(n => n.MaPhong == iRoomID).ToList(); foreach (var item in lstDuyetLich) { foreach (var itemTuan in lstLichTuan) { if (item.NgayDinhKy.Date == itemTuan.NgayDinhKy.Date && item.BatDau.TimeOfDay <= dtstart.TimeOfDay && item.KetThuc.TimeOfDay > dtstart.TimeOfDay) { iKT = 0; } if (item.NgayDinhKy.Date == itemTuan.NgayDinhKy.Date && item.BatDau.TimeOfDay < dtend.TimeOfDay && item.KetThuc.TimeOfDay >= dtend.TimeOfDay) { iKT = 0; } if (item.NgayDinhKy.Date == itemTuan.NgayDinhKy.Date && item.BatDau.TimeOfDay > dtstart.TimeOfDay && item.KetThuc.TimeOfDay < dtend.TimeOfDay) { iKT = 0; } if (iKT == 0) { return(item.NgayDinhKy.ToString("dd/MM/yyyy") + " lúc " + item.BatDau.ToString("HH:mm") + " đến " + item.KetThuc.ToString("HH:mm") + "\n" + item.TieuDe); } } } } return("1"); }