Ejemplo n.º 1
0
        public ActionResult DisplayCalendar(DateTime? day, MonthViewJobSearchDTO searchModel)
        {
            bool isSuccess = true;
            StringBuilder htmlString = new StringBuilder();
            List<MonthViewDayDTO> monthViewDayList = null;

            try
            {
                if (!day.HasValue) day = DateTime.Today;
                int month = day.Value.Month;
                int year = day.Value.Year;

                #region Calculate Date Range of the Calendar
                DateTime monthYear = new DateTime(year, month, 1);
                DateTime firstDate = monthYear.AddDays(-1 * (int)monthYear.DayOfWeek);
                DateTime lastDateOfTheMonth = monthYear.AddMonths(1).AddDays(-1);
                int days = 6 - (int)(lastDateOfTheMonth).DayOfWeek;
                DateTime endDate = lastDateOfTheMonth.AddDays(days);
                #endregion Calculate Date Range of the Calendar

                IJobService jobService = AutoSessionServiceFactory.GetJobService(ApplicationSetting.Current.DefaultConnectionString);
                //if (jobService.GetMonthViewDays(firstDate, endDate, searchModel) != null)
                    monthViewDayList = jobService.GetMonthViewDays(firstDate, endDate, searchModel);

                ViewBag.MonthShortString = day.Value.ToString("MMM");
                ViewBag.nextMonthShortString = day.Value.AddMonths(1).ToString("MMM");
                ViewBag.Month = month;
                ViewBag.Year = year;
                htmlString.Append(this.RenderPartialViewToString(string.Format(ViewPath, "Calendar"), monthViewDayList));
            }
            catch
            {
                isSuccess = false;
            }

            return Json(
               new
               {
                   isSuccess = isSuccess,
                   sHtmlResult = htmlString.ToString()
               });
        }
Ejemplo n.º 2
0
        public List<MonthViewDayDTO> GetMonthViewDays(DateTime startDate, DateTime endDate, MonthViewJobSearchDTO searchModel)
        {
            List<MonthViewDayDTO> records = new List<MonthViewDayDTO>();

            DateTime currentDate = startDate;
            using (var ds = new DataService(this.connectionString, this.consumerInfo))
            {
                var holidays = ds.CrmmHoliday.GetAll().Where(h => h.nStatus == 1 && h.dDate >= startDate && h.dDate <= endDate).Select(h => h.dDate).ToList();

                List<CrmtJob> jobList = ds.CrmtJob.GetAll().Where(j => (j.dCompletionDate.HasValue && j.tActualStartTime.HasValue && j.tActualEndTime.HasValue && j.dCompletionDate >= startDate && j.dCompletionDate <= endDate) || (!(j.dCompletionDate.HasValue && j.tActualStartTime.HasValue && j.tActualEndTime.HasValue) && j.dRepairDate >= startDate && j.dRepairDate <= endDate)).ToList();

                #region Filtering
                if (searchModel != null)
                {
                    if (!string.IsNullOrWhiteSpace(searchModel.sCustomerCodeFilter))
                    {
                        jobList = jobList.Where(j => j.sCustomerCode.ToLower().Contains(searchModel.sCustomerCodeFilter.ToLower().Trim())).ToList();
                    }
                    if (!string.IsNullOrWhiteSpace(searchModel.sTechnicianNameFilter))
                    {
                        jobList = jobList.Where(j => j.Technician1 != null && j.Technician1.sName.ToLower().Contains(searchModel.sTechnicianNameFilter.ToLower().Trim())
                                                || (j.Technician2 != null && j.Technician2.sName.ToLower().Contains(searchModel.sTechnicianNameFilter.ToLower().Trim()))
                                                || (j.Technician3 != null && j.Technician3.sName.ToLower().Contains(searchModel.sTechnicianNameFilter.ToLower().Trim()))
                                                || (j.Technician4 != null && j.Technician4.sName.ToLower().Contains(searchModel.sTechnicianNameFilter.ToLower().Trim()))
                                                ).ToList();
                    }
                    if (searchModel.nIsEcallFilter == 1) jobList = jobList.Where(j => j.bIsEcall == true).ToList();
                    else if (searchModel.nIsEcallFilter == 0) jobList = jobList.Where(j => j.bIsEcall == false).ToList();
                }
                #endregion Filtering

                IEnumerable<MonthViewJobDTO> monthViewJobList = (from j in jobList
                                    orderby j.jobStatus
                                    select new MonthViewJobDTO
                                    {
                                        sCustomerCode = j.sCustomerCode,
                                        nStatus = j.jobStatus,
                                        nTechnician1ID = j.nTechnician1ID,
                                        nTechnician2ID = j.nTechnician2ID,
                                        nTechnician3ID = j.nTechnician3ID,
                                        nTechnician4ID = j.nTechnician4ID,
                                        jobDate = j.dCompletionDate.HasValue? j.dCompletionDate.Value : j.dRepairDate.Value
                                    });

                while (currentDate <= endDate)
                {
                    IEnumerable<MonthViewJobDTO> monthViewCurrentDayJobList = monthViewJobList.Where(j => j.jobDate == currentDate);

                    int jobCount = monthViewCurrentDayJobList.Count();

                    MonthViewDayDTO monthViewDay = new MonthViewDayDTO
                    {
                        nMonth = currentDate.Month,
                        nDay = currentDate.Day,
                        dateString = currentDate.ToString("yyyy-MM-dd"),
                        bIsHoliday = holidays.Contains(currentDate),
                        monthViewJobList = monthViewCurrentDayJobList.Take(5).ToList(),
                        nJobCount = jobCount
                    };
                    records.Add(monthViewDay);
                    currentDate = currentDate.AddDays(1);
                }
            }
            return records;
        }