报表动态代码

页面前台

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="IntegrateSonChart.aspx.cs"
    Inherits="Com.DRPENG.INFOPLAT.UI.XFZGL.ScoreManager.Report.IntegrateSonChart"
    ResponseEncoding="utf-8" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>综合分析各率分布图</title>

    <script language="Javascript" src="FusionCharts/FusionCharts.js"></script>

    <link href="../../css/main.css" type="text/css" rel="stylesheet" />
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
        <asp:Label ID="lblTopInfo" Font-Size="Large" Font-Bold="true" Text="各率分布图" runat="server"></asp:Label></div>
    <div align="center" runat="server">
        <asp:RadioButtonList runat="server" ID="rdoList" AutoPostBack="true" OnSelectedIndexChanged="RG_SelectedIndexChanged"
            RepeatDirection="Horizontal">
        </asp:RadioButtonList>
    </div>
    </form>
    <%=GetProductChartHtml()%>
</body>
</html>
页面后台

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using ScoreManageModule.BusinessModel;
using ScoreManageModule.DataModel;
using Com.DRPENG.SDXY.BasicData.Business;
using Com.DRPENG.SDXY.BasicData.DataModel;
using Com.DRPENG.SDXY.CouseModule.DataModel;
using Com.DRPENG.SDXY.CouseModule.Business;
using Com.DRPENG.Common.ControlFactory;

namespace Com.DRPENG.INFOPLAT.UI.XFZGL.ScoreManager.Report
{
    public partial class IntegrateSonChart : Com.DRPENG.Common.WebStruct.BaseForm
    {
        private static ScoreInfoOneMng ScoreMng = new ScoreInfoOneMng();
        private static ExamArrangeMng ExamArrangeMng = new ExamArrangeMng();
        private static ScoreAnalysis ScoreAnalysisMng = new ScoreAnalysis();
        private static ScoreAreaSetDetailMng ScoreAreaDtlMng = new ScoreAreaSetDetailMng();
        private static OrganizationManager orgMng = (OrganizationManager)ControlFactory.Instance.CreateManager(typeof(OrganizationManager));
        protected static EnrollGradeManager EnrollMng = (EnrollGradeManager)ControlFactory.Instance.CreateManager(typeof(EnrollGradeManager));
        protected static CourseStoreManager courseStoreMng = (CourseStoreManager)ControlFactory.Instance.CreateManager(typeof(CourseStoreManager));
        public static string ExamID, CourseCode, ScoreArea, ScoreArea2, ClassIDes;
        public static bool IsHaveScore, IsContran;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ExamID = Request.QueryString["ExamID"];
                CourseCode = Request.QueryString["CourseCode"];
                ScoreArea = Request.QueryString["ScoreArea"];
                ScoreArea2 = Request.QueryString["ScoreArea2"];
                ClassIDes = Request.QueryString["ClassIDes"];
                IsContran = Request["IsContran"] == "1" ? true : false;
                IsHaveScore = false;
                if (!string.IsNullOrEmpty(ExamID))
                    RadorGroupInit(ScoreArea2);
                if (ExamArrangeMng.ValidExam(new Guid(ExamID)))
                {
                    string NewCls = string.Empty;
                    foreach (string str in ClassIDes.Split(','))
                    {
                        if (ExamArrangeMng.ValidExam(new Guid(ExamID), new Guid(str)))
                            NewCls += str + ",";
                    }
                    if (!string.IsNullOrEmpty(NewCls))
                    {
                        ClassIDes = NewCls.TrimEnd(',');
                        IsHaveScore = true;
                    }
                }
            }
        }

        /// <summary>
        /// 学校ID
        /// </summary>
        protected Guid SchoolID
        {
            get
            {
                return base. CurrentSchoolID;
            }
        }

        void RadorGroupInit(string scoreAreaID)
        {
            ArrayList ScoreAreaSet2 = ScoreAreaDtlMng.GetAllScoreAreaID(scoreAreaID);
            rdoList.DataSource = ScoreAreaSet2;
            rdoList.DataTextField = "ListName";
            rdoList.DataValueField = "ID";
            rdoList.DataBind();
            if (ScoreAreaSet2.Count > 0)
                rdoList.SelectedIndex = 0;
        }

        //生成图形报表
        public string GetProductChartHtml()
        {
            if (!string.IsNullOrEmpty(rdoList.SelectedValue)&&IsHaveScore)
            {
                string ClassName = string.Empty;
                string ClassData = string.Empty;
                string[] Classes = ClassIDes.Split(',');
                string GradeCode = Request.QueryString["GradeCode"];
                ScoreAreaSetDetail detail = ScoreAreaDtlMng.SearchRecord(rdoList.SelectedValue);
                ExamArrange exam = ExamArrangeMng.GetExamArrange(new Guid(ExamID));
                DataTable dt = dt = ScoreAnalysisMng.ComprehensiveAnalysis(ExamID, CourseCode, Classes, ScoreArea, ScoreArea2, IsContran, SchoolID.ToString());
                lblTopInfo.Text = orgMng.QueryByID(new Guid(GradeCode)).Name + exam.ExamName + courseStoreMng.FindCourseStoreByCode(CourseCode).Name + "各率分布图";
                if (dt.Rows.Count > 0)
                {
                    //增加年级信息
                    //计算班级平均分和标准差
                    for (int I = 0; I < dt.Rows.Count; I++)
                    {
                        ClassName = ClassName + dt.Rows[I]["ClassName"].ToString() + ",";
                        ClassData = ClassData + dt.Rows[I][detail.ListName].ToString() + ",";
                    }
                    string[] dataTypeName = new string[1];
                    dataTypeName[0] = rdoList.SelectedItem.Text;
                    string[] dataType = new string[1];
                    dataType[0] = "P";
                    string[] DataName = ClassName.TrimEnd(',').Split(',');
                    string[] DataValue = new string[1];
                    DataValue[0] = ClassData.TrimEnd(',');
                    //标题
                    string title = rdoList.SelectedItem.Text + "直方图";
                    //横坐标说明标题
                    string xTitle = "";
                    //是否动态显示 1为是 其他是否
                    string xmlDataYear = "<chart caption='" + title + "' numberSuffix='%25' XAxisName='" + xTitle + "' subcaption='" + "" + "' showValues='1' yAxisMaxValue='100' yAxisName='百分比' rotateyaxisname='0' baseFontSize='12'>";
                    xmlDataYear += FusionCharts.GetHistogramData(dataTypeName, dataType, DataName, DataValue);
                    xmlDataYear += "<styles><definition><style type='font' color='555555' name='CaptionFont' size='16' /><style type='font' name='SubCaptionFont' bold='0' size='12' /></definition><application><apply toObject='caption' styles='CaptionFont' /><apply toObject='SubCaption' styles='SubCaptionFont' /></application></styles>";
                    xmlDataYear += "</chart>";
                    return FusionCharts.RenderChart("FusionCharts/StackedColumn3D.swf", "", xmlDataYear, "SalesByYear", "550", "380", false, true);
                }
            }
            return "";
        }

        protected void RG_SelectedIndexChanged(object sender, EventArgs e)
        {
            GetProductChartHtml();
        }
    }

    public class FusionCharts
    {
        #region 生成直方图数据
        /// <summary>
        /// 生成数据字符串
        /// </summary>
        /// <param name="DataTypeName">图形数据分布种类名称</param>
        /// <param name="DataType">图形数据类型:S为线形,P为方形</param>
        /// <param name="DataName">数据名字</param>
        /// <param name="DataValue">数据值(个数与DataTypeName数一致,每一个字符串都为种类的数据并用,号隔开)</param>
        /// <returns></returns>
        public static string GetHistogramData(string[] DataTypeName, string[] DataType, string[] DataName, string[] DataValue)
        {
            StringBuilder xmlData = new StringBuilder();
            if (DataTypeName.Length > 0 && DataValue.Length > 0)
            {
                StringBuilder categories = new StringBuilder();
                StringBuilder strAmtDS = new StringBuilder();
                categories.Append("<categories>");
                for (int j = 0; j < DataName.Length; j++)
                {
                    categories.Append("<category label='" + DataName[j] + "'/>");
                }
                categories.Append("</categories>");
                for (int i = 0; i < DataTypeName.Length; i++)
                {
                    strAmtDS.Append("<dataset seriesname='" + DataTypeName[i] + "' parentYAxis='" + DataType[i] + "'>");
                    string[] values = DataValue[i].Split(',');
                    for (int j = 0; j < values.Length; j++)
                        strAmtDS.Append("<set value='" + values[j] + "'/>");
                    strAmtDS.Append("</dataset>");
                }
                xmlData.Append(categories);
                xmlData.Append(strAmtDS);
            }
            return xmlData.ToString();
        }

        //string[] formatStrings(string[] DataValue)
        //{
        //    string[] newValue;
        //    for (int i = 0; i < DataValue.Length; i++)
        //    {
        //        string[] tmpStr = DataValue[i].Split(',');
        //        newValue = new string[tmpStr.Length];
        //        for (int j = 0; j < tmpStr.Length; j++)
        //        {
        //            newValue[j] += tmpStr[j]+",";
        //        }
        //    }
        //}
        #endregion

        /// <summary>
        /// 生成图形字条串
        /// </summary>
        /// <param name="chartSWF"></param>
        /// <param name="strURL"></param>
        /// <param name="strXML"></param>
        /// <param name="chartId"></param>
        /// <param name="chartWidth"></param>
        /// <param name="chartHeight"></param>
        /// <param name="debugMode"></param>
        /// <param name="registerWithJS"></param>
        /// <returns></returns>
        public static string RenderChart(string chartSWF, string strURL, string strXML, string chartId,
                string chartWidth, string chartHeight, bool debugMode, bool registerWithJS)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("<!-- START Script Block for Chart {0} -->" + Environment.NewLine, chartId);
            builder.AppendFormat("<div id='{0}Div' align='center'>" + Environment.NewLine, chartId);
            builder.Append("Chart." + Environment.NewLine);
            builder.Append("</div>" + Environment.NewLine);
            builder.Append("<script type=/"text/javascript/">" + Environment.NewLine);
            builder.AppendFormat("var chart_{0} = new FusionCharts(/"{1}/", /"{0}/", /"{2}/", /"{3}/", /"{4}/", /"{5}/");" + Environment.NewLine, chartId, chartSWF, chartWidth, chartHeight, boolToNum(debugMode), boolToNum(registerWithJS));
            if (strXML.Length == 0)
            {
                builder.AppendFormat("chart_{0}.setDataURL(/"{1}/");" + Environment.NewLine, chartId, strURL);
            }
            else
            {
                builder.Append("chart_" + chartId + ".setDataXML(/"" + strXML + "/");" + Environment.NewLine);
            }


            builder.AppendFormat("chart_{0}.render(/"{1}Div/");" + Environment.NewLine, chartId, chartId);
            builder.Append("</script>" + Environment.NewLine);
            builder.AppendFormat("<!-- END Script Block for Chart {0} -->" + Environment.NewLine, chartId);
            return builder.ToString();
        }

        private static int boolToNum(bool value)
        {
            return value ? 1 : 0;
        }
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值