using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using EMIS.Entities;
using Bowin.Common.Linq;
using Bowin.Common.Linq.Entity;
using EMIS.ViewModel;
using EMIS.DataLogic.EducationManage;
using EMIS.DataLogic.EducationSchedule;
using EMIS.DataLogic.SchedulingManage.SchedulingSettings;
using EMIS.ViewModel.EducationManagement;
using Bowin.Common.Utility;
using EMIS.Utility;
using Bowin.Common.DataTime;
using EMIS.DataLogic.Repositories;
using EMIS.ViewModel.CacheManage;
using EMIS.ViewModel.SchedulingManage.SchedulingSettings;
using EMIS.DataLogic.UniversityManage.TeacherManage;
using EMIS.DataLogic;
using EMIS.ViewModel.EducationManage;
using System.Data.Entity;
namespace EMIS.CommonLogic.EducationSchedule
{
public class EducationMissionClassScheduleAdultServices : BaseServices, IEducationMissionClassScheduleAdultServices
{
public AdultEducationMissionClassDAL educationMissionClassDAL { get; set; }
public EducationSchedulingClassRepository educationSchedulingClassRepository { get; set; }
public EducationMissionClassScheduleDAL educationMissionClassScheduleDAL { get; set; }
public EducationMissionClassSchedulingASdultDAL EducationMissionClassSchedulingASdultDAL { get; set; }
public CollegePriorityDAL collegePriorityDAL { get; set; }
public CoursematerialRepository coursematerialRepository { get; set; }
public ClassmajorRepository classmajorRepository { get; set; }
public ClassroomRepository classroomRepository { get; set; }
public SchoolyearRepository SchoolyearRepository { get; set; }
public CoursesTimeRepository coursesTimeRepository { get; set; }
public CourseTimeHoursDAL CourseTimeHoursDAL { get; set; }
public EducationMissionClassRepository educationMissionClassRepository { get; set; }
public EducationMissionRepository educationMissionRepository { get; set; }
public StaffDAL staffDAL { get; set; }
public CollegeRepository CollegeRepository { get; set; }
public AdultEducationScheduleRepository adultEducationScheduleRepository { get; set; }
public AdultEducationScheduleTeacherRepository AdultEducationScheduleTeacherRepository { get; set; }
public EducationSchedulingClassDAL EducationSchedulingClassDAL { get; set; }
///
/// 列表查询
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
public Bowin.Common.Linq.Entity.IGridResultSet GetEducationMissionClassScheduleViewGrid(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolyearID, Guid? departmentID, Guid? coursematerialID, int? approvalStatus, int? teachingModeID, Guid? grademajorID, int? gradeYearID, int? StandardID, Guid? CoursesTimeID,int? learningformID, int? education, string LearnSystem, int pageIndex, int pageSize)
{
Expression> exp = (x => true);
Expression> executablePlanExp = (x => true);
Expression> executableOptionalCourseExp = (x => true);
Expression> executableFreeSelectionCourseCourseExp = (x => true);
//if(StandardID.HasValue)
//{
// executablePlanExp = executablePlanExp.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == StandardID);
//}
if (campusID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.CF_College.CampusID == campusID);
}
if (collegeID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.CollegeID == collegeID);
}
if (departmentID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.DepartmentID == departmentID);
}
if (gradeYearID.HasValue)
{
//exp = exp.And(x => x.EM_ExecutablePlan.CF_Grademajor.SchoolyearID == gradeYearID);
executablePlanExp = executablePlanExp.And(x => x.CF_Grademajor.GradeID == gradeYearID);
executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.CF_Grademajor.GradeID == gradeYearID);
}
//if (grademajorID.HasValue)
//{
// //exp = exp.And(x => x.EM_ExecutablePlan.GrademajorID == grademajorID);
// executablePlanExp = executablePlanExp.And(x => x.GrademajorID == grademajorID);
// executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.GrademajorID == grademajorID);
//}
if (schoolyearID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
}
if (coursematerialID.HasValue)
{
exp = exp.And(x => x.CoursematerialID == coursematerialID);
executablePlanExp = executablePlanExp.And(x => x.CoursematerialID == coursematerialID);
executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.EM_OptionalCoursePlan.CoursematerialID == coursematerialID);
executableFreeSelectionCourseCourseExp = executableFreeSelectionCourseCourseExp.And(x => x.EM_FreeSelectionCouse.CoursematerialID == coursematerialID);
}
if (approvalStatus.HasValue)
{
exp = exp.And(x => x.RecordStatus == approvalStatus);
}
if (teachingModeID.HasValue)
{
exp = exp.And(x => x.TeachingModeID == teachingModeID);
}
if (CoursesTimeID.HasValue)
{
exp = exp.And(x => x.EM_CoursesTime.Any(c => c.CoursesTimeID == CoursesTimeID));
}
if (learningformID.HasValue)
exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID));
if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
{
var LearnSystems = Convert.ToDecimal(LearnSystem);
exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems));
}
if (education.HasValue)
{
exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.EducationID == education.Value));
}
var query = EducationMissionClassSchedulingASdultDAL.GetEducationMissionClassViewQuery(exp, executablePlanExp,
executableOptionalCourseExp, executableFreeSelectionCourseCourseExp);
if (StandardID.HasValue)
{
query = query.Where(x => x.StandardID == StandardID);
}
if (grademajorID.HasValue)
{
query = query.Where(x => x.GrademajorID == grademajorID);
}
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
var resultQuery = query.OrderByDescending(x => x.SchoolyearCode)
.ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
.ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name);
var result = resultQuery.ToGridResultSet(pageIndex, pageSize);
var educationMissionClassID = result.rows.Select(x => x.EducationMissionClassID).ToList();
var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
result.rows.ForEach(x => x.MissionClassTeacherView = new HashSet(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
return result;
}
///
/// 导出查询
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
public List GetEducationMissionClassScheduleViewGridExcel(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolyearID, Guid? departmentID, Guid? coursematerialID, int? approvalStatus, int? teachingModeID, Guid? grademajorID, int? gradeYearID, int? StandardID, List EducationMissionClassList, Guid? CoursesTimeID, int? learningformID, int? education, string LearnSystem)
{
Expression> exp = (x => true);
Expression> executablePlanExp = (x => true);
Expression> executableOptionalCourseExp = (x => true);
Expression> executableFreeSelectionCourseCourseExp = (x => true);
if (EducationMissionClassList != null)
{
exp = exp.And(x => EducationMissionClassList.Contains(x.EducationMissionClassID));
}
else{
if (campusID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.CF_College.CampusID == campusID);
}
if (collegeID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.CollegeID == collegeID);
}
if (departmentID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.DepartmentID == departmentID);
}
if (gradeYearID.HasValue)
{
executablePlanExp = executablePlanExp.And(x => x.CF_Grademajor.GradeID == gradeYearID);
executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.CF_Grademajor.GradeID == gradeYearID);
}
if (grademajorID.HasValue)
{
executablePlanExp = executablePlanExp.And(x => x.GrademajorID == grademajorID);
executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.GrademajorID == grademajorID);
}
if (schoolyearID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
}
if (coursematerialID.HasValue)
{
exp = exp.And(x => x.CoursematerialID == coursematerialID);
executablePlanExp = executablePlanExp.And(x => x.CoursematerialID == coursematerialID);
executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.EM_OptionalCoursePlan.CoursematerialID == coursematerialID);
executableFreeSelectionCourseCourseExp = executableFreeSelectionCourseCourseExp.And(x => x.EM_FreeSelectionCouse.CoursematerialID == coursematerialID);
}
if (approvalStatus.HasValue)
{
exp = exp.And(x => x.RecordStatus == approvalStatus);
}
if (teachingModeID.HasValue)
{
exp = exp.And(x => x.TeachingModeID == teachingModeID);
}
if (CoursesTimeID.HasValue)
{
exp = exp.And(x => x.EM_CoursesTime.Any(c => c.CoursesTimeID == CoursesTimeID));
}
if (learningformID.HasValue)
exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID));
if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
{
var LearnSystems = Convert.ToDecimal(LearnSystem);
exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems));
}
if (education.HasValue)
{
exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.EducationID == education.Value));
}
}
var query = EducationMissionClassSchedulingASdultDAL.GetEducationMissionClassViewQueryblExcel(exp, executablePlanExp,
executableOptionalCourseExp, executableFreeSelectionCourseCourseExp);
//if (EducationMissionClassList != null)
//{
// query.Where(x => EducationMissionClassList.Contains(x.EducationMissionClassID));
//}
if (StandardID.HasValue)
{
query = query.Where(x => x.StandardID == StandardID);
}
var educationMissionClassID = query.Select(x => x.EducationMissionClassID).ToList();
var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode)
.ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
.ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name)
.ToList();
result.ForEach(x => x.MissionClassTeacherView = new HashSet(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
return result;
}
public void EducationMissionClassScheduleDelete(List missionClassID)
{
var missionClassList = educationMissionClassDAL.educationMissionClassRepository.GetList(x => missionClassID.Contains(x.EducationMissionClassID),
(x => x.CF_Classmajor),
(x => x.EM_EducationMission),
(x => x.EM_EducationMissionClassSettings),
(x => x.EM_EducationMissionClassTeachingSetting),
(x => x.EM_EducationSchedulingClass),
(x => x.EM_EducationSchedulingClass.Select(w => w.CF_Student)),
(x => x.EM_MissionClassTeacher),
(x => x.EM_CourseProcess),
(x => x.EM_CoursesTime),
(x => x.EM_CourseProcess.Select(y => y.EM_CourseProcessTeacher))).ToList();
var adultEducationScheduleIDList = adultEducationScheduleRepository.GetList(x=>missionClassID.Contains(x.EM_EducationSchedulingClass.EM_EducationMissionClass.EducationMissionClassID)).Select(w=>w.AdultEducationScheduleID).ToList();
foreach (var mid in missionClassID)
{
UnitOfWork.Delete(x => x.MissionClassID==mid);
}
foreach(var missionClass in missionClassList)
{
missionClass.RecordStatus = (int)EMIS.ViewModel.EM_EducationMissionClassStatus.Submitted;
this.SetModifyStatus(missionClass);
UnitOfWork.Delete(x => x.EducationMissionID == missionClass.EducationMissionID);
UnitOfWork.Delete(x => x.EducationMissionID == missionClass.EducationMissionID);
}
foreach (var mid in adultEducationScheduleIDList)
{
UnitOfWork.Delete(x => x.AdultEducationScheduleID == mid);
UnitOfWork.Delete(x =>x.AdultEducationScheduleID==mid);
}
UnitOfWork.Commit();
}
///
/// 教学任务导入
///
/// 导入的数据集合
/// 返回的操作失败集合
/// 操作成功记录条数
///
public void EducationMissionClassImport(out int OkCount, out List errdataList, out int successCount, string sourcePhysicalPath, string sourceWebPath, out string errorWebPath, out string Errinfo, Guid schoolyear)
{
var excel = new NpoiExcelHelper();
#region 1.0 单元格抬头
Dictionary cellheader = new Dictionary
{
{ "CollegeName", RSL.Get("College") }, { "Education", RSL.Get("CultureModel") },
{ "Learningform","学习形式" },{ "ClassNumStr", "班级人数" },
{ "Name", "任务班名称" },{ "CourseName", "课程名称" },
{ "TotalhoursStr", "总学时" },{ "ReferenceDays", "参考天数" },
{ "TeachingTime", "上课时间" },{ "ClassroomName", "课室" },
{ "TeacherNameString", "授课教师" },{"ExaminationModeStr","考试方式"},
{ "ExamWeek", "考试周次" },{ "ExamTime", "考试时间" },
{ "Assistant", "班主任" },{ "StandardName", "年级专业" },
{ "CourseCode", "课程代码" },{ "CourseTime", "课时类别" },
{ "TheoryCourseStr", "理论学时" },{ "PracticehoursStr", "实践学时" },
{ "TeachingDay", "执行天数" }, { "TeachingHours", "执行学时" },
{ "ErrorMessage", "错误信息" }
};
#endregion
StringBuilder errorMsg = new StringBuilder(); // 错误信息
List errList = new List();
DataTimeHelper dth = new DataTimeHelper();
#region 1.1解析文件,存放到一个List集合里
// 1.1解析文件,存放到一个List集合里
cellheader.Remove("ErrorMessage");//去除异常列、导入操作不需要
List enlist =
NpoiExcelHelper.ExcelToEntityList(cellheader, sourcePhysicalPath, out errorMsg, out errList);
cellheader.Add("ErrorMessage", "错误信息");//还原字典项
#endregion
#region 读取校验数据
if (enlist.Count() <= 0)
{
throw new Exception("请填写Excel模板信息数据。");
}
//任务班
var missionClassNameList = enlist.Select(x => x.Name).ToList();
var missionClassList = educationMissionClassDAL.educationMissionClassRepository.GetList(x => missionClassNameList.Contains(x.Name),
(x => x.CF_Classmajor),
(x => x.EM_EducationMission),
(x => x.EM_EducationMissionClassTeachingSetting),
(x => x.EM_EducationMissionClassSettings),
(x => x.EM_EducationSchedulingClass),
(x => x.EM_EducationSchedulingClass.Select(w => w.CF_Student)),
(x => x.EM_MissionClassTeacher),
(x => x.EM_CourseProcess),
(x => x.EM_CoursesTime),
(x => x.EM_CourseProcess.Select(y => y.EM_CourseProcessTeacher))).ToList();
var classmajorIDList = missionClassList.Select(w => w.MainScheduleClassID).ToList();
var classmajorList = this.classmajorRepository.GetList(x => classmajorIDList.Contains(x.ClassmajorID), (x => x.CF_Grademajor)).ToList();
//任务班年级
var gradeyearList = classmajorList.Select(x => x.CF_Grademajor.GradeID).Distinct().ToList();
//教师
var teacherNameList = enlist.Where(x => !string.IsNullOrEmpty(x.TeacherNameString))
.SelectMany(x => x.TeacherNameString.Split('\\').ToList()).Distinct().ToList();
var teacherList = staffDAL.staffRepository.GetList(x => teacherNameList.Contains(x.Sys_User.Name));
//教室
var ClassroomNameList = enlist.Select(x => x.ClassroomName);
var ClassroomName = classroomRepository.GetList(x => ClassroomNameList.Contains(x.Name),(x=>x.CF_ClassroomType)).ToList();
//课时类别
List CourseTimeHoursList = CourseTimeHoursDAL.GetCoursesTimeQueryable(x => x.RecordStatus > (int?)SYS_STATUS.UNUSABLE, w => w.RecordStatus > (int?)SYS_STATUS.UNUSABLE
&& (gradeyearList.Contains(w.Years))
).ToList();
//任务班ID
var missionClassIDList = missionClassList.Select(x=>x.EducationMissionClassID).ToList();
//排课班
var educationSchedulingClassIDList= educationSchedulingClassRepository.GetList(x=> missionClassIDList.Contains(x.EM_EducationMissionClass.EducationMissionClassID)).ToList();
//已排的课
var EducationScheduleList = adultEducationScheduleRepository.GetList(x => x.SchoolyearID == schoolyear, (x => x.EM_EducationSchedulingClass)).ToList();
//学年学期
var school= SchoolyearRepository.Entities.Where(x => x.SchoolyearID == schoolyear).FirstOrDefault();
#endregion
#region 1.2 将Excel数据写入数据库中
#region 1.2.1 对List集合进行有效性校验
#region 1.2.1.1检测必填项是否必填
for (int i = 0; i < enlist.Count; i++)
{
EducationMissionImportClassView en = enlist[i];
string errorMsgStr = "第" + (i + 2) + "行数据检测异常:";
en.ErrorMessage = errorMsgStr;
bool isHaveNoInputValue = false; // 是否含有未输入项
en.IsExcelVaildateOK = true;
if (string.IsNullOrEmpty(en.Name))
{
errorMsgStr += "任务班名称不能为空;";
isHaveNoInputValue = true;
}
if (string.IsNullOrEmpty(en.ClassroomName))
{
errorMsgStr += "课室不能为空;";
isHaveNoInputValue = true;
}
if (string.IsNullOrEmpty(en.TeacherNameString))
{
errorMsgStr += "授课教师不能为空;";
isHaveNoInputValue = true;
}
if (string.IsNullOrEmpty(en.TeachingTime))
{
errorMsgStr += "上课时间不能为空;";
isHaveNoInputValue = true;
}
#region 1.2.1.2 检测(数据唯一性、)
var missionClass = missionClassList.Where(x => x.Name == en.Name).FirstOrDefault();
var missionClassYear = missionClassList.Where(x => x.Name == en.Name && x.EM_EducationMission.SchoolyearID == schoolyear).FirstOrDefault();
//var missionStates
#region 任务班
if (!string.IsNullOrEmpty(en.Name))
{
if (missionClass==null)
{
errorMsgStr += "任务班不存在;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
if (missionClassYear == null)
{
errorMsgStr += "任务班的学年学期不是当前选中的学年学期;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
else
{
if (missionClassYear.EM_CoursesTime==null)
{
errorMsgStr += "请设置课时类别;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
}
//if (missionClass.ApprovalStatus == (int)EM_EducationMissionClassStatus.Scheduled)
//{
// errorMsgStr += "任务班状态为以排课状态,不能导入;";
// en.ErrorMessage = errorMsgStr;
// isHaveNoInputValue = true;
//}
//if (missionClass.ApprovalStatus == (int)EM_EducationMissionClassStatus.NotSubmitted)
//{
// errorMsgStr += "任务班状态为未提交状态,不能导入;";
// en.ErrorMessage = errorMsgStr;
// isHaveNoInputValue = true;
//}
}
#endregion
#region 课时类别
if (missionClassYear!=null)
{
if (missionClassYear.EM_CoursesTime.Count()!=0)
{
if (!string.IsNullOrEmpty(en.CourseTime))
{
var missionClassMainClassmajor = classmajorList.FirstOrDefault(x => x.ClassmajorID == missionClassYear.MainScheduleClassID);
var gradeYear = missionClassMainClassmajor.CF_Grademajor.GradeID;
if (CourseTimeHoursList.Count(x => x.Year == gradeYear) != 0)
{
var CourseTimeHours = CourseTimeHoursList.Where(x => x.time_starTime_endTime == en.CourseTime && x.Year == gradeYear).FirstOrDefault();
if(CourseTimeHours!=null){
en.CourseTimeID=CourseTimeHours.CoursesTimeID;
}
else
{
errorMsgStr += "请填写正确的课时类别;";
isHaveNoInputValue = true;
}
}
else
{
errorMsgStr += "该年级的课时类别找不到对应的学时转换设置,请检查学时转换设置;";
isHaveNoInputValue = true;
}
}
else
{
errorMsgStr += "课时类别不能为空;";
isHaveNoInputValue = true;
}
}
else
{
errorMsgStr += "任务班未设置课时类别,请去教学任务设置;";
isHaveNoInputValue = true;
}
}
#endregion
#region 课室
if (missionClassYear != null)
{
if (!string.IsNullOrEmpty(en.ClassroomName))
{
var ClassID = Guid.Empty;
var Classroom = ClassroomName.Where(x => x.Name == en.ClassroomName.Trim()).FirstOrDefault();
if (Classroom != null)
{
ClassID = ClassroomName.Where(x => x.CF_ClassroomType.Any(w => w.ClassroomID == Classroom.ClassroomID && w.ClassroomType == missionClassYear.ClassroomTypeID)).Select(t => t.ClassroomID).FirstOrDefault();
}
if (Classroom == null)
{
errorMsgStr += "课室不存在;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
else
{
if (ClassID == Guid.Empty)
{
errorMsgStr += "课室类型与任务班设置的教室类型不一致;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
else
{
en.ClassroomID = Classroom.ClassroomID;
}
}
}
}
#endregion
#region 上课时间
if (!string.IsNullOrEmpty(en.TeachingTime))
{
if (en.TeachingTime.Contains("日"))
{
en.TeachingTime.TrimEnd("日");
}
if (en.TeachingTime.Contains("月"))
{
List TimesSegment = en.TeachingTime.Split(',').ToList();
if (en.TeachingTime.Contains(",") && !en.TeachingTime.Contains(","))
{
TimesSegment = en.TeachingTime.Split(',').ToList();
}
List teachtingTime = new List();
for (int t = 0; t < TimesSegment.Count(); t++)
{
List month = TimesSegment[t].Split('月').ToList();
for (int m = 1; m < month.Count(); m++)
{
List day = month[m].Split('、').ToList();
for (int d = 0; d < day.Count(); d++)
{
teachtingTime.Add(month[0] + "月");
int index = teachtingTime.Count()-1;
teachtingTime[index] += day[d];
}
}
}
DateTime Date;
en.Time = new List();
foreach (var date in teachtingTime)
{
if (!DateTime.TryParse(date, out Date))
{
errorMsgStr += "上课时间格式不正确;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
break;
}
else
{
en.Time.Add(date);
if (dth.ToDateTimeValue(date) != string.Empty)
{
Date = Convert.ToDateTime(dth.ToDateTimeValue(date));
}
else
{
Date = Convert.ToDateTime(date);
}
if (missionClassYear != null && en.CourseTimeID != null)
{
var isok = EducationScheduleList.Where(x => x.ScheduleDate == Date && x.ClassroomID == en.ClassroomID && x.CoursesTimeID == en.CourseTimeID && x.EM_EducationSchedulingClass.EducationMissionClassID != missionClassYear.EducationMissionClassID).ToList();
if (isok.Count() != 0)
{
errorMsgStr += "该教室在该时间段已被使用;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
break;
}
}
}
}
}
if (!en.TeachingTime.Contains("月"))
{
errorMsgStr += "上课时间格式不正确;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
if (en.TeachingTime.Contains(",") && en.TeachingTime.Contains(","))
{
errorMsgStr += "上课时间分割月份的逗号只能选择中文或英文逗号的一种;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
}
#endregion
#region 授课教师
if (!string.IsNullOrEmpty(en.TeacherNameString))
{
List userID=new List();
string[] TName=null;
if (en.TeacherNameString.Contains("\\"))
{
TName = en.TeacherNameString.Split('\\');
}
if(TName!=null){
var teacher = teacherList.Where(x => TName.Contains(x.Sys_User.Name)).Select(x=>x.UserID).ToList();
userID=teacher;
if(teacher.Count()!=TName.Count())
{
errorMsgStr += "授课教师不存在;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
en.UserID=userID.Distinct().ToList();
}
else
{
userID = teacherList.Where(x=>x.Sys_User.Name==en.TeacherNameString).Select(w => w.UserID).ToList();
if(userID.Count==0){
errorMsgStr += "授课教师不存在;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
DateTime date;
if(en.Time!=null){
foreach(var datetime in en.Time){
if (dth.ToDateTimeValue(datetime) != string.Empty){
date=Convert.ToDateTime(dth.ToDateTimeValue(datetime));
}
else
{
date = Convert.ToDateTime(datetime);
}
if(userID.Count!=0){
if (en.CourseTimeID != null && en.ClassroomID == Guid.Empty)
{
foreach(var staffid in userID){
var staffOnWork = EducationMissionClassSchedulingASdultDAL.CheckTeacherIsOnWork(x => x.CoursesTimeID == en.CourseTimeID && x.ScheduleDate == date, w => w.UserID == staffid).Select(x => x.AdultUserId).FirstOrDefault();
if(staffOnWork==null){
errorMsgStr += "授课教师在"+date.Month+"月"+date.Day+"日已有排课安排;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
break;
}
}
}
}
}
}
en.UserID = userID.Distinct().ToList();
}
}
#endregion
#region 考试周次
if (!string.IsNullOrEmpty(en.ExamWeek))
{
int isok = 0;
List week = en.ExamWeek.Split('\\').ToList();
List weeks = new List();
if (week!=null)
{
for (int w = 0; w < week.Count(); w++)
{
if (int.TryParse(week[w], out isok))
{
int day = Convert.ToInt32(week[w]);
var weeknum = school;
if (day > weeknum.WeeksNum || day < 0)
{
errorMsgStr += "考试周次输入的格式不正确;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
else
{
weeks.Add(day);
}
}
else
{
errorMsgStr += "考试周次输入的格式不正确;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
}
en.ExaWeek = weeks;
}
}
#endregion
#region 考试时间
if(!string.IsNullOrEmpty(en.ExamTime)){
List year = en.ExamTime.Split('日').ToList();
if (year.Count == 2)
{
List times = year[1].Trim().Split('-').ToList();
if (times.Count == 2)
{
DateTime date;
TimeSpan timespan;
string years = year[0] + "日";
if (DateTime.TryParse(years, out date))
{
en.ExamDate = Convert.ToDateTime(years);
}
else
{
errorMsgStr += "考试时间输入的格式不正确;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
List Star = times[0].Split(':').ToList();
if (Star.Count() == 2)
{
int isok = 0;
if (int.TryParse(Star[0], out isok) && int.TryParse(Star[1], out isok))
{
timespan = new TimeSpan(Convert.ToInt32(Star[0]), Convert.ToInt32(Star[1]), 0);
en.StarTime = timespan;
}
else
{
errorMsgStr += "考试时间输入的格式不正确;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
}
else
{
errorMsgStr += "考试时间输入的格式不正确;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
List end=times[1].Split(':').ToList();
if(end.Count()==2){
int isok = 0;
if (int.TryParse(end[0], out isok) && int.TryParse(end[1], out isok))
{
timespan = new TimeSpan(Convert.ToInt32(end[0]), Convert.ToInt32(end[1]), 0);
en.EndTime = timespan;
}
else
{
errorMsgStr += "考试时间输入的格式不正确;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
}
else
{
errorMsgStr += "考试时间输入的格式不正确;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
}
else
{
errorMsgStr += "考试时间输入的格式不正确;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
}
else
{
errorMsgStr += "考试时间输入的格式不正确;";
en.ErrorMessage = errorMsgStr;
isHaveNoInputValue = true;
}
}
for (int j = i + 1; j < enlist.Count; j++)
{
EducationMissionImportClassView enB = enlist[j];
// 判断必填列是否全部重复
if (
!string.IsNullOrEmpty(en.Name) && !string.IsNullOrEmpty(enB.Name)&&
!string.IsNullOrEmpty(en.TeachingTime) && !string.IsNullOrEmpty(enB.TeachingTime) &&
!string.IsNullOrEmpty(en.ClassroomName) && !string.IsNullOrEmpty(enB.ClassroomName) &&
!string.IsNullOrEmpty(en.CourseTime) && !string.IsNullOrEmpty(enB.CourseTime)
)
{
if (
en.Name == enB.Name&&
en.TeachingTime==enB.TeachingTime&&
en.ClassroomName == enB.ClassroomName
)
{
isHaveNoInputValue = true;
errorMsgStr += "第" + (i + 2) + "行与第" + (j + 2) + "行的必填列重复了";
en.ErrorMessage = errorMsgStr;
}
if (
en.Name == enB.Name &&
en.CourseTime != enB.CourseTime
)
{
isHaveNoInputValue = true;
errorMsgStr += "第" + (i + 2) + "行与第" + (j + 2) + "行的课时类别不同";
en.ErrorMessage = errorMsgStr;
}
}
if (!string.IsNullOrEmpty(en.TeachingTime) && !string.IsNullOrEmpty(enB.TeachingTime) && !string.IsNullOrEmpty(en.ClassroomName) && !string.IsNullOrEmpty(enB.ClassroomName))
{
if (en.TeachingTime.Contains("月") && enB.TeachingTime.Contains("月"))
{
string[] TName = en.TeacherNameString.Split('\\');
List TimesSegment = en.TeachingTime.Split(',').ToList();
List TimesSegmentB = enB.TeachingTime.Split(',').ToList();
List teachtingTimeA = new List();
for (int t = 0; t < TimesSegment.Count(); t++)
{
List month = TimesSegment[t].Split('月').ToList();
for (int m = 1; m < month.Count(); m++)
{
List day = month[m].Split('、').ToList();
for (int d = 0; d < day.Count(); d++)
{
teachtingTimeA.Add(month[0] + "月");
int index = teachtingTimeA.Count() - 1;
teachtingTimeA[index] += day[d];
}
}
}
List teachtingTimeB = new List();
for (int t = 0; t < TimesSegmentB.Count(); t++)
{
List month = TimesSegmentB[t].Split('月').ToList();
for (int m = 1; m < month.Count(); m++)
{
List day = month[m].Split('、').ToList();
for (int d = 0; d < day.Count(); d++)
{
teachtingTimeB.Add(month[0] + "月");
int index = teachtingTimeB.Count() - 1;
teachtingTimeB[index] += day[d];
}
}
}
for (int c = 0; c < TimesSegmentB.Count(); c++)
{
foreach (var n in TName)
{
if (enB.TeacherNameString.Contains(n) && teachtingTimeA.Contains(teachtingTimeB[c]) && en.CourseTime == enB.CourseTime)
{
isHaveNoInputValue = true;
errorMsgStr += "第" + (i + 2) + "行与第" + (j + 2) + "行的同一个老师在同一天同一个时间段内有不同的安排";
break;
}
}
if (teachtingTimeA.Contains(teachtingTimeB[c]) && en.ClassroomName == enB.ClassroomName && en.CourseTime == enB.CourseTime)
{
isHaveNoInputValue = true;
errorMsgStr += "第" + (i + 2) + "行与第" + (j + 2) + "行的同一个教室在同一天同一个时间段内有不同的安排";
break;
}
}
}
}
}
#endregion
#endregion
if (isHaveNoInputValue) // 若必填项有值未填
{
en.IsExcelVaildateOK = false;
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
}
}
#endregion
// TODO:其他检测
#region 1.2.1.3 循环写入验证成功的数据
List className = new List();
for (int i = 0; i < enlist.Count; i++)
{
EducationMissionImportClassView enA = enlist[i];
enA.OrderNo = i;
if (enA.IsExcelVaildateOK == false) // 上面验证不通过,不进行此步验证
{
continue;
}
for (int j = i + 1; j < enlist.Count; j++)
{
EducationMissionImportClassView enB = enlist[j];
// 判断必填列是否全部重复
if (
!string.IsNullOrEmpty(enA.Name) && !string.IsNullOrEmpty(enB.Name)
)
{
if (
enA.Name == enB.Name
)
{
className.Add(enA);
}
}
}
try
{
var educationMissionClass = missionClassList.Where(x => x.Name == enA.Name).FirstOrDefault(); //educationMissionClassDAL.GetEducationMissionClassViewQueryble(x => x.Name == enA.Name && x.EM_EducationMission.SchoolyearID == schoolyear, w => true, c => true, a => true).FirstOrDefault();
var classrommId = ClassroomName.Where(x => x.Name == enA.ClassroomName).FirstOrDefault();
var educationMissionClassID = educationMissionClass.EducationMissionClassID;
List educationSchedulingClassID = educationSchedulingClassIDList.Where(x => x.EducationMissionClassID == educationMissionClassID).Select(w=>w.EducationSchedulingClassID).ToList();
var e = className.OrderBy(w => w.OrderNo).Where(x => x.Name == enA.Name).FirstOrDefault();
int errornums = 0;
foreach(var edID in educationSchedulingClassID){
if (errornums==0)
{
foreach(var datetime in enA.Time){
DateTime t = Convert.ToDateTime(datetime);
var studentQuery = this.EducationSchedulingClassDAL.GetStudentQueryable(x => x.EducationSchedulingClassID == edID);
var studentIsBusy = (from es in adultEducationScheduleRepository.GetList(
x => x.SchoolyearID == schoolyear && x.EducationSchedulingClassID != edID)
from s in es.EM_EducationSchedulingClass.CF_Student
.Join(studentQuery, (x => x.UserID), (x => x.UserID), (x, y) => x)
where es.ScheduleDate == t && es.CoursesTimeID == enA.CourseTimeID
select s).Include(x => x.Sys_User).ToList();
if (studentIsBusy.Count > 0)
{
errornums = studentIsBusy.Count;
enA.ErrorMessage += "部分学生在"+t.Month+"月"+t.Day+"日有课,不能上课;";
errList.Add(enA);
break;
}
}
}
List adultEducationScheduleID = EducationScheduleList.Where(x => x.EducationSchedulingClassID == edID).Select(w => w.AdultEducationScheduleID).ToList();
if (e==null)
{
if (adultEducationScheduleID.Count() != 0 && errornums == 0)
{
//先删除旧数据、重新创建新数据
UnitOfWork.Delete(x => x.EducationMissionID == educationMissionClass.EducationMissionID);
UnitOfWork.Delete(x => x.MissionClassID == educationMissionClass.EducationMissionClassID);
UnitOfWork.Delete(x => x.EducationMissionID == educationMissionClass.EducationMissionID);
UnitOfWork.Delete(x => adultEducationScheduleID.Contains((Guid)x.AdultEducationScheduleID));
UnitOfWork.Delete(x => educationSchedulingClassID.Contains((Guid)x.EducationSchedulingClassID));
}
if (educationMissionClass.EM_MissionClassTeacher.Count > 0)
{
UnitOfWork.Delete(x => x.MissionClassID == educationMissionClass.EducationMissionClassID);
}
}
else
{
if(e.OrderNo==enA.OrderNo){
if (adultEducationScheduleID.Count() != 0 && errornums == 0)
{
//先删除旧数据、重新创建新数据
UnitOfWork.Delete(x => x.EducationMissionID == educationMissionClass.EducationMissionID);
UnitOfWork.Delete(x => x.MissionClassID == educationMissionClass.EducationMissionClassID);
UnitOfWork.Delete(x => x.EducationMissionID == educationMissionClass.EducationMissionID);
UnitOfWork.Delete(x => adultEducationScheduleID.Contains((Guid)x.AdultEducationScheduleID));
UnitOfWork.Delete(x => educationSchedulingClassID.Contains((Guid)x.EducationSchedulingClassID));
}
if (educationMissionClass.EM_MissionClassTeacher.Count > 0)
{
UnitOfWork.Delete(x => x.MissionClassID == educationMissionClass.EducationMissionClassID);
}
}
}
}
if (enA != null&&errornums==0) //有数据开始组装数据
{
if(enA.CourseTimeID!=null){
EM_CoursesTime c =coursesTimeRepository.Entities.Where(x=>x.CoursesTimeID==(Guid)enA.CourseTimeID).FirstOrDefault();
if(c!=null){
EM_EducationMissionClass ec = new EM_EducationMissionClass();
ec = educationMissionClass;
ec.ClassroomID = enA.ClassroomID;
ec.EM_CoursesTime = new HashSet();
ec.EM_CoursesTime.Add(c);
this.SetNewStatus(ec);
ec.RecordStatus = (int)EMIS.ViewModel.EM_EducationMissionClassStatus.Scheduled;
UnitOfWork.Update(ec);
}
}
if (enA.ExamDate!=null&&enA.EndTime!=null&&enA.StarTime != null)
{
if (e == null)
{
EM_EducationMissionExamTime Examtime = new EM_EducationMissionExamTime();
Examtime.EducationMissionExamTimeID = Guid.NewGuid();
Examtime.EducationMissionID = educationMissionClass.EducationMissionID;
if (enA.ExamDate.ToLongDateString().ToString() == "0001年1月1日")
{
Examtime.ExamDate = null;
Examtime.StartTime = null;
Examtime.EndTime = null;
}
else
{
Examtime.ExamDate = enA.ExamDate;
TimeSpan tt = new TimeSpan(enA.ExamDate.Hour, enA.ExamDate.Minute, enA.ExamDate.Second);
Examtime.StartTime = enA.StarTime;
Examtime.EndTime = enA.EndTime;
}
this.SetNewStatus(Examtime);
UnitOfWork.Add(Examtime);
}
else
{
if (e.OrderNo == enA.OrderNo)
{
EM_EducationMissionExamTime Examtime = new EM_EducationMissionExamTime();
Examtime.EducationMissionExamTimeID = Guid.NewGuid();
Examtime.EducationMissionID = educationMissionClass.EducationMissionID;
if (enA.ExamDate.ToLongDateString().ToString() == "0001年1月1日")
{
Examtime.ExamDate = null;
Examtime.StartTime = null;
Examtime.EndTime = null;
}
else
{
Examtime.ExamDate = enA.ExamDate;
TimeSpan tt = new TimeSpan(enA.ExamDate.Hour, enA.ExamDate.Minute, enA.ExamDate.Second);
Examtime.StartTime = enA.StarTime;
Examtime.EndTime = enA.EndTime;
}
this.SetNewStatus(Examtime);
UnitOfWork.Add(Examtime);
}
}
}
if(enA.ExaWeek!=null){
if (e == null)
{
foreach (var week in enA.ExaWeek)
{
EM_EducationMissionExamWeekNum ExamWeekNum = new EM_EducationMissionExamWeekNum();
ExamWeekNum.EducationMissionExamWeekNumID = Guid.NewGuid();
ExamWeekNum.EducationMissionID = educationMissionClass.EducationMissionID;
ExamWeekNum.WeeklyNum = week;
this.SetNewStatus(ExamWeekNum);
UnitOfWork.Add(ExamWeekNum);
}
}
else
{
if (e.OrderNo == enA.OrderNo)
{
foreach (var week in enA.ExaWeek)
{
EM_EducationMissionExamWeekNum ExamWeekNum = new EM_EducationMissionExamWeekNum();
ExamWeekNum.EducationMissionExamWeekNumID = Guid.NewGuid();
ExamWeekNum.EducationMissionID = educationMissionClass.EducationMissionID;
ExamWeekNum.WeeklyNum = week;
this.SetNewStatus(ExamWeekNum);
UnitOfWork.Add(ExamWeekNum);
}
}
}
}
foreach(var staffID in enA.UserID){
UnitOfWork.Delete(x => x.MissionClassID == educationMissionClass.EducationMissionClassID && x.UserID == staffID);
EM_MissionClassTeacher teacher = new EM_MissionClassTeacher();
teacher.MissionClassTeacherID = Guid.NewGuid();
teacher.MissionClassID = educationMissionClass.EducationMissionClassID;
teacher.UserID = staffID;
teacher.TeachType = (int?)EM_TeachingMethod.Lecturer;
this.SetNewStatus(teacher);
UnitOfWork.Add(teacher);
}
foreach (var schedulingClass in educationSchedulingClassID)
{
foreach (var times in enA.Time)
{
ES_AdultEducationSchedule EducationScheduling = new ES_AdultEducationSchedule();
EducationScheduling.AdultEducationScheduleID = Guid.NewGuid();
EducationScheduling.EducationSchedulingClassID = schedulingClass;
EducationScheduling.ClassroomID = enA.ClassroomID;
EducationScheduling.SchoolyearID = schoolyear;
EducationScheduling.CoursesTimeID = enA.CourseTimeID;
if (dth.ToDateTimeValue(times) != string.Empty)
EducationScheduling.ScheduleDate = Convert.ToDateTime(dth.ToDateTimeValue(times));
else
EducationScheduling.ScheduleDate = Convert.ToDateTime(times);
SetNewStatus(EducationScheduling);
UnitOfWork.Add(EducationScheduling);
if (enA.UserID != null)
{
foreach (var user in enA.UserID)
{
ES_AdultEducationScheduleTeacher EducationSchedulingTeacher = new ES_AdultEducationScheduleTeacher();
EducationSchedulingTeacher.AdultEducationScheduleTeacherID = Guid.NewGuid();
EducationSchedulingTeacher.AdultEducationScheduleID = EducationScheduling.AdultEducationScheduleID;
EducationSchedulingTeacher.UserID = user;
EducationSchedulingTeacher.TeachingMethod = (int?)EM_TeachingMethod.Lecturer;
SetNewStatus(EducationSchedulingTeacher);
UnitOfWork.Add(EducationSchedulingTeacher);
}
}
}
}
}
UnitOfWork.Commit();
}
catch (Exception)
{
throw;
}
}
#endregion
#endregion
#endregion
#region 1.3 返回各项数据值
errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "教学任务课程安排操作失败文件", sourceWebPath));
successCount = enlist.Distinct().Count() - errList.Distinct().Count();//共条数减去失败条数
errdataList = errList.Distinct().ToList();
OkCount = errList.Distinct().Count();
Errinfo = string.Format("提示:成功导入{0}条记录,失败{1}条,详情请点击错误数据下载查看。", successCount < 1 ? 0 : successCount, OkCount < 1 ? 0 : OkCount);
#endregion
}
}
}