?? classscorequery.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 調用后添加任何構造函數(shù)代碼
//
}
/// <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 參加人數(shù),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 + -