您的位置:首页 > 编程语言 > C#

为某中学编写的C#程序,统计各班个分数段人数

2013-03-21 08:00 211 查看
View Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace GradeStatistics
{
public partial class Form1 : Form
{
int obset = 0;
int s_p = 0;
int s_e = 0;
int obset_2 = 0;
int s_p_2 = 0;
int s_e_2 = 0;
string fileName = "";
string sheetName = "";
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
if (fileName == "" || sheetName == "")
{
MessageBox.Show("请从右侧输入数据源,并确认!");
}
else
{
if (obset == 0 || this.comboBox1.Text == "")
{
MessageBox.Show("请选择统计科目!");
}
if (s_p == 0)
{
MessageBox.Show("请填写起始分数!");
}
if (s_e == 0)
{
MessageBox.Show("请填写结束分数!");
}
if (obset == 1 && s_p == 1 && s_e == 1)
{
if (int.Parse(this.textBox1.Text) > int.Parse(this.textBox2.Text))
{
MessageBox.Show("请填写正确的统计区间!");
}
}
if (this.comboBox1.Text != "" && obset == 1 && s_p == 1 && s_e == 1 && int.Parse(this.textBox1.Text) < int.Parse(this.textBox2.Text))
{
string strOdbcCon = @"Provider=Microsoft.ACE.OLEDB.12.0; Persist Security Info=False;Data Source="+fileName+"; Extended Properties=Excel 8.0";
OleDbConnection excelCon = new OleDbConnection(strOdbcCon);
string selectSql = @"select 班级,count(" + this.comboBox1.Text + ") as " + this.comboBox1.Text + "统计人数 from [" + sheetName + "$] where " + this.comboBox1.Text + ">=" + textBox1.Text + " and " + this.comboBox1.Text + "<=" + textBox2.Text + " group by 班级";
this.label5.Text = this.comboBox1.Text;
OleDbDataAdapter OleDat = new OleDbDataAdapter(selectSql, excelCon);
DataTable dt = new DataTable();
OleDat.Fill(dt);
this.dataGridView1.DataSource = dt.DefaultView;
}
}
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
obset = 1;
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
s_p = 1;
}

private void textBox2_TextChanged(object sender, EventArgs e)
{
s_e = 1;
}

private void button2_Click(object sender, EventArgs e)
{
if (fileName == "" || sheetName == "")
{
MessageBox.Show("请从右侧输入数据源,并确认!");
}
else
{
if (obset_2 == 0 || this.comboBox2.Text == "")
{
MessageBox.Show("请选择统计科目!");
}
if (s_p_2 == 0)
{
MessageBox.Show("请填写起始分数!");
}
if (s_e_2 == 0)
{
MessageBox.Show("请填写结束分数!");
}
if (obset_2 == 1 && s_p_2 == 1 && s_e_2 == 1)
{
if (int.Parse(this.textBox3.Text) < int.Parse(this.textBox4.Text))
{
MessageBox.Show("请填写正确的统计区间!");
}
}
if (this.comboBox2.Text != "" && obset_2 == 1 && s_p_2 == 1 && s_e_2 == 1 && int.Parse(this.textBox3.Text) > int.Parse(this.textBox4.Text))
{
string strOdbcCon_2 = @"Provider=Microsoft.ACE.OLEDB.12.0; Persist Security Info=False;Data Source="+fileName+"; Extended Properties=Excel 8.0";
OleDbConnection excelCon_2 = new OleDbConnection(strOdbcCon_2);
string selectSql_2 = @"select 班级,count(" + this.comboBox2.Text + ") as " + this.comboBox2.Text + "统计人数 from ["+sheetName+"$] where " + this.comboBox2.Text + ">=" + textBox4.Text + " and " + this.comboBox2.Text + "<=" + textBox3.Text + " group by 班级";
this.label11.Text = this.comboBox2.Text;
OleDbDataAdapter OleDat_2 = new OleDbDataAdapter(selectSql_2, excelCon_2);
DataTable dt_2 = new DataTable();
OleDat_2.Fill(dt_2);
this.dataGridView2.DataSource = dt_2.DefaultView;
}
}
}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
obset_2 = 1;
}

private void textBox4_TextChanged(object sender, EventArgs e)
{
s_p_2 = 1;
}

private void textBox3_TextChanged(object sender, EventArgs e)
{
s_e_2 = 1;
}

private void button3_Click(object sender, EventArgs e)
{
string fileName_che = this.textBox5.Text;
string sheetName_che = this.textBox6.Text;
string strOdbcCon_che = @"Provider=Microsoft.ACE.OLEDB.12.0; Persist Security Info=False;Data Source="+fileName_che+"; Extended Properties=Excel 8.0";
OleDbConnection excelCon_che = new OleDbConnection(strOdbcCon_che);
string selectSql_che = @"select * from [" + sheetName_che + "$]";
//this.label5.Text = this.comboBox1.Text;
OleDbDataAdapter OleDat_che = new OleDbDataAdapter(selectSql_che, excelCon_che);
DataTable dt_che = new DataTable();
OleDat_che.Fill(dt_che);
this.dataGridView3.DataSource = dt_che.DefaultView;
MessageBox.Show("请在下方查看数据源是否正确,正确请点击确认数据源!");
}

private void button4_Click(object sender, EventArgs e)
{
fileName = this.textBox5.Text;
sheetName = this.textBox6.Text;
MessageBox.Show("已经确认选择数据源!");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐