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

📄 fteacher.cs

📁 排课系统
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace PK
{
	/// <summary>
	/// fTeacher 的摘要说明。
	/// </summary>
	public class fTeacher : System.Windows.Forms.UserControl
	{
		public event System.EventHandler TCallMessage;
		public event System.EventHandler TCallMessageL;
		public event System.EventHandler NoDisplayL;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private string teacherNo;
		public string getTeacherNo
		{
			get
			{
				return teacherNo;
			}
		}
		/// <summary> 
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public fTeacher()
		{
			// 该调用是 Windows.Forms 窗体设计器所必需的。
			InitializeComponent();

			// TODO: 在 InitializeComponent 调用后添加任何初始化

		}

		/// <summary> 
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region 组件设计器生成的代码
		/// <summary> 
		/// 设计器支持所需的方法 - 不要使用代码编辑器 
		/// 修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(24, 16);
			this.label1.Name = "label1";
			this.label1.TabIndex = 0;
			this.label1.Text = "教师课表查询";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// listBox1
			// 
			this.listBox1.ItemHeight = 12;
			this.listBox1.Location = new System.Drawing.Point(16, 64);
			this.listBox1.Name = "listBox1";
			this.listBox1.Size = new System.Drawing.Size(152, 232);
			this.listBox1.TabIndex = 1;
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(56, 312);
			this.button1.Name = "button1";
			this.button1.TabIndex = 2;
			this.button1.Text = "查询";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(56, 360);
			this.button2.Name = "button2";
			this.button2.TabIndex = 3;
			this.button2.Text = "返回";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// fTeacher
			// 
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.listBox1);
			this.Controls.Add(this.label1);
			this.Name = "fTeacher";
			this.Size = new System.Drawing.Size(200, 416);
			this.Load += new System.EventHandler(this.fTeacher_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void fTeacher_Load(object sender, System.EventArgs e)
		{
			Connection c = new Connection();
			SqlConnection conn = new SqlConnection(c.getConnectionString);
			conn.Open();
			string str = "";
			string strsql = "select * from teacher";
			SqlCommand cmd = new SqlCommand(strsql,conn);
			SqlDataReader dr = cmd.ExecuteReader();
			while (dr.Read())
			{
				str = Convert.ToString(dr["teacherName"]);
				this.listBox1.Items.Add(str);
			}
			dr.Close();
			conn.Close();
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			string str = "";
			try
			{
				str = this.listBox1.SelectedItem.ToString();
				Connection c = new Connection();
				SqlConnection conn = new SqlConnection(c.getConnectionString);
				conn.Open();
				string str1 = "select * from teacher";
				SqlCommand cmd = new SqlCommand(str1,conn);
				SqlDataReader dr = cmd.ExecuteReader();
				while (dr.Read())
				{
					if (str == Convert.ToString(dr["teacherName"]))
					{
						this.teacherNo = Convert.ToString(dr["teacherNo"]);
						if (staticClass.isTeacher(this.teacherNo))
						{
							if (TCallMessageL != null)
								TCallMessageL(sender,e);
							break;
						}
						else
						{
							if (NoDisplayL != null)
								NoDisplayL(sender,e);
							MessageBox.Show("此教师未安排课程!");
						}
					}
				}
				dr.Close();
				conn.Close();
			}
			catch
			{
				if (NoDisplayL != null)
					NoDisplayL(sender,e);
				MessageBox.Show("请选择教师!");
			}
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			if (TCallMessage != null)
				TCallMessage(sender,e);
		}
	}
}

⌨️ 快捷键说明

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