Demo entry 6720703

c#

   

Submitted by en on Mar 17, 2018 at 14:54
Language: ANTLR With C# Target. Code size: 2.7 kB.

using Rdlc.Web.DataAccess;
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;

namespace Rdlc.Web
{
    public partial class Index : 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;

            ReportDataSource rds1 = new ReportDataSource("DataSet1",GetStudentInfo(id));
            ReportDataSource rds2 = new ReportDataSource("DataSet2", GetScores(id));
            ReportViewer1.LocalReport.ReportPath = "StudentInfo.rdlc";
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(rds1);
            ReportViewer1.LocalReport.DataSources.Add(rds2);
            this.ReportViewer1.LocalReport.Refresh();
        }
        /// <summary>
        /// 根据学号获取学生信息
        /// </summary>
        /// <param name="id">学号</param>
        /// <returns></returns>
        public DataTable GetStudentInfo(string id)
        {
            MySqlHelper db = new MySqlHelper();
            var ds = db.ExecuteDataSet("select * from meg where s_id='"+id+"'");
            return ds.Tables[0];
        }
        /// <summary>
        /// 根据学号获取成绩
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable GetScores(string id)
        {
            MySqlHelper db = new MySqlHelper();
            var ds = db.ExecuteDataSet(string.Format(@"select s.*,'' as ranking from scores s,meg m
            where s.s_name=m.s_name and 
            m.s_id='{0}' order by
            s.s_term asc",id));
            //获取班级学期排行数据
            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).