using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.DQPSystem; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.Entities; using Bowin.Common.Linq; using EMIS.DataLogic.DQPSystem; using EMIS.CommonLogic.SystemServices; namespace EMIS.CommonLogic.DQPSystem { public class SOCDetailServices : BaseServices, ISOCDetailServices, IFileUploadServices { public SOCDetailDAL SOCDetailDAL { get; set; } public SOCDAL SOCDAL { get; set; } public IRoleServices RoleServices { get; set; } public IGridResultSet GetSOCDetailViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? staffID, int pageIndex, int pageSize) { Expression> exp = x => true; var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; if (schoolyearID.HasValue) { exp = exp.And(x => x.DQP_SOC.SchoolyearID == schoolyearID); } if (coursematerialID.HasValue) { exp = exp.And(x => x.DQP_SOC.CoursematerialID == coursematerialID); } if (collegeID.HasValue) { exp = exp.And(x => x.DQP_SOC.CF_Department.CollegeID == collegeID); } if (staffID.HasValue) { exp = exp.And(x => x.DQP_SOC.DQP_SOCStaff.Any(y => y.UserID == staffID)); } var role = RoleServices.GetEnabledTeacherRoleViewList(); var teacherRole = role.Where(x => x.RoleName == "教师"); var query = SOCDetailDAL.GetSOCDetailViewQueryable(exp); if (curUser.RoleID == teacherRole.FirstOrDefault().RoleID) { exp = exp.And(x => x.CreateUserID == curUser.UserID); exp = exp.And(x => x.DQP_SOC.DQP_SOCStaff.Any(y => y.UserID == curUser.UserID)); query = SOCDetailDAL.GetSOCDetailViewQueryable(exp); } else { query = this.GetQueryByDataRangeByDepartment(query); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } //query = this.GetQueryByDataRangeByDepartment(query); var result = query .OrderBy(x => x.SchoolyearCode.Length) .ThenByDescending(x => x.SchoolyearCode).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.Name.Length).ThenBy(x => x.Name) .ToGridResultSet(pageIndex, pageSize); return result; } public IGridResultSet GetSOCDetailViewByIDGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? socID, Guid? userID, int pageIndex, int pageSize) { Expression> exp = x => true; if (schoolyearID.HasValue) { exp = exp.And(x => x.DQP_SOC.SchoolyearID == schoolyearID); } if (socID.HasValue) { exp = exp.And(x => x.SOCID == socID); } if (userID.HasValue) { exp = exp.And(x => x.DQP_SOC.DQP_SOCStaff.Any(y => y.UserID == userID)); exp = exp.And(x => x.CreateUserID == userID); } var query = SOCDetailDAL.GetSOCDetailViewQueryable(exp); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } //query = this.GetQueryByDataRangeByDepartment(query); var result = query .OrderBy(x => x.SchoolyearCode.Length) .ThenByDescending(x => x.SchoolyearCode).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.Name.Length).ThenBy(x => x.Name) .ToGridResultSet(pageIndex, pageSize); return result; } public List GetSOCDetailViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? staffID, List idList) { Expression> exp = x => true; var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; if (schoolyearID.HasValue) { exp = exp.And(x => x.DQP_SOC.SchoolyearID == schoolyearID); } if (coursematerialID.HasValue) { exp = exp.And(x => x.DQP_SOC.CoursematerialID == coursematerialID); } if (collegeID.HasValue) { exp = exp.And(x => x.DQP_SOC.CF_Department.CollegeID == collegeID); } if (staffID.HasValue) { exp = exp.And(x => x.DQP_SOC.DQP_SOCStaff.Any(y => y.UserID == staffID)); } if (idList.Count > 0) { exp = exp.And(x => idList.Contains(x.SOCDetailID)); } var role = RoleServices.GetEnabledTeacherRoleViewList(); var teacherRole = role.Where(x => x.RoleName == "教师"); var query = SOCDetailDAL.GetSOCDetailViewQueryable(exp); if (curUser.RoleID == teacherRole.FirstOrDefault().RoleID) { exp = exp.And(x => x.CreateUserID == curUser.UserID); exp = exp.And(x => x.DQP_SOC.DQP_SOCStaff.Any(y => y.UserID == curUser.UserID)); query = SOCDetailDAL.GetSOCDetailViewQueryable(exp); } else { query = this.GetQueryByDataRangeByDepartment(query); } //var query = SOCDetailDAL.GetSOCDetailViewQueryable(exp); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = query .OrderBy(x => x.SchoolyearCode.Length) .ThenByDescending(x => x.SchoolyearCode).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode) .ToList(); return result; } public SOCDetailView GetSOCDetailView(Guid? SOCDetailID) { Expression> exp = x => true; if (SOCDetailID.HasValue) { exp = exp.And(x => x.SOCDetailID == SOCDetailID); } var query = SOCDetailDAL.GetSOCDetailViewQueryable(exp).FirstOrDefault(); return query; } public void SOCDetailEdit(SOCDetailView SOCDetailView, List fileList) { try { var detail = SOCDetailDAL.SOCDetailRepository.GetSingle(x => x.SOCDetailID == SOCDetailView.SOCDetailID, x => x.DQP_SOCDetailAttachment); if (detail != null) { detail.Name = SOCDetailView.Name; //detail.Credit = SOCDetailView.Credit; detail.Description = SOCDetailView.Description; detail.IsGroup = SOCDetailView.IsGroupin; detail.StartTime = SOCDetailView.StartTime; detail.EndTime = SOCDetailView.EndTime; this.SetModifyStatus(detail); if (SOCDetailView.IsChangeAttachment == 1) { UnitOfWork.Remove(x => x.SOCDetailID == SOCDetailView.SOCDetailID); foreach (var file in fileList) { DQP_SOCDetailAttachment attachment = new DQP_SOCDetailAttachment(); if (!detail.DQP_SOCDetailAttachment.Any(x => x.SOCDetailAttachmentID == file.FileID)) { //新增 attachment.SOCDetailAttachmentID = file.FileID; attachment.SOCDetailID = file.FormID; attachment.Name = file.FileName; attachment.Url = file.FileUrl; this.SetNewStatus(attachment); detail.DQP_SOCDetailAttachment.Add(attachment); } } } } UnitOfWork.Commit(); } catch (Exception) { throw; } } public void SOCDetailAttachmentSave(Guid? SOCDetailID, List fileList) { var detail = SOCDetailDAL.SOCDetailRepository.GetSingle(x => x.SOCDetailID == SOCDetailID, x => x.DQP_SOCDetailAttachment); if (detail != null) { UnitOfWork.Delete(x => x.SOCDetailID == SOCDetailID); foreach (var file in fileList) { DQP_SOCDetailAttachment attachment = new DQP_SOCDetailAttachment(); attachment.SOCDetailAttachmentID = Guid.NewGuid(); attachment.SOCDetailID = file.FormID; attachment.Name = file.FileName; attachment.Url = file.FileUrl; this.SetNewStatus(attachment); detail.DQP_SOCDetailAttachment.Add(attachment); } } UnitOfWork.Commit(); } public void SOCDetailDelete(List idList) { UnitOfWork.Delete(w => idList.Contains(w.SOCDetailID)); } public List GetFileList(Guid? formID) { //var socDetailAttachment = SOCDAL.SOCDetailAttachmentRepository.GetSingle(x => x.SOCDetailID == formID); var fileList = SOCDAL.GetSOCDetailAttachmentView(x => x.SOCDetailID == formID).ToList(); return fileList; } public IGridResultSet GetSOCDetailAttachmentViewList(ConfiguretView studentAttachmentConditionView, Guid? socDetailID, int? pageIndex, int? pageSize) { if (!socDetailID.HasValue) { return new GridResultSet(); } Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.SOCDetailID == socDetailID); var query = SOCDetailDAL.GetSOCDetailAttachmentView(exp); return query.ToGridResultSet(pageIndex, pageSize); } } }