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

📄 addcourse.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>
	/// addCourse 的摘要说明。
	/// </summary>
	public class addCourse : System.Windows.Forms.UserControl
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox textBox3;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox textBox4;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.TextBox textBox5;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox textBox6;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label13;
		/// <summary> 
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public addCourse()
		{
			// 该调用是 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.label2 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.textBox4 = new System.Windows.Forms.TextBox();
			this.label6 = new System.Windows.Forms.Label();
			this.textBox5 = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.label7 = new System.Windows.Forms.Label();
			this.textBox6 = new System.Windows.Forms.TextBox();
			this.label8 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.label10 = new System.Windows.Forms.Label();
			this.label11 = new System.Windows.Forms.Label();
			this.label12 = new System.Windows.Forms.Label();
			this.label13 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.Location = new System.Drawing.Point(192, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(120, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "录入课程信息";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(72, 64);
			this.label2.Name = "label2";
			this.label2.TabIndex = 1;
			this.label2.Text = "课程号";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(224, 64);
			this.textBox1.Name = "textBox1";
			this.textBox1.TabIndex = 2;
			this.textBox1.Text = "textBox1";
			// 
			// textBox2
			// 
			this.textBox2.Location = new System.Drawing.Point(224, 120);
			this.textBox2.Name = "textBox2";
			this.textBox2.TabIndex = 3;
			this.textBox2.Text = "textBox2";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(72, 120);
			this.label3.Name = "label3";
			this.label3.TabIndex = 4;
			this.label3.Text = "课程名";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(72, 168);
			this.label4.Name = "label4";
			this.label4.TabIndex = 5;
			this.label4.Text = "教学班号";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textBox3
			// 
			this.textBox3.Location = new System.Drawing.Point(224, 168);
			this.textBox3.Name = "textBox3";
			this.textBox3.TabIndex = 6;
			this.textBox3.Text = "textBox3";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(72, 224);
			this.label5.Name = "label5";
			this.label5.TabIndex = 7;
			this.label5.Text = "上课人数";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textBox4
			// 
			this.textBox4.Location = new System.Drawing.Point(224, 224);
			this.textBox4.Name = "textBox4";
			this.textBox4.TabIndex = 8;
			this.textBox4.Text = "textBox4";
			this.textBox4.TextChanged += new System.EventHandler(this.textBox4_TextChanged);
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(72, 280);
			this.label6.Name = "label6";
			this.label6.TabIndex = 9;
			this.label6.Text = "周学分";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textBox5
			// 
			this.textBox5.Location = new System.Drawing.Point(224, 280);
			this.textBox5.Name = "textBox5";
			this.textBox5.TabIndex = 10;
			this.textBox5.Text = "textBox5";
			this.textBox5.TextChanged += new System.EventHandler(this.textBox5_TextChanged);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(232, 400);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(80, 23);
			this.button1.TabIndex = 11;
			this.button1.Text = "确定";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(72, 328);
			this.label7.Name = "label7";
			this.label7.TabIndex = 12;
			this.label7.Text = "教师号";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textBox6
			// 
			this.textBox6.Location = new System.Drawing.Point(224, 328);
			this.textBox6.Name = "textBox6";
			this.textBox6.TabIndex = 13;
			this.textBox6.Text = "textBox6";
			// 
			// label8
			// 
			this.label8.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label8.ForeColor = System.Drawing.Color.IndianRed;
			this.label8.Location = new System.Drawing.Point(360, 64);
			this.label8.Name = "label8";
			this.label8.TabIndex = 14;
			this.label8.Text = "*";
			this.label8.Click += new System.EventHandler(this.label8_Click);
			// 
			// label9
			// 
			this.label9.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label9.ForeColor = System.Drawing.Color.IndianRed;
			this.label9.Location = new System.Drawing.Point(360, 120);
			this.label9.Name = "label9";
			this.label9.TabIndex = 15;
			this.label9.Text = "*";
			// 
			// label10
			// 
			this.label10.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label10.ForeColor = System.Drawing.Color.IndianRed;
			this.label10.Location = new System.Drawing.Point(360, 168);
			this.label10.Name = "label10";
			this.label10.TabIndex = 16;
			this.label10.Text = "*";
			// 
			// label11
			// 
			this.label11.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label11.ForeColor = System.Drawing.Color.IndianRed;
			this.label11.Location = new System.Drawing.Point(360, 224);
			this.label11.Name = "label11";
			this.label11.TabIndex = 17;
			this.label11.Text = "*";
			// 
			// label12
			// 
			this.label12.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label12.ForeColor = System.Drawing.Color.IndianRed;
			this.label12.Location = new System.Drawing.Point(360, 280);
			this.label12.Name = "label12";
			this.label12.TabIndex = 18;
			this.label12.Text = "*";
			// 
			// label13
			// 
			this.label13.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label13.ForeColor = System.Drawing.Color.IndianRed;
			this.label13.Location = new System.Drawing.Point(360, 328);
			this.label13.Name = "label13";
			this.label13.TabIndex = 19;
			this.label13.Text = "*";
			// 
			// addCourse
			// 
			this.Controls.Add(this.label13);
			this.Controls.Add(this.label12);
			this.Controls.Add(this.label11);
			this.Controls.Add(this.label10);
			this.Controls.Add(this.label9);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.textBox6);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.textBox5);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.textBox4);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.textBox3);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.textBox2);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Name = "addCourse";
			this.Size = new System.Drawing.Size(512, 472);
			this.Load += new System.EventHandler(this.addCourse_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void addCourse_Load(object sender, System.EventArgs e)
		{
			this.textBox1.Text = "";
			this.textBox2.Text = "";
			this.textBox3.Text = "";
			this.textBox4.Text = "";
			this.textBox5.Text = "";
			this.textBox6.Text = "";
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			bool check = false;
			if (this.textBox1.Text.Trim()==""&&this.textBox2.Text.Trim()==""&&this.textBox3.Text.Trim()==""&&this.textBox4.Text.Trim()==""&&this.textBox5.Text.Trim()==""&&this.textBox6.Text.Trim()=="")
			{
				MessageBox.Show("*标记的必须填!");
			}
			else
			{
				Connection c = new Connection();
				SqlConnection conn = new SqlConnection(c.getConnectionString);
				conn.Open();
				string str1 = "select * from teacher";
				string str2 = "select * from course";
				SqlCommand cmd2 = new SqlCommand(str2,conn);
				SqlCommand cmd1 = new SqlCommand(str1,conn);
				SqlDataReader drc = cmd2.ExecuteReader();
				while (drc.Read())
				{
					if (this.textBox1.Text.Trim() == Convert.ToString(drc["courseNo"])&&this.textBox3.Text.Trim() == Convert.ToString(drc["studyClassNo"]))
					{
						MessageBox.Show("课程编号冲突!");
						this.textBox1.Text = "";
						this.textBox3.Text = "";
						return;
					}
				}
				drc.Close();
				SqlDataReader dr1 = cmd1.ExecuteReader();
				while (dr1.Read())
				{
					if (this.textBox6.Text.Trim() == Convert.ToString(dr1["teacherNo"]))
					{
						check = true;
						break;
					}
				}
				if (check)
				{
					dr1.Close();
					dealCourse dc = new dealCourse();
					dc.Open();
					check = dc.AddCourseInfo(this.textBox1.Text.Trim(),this.textBox2.Text.Trim(),this.textBox3.Text.Trim(),Convert.ToInt32(this.textBox4.Text.Trim()),Convert.ToInt32(this.textBox5.Text.Trim()),this.textBox6.Text.Trim());
					if (check)
					{
						MessageBox.Show("添加成功!");
					}
					else
					{
						MessageBox.Show("添加失败!");
					}
					dc.Close();
				}
				else
				{
					MessageBox.Show("此教师不存在!");
					this.textBox6.Text = "";
					this.textBox6.Focus();
				}
			}
		}

		private void label8_Click(object sender, System.EventArgs e)
		{
		
		}

		private void textBox5_TextChanged(object sender, System.EventArgs e)
		{
			string str = this.textBox5.Text.Trim();
			if (this.textBox5.Text.Trim() != "")
			{
				try
				{
					int i = Convert.ToInt32(str);
					if (i >= 7)
					{
						MessageBox.Show("周学分设置不合理!");
						this.textBox5.Text = "";
						this.textBox5.Focus();
					}
				}
				catch
				{
					MessageBox.Show("周学分应为整数!");
					this.textBox5.Text = "";
					this.textBox5.Focus();
				}
			}
		}

		private void textBox4_TextChanged(object sender, System.EventArgs e)
		{
			string str = this.textBox4.Text.Trim();
			if (this.textBox4.Text.Trim() != "")
			{
				try
				{
					int i = Convert.ToInt32(str);
					if (i >= 300)
					{
						MessageBox.Show("上课人数设置不合理!");
						this.textBox4.Text = "";
						this.textBox4.Focus();
					}
				}
				catch
				{
					MessageBox.Show("人数应为整数!");
					this.textBox4.Text = "";
					this.textBox4.Focus();
				}
			}
		}
	}
}

⌨️ 快捷键说明

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