?? scorequery.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 + -