using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.MinorManage.MinorApply; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.Entities; using Bowin.Common.Linq; using EMIS.DataLogic.MinorManage.MinorApply; using EMIS.DataLogic.MinorManage.MinorSetting; using EMIS.CommonLogic.CalendarManage; using EMIS.Utility; using EMIS.ViewModel.MinorManage.MinorSetting; using System.Transactions; using EMIS.CommonLogic.SystemServices; using EMIS.ViewModel.MinorManage.MinorPlanManage; using EMIS.DataLogic.MinorManage.MinorPlanManage; namespace EMIS.CommonLogic.MinorManage.MinorApply { public class StudentMinorRegistApplyServices : BaseWorkflowServices, IStudentMinorRegistApplyServices { public StudentMinorRegistApplyDAL studentMinorRegistApplyDAL { get; set; } public MinorStandardSettingDAL minorStandardSettingDAL { get; set; } public MinorControlDAL minorControlDAL { get; set; } public ISchoolYearServices schoolYearServices { get; set; } public MinorConditionDAL minorConditionDAL { get; set; } public MinorPlanApplyDAL minorPlanApplyDAL { get; set; } public IGridResultSet GetGrademinorViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, int? yearID, int? minorStandardID, int pageIndex, int pageSize) { var user = EMIS.Utility.FormValidate.CustomPrincipal.Current; var applyStatusList = this.GetStatusViewList(); var returnStatus = applyStatusList.Where(x => x.Description.Contains("BP")).FirstOrDefault().ID; var standardID = studentMinorRegistApplyDAL.GetStandardIDListByUserID(user.UserID); List minorStandardIDList = new List(); if (standardID.HasValue) { var squery = minorStandardSettingDAL.GetMinorStandardSettingViewQueryable(x => x.StandardID == standardID); if (squery.Count() > 0) { minorStandardIDList = squery.Select(x => x.MinorStandardID).ToList(); } } Expression> exp = x => true; //只显示已开放状态的辅修专业对应的信息 //exp = exp.And(x => x.RecordStatus == (int)CF_GrademinorStatus.Opened); if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { exp = exp.And(x => x.CollegeID == collegeID); } if (yearID.HasValue) { exp = exp.And(x => x.YearID == yearID); } if (minorStandardID.HasValue) { exp = exp.And(x => x.StandardID == minorStandardID); } if (minorStandardIDList.Count <= 0) { exp = exp.And(x => x.StandardID == null); } else { exp = exp.And(x => minorStandardIDList.Contains(x.StandardID)); } var query = studentMinorRegistApplyDAL.GetMinorClassViewQueryable(exp, user.UserID, returnStatus); //学生报名界面显示已报名的辅修信息,还有已开放的辅修信息 query = query.Where(x => x.OpenStatus == (int)CF_GrademinorStatus.Opened || x.RecordStatus != null); //列表查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var schoolYear = schoolYearServices.GetSchoolYearIsCurrent(true); var control = studentMinorRegistApplyDAL.GetMinorControlViewByUserIDAndSchoolyear(user.UserID, schoolYear.SchoolyearID); var canSelect = true; var result = query.OrderByDescending(x => x.SchoolyearCode).ToGridResultSet(pageIndex, pageSize); if (control != null) { if (DateTime.Now < control.FirstOrDefault().StartDate || DateTime.Now > control.FirstOrDefault().EndDate) { result.rows.ForEach(x => x.CanSelect = false); } result.rows.ForEach(x => x.MinorControlID = control.FirstOrDefault().MinorControlID); result.rows.ForEach(x => x.StartDate = control.FirstOrDefault().StartDate); result.rows.ForEach(x => x.EndDate = control.FirstOrDefault().EndDate); } else{ result.rows.ForEach(x => x.CanSelect = false); } if (query.Any(x => x.CanSelect == false)) { result.rows.ForEach(x => x.CanSelect = false); } result.rows.ForEach(x => x.RecordStatusStr = x.RecordStatus != null ? applyStatusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name : ""); result.rows.ForEach(x => x.CanSelect = x.OpenStatus != (int)CF_GrademinorStatus.Opened ? false : x.CanSelect); result.rows.ForEach(x => x.CanSelect = (x.OperateText == "已报满" || x.OperateText == "已报名") ? false : x.CanSelect); return result; } public void Apply(Guid GrademinorID) { try { //using (TransactionScope ts = new TransactionScope()) //{ Expression> exp = x => true; var user = EMIS.Utility.FormValidate.CustomPrincipal.Current; var schoolYear = schoolYearServices.GetSchoolYearIsCurrent(true); //开放控制验证 var control = studentMinorRegistApplyDAL.GetMinorControlViewByUserIDAndSchoolyear(user.UserID, schoolYear.SchoolyearID); if (control != null) { var con = control.FirstOrDefault(); if (DateTime.Now < con.StartDate || DateTime.Now > con.EndDate) { throw new Exception("不在辅修报名开放时间内"); } } //辅修专业验证 var grademinor = studentMinorRegistApplyDAL.grademinorRepository.GetSingle(x => x.GrademinorID == GrademinorID); if (grademinor != null) { if (grademinor.RecordStatus != (int)CF_GrademinorStatus.Opened) { throw new Exception("该辅修专业不处于已开放状态,不能进行报名"); } } //辅修条件验证 Expression> mcdexp = x => x.RecordStatus >= (int)SYS_STATUS.USABLE; var query = minorConditionDAL.GetMinorConditionViewQueryable(mcdexp); bool isPass = true; foreach (var minorCondition in query) { var retValue = ReflectorHelper.RunMethod(minorCondition.MethodFullName, user.UserID); if (!(bool)retValue) { //表示条件不通过 isPass = false; //终止循环 break; } } if (!isPass) { throw new Exception("辅修条件不通过"); } //查询对应的工作流程环节状态信息View var approveStatusList = this.GetStatusViewList(); if (approveStatusList == null || approveStatusList.Count() <= 0) { throw new Exception("工作流平台中,辅修报名流程未配置,请核查"); } //查询工作流程开始环节状态 var approveStartStatus = this.GetStartStatus(); if (approveStartStatus == null) { throw new Exception("工作流平台中,辅修报名流程开始环节未配置,请核查"); } var action = this.GetActionView(); var actionID = action.Where(x => x.Pid == approveStartStatus).FirstOrDefault().ActionID; EM_StudentMinorRegist studentMinorRegist = new EM_StudentMinorRegist(); studentMinorRegist.StudentMinorRegistID = Guid.NewGuid(); studentMinorRegist.SchoolyearID = schoolYear.SchoolyearID; studentMinorRegist.GrademinorID = GrademinorID; studentMinorRegist.UserID = user.UserID; studentMinorRegist.RecordStatus = approveStartStatus; studentMinorRegist.CreateTime = DateTime.Now; studentMinorRegist.CreateUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID; studentMinorRegist.ModifyTime = DateTime.Now; studentMinorRegist.ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID; UnitOfWork.Add(studentMinorRegist); UnitOfWork.Commit(); List idList = new List(); idList.Add(studentMinorRegist.StudentMinorRegistID); this.StartUp(idList, user.UserID,""); // ts.Complete(); //} } catch (Exception) { throw; } } public IGridResultSet existStandardAndMinorSpecialtyCourseViewGrid(Guid? grademinorID, int pageIndex, int pageSize) { var gradeMinorApplicationID = minorPlanApplyDAL.GrademinorRepository.GetSingle(x => x.GrademinorID == grademinorID).GrademinorApplicationID; Expression> exp = (x => x.GradeMinorApplicationID == gradeMinorApplicationID); var query = minorPlanApplyDAL.existStandardAndMinorSpecialtyCourseView(exp); return this.GetQueryByDataRangeByCollege(query) .OrderBy(x => x.StarttermID).ThenBy(x => x.CourseCode) .ToGridResultSet(pageIndex, pageSize); } public string GetMinorApplyDateTime(Guid? schoolyearID) { var user = EMIS.Utility.FormValidate.CustomPrincipal.Current; var minorcontrolquery = studentMinorRegistApplyDAL.GetMinorControlViewByUserIDAndSchoolyear(user.UserID, schoolyearID.Value); if (minorcontrolquery == null) { return "未开放"; } else { var minorcontrol = studentMinorRegistApplyDAL.GetMinorControlViewByUserIDAndSchoolyear(user.UserID, schoolyearID.Value).FirstOrDefault(); if (minorcontrol.StartDate > DateTime.Now) { return Convert.ToDateTime(minorcontrol.StartDate).ToString("yyyy-MM-dd hh:mm:ss") + " 至 " + Convert.ToDateTime(minorcontrol.EndDate).ToString("yyyy-MM-dd hh:mm:ss") + " (即将开始)"; } else if (minorcontrol.EndDate < DateTime.Now) { return Convert.ToDateTime(minorcontrol.StartDate).ToString("yyyy-MM-dd hh:mm:ss") + " 至 " + Convert.ToDateTime(minorcontrol.EndDate).ToString("yyyy-MM-dd hh:mm:ss") + " (报名结束)"; } else { return Convert.ToDateTime(minorcontrol.StartDate).ToString("yyyy-MM-dd hh:mm:ss") + " 至 " + Convert.ToDateTime(minorcontrol.EndDate).ToString("yyyy-MM-dd hh:mm:ss") + " (开始报名)"; } } } } }