# Demo entry 6720709

**c#**

Submitted by **c**
on Mar 17, 2018 at 15:10

Language: C#. Code size: 9.0 kB.

using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Microsoft.Reporting.WebForms; using Rdlc.Web.DataAccess; namespace Rdlc.Web { public partial class ScroesAnalysis : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { var id = this.TextBox1.Text; var items = this.TextBox2.Text; ReportDataSource rds1 = new ReportDataSource("DataSet1", GetScoresByClassId(id, items)); ReportDataSource rds2 = new ReportDataSource("DataSet2", GetScoresByClassId2(id, items)); ReportDataSource rds3 = new ReportDataSource("DataSet3", GetScoresByClassId3(id, items)); ReportDataSource rds4 = new ReportDataSource("DataSet4", GetScoresByClassId4(id, items)); ReportDataSource rds5 = new ReportDataSource("DataSet5", GetScoresByClassId5(id, items)); ReportViewer1.LocalReport.ReportPath = "ScroesAnalysis.rdlc"; ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.DataSources.Add(rds1); ReportViewer1.LocalReport.DataSources.Add(rds2); ReportViewer1.LocalReport.DataSources.Add(rds3); ReportViewer1.LocalReport.DataSources.Add(rds4); ReportViewer1.LocalReport.DataSources.Add(rds5); this.ReportViewer1.LocalReport.Refresh(); } /// <summary> /// 根据班级获取成绩 /// </summary> /// <param name="id"></param> /// <returns></returns> public DataTable GetScoresByClassId(string id,string term) { MySqlHelper db = new MySqlHelper(); string sqlStr = @"select N'语文' as kemu, (select count(1) from scores where yuwen>=90 and s_class='{0}' and s_term='{1}')/(select count(1) from scores where s_class='{0}' and s_term='{1}') as youxiulv, (select count(1) from scores where yuwen>=60 and s_class='{0}' and s_term='{1}')/(select count(1) from scores where s_class='{0}' and s_term='{1}') as jigelv, (select max( yuwen) from scores where s_class='{0}' and s_term='{1}') as zuigaof, (select min( yuwen) from scores where s_class='{0}' and s_term='{1}') as zuidif, (select count(1) from scores where yuwen>=90 and s_class='{0}' and s_term='{1}') youxiur, (select count(1) from scores where yuwen>=60 and s_class='{0}' and s_term='{1}') jiger, (select avg(yuwen) from scores where s_class='{0}' and s_term='{1}') as pingjunf, (select sum(yuwen) from scores where s_class='{0}' and s_term='{1}') as zongfen union all select N'数学' as kemu, (select count(1) from scores where math>=90 and s_class='{0}' and s_term='{1}')/(select count(1) from scores where s_class='{0}' and s_term='{1}') as youxiulv, (select count(1) from scores where math>=60 and s_class='{0}' and s_term='{1}')/(select count(1) from scores where s_class='{0}' and s_term='{1}') as jigelv, (select max( math) from scores where s_class='{0}' and s_term='{1}') as zuigaof, (select min( math) from scores where s_class='{0}' and s_term='{1}') as zuidif, (select count(1) from scores where math>=90 and s_class='{0}' and s_term='{1}') youxiur, (select count(1) from scores where math>=60 and s_class='{0}' and s_term='{1}') jiger, (select avg(math) from scores where s_class='{0}' and s_term='{1}') as pingjunf, (select sum(math) from scores where s_class='{0}' and s_term='{1}') as zongfen union all select N'英语' as kemu, (select count(1) from scores where English>=90 and s_class='{0}' and s_term='{1}')/(select count(1) from scores where s_class='{0}' and s_term='{1}') as youxiulv, (select count(1) from scores where English>=60 and s_class='{0}' and s_term='{1}')/(select count(1) from scores where s_class='{0}' and s_term='{1}') as jigelv, (select max( English) from scores where s_class='{0}' and s_term='{1}') as zuigaof, (select min( English) from scores where s_class='{0}' and s_term='{1}') as zuidif, (select count(1) from scores where English>=90 and s_class='{0}' and s_term='{1}') youxiur, (select count(1) from scores where English>=60 and s_class='{0}' and s_term='{1}') jiger, (select avg(English) from scores where s_class='{0}' and s_term='{1}') as pingjunf, (select sum(English) from scores where s_class='{0}' and s_term='{1}') as zongfen "; var ds = db.ExecuteDataSet(string.Format(sqlStr, id,term)); return ds.Tables[0]; } public DataTable GetScoresByClassId2(string id,string term) { MySqlHelper db = new MySqlHelper(); string sqlStr = @"select N'语文' as kemu, (select count(1) from scores where yuwen>=90 and s_class='{0}' and s_term='{1}') jiushi, (select count(1) from scores where yuwen>=75 and s_class='{0}' and s_term='{1}') qishiwu, (select count(1) from scores where yuwen>=60 and s_class='{0}' and s_term='{1}') liushi, (select count(1) from scores where yuwen<60 and s_class='{0}' and s_term='{1}') liushix union all select N'数学' as kemu, (select count(1) from scores where math>=90 and s_class='{0}' and s_term='{1}') jiushi, (select count(1) from scores where math>=75 and s_class='{0}' and s_term='{1}') qishiwu, (select count(1) from scores where math>=60 and s_class='{0}' and s_term='{1}') liushi, (select count(1) from scores where math<60 and s_class='{0}' and s_term='{1}') liushix union all select N'英语' as kemu, (select count(1) from scores where English>=90 and s_class='{0}' and s_term='{1}') jiushi, (select count(1) from scores where English>=75 and s_class='{0}' and s_term='{1}') qishiwu, (select count(1) from scores where English>=60 and s_class='{0}' and s_term='{1}') liushi, (select count(1) from scores where English<60 and s_class='{0}' and s_term='{1}') liushix "; var ds = db.ExecuteDataSet(string.Format(sqlStr, id, term)); return ds.Tables[0]; } /// <summary> /// 图表 数学 /// </summary> /// <param name="id"></param> /// <param name="term"></param> /// <returns></returns> public DataTable GetScoresByClassId3(string id, string term) { MySqlHelper db = new MySqlHelper(); string sqlStr = @"select '>=90' as type_name, count(1) as fenshu from scores where math>=90 and s_class='{0}' and s_term='{1}' union all select '>=75' as type_name, count(1) as fenshu from scores where math>=75 and s_class='{0}' and s_term='{1}' union all select '>=60' as type_name, count(1) as fenshu from scores where math>=60 and s_class='{0}' and s_term='{1}' union all select '60以下' as type_name, count(1) as fenshu from scores where math<60 and s_class='{0}' and s_term='{1}' "; var ds = db.ExecuteDataSet(string.Format(sqlStr, id, term)); return ds.Tables[0]; } /// <summary> /// 图表 英语 /// </summary> /// <param name="id"></param> /// <param name="term"></param> /// <returns></returns> public DataTable GetScoresByClassId4(string id,string term) { MySqlHelper db = new MySqlHelper(); string sqlStr = @"select '>=90' as type_name, count(1) as fenshu from scores where English>=90 and s_class='{0}' and s_term='{1}' union all select '>=75' as type_name, count(1) as fenshu from scores where English>=75 and s_class='{0}' and s_term='{1}' union all select '>=60' as type_name, count(1) as fenshu from scores where English>=60 and s_class='{0}' and s_term='{1}' union all select '60以下' as type_name, count(1) as fenshu from scores where English<60 and s_class='{0}' and s_term='{1}' "; var ds = db.ExecuteDataSet(string.Format(sqlStr, id,term)); return ds.Tables[0]; } /// <summary> /// 图表 语文 /// </summary> /// <param name="id"></param> /// <param name="term"></param> /// <returns></returns> public DataTable GetScoresByClassId5(string id,string term) { MySqlHelper db = new MySqlHelper(); string sqlStr = @"select '>=90' as type_name, count(1) as fenshu from scores where yuwen>=90 and s_class='{0}' and s_term='{1}' union all select '>=75' as type_name, count(1) as fenshu from scores where yuwen>=75 and s_class='{0}' and s_term='{1}' union all select '>=60' as type_name, count(1) as fenshu from scores where yuwen>=60 and s_class='{0}' and s_term='{1}' union all select '60以下' as type_name, count(1) as fenshu from scores where yuwen<60 and s_class='{0}' and s_term='{1}' "; var ds = db.ExecuteDataSet(string.Format(sqlStr, id, term)); return ds.Tables[0]; } } }

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.