⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coursearrangecontrol.cs

📁 实现课程表编排和打印功能,通过在候选列表中选择课程和教师(没有被排课且该教师教授所选择的课程)来完成排课,代码约8000行
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace 课程安排
{
    public partial class CourseArrangeControl : UserControl
    { 
        private CourseTableBodyControl.BodyTimeItem time = null;

        public CourseTableBodyControl.BodyTimeItem Time
        {
            get { return time; }
            set 
            { 
                time = value;
                // 将所有老师的项都添加到下拉筐中(老师必须是有时间的)
                if (time != null)
                {
                    this.comboBox2.Items.Clear();
                    if (time.Teachers != null)
                    {
                        for (int i = 0; i < time.Teachers.Count; i++)
                        {
                            this.comboBox2.Items.Add(time.Teachers[i]);
                        }
                    }
                }
            }
        }

        private List<CourseTableBodyControl.BodySubjectItem> subjects = null;

        public System.Collections.Generic.List<课程安排.CourseTableBodyControl.BodySubjectItem> Subjects
        {
            get { return subjects; }
            set 
            { 
                subjects = value;
                if (subjects != null)
                {
                    this.comboBox1.Items.Clear();
                    for (int i = 0; i < subjects.Count; i++)
                    {
                        this.comboBox1.Items.Add(subjects[i].SubjectName);
                    }
                }
            }
        }

        private CourseTableBodyControl.BodyCourseItem course = null;

        public CourseTableBodyControl.BodyCourseItem Course
        {
            get 
            {
                if (course == null)
                    course = new CourseTableBodyControl.BodyCourseItem();
                course.Subject = this.comboBox1.Text;
                course.Teacher = this.comboBox2.Text;
                string str = this.Name.Remove(0, this.Name.Length - 2);
                course.Week = Convert.ToInt32(str[0]) - 48;
                course.CourseOrder = Convert.ToInt32(str[1]) - 48;
                return course; 
            }
            set 
            { 
                course = value;
                if (course != null)
                {
                    this.comboBox1.Text = course.Subject;
                    this.comboBox2.Text = course.Teacher;
                }
            }
        }
    
        public CourseArrangeControl()
        {
            InitializeComponent();
        }

        private void CourseArrangeControl_Resize(object sender, EventArgs e)
        {
            if (this.Width != 105)
                this.Width = 105;
            if (this.Height != 45)
                this.Height = 45;
        }

        //  根据所选择课程,重新设置所能够选择的老师
        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            if (Utility.CheckComboText(this.comboBox1))
            {
                comboBox2.Items.Clear();
                for (int i = 0; i < subjects.Count; i++)
                {
                    if (this.comboBox1.Text == subjects[i].SubjectName)
                    {
                        List<string> list = GetIntersect(subjects[i].Teachers, time.Teachers);
                        for (int j = 0; j < list.Count; j++)
                        {
                            this.comboBox2.Items.Add(list[j]);
                        }
                        this.comboBox2.Text = "";
                        if (this.comboBox2.Items.Count == 1)  // 当候选值只有一个时,设置显示该值
                        {
                            this.comboBox2.Text = this.comboBox2.Items[0].ToString();
                        }
                    }
                }

            }
        }


        //#region 处理方式有点不合理,不使用(改为由课程决定候选教师,去除有教师决定候选课程功能)
        ////  根据所选择课程,重新设置所能够选择的老师
        //private int 校验 = 1;  
        //private void comboBox1_TextChanged(object sender, EventArgs e)
        //{
        //    if (校验 == 0)
        //    {
        //        校验 = 1;
        //        return;
        //    }
        //    if (Utility.CheckComboText(this.comboBox1))
        //    {
        //        comboBox2.Items.Clear();
        //        this.comboBox2.Items.Add("");
        //        if (comboBox1.Text == "")
        //        {
        //            if (time != null)
        //            {
        //                for (int i = 0; i < time.Teachers.Count; i++)
        //                {
        //                    this.comboBox2.Items.Add(time.Teachers[i]);
        //                }
        //            }
        //        }
        //        else
        //        {
        //            for (int i = 0; i < subjects.Count; i++)
        //            {
        //                if (this.comboBox1.Text == subjects[i].SubjectName)
        //                {
        //                    List<string> list = GetIntersect(subjects[i].Teachers, time.Teachers);
        //                    for (int j = 0; j < list.Count; j++)
        //                    {
        //                        this.comboBox2.Items.Add(list[j]);
        //                    }
        //                    if (!Utility.CheckComboText(this.comboBox2))
        //                        this.comboBox2.Text = "";
        //                    if (this.comboBox2.Items.Count == 1)  // 当候选值只有一个时,设置显示该值
        //                    {
        //                        校验 = 0;
        //                        this.comboBox2.Text = this.comboBox2.Items[0].ToString();
        //                    }
        //                }
        //            }
        //        }
        //    }
        //}

        ////  根据所选择的老师,重新设置所能够选择的课程
        //private void comboBox2_TextChanged(object sender, EventArgs e)
        //{
        //    if (校验 == 0)
        //    {
        //        校验 = 1;
        //        return;
        //    }
        //    if (Utility.CheckComboText(this.comboBox2))
        //    {
        //        comboBox1.Items.Clear();
        //        comboBox1.Items.Add("");
        //        if (this.comboBox2.Text == "")
        //        {
        //            for (int i = 0; i < subjects.Count; i++)
        //            {
        //                this.comboBox1.Items.Add(subjects[i].SubjectName);
        //            }
        //        }
        //        else
        //        {
        //            for (int i = 0; i < subjects.Count; i++)
        //            {
        //                if (subjects[i].Teachers.Contains(this.comboBox2.Text))
        //                {
        //                    this.comboBox1.Items.Add((subjects[i].SubjectName));
        //                }
        //            }
        //            if (!Utility.CheckComboText(this.comboBox1))
        //                comboBox1.Text = "";
        //            if (this.comboBox1.Items.Count == 1)
        //            {
        //                校验 = 0;
        //                this.comboBox1.Text = this.comboBox1.Items[0].ToString();
        //            }
        //        }
        //    }
        //}
        //#endregion

        private List<string> GetIntersect(List<string> list1, List<string> list2)
        {
            List<string> list = new List<string>();
            for (int i = 0; i < list1.Count; i++)
            {
                if (list2.Contains(list1[i]))
                    list.Add(list1[i]);
            }
            return list;
        }

        public override Color BackColor
        {
            get
            {
                return base.BackColor;
            }
            set
            {
                base.BackColor = value;
                this.comboBox1.BackColor = base.BackColor;
                this.comboBox2.BackColor = base.BackColor;
            }
        }

        public void ClearText()
        {
            this.comboBox1.Text = "";
            this.comboBox2.Text = "";
        }
        public void ClearItems()
        {
            this.comboBox1.Items.Clear();
            this.comboBox2.Items.Clear();
        }
    }
}

⌨️ 快捷键说明

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