/// <summary> /// Gets the plan courses. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> public DisplayPlanCourseDto GetPlanCourses(CourseListRequest request) { var response = new DisplayPlanCourseDto(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var period = unitOfWork.SchedulePeriods.FindBy(s => s.ID == request.SchedulePeriodId).SingleOrDefault(); if (period == null) { response.Successful = false; response.ErrorMessage = "Nie ma okresu rozkładu jazdy o takim identyfikatorze."; return response; } // pobiera tylko te planowane kursy które nie mają daty wykonania var courses = unitOfWork.PlanCourses.FindBy(c => c.EXECUTIONDATE == null && c.COURSE.SCHEDULEPERIODID == request.SchedulePeriodId); // Filtorwanie kursów zależne od filtra if (request.LineId != 0) { courses = courses.Where(c => c.COURSE.LINEID == request.LineId); } if (request.DayTypeId != 0) { courses = courses.Where(c => c.COURSE.DAYTYPEID.HasValue ? c.COURSE.DAYTYPEID == request.DayTypeId : false); } if (request.ExceptionId != 0) { courses = courses.Where(c => c.COURSE.EXCEPTIONID.HasValue ? c.COURSE.EXCEPTIONID == request.ExceptionId : false); } response.Objects = AutoMapper.Mapper.Map<IList<PLANCOURSE>, IList<SWKM.BLL.Dto.PlanCourseListDto>>(courses.ToList()); response.PlanningPeriod = period.PLANNINGPERIOD; response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił błąd przy wczytywaniu listy planowanych kursów."; } return response; }
/// <summary> /// Refreshes the grid. /// </summary> public void RefreshGrid() { var request = new CourseListRequest(); request.SchedulePeriodId = this.schedulePeriodCbx.SelectedValue != null ? (int)this.schedulePeriodCbx.SelectedValue : 0; request.LineId = this.lineCbx.SelectedValue != null ? (int)this.lineCbx.SelectedValue : 0; request.DayTypeId = this.dayTypeCbx.SelectedValue != null ? (int)this.dayTypeCbx.SelectedValue : 0; request.ExceptionId = this.exceptionCbx.SelectedValue != null ? (int)this.exceptionCbx.SelectedValue : 0; var stations = this.courseLogic.GetCourses(request); if (stations.Successful) { this.courseGrid.DataSource = stations.Objects; ; } else { MessageBox.Show(this, stations.ErrorMessage, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Gets the courses. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> public OperationListResponse<SWKM.BLL.Dto.CourseListDto> GetCourses(CourseListRequest request) { var response = new OperationListResponse<SWKM.BLL.Dto.CourseListDto>(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); // pobiera tylko te krusy które ne należą do usuniętych lini var courses = unitOfWork.Courses.FindBy(c => c.LINE.DELETEDDATE == null); // Filtorwanie kursów zależne od filtra if (request.SchedulePeriodId != 0) { courses = courses.Where(c => c.SCHEDULEPERIODID == request.SchedulePeriodId); } if (request.LineId != 0) { courses = courses.Where(c => c.LINEID == request.LineId); } if (request.DayTypeId != 0) { courses = courses.Where(c => c.DAYTYPEID.HasValue ? c.DAYTYPEID == request.DayTypeId : false); } if (request.ExceptionId != 0) { courses = courses.Where(c => c.EXCEPTIONID.HasValue ? c.EXCEPTIONID == request.ExceptionId : false); } response.Objects = AutoMapper.Mapper.Map<IList<COURSE>, IList<SWKM.BLL.Dto.CourseListDto>> (courses.ToList()); response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił błąd przy wczytywaniu listy kursów."; } return response; }