Esempio n. 1
0
        public ActionResult GetJobs(DateTime? day, DayViewJobSearchDTO searchModel)
        {
            bool isSuccess = true;
            StringBuilder htmlString = new StringBuilder();

            try
            {
                IJobService jobService = AutoSessionServiceFactory.GetJobService(ApplicationSetting.Current.DefaultConnectionString);
                DayViewDTO dayView = new DayViewDTO();
                dayView.day = day;
                dayView.plannedJobs = jobService.GetPlannedDayViewJobs(day.Value, searchModel).ToList();
                dayView.unplannedJobs = jobService.GetUnplannedDayViewJobs(day.Value).ToList();
                int? maxColumn = dayView.plannedJobs.Select(j => j.column).Max();
                ViewBag.MaxColumn = maxColumn.HasValue ? maxColumn.Value : 0;
                htmlString.Append(this.RenderPartialViewToString(string.Format(ViewPath, "Calendar"), dayView));
            }
            catch(Exception)
            {
                isSuccess = false;
            }

            return Json(
               new
               {
                   isSuccess = isSuccess,
                   sHtmlResult = htmlString.ToString()
               });
        }
Esempio n. 2
0
        public IEnumerable<DayViewJobDTO> GetPlannedDayViewJobs(DateTime day, DayViewJobSearchDTO searchModel)
        {
            IEnumerable<DayViewJobDTO> records = null;

            using (var ds = new DataService(this.connectionString, this.consumerInfo))
            {
                TimeSpan zeroTimeSpan = new TimeSpan(0, 0, 0);
                List<CrmtJob> jobList = (from j in ds.CrmtJob.GetAll()
                                         where (j.dCompletionDate.HasValue && j.tActualStartTime.HasValue && j.tActualEndTime.HasValue && j.dCompletionDate == day) ||
                                         (!(j.dCompletionDate.HasValue && j.tActualStartTime.HasValue && j.tActualEndTime.HasValue) && j.dRepairDate == day && j.tStartTime.HasValue && j.tEndTime.HasValue && (j.tStartTime != zeroTimeSpan && j.tEndTime != zeroTimeSpan))
                                         select j).ToList();
                records = (from j in jobList
                           //orderby j.tStartTime, j.tEndTime
                           select new DayViewJobDTO
                           {
                               nID = j.nID,
                               sCustomerCode = j.sCustomerCode,
                               sCustomerName = j.sCustomerName,
                               dRepairDate = j.isCompleted ? j.dCompletionDate : j.dRepairDate,
                               tStartTime = j.isCompleted ? j.tActualStartTime : j.tStartTime,
                               tEndTime = j.isCompleted ? j.tActualEndTime : j.tEndTime,
                               nStatus = j.jobStatus,
                               bIsEcall = j.bIsEcall,
                               nTechnician1ID = j.nTechnician1ID,
                               nTechnician2ID = j.nTechnician2ID,
                               nTechnician3ID = j.nTechnician3ID,
                               nTechnician4ID = j.nTechnician4ID
                           }).ToList();
                records = records.OrderBy(r => r.tStartTime).ThenBy(r => r.tEndTime).ToList();

                foreach (DayViewJobDTO job in records)
                {
                    #region Get Technician
                    job.technicians = new List<JobTechnicianDTO>();
                    JobTechnicianDTO technician = new JobTechnicianDTO();
                    if (job.nTechnician1ID.HasValue)
                    {
                        technician.nID = job.nTechnician1ID.Value;
                        job.technicians.Add(technician);
                    }
                    if (job.nTechnician2ID.HasValue)
                    {
                        technician = new JobTechnicianDTO();
                        technician.nID = job.nTechnician2ID.Value;
                        job.technicians.Add(technician);
                    }
                    if (job.nTechnician3ID.HasValue)
                    {
                        technician = new JobTechnicianDTO();
                        technician.nID = job.nTechnician3ID.Value;
                        job.technicians.Add(technician);
                    }
                    if (job.nTechnician4ID.HasValue)
                    {
                        technician = new JobTechnicianDTO();
                        technician.nID = job.nTechnician4ID.Value;
                        job.technicians.Add(technician);
                    }
                    foreach (JobTechnicianDTO jobTechnician in job.technicians)
                    {
                        CrmmTechnician crmmTechnician = (from t in ds.CrmmTechnician.GetAll()
                                                         where t.nID == jobTechnician.nID
                                                         select t).FirstOrDefault();
                        if (crmmTechnician != null)
                        {
                            jobTechnician.sName = crmmTechnician.sName;
                            jobTechnician.bIsLeave = crmmTechnician.isLeave(job.dRepairDate, job.tStartTime, job.tEndTime);
                        }
                    }
                    #endregion Get Technician
                }

                #region Filtering
                if (searchModel != null)
                {
                    if (!string.IsNullOrWhiteSpace(searchModel.sCustomerCodeFilter))
                    {
                        records = records.Where(j => j.sCustomerCode.ToLower().Contains(searchModel.sCustomerCodeFilter.ToLower().Trim()));
                    }
                    if (!string.IsNullOrWhiteSpace(searchModel.sTechnicianNameFilter))
                    {
                        records = records.Where(j => j.technicians.Any(t => t.sName.ToLower().Contains(searchModel.sTechnicianNameFilter.ToLower().Trim())));
                    }
                    if (searchModel.nIsEcallFilter == 1) records = records.Where(j => j.bIsEcall == true);
                    else if (searchModel.nIsEcallFilter == 0) records = records.Where(j => j.bIsEcall == false);
                }

                #endregion Filtering

                foreach (DayViewJobDTO job in records)
                {
                    #region Get column index
                    job.calculatedStartTime = job.tStartTime;
                    job.calculatedEndTime = job.tEndTime;
                    if (job.tStartTime < TimeSpan.FromHours(8))
                    {
                        job.calculatedStartTime = new TimeSpan(8, 0, 0);
                    }
                    else if (job.tStartTime >= TimeSpan.FromHours(18))
                    {
                        job.calculatedStartTime = new TimeSpan(18, 0, 0);
                        job.calculatedEndTime = new TimeSpan(19, 0, 0);
                    }
                    if (job.tEndTime > TimeSpan.FromHours(18))
                    {
                        job.calculatedEndTime = new TimeSpan(19, 0, 0);
                    }

                    var previousJobs = records.Where(r => r.calculatedStartTime.HasValue && r.calculatedEndTime.HasValue && job.calculatedEndTime > r.calculatedStartTime && job.calculatedStartTime < r.calculatedEndTime && r.column.HasValue).OrderBy(r => r.column).ToList();
                    int jobCount = previousJobs.Count();
                    if (jobCount > 0)
                    {
                        int lastColumnIndex = 0;
                        for (int i = 0; i < jobCount; i++)
                        {
                            int columnIndex = previousJobs.ElementAt(i).column.Value;
                            if (i == 0 && columnIndex != 0)
                            {
                                job.column = 0;
                                break;
                            }
                            if (i != 0)
                            {
                                if (lastColumnIndex + 1 != columnIndex)
                                {
                                    job.column = lastColumnIndex + 1;
                                    break;
                                }
                            }
                            lastColumnIndex = columnIndex;
                            continue;
                        }
                        if (!job.column.HasValue) job.column = lastColumnIndex + 1;
                    }
                    else
                    {
                        job.column = 0;
                    }
                    #endregion Get column index

                    #region Get height and top
                    double minuteDiff = job.calculatedEndTime.Value.Subtract(job.calculatedStartTime.Value).TotalMinutes;
                    job.height = (int)(minuteDiff / 60 * 61);
                    job.top = (int)(job.calculatedStartTime.Value.Subtract(TimeSpan.FromHours(8)).TotalMinutes / 60 * 61);
                    #endregion Get height and top
                }

                return records.ToList();
            }
        }