public JsonResult DeleteLichHop(long id, bool isCancel = false) { AssignUserInfo(); JsonResultBO result = new JsonResultBO(true); QUANLY_PHONGHOPBusiness = Get <QUANLY_PHONGHOPBusiness>(); QUANLY_PHONGHOP entity = QUANLY_PHONGHOPBusiness.Find(id); if (entity != null && entity.IS_DELETE != true) { entity.IS_DELETE = true; QUANLY_PHONGHOPBusiness.Save(entity); if (isCancel) { SYS_TINNHANBusiness = Get <SYS_TINNHANBusiness>(); string bookDate = entity.NGAYDAT != null?entity.NGAYDAT.Value.ToVietnameseDateFormat() : string.Empty; string title = "THÔNG BÁO HỦY LỊCH"; string url = string.Empty; string startTime = string.Format("{0}h{1}", entity.GIOBATDAU.Value.ToString("D2"), entity.PHUTBATDAU.Value.ToString("D2")); string endTime = string.Format("{0}h{1}", entity.GIOKETTHUC.Value.ToString("D2"), entity.PHUTKETTHUC.Value.ToString("D2")); string content = string.Format("Cuộc họp về \"{0}\" trong ngày {1} ({2} - {3}) đã bị hủy", entity.MUCDICH, bookDate, startTime, endTime); SYS_TINNHANBusiness.sendMessageMultipleUsers(new List <long> { entity.CREATED_BY.GetValueOrDefault() }, currentUser, title, content, url, string.Empty, false, entity.ID, 0); } } else { result.Status = false; } return(Json(result)); }
public PartialViewResult EditFastRoomRequest(QUANLY_PHONGHOP item) { AssignUserInfo(); DM_NGUOIDUNGBusiness = Get <DM_NGUOIDUNGBusiness>(); QUANLY_PHONGHOPBusiness = Get <QUANLY_PHONGHOPBusiness>(); QUANLY_PHONGHOP roomEntity; if (item.ID > 0) { roomEntity = QUANLY_PHONGHOPBusiness.Find(item.ID) ?? new QUANLY_PHONGHOP(); } else { if (item.GIOBATDAU >= 8 && item.GIOBATDAU < 23) { item.GIOKETTHUC = item.GIOBATDAU + 1; } else if (item.GIOBATDAU < 8) { item.GIOBATDAU = 8; item.GIOKETTHUC = item.GIOBATDAU + 1; } else { item.GIOKETTHUC = item.GIOBATDAU; } roomEntity = item; } EditVM viewModel = new EditVM(roomEntity); viewModel.groupLeaders = DM_NGUOIDUNGBusiness.GetDropDownByDeptParentId(currentUser.DeptParentID.GetValueOrDefault(), roomEntity.USER_ID); return(PartialView("EditPhong", viewModel)); }
public EditVM(QUANLY_PHONGHOP roomEntity) { this.roomEntity = roomEntity; this.groupStartHours = Utility.GetHours(roomEntity.GIOBATDAU.GetValueOrDefault(), 8); this.groupStartMinutes = Utility.GetMinutes(roomEntity.PHUTBATDAU.GetValueOrDefault(), 5); this.groupEndHours = Utility.GetHours(roomEntity.GIOKETTHUC.GetValueOrDefault(), 8); this.groupEndMinutes = Utility.GetMinutes(roomEntity.PHUTKETTHUC.GetValueOrDefault(), 5); }
public PartialViewResult EditRoomRequest(long id) { AssignUserInfo(); DM_NGUOIDUNGBusiness = Get <DM_NGUOIDUNGBusiness>(); QUANLY_PHONGHOPBusiness = Get <QUANLY_PHONGHOPBusiness>(); QUANLY_PHONGHOP roomEntity = QUANLY_PHONGHOPBusiness.Find(id) ?? new QUANLY_PHONGHOP(); EditVM viewModel = new EditVM(roomEntity); viewModel.groupLeaders = DM_NGUOIDUNGBusiness.GetDropDownByDeptParentId(currentUser.DeptParentID.GetValueOrDefault(), roomEntity.USER_ID); return(PartialView("EditPhong", viewModel)); }
public JsonResult SaveBooking(FormCollection col) { AssignUserInfo(); JsonResultBO result = new JsonResultBO(true); QUANLY_PHONGHOPBusiness = Get <QUANLY_PHONGHOPBusiness>(); QL_PHONGHOPBusiness = Get <QL_PHONGHOPBusiness>(); SYS_TINNHANBusiness = Get <SYS_TINNHANBusiness>(); List <long> notifyUsers = new List <long>(); string title = string.Empty; string content = string.Empty; string url = string.Empty; string bookDate = string.Empty; string startTime = string.Empty; string endTime = string.Empty; string roomName = string.Empty; QUANLY_PHONGHOP bookEntity = QUANLY_PHONGHOPBusiness.Find(col["ID"].ToIntOrZero()); if (bookEntity != null && bookEntity.IS_DELETE != true) { bookEntity.PHONG_ID = col["PHONG_ID"].ToIntOrZero(); QUANLY_PHONGHOPBusiness.Save(bookEntity); //hủy lịch các phòng khác string duplicateIds = col["DUPLICATE"]; if (!string.IsNullOrEmpty(duplicateIds)) { List <int> ids = duplicateIds.ToListInt(','); foreach (var id in ids) { QUANLY_PHONGHOP cancelCalendar = QUANLY_PHONGHOPBusiness.Find(id); if (cancelCalendar != null) { cancelCalendar.IS_DELETE = true; QUANLY_PHONGHOPBusiness.Save(cancelCalendar); //gửi thông báo hủy lịch đến người đặt lịch bookDate = cancelCalendar.NGAYDAT != null?cancelCalendar.NGAYDAT.Value.ToVietnameseDateFormat() : string.Empty; startTime = string.Format("{0}h{1}", cancelCalendar.GIOBATDAU.Value.ToString("D2"), cancelCalendar.PHUTBATDAU.Value.ToString("D2")); endTime = string.Format("{0}h{1}", cancelCalendar.GIOKETTHUC.Value.ToString("D2"), cancelCalendar.PHUTKETTHUC.Value.ToString("D2")); title = "THÔNG BÁO HỦY LỊCH"; content = string.Format("Cuộc họp về \"{0}\" trong ngày {1} ({2} - {3}) đã bị hủy", cancelCalendar.MUCDICH, bookDate, startTime, endTime); SYS_TINNHANBusiness.sendMessageMultipleUsers(new List <long> { cancelCalendar.CREATED_BY.GetValueOrDefault() }, currentUser, title, content, url, string.Empty, false, cancelCalendar.ID, 0); } } } result.Message = "Đặt phòng thành công"; //lấy thông tin phòng, người đặt lịch và thời gian đặt lịch QL_PHONGHOP room = QL_PHONGHOPBusiness.Find(bookEntity.PHONG_ID) ?? new QL_PHONGHOP(); roomName = room.TENPHONG; notifyUsers.Add(bookEntity.CREATED_BY.GetValueOrDefault()); bookDate = bookEntity != null?bookEntity.NGAYDAT.Value.ToVietnameseDateFormat() : string.Empty; startTime = string.Format("{0}h{1}", bookEntity.GIOBATDAU.Value.ToString("D2"), bookEntity.PHUTBATDAU.Value.ToString("D2")); endTime = string.Format("{0}h{1}", bookEntity.GIOKETTHUC.Value.ToString("D2"), bookEntity.PHUTKETTHUC.Value.ToString("D2")); } else { result.Status = false; result.Message = "Yêu cầu đặt lịch không tồn tại"; } title = "THÔNG BÁO ĐẶT PHÒNG"; content = string.Format("Cuộc họp về \"{0}\" trong ngày {1} ({2} - {3}) được đặt tại {4}", bookEntity.MUCDICH, bookDate, startTime, endTime, roomName); SYS_TINNHANBusiness.sendMessageMultipleUsers(notifyUsers, currentUser, title, content, url, string.Empty, false, bookEntity.ID, 0); return(Json(result)); }
public JsonResult CheckBookingRoom(long bookId, int roomId) { QUANLY_PHONGHOPBusiness = Get <QUANLY_PHONGHOPBusiness>(); QUANLY_PHONGHOP bookEntity = QUANLY_PHONGHOPBusiness.Find(bookId); if (bookEntity != null && bookEntity.IS_DELETE != true) { List <QUANLY_PHONGHOP> roomBookings = QUANLY_PHONGHOPBusiness.GetBookingsOfRoomInDay(bookEntity.NGAYDAT.GetValueOrDefault(), roomId); roomBookings = roomBookings.Where(x => x.GIOBATDAU <= 12).ToList(); if (roomBookings.Any()) { int totalBookDuplicate = 0; //tổng số lịch bị trùng int totalNormalBookDuplicate = 0; //tổng số lịch thường bị trùng int totalSpecialBookDuplicate = 0; //tổng số lịch đặt biệt bị trùng List <int> duplicateIds = new List <int>(); //tính tổng số phút bắt đầu - kết thúc để tính sự trùng lặp int totalStartMinutes = bookEntity.GIOBATDAU.GetValueOrDefault() * 60 + bookEntity.PHUTBATDAU.GetValueOrDefault(); int totalEndMinutes = bookEntity.GIOKETTHUC.GetValueOrDefault() * 60 + bookEntity.PHUTKETTHUC.GetValueOrDefault(); foreach (var roomBooking in roomBookings) { bool isDuplicate = false; int totalStartMinutesDb = roomBooking.GIOBATDAU.GetValueOrDefault() * 60 + roomBooking.PHUTBATDAU.GetValueOrDefault(); int totalEndMinutesDb = roomBooking.GIOKETTHUC.GetValueOrDefault() * 60 + roomBooking.PHUTKETTHUC.GetValueOrDefault(); //kiểm tra khoảng thời gian trùng lặp if (totalStartMinutes <= totalEndMinutesDb && totalEndMinutes >= totalStartMinutesDb) { isDuplicate = true; } if (isDuplicate) { totalBookDuplicate++; if (roomBooking.USER_ID != 0) { totalSpecialBookDuplicate++; } else { totalNormalBookDuplicate++; duplicateIds.Add(roomBooking.ID); } } } if (totalBookDuplicate == 0) { return(Json(new { isDuplicate = false })); } else { return(Json(new { isDuplicate = true, totalBookDuplicate = totalBookDuplicate, totalNormalBookDuplicate = totalNormalBookDuplicate, totalSpecialBookDuplicate = totalSpecialBookDuplicate, duplicateIds = string.Join(",", duplicateIds.ToArray()) })); } } else { return(Json(new { isDuplicate = false })); } } else { return(Json(null)); } }
public JsonResult SaveRoomRequest(FormCollection fc) { AssignUserInfo(); SYS_TINNHANBusiness = Get <SYS_TINNHANBusiness>(); QUANLY_PHONGHOPBusiness = Get <QUANLY_PHONGHOPBusiness>(); DM_NGUOIDUNGBusiness = Get <DM_NGUOIDUNGBusiness>(); JsonResultBO result = new JsonResultBO(true); QUANLY_PHONGHOP entity = new QUANLY_PHONGHOP(); entity.ID = fc["ID"].ToIntOrZero(); entity.USER_ID = fc["USER_ID"].ToLongOrZero(); entity.MUCDICH = fc["MUCDICH"].Trim(); entity.THANHPHANTHAMDU = fc["THANHPHANTHAMDU"].Trim(); entity.GIOBATDAU = fc["GIOBATDAU"].ToIntOrZero(); entity.PHUTBATDAU = fc["PHUTBATDAU"].ToIntOrZero(); entity.GIOKETTHUC = fc["GIOKETTHUC"].ToIntOrZero(); entity.PHUTKETTHUC = fc["PHUTKETTHUC"].ToIntOrZero(); entity.CREATED_AT = DateTime.Now; entity.CREATED_BY = currentUser.ID; entity.NGAYDAT = fc["NGAYDAT"].ToDateTime(); entity.IS_DELETE = false; entity.CCTC_THANHPHAN_ID = currentUser.DeptParentID.GetValueOrDefault(); //danh sách người nhận thông báo đặt lịch họp List <long> notifyUsers = DM_NGUOIDUNGBusiness.GetListUsersByFunctionCodeAndDeptId("QUANLY_DAT_PHONGHOP", currentUser.DeptParentID.GetValueOrDefault()); string title = string.Empty; string content = string.Empty; string url = string.Empty; string bookDate = entity.NGAYDAT.Value.ToVietnameseDateFormat(); string startTime = string.Format("{0}h{1}", entity.GIOBATDAU.Value.ToString("D2"), entity.PHUTBATDAU.Value.ToString("D2")); string endTime = string.Format("{0}h{1}", entity.GIOKETTHUC.Value.ToString("D2"), entity.PHUTKETTHUC.Value.ToString("D2")); //kiểm tra trùng lịch lãnh đạo if (entity.USER_ID > 0) { List <QUANLY_PHONGHOP> bookingsOfUserInDay = QUANLY_PHONGHOPBusiness.GetBookingsOfUserInDay(entity.NGAYDAT.Value, entity.USER_ID); if (entity.ID > 0) { bookingsOfUserInDay = bookingsOfUserInDay.Where(x => x.ID != entity.ID).ToList(); } if (bookingsOfUserInDay.Any()) { int totalBookDuplicate = 0; //tổng số lịch bị trùng int totalStartMinutes = entity.GIOBATDAU.GetValueOrDefault() * 60 + entity.PHUTBATDAU.GetValueOrDefault(); int totalEndMinutes = entity.GIOKETTHUC.GetValueOrDefault() * 60 + entity.PHUTKETTHUC.GetValueOrDefault(); foreach (var booking in bookingsOfUserInDay) { int totalStartMinutesDb = booking.GIOBATDAU.GetValueOrDefault() * 60 + booking.PHUTBATDAU.GetValueOrDefault(); int totalEndMinutesDb = booking.GIOKETTHUC.GetValueOrDefault() * 60 + booking.PHUTKETTHUC.GetValueOrDefault(); //kiểm tra khoảng thời gian trùng lặp if (totalStartMinutes >= totalStartMinutesDb && totalStartMinutes <= totalStartMinutesDb) //giờ bắt đầu nằm trong khoảng họp { totalBookDuplicate++; } else if (totalStartMinutes <= totalStartMinutesDb && totalEndMinutes >= totalStartMinutesDb && totalEndMinutes <= totalEndMinutesDb) //giờ kết thúc nằm trong khoảng họp { totalBookDuplicate++; } else if (totalStartMinutes >= totalStartMinutesDb && totalEndMinutes <= totalStartMinutesDb) //giờ bắt đầu và giờ kết thúc đều nằm trong khoảng họp { totalBookDuplicate++; } } if (totalBookDuplicate > 0) { result.Message = string.Format("Trong ngày {0} lãnh đạo có {1} lịch diễn ra trong khoảng thời gian trên", bookDate, totalBookDuplicate); result.Status = false; return(Json(result)); } } } if (entity.ID > 0) { QUANLY_PHONGHOP dbEntity = QUANLY_PHONGHOPBusiness.Find(entity.ID); dbEntity.USER_ID = entity.USER_ID; dbEntity.MUCDICH = entity.MUCDICH; dbEntity.THANHPHANTHAMDU = entity.THANHPHANTHAMDU; dbEntity.GIOBATDAU = entity.GIOBATDAU; dbEntity.GIOKETTHUC = entity.GIOKETTHUC; dbEntity.NGAYDAT = entity.NGAYDAT; dbEntity.PHUTBATDAU = entity.PHUTBATDAU; dbEntity.PHUTKETTHUC = entity.PHUTKETTHUC; dbEntity.CCTC_THANHPHAN_ID = entity.CCTC_THANHPHAN_ID; QUANLY_PHONGHOPBusiness.Save(dbEntity); result.Message = "Cập nhật lịch họp thành công"; title = "THÔNG BÁO THAY ĐổI LỊCH HỌP"; content = string.Format("{0} đã thay đổi thông tin lịch họp vào ngày {1} lúc {2} đến {3}", currentUser.HOTEN, bookDate, startTime, endTime); } else { QUANLY_PHONGHOPBusiness.Save(entity); result.Message = "Thêm mới lịch họp thành công"; title = "THÔNG BÁO ĐẶT LỊCH HỌP"; content = string.Format("{0} đã đặt một lịch họp vào ngày {1} lúc {2} đến {3}", currentUser.HOTEN, bookDate, startTime, endTime); } //gửi tin nhắn cho người có nhiệm vụ đặt phòng SYS_TINNHANBusiness.sendMessageMultipleUsers(notifyUsers, currentUser, title, content, url, string.Empty, false, entity.ID, 0); return(Json(result)); }