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

📄 inputgrade.cs

📁 c#+SQL Server 中小型信息系统开发实例精选书上代码
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;


namespace StudentManagementsystem
{
	/// <summary>
	/// InputGrade 的摘要说明。
	/// </summary>
	public class InputGrade : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button drawbackbutt;
		private System.Windows.Forms.TextBox Stu_name;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button ExitNGrd;
		private System.Windows.Forms.Button InputnewGrd;
		private System.Windows.Forms.TextBox Grdsem;
		private System.Windows.Forms.TextBox GrdYear;
		private System.Windows.Forms.TextBox Grade;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		/// 
		private SqlConnection NewGrdConn;
		private SqlCommand NewGrdComd;
		private string NewGrdStrConn="workstation id=localhost;Integrated Security=SSPI;database=StuMagSys";
		private string NewGrdStrComd;
		private SqlDataAdapter NewGrdsqlda;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.ComboBox GrdClass;
		private System.Windows.Forms.ComboBox CourseCB;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;

		private System.ComponentModel.Container components = null;

		public InputGrade()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			this.InputGrade_Load();
			//
			// 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.drawbackbutt = new System.Windows.Forms.Button();
			this.ExitNGrd = new System.Windows.Forms.Button();
			this.InputnewGrd = new System.Windows.Forms.Button();
			this.Grdsem = new System.Windows.Forms.TextBox();
			this.GrdYear = new System.Windows.Forms.TextBox();
			this.Grade = new System.Windows.Forms.TextBox();
			this.Stu_name = new System.Windows.Forms.TextBox();
			this.label10 = new System.Windows.Forms.Label();
			this.label12 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.GrdClass = new System.Windows.Forms.ComboBox();
			this.CourseCB = new System.Windows.Forms.ComboBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.SuspendLayout();
			// 
			// drawbackbutt
			// 
			this.drawbackbutt.Location = new System.Drawing.Point(144, 192);
			this.drawbackbutt.Name = "drawbackbutt";
			this.drawbackbutt.Size = new System.Drawing.Size(88, 24);
			this.drawbackbutt.TabIndex = 53;
			this.drawbackbutt.Text = "撤销";
			this.drawbackbutt.Click += new System.EventHandler(this.drawbackbutt_Click);
			// 
			// ExitNGrd
			// 
			this.ExitNGrd.Location = new System.Drawing.Point(248, 192);
			this.ExitNGrd.Name = "ExitNGrd";
			this.ExitNGrd.Size = new System.Drawing.Size(88, 24);
			this.ExitNGrd.TabIndex = 52;
			this.ExitNGrd.Text = "退出";
			this.ExitNGrd.Click += new System.EventHandler(this.ExitNGrd_Click);
			// 
			// InputnewGrd
			// 
			this.InputnewGrd.Location = new System.Drawing.Point(40, 192);
			this.InputnewGrd.Name = "InputnewGrd";
			this.InputnewGrd.Size = new System.Drawing.Size(88, 24);
			this.InputnewGrd.TabIndex = 51;
			this.InputnewGrd.Text = "录入";
			this.InputnewGrd.Click += new System.EventHandler(this.InputnewGrd_Click);
			// 
			// Grdsem
			// 
			this.Grdsem.Location = new System.Drawing.Point(176, 144);
			this.Grdsem.Name = "Grdsem";
			this.Grdsem.Size = new System.Drawing.Size(112, 21);
			this.Grdsem.TabIndex = 48;
			this.Grdsem.Text = "";
			// 
			// GrdYear
			// 
			this.GrdYear.Location = new System.Drawing.Point(176, 120);
			this.GrdYear.Name = "GrdYear";
			this.GrdYear.Size = new System.Drawing.Size(112, 21);
			this.GrdYear.TabIndex = 46;
			this.GrdYear.Text = "";
			// 
			// Grade
			// 
			this.Grade.Location = new System.Drawing.Point(176, 96);
			this.Grade.Name = "Grade";
			this.Grade.Size = new System.Drawing.Size(112, 21);
			this.Grade.TabIndex = 40;
			this.Grade.Text = "";
			// 
			// Stu_name
			// 
			this.Stu_name.Location = new System.Drawing.Point(176, 24);
			this.Stu_name.Name = "Stu_name";
			this.Stu_name.Size = new System.Drawing.Size(112, 21);
			this.Stu_name.TabIndex = 33;
			this.Stu_name.Text = "";
			// 
			// label10
			// 
			this.label10.Location = new System.Drawing.Point(112, 120);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(48, 16);
			this.label10.TabIndex = 45;
			this.label10.Text = "学年:";
			// 
			// label12
			// 
			this.label12.Location = new System.Drawing.Point(112, 144);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(48, 23);
			this.label12.TabIndex = 43;
			this.label12.Text = "学期:";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(112, 96);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(48, 16);
			this.label8.TabIndex = 37;
			this.label8.Text = "成绩:";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(112, 72);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(48, 16);
			this.label3.TabIndex = 32;
			this.label3.Text = "课程:";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(112, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(48, 16);
			this.label1.TabIndex = 30;
			this.label1.Text = "姓名:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(112, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(48, 16);
			this.label2.TabIndex = 54;
			this.label2.Text = "班级:";
			// 
			// GrdClass
			// 
			this.GrdClass.Location = new System.Drawing.Point(176, 48);
			this.GrdClass.Name = "GrdClass";
			this.GrdClass.Size = new System.Drawing.Size(112, 20);
			this.GrdClass.TabIndex = 55;
			// 
			// CourseCB
			// 
			this.CourseCB.Location = new System.Drawing.Point(176, 72);
			this.CourseCB.Name = "CourseCB";
			this.CourseCB.Size = new System.Drawing.Size(112, 20);
			this.CourseCB.TabIndex = 56;
			// 
			// groupBox1
			// 
			this.groupBox1.Location = new System.Drawing.Point(32, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(320, 168);
			this.groupBox1.TabIndex = 57;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "成绩录入";
			// 
			// groupBox2
			// 
			this.groupBox2.Location = new System.Drawing.Point(32, 176);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(320, 48);
			this.groupBox2.TabIndex = 58;
			this.groupBox2.TabStop = false;
			// 
			// InputGrade
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(384, 245);
			this.Controls.Add(this.CourseCB);
			this.Controls.Add(this.GrdClass);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.drawbackbutt);
			this.Controls.Add(this.ExitNGrd);
			this.Controls.Add(this.InputnewGrd);
			this.Controls.Add(this.Grdsem);
			this.Controls.Add(this.GrdYear);
			this.Controls.Add(this.Grade);
			this.Controls.Add(this.Stu_name);
			this.Controls.Add(this.label10);
			this.Controls.Add(this.label12);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.groupBox2);
			this.Name = "InputGrade";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "录入成绩";
			this.ResumeLayout(false);

		}
		#endregion
		//添加窗体的班级列表和课程列表
		private void InputGrade_Load()
		{  

			DataSet NewGrddClassset=new DataSet();
			
			string NewGrdStrConnSql="select Class_name from class";
			this.NewGrdConn=new SqlConnection(this.NewGrdStrConn);
			this.NewGrdsqlda=new SqlDataAdapter(NewGrdStrConnSql,this.NewGrdConn);
			NewGrddClassset.Clear();
			this.NewGrdsqlda.Fill(NewGrddClassset,"Class");
			for(int i=0;i<NewGrddClassset.Tables[0].Rows.Count;i++)
			{
				GrdClass.Items.Add(NewGrddClassset.Tables[0].Rows[i][0]);
			}
			GrdClass.SelectedIndex=0;
			
			DataSet NewGrddCourseset=new DataSet();
			NewGrdStrConnSql="select Course_name from course";
			this.NewGrdConn=new SqlConnection(this.NewGrdStrConn);
			this.NewGrdsqlda=new SqlDataAdapter(NewGrdStrConnSql,this.NewGrdConn);
			NewGrddCourseset.Clear();
			this.NewGrdsqlda.Fill(NewGrddCourseset,"Class");
			for(int i=0;i<NewGrddCourseset.Tables[0].Rows.Count;i++)
			{
				CourseCB.Items.Add(NewGrddCourseset.Tables[0].Rows[i][0]);
			}
			CourseCB.SelectedIndex=0;

		}


		private void ExitNGrd_Click(object sender, System.EventArgs e)
		{
			if(MessageBox.Show("您确认要退出?","确认",MessageBoxButtons.YesNo)==DialogResult.Yes)
				this.Close();
		}
		//撤销按钮
		private void drawbackbutt_Click(object sender, System.EventArgs e)
		{
			this.Grade.Text="";
			this.Stu_name.Text="";

			this.GrdYear.Text="";
			this.Grdsem.Text="";
		}
		//shu
		private void InputnewGrd_Click(object sender, System.EventArgs e)
		{
			try
			{
				//检验输入数据是否符合要求
				if(this.GrdClass.Text==""||this.Grdsem.Text==""||this.GrdYear.Text==""||this.Grade.Text=="")
				{
					MessageBox.Show("学生姓名、成绩、课程名称、学期、学年必须填写!","提示");
				}
				else
				{
					DataSet NewGrddClassset=new DataSet();
					//查询学生所在班级的班级号
					string NewGrdStrConnSql="select course.course_id,student.student_id from student,course,student_course,class where student.class_id=class.class_id and class.class_name="+"'"+this.GrdClass.SelectedItem.ToString().Trim()+"'"+" and student.student_name="+"'"+this.Stu_name.Text.ToString().Trim()+"'"+" and "+"course.course_name="+"'"+this.CourseCB.SelectedItem.ToString().Trim()+"'";
					this.NewGrdConn=new SqlConnection(this.NewGrdStrConn);
					this.NewGrdsqlda=new SqlDataAdapter(NewGrdStrConnSql,this.NewGrdConn);
					NewGrddClassset.Clear();
					this.NewGrdsqlda.Fill(NewGrddClassset,"Class");
					string courseId=NewGrddClassset.Tables[0].Rows[0][0].ToString().Trim();
					string StuId=NewGrddClassset.Tables[0].Rows[0][1].ToString().Trim();


					NewGrdStrComd="insert into Student_course(student_id,Course_id,Grade,SC_semester,School_year)values"+
						"("+"'"+StuId+"'"+","+"'"+courseId+"'"+
						","+"'"+this.Grade.Text.ToString().Trim()+"'"+","+"'"+
						this.Grdsem.Text.ToString().Trim()+"'"+","+"'"+this.GrdYear.Text.ToString().Trim()+"'"+")";
					NewGrdConn=new SqlConnection(NewGrdStrConn);

					NewGrdConn.Open();
					NewGrdComd=new SqlCommand(NewGrdStrComd,NewGrdConn);
					int Succnum=NewGrdComd.ExecuteNonQuery();
					if(Succnum>0) MessageBox.Show("录入成功");
				}
			} 
			catch
			{
				MessageBox.Show("姓名或班级输入有误!请重新输入。","确认",MessageBoxButtons.YesNo);
			}
		}

	}
}

⌨️ 快捷键说明

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