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

📄 mainmodule.cs

📁 实现课程表编排和打印功能,通过在候选列表中选择课程和教师(没有被排课且该教师教授所选择的课程)来完成排课,代码约8000行
💻 CS
📖 第 1 页 / 共 5 页
字号:
            //return base.Equals(obj);
            bool b = false;
            if (obj is Subject)
            {
                if (this.subjectName == (obj as Subject).subjectName && this.level == (obj as Subject).level)
                    b = true;
            }
            return b;
        }

        private string subjectName;

        public string SubjectName
        {
            get { return subjectName; }
            set { subjectName = value; }
        }

        private EditLevel level;

        public EditLevel Level
        {
            get { return level; }
            set { level = value; }
        }

        private IList<Teacher> teachers;

        public IList<Teacher> Teachers
        {
            get { return teachers; }
            set { teachers = value; }
        }

        public void AddTeacher(string TeacherName)
        {
            for (int i = 0; i < School.Teachers.Count; i++)
            {
                if (School.Teachers[i].TeacherName == TeacherName)
                {
                    if (!this.teachers.Contains(School.Teachers[i]))
                    {
                        this.teachers.Add(School.Teachers[i]);
                        break;
                    }
                }
            }
        }

        public void AddTeacher(Teacher Teacher)
        {
            if (this.teachers == null)
                this.teachers = new List<Teacher>();
            if (!this.teachers.Contains(Teacher))
                this.teachers.Add(Teacher);
        }

        public void RemoveTeacher(string TeacherName)
        {
            if (this.teachers != null)
            {
                for (int i = 0; i < this.teachers.Count; i++)
                {
                    if (this.teachers[i].TeacherName == TeacherName)
                    {
                        this.teachers.Remove(this.teachers[i]);
                        break;
                    }
                }
            }
        }

        public void RemoveTeacher(Teacher Teacher)
        {
            if (this.teachers != null)
            {
                if (this.teachers.Contains(Teacher))
                    this.teachers.Remove(Teacher);
            }
        }

        public void RemoveAllTeacher()
        {
            if (this.teachers != null)
                this.teachers.Clear();
        }

        public bool HasTeacher(string TeacherName)
        {
            bool b = false;
            if (this.teachers != null)
            {
                for (int i = 0; i < this.teachers.Count; i++)
                {
                    if (this.teachers[i].TeacherName == TeacherName)
                    {
                        b = true;
                        break;
                    }
                }
            }
            return b;
        }

        public bool HasTeacher(Teacher Teacher)
        {
            bool b = false;
            if (this.teachers != null)
            {
                for (int i = 0; i < this.teachers.Count; i++)
                {
                    if (this.teachers[i].TeacherName == Teacher.TeacherName)
                    {
                        b = true;
                        break;
                    }
                }
            }
            return b;
        }

        public Subject()
        {
            
        }

        public Subject(string SubjectName, EditLevel Level)
        {
            this.subjectName = SubjectName;
            this.level = Level;
        }

        ~Subject()
        {
            
        }

        public void Dispose()
        {
            
        }

        public Teacher GetTeacher(string TeacherName)
        {
            Teacher teacher = null;
            if (this.teachers != null)
            {
                for (int i = 0; i < this.teachers.Count; i++)
                {
                    if (this.teachers[i].TeacherName == TeacherName)
                    {
                        teacher = this.teachers[i];
                        break;
                    }
                }
            }
            return teacher;
        }
    }

    public static class School
    {
        public static string Term = "";

        private static IList<Teacher> teachers;

        public static IList<Teacher> Teachers
        {
            get { return School.teachers; }
            set { School.teachers = value; }
        }
        private static IList<Grade> grades;

        public static IList<Grade> Grades
        {
            get { return School.grades; }
            set { School.grades = value; }
        }
        private static IList<Subject> subjects;

        public static IList<Subject> Subjects
        {
            get { return School.subjects; }
            set { School.subjects = value; }
        }
        private static IList<Course> courses;

        public static IList<Course> Courses
        {
            get { return School.courses; }
            set { School.courses = value; }
        }
        private static IList<Class> classes;

        public static IList<Class> Classes
        {
            get { return School.classes; }
            set { School.classes = value; }
        }

        // 从数据库中载入数据
        private static readonly string sqlClass = "select * from 班级表";
        private static readonly string sqlRelationTable1 = "select * from 关系表1";
        private static readonly string sqlTeacher = "select * from 教师表";
        private static readonly string sqlSubject = "select * from 科目名称";
        private static readonly string sqlCourseTable = "select * from 课程表";

        private static readonly string classTableName = "班级表";
        private static readonly string relationTableName = "关系表1";
        private static readonly string teacherTableName = "教师表";
        private static readonly string subjectTableName = "科目名称";
        private static readonly string courseTableName = "课程表";

        private static readonly string idField = "编号";  // 主键
        private static readonly string classNameField = "班级名称";        // 班级名称
        private static readonly string classStartTimeField = "入学时间";   // 入学时间
        private static readonly string classLevelField = "教学级别";       // 教学级别
        private static readonly string relateTypeField = "关系类型";   // 关系类型
        private static readonly string relatePK1Field = "关系表1主键";    // 关系表1主键
        private static readonly string relatePK2Field = "关系表2主键";    // 关系表2主键
        private static readonly string teacherNameField = "姓名";  // 教师姓名
        private static readonly string subjectNameField = "科目名称";  // 科目名称
        private static readonly string courseTeacherIdField = "教师编号"; // 教师编号
        private static readonly string courseClassIdField = "班级编号";   // 班级编号
        private static readonly string courseSubjectIdField = "科目编号"; // 科目编号
        private static readonly string courseTimeField = "上课时间";      // 上课时

        public static void ReadProperties()
        {
            string path = AppDomain.CurrentDomain.BaseDirectory.ToString();
            path = path + "properties.txt";
            System.IO.FileStream fs = System.IO.File.Open(path, System.IO.FileMode.Open);
            byte[] bytes = new byte[fs.Length];
            fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
            StringBuilder sb = new StringBuilder();
            //for (int i = 0; i < bytes.Length; i++)
            //{
            //    sb.Append(Convert.ToChar(bytes[i]));
            //}
            Encoding unicode = Encoding.Unicode;
            char[] chars = new char[unicode.GetCharCount(bytes)];
            unicode.GetChars(bytes, 0, bytes.Length, chars, 0);
            for (int i = 0; i < chars.Length; i++)
            {
                sb.Append(chars[i].ToString());
            }

            //Encoding unicode = Encoding.Unicode;
            //Encoding assii = Encoding.ASCII;
            //byte[] assiiBytes = assii.GetBytes(sb.ToString());
            //byte[] unicodeBytes = Encoding.Convert(Encoding.ASCII, Encoding.Unicode, assiiBytes);
            //char[] chars = new char[unicode.GetCharCount(unicodeBytes)];
            //chars = unicode.GetChars(unicodeBytes);
            //sb.Remove(0, sb.Length);
            //for (int i = 0; i < chars.Length; i++)
            //{
            //    sb.Append(chars[i].ToString());
            //}

            string[] properties = sb.ToString().Split(';');
            for (int i = 0; i < properties.Length; i++)
            {
                string[] property = properties[i].Split('=');
                if (property.Length == 2)
                {
                    if (property[0].ToString().ToLower() == "term")
                    {
                        School.Term = property[1];
                    }
                }
            }
            fs.Close();
        }

        public static void WriteProperties()
        {
            string property = "term=" + School.Term + ";";
            string properties = property;
             
            UnicodeEncoding unicode = new UnicodeEncoding();
            byte[] bytes = new byte[unicode.GetByteCount(properties)];
            unicode.GetBytes(properties, 0, properties.Length, bytes, 0);
            //byte[] bytes = new byte[propertys.Length];
            //for (int i = 0; i < propertys.Length; i++)
            //{
            //    bytes[i] = Convert.ToByte(propertys[i]);
            //}
            string path = AppDomain.CurrentDomain.BaseDirectory.ToString();
            path = path + "properties.txt";
            System.IO.FileStream fs = System.IO.File.Open(path, System.IO.FileMode.Open);
            fs.Write(bytes, 0, bytes.Length);
            fs.Close();
        }

        public static void AddCourse(Course Course)
        {
            if (School.courses == null)
                School.courses = new List<Course>();
            if (!School.courses.Contains(Course))
                School.courses.Add(Course);
        }

        public static void AddGrade(Grade Grade)
        {
            if (School.grades == null)
                School.grades = new List<Grade>();
            if (!School.grades.Contains(Grade))
                School.grades.Add(Grade);
        }

        public static void AddClass(Class Class)
        {
            if (School.classes == null)
                School.classes = new List<Class>();
            if (!School.classes.Contains(Class))
                School.classes.Add(Class);
        }

        public static void AddSubject(Subject Subject)
        {
            if (School.subjects == null)
                School.subjects = new List<Subject>();
            if (!School.subjects.Contains(Subject))
                School.subjects.Add(Subject);
        }

        public static void AddTeacher(Teacher Teacher)
        {
            if (School.teachers == null)
                School.teachers = new List<Teacher>();
            if (!School.teachers.Contains(Teacher))
                School.teachers.Add(Teacher);
        }

        public static void RemoveClass(Class Class)
        {
            if (School.classes != null)
            {
                if (School.classes.Contains(Class))
                    School.classes.Remove(Class);
            }
        }

        public static void RemoveCourse(Course Course)
        {
            if (School.courses != null)
            {
                if (School.courses.Contains(Course))
                    School.courses.Remove(Course);
            }
        }

        public static void RemoveGrade(Grade Grade)
        {
            if (School.grades != null)
            {
                if (School.grades.Contains(Grade))
                    School.grades.Remove(Grade);
            }
        }

        public static void RemoveSubject(Subject Subject)
        {
            if (School.subjects != null)
            {
                if (School.subjects.Contains(Subject))
                    School.subjects.Remove(Subject);
            }
        }

        public static void RemoveTeacher(Teacher Teacher)
        {
            if (School.teachers != null)
            {
                if (School.teachers.Contains(Teacher))
                    School.teachers.Remove(Teacher);
            }
        }

        public static void RemoveAllClass()
        {
            if (School.teachers != null)
            {
                School.teachers.Clear();
            }
        }

        public static void RemoveAllCourse()
        {
            if (School.courses != null)
            {
                School.courses.Clear();
            }
        }

        public static void RemoveAllGrade()
        {
            if (School.grades != null)
            {
                School.grades.Clear();
            }
        }

        public static void RemoveAllSubject()
        {

⌨️ 快捷键说明

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