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.ViewModel.PaymentManage; using EMIS.ViewModel; using EMIS.Entities; using EMIS.DataLogic.PaymentManage; namespace EMIS.CommonLogic.PaymentManage { public class WorktimeRateServices : BaseServices, IWorktimeRateServices { public WorktimeRateDAL WorktimeRateDAL { get; set; } public IGridResultSet GetWorktimeRateViewList(ConfiguretView worktimeRateConditionView, Guid? collegeID, int? teachingModeID, int? teachingMethodID, int? paymentLevelID, int? pageIndex, int? pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { exp = exp.And(x => x.CollegeID == collegeID); } if (teachingModeID.HasValue) { exp = exp.And(x => x.TeachingModeID == teachingModeID); } if (teachingMethodID.HasValue) { exp = exp.And(x => x.TeachingMethodID == teachingMethodID); } if (paymentLevelID.HasValue) { exp = exp.And(x => x.PaymentLevelID == paymentLevelID); } var query = WorktimeRateDAL.GetWorktimeRateViewQueryable(exp); if (!string.IsNullOrEmpty(worktimeRateConditionView.ConditionValue) && !string.IsNullOrEmpty(worktimeRateConditionView.Attribute)) query = query.DynamicWhere(worktimeRateConditionView.Attribute, worktimeRateConditionView.Condition, worktimeRateConditionView.ConditionValue); query = this.GetQueryByDataRangeByCollege(query); query = query.OrderBy(x => x.CollegeNo.Length) .ThenBy(x => x.CollegeNo) .ThenBy(x => x.TeachingModeID) .ThenBy(x => x.TeachingMethodID) .ThenBy(x => x.PaymentLevelID) .ThenBy(x => x.StudentCountStart); return query.ToGridResultSet(pageIndex, pageSize); } public List GetWorktimeRateViewList(ConfiguretView worktimeRateConditionView, Guid? collegeID, int? teachingModeID, int? teachingMethodID, int? paymentLevelID) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { exp = exp.And(x => x.CollegeID == collegeID); } if (teachingModeID.HasValue) { exp = exp.And(x => x.TeachingModeID == teachingModeID); } if (teachingMethodID.HasValue) { exp = exp.And(x => x.TeachingMethodID == teachingMethodID); } if (paymentLevelID.HasValue) { exp = exp.And(x => x.PaymentLevelID == paymentLevelID); } var query = WorktimeRateDAL.GetWorktimeRateViewQueryable(exp); if (!string.IsNullOrEmpty(worktimeRateConditionView.ConditionValue) && !string.IsNullOrEmpty(worktimeRateConditionView.Attribute)) query = query.DynamicWhere(worktimeRateConditionView.Attribute, worktimeRateConditionView.Condition, worktimeRateConditionView.ConditionValue); query = this.GetQueryByDataRangeByCollege(query); query = query.OrderBy(x => x.CollegeNo.Length) .ThenBy(x => x.CollegeNo) .ThenBy(x => x.TeachingModeID) .ThenBy(x => x.TeachingMethodID) .ThenBy(x => x.PaymentLevelID) .ThenBy(x => x.StudentCountStart); return query.ToList(); } public WorktimeRateView GetWorktimeRateView(Guid? worktimeRateID) { var query = WorktimeRateDAL.GetWorktimeRateViewQueryable(x => x.WorktimeRateID == worktimeRateID); return query.FirstOrDefault(); } public void Save(WorktimeRateView worktimeRateView) { TP_WorktimeRate worktimeRate = new TP_WorktimeRate(); var dupWorktimeRate = WorktimeRateDAL.WorktimeRateRepository.GetSingle(x => x.CollegeID == worktimeRateView.CollegeID && x.TeachingModeID == worktimeRateView.TeachingModeID && x.TeachingMethodID == worktimeRateView.TeachingMethodID && x.PaymentLevelID == worktimeRateView.PaymentLevelID && ( (worktimeRateView.StudentCountEnd == null || x.StudentCountStart <= worktimeRateView.StudentCountEnd) && (x.StudentCountEnd == null || x.StudentCountEnd >= worktimeRateView.StudentCountStart) ) && x.WorktimeRateID != worktimeRateView.WorktimeRateID ); if (dupWorktimeRate != null) { throw new Exception("已有相同的工作量系数设置,请勿重复设置。"); } if (worktimeRateView.WorktimeRateID == null || worktimeRateView.WorktimeRateID == Guid.Empty) { worktimeRate = new TP_WorktimeRate(); worktimeRate.WorktimeRateID = Guid.NewGuid(); SetNewStatus(worktimeRate); UnitOfWork.Add(worktimeRate); } else { worktimeRate = WorktimeRateDAL.WorktimeRateRepository.GetSingle(x => x.WorktimeRateID == worktimeRateView.WorktimeRateID); if (worktimeRate == null) { throw new Exception("未能找到需要修改的数据,数据可能已被其他用户更改。"); } SetModifyStatus(worktimeRate); } worktimeRate.CollegeID = worktimeRateView.CollegeID; worktimeRate.TeachingModeID = worktimeRateView.TeachingModeID; worktimeRate.TeachingMethodID = worktimeRateView.TeachingMethodID; worktimeRate.PaymentLevelID = worktimeRateView.PaymentLevelID; worktimeRate.StudentCountStart = worktimeRateView.StudentCountStart; worktimeRate.StudentCountEnd = worktimeRateView.StudentCountEnd; worktimeRate.WorktimeRate = worktimeRateView.WorktimeRate; UnitOfWork.Commit(); } public void Delete(IList worktimeRateIDList) { if (worktimeRateIDList.Count > 0) { UnitOfWork.Delete(x => worktimeRateIDList.Contains(x.WorktimeRateID)); } } } }