📄 bteachplan.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using Entities;
using Search;
using DAL;
using System.Collections;
namespace BLL
{
public class BTeachPlan
{
public int AddTeachPlan(Entities.TeachPlan teachPlan)
{
IDTeachPlan Teach = DALContainer.Factory.GetIDTeachPlan();
return Teach.Insert(teachPlan);
}
public int Insert(Entities.TeachPlan eTeachPlan)
{
IDTeachPlan Teach = DALContainer.Factory.GetIDTeachPlan();
Course eCourse = new BLL.BCourse().GetEntities(eTeachPlan.CourseID);
int TimeSpan = eCourse.TimeSpan;
TimePlan eTimePlan = new BLL.BTimePlan().GetEntities(eTeachPlan.TimePlanID);
int count = GetDays(eTimePlan);
int Weeks = TimeSpan / count;
int days = 0;
if((TimeSpan % count)!=0)
{
days = (TimeSpan % count) > 4 ? 2 : 1;
}
int Totals = Weeks * 7 + days;
eTeachPlan.OverDate = eTeachPlan.BeginDate.AddDays(Totals);
return Teach.Insert(eTeachPlan);
}
public int Update(int ClassID, int CouserID, int TeacherID, int TimePlanID, DateTime BeginTime, DateTime EndTime)
{
IDTeachPlan Teach = DALContainer.Factory.GetIDTeachPlan();
TeachPlanSearcher Seach = new TeachPlanSearcher();
TeachPlanSearcher newValue = new TeachPlanSearcher();
Seach.ClassID = ClassID;
Seach.ClassIDIsValid = true;
Seach.CourseID = CouserID;
Seach.CourseIDIsValid = true;
Seach.TeacherID = TeacherID;
Seach.TeacherIDIsValid = true;
Seach.TimePlanID = TimePlanID;
Seach.TimePlanIDIsValid = true;
newValue.BeginDate = BeginTime;
newValue.BeginDateIsValid = true;
newValue.OverDate = EndTime;
newValue.OverDateIsValid = true;
return Teach.Update(Seach, newValue);
}
public int Update(TeachPlanSearcher searcher, TeachPlanSearcher newValues)
{
IDTeachPlan dTeachPlan = DALContainer.Factory.GetIDTeachPlan();
return dTeachPlan.Update(searcher, newValues);
}
public Entities.TeachPlan GetEntities(object TeachPlan_ID)
{
IDTeachPlan dTeachPlan = DALContainer.Factory.GetIDTeachPlan();
return dTeachPlan.SelectSingle(TeachPlan_ID);
}
public ArrayList GetClassTechPlan(int clsID, int year, int month)
{
ArrayList plans = new ArrayList();
DateTime date = System.DateTime.Parse(year + "-" + month + "-1");
IDTeachPlan dTeachPlan = DALContainer.Factory.GetIDTeachPlan();
IDTimePlanChanging dChanging = DALContainer.Factory.GetIDTimePlanChanging();
IDCourseTeacherChanging dTeacherChanging = DALContainer.Factory.GetIDCourseTeacherChanging();
IDClassTempCourse dClassTempCourse = DALContainer.Factory.GetIDClassTempCourse();
IDClassMovement dClassMovement = DALContainer.Factory.GetIDClassMovement();
IDHoliday dHoliday = DALContainer.Factory.GetIDHoliday();
ArrayList teachPlans = dTeachPlan.GetClassTechPlan(clsID, year, month);
foreach (TeachPlan teachPlan in teachPlans)
{
//获取该课程时间安排的变化
TimePlanChangingSearcher changingSearcher = new TimePlanChangingSearcher();
changingSearcher.TeachPlanID = teachPlan.TeachPlanID;
changingSearcher.TeachPlanIDIsValid = true;
ArrayList timeChangings = dChanging.Select(changingSearcher);
//获取该课程教员安排的变化
CourseTeacherChangingSearcher ctcs = new CourseTeacherChangingSearcher();
ctcs.TeachPlanID = teachPlan.TeachPlanID;
ctcs.TeachPlanIDIsValid = true;
ArrayList teacherChangings = dTeacherChanging.Select(ctcs);
//获取临时课安排
ClassTempCourseSearcher tcs = new ClassTempCourseSearcher();
tcs.ClassID = teachPlan.ClassID;
tcs.ClassIDIsValid = true;
ArrayList tempCourses=dClassTempCourse.Select(tcs);
//获取活动安排
ClassMovementSearcher cms = new ClassMovementSearcher();
cms.ClassID = teachPlan.ClassID;
cms.ClassIDIsValid = true;
ArrayList movements = dClassMovement.Select(cms);
//获取假日安排
HolidaySearcher hs = new HolidaySearcher();
hs.ClassID = teachPlan.ClassID;
hs.ClassIDIsValid = true;
ArrayList holidays=dHoliday.Select(hs);
TimePlan tempTimePlan = teachPlan.TimePlan;
DateTime tempDate;
if (teachPlan.BeginDate < date)
tempDate = date;
else
tempDate = teachPlan.BeginDate;
TeachPlanInfo planInfo = GetPlanInfo(date,teachPlan,timeChangings,teacherChangings,tempCourses,movements,holidays);
planInfo.Teacher = teachPlan.Employee.EmployeeName;
planInfo.PlanID = teachPlan.TeachPlanID;
plans.Add(planInfo);
}
return plans;
}
private TeachPlanInfo GetPlanInfo(DateTime date,TeachPlan teachPlan, ArrayList timePlanChangings, ArrayList teacherChangings, ArrayList tempCourses, ArrayList movements, ArrayList holidays)
{
TimePlan tempTimePlan = teachPlan.TimePlan;
//首先设置tempDate为课程在本月的第一天上课日期
DateTime tempDate;
if (teachPlan.BeginDate < date)
tempDate = date;
else
tempDate = teachPlan.BeginDate;
TeachPlanInfo planInfo = new TeachPlanInfo();
//取出课程在本月的安排情况
while (tempDate < date.AddMonths(1) && tempDate < teachPlan.OverDate.AddDays(1))
{
foreach (TimePlanChanging changing in timePlanChangings)
{
if (changing.InureDate <= tempDate)
{
tempTimePlan = changing.TimePlan;
}
}
//上午是否有课
bool am = GetTimePlan(tempDate, tempTimePlan, true);
//下午是否有课
bool pm = GetTimePlan(tempDate, tempTimePlan, false);
//根据放假再次判断是否有课
foreach (Holiday holiday in holidays)
{
if (holiday.StartDate <= tempDate && holiday.EndDate >= tempDate)
{
if (holiday.StartDate == tempDate)
{
if (holiday.AMStart)
{
am = false;
pm = false;
}
else
{
pm=false;
}
}
if (holiday.EndDate == tempDate)
{
if (holiday.AMEnd)
{
am = false;
}
else
{
am = false;
pm = false;
}
}
if (holiday.StartDate < tempDate && holiday.EndDate > tempDate)
{
am = false;
pm = false;
}
}
}
DayPlan dayPlan = GetDayPlan(am,pm,tempDate,teachPlan,teacherChangings,tempCourses,movements);
dayPlan.Date = tempDate;
planInfo.DaysPlan.Add(dayPlan);
tempDate = tempDate.AddDays(1);
}
//planInfo.CourseName = teachPlan.Course.CourseName;
//planInfo.CourseColor = teachPlan.Course.CourseColor;
planInfo.Teacher = teachPlan.Employee.EmployeeName;
planInfo.PlanID = teachPlan.TeachPlanID;
return planInfo;
}
/// <summary>
/// 获取每天的课程安排
/// </summary>
/// <param name="am">上午是否有课</param>
/// <param name="pm">下午是否有课</param>
/// <param name="date">日期</param>
/// <param name="teachPlan">课程安排对象</param>
/// <param name="teacherChangings">教员变更信息</param>
/// <param name="tempCourses">临时课信息</param>
/// <param name="movements">活动信息</param>
/// <returns></returns>
private DayPlan GetDayPlan(bool am,bool pm,DateTime date,TeachPlan teachPlan, ArrayList teacherChangings, ArrayList tempCourses, ArrayList movements)
{
DayPlan dayPlan = new DayPlan();
if (!am && !pm)
return dayPlan;
string teacher = teachPlan.Employee.EmployeeName;
foreach (CourseTeacherChanging teacherChanging in teacherChangings)
{
if (teacherChanging.InureDate <= date)
{
teacher = teacherChanging.Employee.EmployeeName;
}
}
dayPlan.AmPlan.HasCourse = am;
dayPlan.AmPlan.CourseColor = teachPlan.Course.CourseColor;
dayPlan.AmPlan.CourseName = teachPlan.Course.CourseName;
dayPlan.AmPlan.Teacher = teacher;
dayPlan.PmPlan.HasCourse = pm;
dayPlan.PmPlan.CourseColor = teachPlan.Course.CourseColor;
dayPlan.PmPlan.CourseName = teachPlan.Course.CourseName;
dayPlan.PmPlan.Teacher = teacher;
//如果当天有临时课,获取当天临时课信息
foreach (ClassTempCourse tempCourse in tempCourses)
{
if (tempCourse.TempCourseDate == date)
{
HalfDayPlan halfDayPlan = null;
if (tempCourse.IsAm)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -