Beispiel #1
0
        public JsonResult SendEmail(FormCollection fc)
        {
            JsonResultBO result = new JsonResultBO(false);

            lichCongTacBusiness = Get <LICHCONGTACBusiness>();
            dmNguoiDungBusiness = Get <DM_NGUOIDUNGBusiness>();

            DateTime           currentDate = DateTime.Now;
            var                startOfWeek = currentDate.GetStartDayOfWeek();
            var                endOfWeek   = currentDate.GetEndDayOfWeek();
            LICHCONGTAC_SEARCH searchModel = new LICHCONGTAC_SEARCH();

            searchModel.startDate = startOfWeek;
            searchModel.endDate   = endOfWeek;
            List <long> userIds = fc["LANHDAO_ID"].ToListLong(',');
            string      subject = fc["TIEUDE"].Trim();

            string emailTemplatePath = Path.Combine(ConfigurationManager.AppSettings["FileUpload"], ConfigurationManager.AppSettings["LichCongTacEmailTemplate"]);
            string emailContent      = System.IO.File.ReadAllText(emailTemplatePath);

            foreach (var item in userIds)
            {
                DM_NGUOIDUNG user = dmNguoiDungBusiness.Find(item);
                if (user != null && string.IsNullOrEmpty(user.EMAIL) == false)
                {
                    searchModel.leaderId = user.ID;
                    List <LICHCONGTAC_BO> calendars        = lichCongTacBusiness.GetListLichCongTacs(searchModel);
                    List <LICHCONGTAC_BO> deletedCalendars = lichCongTacBusiness.GetListDeletedLichCongTacs(searchModel);
                    emailContent = emailContent.Replace("[[recipient]]", user.HOTEN);
                    emailContent = emailContent.Replace("[[week_header_title]]", currentDate.GetWeekNumber() + " (từ ngày " + startOfWeek.ToVietnameseDateFormat() + " đến ngày " + endOfWeek.ToVietnameseDateFormat() + ")");
                    emailContent = emailContent.Replace("[[week_title]]", currentDate.GetNameOfWeek() + " năm " + currentDate.Year);
                    emailContent = emailContent.Replace("[[week_start_end_date_title]]", currentDate.GetNameOfWeek() +
                                                        " (" + startOfWeek.GetNameOfDay() + ", "
                                                        + startOfWeek.ToVietnameseDateFormat() + " - "
                                                        + endOfWeek.GetNameOfDay() + ", "
                                                        + endOfWeek.ToVietnameseDateFormat() + ")");
                    emailContent = emailContent.Replace("[[email_main_content]]", this.GenerateLichCongTacEmailContent(calendars));
                    emailContent = emailContent.Replace("[[email_error_content]]", this.GenerateLichCongTacDeleteEmailContent(deletedCalendars));
                    List <string> address = new List <string>()
                    {
                        user.EMAIL
                    };
                    EmailProvider.sendEmail(emailContent, subject, address);
                }
            }
            result.Status = true;
            return(Json(result));
        }
Beispiel #2
0
        public PartialViewResult GetCalendarToRegisterCar(FormCollection collection)
        {
            lichCongTacBusiness = Get <LICHCONGTACBusiness>();
            LICHCONGTAC_SEARCH searchModel = new LICHCONGTAC_SEARCH();

            searchModel.leaderId  = collection["CAL_LANHDAO_ID"].ToIntOrNULL();
            searchModel.startDate = collection["CAL_NGAYBATDAU"].ToDateTime();
            searchModel.endDate   = collection["CAL_NGAYKETTHUC"].ToDateTime();
            LichCongTacByDayViewModel viewModel = new LichCongTacByDayViewModel();

            viewModel.groupDateEntities = lichCongTacBusiness.GetListLichCongTacs(searchModel)
                                          .GroupBy(x => x.NGAY_CONGTAC).OrderBy(x => x.Key)
                                          .Select(x => new LichCongTacDateEntity()
            {
                title            = x.Key.GetNameOfDay() + " (" + x.Key.ToVietnameseDateFormat() + ")",
                groupOfCalendars = x.OrderBy(y => y.GIO_CONGTAC).ThenBy(y => y.PHUT_CONGTAC).ToList()
            }).ToList();
            return(PartialView("_ListLichCongTacRegisterCar", viewModel));
        }
Beispiel #3
0
        public PartialViewResult SearchLichCongTac(LICHCONGTAC_SEARCH searchModel)
        {
            AssignUserInfo();
            lichCongTacBusiness = Get <LICHCONGTACBusiness>();
            DM_THAOTAC userFunction = currentUser.ListThaoTac.Where(o => o.MA_THAOTAC.ToUpper() == "TAO_LICHCONGTAC").FirstOrDefault();

            searchModel.queryDeptId = currentUser.DeptParentID;
            if (searchModel.calendarDay == null)
            {
                searchModel.calendarDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            }
            else
            {
                var calendarDayValue = searchModel.calendarDay.Value;
                searchModel.calendarDay = new DateTime(calendarDayValue.Year, calendarDayValue.Month, calendarDayValue.Day);
            }
            var currentDay   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            var day          = searchModel.calendarDay.Value;
            var groupOfYears = lichCongTacBusiness.GetListYears(day);
            var groupOfWeeks = Enumerable.Range(1, 52).Select(w => new SelectListItem()
            {
                Value    = w.ToString(),
                Text     = "Tuần " + w,
                Selected = (day.GetWeekNumber() == w)
            }).ToList();
            var groupOfMonths = Enumerable.Range(1, 12).Select(m => new SelectListItem()
            {
                Value    = m.ToString(),
                Text     = "Tháng " + m,
                Selected = (day.Month == m)
            }).ToList();

            if (searchModel.calendarType == LICH_CONSTANT.NGAY)
            {
                //nếu người dùng tìm kiếm không nhập ngày bắt đầu và kết thúc mặc định lấy của tuần này
                if (searchModel.startDate == null && searchModel.endDate == null)
                {
                    searchModel.startDate = day.GetStartDayOfWeek();
                    searchModel.endDate   = day.GetEndDayOfWeek();
                }
                LichCongTacByDayViewModel viewModel = new LichCongTacByDayViewModel();
                viewModel.currentUserId     = currentUser.ID;
                viewModel.startDate         = searchModel.startDate;
                viewModel.endDate           = searchModel.endDate;
                viewModel.groupOfYears      = groupOfYears;
                viewModel.title             = "Từ " + string.Format("{0:dd/MM/yyyy}", searchModel.startDate) + " đến " + string.Format("{0:dd/MM/yyyy}", searchModel.endDate);
                viewModel.groupDateEntities = lichCongTacBusiness.GetListLichCongTacs(searchModel)
                                              .GroupBy(x => x.NGAY_CONGTAC).OrderBy(x => x.Key)
                                              .Select(x => new LichCongTacDateEntity()
                {
                    title            = x.Key.GetNameOfDay() + " (" + x.Key.ToVietnameseDateFormat() + ")",
                    isToday          = x.Key.Equals(currentDay),
                    groupOfCalendars = x.OrderBy(y => y.GIO_CONGTAC).ThenBy(y => y.PHUT_CONGTAC).ToList()
                }).ToList();
                return(PartialView("_ListLichCongTacByDayOfWeek", viewModel));
            }
            else if (searchModel.calendarType == LICH_CONSTANT.TUAN)
            {
                LichCongTacByWeekViewModel viewModel = new LichCongTacByWeekViewModel();
                var startOfWeek = day.GetStartDayOfWeek();
                var endOfWeek   = day.GetEndDayOfWeek();
                viewModel.currentUserId = currentUser.ID;
                viewModel.canCreate     = (userFunction != null && userFunction.DM_THAOTAC_ID > 0);
                viewModel.title         = day.GetNameOfWeek() + " (" + startOfWeek.GetNameOfDay() + ", " + startOfWeek.ToVietnameseDateFormat() + " - " + endOfWeek.GetNameOfDay() + ", " + endOfWeek.ToVietnameseDateFormat() + ")";
                viewModel.groupOfYears  = groupOfYears;
                viewModel.groupOfWeeks  = groupOfWeeks;

                searchModel.startDate = startOfWeek;
                searchModel.endDate   = endOfWeek;
                List <LICHCONGTAC_BO> calendars = lichCongTacBusiness.GetListLichCongTacs(searchModel);

                //lấy các ngày trong tuần
                viewModel.groupOfDates = new List <DateTime>();
                for (var d = startOfWeek; d <= endOfWeek; d = d.AddDays(1))
                {
                    viewModel.groupOfDates.Add(d);
                }

                //lấy lịch theo từng khung giờ theo từng ngày
                viewModel.groupWeekHourEntities = new List <LichCongTacByWeekHourEntity>();
                for (int h = 0; h <= 23; h++)
                {
                    LichCongTacByWeekHourEntity hourEntity = new LichCongTacByWeekHourEntity();
                    hourEntity.title             = h.ToString("D2") + "h";
                    hourEntity.hour              = h;
                    hourEntity.groupDateEntities = new List <LichCongTacDateEntity>();
                    for (var d = startOfWeek; d <= endOfWeek; d = d.AddDays(1))
                    {
                        LichCongTacDateEntity hourDateEntity = new LichCongTacDateEntity();
                        hourDateEntity.date             = d;
                        hourDateEntity.groupOfCalendars = new List <LICHCONGTAC_BO>();
                        hourDateEntity.groupOfCalendars.AddRange(calendars
                                                                 .Where(x => x.NGAY_CONGTAC.Day == d.Day && x.GIO_CONGTAC == h)
                                                                 .OrderBy(x => x.GIO_CONGTAC).ThenBy(x => x.PHUT_CONGTAC).ToList());
                        hourDateEntity.isToday = (d.Equals(currentDay));
                        hourEntity.groupDateEntities.Add(hourDateEntity);
                    }
                    viewModel.groupWeekHourEntities.Add(hourEntity);
                }
                return(PartialView("_ListLichCongTacByWeek", viewModel));
            }
            else
            {
                LichCongTacByMonthViewModel viewModel = new LichCongTacByMonthViewModel();
                viewModel.currentUserId = currentUser.ID;
                viewModel.canCreate     = (userFunction != null && userFunction.DM_THAOTAC_ID > 0);
                viewModel.year          = day.Year;
                viewModel.month         = day.Month;
                viewModel.title         = "Tháng " + day.Month + ", năm " + day.Year;
                viewModel.groupOfYears  = groupOfYears;
                viewModel.groupOfMonths = groupOfMonths;

                //lấy ngày đầu tiên và cuối cùng trong tháng
                int lastDayInMonth = DateTime.DaysInMonth(day.Year, day.Month);
                searchModel.startDate = (new DateTime(day.Year, day.Month, 1));
                searchModel.endDate   = (new DateTime(day.Year, day.Month, lastDayInMonth));
                List <LICHCONGTAC_BO> calendars = lichCongTacBusiness.GetListLichCongTacs(searchModel);

                List <DateTime> datesOfMonth = Enumerable.Range(1, lastDayInMonth)
                                               .Select(x => new DateTime(day.Year, day.Month, x)).ToList();
                DateTime defaultDate = new DateTime(1, 1, 1);

                viewModel.groupWeekEntities = new List <LichCongTacByMonthWeekEntity>();
                for (int w = 1; w <= 6; w++)
                {
                    LichCongTacByMonthWeekEntity weekEntity = new LichCongTacByMonthWeekEntity();
                    List <DateTime> daysOfWeek = datesOfMonth.Where(x => x.GetWeekOfMonth() == w).ToList();
                    if (daysOfWeek.Any())
                    {
                        weekEntity.groupDateEntities = new List <LichCongTacDateEntity>();
                        for (int d = (int)DayOfWeek.Sunday; d <= (int)DayOfWeek.Saturday; d++)
                        {
                            DateTime weekDay = daysOfWeek.Where(x => (int)x.DayOfWeek == d).FirstOrDefault();
                            LichCongTacDateEntity dateEntity = new LichCongTacDateEntity();
                            if (weekDay != defaultDate)
                            {
                                dateEntity.isToday          = weekDay.Equals(currentDay);
                                dateEntity.date             = weekDay;
                                dateEntity.title            = weekDay.Day.ToString();
                                dateEntity.groupOfCalendars = calendars.Where(x => x.NGAY_CONGTAC.Day == weekDay.Day)
                                                              .OrderBy(x => x.GIO_CONGTAC)
                                                              .ThenBy(x => x.PHUT_CONGTAC)
                                                              .ToList();
                            }
                            weekEntity.groupDateEntities.Add(dateEntity);
                        }
                        viewModel.groupWeekEntities.Add(weekEntity);
                    }
                }
                return(PartialView("_ListLichCongTacByMonth", viewModel));
            }
        }