123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using EMIS.DataLogic.ScoreManage;
- using EMIS.ViewModel;
- using Bowin.Common.Linq.Entity;
- using EMIS.Entities;
- using EMIS.ViewModel.ScoreManage;
- using EMIS.DataLogic.ExaminationApply;
- using System.Linq.Expressions;
- using Bowin.Common.Linq;
- namespace EMIS.CommonLogic.ScoreManage
- {
- public class LevelSettingServices: BaseServices,ILevelSettingServices
- {
- public LevelSettingDAL levelSettingDAL { get; set; }
- public ExaminationSubjectDAL ExaminationSubjectDAL { get; set; }
- public Bowin.Common.Linq.Entity.IGridResultSet<LevelSettingView> GetLevelSettingGrid(ViewModel.ConfiguretView configuretView, Guid? examinationSubjectID, int pageIndex, int pageSize)
- {
- Expression<Func<ER_LevelSetting, bool>> exp = x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE;
- if (examinationSubjectID.HasValue)
- {
- exp = exp.And(x => x.ExaminationSubjectID == examinationSubjectID);
- }
- var query = levelSettingDAL.GetLevelSettingViewQueryable(exp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- return query.OrderByDescending(x => x.ExaminationSubjectName).ThenByDescending(x => x.MaxScore).ThenByDescending(x => x.MinScore).ToGridResultSet<LevelSettingView>(pageIndex, pageSize);
- }
- public LevelSettingView GetLevelSettingView(Guid? LevelSettingID)
- {
- var query = levelSettingDAL.GetLevelSettingViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).Where(x => x.LevelSettingID == LevelSettingID).FirstOrDefault();
- return query;
- }
- public ER_LevelSetting GetLevelSettingEntity(Guid? LevelSettingID)
- {
- return levelSettingDAL.levelSettingRepository.GetSingle(x => x.LevelSettingID == LevelSettingID);
- }
- public void Save(LevelSettingView levelSettingView)
- {
- try
- {
-
- var query = levelSettingDAL.GetLevelSettingViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE&&x.ExaminationSubjectID==levelSettingView.ExaminationSubjectID).ToList();
- //修改的时候排除本身
- if (levelSettingView != null)
- {
- query = query.Where(x => x.LevelSettingID != levelSettingView.LevelSettingID).ToList();
- }
- foreach (var LevelSetting in query)
- {
- if ((LevelSetting.MaxScore >= levelSettingView.MaxScore && LevelSetting.MinScore <= levelSettingView.MaxScore)
- || (LevelSetting.MaxScore >= levelSettingView.MinScore && LevelSetting.MinScore <= levelSettingView.MinScore))
- throw new Exception(string.Format("{0}分数段{1}与{2}<=总成绩<={3}分数段有重合。", LevelSetting.LevelName, LevelSetting.ScoreRange.Replace(" ", ""), levelSettingView.MinScore, levelSettingView.MaxScore));
- }
- ER_LevelSetting levelSettingEntity = null;
- if (levelSettingView.LevelSettingID == null || levelSettingView.LevelSettingID == Guid.Empty)
- {
- levelSettingEntity = new ER_LevelSetting();
- levelSettingEntity.LevelSettingID = Guid.NewGuid();
- SetNewStatus(levelSettingEntity);
- UnitOfWork.Add(levelSettingEntity);
- }
- else
- {
- levelSettingEntity = GetLevelSettingEntity(levelSettingView.LevelSettingID);
- if (levelSettingEntity == null)
- throw new Exception("未找到相对应的等级成绩设置!");
- SetModifyStatus(levelSettingEntity);
- }
- //if (levelSettingEntity.ExaminationSubjectID == null)
- //{
- // EX_ExaminationSubject examinationSubject = ExaminationSubjectDAL.ExaminationSubjectRepository.Entities.Where(x => x.Name == levelSettingView.ExaminationSubjectName).OrderByDescending(x=>x.CreateTime).FirstOrDefault();
- // levelSettingEntity.ExaminationSubjectID = levelSettingView.ExaminationSubjectID;
- //}
- //else
- //{
- // levelSettingEntity.ExaminationSubjectID = levelSettingView.ExaminationSubjectID;
- //}
- levelSettingEntity.ExaminationSubjectID = levelSettingView.ExaminationSubjectID;
- levelSettingEntity.LevelName = levelSettingView.LevelName;
- levelSettingEntity.LevelNum = levelSettingView.LevelNo;
- levelSettingEntity.MaxScore = levelSettingView.MaxScore;
- levelSettingEntity.MinScore = levelSettingView.MinScore;
- levelSettingEntity.Remark = levelSettingView.Remark;
- UnitOfWork.Commit();
- }
- catch (Exception)
- {
- throw;
- }
- }
- public void Delete(IList<Guid?> levelSettingID)
- {
- if (levelSettingID.Count > 0)
- {
- UnitOfWork.Delete<ER_LevelSetting>(x => levelSettingID.Contains(x.LevelSettingID));
- }
- }
- }
- }
|