zoukankan      html  css  js  c++  java
  • ExtJS 动态无刷新ReportViewer

    好久没上来了,最近用Ext做了一个无刷新的报表查询功能,跟大家分享下:

    首先我们说下思路:

    1.通过Ext实现查询条件无刷新

    2.在aspx页面中放置一个ReportViewer控件

    3.ReportViewer控件的查询添加不要,通过Ext动态拼

    4.报表文件是从WebService中找到的文件名,然后在客户端的Reportviewer控件显示

    思路简单就是这些,呵呵。现在开始操作:

    1.首先将Ext需要的文件放置到项目中(简单来说就是先将Ext部署到项目上).

    2.新建一个a.aspx页面用于拼查询条件,代码如下:

    View Code
    <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title>查询统计</title>
    <link href="../Resource/Scripts/Common/Extjs/resources/css/ext-all.css" rel="Stylesheet"
    type="text/css" />
    <link href="../Styles/ktv.css" rel="stylesheet" type="text/css" />
    <script src="../Resource/Scripts/Common/Extjs/adapter/ext/ext-base.js" type="text/javascript"></script>
    <script src="../Resource/Scripts/Common/Extjs/ext-all.js" type="text/javascript"></script>
    <script src="../Resource/Scripts/Common/Jquery/jquery-1.5.2.js" type="text/javascript"></script>
    <script src="../Resource/Scripts/Common/Ajax/ajax.js" type="text/javascript"></script>
    <link href="../Resource/Scripts/basa/Common/Ext.ux.form.LovCombo.css" rel="stylesheet"
    type="text/css" />
    <script src="../Resource/Scripts/basa/Common/Ext.ux.form.LovCombo.js" type="text/javascript"></script>
    <%-- <script src="../Resource/Scripts/basa/Common/CheckCb.js" type="text/javascript"></script>
    <link href="../Resource/Scripts/basa/Common/CheckCb.css" rel="stylesheet" type="text/css" />--%>
    <script src="../Resource/Scripts/basa/Common/MsgAlert.js" type="text/javascript"></script>
    <script src="../Resource/Scripts/Common/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="../Resource/Scripts/basa/Common/comboBox.js" type="text/javascript"></script>
    <script src="../Resource/Scripts/basa/WebReportView/ReportServer.js" type="text/javascript"></script>
    <style type="text/css">
    .HideDiv
    {
    display:none
    }
    </style>
    <script type="text/javascript">
    Ext.ux.form.LovCombo.prototype.onRealBlur = function () { // by kimmking
    this.list.hide();
    this.setValue(this.value);
    }
    </script>
    </head>
    <body onload="PageLoad();">
    <form id="form1" runat="server">
    <div class="content" id="content">
    <div class="HideDiv" id="findpanel">
    <div class="findparam" id="findval">
    <div id="tbParams"></div>
    </div>
    </div>
    <div>
    <iframe id="ifReport" name ="ifReport" style="100%; height:480px"></iframe>
    </div>
    </div>
    </form>
    </body>
    </html>

    上述代码中,在a.aspx页面中放置一个iframe用于显示ReportViewer

    3.a.aspx页面的后台文件如下:

    View Code
     public partial class ReportServer : System.Web.UI.Page
    {
    public static string ReportServerUrl = Properties.Settings.Default.Wanda_Ktv_HQWeb_WebReference_ReportingService2005;
    ArrayList alst = new ArrayList();
    protected void Page_Load(object sender, EventArgs e)
    {
    string parName = Request.Params["_action"] ==
    null ? string.Empty : base.Request.Params["_action"].ToString();
    if (!string.IsNullOrEmpty(parName))
    {
    switch (parName)
    {
    case "GetReportParams":
    GetReportParams();
    break;
    case "GetReportParent":
    GetReportParams();
    break;
    }
    }
    }


    /// <summary>
    /// 获取报表参数
    /// </summary>
    private void GetReportParams()
    {
    string reportUrl = Request.Params["reportUrl"].ToString();

    ReportingService2005 reportService = new ReportingService2005();

    reportService.Url = ReportServerUrl;

    reportService.UseDefaultCredentials = true;

    string parentId = string.Empty;
    if (Request.Params["parentId"] != null && Request.Params["parentId"].ToString() != string.Empty)
    {
    parentId = Request.Params["parentId"].ToString();
    }
    string associate = string.Empty;
    if (Request.Params["associate"] != null && Request.Params["associate"].ToString() != string.Empty)
    {
    associate = Request.Params["associate"].ToString();
    }

    List<Microsoft.Reporting.WebForms.ReportParameter> rpa = new List<Microsoft.Reporting.WebForms.ReportParameter>();

    Microsoft.Reporting.WebForms.ReportParameter r = new Microsoft.Reporting.WebForms.ReportParameter();

    string historyId = null;
    bool rendering = true;
    ParameterValue[] values = null;
    ArrayList lst = new ArrayList();
    DataSourceCredentials[] credentials = null;

    if (parentId != string.Empty)
    {
    ParameterValue pav = new ParameterValue();
    pav.Value = parentId;
    if (associate != string.Empty)
    {
    pav.Name = associate;
    }
    lst.Add(pav);
    }
    if (lst.Count > 0)
    {
    values = lst.ToArray(typeof(WebReference.ParameterValue)) as ParameterValue[];
    }
    ReportParameter[] paremeterValue = reportService.GetReportParameters(reportUrl, historyId, rendering, values, credentials);

    if (paremeterValue.Length > 0)
    {
    List<ExhibitReport> listReportCountrol = new List<ExhibitReport>();

    foreach (ReportParameter par in paremeterValue)
    {
    ExhibitReport eReport = new ExhibitReport();
    eReport.ControlName = par.Name;
    eReport.LabelName = par.Prompt;
    eReport.ControlType = "text";
    eReport.ControlCode = par.Name;
    Dictionary<string, object> dict = new Dictionary<string, object>();
    //级联
    if (par.Dependencies != null)
    {
    foreach (string item in par.Dependencies)
    {
    //dict.Add(par.Name, item);
    dict.Add(par.Name,item);
    alst = new ArrayList();
    alst.Add(item);
    eReport.associateName = item;
    }
    eReport.Associate = dict;

    }

    if (par.ValidValues != null && par.ValidValues.Length > 0)
    {
    eReport.ControlType = "select";
    #region
    if (par.MultiValue)
    {
    eReport.ControlType = "multiSelect";
    EReportControlValue(par, eReport);

    if (par.Dependencies != null)
    {
    if (parentId != string.Empty)
    {
    foreach (string item in par.Dependencies)
    {
    if (par.Dependencies[0] == item)
    {
    List<ControlValue> lcv = new List<ControlValue>();
    ControlValue cv = new ControlValue();
    cv.Code = parentId;
    cv.Name = par.Dependencies[0];
    lcv.Add(cv);
    eReport.ControlValue = lcv;
    }
    }

    }
    }
    }
    else
    {
    EReportControlValue(par, eReport);
    }
    #endregion
    }
    if (par.Type == ParameterTypeEnum.DateTime)
    {
    eReport.ControlType = "dateTime";
    }
    listReportCountrol.Add(eReport);
    }
    JavaScriptSerializer js = new JavaScriptSerializer();

    string json = js.Serialize(listReportCountrol);

    Response.Write(json);
    Response.End();
    }
    else
    {
    //该报表没有参数
    // 查询按钮不显示 且不显示 查询区域DIV
    Response.Write("-1");
    Response.End();
    }

    }

    private static void EReportControlValue(ReportParameter par, ExhibitReport eReport)
    {
    List<ControlValue> lcv = new List<ControlValue>();
    foreach (ValidValue v in par.ValidValues)
    {
    ControlValue cv = new ControlValue();
    cv.Code = v.Value;
    cv.Name = v.Label;
    lcv.Add(cv);
    }
    eReport.ControlValue = lcv;
    }
    }
    }


    public class ExhibitReport
    {
    public string LabelName { get; set; }

    public string ControlName { get; set; }

    public string ControlType { get; set; }

    public List<ControlValue> ControlValue { get; set; }

    public string ControlCode { get; set; }

    public Dictionary<string, object> Associate { get; set; }
    public string associateName { get; set; }
    }

    public class ControlValue
    {
    public string Code { get; set; }

    public string Name { get; set; }
    }

    此文件可以实现级联的。先通过查询报表由哪些条件,然后将条件用Json传递到前台。

    4.新建一个b.js文件,此文件用于拼接条件,代码如下:

    View Code
    var _reportUrl;

    var _reportValue;

    //页面初始化
    //获取REQUES URL参数—获取报表文件参数—生成对应TABLE
    function PageLoad() {
    //var _reportUrl = GetRequest().path;
    _reportUrl = GetRequest().path;
    //获取报表参数
    _reportValue = GetReportParams(_reportUrl);
    //显示DIV(拼接)
    ShowDiv(_reportValue);
    if (_reportValue != undefined) {
    for (var i = 0; i < _reportValue.length; i++) {
    if (_reportValue[i].ControlType == 'multiSelect') {
    ShowBaseCheckComboBox(_reportValue[i].ControlValue, _reportValue[i].ControlName);
    }
    if (_reportValue[i].Associate != null) {
    if (_reportValue[_reportValue.length - i].ControlType == 'text') {
    ShowReportValueSelect(_reportValue[i].ControlName, _reportValue[i].associateName, 'Json', getReportValue, true, undefined, _reportValue[i].associateName);
    } else {
    ShowReportValueSelect(_reportValue[i].ControlName, _reportValue[i].associateName, 'Json', getReportValue, true, undefined, _reportValue[i].associateName);
    }
    }
    if (_reportValue[i].ControlType == 'select') {
    ShowBaseEasyComboBox(_reportValue[i].ControlValue, _reportValue[i].ControlName);
    }
    }
    }
    PageLoadReport('', _reportUrl);
    }
    function getReportValue(parentId, associate) {
    var data;
    Fix.Ajax.url = 'http://www.cnblogs.com/http://www.cnblogs.com/WebReportView/ReportServer.aspx';
    Fix.Ajax.action = 'GetReportParent';
    Fix.Ajax.asyn = false;
    Fix.Ajax.JSON = 'parentId=' + parentId + '&reportUrl=' + _reportUrl + '&associate=' + associate;
    Fix.Ajax.success = function () {
    data = Fix.Ajax.returnJSON; //回调函数
    }
    Fix.Ajax.execute(); //执行
    return data;
    }
    function SetComboBoxDis(txtId) {
    SetComboBoxValue(txtId, '');
    }

    function ShowReportValueSelect(txtId, parentId, dataType, myDataFunc, Isput, myData, associate) {
    var parentInput = document.getElementById(parentId);
    if (parentInput == undefined || parentInput == '') {
    parentInput = parent.document.getElementById(parentId);
    }

    Ext.onReady(function () {
    var parentCombo = Ext.getCmp(parentId + '_cb');
    if (parentCombo == undefined || parentCombo == '') {
    parentCombo = parent.Ext.getCmp(parentId + '_cb');
    if (parentCombo == undefined || parentCombo == '') {
    parentCombo = document.getElementById(parentId);
    }
    }
    var reportCombo = Ext.getCmp(txtId + '_cb');
    if (reportCombo == undefined || reportCombo == '') {
    reportCombo = parent.Ext.getCmp(txtId + '_cb');
    }
    if (myData == undefined || myData == '' || myData == [] || myData.length == 0) {
    myData = undefined;
    myData = [];
    var obj = {};
    obj.code = undefined;
    obj.value = '未定义';
    myData.push(obj);
    Ext.QuickTips.init();
    }
    var store = new Ext.data.Store({
    proxy: new Ext.data.MemoryProxy(myData),
    reader: new Ext.data.ArrayReader({}, [{ name: 'code', mapping: 'code' }, { name: 'value', mapping: 'value'}])
    });
    store.load();
    if (reportCombo == undefined || reportCombo == '') {
    var cb = new Ext.form.ComboBox({
    id: txtId + '_cb',
    editable: false,
    store: store,
    displayField: 'value',
    valueField: 'code',
    typeAhead: true,
    mode: 'local',
    120,

    maxHeight: 200,
    forceSelection: true,
    triggerAction: 'all',
    // selectOnFocus: true,
    applyTo: txtId
    });
    cb.on('select', function (c, r, i) {
    document.getElementById(txtId).CodeValue = r.data.code;
    });
    document.getElementById(txtId).IsCombox = true;
    }
    parentCombo.on('select', function (c, r, i) {
    parentInput = document.getElementById(parentId);
    if (parentInput == undefined || parentInput == '') {
    parentInput = parent.document.getElementById(parentId);
    }
    reportInput = document.getElementById(txtId);
    if (reportInput == undefined || reportInput == '') {
    reportInput = parent.document.getElementById(txtId);
    }

    if (parentInput.CodeValue == undefined) {
    reportInput.style.readyonly = true;
    }
    if (parentInput.CodeValue != undefined) {
    myData = myDataFunc(parentInput.CodeValue, associate);
    }
    else {
    myData = myDataFunc(parentInput.value, associate);
    }
    if (myData != undefined || myData != '' || myData != [] || myData.length != 0) {
    for (var i = 0; i < myData.length; i++) {
    if (myData[i].Associate != null) {
    if (myData[i].ControlValue == null) {
    myData = undefined;
    reportInput.value = '未定义';
    SetComboBoxDisabled(txtId, true);
    break;
    }
    else {
    reportInput.value = '请选择...';
    SetComboBoxDisabled(txtId, false);
    }
    }
    }
    }
    if (myData == undefined || myData == '' || myData == [] || myData.length == 0) {
    myData = undefined;
    myData = [];
    var obj = {};
    obj.code = undefined;
    obj.value = '未定义';
    myData.push(obj);
    }

    });
    });
    }

    function GetReportParams(rUrl) {
    var data;
    Fix.Ajax.url = 'http://www.cnblogs.com/http://www.cnblogs.com/WebReportView/ReportServer.aspx';
    Fix.Ajax.action = 'GetReportParams';
    Fix.Ajax.asyn = false;
    Fix.Ajax.JSON = 'reportUrl=' + rUrl;
    Fix.Ajax.success = function () {
    data = Fix.Ajax.returnJSON; //回调函数
    }
    Fix.Ajax.execute(); //执行
    return data;
    }

    function ShowDiv(values) {
    if (values == -1) {
    //没有查询条件
    document.getElementById('findpanel').className = 'HideDiv';
    } else if (values != undefined && values.length > 0) {
    //开始拼TABLE
    document.getElementById('findpanel').className = 'findpanel';
    var rows = values.length % 3;
    if (rows == 0) {
    rows = (values.length / 3) + 1;
    } else {
    var ys = Math.round(values.length % 3)
    if (ys == 1) {
    rows = Math.round(values.length / 3) + 2;
    } else {
    rows = Math.round(values.length / 3) + 1;
    }
    }
    var tb = new Array();
    tb.push('<table><tbody>');
    for (var i = 0; i < rows; i++) {
    tb.push('<tr>');
    if (i + 1 != rows) {
    for (var j = 0; j < 6; j++) {
    if ((j % 2) == 0) {
    //LABEL
    tb.push('<td class="label">');
    try {
    var obj = values[i * 3 + j / 2];
    tb.push(obj.LabelName);
    }
    catch (e) { }
    } else {
    //control
    tb.push('<td class="txt1">');
    try {
    var obj = values[i * 3 + (j - 1) / 2];
    if (obj.ControlType == 'text') {
    tb.push('<input type="text" id ="' + obj.ControlName + '" class="findinput" />');
    } else if (obj.ControlType == 'select') {
    tb.push('<input type="text" id="' + obj.ControlName + '" name ="' + obj.ControlName + '" class="findinput" />');
    } else if (obj.ControlType == 'dateTime') {
    tb.push('<input type="text" id ="' + obj.ControlName
    + '" readonly=readonly onclick="WdatePicker({dateFmt:\'yyyy-MM-dd\'});" class="findinput" />'); ;
    } else if (obj.ControlType == 'multiSelect') {
    tb.push('<input type="text" id="' + obj.ControlName + '" name ="' + obj.ControlName + '" class="findinput" />');
    }
    } catch (e) { }
    }
    tb.push('</td>');
    }
    } else {
    tb.push('<td colspan="4">');
    tb.push('</td>');
    tb.push('<td class="Button_table" colspan="2">');
    tb.push('<input id="btSubimt" align="right" type="button" value="查询" class="Button_width" onclick="SetIframPage();" />');
    tb.push('</td>');
    }
    tb.push('</tr>');
    }
    tb.push('</tbody></table>');

    document.getElementById('tbParams').innerHTML = tb.join('');
    }
    }
    function ShowBaseEasyComboBox(value, txtId) {
    var valueListPush = [];
    for (var i = 0; i < value.length; i++) {
    var code = {};
    code.code = value[i].Code;
    code.value = value[i].Name;
    valueListPush.push(code);
    }
    ShowEasyComboBox(txtId, 'Json', valueListPush, true);
    }

    function ShowBaseCheckComboBox(value, txtId) {
    var valueListPush = [];
    for (var i = 0; i < value.length; i++) {
    var code = {};
    code.code = value[i].Code;
    code.value = value[i].Name;
    valueListPush.push(code);
    }
    //ShowCheckComboBox(txtId, 'Json', valueListPush, false);
    ShowCheck(txtId, 'Json', valueListPush, false);
    }

    function ShowCheck(txtId, dataType, myData, IsPut) {
    var t = false;
    Ext.onReady(function () {
    Ext.QuickTips.init();

    var arrData = [];
    var arr = {};
    arr.code = 'all';
    arr.value = ' (全选)';
    // arrData.unshift(arr);
    arrData.push(arr);

    var aData = arrData.concat(myData);

    var store = '';
    if (dataType == 'Json') {
    var rt = {};
    rt.data = aData;
    store = new Ext.data.JsonStore({
    fields: ['code', 'value'],
    root: 'data',
    data: rt
    });
    store.load();
    store.on('load', function (ds, records, o) {
    var isFirst = true;
    var selectItems = '';
    for (var i = 0; i < records.length; i++) {
    if (records[i].data.selected == 'y') {
    if (isFirst) {
    selectItems = selectItems + records[i].data.value;
    isFirst = false;
    }
    else {
    selectItems = selectItems + "," + records[i].data.value;
    }
    }
    }
    cb.setValue(selectItems);
    });
    }
    var cb = new Ext.ux.form.LovCombo({
    id: txtId + '_cb',
    store: store,
    mode: 'local',
    valueField: 'code',
    120,
    displayField: 'value',
    emptyText: '请选择...',
    forceSelection: true,
    editable: t,
    selectAllOn: 'all',
    typeAhead: true,
    applyTo: txtId
    });
    cb.on('select', function (c, r, i) {
    if (r.data.code != '') {
    if (r.data.code == 'all') {
    cb.selectAll();
    }
    else {
    document.getElementById(txtId).CodeValue = r.data.code;
    }
    }
    else document.getElementById(txtId).CodeValue = undefined;
    });
    document.getElementById(txtId).IsCombox = true;
    });
    }

    function SetIframPage(value) {
    var v = GetReportParmartValye();
    PageLoadReport(v, _reportUrl);
    }

    function PageLoadReport(value, report) {
    var iframe = document.getElementById('ifReport');
    iframe.src = 'ShowReport.aspx?reportValue=' + value + '&reportUrl=' + report;
    }

    function GetReportParmartValye() {
    var valuelist = '';
    for (var i = 0; i < _reportValue.length; i++) {
    if (_reportValue[i].ControlType == 'text') {
    var str = document.getElementById(_reportValue[i].ControlName).value;

    valuelist += _reportValue[i].ControlName + '|' + str;

    } else if (_reportValue[i].ControlType == 'select') {

    var str = document.getElementById(_reportValue[i].ControlName).CodeValue;
    if (str == undefined) {
    str = '';
    }
    valuelist += _reportValue[i].ControlName + '|' + str;

    } else if (_reportValue[i].ControlType == 'dateTime') {

    var str = document.getElementById(_reportValue[i].ControlName).value;

    valuelist += _reportValue[i].ControlName + '|' + str;

    } else if (_reportValue[i].ControlType == 'multiSelect') {
    var ccc = '';
    ccc = document.getElementById(_reportValue[i].ControlName).value;
    if (_reportValue[i].ControlCode.indexOf('Id') > 0) {
    if (/.*[\u4e00-\u9fa5]+.*$/.test(ccc)) { }
    ccc += document.getElementById(_reportValue[i].ControlName).CodeValue;
    if (ccc.length > 0) {
    ccc = ccc.substring(0, ccc.length - 9);
    }
    }

    if (ccc == undefined) {
    ccc = '';
    }
    valuelist += _reportValue[i].ControlName + '|' + ccc;

    } else {
    valuelist += _reportValue[i].ControlName + '|';
    }
    valuelist += '!';
    }
    valuelist = valuelist.substr(0, valuelist.length - 1)
    return valuelist;
    }

    //解析REQUES URL参数(报表类型 从这里接受)
    function GetRequest() {
    var url = decodeURI(location.search); //获取url中"?"符后的字串 + 解密
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
    var str = url.substr(1);
    strs = str.split("&");
    for (var i = 0; i < strs.length; i++) {
    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
    }
    }
    return theRequest;
    }

    根据条件类型的不同,通过Ext拼成不同的类型。通过Ajax实现数据传递到后台,以求实现Ajax同步处理,而页面无刷新。

    5.新建c.aspx页面用于接收a.aspx页面中传递的参数信息,并在Reportviewer控件中显示根据条件查询到的报表信息。

    前台页面如下:

    View Code
    <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <rsweb:ReportViewer ID="rvp" runat="server" ProcessingMode="Remote"
    Width="100%" Height="80%" ShowParameterPrompts="false" >
    </rsweb:ReportViewer>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    </div>
    </form>
    </body>
    </html>

    后台页面代码如下:

    View Code
     public static string ReportServerUrl = Properties.Settings.Default.Wanda_Ktv_HQWeb_WebReference_ReportingService2005;

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    SetReportView();
    }
    }

    private void SetReportView()
    {
    string reportPagth = Request.Params["reportUrl"].ToString(); ;

    string reportValue = Request.Params["reportValue"].ToString();

    rvp.ServerReport.ReportPath = reportPagth;

    rvp.ServerReport.ReportServerUrl = new Uri(ReportServerUrl.Replace("/ReportService2005.asmx", ""));

    if (!string.IsNullOrEmpty(reportValue))
    {

    IList<Microsoft.Reporting.WebForms.ReportParameter> rpa = new List<Microsoft.Reporting.WebForms.ReportParameter>();

    //定义凭据
    ReportingService2005 reportService = new ReportingService2005();
    reportService.UseDefaultCredentials = true;
    reportService.Url = ReportServerUrl;

    ArrayList arr = new ArrayList();
    ArrayList lst = new ArrayList();
    //查找参数
    ReportParameter[] paremeterValue = reportService.GetReportParameters(reportPagth, null, false, null, null);

    if (paremeterValue.Length > 0)
    {
    string[] values = reportValue.Split('!');
    List<ControlValue> _listValue = new List<ControlValue>();
    for (int i = 0; i < values.Length; i++)
    {
    string[] list = values[i].Split('|');
    _listValue.Add(new ControlValue
    {
    Code = list[0],
    Name = list[1]
    });
    }

    foreach (ReportParameter par in paremeterValue)
    {
    for (int i = 0; i < _listValue.Count; i++)
    {
    if (par.Nullable)
    {
    if (_listValue[i].Name == "")
    {
    lst.Add(_listValue[i].Name);
    }
    }
    else if (par.Name.Equals(_listValue[i].Code) && par.AllowBlank)
    {
    Microsoft.Reporting.WebForms.ReportParameter r = new Microsoft.Reporting.WebForms.ReportParameter();
    r.Name = _listValue[i].Code;
    SetParameter(_listValue, i, ref r);
    rpa.Add(r);
    }
    else if (par.Name.Equals(_listValue[i].Code) && !par.AllowBlank)
    {
    if (_listValue[i].Name == "")
    {
    lst.Add(par.Prompt);
    }
    else
    {
    Microsoft.Reporting.WebForms.ReportParameter r = new Microsoft.Reporting.WebForms.ReportParameter();
    r.Name = _listValue[i].Code;
    SetParameter(_listValue, i, ref r);
    rpa.Add(r);
    }
    }
    }
    }
    if (lst.Count > 0)
    {
    for (int i = 0; i < lst.Count; i++)
    {
    Response.Write("<script language='javascript'>parent.parent.parent.ExtAlert('提示','查询条件 " + lst[i].ToString().Replace(":", "") + " 不允许为空。');</script>");
    return;
    }
    //return;
    }
    }

    if (rpa.Count > 0 && lst.Count <= 0)
    {
    rvp.ServerReport.SetParameters(rpa);
    }
    }
    rvp.ServerReport.Refresh();
    }

    private static void SetParameter(List<ControlValue> _listValue, int i, ref Microsoft.Reporting.WebForms.ReportParameter r)
    {
    if (_listValue[i].Name.Contains(','))
    {
    string[] pa = _listValue[i].Name.Split(',');
    for (int k = 0; k < pa.Length; k++)
    {
    pa[k] = pa[k].Trim();
    }
    r.Values.AddRange(pa);
    }
    else
    {
    r.Values.Add(_listValue[i].Name);
    }
    }

    }
    }

    好了,现在一个报表功能就可以实现了。





  • 相关阅读:
    JMeter学习使用(1)
    ip设置
    JMeter安装过程小问题
    appium-doctor
    使用 Xcode-Instrument-Automation -App -Ios自动化测试
    接口测试学习 -01
    在Windows下安装配置jforum测试环境
    root_one Android自动化测试02--git拉取及eclipse导入
    selenium+python学习总结-mac
    MySQL速学篇第四课
  • 原文地址:https://www.cnblogs.com/jasonjiang/p/2302008.html
Copyright © 2011-2022 走看看