bviewteachplan.cs

来自「这是一个自动排课软件(包含源码,需求分析,详细设计).希望对你有所帮助.」· CS 代码 · 共 270 行

CS
270
字号
using System;
using System.Collections.Generic;
using System.Text;
using Entities;
using Search;
using DAL;
using System.Collections;

namespace BLL
{
    public class BViewTeachPlan
    {
        public ArrayList GetDetectInfo(int courseID,int timePlanID,DateTime beginDate)
        {
            IDTimePlan dTimePlan = DALContainer.Factory.GetIDTimePlan();
            TimePlan timePlan = dTimePlan.SelectSingle(timePlanID);
            DateTime endDate = GetLastDate(courseID, timePlan,beginDate);

            ArrayList clashes = new ArrayList();
            //获取教员角色的用户
            IDTeacherAbility dTeacherAbility = DALContainer.Factory.GetIDTeacherAbility();
            TeacherAbilitySearcher abilitySearcher = new TeacherAbilitySearcher();
            abilitySearcher.CourseID = courseID;
            abilitySearcher.CourseIDIsValid = true;
            ArrayList teacherAbilities = dTeacherAbility.Select(abilitySearcher);
            
            IDViewTeachPlan dViewPlan = DALContainer.Factory.GetIDViewTeachPlan();
            foreach (TeacherAbility teacherAbility in teacherAbilities)
            {
                TeachClash clash = new TeachClash();
                clash.TeacherID = teacherAbility.Employee.EmployeeID;
                clash.TeacherName=teacherAbility.Employee.EmployeeName;

                ViewTeachPlanSearcher teachPlanSearcher = new ViewTeachPlanSearcher();
                teachPlanSearcher.TeacherID = clash.TeacherID;
                teachPlanSearcher.TeacherIDIsValid = true;
                ArrayList viewTeachPlans= dViewPlan.Select(teachPlanSearcher);
                foreach (ViewTeachPlan teachPlan in viewTeachPlans)
                {
                    TeachInfo info = new TeachInfo();
                    info.ClassName = teachPlan.ClassName;
                    info.CourseName = teachPlan.CourseName;
                    info.BeginDate = teachPlan.BeginDate;
                    info.EndDate = teachPlan.EndDate;
                    info.TimePlanID = teachPlan.TimeplanId;
                    info.TimePlanName = teachPlan.TimePlanName;
                    clash.TeachInfos.Add(info);
                }
                clash.Description = GetClashDesc(courseID, timePlan, beginDate, endDate, viewTeachPlans);
                clashes.Add(clash);
            }
            return clashes;
        }
        private string GetClashDesc(int courseID, TimePlan timePlan, DateTime beginDate, DateTime endDate, ArrayList viewTeachPlans)
        {
            int clashDays = 0;
            int reverseDays=0;
            foreach (ViewTeachPlan teachPlan in viewTeachPlans)
            {
                if(teachPlan.BeginDate>endDate || teachPlan.EndDate<beginDate)
                    continue;
                DateTime tempDate = teachPlan.BeginDate>beginDate?teachPlan.BeginDate:beginDate;
                
                while (tempDate <= teachPlan.EndDate && tempDate<=endDate)
                {
                    bool am = HasCourse(tempDate, timePlan, true);
                    bool pm = HasCourse(tempDate, timePlan, false);
                    bool am2=HasCourse(tempDate,teachPlan,true);
                    bool pm2=HasCourse(tempDate,teachPlan,false);
                    
                    if (am && pm)
                    {
                        if(am2 && pm2)
                        {
                            clashDays+=2;
                            reverseDays+=2;
                        }
                        else if(am2 || pm2)
                        {
                            clashDays++;
                            reverseDays++;
                        }
                    }
                    else if(am)
                    {
                        if(am2 && pm2)
                        {
                            clashDays++;
                            reverseDays++;
                        }
                        else if(am2)
                        {
                            clashDays++;
                        }
                        else if(pm2)
                        {
                            reverseDays++;
                        }
                    }
                    else if(pm)
                    {
                        if(am2 && pm2)
                        {
                            clashDays++;
                            reverseDays++;
                        }
                        else if(am2)
                        {
                            reverseDays++;
                        }
                        else if(pm2)
                        {
                            clashDays++;
                        }
                    }
                    tempDate=tempDate.AddDays(1);
                }
            }
            if(clashDays == 0)
                return "没有冲突";
            else if(clashDays<=reverseDays)
                return "冲突数:"+clashDays.ToString();
            else
                return "冲突数:"+clashDays.ToString()+ "; 切换上下午后的冲突数:"+reverseDays.ToString();
        }
        public DateTime GetLastDate(int courseID, TimePlan timePlan, DateTime beginDate)
        {
            BLL.BCourse bCourse = new BLL.BCourse();
            Course course = bCourse.GetEntities(courseID);
            int timeSpan = course.TimeSpan;
            int chapterCount = 0;
            DateTime tempDate = beginDate;
            while (chapterCount < timeSpan)
            {
                if (HasCourse(tempDate, timePlan, true))
                {
                    chapterCount++;
                }
                if (HasCourse(tempDate, timePlan, false))
                {
                    chapterCount++;
                }
                tempDate=tempDate.AddDays(1);
            }
            return tempDate.AddDays(-1);
        }
        private bool HasCourse(DateTime date, ViewTeachPlan viewTeachPlan, bool isAm)
        {
            switch (date.DayOfWeek)
            {
                case DayOfWeek.Sunday:
                    return isAm ? viewTeachPlan.SundayAm : viewTeachPlan.SundayPm;
                case DayOfWeek.Monday:
                    return isAm ? viewTeachPlan.MondayAm : viewTeachPlan.MondayPm;
                case DayOfWeek.Tuesday:
                    return isAm ? viewTeachPlan.TuesdayAm : viewTeachPlan.TuesdayPm;
                case DayOfWeek.Wednesday:
                    return isAm ? viewTeachPlan.WednesdayAm : viewTeachPlan.WednesdayPm;
                case DayOfWeek.Thursday:
                    return isAm ? viewTeachPlan.ThursdayAm : viewTeachPlan.ThursdayPm;
                case DayOfWeek.Friday:
                    return isAm ? viewTeachPlan.FridayAm : viewTeachPlan.FridayPm;
                case DayOfWeek.Saturday:
                    return isAm ? viewTeachPlan.SaturdayAm : viewTeachPlan.SaturdayPm;
            }
            return false;
        }
        private bool HasCourse(DateTime date, TimePlan timePlan, bool isAm)
        {
            switch (date.DayOfWeek)
            {
                case DayOfWeek.Sunday:
                    return isAm ? timePlan.SundayAm : timePlan.SundayPm;
                case DayOfWeek.Monday:
                    return isAm ? timePlan.MondayAm : timePlan.MondayPm;
                case DayOfWeek.Tuesday:
                    return isAm ? timePlan.TuesdayAm : timePlan.TuesdayPm;
                case DayOfWeek.Wednesday:
                    return isAm ? timePlan.WednesdayAm : timePlan.WednesdayPm;
                case DayOfWeek.Thursday:
                    return isAm ? timePlan.ThursdayAm : timePlan.ThursdayPm;
                case DayOfWeek.Friday:
                    return isAm ? timePlan.FridayAm : timePlan.FridayPm;
                case DayOfWeek.Saturday:
                    return isAm ? timePlan.SaturdayAm : timePlan.SaturdayPm;
            }
            return false;
        }
    }

    public class TeachClash
    {
        private int teacherID;

        public int TeacherID
        {
            get { return teacherID; }
            set { teacherID = value; }
        }
        private string teacherName;

        public string TeacherName
        {
            get { return teacherName; }
            set { teacherName = value; }
        }
        private string description="没有冲突";

        public string Description
        {
            get { return description; }
            set { description = value; }
        }
        private ArrayList teachInfos=new ArrayList();

        public ArrayList TeachInfos
        {
            get { return teachInfos; }
            set { teachInfos = value; }
        }
    }
    public class TeachInfo
    {
        private string className;

        public string ClassName
        {
            get { return className; }
            set { className = value; }
        }
        private string courseName;

        public string CourseName
        {
            get { return courseName; }
            set { courseName = value; }
        }

        private DateTime  beginDate;

        public DateTime  BeginDate
        {
            get { return beginDate; }
            set { beginDate = value; }
        }
        private DateTime endDate;

        public DateTime EndDate
        {
            get { return endDate; }
            set { endDate = value; }
        }
        private int timePlanID;

        public int TimePlanID
        {
            get { return timePlanID; }
            set { timePlanID = value; }
        }

        private string timePlanName;

        public string TimePlanName
        {
            get { return timePlanName; }
            set { timePlanName = value; }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?