为某中学编写的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("已经确认选择数据源!"); } } }
相关文章推荐
- 实验7(4)编写程序,输入一批学生的成绩,遇0或负数则输入结束,要求统计并输出优秀(大于85)、通过(60~84)和不及格(小于60)的学生人数。
- 统计各班学生的平均成绩,各班人数不等,但不超过30,编写一个程序求
- 四、编写程序,输入一批学生的成绩,遇0或负数则输入结束,要求统计并输出优秀(大于85)、通过(60~84)和不及格(小于60)的学生人数。
- 请你编写一个统计《C++程序设计》课程的成绩。统计的内容包括最高分、最低分、平均分,以及在90100,80 89,70 79,60 69和60以下个分数段的人数
- 16. 编写函数,统计一批成绩中各分数段的人数。
- 用PL/SQL语言编写一程序,实现按部门分段统计各个工资段的职工人数、以及各部门的工资总额
- 统计和输出实验 8 数组2 一次考试中的最高分、最低分、平均分,以及在90~100、 80~89、 70~79、 60~69和60分以下各分数段的人数。程序代码如下
- 实验七4编写程序,输入一批学生的成绩,遇0或负数则输入结束,要求统计并输出优秀(大于85)、通过(60~84)和不及格(小于60)的学生人数。
- 如何通过servlet编写程序能够统计浏览客户端页面的人数,ip不同人数加1
- 编写程序,统计某旅馆住宿客人的总数,要求输入客人姓名,输出客人编号(按先后顺序自动生成),姓名以及总人数。
- 实验8 统计和输出一次考试中的最高分、最低分、平均分,以及在90~100、 80~89、 70~79、 60~69和60分以下各分数段的人数。程序代码如下(可复制):
- C#编写简单的聊天程序
- 编写一个程序统计各个数字、空白符(包括空格符、制表符及换行符)以及其它字符出现的次数
- win7环境中编写的C#程序无法在xp中运行
- 编写高质量代码改善C#程序的157个建议
- C#编写的生成缩略图程序
- C#基础:用记事本编写简单WinForm窗体程序
- 使用记事本编写C#程序并编译
- c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程
- C#编写的winform程序打包方法