예제 #1
0
        public virtual ActionResult Create([DataSourceRequest] DataSourceRequest request, TaskViewModel task)
        {
            if (KiemTraSession() == true)
            {
                return(RedirectToAction("DangNhap", "QuanTri"));
            }
            if (Session["PhongHop"] == null)
            {
                return(RedirectToAction("DangKy", "LichHop"));
            }

            NhanVien nv = (NhanVien)Session["DangNhap"];

            task.CreatedUserId = nv.Id;

            task.CreatedDate = DateTime.Now;
            task.OwnerID     = int.Parse(Session["PhongHop"].ToString());
            task.Status      = true;

            if (ModelState.IsValid && KiemTraLichTrung(task.Start.ToString("d/M/yyyy H:m"), task.End.ToString("d/M/yyyy H:m"), "0", task.RecurrenceRule) == "1")
            {
                taskService.Insert(task, ModelState);
            }

            string  sNoiDung = " <p>Dear Ms. Đoan,</p><p>  <b>" + nv.HoTen + "</b> như sau:</p>";
            LichHop lh       = db.LichHops.SingleOrDefault(n => n.ID == task.TaskID);

            sNoiDung += LayNoiDungLich(lh);
            sNoiDung += "<p>Trân trọng.</p>";
            MailLich(sNoiDung);

            return(Json(new[] { task }.ToDataSourceResult(request, ModelState)));
        }
예제 #2
0
        public string LayNoiDungLich(LichHop lh)
        {
            string sDinhKy = "";

            if (lh.RecurrenceRule != null)
            {
                sDinhKy = " (Định kỳ)";
            }
            string sNoiDung = "";

            sNoiDung += "<ul>";
            sNoiDung += "<li>Cuộc họp: " + lh.Subject + "</li>";
            sNoiDung += "<li>Thời gian: " + lh.Start.Value.ToString("HH:mm") + " - " + lh.End.Value.ToString("HH:mm") + "</li>";
            sNoiDung += "<li>Ngày: " + lh.Start.Value.DayOfWeek + " " + lh.Start.Value.ToString("dd/MM/yyyy") + sDinhKy + "</li>";
            sNoiDung += "<li>Tại phòng họp: " + db.PhongHops.SingleOrDefault(n => n.Id == lh.RoomId).Name + "</li>";
            sNoiDung += "</ul>";

            return(sNoiDung);
        }
예제 #3
0
        public virtual JsonResult Destroy([DataSourceRequest] DataSourceRequest request, TaskViewModel task)
        {
            NhanVien nv = (NhanVien)Session["DangNhap"];

            if (ModelState.IsValid && (task.CreatedUserId == nv.Id || HttpContext.User.IsInRole("UPDATE-LICH")))
            {
                //taskService.Delete(task, ModelState);

                task.Status = false;
                taskService.Update(task, ModelState);
            }

            string  sNoiDung = " <p>Dear Ms. Đoan,</p><p>Hệ thống vừa ghi nhận thao tác hủy sử dụng phòng họp của Ông/Bà <b>" + nv.HoTen + "</b> như sau:</p>";
            LichHop lh       = db.LichHops.SingleOrDefault(n => n.ID == task.TaskID);

            sNoiDung += LayNoiDungLich(lh);
            sNoiDung += "<p>Trân trọng.</p>";
            MailLich(sNoiDung);

            return(Json(new[] { task }.ToDataSourceResult(request, ModelState)));
        }
예제 #4
0
        public virtual ActionResult Update([DataSourceRequest] DataSourceRequest request, TaskViewModel task)
        {
            if (KiemTraSession() == true)
            {
                return(RedirectToAction("DangNhap", "QuanTri"));
            }
            if (Session["PhongHop"] == null)
            {
                return(RedirectToAction("DangKy", "LichHop"));
            }

            NhanVien nv = (NhanVien)Session["DangNhap"];

            task.OwnerID = int.Parse(Session["PhongHop"].ToString());

            //gui mail lay noi dung cu
            string  sNoiDung = " <p>Dear Ms. Đoan,</p><p>Hệ thống vừa ghi thao tác chỉnh sửa lịch họp của Ông/Bà <b>" + nv.HoTen + "</b> như sau:</p> <p>Lịch họp cũ: </p>";
            LichHop lh       = db.LichHops.SingleOrDefault(n => n.ID == task.TaskID);

            sNoiDung += LayNoiDungLich(lh);

            if (ModelState.IsValid && (task.CreatedUserId == nv.Id || HttpContext.User.IsInRole("UPDATE-LICH")) && KiemTraLichTrung(task.Start.ToString("d/M/yyyy H:m"), task.End.ToString("d/M/yyyy H:m"), task.TaskID.ToString(), task.RecurrenceRule) == "1")
            {
                task.UpdatedDate = DateTime.Now;
                taskService.Update(task, ModelState);
            }

            //gui mail lay moi dung moi

            lh.Subject        = task.Title;
            lh.Start          = task.Start;
            lh.End            = task.End;
            lh.RecurrenceRule = task.RecurrenceRule;

            sNoiDung += "<p>Lịch họp mới: </p>";
            sNoiDung += LayNoiDungLich(lh);
            sNoiDung += "<p>Trân trọng.</p>";
            MailLich(sNoiDung);
            return(Json(new[] { task }.ToDataSourceResult(request, ModelState)));
        }
예제 #5
0
        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");
        }
예제 #6
0
        public List <LichHop> getDataLH(string date)
        {
            if (date == null)
            {
                date = DateTime.Now.ToString("dd/MM/yyyy");
            }
            ViewBag.DATE = date;
            string[]        arrDate   = date.Split('/');
            int             _ngay     = Convert.ToInt32(arrDate[0]);
            int             _thang    = Convert.ToInt32(arrDate[1]);
            int             _nam      = Convert.ToInt32(arrDate[2]);
            List <DateTime> listWeeks = getListWeeks(Convert.ToDateTime(date));
            int             startWeek = 0;
            int             endWeek   = 0;

            for (int i = 0; i < listWeeks.Count() - 1; i++)
            {
                if (_ngay >= listWeeks[i].Day && _ngay < listWeeks[i + 1].Day)
                {
                    startWeek = listWeeks[i].Day;
                    endWeek   = listWeeks[i + 1].Day - 1;
                    break;
                }
                else
                {
                    startWeek = listWeeks[i + 1].Day;
                }
            }
            if (endWeek == 0)
            {
                string d = "01/" + (_thang + 1) + "/" + _nam;
                endWeek = Convert.ToDateTime(d).AddDays(-1).Day;
            }
            DT_WebGISEntities MyContext = new DT_WebGISEntities();
            var listData = MyContext.CMS_Schedules.Where(x => x.StartDate.Value.Day >= startWeek &&
                                                         x.StartDate.Value.Day <= endWeek).ToList();

            #region GanDuLieuLichHop

            //List<CMS_Leader> lLeader = MyContext.CMS_Leader.ToList();
            //CMS_Schedules schedule;
            //for (int i = startWeek; i <= endWeek; i++)
            //{
            //    var data = listData.Where(x => x.StartDate.Value.Day == i).ToList();
            //    DateTime dtime = new DateTime(_nam, _thang, i, 0, 0, 0);
            //    int dow = Convert.ToInt32(dtime.DayOfWeek);//bỏ thứ 7, cn: cn=0
            //    if (data == null || data.Count() < 1 && dow != 6 && dow != 0)
            //    {
            //        foreach (var item in lLeader)
            //        {
            //            schedule = new CMS_Schedules();
            //            schedule.Title = "Làm việc tại cơ quan";
            //            schedule.Leaders = item.Position + " " + item.Name;
            //            schedule.StartDate = dtime.AddHours(8);
            //            MyContext.CMS_Schedules.Add(schedule);
            //            schedule = new CMS_Schedules();
            //            schedule.Title = "Làm việc tại cơ quan";
            //            schedule.Leaders = item.Position + " " + item.Name;
            //            schedule.StartDate = dtime.AddHours(13);
            //            MyContext.CMS_Schedules.Add(schedule);
            //        }
            //    }
            //}
            //MyContext.SaveChanges();
            listData = MyContext.CMS_Schedules.Where(x => x.StartDate.Value.Day >= startWeek &&
                                                     x.StartDate.Value.Day <= endWeek).ToList();

            #endregion GanDuLieuLichHop

            List <LichHop> listLH = new List <LichHop>();
            LichHop        lh;
            for (int i = startWeek; i <= endWeek; i++)
            {
                string da  = i + "/" + _thang + "/" + _nam;
                int    dow = Convert.ToInt32(Convert.ToDateTime(da).DayOfWeek);
                if (dow != 6 && dow != 0)
                {
                    lh      = new LichHop();
                    lh.data = listData.Where(x => x.StartDate.Value.Day == i).ToList();
                    lh.thu  = getThu(Convert.ToDateTime(da).DayOfWeek.ToString());
                    lh.ngay = da;
                    listLH.Add(lh);
                }
            }
            return(listLH);
        }