using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Common.Specialtymanage; using EMIS.Entities; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.Specialtymanage; using EMIS.ViewModel; using System.Text.RegularExpressions; using Bowin.Common.Utility; using EMIS.ViewModel.Cache; using EMIS.Utility; using System.Linq.Expressions; using EMIS.DataLogic.ExamManage; namespace EMIS.CommonLogic.ExamManage { public class ExamBatchProjectServices : BaseServices, IExamBatchProjectServices { public ExaminationBatchDAL ExaminationBatchDAL { get; set; } public ExamBatchProjectDAL ExamBatchProjectDAL { get; set; } public ProjectFeeDAL ProjectFeeDAL { get; set; } public IGridResultSet GetBatchProjectListGridView(int pageIndex, int pageSize, params EMIS.ViewModel.ConfiguretView[] configuretViews) { //校区信息 System.Linq.Expressions.Expression> expCampus = (x =>true); var query = ExamBatchProjectDAL.GetBatchProjectList(expCampus); //查询条件 foreach (var configuretView in configuretViews) { if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query .OrderByDescending(x => x.Schoolyear).ThenBy(x => x.StartDate) .ThenBy(x => x.ExaminationBatchID).ThenBy(x => x.Name) .ToGridResultSet(pageIndex, pageSize); } public IGridResultSet GetExamBatchExamTypeListViewGrid(int pageIndex, int pageSize, params EMIS.ViewModel.ConfiguretView[] configuretViews) { System.Linq.Expressions.Expression> expCampus = (x => x.RecordStatus == (int)SYS_STATUS.USABLE); var query = ExamBatchProjectDAL.GetBatchProjectList(expCampus); //查询条件 foreach (var configuretView in configuretViews) { if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = query.OrderBy(x => x.ExaminationBatchProjectID).GroupBy(x => new { x.ExaminationBatchID, x.ExaminationTypeID, x.ExaminationType }).Select(x => new EMIS.ViewModel.ExaminationApply.ExaminationTypeView() { ExaminationBatchID = x.Key.ExaminationBatchID, ExaminationTypeID = x.Key.ExaminationTypeID.Value, Name = x.Key.ExaminationType }); return result .OrderBy(x => x.ExaminationBatchID) .ToGridResultSet(pageIndex, pageSize); } public IQueryable GetBatchProjectList(params EMIS.ViewModel.ConfiguretView[] configuretViews) { System.Linq.Expressions.Expression> expCampus = (x => x.RecordStatus == (int)SYS_STATUS.USABLE); var query = ExamBatchProjectDAL.GetBatchProjectList(expCampus); //查询条件 foreach (var configuretView in configuretViews) { if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query .OrderBy(x => x.ExaminationBatchID).AsQueryable(); } public List SelectProjects(Guid ExaminationBatchID, List list) { //筛选已经存在的考试 var examlist = ExamBatchProjectDAL.GetBatchProjectList(q => q.ExaminationBatchID == ExaminationBatchID).Select(q => q.ExaminationProjectID).ToArray(); list = list.Where(q => !examlist.Contains(q)).ToList(); var addlist = new List(); var batch = ExaminationBatchDAL.GetBatchList(q => q.ExaminationBatchID == ExaminationBatchID).SingleOrDefault(); list.ForEach(id => { var project = ProjectFeeDAL.ProjectRepository.GetSingle(q => q.ExaminationProjectID == id); var entity = new EX_ExaminationBatchProject() { ExaminationBatchProjectID = Guid.NewGuid(), ExaminationBatchID = ExaminationBatchID, ExaminationProjectID = id, StartDate = batch.StartDate, EndDate = batch.EndDate, Remark = project.Remark, RecordStatus = (int)SYS_STATUS.UNUSABLE }; this.SetModifyStatus(entity); addlist.Add(entity); this.ExamBatchProjectDAL.BatchProjectRepository.UnitOfWork.Add(entity); }); this.ExamBatchProjectDAL.BatchProjectRepository.UnitOfWork.Commit(); System.Linq.Expressions.Expression> expCampus = (x => x.ExaminationBatchID == ExaminationBatchID && list.Contains(x.ExaminationProjectID)); var query = ExamBatchProjectDAL.GetBatchProjectList(expCampus); return query.ToList(); } public EMIS.ViewModel.ExamBatchProjectView GetView(Expression> expCampus) { var query = ExamBatchProjectDAL.GetBatchProjectList(expCampus).SingleOrDefault(); return query; } public void Edit(ExamBatchProjectView view, IList listData) { try { var dbBatchProjectList = ExamBatchProjectDAL.BatchProjectRepository.Entities.ToList(); //var entity = ExaminationBatchDAL.BatchRepository.Entities // .SingleOrDefault(x => x.ExaminationBatchID == view.ExaminationBatchID); //if (entity == null) //{ // entity = new EX_ExaminationBatch(); // this.SetNewStatus(entity); // ExaminationBatchDAL.BatchRepository.UnitOfWork.Add(entity); //} List batchProjectList = new List(); foreach (var data in listData) { if (dbBatchProjectList.Where(x => x.ExaminationBatchID == view.ExaminationBatchID && x.ExaminationProjectID == data.ExaminationProjectID).Count() > 0) { throw new Exception("要添加的项目该批次已存在,请检查后再添加"); } EX_ExaminationBatchProject item = new EX_ExaminationBatchProject(); item.ExaminationBatchProjectID = Guid.NewGuid(); item.ExaminationBatchID = view.ExaminationBatchID; item.ExaminationProjectID = data.ExaminationProjectID; //ExamBatchProjectDAL.BatchProjectRepository.Entities.SingleOrDefault(x => x.ExaminationBatchProjectID == data.ExaminationBatchProjectID); item.SimulateTime = data.SimulateTime; item.Training = data.Training; item.TakeCourseTime = data.TakeCourseTime; item.MaxRegistCount = data.MaxRegistCount; item.Remark = data.Remark; //item.RecordStatus = (int)SYS_STATUS.USABLE; //item.CreateTime = DateTime.Now; item.StartDate = view.StartDate; item.EndDate = view.EndDate; this.SetNewStatus(item); batchProjectList.Add(item); } UnitOfWork.BulkInsert(batchProjectList); } catch (Exception) { throw; } //ExaminationBatchDAL.BatchRepository.UnitOfWork.Commit(); } public void Edit(ExamBatchProjectView view) { var item = ExamBatchProjectDAL.BatchProjectRepository.Entities .SingleOrDefault(x => x.ExaminationBatchProjectID == view.ExaminationBatchProjectID); item.SimulateTime = view.SimulateTime; item.Training = view.Training; item.TakeCourseTime = view.TakeCourseTime; item.MaxRegistCount = view.MaxRegistCount; item.Remark = view.Remark; item.StartDate = view.StartDate; item.EndDate = view.EndDate; this.SetModifyStatus(item); ExaminationBatchDAL.BatchRepository.UnitOfWork.Commit(); } public bool DeleteBatchProject(List ExamBatchProjectIDs) { try { UnitOfWork.Delete(x => ExamBatchProjectIDs.Contains(x.ExaminationBatchProjectID)); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } } }