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

📄 scoreview.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 教务管理系统1
{
	/// <summary>
	/// ScoreView 的摘要说明。
	/// </summary>
	public class ScoreView : System.Windows.Forms.Form
  	{
		private string stuID;//保存学生学号
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Data.SqlClient.SqlConnection sqlConnection1;
		private 教务管理系统1.DataSet2 dataSet21;
		private System.Windows.Forms.TextBox txt1;
		private System.Windows.Forms.TextBox txt2;
		private System.Windows.Forms.TextBox txt3;
		private System.Data.SqlClient.SqlDataAdapter da1;
		private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
		private System.Windows.Forms.Button button2;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ScoreView()
		{
			//
			// 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.groupBox1 = new System.Windows.Forms.GroupBox();
			this.button2 = new System.Windows.Forms.Button();
			this.label3 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.button1 = new System.Windows.Forms.Button();
			this.txt3 = new System.Windows.Forms.TextBox();
			this.dataSet21 = new 教务管理系统1.DataSet2();
			this.txt2 = new System.Windows.Forms.TextBox();
			this.txt1 = new System.Windows.Forms.TextBox();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.da1 = new System.Data.SqlClient.SqlDataAdapter();
			this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataSet21)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.button2);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.button1);
			this.groupBox1.Controls.Add(this.txt3);
			this.groupBox1.Controls.Add(this.txt2);
			this.groupBox1.Controls.Add(this.txt1);
			this.groupBox1.Location = new System.Drawing.Point(24, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(592, 96);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "学生信息";
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(416, 56);
			this.button2.Name = "button2";
			this.button2.TabIndex = 8;
			this.button2.Text = "打印成绩单";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 40);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(32, 23);
			this.label3.TabIndex = 7;
			this.label3.Text = "学号";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(144, 56);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(72, 23);
			this.label2.TabIndex = 6;
			this.label2.Text = "班级名称";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(144, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 23);
			this.label1.TabIndex = 5;
			this.label1.Text = "姓名";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(416, 16);
			this.button1.Name = "button1";
			this.button1.TabIndex = 3;
			this.button1.Text = "查询成绩";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// txt3
			// 
			this.txt3.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet21, "选课表.班级名称"));
			this.txt3.Location = new System.Drawing.Point(216, 56);
			this.txt3.Name = "txt3";
			this.txt3.ReadOnly = true;
			this.txt3.TabIndex = 2;
			this.txt3.Text = "";
			// 
			// dataSet21
			// 
			this.dataSet21.DataSetName = "DataSet2";
			this.dataSet21.Locale = new System.Globalization.CultureInfo("zh-CN");
			// 
			// txt2
			// 
			this.txt2.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet21, "选课表.姓名"));
			this.txt2.Location = new System.Drawing.Point(216, 24);
			this.txt2.Name = "txt2";
			this.txt2.ReadOnly = true;
			this.txt2.TabIndex = 1;
			this.txt2.Text = "";
			// 
			// txt1
			// 
			this.txt1.Location = new System.Drawing.Point(40, 40);
			this.txt1.Name = "txt1";
			this.txt1.TabIndex = 0;
			this.txt1.Text = "";
			// 
			// dataGrid1
			// 
			this.dataGrid1.CaptionVisible = false;
			this.dataGrid1.DataMember = "";
			this.dataGrid1.DataSource = this.dataSet21.选课表;
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(32, 136);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.Size = new System.Drawing.Size(576, 224);
			this.dataGrid1.TabIndex = 1;
			// 
			// da1
			// 
			this.da1.SelectCommand = this.sqlSelectCommand1;
			this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																						  new System.Data.Common.DataTableMapping("Table", "选课表", new System.Data.Common.DataColumnMapping[] {
																																																 new System.Data.Common.DataColumnMapping("姓名", "姓名"),
																																																 new System.Data.Common.DataColumnMapping("课程名", "课程名"),
																																																 new System.Data.Common.DataColumnMapping("学分", "学分"),
																																																 new System.Data.Common.DataColumnMapping("成绩", "成绩"),
																																																 new System.Data.Common.DataColumnMapping("教师", "教师"),
																																																 new System.Data.Common.DataColumnMapping("班级名称", "班级名称"),
																																																 new System.Data.Common.DataColumnMapping("必修或选修", "必修或选修"),
																																																 new System.Data.Common.DataColumnMapping("学号", "学号"),
																																																 new System.Data.Common.DataColumnMapping("课程号", "课程号"),
																																																 new System.Data.Common.DataColumnMapping("Expr1", "Expr1")})});
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = "SELECT 学生表.姓名, 课程表.课程名, 课程表.学分, 选课表.成绩, 课程表.教师, 学生表.班级名称, 课程表.必修或选修, 学生表.学号, 课程表." +
				"课程号, 选课表.课程号 AS Expr1 FROM 选课表 INNER JOIN 课程表 ON 课程表.课程号 = 选课表.课程号 INNER JOIN 学生" +
				"表 ON 选课表.学号 = 学生表.学号 WHERE (选课表.学号 LIKE @Param2)";
			this.sqlSelectCommand1.Connection = this.sqlConnection1;
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param2", System.Data.SqlDbType.VarChar, 8, "学号"));
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=localhost;packet size=4096;integrated security=SSPI;initial catalo" +
				"g=\"study&teach\";persist security info=False";
			// 
			// ScoreView
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(640, 406);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.groupBox1);
			this.Name = "ScoreView";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "学生成绩查询";
			this.Load += new System.EventHandler(this.ScoreView_Load);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataSet21)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void button1_Click(object sender, System.EventArgs e)
		{
			txt2.Clear();//先清空信息			txt3.Clear();			dataSet21.Clear();							string strConn="workstation id=localhost;Integrated Security=SSPI;database=study&teach;";			SqlConnection cn=new SqlConnection(strConn);			cn.Open();
			SqlCommand cmd=cn.CreateCommand();
			cmd.CommandText="select 学生表.姓名,学生表.班级名称 from 学生表 where (学号='"+txt1.Text.Trim()+"')";
			SqlDataReader dr=cmd.ExecuteReader();
			dr.Read();//读入学生的数据
			if(!dr.HasRows)//判断学号是否输入正确
			{
				MessageBox.Show("无此学生,请重新输入学号","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
				dr.Close();
				return;
			}
			txt2.Text=dr.GetValue(0).ToString().Trim();//显示姓名
			txt3.Text=dr.GetValue(1).ToString().Trim();//显示班级名称
			dr.Close();				
			da1.SelectCommand.Parameters[0].Value=txt1.Text.Trim();
			da1.Fill(dataSet21);
		}

		private void ScoreView_Load(object sender, System.EventArgs e)
		{
		
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			if(txt2.Text.Trim()=="")
			{
				MessageBox.Show("请先输入正确的学号","提示");
				return;
			}
			ScoreList newFrm=new ScoreList();
			ScoreList.studentID=txt1.Text.Trim();//向报表预览窗体中传递学号
			newFrm.Text=txt2.Text+"同学成绩表";
			newFrm.ShowDialog();
		}
		
	}
}

⌨️ 快捷键说明

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