frmaddcourse.cs

来自「我在北大青鸟学习cshop的作业(学生管理系统)!希望大家给以指导。」· CS 代码 · 共 258 行

CS
258
字号
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Aptech.Student.DataAccess;
using Aptech.Student.Common;
namespace 学生管理系统
{
	/// <summary>
	/// frmAddCourse 的摘要说明。
	/// </summary>
	public class frmAddCourse : System.Windows.Forms.Form
	{
		frmMain frm;
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.Button btnAdd;
		private System.Windows.Forms.TextBox txtRemark;
		private System.Windows.Forms.ComboBox cmbSubject;
		private System.Windows.Forms.ComboBox cmbClass;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.DateTimePicker dateTimePicker1;
		private System.Windows.Forms.DateTimePicker dateTimePicker2;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmAddCourse(frmMain frm)
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
            this.frm =frm;
			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

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

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.btnExit = new System.Windows.Forms.Button();
			this.btnAdd = new System.Windows.Forms.Button();
			this.txtRemark = new System.Windows.Forms.TextBox();
			this.cmbSubject = new System.Windows.Forms.ComboBox();
			this.cmbClass = new System.Windows.Forms.ComboBox();
			this.label5 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
			this.dateTimePicker2 = new System.Windows.Forms.DateTimePicker();
			this.SuspendLayout();
			// 
			// btnExit
			// 
			this.btnExit.Location = new System.Drawing.Point(283, 255);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(67, 32);
			this.btnExit.TabIndex = 23;
			this.btnExit.Text = "关闭";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// btnAdd
			// 
			this.btnAdd.Location = new System.Drawing.Point(110, 255);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.Size = new System.Drawing.Size(67, 32);
			this.btnAdd.TabIndex = 22;
			this.btnAdd.Text = "建立";
			this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
			// 
			// txtRemark
			// 
			this.txtRemark.Location = new System.Drawing.Point(177, 175);
			this.txtRemark.Multiline = true;
			this.txtRemark.Name = "txtRemark";
			this.txtRemark.Size = new System.Drawing.Size(259, 64);
			this.txtRemark.TabIndex = 21;
			this.txtRemark.Text = "";
			// 
			// cmbSubject
			// 
			this.cmbSubject.Location = new System.Drawing.Point(184, 63);
			this.cmbSubject.Name = "cmbSubject";
			this.cmbSubject.Size = new System.Drawing.Size(192, 20);
			this.cmbSubject.TabIndex = 18;
			// 
			// cmbClass
			// 
			this.cmbClass.Location = new System.Drawing.Point(184, 31);
			this.cmbClass.Name = "cmbClass";
			this.cmbClass.Size = new System.Drawing.Size(192, 20);
			this.cmbClass.TabIndex = 17;
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(52, 175);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(77, 16);
			this.label5.TabIndex = 16;
			this.label5.Text = "备注:";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(52, 135);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(77, 16);
			this.label4.TabIndex = 15;
			this.label4.Text = "结束日期:";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(52, 95);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(77, 16);
			this.label3.TabIndex = 14;
			this.label3.Text = "开课日期:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(52, 63);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(77, 16);
			this.label2.TabIndex = 13;
			this.label2.Text = "科目:";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(52, 31);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(77, 16);
			this.label1.TabIndex = 12;
			this.label1.Text = "班级:";
			// 
			// dateTimePicker1
			// 
			this.dateTimePicker1.Location = new System.Drawing.Point(184, 96);
			this.dateTimePicker1.Name = "dateTimePicker1";
			this.dateTimePicker1.Size = new System.Drawing.Size(192, 21);
			this.dateTimePicker1.TabIndex = 24;
			// 
			// dateTimePicker2
			// 
			this.dateTimePicker2.Location = new System.Drawing.Point(184, 136);
			this.dateTimePicker2.Name = "dateTimePicker2";
			this.dateTimePicker2.Size = new System.Drawing.Size(192, 21);
			this.dateTimePicker2.TabIndex = 25;
			// 
			// frmAddCourse
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(488, 318);
			this.Controls.Add(this.dateTimePicker2);
			this.Controls.Add(this.dateTimePicker1);
			this.Controls.Add(this.btnExit);
			this.Controls.Add(this.btnAdd);
			this.Controls.Add(this.txtRemark);
			this.Controls.Add(this.cmbSubject);
			this.Controls.Add(this.cmbClass);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Name = "frmAddCourse";
			this.Text = "frmAddCourse";
			this.Load += new System.EventHandler(this.frmAddCourse_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void frmAddCourse_Load(object sender, System.EventArgs e)
		{
			//读出数据库中班级和科目写到下来列表框
			Aptech.Student.DataAccess.Classs classes=new Classs ();
			Aptech.Student.DataAccess.Subjects subject =new Subjects ();
			System.Data .DataSet  dsClass=classes.SelectClass(-1,"");
			System.Data .DataSet  dsSubject=subject.SelectSubject(-1,"");
			
			foreach(System.Data .DataRow row in dsClass.Tables [0].Rows)
			{
				this.cmbClass .Items .Add (row[1].ToString());
			}
			//this.cmbClass.SelectedIndex=0;
            
			foreach(System.Data .DataRow row in dsSubject.Tables [0].Rows)
			{
				this.cmbSubject.Items .Add (row[1].ToString());
			}
			//this.cmbSubject.SelectedIndex=0; 



		}

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			Aptech.Student.DataAccess.Courses course=new Courses ();
			Aptech.Student.DataAccess.Classs classes=new Classs ();
			Aptech.Student.DataAccess.Subjects subject =new Subjects ();
			System.Data .DataSet  dsClass=classes.SelectClass(-1,this.cmbClass.SelectedItem.ToString());
			System.Data .DataSet  dsSubject=subject.SelectSubject(-1,this.cmbSubject.SelectedItem.ToString ());
			int classId=(int)dsClass.Tables[0].Rows [0][0];
			int    subjectId=(int)dsSubject.Tables[0].Rows [0][0];
			
			
			if	(course.InsertCourse(classId,subjectId,(DateTime)this.dateTimePicker1 .Value  ,(DateTime)this.dateTimePicker2 .Value ,this.txtRemark.Text ))
			{
				MessageBox.Show ("添加成功");
				this.frm.ShowCourse(-1,classId,-1);
			}
			else
			{
				MessageBox.Show ("添加失败");
			}


		



		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			this.Close ();
		}
	}
}

⌨️ 快捷键说明

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