frmupdatestudent.cs

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

CS
359
字号
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Aptech.Student.DataAccess;
using Aptech.Student.Common;

namespace 学生管理系统
{
	/// <summary>
	/// frmUpdateStudent 的摘要说明。
	/// </summary>
	public class frmUpdateStudent : System.Windows.Forms.Form
	{
		string studentNo;
		int classId;
		frmMain frm;
		System.Data .DataSet dsClass;
		System.Data .DataSet dsStudents;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.ComboBox cmbClass;
		private System.Windows.Forms.DateTimePicker dateTimeBirthday;
		private System.Windows.Forms.ComboBox cmbSex;
		private System.Windows.Forms.TextBox txtName;
		private System.Windows.Forms.TextBox txtNo;
		private System.Windows.Forms.TextBox txtRemark;
		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.DataGrid dataGrid1;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmUpdateStudent(frmMain frm,string studentNo)
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			this.frm =frm;
			this.studentNo =studentNo;

			//
			// 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.button3 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.cmbClass = new System.Windows.Forms.ComboBox();
			this.dateTimeBirthday = new System.Windows.Forms.DateTimePicker();
			this.cmbSex = new System.Windows.Forms.ComboBox();
			this.txtName = new System.Windows.Forms.TextBox();
			this.txtNo = new System.Windows.Forms.TextBox();
			this.txtRemark = 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.dataGrid1 = new System.Windows.Forms.DataGrid();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(320, 312);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(88, 24);
			this.button3.TabIndex = 31;
			this.button3.Text = "退出";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(176, 312);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(96, 24);
			this.button2.TabIndex = 30;
			this.button2.Text = "删除";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(48, 312);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(88, 24);
			this.button1.TabIndex = 29;
			this.button1.Text = "更新";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// cmbClass
			// 
			this.cmbClass.Location = new System.Drawing.Point(136, 176);
			this.cmbClass.Name = "cmbClass";
			this.cmbClass.Size = new System.Drawing.Size(200, 20);
			this.cmbClass.TabIndex = 28;
			// 
			// dateTimeBirthday
			// 
			this.dateTimeBirthday.Location = new System.Drawing.Point(136, 136);
			this.dateTimeBirthday.Name = "dateTimeBirthday";
			this.dateTimeBirthday.TabIndex = 27;
			// 
			// cmbSex
			// 
			this.cmbSex.Items.AddRange(new object[] {
														"男",
														"女"});
			this.cmbSex.Location = new System.Drawing.Point(136, 96);
			this.cmbSex.Name = "cmbSex";
			this.cmbSex.Size = new System.Drawing.Size(200, 20);
			this.cmbSex.TabIndex = 26;
			// 
			// txtName
			// 
			this.txtName.Location = new System.Drawing.Point(136, 56);
			this.txtName.Name = "txtName";
			this.txtName.Size = new System.Drawing.Size(192, 21);
			this.txtName.TabIndex = 25;
			this.txtName.Text = "";
			// 
			// txtNo
			// 
			this.txtNo.Location = new System.Drawing.Point(136, 16);
			this.txtNo.Name = "txtNo";
			this.txtNo.Size = new System.Drawing.Size(192, 21);
			this.txtNo.TabIndex = 24;
			this.txtNo.Text = "";
			// 
			// txtRemark
			// 
			this.txtRemark.Location = new System.Drawing.Point(112, 216);
			this.txtRemark.Multiline = true;
			this.txtRemark.Name = "txtRemark";
			this.txtRemark.Size = new System.Drawing.Size(272, 72);
			this.txtRemark.TabIndex = 23;
			this.txtRemark.Text = "";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(16, 216);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(72, 24);
			this.label6.TabIndex = 22;
			this.label6.Text = "备注:";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(16, 176);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(72, 24);
			this.label5.TabIndex = 21;
			this.label5.Text = "所属班级";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(16, 136);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(72, 24);
			this.label4.TabIndex = 20;
			this.label4.Text = "出生日期";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 96);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(72, 24);
			this.label3.TabIndex = 19;
			this.label3.Text = "性别";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 56);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(72, 24);
			this.label2.TabIndex = 18;
			this.label2.Text = "姓名";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 24);
			this.label1.TabIndex = 17;
			this.label1.Text = "学号";
			// 
			// dataGrid1
			// 
			this.dataGrid1.DataMember = "";
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(32, 360);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.Size = new System.Drawing.Size(392, 72);
			this.dataGrid1.TabIndex = 32;
			// 
			// frmUpdateStudent
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(464, 438);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.button3);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.cmbClass);
			this.Controls.Add(this.dateTimeBirthday);
			this.Controls.Add(this.cmbSex);
			this.Controls.Add(this.txtName);
			this.Controls.Add(this.txtNo);
			this.Controls.Add(this.txtRemark);
			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 = "frmUpdateStudent";
			this.Text = "frmUpdateStudent";
			this.Load += new System.EventHandler(this.frmUpdateStudent_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void frmUpdateStudent_Load(object sender, System.EventArgs e)
		{//加载
			//将所有的班级写到cmbclass的items里
			Classs classes=new Classs ();
		    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;
			}
			//得到所点击的学生的信息的dataset
			Students students=new Students ();
			dsStudents=students.SelectStudent(-1,"" ,this.studentNo ,-1);
			this.classId =(int)dsStudents.Tables [0].Rows [0][5];
			this.txtNo.Text =dsStudents.Tables [0].Rows [0][1].ToString();
			this.txtName.Text =dsStudents.Tables [0].Rows [0][2].ToString();
			if((int)dsStudents.Tables [0].Rows [0][3]==0)//判断男女
			{
				this.cmbSex .SelectedIndex=0;
			}
			else
			{
				this.cmbSex .SelectedIndex=1;
			}
			this.dateTimeBirthday.Value=(System.DateTime )dsStudents.Tables [0].Rows [0][4];

			for(int i=0;i<this.cmbClass .Items.Count;i++)
			{   
				

				if(this.cmbClass .Items [i].ToString().Equals(dsStudents.Tables [0].Rows [0][8].ToString()))
				{
					
					this.cmbClass.SelectedIndex=i;
				
				}
			}

         
		
		}

		private void button1_Click(object sender, System.EventArgs e)
		{//更新
			Students student=new Students();
			Classs classes=new Classs ();
			this.dsClass=classes.SelectClass(-1,this.cmbClass.SelectedItem.ToString());
			int classId=(int)dsClass.Tables [0].Rows[0][0];
			this.dataGrid1.DataSource =dsStudents.Tables [0];
			int studentId=(int)dsStudents.Tables [0].Rows [0][0];



			if (student.UpdateStudent(studentId,this.txtNo.Text ,this.txtName.Text  ,this.dateTimeBirthday .Value,this.cmbSex .SelectedIndex,classId,this.txtRemark.Text))
			{
				MessageBox.Show ("更新成功");
			    this.frm .ShowStudent (-1,"","",this.classId );
			}
			else
			{

				MessageBox.Show ("更新失败");

			}
         
		
		}

		private void button2_Click(object sender, System.EventArgs e)
		{//删除
			Students student=new Students();
			Scores scores=new Scores ();
			DataBaseOperate db=new DataBaseOperate ();
			int studentId=(int)dsStudents.Tables [0].Rows [0][0];
			
			db.StartTransation ();
			scores.DeleteScore(-1,-1,studentId,-1);
			student.DeleteStudent(studentId,-1);
			if(	db.Commit())
			{
				
				MessageBox.Show ("删除成功");
			this.frm .ShowStudent (-1,"","",this.classId );
			}
			else
			{
				MessageBox.Show ("删除失败");
			}
		
		}

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

⌨️ 快捷键说明

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