frmupdateclass.cs

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

CS
296
字号
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Aptech.Student.DataAccess;
using Aptech.Student.Common;
using System.Data ;
namespace 学生管理系统
{
	/// <summary>
	/// frmUpdateClass 的摘要说明。
	/// </summary>
	public class frmUpdateClass : System.Windows.Forms.Form
	{
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		
		string className;
		frmMain frm;
	
		private int classId;
		
		private System.DateTime classEnterTime;
		private System.Windows.Forms.DateTimePicker dateTimePicker1;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.ListView lvSubject;
		private System.Windows.Forms.TextBox txtName;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtRemark;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.ComponentModel.Container components = null;

		public frmUpdateClass(frmMain frm,string className)
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
           
			this.frm =frm;
         this.className =className;
			//
			// 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.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
			this.button3 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.panel1 = new System.Windows.Forms.Panel();
			this.lvSubject = new System.Windows.Forms.ListView();
			this.txtName = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.txtRemark = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.panel1.SuspendLayout();
			this.SuspendLayout();
			// 
			// dateTimePicker1
			// 
			this.dateTimePicker1.Location = new System.Drawing.Point(164, 63);
			this.dateTimePicker1.Name = "dateTimePicker1";
			this.dateTimePicker1.Size = new System.Drawing.Size(160, 21);
			this.dateTimePicker1.TabIndex = 20;
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(364, 327);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(64, 24);
			this.button3.TabIndex = 19;
			this.button3.Text = "退出";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(228, 327);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(80, 24);
			this.button2.TabIndex = 18;
			this.button2.Text = "删除";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(116, 327);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(64, 24);
			this.button1.TabIndex = 17;
			this.button1.Text = "更新";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.lvSubject);
			this.panel1.Location = new System.Drawing.Point(84, 175);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(392, 128);
			this.panel1.TabIndex = 16;
			// 
			// lvSubject
			// 
			this.lvSubject.CheckBoxes = true;
			this.lvSubject.Location = new System.Drawing.Point(0, 8);
			this.lvSubject.Name = "lvSubject";
			this.lvSubject.Size = new System.Drawing.Size(384, 112);
			this.lvSubject.TabIndex = 0;
			this.lvSubject.View = System.Windows.Forms.View.List;
			// 
			// txtName
			// 
			this.txtName.Location = new System.Drawing.Point(164, 31);
			this.txtName.Name = "txtName";
			this.txtName.Size = new System.Drawing.Size(160, 21);
			this.txtName.TabIndex = 15;
			this.txtName.Text = "";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(76, 103);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(56, 16);
			this.label3.TabIndex = 14;
			this.label3.Text = "备注:";
			// 
			// txtRemark
			// 
			this.txtRemark.Location = new System.Drawing.Point(164, 103);
			this.txtRemark.Multiline = true;
			this.txtRemark.Name = "txtRemark";
			this.txtRemark.Size = new System.Drawing.Size(160, 64);
			this.txtRemark.TabIndex = 13;
			this.txtRemark.Text = "";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(76, 67);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(56, 16);
			this.label2.TabIndex = 12;
			this.label2.Text = "入学时间";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(76, 31);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 16);
			this.label1.TabIndex = 11;
			this.label1.Text = "班级名:";
			// 
			// frmUpdateClass
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(536, 382);
			this.Controls.Add(this.dateTimePicker1);
			this.Controls.Add(this.button3);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.txtName);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.txtRemark);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Name = "frmUpdateClass";
			this.Text = "frmUpdateClass";
			this.Load += new System.EventHandler(this.frmUpdateClass_Load);
			this.panel1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void frmUpdateClass_Load(object sender, System.EventArgs e)
		{
			//窗体加载
			//显示文本
			this.txtName.Text =this.className;
			Aptech.Student.DataAccess.Classs classes=new Classs ();
			System.Data.DataSet  dsclass=classes.SelectClass(-1,this.txtName.Text);
			this.classId =(int)(int)dsclass.Tables[0].Rows[0][0];
			this.classEnterTime =(System.DateTime)dsclass.Tables[0].Rows[0][2];
			this.dateTimePicker1 .Value =(System.DateTime)dsclass.Tables[0].Rows[0][2];
			this.txtRemark.Text=dsclass.Tables[0].Rows[0][3].ToString();
			//得到所有的科目写道ListView中
			Aptech.Student.DataAccess.Subjects subjects=new Subjects ();
			System.Data.DataSet dsSubjects=subjects.SelectSubject(-1,"");
			Aptech.Student.DataAccess.Courses course=new Courses ();
			System.Data.DataSet dsCourses=course.SelectCourse(-1,this.classId,-1);
			
			foreach(System.Data.DataRow row in dsSubjects.Tables [0].Rows )
			{
				ListViewItem item=new ListViewItem (row[1].ToString (),2);
				this.lvSubject.Items .Add (item);
				
			}

			foreach(System.Data.DataRow rc in dsCourses.Tables [0].Rows   )
			{
				for(int i=0;i<this.lvSubject .Items .Count ;i++)
				{
					if(this.lvSubject .Items[i].Text .Equals (rc[7].ToString()))
					{
						this.lvSubject .Items[i].Checked=true;
					}
				}
			}
         

         

		
		}

		private void button1_Click(object sender, System.EventArgs e)//更新
		{
			Classs classes=new Classs ();
         
			if(classes.UpdateClass (this.classId ,this.className ,this.classEnterTime ,this.txtRemark .Text ))
			{
				MessageBox.Show("更新成功");
				this.frm .ShowClass ();
			}
			else
			{
				MessageBox.Show("更新失败");
			}
           
		
		}

		private void button2_Click(object sender, System.EventArgs e)//删除
		{
			DataBaseOperate  db=new DataBaseOperate (); 
			Classs  classes=new Classs ();
			Courses courses=new Courses ();
			Scores scores=new Scores ();
			Students students=new Students ();
			
			try
			{
				db.StartTransation(); 
				scores.DeleteScore(-1,-1,-1,this.classId );
				courses.DeleteCourse(-1,-1,this.classId );
				students.DeleteStudent(-1,this.classId );
				classes.DeleteClass(this.classId );
				
				db.Commit();
				MessageBox.Show ("删除成功");
				this.frm .ShowClass ();
				
			}
			catch(Exception ex)
			{
				MessageBox.Show ("删除失败");
			}
		
		}

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

⌨️ 快捷键说明

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