123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- 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<ProjectRecordView> GetProjectRecordViewGrid(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID, int? supervisionType,
- Guid? supervisionCollegeID, DateTime? startDate, DateTime? endDate,int DataRange, int? pageIndex = null, int? pageSize = null)
- {
- Expression<Func<SUP_ProjectRecord, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<CF_Staff, bool>> 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<ProjectRecordView> GetProjectRecordViewList(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID, int? supervisionType,
- Guid? supervisionCollegeID, DateTime? startDate, DateTime? endDate, List<Guid?> idList, int DataRange)
- {
- Expression<Func<SUP_ProjectRecord, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<CF_Staff, bool>> 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<Func<SUP_ProjectRecord, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<CF_Staff, bool>> 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<ProjectRecordTeacherView> teacherList, List<FileUploadView> 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<SUP_ProjectRecordAttachment> addAttachmentList = new List<SUP_ProjectRecordAttachment>();
- 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<CF_Staff>();
- 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<CF_Staff> addStaff = new HashSet<CF_Staff>();
- teacherList.ForEach(x =>
- {
- CF_Staff staff = projectRecordDAL.StaffRepository.GetSingle(y => y.UserID == x.UserID);
- //educationMissionClassCheck.Sys_User = new HashSet<Sys_User>();
- addStaff.Add(staff);
- });
- projectRecord.SUP_ProjectRecord_CF_Staff = addStaff;
- projectRecord.SUP_ProjectRecordAttachment = new HashSet<SUP_ProjectRecordAttachment>();
- 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<Guid?> 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<CF_Staff>();
- }
- UnitOfWork.Remove<SUP_ProjectRecordAttachment>(x => projectRecordIDList.Contains(x.ProjectRecordID));
- UnitOfWork.Remove<SUP_ProjectRecord>(x => projectRecordIDList.Contains(x.ProjectRecordID));
- UnitOfWork.Commit();
- }
- public IGridResultSet<ProjectRecordTeacherView> 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<ProjectRecordTeacherView> 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<FileUploadView> GetFileList(Guid? formID)
- {
- //var socDetailAttachment = SOCDAL.SOCDetailAttachmentRepository.GetSingle(x => x.SOCDetailID == formID);
- var fileList = projectRecordDAL.GetProjectRecordAttachmentView(x => x.ProjectRecordID == formID).ToList();
- return fileList;
- }
- }
- }
|