123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using EMIS.DataLogic.Common.CalendarManage;
- using Bowin.Common.Linq.Entity;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using System.Linq.Expressions;
- using EMIS.ViewModel.CalendarManage;
- namespace EMIS.CommonLogic.CalendarManage
- {
- public class CoursesTimeServices : BaseServices, ICoursesTimeServices
- {
- public CoursesTimeDAL coursesTimeDAL { get; set; }
- public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
- /// <summary>
- /// 查询课程时间信息
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="timesSegment">时间段</param>
- /// <param name="pageIndex">页码</param>
- /// <param name="pageSize">显示页数</param>
- /// <returns></returns>
- public IGridResultSet<CoursesTimeView> GetCoursesTimeViewGrid(ConfiguretView configuretView, int? timesSegment, int pageIndex, int pageSize)
- {
- var query = coursesTimeDAL.GetCoursesTimeQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (timesSegment.HasValue && timesSegment != -1)
- query = query.Where(x => x.TimesSegment == timesSegment);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.CreateTime).ToGridResultSet<CoursesTimeView>(pageIndex, pageSize);
- return query.OrderBy(x => x.StartTimes).ToGridResultSet<CoursesTimeView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询课程时间信息
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="timesSegment">时间段</param>
- /// <returns></returns>
- public List<CoursesTimeView> GetCoursesTimeViewList(ConfiguretView configuretView, int? timesSegment)
- {
- var query = coursesTimeDAL.GetCoursesTimeQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (timesSegment.HasValue && timesSegment != -1)
- query = query.Where(x => x.TimesSegment == timesSegment);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.CreateTime).ToList();
- return query.OrderBy(x => x.StartTimes).ToList();
- }
- /// <summary>
- /// 查询课程时间信息
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="timesSegment">时间段</param>
- /// <returns></returns>
- public List<CoursesTimeView> GetCoursesTimeViewFutureList(int? weekNum, int? weekday)
- {
- var currentSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
- var query = coursesTimeDAL.GetCoursesTimeQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- var result = query.OrderBy(x => x.StartTimes).ToList();
- result = result.Where(x => !this.SchoolYearServices.Value.IsTimePassed(currentSchoolyear, weekNum, weekday, x.StartHour, x.StartMinutes))
- .ToList();
- return result;
- }
- /// <summary>
- /// 获取课程时间信息
- /// </summary>
- /// <param name="coursesTimeID">主键ID</param>
- /// <returns></returns>
- public EM_CoursesTime GetCoursesTime(Guid? coursesTimeID)
- {
- //查询条件
- Expression<Func<EM_CoursesTime, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- expression = (x => x.CoursesTimeID == coursesTimeID);
- return coursesTimeDAL.coursesTimeRepository.GetSingle(expression);
- }
- /// <summary>
- /// 获取下一堂课程时间信息
- /// </summary>
- /// <param name="coursesTimeID">主键ID</param>
- /// <returns></returns>
- public CoursesTimeView GetNextCoursesTime(Guid? coursesTimeID)
- {
- //查询条件
- Expression<Func<EM_CoursesTime, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- expression = (x => x.CoursesTimeID == coursesTimeID);
- return coursesTimeDAL.GetNextCoursesTimeQueryable(expression).FirstOrDefault();
- }
- /// <summary>
- /// 获取课程时间信息
- /// </summary>
- /// <param name="coursesTimeID">主键ID</param>
- /// <returns></returns>
- public CoursesTimeView GetCoursesTimeView(Guid? coursesTimeID)
- {
- CoursesTimeView coursesTimeView = new CoursesTimeView();
- if (coursesTimeID.HasValue)
- coursesTimeView = coursesTimeDAL.GetCoursesTimeQueryable(x => true).Where(x => x.CoursesTimeID == coursesTimeID).FirstOrDefault();
- return coursesTimeView;
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="coursesTime">实体</param>
- /// <returns></returns>
- public bool CoursesTimeAdd(CoursesTimeView coursesTimeView)
- {
- try
- {
- if (this.coursesTimeDAL.coursesTimeRepository
- .GetList(x => x.EndTimes >= coursesTimeView.StartTimes && x.StartTimes <= coursesTimeView.EndTimes
- && x.RecordStatus > (int)SYS_STATUS.UNUSABLE).Count() > 0)
- {
- throw new Exception("节次已存在,请重新输入!");
- }
- EM_CoursesTime coursesTime = new EM_CoursesTime();
- coursesTime.CoursesTimeID = Guid.NewGuid();
- coursesTime.StartTimes = coursesTimeView.StartTimes.Value;
- coursesTime.EndTimes = coursesTimeView.EndTimes.Value;
- coursesTime.TimesSegment = coursesTimeView.TimesSegment.Value;
- coursesTime.StartHour = coursesTimeView.StartHour.Value;
- coursesTime.StartMinutes = coursesTimeView.StartMinutes.Value;
- coursesTime.EndHour = coursesTimeView.EndHour.Value;
- coursesTime.EndMinutes = coursesTimeView.EndMinutes.Value;
- this.SetNewStatus(coursesTime);
- UnitOfWork.Add(coursesTime);
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 修改
- /// </summary>
- /// <param name="coursesTime">实体</param>
- /// <returns></returns>
- public bool CoursesTimeUpdate(CoursesTimeView coursesTimeView)
- {
- try
- {
- if (this.coursesTimeDAL.coursesTimeRepository
- .GetList(x => x.EndTimes >= coursesTimeView.StartTimes && x.StartTimes <= coursesTimeView.EndTimes
- && x.RecordStatus > (int)SYS_STATUS.UNUSABLE
- && x.CoursesTimeID != coursesTimeView.CoursesTimeID).Count() > 0)
- {
- throw new Exception("节次已存在,请重新输入!");
- }
- EM_CoursesTime coursesTime = GetCoursesTime(coursesTimeView.CoursesTimeID);
- if (coursesTime == null)
- {
- throw new Exception("保存失败,未能找到相对应的数据!");
- }
- coursesTime.StartTimes = coursesTimeView.StartTimes.Value;
- coursesTime.EndTimes = coursesTimeView.EndTimes.Value;
- coursesTime.TimesSegment = coursesTimeView.TimesSegment.Value;
- coursesTime.StartHour = coursesTimeView.StartHour.Value;
- coursesTime.StartMinutes = coursesTimeView.StartMinutes.Value;
- coursesTime.EndHour = coursesTimeView.EndHour.Value;
- coursesTime.EndMinutes = coursesTimeView.EndMinutes.Value;
- this.SetModifyStatus(coursesTime);
- UnitOfWork.Update(coursesTime);
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="coursesTimeIDs"></param>
- /// <returns></returns>
- public bool CoursesTimeDelete(List<Guid> coursesTimeIDs)
- {
- try
- {
- UnitOfWork.Update<EM_CoursesTime>((x => new EM_CoursesTime { RecordStatus = (int)SYS_STATUS.UNUSABLE }), x => coursesTimeIDs.Contains(x.CoursesTimeID));
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
|