using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.DataLogic.SelectCourse; using System.Linq.Expressions; using EMIS.Entities; namespace EMIS.CommonLogic.SelectCourse { public class TypeSettingServices : BaseServices, ITypeSettingServices { public TypeSettingDAL TypeSettingDAL { get; set; } public Bowin.Common.Linq.Entity.IGridResultSet GetTypeSettingViewList( ViewModel.ConfiguretView configuretView, Guid? schoolYearID, int? selectCourseTypeID, int? recordStatus, int pageIndex, int pageSize) { Expression> typeSettingExp = (x => true); Expression> schoolYearExp = (x => true); if (schoolYearID.HasValue) { typeSettingExp = typeSettingExp.And(x => x.SchoolyearID == schoolYearID.Value); } if (selectCourseTypeID.HasValue) { typeSettingExp = typeSettingExp.And(x => x.SelectCourseTypeID == selectCourseTypeID.Value); } if (recordStatus.HasValue) { typeSettingExp = typeSettingExp.And(x => x.RecordStatus == recordStatus.Value); } IQueryable q = TypeSettingDAL.GetTypeSettingView(typeSettingExp, schoolYearExp) .OrderByDescending(x => x.SchoolyearCode); if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute)) q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return q.ToGridResultSet(pageIndex, pageSize); } public IList GetTypeSettingViewList(ViewModel.ConfiguretView configuretView, Guid? schoolYearID, int? selectCourseTypeID, int? recordStatus) { Expression> typeSettingExp = (x => true); Expression> schoolYearExp = (x => true); if (schoolYearID.HasValue) { typeSettingExp = typeSettingExp.And(x => x.SchoolyearID == schoolYearID.Value); } if (selectCourseTypeID.HasValue) { typeSettingExp = typeSettingExp.And(x => x.SelectCourseTypeID == selectCourseTypeID.Value); } if (recordStatus.HasValue) { typeSettingExp = typeSettingExp.And(x => x.RecordStatus == recordStatus.Value); } IQueryable q = TypeSettingDAL.GetTypeSettingView(typeSettingExp, schoolYearExp) .OrderByDescending(x => x.SchoolyearCode); if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute)) q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return q.ToList(); } public ViewModel.SelectCourse.SelectCourseTypeSettingView GetTypeSettingViewInfo(Guid? typeSettingID) { return TypeSettingDAL.GetTypeSettingView((x => x.SelectCourseTypeSettingID == typeSettingID), (x => true)).FirstOrDefault(); } public void Save(ViewModel.SelectCourse.SelectCourseTypeSettingView typeSetting) { var dupSettingList = TypeSettingDAL.SelectCourseTypeSettingRepository .GetList(x => x.SchoolyearID == typeSetting.SchoolyearID && x.SelectCourseTypeID == typeSetting.SelectCourseTypeID && x.EndTime >= typeSetting.StartTime && x.StartTime <= typeSetting.EndTime && x.SelectCourseTypeSettingID != typeSetting.SelectCourseTypeSettingID).ToList(); var typeSettingEntity = TypeSettingDAL.SelectCourseTypeSettingRepository .GetSingle(x => x.SelectCourseTypeSettingID == typeSetting.SelectCourseTypeSettingID); if (typeSettingEntity != null) { if (dupSettingList.Count > 0) { throw new Exception("在同一学年学期的有效时间内存在重复的类型设定,不能保存。"); } typeSettingEntity.SchoolyearID = typeSetting.SchoolyearID; typeSettingEntity.SelectCourseTypeID = typeSetting.SelectCourseTypeID; typeSettingEntity.StartTime = typeSetting.StartTime; typeSettingEntity.EndTime = typeSetting.EndTime; typeSettingEntity.MaxSelectCount = typeSetting.MaxSelectCount; typeSettingEntity.MinSelectCount = typeSetting.MinSelectCount; typeSettingEntity.MaxCredit = typeSetting.MaxCredit; typeSettingEntity.MinCredit = typeSetting.MinCredit; typeSettingEntity.Remark = typeSetting.Remark; this.SetModifyStatus(typeSettingEntity); } else { if (dupSettingList.Count > 0) { throw new Exception("在同一学年学期的有效时间内存在重复的类型设定,不能添加。"); } typeSettingEntity = new EM_SelectCourseTypeSetting(); typeSettingEntity.SelectCourseTypeSettingID = Guid.NewGuid(); typeSettingEntity.SchoolyearID = typeSetting.SchoolyearID; typeSettingEntity.SelectCourseTypeID = typeSetting.SelectCourseTypeID; typeSettingEntity.StartTime = typeSetting.StartTime; typeSettingEntity.EndTime = typeSetting.EndTime; typeSettingEntity.MaxSelectCount = typeSetting.MaxSelectCount; typeSettingEntity.MinSelectCount = typeSetting.MinSelectCount; typeSettingEntity.MaxCredit = typeSetting.MaxCredit; typeSettingEntity.MinCredit = typeSetting.MinCredit; typeSettingEntity.Remark = typeSetting.Remark; this.SetNewStatus(typeSettingEntity); UnitOfWork.Add(typeSettingEntity); } UnitOfWork.Commit(); } public void Delete(IList typeSettingIDList) { if (typeSettingIDList.Count > 0) { UnitOfWork.Delete(x => typeSettingIDList.Contains(x.SelectCourseTypeSettingID)); } } } }