Demo entry 6720705

c#

   

Submitted by en on Mar 17, 2018 at 15:02
Language: C#. Code size: 2.2 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 Scores : 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));
            ReportViewer1.LocalReport.ReportPath = "ScoresInfo.rdlc";
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(rds1);
            this.ReportViewer1.LocalReport.Refresh();
        }
        /// <summary>
        /// 根据班级获取成绩
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable GetScoresByClassId(string id,string terms)
        {
            MySqlHelper db = new MySqlHelper();
            var ds = db.ExecuteDataSet(string.Format(@"select m.s_id as no,s.*,'' as ranking from scores s,meg m
            where s.s_name=m.s_name and 
            s.s_class='{0}'and s.s_term='{1}' order by
            m.s_id asc", id,terms));
            //获取班级学期排行数据
            string sqlStr =
                "select s.* from scores s where s.s_term='{0}' and s.s_class='{1}' order by s_sum desc;";
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                var term = dr["s_term"].ToString();
                var sclass = dr["s_class"].ToString();
                var data = db.ExecuteDataTable(string.Format(sqlStr, term, sclass));
                for (int i = 0; i < data.Rows.Count; i++)
                {
                    if (data.Rows[i]["s_name"].ToString() == dr["s_name"].ToString())
                    {
                        dr["ranking"] = i + 1;
                    }
                }

            }
            return ds.Tables[0];
        }
    }
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).