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

📄 frmprint.cs

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

namespace 课程安排
{
    public partial class frmPrint : Form
    {
        private List<PrintContent> printContents = null;

        public List<PrintContent> PrintContents
        {
            get { return printContents; }
            set { printContents = value; }
        }

        private PrintInfo printInformation = null;

        public PrintInfo PrintInformation
        {
            get { return printInformation; }
            set { printInformation = value; }
        }

        public frmPrint()
        {
            InitializeComponent();
            this.radioClass.Checked = true;
            this.radioSchool.Checked = true;

            this.printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
            this.printDocument1.BeginPrint += new PrintEventHandler(printDocument1_BeginPrint);
            this.printDocument1.DefaultPageSettings.Landscape = true;

            LoadGrade();
        }

        private void radioSchool_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioSchool.Checked)
            {
                this.comboClass.Enabled = false;
                this.comboGrade.Enabled = false;
            }
        }

        private void radioGrade_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioGrade.Checked)
            {
                this.comboGrade.Enabled = true;
            }
        }

        private void radioClass_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioClass.Checked)
            {
                this.comboClass.Enabled = true;
                this.comboGrade.Enabled = true;
            }
        }

        private void comboGrade_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.comboClass.Items.Clear();
            this.comboClass.Text = "";
            if (Utility.CheckComboText(this.comboGrade))
            {
                Grade grade = Utility.GetGradeObjectFromShowName(this.comboGrade.Text);
                if (this.radioClassCT.Checked)
                    LoadClass(grade);
                else
                    LoadTeacher(grade);
            }
        }

        private void radioClassCT_CheckedChanged(object sender, EventArgs e)
        {
            this.comboClass.Items.Clear();
            this.comboClass.Text = "";
            if (Utility.CheckComboText(this.comboGrade))
            {
                Grade grade = Utility.GetGradeObjectFromShowName(this.comboGrade.Text);
                if (this.radioClassCT.Checked)
                    LoadClass(grade);
                else
                    LoadTeacher(grade);
            }
        }

        private void radioTeacherCT_CheckedChanged(object sender, EventArgs e)
        {
            this.comboClass.Items.Clear();
            this.comboClass.Text = "";
            if (Utility.CheckComboText(this.comboGrade))
            {
                Grade grade = Utility.GetGradeObjectFromShowName(this.comboGrade.Text);
                if (this.radioClassCT.Checked)
                    LoadClass(grade);
                else
                    LoadTeacher(grade);
            }
        }

        #region 函数部分
        

        private void LoadGrade()
        {
            if (School.Grades != null)
            {
                for (int i = 0; i < School.Grades.Count; i++)
                {
                    string showGrade = Utility.GetShowGradeNameFromObject(School.Grades[i]);
                    this.comboGrade.Items.Add(showGrade);
                }
                if (this.comboGrade.Items.Count > 0)
                    this.comboGrade.SelectedIndex = 0;
                if (Utility.CheckComboText(this.comboGrade))
                {
                    Grade grade = Utility.GetGradeObjectFromShowName(this.comboGrade.Text);
                    LoadClass(grade);
                }
            }
        }
        private void LoadClass(Grade grade)
        {
            if (grade != null)
            {
                if (grade.Classes != null)
                {
                    this.comboClass.Items.Clear();
                    for (int i = 0; i < grade.Classes.Count; i++)
                    {
                        this.comboClass.Items.Add(grade.Classes[i].ClassName);
                    }
                    if (this.comboClass.Items.Count > 0)
                        this.comboClass.SelectedIndex = 0;
                }
            }
        }
        private void LoadTeacher(Grade grade)
        {
            if (grade != null)
            {
                if (grade.Teachers != null)
                {
                    this.comboClass.Items.Clear();
                    for (int i = 0; i < grade.Teachers.Count; i++)
                    {
                        this.comboClass.Items.Add(grade.Teachers[i].TeacherName);
                    }
                    if (this.comboClass.Items.Count > 0)
                        this.comboClass.SelectedIndex = 0;
                }
            }
        }
        //  将用户所选择的信息转换成相应的打印信息
        private bool GetPrintInfo()
        {
            bool b = true;
            if (this.printInformation == null)
                this.printInformation = new PrintInfo();
            if (this.radioClassCT.Checked)
                this.printInformation.Format = PrintInfo.PrintFormat.班级角度;
            else
                this.printInformation.Format = PrintInfo.PrintFormat.教师角度;

            if (this.radioSchool.Checked)
            {
                this.printInformation.Select = PrintInfo.PrintSelect.全校;
                this.printInformation.SelectInfo = "";
            }
            else if (this.radioGrade.Checked)
            {
                this.printInformation.Select = PrintInfo.PrintSelect.全年级;
                if (Utility.CheckComboText(this.comboGrade))
                    this.printInformation.SelectInfo = Utility.GetGradeObjectFromShowName(this.comboGrade.Text).GradeName;
                else
                {
                    MessageBox.Show("请从下拉框中选择一个年级", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    b = false;
                }
                    
            }
            else
            {
                this.printInformation.Select = PrintInfo.PrintSelect.班级;
                if (Utility.CheckComboText(this.comboClass))
                    this.printInformation.SelectInfo = this.comboClass.Text;
                else
                {
                    MessageBox.Show("请从下拉框中选择一个班级", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    b = false;
                }
            }
            return b;
        }
        //  根据打印信息创建打印数据
        private void CreatePrintContents(PrintInfo pi)
        {
            if (this.printContents == null)
                this.printContents = new List<PrintContent>();
            else
                this.printContents.Clear();

            if (pi != null)
            {
                if (pi.Format == PrintInfo.PrintFormat.教师角度)
                {
                    if (pi.Select == PrintInfo.PrintSelect.全校)
                    {
                        if (School.Teachers != null)
                        {
                            for (int i = 0; i < School.Teachers.Count; i++)
                            {
                                if (School.Teachers[i].CourseTable != null)
                                {
                                    PrintContent pc = new PrintContent();
                                    pc.ClassName = "";
                                    pc.TeacherName = "教师: " + School.Teachers[i].TeacherName;
                                    pc.Term = School.Term;      
                                    pc.CourseTableType = CourseTableType.教师;
                                    pc.CourseTable = GetPrintTableContent(School.Teachers[i].CourseTable, pi.Format);
                                    this.printContents.Add(pc);
                                }

                            }
                        }
                    }
                    else if (pi.Select == PrintInfo.PrintSelect.全年级)
                    {
                        Grade grade = School.GetGrade(pi.SelectInfo);
                        if (grade != null)
                        {
                            if (grade.Teachers != null)
                            {
                                for (int i = 0; i < grade.Teachers.Count; i++)
                                {
                                    Teacher teacher = grade.Teachers[i];
                                    if (teacher.CourseTable != null)
                                    {
                                        PrintContent pc = new PrintContent();
                                        pc.ClassName = "";
                                        pc.TeacherName = "教师: " + teacher.TeacherName;
                                        pc.Term = School.Term;      
                                        pc.CourseTableType = CourseTableType.教师;
                                        pc.CourseTable = GetPrintTableContent(teacher.CourseTable, pi.Format);
                                        this.printContents.Add(pc);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Teacher teacher = School.GetTeacher(pi.SelectInfo);
                        if (teacher != null)
                        {
                            if (teacher.CourseTable != null)
                            {
                                PrintContent pc = new PrintContent();
                                pc.ClassName = "";
                                pc.TeacherName = "教师: " + teacher.TeacherName;
                                pc.Term = School.Term;      
                                pc.CourseTableType = CourseTableType.教师;
                                pc.CourseTable = GetPrintTableContent(teacher.CourseTable, pi.Format);
                                this.printContents.Add(pc);
                            }
                        }
                    }
                }
                else
                {
                    if (pi.Select == PrintInfo.PrintSelect.全校)
                    {
                        if (School.Classes != null)
                        {
                            for (int i = 0; i < School.Classes.Count; i++)
                            {
                                Class cls = School.Classes[i];
                                if (cls.CourseTable != null)
                                {
                                    PrintContent pc = new PrintContent();
                                    pc.ClassName = "班级: " + cls.ClassName;
                                    pc.TeacherName = "";
                                    pc.Term = School.Term;      
                                    pc.CourseTableType = CourseTableType.班级;
                                    pc.CourseTable = GetPrintTableContent(cls.CourseTable, pi.Format);
                                    this.printContents.Add(pc);
                                }
                            }

⌨️ 快捷键说明

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