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

📄 classscorequery.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>
	/// ClassScoreQuery 的摘要说明。
	/// </summary>
	public class ClassScoreQuery : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TextBox textBox3;
		private System.Windows.Forms.NumericUpDown numericUpDown2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.NumericUpDown numericUpDown1;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.Button button1;
		private System.Data.OleDb.OleDbConnection oleDbConnection1;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Button button2;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ClassScoreQuery()
		{
			//
			// 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.textBox3 = new System.Windows.Forms.TextBox();
			this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
			this.label3 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.button2 = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// 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.Location = new System.Drawing.Point(11, 10);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(576, 62);
			this.groupBox1.TabIndex = 7;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "查询条件";
			// 
			// textBox3
			// 
			this.textBox3.Location = new System.Drawing.Point(459, 21);
			this.textBox3.Name = "textBox3";
			this.textBox3.Size = new System.Drawing.Size(53, 25);
			this.textBox3.TabIndex = 9;
			this.textBox3.Text = "2006";
			// 
			// numericUpDown2
			// 
			this.numericUpDown2.Location = new System.Drawing.Point(512, 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(43, 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(427, 24);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(21, 21);
			this.label3.TabIndex = 4;
			this.label3.Text = "至";
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(21, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(67, 21);
			this.label1.TabIndex = 0;
			this.label1.Text = "班级名称";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(96, 21);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(117, 25);
			this.textBox1.TabIndex = 2;
			this.textBox1.Text = "2004中文1班";
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(240, 24);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(67, 21);
			this.label2.TabIndex = 1;
			this.label2.Text = "学期范围";
			// 
			// numericUpDown1
			// 
			this.numericUpDown1.Location = new System.Drawing.Point(373, 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(320, 21);
			this.textBox2.Name = "textBox2";
			this.textBox2.Size = new System.Drawing.Size(53, 25);
			this.textBox2.TabIndex = 8;
			this.textBox2.Text = "2002";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(608, 31);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(64, 31);
			this.button1.TabIndex = 6;
			this.button1.Text = "查询";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// oleDbConnection1
			// 
			this.oleDbConnection1.ConnectionString = "Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet." +
				"OLEDB.4.0;";
			// 
			// dataGrid1
			// 
			this.dataGrid1.AllowSorting = false;
			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.Highlight;
			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(765, 334);
			this.dataGrid1.TabIndex = 8;
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(704, 31);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(64, 29);
			this.button2.TabIndex = 9;
			this.button2.Text = "退出";
			// 
			// ClassScoreQuery
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
			this.ClientSize = new System.Drawing.Size(786, 422);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.button1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "ClassScoreQuery";
			this.Text = "班级成绩查询";
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).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 cstr(cint(xq/10))+'-'+cstr(cint(xq/10)+1)+'年度第'+cstr(xq mod 10)+'学期' as 学期 from cjxx inner join xsxx on cjxx.xuehao=xsxx.xuehao inner join bjxx on xsxx.bjbh=bjxx.bjbh where bjbh.bjmc='"+textBox1.Text.Trim()+"' and xq between '"+xq1+"'and '"+xq2+"' order by xq desc";
				sql="select 学期课程,count(学期课程) as 参加人数,sum(score) as 总成绩,avg(score) as 平均成绩,max(score) as 最高分,min(score) as 最低分 from (select semester,'('+cstr(cint(semester/10))+'-'+cstr(cint(semester/10)+1)+'年度第'+cstr(semester mod 10)+'学期)'+scoreinfo.course as 学期课程,score from (scoreinfo inner join studentinfo on scoreinfo.studentnumber=studentinfo.studentnumber) inner join classinfo on studentinfo.classid=classinfo.classid where classinfo.classname='"+textBox1.Text.Trim()+"' and semester between '"+xq1+"'and '"+xq2+"' order by semester desc) as xqkc group by xqkc.学期课程";
				OleDbDataAdapter adp=new OleDbDataAdapter(sql,oleDbConnection1);
				DataSet ds=new DataSet();
				adp.Fill(ds,"class_score");
				if (ds.Tables["class_score"].Rows.Count!=0)
				{
					dataGrid1.DataSource=ds.Tables["class_score"].DefaultView;
					dataGrid1.CaptionText="共检索出"+ds.Tables["class_score"].Rows.Count+"门课程";
					for (int i=0;i<=ds.Tables["class_score"].Rows.Count-1;i++)
						dataGrid1[i,0]=Convert.ToString((i+1)).Trim()+":"+dataGrid1[i,0].ToString();
				}
			}
		}



	}
}

⌨️ 快捷键说明

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