123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- 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.DataLogic.ExaminationApply;
- using EMIS.ViewModel.ExaminationApply;
- using EMIS.Entities;
- using EMIS.ViewModel;
- namespace EMIS.CommonLogic.ExaminationApply
- {
- public class OpenControlServices : BaseServices, IOpenControlServices
- {
- public OpenControlDAL OpenControlDAL { get; set; }
- public ExaminationSubjectDAL ExaminationSubjectDAL { get; set; }
- public ExaminationSubjectServices ExaminationSubjectServices { get; set; }
- public Bowin.Common.Linq.Entity.IGridResultSet<OpenControlView> GetOpenControlViewList(ViewModel.ConfiguretView openControlView, Guid? examinationTypeID,
- Guid? examinationSubjectID, int? yearNum, int? studentType, int pageIndex, int pageSize)
- {
- Expression<Func<EX_ExaminationOpenControl, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (examinationTypeID.HasValue)
- {
- exp = exp.And(x => x.EX_ExaminationSubject.ExaminationTypeID == examinationTypeID);
- }
- if (examinationSubjectID.HasValue)
- {
- exp = exp.And(x => x.ExaminationSubjectID == examinationSubjectID);
- }
- if (yearNum.HasValue)
- {
- exp = exp.And(x => x.SchoolyearNumID == yearNum);
- }
- if (studentType.HasValue)
- {
- exp = exp.And(x => x.StudentType == studentType);
- }
- var q = OpenControlDAL.GetOpenControlView(exp);
- if (!string.IsNullOrEmpty(openControlView.ConditionValue) && !string.IsNullOrEmpty(openControlView.Attribute))
- q = q.DynamicWhere(openControlView.Attribute, openControlView.Condition, openControlView.ConditionValue);
- return q.ToGridResultSet<OpenControlView>(pageIndex, pageSize);
- }
- public IList<OpenControlView> GetOpenControlViewList(ViewModel.ConfiguretView openControlView, Guid? examinationTypeID, Guid? examinationSubjectID, int? yearNum, int? studentType)
- {
- Expression<Func<EX_ExaminationOpenControl, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (examinationTypeID.HasValue)
- {
- exp = exp.And(x => x.EX_ExaminationSubject.ExaminationTypeID == examinationTypeID);
- }
- if (examinationSubjectID.HasValue)
- {
- exp = exp.And(x => x.ExaminationSubjectID == examinationSubjectID);
- }
- if (yearNum.HasValue)
- {
- exp = exp.And(x => x.SchoolyearNumID == yearNum);
- }
- if (studentType.HasValue)
- {
- exp = exp.And(x => x.StudentType == studentType);
- }
- var q = OpenControlDAL.GetOpenControlView(exp);
- if (!string.IsNullOrEmpty(openControlView.ConditionValue) && !string.IsNullOrEmpty(openControlView.Attribute))
- q = q.DynamicWhere(openControlView.Attribute, openControlView.Condition, openControlView.ConditionValue);
- return q.ToList();
- }
- public ViewModel.ExaminationApply.OpenControlView GetOpenControlViewInfo(Guid? openControlID)
- {
- return OpenControlDAL.GetOpenControlView(x => x.ExaminationOpenControlID == openControlID).FirstOrDefault();
- }
- public void Save(ViewModel.ExaminationApply.OpenControlView openControlView)
- {
- EX_ExaminationSubject examinationSubject = null;
- if (openControlView.StudentTypeID.Count == 0)
- throw new Exception("请选择学生类别");
- if (openControlView.ExaminationSubjectEditID != null)
- {
- examinationSubject = ExaminationSubjectDAL.ExaminationSubjectRepository.Entities.Where(x => x.ExaminationSubjectID == openControlView.ExaminationSubjectEditID).FirstOrDefault();
- }
- else
- {
- examinationSubject = ExaminationSubjectDAL.ExaminationSubjectRepository.Entities.Where(x => x.ExaminationSubjectID == openControlView.ExaminationSubjectID).FirstOrDefault();
- }
- if (examinationSubject != null && examinationSubject.ExaminationDate <= openControlView.EndDate)
- {
- throw new Exception("报名截止时间不能大于考试时间。");
- }
- if (openControlView.StartDate > openControlView.EndDate)
- {
- throw new Exception("报名时间开始不能大于结束时间。");
- }
- ////验证限定人数是否超过最大报名数
- //if (openControlView.ExaminationSubjectID != null)
- //{
- // //1.0该科目的最大报名数
- // int? peopleNumLimit = OpenControlDAL.ExaminationSubjectRepository.Entities.Where(x => x.ExaminationSubjectID == openControlView.ExaminationSubjectID).FirstOrDefault().PeopleNumLimit;
- // //2.0 获取同一科目,学生类别,年级数汇总限定人数
- // var query = OpenControlDAL.ExaminationOpenControlRepository.Entities
- // .Where(x => x.ExaminationSubjectID == openControlView.ExaminationSubjectID
- // && openControlView.StudentTypeID.Contains(x.StudentType.Value));
- // var peopleNumLimitSumCountList = query.GroupBy(x => x.StudentType).Select(x => x.Sum(w => w.PeopleNumLimit)).ToList();
- // //int? peopleNumLimitSumCount = OpenControlDAL.ExaminationOpenControlRepository.Entities
- // // .Where(x => x.ExaminationSubjectID == openControlView.ExaminationSubjectID
- // // && x.StudentType == openControlView.StudentType )
- // // .Select(w => w.PeopleNumLimit).Sum();
- // //if (openControlView.PeopleNumLimit > peopleNumLimit)
- // //{
- // // throw new Exception("限定人数超过该科目的最大报名数。");
- // //}
- // foreach (var peopleNumLimitSumCount in peopleNumLimitSumCountList)
- // {
- // if (peopleNumLimitSumCount + openControlView.PeopleNumLimit > peopleNumLimit)
- // {
- // throw new Exception("该学生类别及年级数汇总限定人数超过该科目的最大报名数。");
- // }
- // }
- //}
- var openControlEntity = OpenControlDAL.ExaminationOpenControlRepository.GetSingle(x => x.ExaminationOpenControlID == openControlView.ExaminationOpenControlID);
- int? type = openControlView.StudentTypeID[0];
- if (openControlEntity != null)
- {
- var RepeatOpenControl = OpenControlDAL.ExaminationOpenControlRepository.GetSingle(x =>
- x.ExaminationSubjectID == openControlView.ExaminationSubjectEditID &&
- x.StudentType == type &&
- //openControlView.StudentTypeID.Contains(x.StudentType.Value) &&
- x.SchoolyearNumID == openControlView.SchoolyearNumID);
- if (RepeatOpenControl != null && openControlEntity.ExaminationOpenControlID != RepeatOpenControl.ExaminationOpenControlID)
- { //判断考试科目、学生类别、年级数不能重复
- throw new Exception("已存在相同的考试科目、学生类别、年级数,请核查");
- }
- openControlEntity.ExaminationSubjectID = openControlView.ExaminationSubjectEditID;
- openControlEntity.StudentType = openControlView.StudentTypeID[0];
- openControlEntity.SchoolyearNumID = openControlView.SchoolyearNumID;
- openControlEntity.StartDate = openControlView.StartDate;
- openControlEntity.EndDate = openControlView.EndDate;
- openControlEntity.PeopleNumLimit = openControlView.PeopleNumLimit;
- this.SetModifyStatus(openControlEntity);
- }
- else
- {
- var RepeatOpenControl = OpenControlDAL.ExaminationOpenControlRepository.GetSingle(x =>
- x.ExaminationSubjectID == openControlView.ExaminationSubjectID &&
- //x.StudentType == openControlView.StudentType &&
- openControlView.StudentTypeID.Contains(x.StudentType.Value) &&
- x.SchoolyearNumID == openControlView.SchoolyearNumID);
- if (RepeatOpenControl != null)
- { //判断考试科目、学生类别、年级数不能重复
- throw new Exception("已存在相同的考试科目、学生类别、年级数,请核查");
- }
- if (openControlView.ExaminationSubjectID == null)//考试科目选择全部
- {
- //批量以考试科目增加数据
- if (openControlView.ExaminationTypeID != null)
- {
- List<ExaminationSubjectView> subjectList = ExaminationSubjectDAL.GetExaminationSubjectView(x => x.ExaminationTypeID == openControlView.ExaminationTypeID).ToList();
- if (openControlView.StudentTypeID.Count > 0)
- {
- subjectList.ForEach(w =>
- {
- openControlView.StudentTypeID.ForEach(x =>
- {
- openControlEntity = new EX_ExaminationOpenControl();
- openControlEntity.ExaminationOpenControlID = Guid.NewGuid();
- openControlEntity.ExaminationSubjectID = w.ExaminationSubjectID;
- openControlEntity.StudentType = x;
- openControlEntity.SchoolyearNumID = openControlView.SchoolyearNumID;
- openControlEntity.StartDate = openControlView.StartDate;
- openControlEntity.EndDate = openControlView.EndDate;
- openControlEntity.PeopleNumLimit = openControlView.PeopleNumLimit;
- this.SetNewStatus(openControlEntity);
- UnitOfWork.Add(openControlEntity);
- });
- });
- }
- }
- }
- else
- {
- if (openControlView.StudentTypeID.Count > 0)
- {
- openControlView.StudentTypeID.ForEach(x =>
- {
- openControlEntity = new EX_ExaminationOpenControl();
- openControlEntity.ExaminationOpenControlID = Guid.NewGuid();
- openControlEntity.ExaminationSubjectID = openControlView.ExaminationSubjectID;
- openControlEntity.StudentType = x;
- openControlEntity.SchoolyearNumID = openControlView.SchoolyearNumID;
- openControlEntity.StartDate = openControlView.StartDate;
- openControlEntity.EndDate = openControlView.EndDate;
- openControlEntity.PeopleNumLimit = openControlView.PeopleNumLimit;
- this.SetNewStatus(openControlEntity);
- UnitOfWork.Add(openControlEntity);
- });
- }
- }
- }
- UnitOfWork.Commit();
- }
- public void Delete(IList<Guid?> openControlID)
- {
- if (openControlID.Count > 0)
- {
- UnitOfWork.Delete<EX_ExaminationOpenControl>(x => openControlID.Contains(x.ExaminationOpenControlID));
- }
- }
- //获取学生类别信息
- public List<string> GetStudentType(Guid? openControlID)
- {
- return OpenControlDAL.GetStudentTypeQueryble(openControlID);
- }
- }
- }
|