frmupdatecourse.cs

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

CS
307
字号
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>
	/// frmUpdateCourse 的摘要说明。
	/// </summary>
	public class frmUpdateCourse : System.Windows.Forms.Form
	{
		string courseName;
		frmMain frm;
	
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.Button btnDelect;
		private System.Windows.Forms.Button btnUpdate;
		private System.Windows.Forms.TextBox txtRemark;
		private System.Windows.Forms.DateTimePicker dateTimePicker2;
		private System.Windows.Forms.DateTimePicker dateTimePicker1;
		private System.Windows.Forms.TextBox txtSubject;
		private System.Windows.Forms.TextBox txtClassName;
		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;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmUpdateCourse(string courseName,
			frmMain frm)
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			this.courseName =courseName;
			
			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.btnDelect = new System.Windows.Forms.Button();
			this.btnUpdate = new System.Windows.Forms.Button();
			this.txtRemark = new System.Windows.Forms.TextBox();
			this.dateTimePicker2 = new System.Windows.Forms.DateTimePicker();
			this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
			this.txtSubject = new System.Windows.Forms.TextBox();
			this.txtClassName = new System.Windows.Forms.TextBox();
			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.SuspendLayout();
			// 
			// btnExit
			// 
			this.btnExit.Location = new System.Drawing.Point(328, 272);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(80, 24);
			this.btnExit.TabIndex = 25;
			this.btnExit.Text = "退出";
			// 
			// btnDelect
			// 
			this.btnDelect.Location = new System.Drawing.Point(200, 272);
			this.btnDelect.Name = "btnDelect";
			this.btnDelect.Size = new System.Drawing.Size(80, 24);
			this.btnDelect.TabIndex = 24;
			this.btnDelect.Text = "删除";
			this.btnDelect.Click += new System.EventHandler(this.btnDelect_Click);
			// 
			// btnUpdate
			// 
			this.btnUpdate.Location = new System.Drawing.Point(64, 272);
			this.btnUpdate.Name = "btnUpdate";
			this.btnUpdate.Size = new System.Drawing.Size(80, 24);
			this.btnUpdate.TabIndex = 23;
			this.btnUpdate.Text = "更新";
			this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
			// 
			// txtRemark
			// 
			this.txtRemark.Location = new System.Drawing.Point(176, 192);
			this.txtRemark.Multiline = true;
			this.txtRemark.Name = "txtRemark";
			this.txtRemark.Size = new System.Drawing.Size(200, 64);
			this.txtRemark.TabIndex = 22;
			this.txtRemark.Text = "";
			// 
			// dateTimePicker2
			// 
			this.dateTimePicker2.Location = new System.Drawing.Point(176, 152);
			this.dateTimePicker2.Name = "dateTimePicker2";
			this.dateTimePicker2.Size = new System.Drawing.Size(144, 21);
			this.dateTimePicker2.TabIndex = 21;
			// 
			// dateTimePicker1
			// 
			this.dateTimePicker1.Location = new System.Drawing.Point(176, 112);
			this.dateTimePicker1.Name = "dateTimePicker1";
			this.dateTimePicker1.Size = new System.Drawing.Size(144, 21);
			this.dateTimePicker1.TabIndex = 20;
			// 
			// txtSubject
			// 
			this.txtSubject.Enabled = false;
			this.txtSubject.Location = new System.Drawing.Point(176, 72);
			this.txtSubject.Name = "txtSubject";
			this.txtSubject.Size = new System.Drawing.Size(144, 21);
			this.txtSubject.TabIndex = 19;
			this.txtSubject.Text = "";
			// 
			// txtClassName
			// 
			this.txtClassName.Enabled = false;
			this.txtClassName.Location = new System.Drawing.Point(176, 32);
			this.txtClassName.Name = "txtClassName";
			this.txtClassName.Size = new System.Drawing.Size(144, 21);
			this.txtClassName.TabIndex = 18;
			this.txtClassName.Text = "";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(32, 192);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(96, 24);
			this.label5.TabIndex = 17;
			this.label5.Text = "备注";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(32, 152);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(96, 24);
			this.label4.TabIndex = 16;
			this.label4.Text = "结束日期";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(32, 112);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(96, 24);
			this.label3.TabIndex = 15;
			this.label3.Text = "开始日期";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(32, 72);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(96, 24);
			this.label2.TabIndex = 14;
			this.label2.Text = "科目";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(32, 32);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(96, 24);
			this.label1.TabIndex = 13;
			this.label1.Text = "班级";
			// 
			// frmUpdateCourse
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(520, 366);
			this.Controls.Add(this.btnExit);
			this.Controls.Add(this.btnDelect);
			this.Controls.Add(this.btnUpdate);
			this.Controls.Add(this.txtRemark);
			this.Controls.Add(this.dateTimePicker2);
			this.Controls.Add(this.dateTimePicker1);
			this.Controls.Add(this.txtSubject);
			this.Controls.Add(this.txtClassName);
			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 = "frmUpdateCourse";
			this.Text = "frmUpdateCourse";
			this.Load += new System.EventHandler(this.frmUpdateCourse_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void frmUpdateCourse_Load(object sender, System.EventArgs e)
		{//加载
			foreach(DataRow row in this.frm .dsCourses.Tables [0].Rows)
			{
				if(this.courseName.Equals (row[7].ToString()))
				{
					this.txtClassName.Text  =row[6].ToString ();
					this.txtSubject.Text =row[7].ToString ();
					this.dateTimePicker1.Value =(DateTime)row[3];
					this.dateTimePicker2.Value =(DateTime)row[4];
					this.txtRemark.Text =row[5].ToString ();

				}
			}
	
		
		}

		private void btnUpdate_Click(object sender, System.EventArgs e)
		{//更新 
			Courses course=new Courses ();
			int courseId=0;
			int classId=0;
			foreach(DataRow row in this.frm.dsCourses .Tables [0].Rows)
			{
				if(this.courseName.Equals (row[7].ToString()))
				{
					courseId=(int)row[0];
					classId=(int)row[1];

				}
			}
              
			if(course.UpdateCourse(courseId,(DateTime)this.dateTimePicker1.Value ,(DateTime)this.dateTimePicker2.Value ,this.txtRemark.Text ))
			{
				MessageBox.Show ("更新成功");
				this.frm .ShowCourse(-1,classId,-1);
			}
			else
			{
				MessageBox.Show ("更新失败");
			}

		
		}

		private void btnDelect_Click(object sender, System.EventArgs e)
		{//删除
			Aptech.Student.DataAccess.Courses course=new Courses ();
			Aptech.Student.DataAccess.Scores scores=new Scores ();
			Aptech.Student.Common.DataBaseOperate db=new DataBaseOperate ();
			int courseId=0;
			int subjectId=0;
			int classId=0;
			foreach(DataRow row in this.frm.dsCourses .Tables [0].Rows)
			{
				if(this.courseName.Equals (row[7].ToString()))
				{
					courseId=(int)row[0];
					subjectId=(int)row[2];
					classId=(int)row[1];
				}
			}
              
			try
			{
				db.StartTransation ();
				scores.DeleteScore(-1,subjectId,-1,classId);
				course.DeleteCourse(courseId,-1,-1);
				db.Commit ();
				MessageBox.Show ("删除成功");
				this.frm .ShowCourse (-1,classId,-1);
			}
			catch
			{
				MessageBox.Show ("删除失败");
			}


		
		
		}
	}
}
		

⌨️ 快捷键说明

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