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

📄 frmupdatestudent.cs

📁 三层体系结构的应用-学员管理系统 一个学校需要一个学生管理系统。分以下功能: 管理班档案 管理学生档案 学校开了多门课程
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Student
{
	using Aptech.Student.Business;
	using Aptech.Student.DataAccess;

	/// <summary>
	/// frmUpdateStudent 的摘要说明。
	/// </summary>
	public class frmUpdateStudent : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox txtStudentNo;
		private System.Windows.Forms.Label lblStudentNo;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox txtRemark;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtStudentName;
		private System.Windows.Forms.ComboBox ddlGender;
		private System.Windows.Forms.ComboBox ddlClass;
		private System.Windows.Forms.Button btnModify;
		private System.Windows.Forms.Button btnDelete;
		private System.Windows.Forms.Button btnClose;
		private System.Windows.Forms.GroupBox groupBox1;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.DateTimePicker txtBirthday;
		private int	m_iStudentId;

		public frmUpdateStudent()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		public frmUpdateStudent(
			int		iStudentId)
		{
			m_iStudentId = iStudentId;
			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.txtStudentNo = new System.Windows.Forms.TextBox();
			this.lblStudentNo = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.txtRemark = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.txtStudentName = new System.Windows.Forms.TextBox();
			this.ddlGender = new System.Windows.Forms.ComboBox();
			this.txtBirthday = new System.Windows.Forms.DateTimePicker();
			this.ddlClass = new System.Windows.Forms.ComboBox();
			this.btnModify = new System.Windows.Forms.Button();
			this.btnDelete = new System.Windows.Forms.Button();
			this.btnClose = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// txtStudentNo
			// 
			this.txtStudentNo.Location = new System.Drawing.Point(120, 16);
			this.txtStudentNo.Name = "txtStudentNo";
			this.txtStudentNo.Size = new System.Drawing.Size(160, 21);
			this.txtStudentNo.TabIndex = 0;
			this.txtStudentNo.Text = "";
			// 
			// lblStudentNo
			// 
			this.lblStudentNo.Location = new System.Drawing.Point(40, 16);
			this.lblStudentNo.Name = "lblStudentNo";
			this.lblStudentNo.Size = new System.Drawing.Size(70, 23);
			this.lblStudentNo.TabIndex = 1;
			this.lblStudentNo.Text = "学号:";
			this.lblStudentNo.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(40, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(70, 23);
			this.label2.TabIndex = 2;
			this.label2.Text = "姓名:";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(40, 80);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(70, 23);
			this.label3.TabIndex = 3;
			this.label3.Text = "性别:";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(40, 112);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(70, 23);
			this.label4.TabIndex = 4;
			this.label4.Text = "出生日期:";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(40, 144);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(70, 23);
			this.label5.TabIndex = 5;
			this.label5.Text = "所属班级:";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtRemark
			// 
			this.txtRemark.Location = new System.Drawing.Point(120, 176);
			this.txtRemark.Multiline = true;
			this.txtRemark.Name = "txtRemark";
			this.txtRemark.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
			this.txtRemark.Size = new System.Drawing.Size(320, 104);
			this.txtRemark.TabIndex = 6;
			this.txtRemark.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(40, 176);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(70, 23);
			this.label1.TabIndex = 7;
			this.label1.Text = "备注:";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtStudentName
			// 
			this.txtStudentName.Location = new System.Drawing.Point(120, 48);
			this.txtStudentName.Name = "txtStudentName";
			this.txtStudentName.Size = new System.Drawing.Size(160, 21);
			this.txtStudentName.TabIndex = 8;
			this.txtStudentName.Text = "";
			// 
			// ddlGender
			// 
			this.ddlGender.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.ddlGender.Items.AddRange(new object[] {
														   "男",
														   "女"});
			this.ddlGender.Location = new System.Drawing.Point(120, 80);
			this.ddlGender.Name = "ddlGender";
			this.ddlGender.Size = new System.Drawing.Size(160, 20);
			this.ddlGender.TabIndex = 9;
			// 
			// txtBirthday
			// 
			this.txtBirthday.CustomFormat = "yyyy-MM-dd HH:mm:ss";
			this.txtBirthday.Location = new System.Drawing.Point(120, 112);
			this.txtBirthday.Name = "txtBirthday";
			this.txtBirthday.Size = new System.Drawing.Size(160, 21);
			this.txtBirthday.TabIndex = 10;
			// 
			// ddlClass
			// 
			this.ddlClass.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.ddlClass.Location = new System.Drawing.Point(120, 144);
			this.ddlClass.Name = "ddlClass";
			this.ddlClass.Size = new System.Drawing.Size(160, 20);
			this.ddlClass.TabIndex = 11;
			// 
			// btnModify
			// 
			this.btnModify.Location = new System.Drawing.Point(144, 296);
			this.btnModify.Name = "btnModify";
			this.btnModify.Size = new System.Drawing.Size(75, 22);
			this.btnModify.TabIndex = 12;
			this.btnModify.Text = "应用";
			this.btnModify.Click += new System.EventHandler(this.btnModify_Click);
			// 
			// btnDelete
			// 
			this.btnDelete.Location = new System.Drawing.Point(224, 296);
			this.btnDelete.Name = "btnDelete";
			this.btnDelete.Size = new System.Drawing.Size(75, 22);
			this.btnDelete.TabIndex = 13;
			this.btnDelete.Text = "删除";
			this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
			// 
			// btnClose
			// 
			this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnClose.Location = new System.Drawing.Point(304, 296);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new System.Drawing.Size(75, 22);
			this.btnClose.TabIndex = 14;
			this.btnClose.Text = "关闭";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.txtBirthday);
			this.groupBox1.Controls.Add(this.ddlClass);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.txtStudentNo);
			this.groupBox1.Controls.Add(this.label4);
			this.groupBox1.Controls.Add(this.ddlGender);
			this.groupBox1.Controls.Add(this.label5);
			this.groupBox1.Controls.Add(this.txtRemark);
			this.groupBox1.Controls.Add(this.txtStudentName);
			this.groupBox1.Controls.Add(this.lblStudentNo);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Location = new System.Drawing.Point(-8, -8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(500, 296);
			this.groupBox1.TabIndex = 15;
			this.groupBox1.TabStop = false;
			// 
			// frmUpdateStudent
			// 
			this.AcceptButton = this.btnModify;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.CancelButton = this.btnClose;
			this.ClientSize = new System.Drawing.Size(472, 326);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.btnDelete);
			this.Controls.Add(this.btnModify);
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmUpdateStudent";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "更新学生信息";
			this.Load += new System.EventHandler(this.frmUpdateStudent_Load);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void frmUpdateStudent_Load(object sender, System.EventArgs e)
		{
			GetGender();
			GetClass();
			GetStudentInfo();
		}

		private void GetGender()
		{
			
		}	

		private void GetClass()
		{
			Classs classs = new Classs();
			DataSet dataSet = new DataSet();
			try
			{
				dataSet = classs.SelectClass(
					-1,
					"");
			}
			catch(Exception e)
			{
				MessageBox.Show(e.Message);
				this.Close();
				return;
			}
			ddlClass.DisplayMember = "ClassName";
			ddlClass.ValueMember = "ClassId";
			ddlClass.DataSource = dataSet.Tables[0];
		}

		private void GetStudentInfo()
		{
			Students students = new Students();
			DataSet dataSet = new DataSet();
			try
			{
				dataSet = students.SelectStudent(
					m_iStudentId,
					"",
					"",
					-1);
			}
			catch(Exception e)
			{
				MessageBox.Show(e.Message);
			}
			if(dataSet.Tables[0].Rows.Count == 0)
			{
				MessageBox.Show("学生信息不存在。");
				this.Close();
				this.Dispose();
			}
			DataRow  row = dataSet.Tables[0].Rows[0];
			this.txtRemark.Text = row["Remark"].ToString();
			this.txtStudentName.Text = row["StudentName"].ToString();
			this.txtStudentNo.Text = row["StudentNo"].ToString();
			ddlClass.SelectedValue = Convert.ToInt32(row["ClassId"]);
			ddlGender.SelectedIndex = Convert.ToInt32(row["Gender"]);
		}

		private void btnDelete_Click(object sender, System.EventArgs e)
		{
			Students students = new Students();
			try
			{
				students.DeleteStudent(
					m_iStudentId,
					-1);
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
				students.Dispose();
				return;
			}
			MessageBox.Show("删除成功。");
			students.Dispose();
			this.Close();
		}

		private void btnModify_Click(object sender, System.EventArgs e)
		{
			Students students = new Students();
			try
			{
				students.UpdateStudent(
					m_iStudentId,
					txtStudentNo.Text,
					txtStudentName.Text,
					txtBirthday.Value,
					ddlGender.SelectedIndex,
					Convert.ToInt32(ddlClass.SelectedValue),
					txtRemark.Text);
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
				students.Dispose();
				return;
			}
			MessageBox.Show("更改成功。");
			students.Dispose();
		}
	}
}

⌨️ 快捷键说明

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