using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.ViewModel; using EMIS.DataLogic.GraduationManage.GraduationSetting; using EMIS.CommonLogic.SystemServices; using EMIS.ViewModel.GraduationManage.GraduationSetting; namespace EMIS.CommonLogic.GraduationManage.GraduationSetting { public class GraduationSchoolYearServices: BaseServices, IGraduationSchoolYearServices { public GraduationSchoolYearDAL GraduationSchoolYearDAL { get; set; } public Lazy ParameterServices { get; set; } /// /// 查询毕业学期信息View /// /// /// /// /// /// /// /// /// public IGridResultSet GetGradSchoolYearViewGrid(ConfiguretView configuretView, int? years, int? schoolcodeID, int? isCurrent, int? isEnable, int pageIndex, int pageSize) { //查询设置的毕业学期Value var graduatingSemesterID = ParameterServices.Value.GetParameterValue(CF_ParameterType.GraduationSchoolyear); //毕业学期设置信息 Expression> expGraduateSchoolyear = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = GraduationSchoolYearDAL.GetGraduationSchoolYearViewQueryable(expGraduateSchoolyear, graduatingSemesterID); if (years.HasValue) { query = query.Where(x => x.Years == years); } if (schoolcodeID.HasValue) { query = query.Where(x => x.SchoolcodeID == schoolcodeID); } if (isCurrent.HasValue) { if (isCurrent == 1) { query = query.Where(x => x.IsCurrent == true); } if (isCurrent == 0) { query = query.Where(x => x.IsCurrent != true); } } if (isEnable.HasValue) { if (isEnable == 1) { query = query.Where(x => x.IsEnable == true); } if (isEnable == 0) { query = query.Where(x => x.IsEnable != true); } } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderByDescending(x => x.IsEnable) .ThenByDescending(x => x.GraduatingSemesterValue) .ToGridResultSet(pageIndex, pageSize); } /// /// 查询毕业学期信息List /// /// /// /// /// /// /// public IList GetGradSchoolYearViewList(ConfiguretView configuretView, int? years, int? schoolcodeID, int? isCurrent, int? isEnable) { //查询设置的毕业学期Value var graduatingSemesterID = ParameterServices.Value.GetParameterValue(CF_ParameterType.GraduationSchoolyear); //毕业学期设置信息 Expression> expGraduateSchoolyear = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = GraduationSchoolYearDAL.GetGraduationSchoolYearViewQueryable(expGraduateSchoolyear, graduatingSemesterID); if (years.HasValue) { query = query.Where(x => x.Years == years); } if (schoolcodeID.HasValue) { query = query.Where(x => x.SchoolcodeID == schoolcodeID); } if (isCurrent.HasValue) { if (isCurrent == 1) { query = query.Where(x => x.IsCurrent == true); } if (isCurrent == 0) { query = query.Where(x => x.IsCurrent != true); } } if (isEnable.HasValue) { if (isEnable == 1) { query = query.Where(x => x.IsEnable == true); } if (isEnable == 0) { query = query.Where(x => x.IsEnable != true); } } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderByDescending(x => x.IsEnable) .ThenByDescending(x => x.GraduatingSemesterValue) .ToList(); } /// /// 查询对应的毕业学期信息View(根据毕业学期设置信息ID) /// /// /// public GraduationSchoolYearView GetGradSchoolYearView(Guid? graduationSchoolYearSettingID) { try { //查询设置的毕业学期Value var graduatingSemesterID = ParameterServices.Value.GetParameterValue(CF_ParameterType.GraduationSchoolyear); //毕业学期设置信息 Expression> expGraduateSchoolyear = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expGraduateSchoolyear = expGraduateSchoolyear.And(x => x.GraduateSchoolyearID == graduationSchoolYearSettingID); var query = GraduationSchoolYearDAL.GetGraduationSchoolYearViewQueryable(expGraduateSchoolyear, graduatingSemesterID) .SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑(新增、修改,业务主键:毕业学期设置信息ID) /// 判断启用状态(只有一种启用状态) /// /// public void GraduationSchoolYearEdit(GraduationSchoolYearView graduationSchoolYearView) { try { //查询数据库进行验证 var gradSchoolYearVerification = GraduationSchoolYearDAL.GraduateSchoolyearRepository .GetList(x => x.GraduateSchoolyearID != graduationSchoolYearView.GraduationSchoolYearSettingID && x.SchoolyearID == graduationSchoolYearView.GraduatingSemesterID) .SingleOrDefault(); if (gradSchoolYearVerification == null) { //数据有误验证 if (graduationSchoolYearView.GraduationSchoolYearSettingID != Guid.Empty) { var gradSchoolYear = GraduationSchoolYearDAL.GraduateSchoolyearRepository .GetList(x => x.SchoolyearID == graduationSchoolYearView.GraduatingSemesterID) .SingleOrDefault(); if (gradSchoolYear == null) { throw new Exception("数据有误,请核查。"); } else { //表示修改 //查询设置的毕业学期Value var graduatingSemesterID = ParameterServices.Value.GetParameterValue(CF_ParameterType.GraduationSchoolyear); if (graduationSchoolYearView.GraduatingSemesterID == graduatingSemesterID) { if (!graduationSchoolYearView.IsEnable) { ParameterServices.Value.SaveTo(CF_ParameterType.GraduationSchoolyear, null); } } else { //设置对应的毕业学期 if (graduationSchoolYearView.IsEnable) { ParameterServices.Value.SaveTo(CF_ParameterType.GraduationSchoolyear, graduationSchoolYearView.GraduatingSemesterID.Value); } } gradSchoolYear.GraduateDate = graduationSchoolYearView.GraduateDate; SetModifyStatus(gradSchoolYear); } } else { //表示新增 //设置对应的毕业学期 if (graduationSchoolYearView.IsEnable) { ParameterServices.Value.SaveTo(CF_ParameterType.GraduationSchoolyear, graduationSchoolYearView.GraduatingSemesterID.Value); } ER_GraduateSchoolyear newGraduateSchoolyear = new ER_GraduateSchoolyear(); newGraduateSchoolyear.GraduateSchoolyearID = Guid.NewGuid(); newGraduateSchoolyear.SchoolyearID = graduationSchoolYearView.GraduatingSemesterID; newGraduateSchoolyear.GraduateDate = graduationSchoolYearView.GraduateDate; SetNewStatus(newGraduateSchoolyear); UnitOfWork.Add(newGraduateSchoolyear); } } else { throw new Exception("已存在相同的毕业学期信息,请核查。"); } //事务提交 UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除(注:需对设置的毕业学期进行处理) /// /// /// public bool GraduationSchoolYearDelete(List graduationSchoolYearSettingIDs) { try { //查询设置的毕业学期Value var graduatingSemesterID = ParameterServices.Value.GetParameterValue(CF_ParameterType.GraduationSchoolyear); //毕业学期设置信息 Expression> expGraduateSchoolyear = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expGraduateSchoolyear = expGraduateSchoolyear.And(x => graduationSchoolYearSettingIDs.Contains(x.GraduateSchoolyearID)); var gradSchoolYearViewList = GraduationSchoolYearDAL .GetGraduationSchoolYearViewQueryable(expGraduateSchoolyear, graduatingSemesterID).ToList(); foreach (var gradSchoolYearView in gradSchoolYearViewList) { if (gradSchoolYearView.IsEnable) { ParameterServices.Value.SaveTo(CF_ParameterType.GraduationSchoolyear, null); } } UnitOfWork.Delete(x => graduationSchoolYearSettingIDs.Contains(x.GraduateSchoolyearID)); UnitOfWork.Commit(); return true; } catch (Exception ex) { throw new Exception(ex.Message); } } } }