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.ViewModel.TerminatePrinter; using EMIS.ViewModel; using EMIS.DataLogic.TerminatePrinter; using EMIS.Entities; namespace EMIS.CommonLogic.TerminatePrinter { public class StudentPrintTimesServices : BaseServices, IStudentPrintTimesServices { public StudentPrintTimesDAL StudentPrintTimesDAL { get; set; } public IGridResultSet GetStudentPrintTimesViewGrid(ConfiguretView conditionView, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID, int? pageIndex, int? pageSize) { Expression> facultyExp = (x => true); Expression> gradeExp = (x => true); Expression> classExp = (x => true); if (collegeID.HasValue) { facultyExp = facultyExp.And(x => x.CollegeID == collegeID); } if (yearID.HasValue) { gradeExp = gradeExp.And(x => x.GradeID == yearID); } if (standardID.HasValue) { facultyExp = facultyExp.And(x => x.StandardID == standardID); } if (classmajorID.HasValue) { classExp = classExp.And(x => x.ClassmajorID == classmajorID); } var query = StudentPrintTimesDAL.GetStudentPrintTimesViewQueryable(facultyExp, gradeExp, classExp); if (!string.IsNullOrEmpty(conditionView.ConditionValue)) query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue.Trim()); query = query.OrderByDescending(x => x.YearID) .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo) .ThenBy(x => x.StandardID) .ThenBy(x => x.ClassmajorNo) .ThenBy(x => x.LoginID); return query.ToGridResultSet(pageIndex, pageSize); } public List GetStudentPrintTimesViewGrid(ConfiguretView conditionView, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID) { Expression> facultyExp = (x => true); Expression> gradeExp = (x => true); Expression> classExp = (x => true); if (collegeID.HasValue) { facultyExp = facultyExp.And(x => x.CollegeID == collegeID); } if (yearID.HasValue) { gradeExp = gradeExp.And(x => x.GradeID == yearID); } if (standardID.HasValue) { facultyExp = facultyExp.And(x => x.StandardID == standardID); } if (classmajorID.HasValue) { classExp = classExp.And(x => x.ClassmajorID == classmajorID); } var query = StudentPrintTimesDAL.GetStudentPrintTimesViewQueryable(facultyExp, gradeExp, classExp); if (!string.IsNullOrEmpty(conditionView.ConditionValue)) query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue.Trim()); query = query.OrderByDescending(x => x.YearID) .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo) .ThenBy(x => x.StandardID) .ThenBy(x => x.ClassmajorNo) .ThenBy(x => x.LoginID); return query.ToList(); } public StudentPrintMessageView GetStudentPrintMessageView(Guid userID) { return StudentPrintTimesDAL.GetStudentPrintMessageViewQueryable(x => x.UserID == userID).FirstOrDefault(); } public void Count(Guid userID) { Tem_StudentPrintTimes printTimes = this.StudentPrintTimesDAL.StudentPrintTimesRepository.GetSingle(x => x.UserID == userID); if (printTimes == null) { printTimes = new Tem_StudentPrintTimes() { StudentPrintTimesID = Guid.NewGuid(), UserID = userID, Times = 1, RecordStatus = (int)SYS_STATUS.UNUSABLE, CreateUserID = userID, CreateTime = DateTime.Now, }; this.UnitOfWork.Add(printTimes); } else { printTimes.Times++; } printTimes.ModifyUserID = userID; printTimes.ModifyTime = DateTime.Now; this.UnitOfWork.Commit(); } public void BatchUpdate(IList userIDList, int times) { var nullableUserIDList = userIDList.Select(x => (Guid?)x).ToList(); var printTimesList = this.StudentPrintTimesDAL.StudentPrintTimesRepository.GetList(x => nullableUserIDList.Contains(x.UserID)).ToList(); var updateList = (from printTimes in printTimesList from user in userIDList.Where(x => x == printTimes.UserID) select printTimes).ToList(); updateList.ForEach(x => { x.Times = times; this.SetModifyStatus(x); }); var insertList = (from user in userIDList from printTimes in printTimesList.Where(x => x.UserID == user).DefaultIfEmpty() where printTimes == null select new Tem_StudentPrintTimes { StudentPrintTimesID = Guid.NewGuid(), UserID = user, Times = times }).ToList(); insertList.ForEach(x => { this.SetNewStatus(x); }); UnitOfWork.BatchUpdate(updateList); UnitOfWork.BulkInsert(insertList); } } }