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

📄 frmaddstudent.cs

📁 我在北大青鸟学习cshop的作业(学生管理系统)!希望大家给以指导。
💻 CS
字号:
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>
	/// frmAddStudent 的摘要说明。
	/// </summary>
	public class frmAddStudent : 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 cmbClass;
		private System.Windows.Forms.ComboBox cmbSex;
		private System.Windows.Forms.TextBox txtName;
		private System.Windows.Forms.TextBox txtNo;
		private System.Windows.Forms.Label label6;
		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;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmAddStudent(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.cmbClass = new System.Windows.Forms.ComboBox();
			this.cmbSex = new System.Windows.Forms.ComboBox();
			this.txtName = new System.Windows.Forms.TextBox();
			this.txtNo = new System.Windows.Forms.TextBox();
			this.label6 = new System.Windows.Forms.Label();
			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.SuspendLayout();
			// 
			// btnExit
			// 
			this.btnExit.Location = new System.Drawing.Point(392, 152);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(80, 40);
			this.btnExit.TabIndex = 27;
			this.btnExit.Text = "退出";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// btnAdd
			// 
			this.btnAdd.Location = new System.Drawing.Point(392, 104);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.Size = new System.Drawing.Size(80, 40);
			this.btnAdd.TabIndex = 26;
			this.btnAdd.Text = "添加";
			this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
			// 
			// txtRemark
			// 
			this.txtRemark.Location = new System.Drawing.Point(144, 272);
			this.txtRemark.Multiline = true;
			this.txtRemark.Name = "txtRemark";
			this.txtRemark.Size = new System.Drawing.Size(312, 104);
			this.txtRemark.TabIndex = 25;
			this.txtRemark.Text = "";
			// 
			// cmbClass
			// 
			this.cmbClass.Location = new System.Drawing.Point(144, 224);
			this.cmbClass.Name = "cmbClass";
			this.cmbClass.Size = new System.Drawing.Size(192, 20);
			this.cmbClass.TabIndex = 24;
			// 
			// cmbSex
			// 
			this.cmbSex.Items.AddRange(new object[] {
														"男",
														"女"});
			this.cmbSex.Location = new System.Drawing.Point(144, 120);
			this.cmbSex.Name = "cmbSex";
			this.cmbSex.Size = new System.Drawing.Size(192, 20);
			this.cmbSex.TabIndex = 22;
			// 
			// txtName
			// 
			this.txtName.Location = new System.Drawing.Point(144, 72);
			this.txtName.Name = "txtName";
			this.txtName.Size = new System.Drawing.Size(192, 21);
			this.txtName.TabIndex = 21;
			this.txtName.Text = "";
			// 
			// txtNo
			// 
			this.txtNo.Location = new System.Drawing.Point(144, 24);
			this.txtNo.Name = "txtNo";
			this.txtNo.Size = new System.Drawing.Size(192, 21);
			this.txtNo.TabIndex = 20;
			this.txtNo.Text = "";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(24, 272);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(80, 16);
			this.label6.TabIndex = 19;
			this.label6.Text = "备注:";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(24, 224);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(80, 16);
			this.label5.TabIndex = 18;
			this.label5.Text = "所属班级:";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(24, 168);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(80, 24);
			this.label4.TabIndex = 17;
			this.label4.Text = "出生年月:";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(24, 120);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(80, 24);
			this.label3.TabIndex = 16;
			this.label3.Text = "性别:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(24, 72);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(80, 24);
			this.label2.TabIndex = 15;
			this.label2.Text = "姓名:";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(24, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(80, 24);
			this.label1.TabIndex = 14;
			this.label1.Text = "学号:";
			// 
			// dateTimePicker1
			// 
			this.dateTimePicker1.Location = new System.Drawing.Point(144, 160);
			this.dateTimePicker1.Name = "dateTimePicker1";
			this.dateTimePicker1.Size = new System.Drawing.Size(192, 21);
			this.dateTimePicker1.TabIndex = 28;
			// 
			// frmAddStudent
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(544, 422);
			this.Controls.Add(this.dateTimePicker1);
			this.Controls.Add(this.btnExit);
			this.Controls.Add(this.btnAdd);
			this.Controls.Add(this.txtRemark);
			this.Controls.Add(this.cmbClass);
			this.Controls.Add(this.cmbSex);
			this.Controls.Add(this.txtName);
			this.Controls.Add(this.txtNo);
			this.Controls.Add(this.label6);
			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 = "frmAddStudent";
			this.Text = "frmAddStudent";
			this.Load += new System.EventHandler(this.frmAddStudent_Load);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void frmAddStudent_Load(object sender, System.EventArgs e)
		{//窗体加载
			//性别默认为男
			this.cmbSex.SelectedIndex=0;
			//读出数据库中所有的班级写到cmbClass中
			Classs classes=new Classs ();
		System.Data .DataSet   dsClass=classes.SelectClass(-1,"");
         
        
			foreach(System.Data.DataRow row in  dsClass.Tables [0].Rows)
			{   
				this.cmbClass.Items .Add (row[1].ToString());
				this.cmbClass.SelectedIndex=0;
			}
		
		}

		private void btnAdd_Click(object sender, System.EventArgs e)
		{//添加
			string sNo=this.txtNo.Text.Trim () ;
			string sName=this.txtName.Text .Trim ();
			string sSex=this.cmbSex.SelectedItem.ToString();
			DateTime  sTime=this.dateTimePicker1 .Value ;
			string sClass=this.cmbClass.SelectedItem .ToString();
			string sRemark=this.txtRemark.Text;
		
			if(sNo==""||sName=="")
			{
				MessageBox.Show ("请输入学生信息!");
				return;
			}
			//判断男女转换为int
			int sex;
			if(sSex.Equals("男"))
			{
				sex=0;
			}
			else
			{
				sex=1;
			}
			
			//根据班级名得到班级id
			Aptech.Student.DataAccess .Classs classes=new Classs ();
			System.Data .DataSet dsClass=classes.SelectClass(-1,sClass);
			int classId=(int)dsClass.Tables[0].Rows [0][0];
			Aptech.Student.DataAccess.Students students=new Students ();
			if(students.InsertStudent(sTime,sex,classId,0,sNo,sName,sRemark))
			{
				MessageBox.Show ("添加新学生成功");
				this.frm.ShowStudent (-1,"","",classId);
			}
			else
			{
				MessageBox.Show ("添加新学生失败");
			}


		
		}
	}
}

⌨️ 快捷键说明

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