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

📄 querystugrade.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>
	/// QueryStuGrade 的摘要说明。
	/// </summary>
	public class QueryStuGrade : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button QueryStuClass;
		private System.Windows.Forms.Button ExitQryStu;
		private System.Windows.Forms.Button QryStuN;
		private System.Windows.Forms.DataGrid QryStuGrdDg;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox QryStuName;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		/// 

		private string QryStugrdstrconn;
		private SqlConnection QrySgrdconn;
		private string QryStuGrdconnstr="workstation id=localhost;Integrated Security=SSPI;database=StuMagSys";
		private SqlDataAdapter QryStuGrdsqlda;
		private System.Windows.Forms.ComboBox Class;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;

		private System.ComponentModel.Container components = null;

		public QueryStuGrade()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			this.QueryStuGrade_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.QueryStuClass = new System.Windows.Forms.Button();
			this.ExitQryStu = new System.Windows.Forms.Button();
			this.QryStuN = new System.Windows.Forms.Button();
			this.QryStuGrdDg = new System.Windows.Forms.DataGrid();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.QryStuName = new System.Windows.Forms.TextBox();
			this.Class = new System.Windows.Forms.ComboBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			((System.ComponentModel.ISupportInitialize)(this.QryStuGrdDg)).BeginInit();
			this.SuspendLayout();
			// 
			// QueryStuClass
			// 
			this.QueryStuClass.Location = new System.Drawing.Point(340, 62);
			this.QueryStuClass.Name = "QueryStuClass";
			this.QueryStuClass.Size = new System.Drawing.Size(96, 24);
			this.QueryStuClass.TabIndex = 15;
			this.QueryStuClass.Text = "检索";
			this.QueryStuClass.Click += new System.EventHandler(this.QueryStuClass_Click);
			// 
			// ExitQryStu
			// 
			this.ExitQryStu.Location = new System.Drawing.Point(448, 48);
			this.ExitQryStu.Name = "ExitQryStu";
			this.ExitQryStu.Size = new System.Drawing.Size(96, 24);
			this.ExitQryStu.TabIndex = 14;
			this.ExitQryStu.Text = "退出";
			this.ExitQryStu.Click += new System.EventHandler(this.ExitQryStu_Click);
			// 
			// QryStuN
			// 
			this.QryStuN.Location = new System.Drawing.Point(340, 30);
			this.QryStuN.Name = "QryStuN";
			this.QryStuN.Size = new System.Drawing.Size(96, 24);
			this.QryStuN.TabIndex = 13;
			this.QryStuN.Text = "检索";
			this.QryStuN.Click += new System.EventHandler(this.QryStuN_Click);
			// 
			// QryStuGrdDg
			// 
			this.QryStuGrdDg.DataMember = "";
			this.QryStuGrdDg.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.QryStuGrdDg.Location = new System.Drawing.Point(64, 120);
			this.QryStuGrdDg.Name = "QryStuGrdDg";
			this.QryStuGrdDg.Size = new System.Drawing.Size(504, 256);
			this.QryStuGrdDg.TabIndex = 12;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(68, 62);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(80, 16);
			this.label2.TabIndex = 11;
			this.label2.Text = "按班级检索:";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(68, 30);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(112, 16);
			this.label1.TabIndex = 9;
			this.label1.Text = "按学生姓名检索:";
			// 
			// QryStuName
			// 
			this.QryStuName.Location = new System.Drawing.Point(180, 30);
			this.QryStuName.Name = "QryStuName";
			this.QryStuName.Size = new System.Drawing.Size(148, 21);
			this.QryStuName.TabIndex = 8;
			this.QryStuName.Text = "";
			// 
			// Class
			// 
			this.Class.Location = new System.Drawing.Point(176, 64);
			this.Class.Name = "Class";
			this.Class.Size = new System.Drawing.Size(152, 20);
			this.Class.TabIndex = 16;
			// 
			// groupBox1
			// 
			this.groupBox1.Location = new System.Drawing.Point(56, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(520, 88);
			this.groupBox1.TabIndex = 17;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "检索项";
			// 
			// groupBox2
			// 
			this.groupBox2.Location = new System.Drawing.Point(56, 96);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(520, 288);
			this.groupBox2.TabIndex = 18;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "检索结果";
			// 
			// QueryStuGrade
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(624, 405);
			this.Controls.Add(this.Class);
			this.Controls.Add(this.QueryStuClass);
			this.Controls.Add(this.ExitQryStu);
			this.Controls.Add(this.QryStuN);
			this.Controls.Add(this.QryStuGrdDg);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.QryStuName);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.groupBox2);
			this.Name = "QueryStuGrade";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "查询学生成绩";
			((System.ComponentModel.ISupportInitialize)(this.QryStuGrdDg)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion
		//设置班级列表
		private void QueryStuGrade_Load()
		{  

			DataSet QryStudClassset=new DataSet();
			
			QryStugrdstrconn="select Class_name from class";
			this.QrySgrdconn=new SqlConnection(this.QryStuGrdconnstr);
			this.QryStuGrdsqlda=new SqlDataAdapter(this.QryStugrdstrconn,this.QrySgrdconn);
			QryStudClassset.Clear();
			this.QryStuGrdsqlda.Fill(QryStudClassset,"Class");
			for(int i=0;i<QryStudClassset.Tables[0].Rows.Count;i++)
			{
				Class.Items.Add(QryStudClassset.Tables[0].Rows[i][0]);
			}
			Class.SelectedIndex=0;
		}

		private void QryStuN_Click(object sender, System.EventArgs e)
		{
			try
			{
				DataSet QryStuGrddset =new DataSet();
				QryStugrdstrconn="select student_name as 学生姓名,grade as 成绩,SC_semester as 学期,School_year as 学年 from student,student_course where student.student_id=student_course.student_id and student.student_name="+"'"+this.QryStuName.Text.ToString().Trim()+"'";
				QrySgrdconn=new SqlConnection(QryStuGrdconnstr);
				QryStuGrdsqlda=new SqlDataAdapter(QryStugrdstrconn,QrySgrdconn);
				QryStuGrddset.Clear();
				QryStuGrdsqlda.Fill(QryStuGrddset,"Student_course");
				QryStuGrdDg.DataSource=QryStuGrddset.Tables[0];
		
			}
			catch
			{
				MessageBox.Show("没有该学生的成绩信息。","信息");
			}
		}

		private void ExitQryStu_Click(object sender, System.EventArgs e)
		{
			if(MessageBox.Show("您确认要退出本系统?","确认",MessageBoxButtons.YesNoCancel)==DialogResult.Yes)
				this.Close();
		}

		private void QueryStuClass_Click(object sender, System.EventArgs e)
		{
			try
			{
				DataSet QryStuGrddset =new DataSet();
				QryStugrdstrconn="select student_name as 学生姓名,student_course.grade as 成绩,SC_semester as 学期,School_year as 学年 from student,student_course,class where student.student_id=student_course.student_id and student.Class_id=Class.Class_id and Class.Class_name="+"'"+this.Class.SelectedItem.ToString().Trim()+"'";
				QrySgrdconn=new SqlConnection(QryStuGrdconnstr);
				QryStuGrdsqlda=new SqlDataAdapter(QryStugrdstrconn,QrySgrdconn);
				QryStuGrddset.Clear();
				QryStuGrdsqlda.Fill(QryStuGrddset,"Student_course");
				QryStuGrdDg.DataSource=QryStuGrddset.Tables[0];
		
			}
			catch
			{
				MessageBox.Show("没有该学生的成绩信息。","信息");
			}
		}
	}
}

⌨️ 快捷键说明

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