using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.MinorManage.MinorPlanManage; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.MinorManage.MinorPlanManage; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.Entities; using Bowin.Common.Linq; using EMIS.CommonLogic.MinorManage.MinorApply; using EMIS.DataLogic.MinorManage.MinorApply; using EMIS.ViewModel.CacheManage; using EMIS.ViewModel.Students; namespace EMIS.CommonLogic.MinorManage.MinorPlanManage { public class MinorSpecialtyServices : BaseServices, IMinorSpecialtyServices { public MinorSpecialtyDAL MinorSpecialtyDAL { get; set; } public IMinorApplyServices minorApplyServices { get; set; } public MinorApplyDAL minorApplyDAL { get; set; } public IGridResultSet GetMinorSpecialtyViewGrid(ConfiguretView configuretView, int? yearID, int? standardID, Guid? collegeID, int? grademinorStatus, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (yearID.HasValue) exp = exp.And(x => x.YearID == yearID); if (standardID.HasValue) exp = exp.And(x => x.StandardID == standardID); if (collegeID.HasValue) exp = exp.And(x => x.CollegeID == collegeID); if (grademinorStatus.HasValue) exp = exp.And(x => x.RecordStatus == grademinorStatus); var query = MinorSpecialtyDAL.GetMinorSpecialtyViewQueryable(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.YearID).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo) .ThenByDescending(x => x.StandardID).ThenByDescending(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); return result; } public List GetMinorSpecialtyViewList(ConfiguretView configuretView, int? yearID, int? standardID, Guid? collegeID, int? grademinorStatus, List GrademinorIDList) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (GrademinorIDList != null) exp = exp.And(x => GrademinorIDList.Contains(x.GrademinorID)); if (yearID.HasValue) exp = exp.And(x => x.YearID == yearID); if (standardID.HasValue) exp = exp.And(x => x.StandardID == standardID); if (collegeID.HasValue) exp = exp.And(x => x.CollegeID == collegeID); if (grademinorStatus.HasValue) exp = exp.And(x => x.RecordStatus == grademinorStatus); var query = MinorSpecialtyDAL.GetMinorSpecialtyViewQueryable(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.YearID).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo) .ThenByDescending(x => x.StandardID).ThenByDescending(x => x.CreateTime).ToList(); } public MinorSpecialtyView GetMinorSpecialtyView(Guid? GrademinorID) { Expression> exp = (x => x.GrademinorID == GrademinorID); var query = MinorSpecialtyDAL.GetMinorSpecialtyViewQueryable(exp).FirstOrDefault(); return query; } public bool MinorSpecialtyOpen(List IDList) { try { if (IDList.Count > 0) { var MinorSpecialtyList = MinorSpecialtyDAL.GrademinorRepository.GetList(x => IDList.Contains(x.GrademinorID)).ToList(); foreach (var MinorSpecialty in MinorSpecialtyList) { CF_Grademinor Grademinor = MinorSpecialty; Grademinor.RecordStatus = (int)CF_GrademinorStatus.Opened; SetModifyStatus(Grademinor); UnitOfWork.Commit(); } } return true; } catch (Exception) { throw; } } public bool MinorSpecialtyCancel(List IDList) { try { if (IDList.Count > 0) { var MinorSpecialtyList = MinorSpecialtyDAL.GrademinorRepository.GetList(x => IDList.Contains(x.GrademinorID)).ToList(); foreach (var MinorSpecialty in MinorSpecialtyList) { CF_Grademinor Grademinor = MinorSpecialty; Grademinor.RecordStatus = (int)CF_GrademinorStatus.NotOpened; SetModifyStatus(Grademinor); UnitOfWork.Commit(); } } return true; } catch (Exception) { throw; } } /// /// 开班 /// /// public void OpenClass(List iDList) { try { if (iDList.Count > 0) { Expression> exp = x => true; Expression> expcla = x => true; Expression> expcol = x => true; var endStatusID = minorApplyServices.GetCorrectEndStatus(); var inputStatus = minorApplyServices.GetStartApproveStatusList(); //获取所有的辅修报名信息 var minorStudentList = minorApplyDAL.GetMinorApplyViewQueryable(exp, expcla, expcol); var minorApplyViewList = this.GetQueryByDataRangeByCollege(minorStudentList).ToList(); //var query = minorApplyViewList.GroupBy(x => new //{ // x.GrademinorID, //}).ToList(); List classminorList = new List(); var minorSpecialtyList = MinorSpecialtyDAL.GrademinorRepository.GetList(x => iDList.Contains(x.GrademinorID)).ToList(); foreach (var minorSpecialty in minorSpecialtyList) { if (minorSpecialty.RecordStatus != (int)CF_GrademinorStatus.Opened) { throw new Exception("只能对 已开放 状态的辅修专业进行开班"); } //还有没有处理完的学生报名信息不让开班 if (minorStudentList.Any(x => x.GrademinorID == minorSpecialty.GrademinorID && x.GradeYearID == minorSpecialty.YearID && inputStatus.Contains(x.RecordStatus))) { throw new Exception("所选辅修专业对应的学生报名信息存在未处理完的,请处理完再开班"); } CF_Grademinor Grademinor = minorSpecialty; Grademinor.RecordStatus = (int)CF_GrademinorStatus.Confirmed; SetModifyStatus(Grademinor); UnitOfWork.Commit(); //生成辅修班级 var standardName = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Standard.ToString()).Where(x => x.Value == minorSpecialty.StandardID).Select(x => x.Name).FirstOrDefault(); CF_Classminor classminor = new CF_Classminor(); classminor.ClassminorID = Guid.NewGuid(); classminor.GrademinorID = minorSpecialty.GrademinorID; classminor.Name = minorSpecialty.YearID.ToString() + standardName + "辅修班"; classminor.Abbreviation = classminor.Name; classminor.ClassNum = 1; SetNewStatus(classminor); if (minorApplyViewList.Where(x => x.GrademinorID == minorSpecialty.GrademinorID && x.GradeYearID == minorSpecialty.YearID).Count() <= 0) { throw new Exception("所选的辅修专业没有学生报名,不能开班"); } if (minorApplyViewList.Where(x => x.GrademinorID == minorSpecialty.GrademinorID && x.GradeYearID == minorSpecialty.YearID && x.RecordStatus == endStatusID).Count() > 0) { var Student = minorApplyViewList.Where(x => x.GrademinorID == minorSpecialty.GrademinorID && x.GradeYearID == minorSpecialty.YearID && x.RecordStatus == endStatusID).Select(x => new CF_ClassminorStudent { ClassminorStudentID = Guid.NewGuid(), ClassminorID = classminor.ClassminorID, UserID = x.UserID.Value, RecordStatus = (int)SYS_STATUS.USABLE, CreateTime = DateTime.Now, CreateUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID, ModifyTime = DateTime.Now, ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID, }); classminor.CF_ClassminorStudent = new HashSet(Student.ToList()); } else { classminor.CF_ClassminorStudent = new HashSet(); } classminorList.Add(classminor); } UnitOfWork.BulkInsert(classminorList); UnitOfWork.BulkInsert(classminorList.SelectMany(x => x.CF_ClassminorStudent).ToList()); } } catch (Exception) { throw; } } /// /// 取消开班 /// /// public void CancelClass(List idList) { try { if (idList.Count > 0) { var minorSpecialtyList = MinorSpecialtyDAL.GrademinorRepository.GetList(x => idList.Contains(x.GrademinorID)).ToList(); foreach (var minorSpecialty in minorSpecialtyList) { if (minorSpecialty.RecordStatus != (int)CF_GrademinorStatus.Opened) { throw new Exception("只能对 已开放 状态的辅修专业取消开班"); } CF_Grademinor grademinor = minorSpecialty; grademinor.RecordStatus = (int)CF_GrademinorStatus.Cancelled; SetModifyStatus(grademinor); UnitOfWork.Commit(); } } } catch (Exception) { throw; } } public IGridResultSet GetStudentsByGrademinorID(Guid grademinorID) { Expression> exp = x => x.GrademinorID == grademinorID; var query = MinorSpecialtyDAL.GetStudentsQueryable(exp); return query.OrderBy(x => x.LoginID).ToGridResultSet(); } } }