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

📄 scorequery.cs

📁 C#编写的学籍管理系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data;

namespace WindowsApplication1
{
	/// <summary>
	/// ScoreQuery 的摘要说明。
	/// </summary>
	public class ScoreQuery : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.NumericUpDown numericUpDown1;
		private System.Windows.Forms.NumericUpDown numericUpDown2;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.TextBox textBox3;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Data.OleDb.OleDbConnection oleDbConnection1;
		private System.Windows.Forms.DataGrid dataGrid2;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ScoreQuery()
		{
			//
			// 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.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
			this.label3 = new System.Windows.Forms.Label();
			this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
			this.dataGrid2 = new System.Windows.Forms.DataGrid();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).BeginInit();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(24, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(36, 21);
			this.label1.TabIndex = 0;
			this.label1.Text = "学号";
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(181, 31);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(67, 21);
			this.label2.TabIndex = 1;
			this.label2.Text = "学期范围";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(75, 21);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(96, 25);
			this.textBox1.TabIndex = 2;
			this.textBox1.Text = "007";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(536, 16);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(54, 31);
			this.button1.TabIndex = 4;
			this.button1.Text = "查询";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.textBox3);
			this.groupBox1.Controls.Add(this.numericUpDown2);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.textBox1);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.numericUpDown1);
			this.groupBox1.Controls.Add(this.textBox2);
			this.groupBox1.Controls.Add(this.button1);
			this.groupBox1.Location = new System.Drawing.Point(11, 10);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(621, 62);
			this.groupBox1.TabIndex = 5;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "查询条件";
			// 
			// textBox3
			// 
			this.textBox3.Location = new System.Drawing.Point(405, 21);
			this.textBox3.Name = "textBox3";
			this.textBox3.Size = new System.Drawing.Size(54, 25);
			this.textBox3.TabIndex = 9;
			this.textBox3.Text = "2006";
			// 
			// numericUpDown2
			// 
			this.numericUpDown2.Location = new System.Drawing.Point(459, 21);
			this.numericUpDown2.Maximum = new System.Decimal(new int[] {
																		   2,
																		   0,
																		   0,
																		   0});
			this.numericUpDown2.Minimum = new System.Decimal(new int[] {
																		   1,
																		   0,
																		   0,
																		   0});
			this.numericUpDown2.Name = "numericUpDown2";
			this.numericUpDown2.Size = new System.Drawing.Size(42, 25);
			this.numericUpDown2.TabIndex = 7;
			this.numericUpDown2.Value = new System.Decimal(new int[] {
																		 1,
																		 0,
																		 0,
																		 0});
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Location = new System.Drawing.Point(373, 21);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(21, 21);
			this.label3.TabIndex = 4;
			this.label3.Text = "至";
			// 
			// numericUpDown1
			// 
			this.numericUpDown1.Location = new System.Drawing.Point(320, 21);
			this.numericUpDown1.Maximum = new System.Decimal(new int[] {
																		   2,
																		   0,
																		   0,
																		   0});
			this.numericUpDown1.Minimum = new System.Decimal(new int[] {
																		   1,
																		   0,
																		   0,
																		   0});
			this.numericUpDown1.Name = "numericUpDown1";
			this.numericUpDown1.Size = new System.Drawing.Size(43, 25);
			this.numericUpDown1.TabIndex = 6;
			this.numericUpDown1.Value = new System.Decimal(new int[] {
																		 1,
																		 0,
																		 0,
																		 0});
			// 
			// textBox2
			// 
			this.textBox2.Location = new System.Drawing.Point(267, 21);
			this.textBox2.Name = "textBox2";
			this.textBox2.Size = new System.Drawing.Size(53, 25);
			this.textBox2.TabIndex = 8;
			this.textBox2.Text = "2002";
			// 
			// dataGrid1
			// 
			this.dataGrid1.AllowSorting = false;
			this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.Control;
			this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.dataGrid1.CaptionFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.dataGrid1.CaptionForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.CaptionText = "成绩列表";
			this.dataGrid1.DataMember = "";
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(11, 82);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.PreferredColumnWidth = 100;
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.Size = new System.Drawing.Size(618, 196);
			this.dataGrid1.TabIndex = 6;
			// 
			// oleDbConnection1
			// 
			this.oleDbConnection1.ConnectionString = "Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet." +
				"OLEDB.4.0;";
			// 
			// dataGrid2
			// 
			this.dataGrid2.AllowSorting = false;
			this.dataGrid2.BackgroundColor = System.Drawing.SystemColors.Control;
			this.dataGrid2.CaptionBackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.dataGrid2.CaptionFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.dataGrid2.CaptionForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid2.CaptionText = "成绩统计";
			this.dataGrid2.DataMember = "";
			this.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid2.Location = new System.Drawing.Point(11, 288);
			this.dataGrid2.Name = "dataGrid2";
			this.dataGrid2.PreferredColumnWidth = 100;
			this.dataGrid2.ReadOnly = true;
			this.dataGrid2.Size = new System.Drawing.Size(618, 144);
			this.dataGrid2.TabIndex = 7;
			// 
			// ScoreQuery
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
			this.ClientSize = new System.Drawing.Size(640, 446);
			this.Controls.Add(this.dataGrid2);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.groupBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "ScoreQuery";
			this.Text = "学生成绩查询";
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion
		public bool strisyear(string s)
		{
			if (s.Trim().Length!=4)
				return (false);
			else
			{
				int n=1;
				for (int i=0;i<=s.Length-1;i++)
				{
					if (!System.Char.IsNumber(s[i]))
					{
						n=-1;
						break;
					}
				}
				if (n==1)
					return (true);
				else
					return (false);
			}
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			if (!strisyear(textBox2.Text.Trim()) || !strisyear(textBox3.Text.Trim()))
				MessageBox.Show("年份输入非法");
			else if (textBox1.Text.Trim()=="")
			{
                MessageBox.Show("学号不能为空");
			}
			else if ( int.Parse(textBox2.Text.Trim())<= int.Parse(textBox3.Text.Trim()) && numericUpDown1.Value<=numericUpDown2.Value   )
			{
				string sql,xq1,xq2;
				xq1=textBox2.Text.Trim()+numericUpDown1.Value.ToString();
				xq2=textBox3.Text.Trim()+numericUpDown2.Value.ToString();
				sql="select ScoreId as 编号,Course as 课程,Score as 成绩,cstr(cint(Semester/10))+'-'+cstr(cint(Semester/10)+1)+'年度第'+cstr(Semester mod 10)+'学期' as 学期 from ScoreInfo where StudentNumber='"+textBox1.Text.Trim()+"' and Semester between '"+xq1+"'and '"+xq2+"' order by Semester desc";
				OleDbDataAdapter adp=new OleDbDataAdapter(sql,oleDbConnection1);
				DataSet ds=new DataSet();
				adp.Fill(ds,"score");
				if (ds.Tables["score"].Rows.Count!=0)
				{
					dataGrid1.DataSource=ds.Tables["score"].DefaultView;
					dataGrid1.CaptionText="共检索出"+ds.Tables["score"].Rows.Count+"门课程";
					for (int i=0;i<=ds.Tables["score"].Rows.Count-1;i++)
						dataGrid1[i,0]=i+1;

					sql="select cstr(cint(Semester/10))+'-'+cstr(cint(Semester/10)+1)+'年度第'+cstr(Semester mod 10)+'学期' as 学期,avg(Score) as 平均成绩,sum(Score) as 总成绩,count(ScoreId) as 课程数量  from ScoreInfo where StudentNumber='"+textBox1.Text.Trim()+"'and Semester between '"+xq1+"'and '"+xq2+"' group by Semester";
				    adp.SelectCommand.CommandText=sql;
					DataSet ds2=new DataSet();
					adp.Fill(ds,"tj");
					dataGrid2.DataSource=ds.Tables["tj"].DefaultView;
				}
				else
				{
					dataGrid1.DataSource=null;
					dataGrid1.CaptionText="暂时无纪录";
				}
			}
			else
			{
				MessageBox.Show("请在左边输入较小的学期数值");
			}
		}
	}
}

⌨️ 快捷键说明

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