using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.SupervisionManage; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.SupervisionManage; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.Entities; using Bowin.Common.Linq; using EMIS.CommonLogic.SystemServices; namespace EMIS.CommonLogic.SupervisionManage { public class SupEvaluationServices : BaseServices, ISupEvaluationServices { public SupEvaluationDAL SupEvaluationDAL { get; set; } public IGridResultSet GetSupEvaluationViewGrid(ConfiguretView configuretView,Guid? schoolyearID, Guid? collegeID, DateTime? startTimes, DateTime? endTimes, int? SupervisionTypeID, int DataRange, int pageIndex, int pageSize) { Expression> lessonFilter = (x => true); Expression> projectFilter = (x => true); Expression> supervisorExp = (x => true); if (schoolyearID.HasValue) { lessonFilter = lessonFilter.And(x => x.SchoolyearID == schoolyearID); projectFilter = projectFilter.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { supervisorExp = supervisorExp.And(x => x.CollegeID == collegeID); } if(startTimes.HasValue) { lessonFilter = lessonFilter.And(x => x.LessonDate >= startTimes); projectFilter = projectFilter.And(x => x.ProjectDate >= startTimes); } if (endTimes.HasValue) { var endDate= endTimes.Value.AddDays(1); lessonFilter = lessonFilter.And(x => x.LessonDate < endDate); projectFilter = projectFilter.And(x => x.ProjectDate < endDate); } if(DataRange!=(int)SYS_DataRange.All) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var curUserID = curUser.UserID; lessonFilter = lessonFilter.And(x => x.UserID == curUserID); projectFilter = projectFilter.And(x => x.UserID == curUserID); } var query = SupEvaluationDAL.GetSupEvaluationViewQueryable(lessonFilter, projectFilter, supervisorExp); if (SupervisionTypeID.HasValue) { if (SupervisionTypeID == (int)SUP_EvaluationType.Lesson) { query = query.Where(x => x.SupervisionTypeID ==null); } else { query = query.Where(x => x.SupervisionTypeID == (int)SUP_SupervisionType.Evaluation); } } if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); var result = query.OrderByDescending(x => x.SchoolyearCode).ThenBy(x=>x.SupervisionCollegeName).ThenBy(x=>x.UserName) .ThenBy(x => x.CourseName).ThenByDescending(x => x.LessonDate).ToGridResultSet(pageIndex, pageSize); return result; } public List GetSupEvaluationViewGridList(ConfiguretView configuretView,Guid? schoolyearID, Guid? collegeID, DateTime? startTimes, DateTime? endTimes, int? SupervisionTypeID, int DataRange, List selectedLessonRecordID, List selectedProjectRecordID) { Expression> lessonFilter = (x => true); Expression> projectFilter = (x => true); Expression> supervisorExp = (x => true); if (schoolyearID.HasValue) { lessonFilter = lessonFilter.And(x => x.SchoolyearID == schoolyearID); projectFilter = projectFilter.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { supervisorExp = supervisorExp.And(x => x.CollegeID == collegeID); } if (startTimes.HasValue) { lessonFilter = lessonFilter.And(x => x.LessonDate >= startTimes); projectFilter = projectFilter.And(x => x.ProjectDate >= startTimes); } if (endTimes.HasValue) { lessonFilter = lessonFilter.And(x => x.LessonDate < endTimes.Value.AddDays(1)); projectFilter = projectFilter.And(x => x.ProjectDate < endTimes.Value.AddDays(1)); } if (DataRange != (int)SYS_DataRange.All) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var curUserID = curUser.UserID; lessonFilter = lessonFilter.And(x => x.UserID == curUserID); projectFilter = projectFilter.And(x => x.UserID == curUserID); } var query = SupEvaluationDAL.GetSupEvaluationViewQueryable(lessonFilter, projectFilter, supervisorExp); if (selectedLessonRecordID.Count > 0) { List LessonRecordIDList = new List(); foreach(var LessonRecordID in selectedLessonRecordID) { LessonRecordIDList.Add(LessonRecordID); } query = query.Where(x => LessonRecordIDList.Contains(x.LessonRecordID)); } if (selectedProjectRecordID.Count > 0) { List ProjectRecordIDList = new List(); foreach (var ProjectRecordID in selectedLessonRecordID) { ProjectRecordIDList.Add(ProjectRecordID); } query = query.Where(x => ProjectRecordIDList.Contains(x.ProjectRecordID)); } if (SupervisionTypeID.HasValue) { query = query.Where(x => x.SupervisionTypeID == SupervisionTypeID); } if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); return query.ToList(); } } }