using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.ExamManage; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using Bowin.Common.Linq; using System.Text; using EMIS.DataLogic.ExamManage; using EMIS.DataLogic.SystemDAL; using EMIS.ViewModel.SystemView; namespace EMIS.CommonLogic.ExamManage { public class LevelSettingSubjectServices: BaseServices, ILevelSettingSubjectServices { public LevelSettingSubjectDAL levelSettingSubjectDAL { get; set; } public DictionaryDAL dictionaryDAL { get; set; } public IGridResultSet GetLevelSettingViewGrid(ConfiguretView examinationSubjectView, Guid? examinationTypeID, Guid? examinationProjectID, int pageIndex, int pageSize) { Expression> erexp = x => true; if (examinationTypeID.HasValue) { erexp = erexp.And(x => x.ExaminationTypeID == examinationTypeID); } if (examinationProjectID.HasValue) { erexp = erexp.And(x => x.ExaminationProjectID == examinationProjectID); } var query = levelSettingSubjectDAL.GetLevelSettingView(erexp); if (!string.IsNullOrEmpty(examinationSubjectView.ConditionValue) && !string.IsNullOrEmpty(examinationSubjectView.Attribute)) query = query.DynamicWhere(examinationSubjectView.Attribute, examinationSubjectView.Condition, examinationSubjectView.ConditionValue); return query.OrderBy(x => x.ExaminationTypeName).ThenBy(x => x.ExaminationProjectName).ThenBy(x => x.LevelName).ToGridResultSet(pageIndex, pageSize); } public LevelSettingView GetLevelSettingView(Guid? levelSettingID) { var query = levelSettingSubjectDAL.GetLevelSettingSubjectView(levelSettingID); return query; } public void Edit(LevelSettingView levelSettingView, List levelSettingSubjectViewList) { try { List levelSettingSubjectList = new List(); if (!levelSettingView.LevelSettingID.HasValue || levelSettingView.LevelSettingID == Guid.Empty) { ER_LevelSetting levelSetting = new ER_LevelSetting(); levelSetting.LevelSettingID = Guid.NewGuid(); levelSetting.ExaminationProjectID = levelSettingView.ExaminationProjectID; levelSetting.LevelName = levelSettingView.LevelName; levelSetting.IsPassed = levelSettingView.IsPassedEdit; levelSetting.IsPassLine = levelSettingView.IsPassLineEdit; SetNewStatus(levelSetting); foreach (var levelSettingSubjectView in levelSettingSubjectViewList) { ER_LevelSettingSubject levelSettingSubject = new ER_LevelSettingSubject(); levelSettingSubject.LevelSettingSubjectID = Guid.NewGuid(); levelSettingSubject.LevelSettingID = levelSetting.LevelSettingID; levelSettingSubject.ExaminationSubjectID = levelSettingSubjectView.ExaminationSubjectID; levelSettingSubject.PassScore = levelSettingSubjectView.PassScore; SetNewStatus(levelSettingSubject); levelSettingSubjectList.Add(levelSettingSubject); //UnitOfWork.Add(levelSettingSubject); } UnitOfWork.Add(levelSetting); UnitOfWork.BulkInsert(levelSettingSubjectList); UnitOfWork.Commit(); } else { var levelSetting = levelSettingSubjectDAL.levelSettingRepository.GetList(x => x.LevelSettingID == levelSettingView.LevelSettingID).FirstOrDefault(); if (levelSetting == null) { throw new Exception("您要修改的记录已被删除或不存在"); } levelSetting.ExaminationProjectID = levelSettingView.ExaminationProjectID; levelSetting.LevelName = levelSettingView.LevelName; levelSetting.IsPassed = levelSettingView.IsPassedEdit; levelSetting.IsPassLine = levelSettingView.IsPassLineEdit; SetModifyStatus(levelSetting); if (levelSettingSubjectViewList.Count > 0) { UnitOfWork.Delete(x => x.LevelSettingID == levelSetting.LevelSettingID); foreach (var levelSettingSubjectView in levelSettingSubjectViewList) { ER_LevelSettingSubject levelSettingSubject = new ER_LevelSettingSubject(); levelSettingSubject.LevelSettingSubjectID = Guid.NewGuid(); levelSettingSubject.LevelSettingID = levelSetting.LevelSettingID; levelSettingSubject.ExaminationSubjectID = levelSettingSubjectView.ExaminationSubjectID; levelSettingSubject.PassScore = levelSettingSubjectView.PassScore; SetNewStatus(levelSettingSubject); levelSettingSubjectList.Add(levelSettingSubject); //UnitOfWork.Add(levelSettingSubject); } } UnitOfWork.BulkInsert(levelSettingSubjectList); UnitOfWork.Commit(); } } catch (Exception) { throw; } } public void Delete(List LevelSettingIDList) { try { var ProjectScoreList = levelSettingSubjectDAL.projectScoreRepository.GetList(x => LevelSettingIDList.Contains(x.LevelSettingID)); if (ProjectScoreList.Count() > 0) { throw new Exception("选中的设置有已被使用的记录不能删除"); } UnitOfWork.Delete(x => LevelSettingIDList.Contains(x.LevelSettingID)); UnitOfWork.Delete(x => LevelSettingIDList.Contains(x.LevelSettingID)); } catch (Exception) { throw; } } public IGridResultSet GetLevelSettingSubjectViewGridByID(Guid? levelSettingID, int pageIndex, int pageSize) { var query = levelSettingSubjectDAL.GetLevelSettingSubjectViewByLevelID(levelSettingID); return query.OrderBy(x => x.ExaminationSubjectID).ToGridResultSet(pageIndex, pageSize); } public IGridResultSet GetExaminationSubjectDicSelect(Guid? examinationProjectID, int pageIndex, int pageSize) { var examinationSubjectIDList = levelSettingSubjectDAL.examinationProjectSubjectRepository.Entities.Where(x => x.ExaminationProjectID == examinationProjectID).Select(x => x.ExaminationSubjectID).ToList(); var query = dictionaryDAL.GetDictionaryItemQuery("EX_ExaminationSubject").Where(x => examinationSubjectIDList.Contains(x.Value)); return query.OrderBy(x => x.OrderNo).ToGridResultSet(pageIndex, pageSize); } public IGridResultSet GetLevelSettingSubjectViewGridByProjectID(ConfiguretView configuretView, Guid? examinationProjectID, int pageIndex, int pageSize) { var LevelSettingSubjectList = levelSettingSubjectDAL.GetLevelSettingSubjectViewByProjectID(examinationProjectID).ToList(); List subjectIDList = LevelSettingSubjectList.Select(x => x.ExaminationSubjectID).ToList(); var query = from a in levelSettingSubjectDAL.dictionaryItemRepository.GetList(x => x.DictionaryCode == "EX_ExaminationSubject" && subjectIDList.Contains(x.Value)) select new DictionaryItemView { DictionaryItemID = a.DictionaryItemID, DictionaryCode = a.DictionaryCode, Code = a.Code, DictionaryName = a.Sys_Dictionary.Name, Value = a.Value, IsEditable = a.IsEditable.Value, IsVisible = a.RecordStatus > 0, Name = a.Name, OrderNo = a.OrderNo, RecordStatus = a.RecordStatus, }; return query.OrderBy(x => x.Value).ToGridResultSet(pageIndex, pageSize); } } }