using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.SupervisionManage; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.Entities; using EMIS.DataLogic.SupervisionManage; using EMIS.CommonLogic.SystemServices; using EMIS.CommonLogic.CalendarManage; using System.Web; namespace EMIS.CommonLogic.SupervisionManage { public class ProjectRecordServices : BaseServices, IProjectRecordServices, IFileUploadServices { public ProjectRecordDAL projectRecordDAL { get; set; } public ISchoolYearServices schoolYearServices { get; set; } public IGridResultSet GetProjectRecordViewGrid(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID, int? supervisionType, Guid? supervisionCollegeID, DateTime? startDate, DateTime? endDate,int DataRange, int? pageIndex = null, int? pageSize = null) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> supervisorExp = (x => true); if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { supervisorExp = supervisorExp.And(x => x.CollegeID == collegeID); } if (supervisionType.HasValue) { exp = exp.And(x => x.SupervisionTypeID == supervisionType); } if (supervisionCollegeID.HasValue) { exp = exp.And(x => x.SupervisionCollegeID == supervisionCollegeID); } if (startDate.HasValue) { exp = exp.And(x => x.ProjectDate >= startDate); } if (endDate.HasValue) { var correctEndDate = endDate.Value.Date.AddDays(1); exp = exp.And(x => x.ProjectDate < correctEndDate); } var query = projectRecordDAL.GetProjectRecordViewQueryable(exp, supervisorExp,null,null); if (DataRange == (int)SYS_DataRange.Teacher) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var curUserID = curUser.UserID; query = projectRecordDAL.GetProjectRecordViewQueryable(exp, supervisorExp, curUserID,null); } if(DataRange != (int)SYS_DataRange.All&&DataRange!=(int)SYS_DataRange.Teacher) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var curUserID = curUser.UserID; var CollegeID = projectRecordDAL.StaffRepository.GetList(x => x.UserID == curUserID).Select(w => w.CollegeID).FirstOrDefault(); query = projectRecordDAL.GetProjectRecordViewQueryable(exp, supervisorExp, curUserID, CollegeID); } if (!string.IsNullOrEmpty(conditionView.ConditionValue)) { query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue); } //query = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo) // .ThenBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode); query=query.OrderByDescending(x => x.SchoolyearID).OrderByDescending(x => x.CreateTime); return query.ToGridResultSet(pageIndex, pageSize); } public List GetProjectRecordViewList(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID, int? supervisionType, Guid? supervisionCollegeID, DateTime? startDate, DateTime? endDate, List idList, int DataRange) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> supervisorExp = (x => true); if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { supervisorExp = supervisorExp.And(x => x.CollegeID == collegeID); } if (supervisionType.HasValue) { exp = exp.And(x => x.SupervisionTypeID == supervisionType); } if (supervisionCollegeID.HasValue) { exp = exp.And(x => x.SupervisionCollegeID == supervisionCollegeID); } if (startDate.HasValue) { exp = exp.And(x => x.ProjectDate >= startDate); } if (endDate.HasValue) { var correctEndDate = endDate.Value.Date.AddDays(1); exp = exp.And(x => x.ProjectDate < correctEndDate); } if (idList != null && idList.Count > 0) { exp = exp.And(x => idList.Contains(x.ProjectRecordID)); } var query = projectRecordDAL.GetProjectRecordViewQueryable(exp, supervisorExp, null,null); if (DataRange == (int)SYS_DataRange.Teacher) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var curUserID = curUser.UserID; var User = projectRecordDAL.UserRepository.Entities.Where(x => x.UserID == curUserID).FirstOrDefault(); query = projectRecordDAL.GetProjectRecordViewQueryable(exp, supervisorExp, curUserID,null); } if (DataRange != (int)SYS_DataRange.All && DataRange != (int)SYS_DataRange.Teacher) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var curUserID = curUser.UserID; var CollegeID = projectRecordDAL.StaffRepository.GetList(x => x.UserID == curUserID).Select(w => w.CollegeID).FirstOrDefault(); query = projectRecordDAL.GetProjectRecordViewQueryable(exp, supervisorExp, curUserID, CollegeID); } if (!string.IsNullOrEmpty(conditionView.ConditionValue)) { query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue); } //query = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo) // .ThenBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode); query = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearID).OrderByDescending(x => x.CreateTime); return query.ToList(); } public ProjectRecordView GetProjectRecordView(Guid? projectRecordID) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> supervisorExp = (x => true); if(projectRecordID.HasValue) { exp = exp.And(x => x.ProjectRecordID == projectRecordID); } return projectRecordDAL.GetProjectRecordViewQueryable(exp, supervisorExp,null,null).FirstOrDefault(); } public void Save(ProjectRecordView projectRecordView, List teacherList, List fileList) { try { var schoolyear = schoolYearServices.GetCurrentSchoolYear(); if (projectRecordView.SupervisionTypeID == (int)SUP_SupervisionType.Evaluation) { SUP_ProjectRecord dbProjectRecordView = projectRecordDAL.ProjectRecordRepository.Entities.Where(x => x.ProjectRecordID != projectRecordView.ProjectRecordID && x.UserID == projectRecordView.UserID && x.SupervisionTypeID == projectRecordView.SupervisionTypeID && x.SchoolyearID == projectRecordView.SchoolyearID && x.CoursematerialID == projectRecordView.CoursematerialID).FirstOrDefault(); if (dbProjectRecordView != null) { throw new Exception("该教师对应的课程信息已经存在督导项目。"); } } SUP_ProjectRecord projectRecord = null; List addAttachmentList = new List(); var dbProjectRecord = projectRecordDAL.ProjectRecordRepository.GetSingle(x => x.ProjectRecordID == projectRecordView.ProjectRecordID); if (dbProjectRecord == null) { projectRecord = new SUP_ProjectRecord(); projectRecord.ProjectRecordID = Guid.NewGuid(); SetNewStatus(projectRecord); UnitOfWork.Add(projectRecord); } else { projectRecord = this.projectRecordDAL.ProjectRecordRepository .GetSingle(x => x.ProjectRecordID == projectRecordView.ProjectRecordID, (x => x.SUP_ProjectRecord_CF_Staff), (x => x.SUP_ProjectRecordAttachment)); if (projectRecord == null) { throw new Exception("当前编辑的记录可能已被其他人删除。"); } projectRecord.SUP_ProjectRecord_CF_Staff = new HashSet(); SetModifyStatus(projectRecord); } projectRecord.SchoolyearID = projectRecordView.SchoolyearID;//schoolyear.SchoolYearID; projectRecord.ProjectDate = projectRecordView.ProjectDate; projectRecord.Location = projectRecordView.Location; projectRecord.SupervisionCollegeID = projectRecordView.SupervisionCollegeID; projectRecord.SupervisionTypeID = projectRecordView.SupervisionTypeID; projectRecord.UserID = projectRecordView.UserID; projectRecord.TotalScore = projectRecordView.TotalScore; projectRecord.CoursematerialID = projectRecordView.CoursematerialID; projectRecord.OtherTarget = projectRecordView.OtherTarget; projectRecord.Weekday = projectRecordView.Weekday; projectRecord.CoursesTimeID = projectRecordView.CoursesTimeID; projectRecord.Content = HttpUtility.HtmlDecode(projectRecordView.Content); //projectRecordView.Content; projectRecord.Advise = HttpUtility.HtmlDecode(projectRecordView.Advise); //projectRecordView.Advise; HashSet addStaff = new HashSet(); teacherList.ForEach(x => { CF_Staff staff = projectRecordDAL.StaffRepository.GetSingle(y => y.UserID == x.UserID); //educationMissionClassCheck.Sys_User = new HashSet(); addStaff.Add(staff); }); projectRecord.SUP_ProjectRecord_CF_Staff = addStaff; projectRecord.SUP_ProjectRecordAttachment = new HashSet(); fileList.ToList().ForEach(x => { var attachment = new SUP_ProjectRecordAttachment(); attachment.ProjectRecordAttachmentID = Guid.NewGuid(); attachment.ProjectRecordID = projectRecord.ProjectRecordID; attachment.Name = x.FileName; attachment.Url = x.FileUrl; this.SetNewStatus(attachment); UnitOfWork.Add(attachment); }); UnitOfWork.Commit(); } catch (Exception) { throw; } } public void Delete(IList projectRecordIDList) { var projectRecordList = projectRecordDAL.ProjectRecordRepository.GetList(x => projectRecordIDList.Contains(x.ProjectRecordID), (x => x.SUP_ProjectRecord_CF_Staff)); foreach (var projectRecord in projectRecordList) { projectRecord.SUP_ProjectRecord_CF_Staff = new HashSet(); } UnitOfWork.Remove(x => projectRecordIDList.Contains(x.ProjectRecordID)); UnitOfWork.Remove(x => projectRecordIDList.Contains(x.ProjectRecordID)); UnitOfWork.Commit(); } public IGridResultSet GetProjectRecordTeacherViewGridByID(Guid? projectRecordID, int? pageIndex, int? pageSize) { return projectRecordDAL.GetProjectRecordTeacherView(projectRecordID).OrderBy(x => x.LoginID.Length).OrderBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize); } public IGridResultSet GetDefaultTeacherViewGrid(int? pageIndex, int? pageSize) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; return projectRecordDAL.GetDefaultTeacherView(curUser.UserID).OrderBy(x => x.LoginID.Length).OrderBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize); } public List GetFileList(Guid? formID) { //var socDetailAttachment = SOCDAL.SOCDetailAttachmentRepository.GetSingle(x => x.SOCDetailID == formID); var fileList = projectRecordDAL.GetProjectRecordAttachmentView(x => x.ProjectRecordID == formID).ToList(); return fileList; } } }