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

📄 frmscore.cs

📁 简单的学生成绩管理系统。实现学生成绩学号管理
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace 教务管理系统
{
	/// <summary>
	/// frmScore 的摘要说明。
	/// </summary>
	public class frmScore : System.Windows.Forms.Form
	{
		internal System.Windows.Forms.GroupBox GroupBox3;
		internal System.Windows.Forms.Button btnUpdate;
		internal System.Windows.Forms.Label Label6;
		internal System.Windows.Forms.TextBox txbScore;
		internal System.Windows.Forms.DataGrid dgdList;
		internal System.Windows.Forms.GroupBox GroupBox2;
		internal System.Windows.Forms.Button btnSubmit;
		internal System.Windows.Forms.Button btnSearch;
		internal System.Windows.Forms.TextBox txbId;
		internal System.Windows.Forms.TextBox txbName;
		internal System.Windows.Forms.Label Label5;
		internal System.Windows.Forms.Label Label4;
		internal System.Windows.Forms.Label Label3;
		internal System.Windows.Forms.Label Label2;
		internal System.Windows.Forms.TextBox txbPY;
		internal System.Windows.Forms.GroupBox GroupBox1;
		internal System.Windows.Forms.Label Label1;
		internal System.Windows.Forms.Button btnClear;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		// added member
		private DataTable dtData;

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

			//
			// 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.GroupBox3 = new System.Windows.Forms.GroupBox();
			this.btnUpdate = new System.Windows.Forms.Button();
			this.Label6 = new System.Windows.Forms.Label();
			this.txbScore = new System.Windows.Forms.TextBox();
			this.dgdList = new System.Windows.Forms.DataGrid();
			this.GroupBox2 = new System.Windows.Forms.GroupBox();
			this.btnSubmit = new System.Windows.Forms.Button();
			this.btnSearch = new System.Windows.Forms.Button();
			this.txbId = new System.Windows.Forms.TextBox();
			this.txbName = 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.txbPY = new System.Windows.Forms.TextBox();
			this.GroupBox1 = new System.Windows.Forms.GroupBox();
			this.Label1 = new System.Windows.Forms.Label();
			this.btnClear = new System.Windows.Forms.Button();
			this.GroupBox3.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dgdList)).BeginInit();
			this.GroupBox2.SuspendLayout();
			this.GroupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// GroupBox3
			// 
			this.GroupBox3.Controls.Add(this.btnUpdate);
			this.GroupBox3.Controls.Add(this.Label6);
			this.GroupBox3.Controls.Add(this.txbScore);
			this.GroupBox3.Controls.Add(this.dgdList);
			this.GroupBox3.Dock = System.Windows.Forms.DockStyle.Fill;
			this.GroupBox3.Location = new System.Drawing.Point(0, 163);
			this.GroupBox3.Name = "GroupBox3";
			this.GroupBox3.Size = new System.Drawing.Size(553, 138);
			this.GroupBox3.TabIndex = 5;
			this.GroupBox3.TabStop = false;
			this.GroupBox3.Text = "课程成绩输入";
			// 
			// btnUpdate
			// 
			this.btnUpdate.Location = new System.Drawing.Point(473, 74);
			this.btnUpdate.Name = "btnUpdate";
			this.btnUpdate.Size = new System.Drawing.Size(54, 22);
			this.btnUpdate.TabIndex = 8;
			this.btnUpdate.Text = "修改成绩";
			this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
			// 
			// Label6
			// 
			this.Label6.Location = new System.Drawing.Point(448, 40);
			this.Label6.Name = "Label6";
			this.Label6.Size = new System.Drawing.Size(26, 15);
			this.Label6.TabIndex = 5;
			this.Label6.Text = "成绩";
			// 
			// txbScore
			// 
			this.txbScore.Location = new System.Drawing.Point(472, 37);
			this.txbScore.Name = "txbScore";
			this.txbScore.Size = new System.Drawing.Size(54, 20);
			this.txbScore.TabIndex = 6;
			this.txbScore.Text = "";
			// 
			// dgdList
			// 
			this.dgdList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left)));
			this.dgdList.CaptionVisible = false;
			this.dgdList.DataMember = "";
			this.dgdList.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dgdList.Location = new System.Drawing.Point(7, 15);
			this.dgdList.Name = "dgdList";
			this.dgdList.Size = new System.Drawing.Size(433, 118);
			this.dgdList.TabIndex = 0;
			// 
			// GroupBox2
			// 
			this.GroupBox2.Controls.Add(this.btnSubmit);
			this.GroupBox2.Controls.Add(this.btnSearch);
			this.GroupBox2.Controls.Add(this.txbId);
			this.GroupBox2.Controls.Add(this.txbName);
			this.GroupBox2.Controls.Add(this.Label5);
			this.GroupBox2.Controls.Add(this.Label4);
			this.GroupBox2.Controls.Add(this.Label3);
			this.GroupBox2.Controls.Add(this.Label2);
			this.GroupBox2.Controls.Add(this.txbPY);
			this.GroupBox2.Dock = System.Windows.Forms.DockStyle.Top;
			this.GroupBox2.Location = new System.Drawing.Point(0, 82);
			this.GroupBox2.Name = "GroupBox2";
			this.GroupBox2.Size = new System.Drawing.Size(553, 81);
			this.GroupBox2.TabIndex = 4;
			this.GroupBox2.TabStop = false;
			this.GroupBox2.Text = "选择课程";
			// 
			// btnSubmit
			// 
			this.btnSubmit.Location = new System.Drawing.Point(173, 45);
			this.btnSubmit.Name = "btnSubmit";
			this.btnSubmit.Size = new System.Drawing.Size(54, 21);
			this.btnSubmit.TabIndex = 8;
			this.btnSubmit.Text = "最终提交";
			this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
			// 
			// btnSearch
			// 
			this.btnSearch.Location = new System.Drawing.Point(120, 45);
			this.btnSearch.Name = "btnSearch";
			this.btnSearch.Size = new System.Drawing.Size(47, 21);
			this.btnSearch.TabIndex = 7;
			this.btnSearch.Text = "查询";
			this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
			// 
			// txbId
			// 
			this.txbId.Location = new System.Drawing.Point(64, 46);
			this.txbId.Name = "txbId";
			this.txbId.Size = new System.Drawing.Size(54, 20);
			this.txbId.TabIndex = 6;
			this.txbId.Text = "";
			this.txbId.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txbId_KeyDown);
			// 
			// txbName
			// 
			this.txbName.Location = new System.Drawing.Point(167, 18);
			this.txbName.Name = "txbName";
			this.txbName.Size = new System.Drawing.Size(54, 20);
			this.txbName.TabIndex = 5;
			this.txbName.Text = "";
			this.txbName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txbName_KeyDown);
			// 
			// Label5
			// 
			this.Label5.Location = new System.Drawing.Point(120, 22);
			this.Label5.Name = "Label5";
			this.Label5.Size = new System.Drawing.Size(47, 15);
			this.Label5.TabIndex = 3;
			this.Label5.Text = "课程名称";
			// 
			// Label4
			// 
			this.Label4.Location = new System.Drawing.Point(7, 52);
			this.Label4.Name = "Label4";
			this.Label4.Size = new System.Drawing.Size(65, 15);
			this.Label4.TabIndex = 2;
			this.Label4.Text = "课程编号";
			// 
			// Label3
			// 
			this.Label3.Location = new System.Drawing.Point(7, 22);
			this.Label3.Name = "Label3";
			this.Label3.Size = new System.Drawing.Size(57, 15);
			this.Label3.TabIndex = 1;
			this.Label3.Text = "课程拼音";
			// 
			// Label2
			// 
			this.Label2.Location = new System.Drawing.Point(240, 16);
			this.Label2.Name = "Label2";
			this.Label2.Size = new System.Drawing.Size(307, 65);
			this.Label2.TabIndex = 0;
			this.Label2.Text = "这里选择一门课程,查询出该课程所有的学生,并输入成绩。实际应用时不用选择课程,而是根据登陆系统的的老师的编号,自动列出该老师所有课程,老师只能对自己的课程进行成绩" +
				"的输入的操作;最终提交是老师提交的成绩,提交后的成绩将不可以修改。";
			// 
			// txbPY
			// 
			this.txbPY.Location = new System.Drawing.Point(64, 18);
			this.txbPY.Name = "txbPY";
			this.txbPY.Size = new System.Drawing.Size(54, 20);
			this.txbPY.TabIndex = 4;
			this.txbPY.Text = "";
			this.txbPY.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txbPY_KeyDown);
			// 
			// GroupBox1
			// 
			this.GroupBox1.Controls.Add(this.Label1);
			this.GroupBox1.Controls.Add(this.btnClear);
			this.GroupBox1.Dock = System.Windows.Forms.DockStyle.Top;
			this.GroupBox1.Location = new System.Drawing.Point(0, 0);
			this.GroupBox1.Name = "GroupBox1";
			this.GroupBox1.Size = new System.Drawing.Size(553, 82);
			this.GroupBox1.TabIndex = 3;
			this.GroupBox1.TabStop = false;
			this.GroupBox1.Text = "结束选课,生成空成绩单";
			// 
			// Label1
			// 
			this.Label1.Location = new System.Drawing.Point(167, 7);
			this.Label1.Name = "Label1";
			this.Label1.Size = new System.Drawing.Size(377, 67);
			this.Label1.TabIndex = 1;
			this.Label1.Text = "应该单独有一个终止选课的功能,终止选课后生成空的成绩单,所有学生将不允许更改课程信息,如果需要更改,必须单独申请,特殊处理。终止选课一学年应该只能进行一次操作。读" +
				"者需要注意实例没有制作开始选课等功能,终止选课后在学生选课中仍然可以更改选择的课程。";
			// 
			// btnClear
			// 
			this.btnClear.Location = new System.Drawing.Point(16, 24);
			this.btnClear.Name = "btnClear";
			this.btnClear.Size = new System.Drawing.Size(126, 42);
			this.btnClear.TabIndex = 0;
			this.btnClear.Text = "终止选课,生成空成绩单";
			this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
			// 
			// frmScore
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(553, 301);
			this.Controls.Add(this.GroupBox3);
			this.Controls.Add(this.GroupBox2);
			this.Controls.Add(this.GroupBox1);
			this.Name = "frmScore";
			this.Text = "成绩输入";
			this.GroupBox3.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dgdList)).EndInit();
			this.GroupBox2.ResumeLayout(false);
			this.GroupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void SetDGDList()
		{
			string strSQL = "select b.课程名称,a.学号,c.姓名,a.成绩,";
			strSQL += " a.编号,a.课程编号  from 成绩表 as a, 课程信息 as b, ";
			strSQL += "学生信息 as c where a.课程编号=b.课程编号 and a.学号";
			strSQL += "=c.学号 and 是否已确定成绩 = 'N' ";
			string strFilter = "";
			if ( txbPY.Text.Trim().Length != 0 )
			{
				strFilter += " and 拼音码 like '" + txbPY.Text.Trim() + "%'";
			}
			if ( txbId.Text.Trim().Length != 0 )
			{
				strFilter += " and a.学号 like '" + txbId.Text.Trim() + "%'";
			}
			if ( txbName.Text.Trim().Length != 0 )
			{
				strFilter += " and c.姓名 like '" + txbName.Text + "%'";
			}
			if ( strFilter.Trim().Length == 0 )
			{
				return;
			}
			else
			{
				strFilter += " order by b.课程名称,a.学号";
				DataBase db = new DataBase();
				DataView dv = db.RunSelectSQL( strSQL + strFilter );
				dv.AllowNew = false;
				dv.AllowEdit = false;
				dv.AllowDelete = false;
				dtData = dv.Table;
				dgdList.DataSource = dv;
				dgdList.AllowSorting = false;
				db.Dispose();
			}
		}

		private void btnClear_Click(object sender, System.EventArgs e)
		{
			DataBase db = new DataBase();
			db.RunDelOrInsSQL( "exec sf_终止选课" );
			db.Dispose();
		}

		private void txbId_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if ( e.KeyCode == Keys.Enter )
				SetDGDList();
		}

		private void btnSearch_Click(object sender, System.EventArgs e)
		{
			SetDGDList();
		}

		private void txbPY_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if ( e.KeyCode == Keys.Enter )
				SetDGDList();
		}

		private void txbName_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if ( e.KeyCode == Keys.Enter )
				SetDGDList();
		}

		private void btnSubmit_Click(object sender, System.EventArgs e)
		{
			if ( dgdList.CurrentCell.RowNumber == -1 )
				return;
			string strSubject = dtData.Rows[ dgdList.CurrentCell.RowNumber ][ 5 ].ToString().Trim();
			DialogResult dlgResult = MessageBox.Show( "提交后成绩不可以修改,是否确认提交?", 
				"提示", MessageBoxButtons.YesNo );
			if ( dlgResult == DialogResult.Yes )
			{
				string strSQL = "exec sf_成绩提交 " + strSubject;
				DataBase db = new DataBase();
				db.RunDelOrInsSQL( strSQL );
				db.Dispose();
				MessageBox.Show( "提交成绩成功!" );
				SetDGDList();
			}
		}

		private void btnUpdate_Click(object sender, System.EventArgs e)
		{
			try
			{
				int score = Int32.Parse( txbScore.Text );
			}
			catch ( Exception ex )
			{
				MessageBox.Show( "成绩格式不正确!" + ex.ToString() );
			}
			if ( dgdList.CurrentCell.RowNumber != -1 )
			{
				DataBase db = new DataBase();
				string strSQL = "update 成绩表 set 成绩=" + txbScore.Text.Trim() + " where 编号=";
				strSQL += dtData.Rows[ dgdList.CurrentCell.RowNumber ][ 4 ].ToString().Trim();
				db.RunDelOrInsSQL( strSQL );
				db.Dispose();
				SetDGDList();
			}
		}
	}
}

⌨️ 快捷键说明

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