using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.DataLogic.TerminatePrinter; using EMIS.ViewModel.TerminatePrinter; using EMIS.ViewModel; using EMIS.Entities; namespace EMIS.CommonLogic.TerminatePrinter { public class PrintControlServices : BaseServices, IPrintControlServices { public PrintControlDAL PrintControlDAL { get; set; } public IGridResultSet GetPrintControlViewGrid(ConfiguretView conditionView, int? yearID, int? pageIndex, int? pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (yearID.HasValue) { exp = exp.And(x => x.YearID == yearID); } var query = PrintControlDAL.GetPrintControlViewQueryable(exp); if (!string.IsNullOrEmpty(conditionView.ConditionValue)) query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue.Trim()); query = query.OrderByDescending(x => x.YearID); return query.ToGridResultSet(pageIndex, pageSize); } public PrintControlView GetPrintControlView(Guid? printControlID) { return PrintControlDAL.GetPrintControlViewQueryable(x => x.PrintControlID == printControlID).FirstOrDefault(); } public void Save(PrintControlView printControlView) { try { Tem_PrintControl dupPrintControl = PrintControlDAL.PrintControlRepository.Entities.Where(x => x.YearID == printControlView.YearID && x.PrintControlID != printControlView.PrintControlID).FirstOrDefault(); if (dupPrintControl != null) { throw new Exception("已经存在" + printControlView.YearID.ToString() + "年级的设置,不能保存。"); } Tem_PrintControl printControl = null; if (printControlView.PrintControlID == null || printControlView.PrintControlID == Guid.Empty) { printControl = new Tem_PrintControl(); printControl.PrintControlID = Guid.NewGuid(); SetNewStatus(printControl); UnitOfWork.Add(printControl); } else { printControl = this.PrintControlDAL.PrintControlRepository.GetSingle(x => x.PrintControlID == printControlView.PrintControlID); if (printControl == null) { throw new Exception("未找到相对应的等级成绩。"); } SetModifyStatus(printControl); } printControl.YearID = printControlView.YearID; printControl.Times = printControlView.Times; UnitOfWork.Commit(); } catch (Exception) { throw; } } public void Delete(IList printControlIDList) { if (printControlIDList.Count > 0) { UnitOfWork.Delete(x => printControlIDList.Contains(x.PrintControlID)); } } } }