zoukankan      html  css  js  c++  java
  • 水晶报表动态后台绑定代码

    前台

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="dkjybgDY.aspx.cs" Inherits="MK_dkjybg_dkjybgDY" %>

    <%@ Register assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>

    <!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 id="Head1" runat="server">
    <title>无标题页</title>
    <style type="text/css">
    .style1
    {
    100%;
    }
    </style>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>

    <table class="style1">
    <tr>
    <td align="center">
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
    AutoDataBind="True" DisplayGroupTree="False"
    EnableDatabaseLogonPrompt="False" HasExportButton="False"
    HasToggleGroupTreeButton="False" />
    <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
    </CR:CrystalReportSource>
    </td>
    </tr>
    </table>

    </div>
    </form>
    </body>
    </html>

    后台

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    using System.Data;
    using System.Data.SqlClient;
    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;
    using System.Configuration;

    public partial class MK_dkjybg_dkjybgDY : System.Web.UI.Page
    {
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DH"].ConnectionString);
    DataSet ds = new DataSet();
    sqlconn g_conn = new sqlconn();

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Page_Init(object sender, EventArgs e)
    {
    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");
    System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("zh-CN");

    TableLogOnInfo info = new TableLogOnInfo();
    TableLogOnInfos infos = new TableLogOnInfos();
    ConnectionInfo conns = new ConnectionInfo();
    conns.ServerName = ConfigurationManager.AppSettings["ip"].ToString();//数据库ip
    conns.DatabaseName = ConfigurationManager.AppSettings["date"].ToString();//数据库名
    conns.UserID = ConfigurationManager.AppSettings["use"].ToString();//数据库sa
    conns.Password = ConfigurationManager.AppSettings["pass"].ToString();//数据库密码
    info.ConnectionInfo = conns;
    infos.Add(info);
    this.CrystalReportViewer1.LogOnInfo = infos;

    ReportDocument erp = new ReportDocument();
    erp.Load(Server.MapPath("Cdkjybg.rpt"));

    int NMId = int.Parse(Session["dkjybg"].ToString());
    DataTable dt = g_conn.GetDataSet("select dkjybg_id 内码,dkjybg_djbm 单据编码 from dkjybg where dkjybg_id=" + NMId + "").Tables[0];
    foreach (DataRow dr in dt.Rows)
    {
    TextObject txtdjbh = (TextObject)erp.ReportDefinition.ReportObjects["txtdjbh"];
    txtdjbh.Text = dr["单据编码"].ToString();
    }

    ds.Clear();
    string sql = string.Empty;

    sql += "select * from dkjybgmx where dkjybgmx_btid=" + NMId + " order by dkjybgmx_xh";

    SqlCommand com = new SqlCommand(sql, con);
    SqlDataAdapter sqlad = new SqlDataAdapter();
    sqlad.SelectCommand = com;
    sqlad.Fill(ds);


    erp.SetDataSource(ds.Tables[0]);


    CrystalReportSource1.DataBind();
    CrystalReportViewer1.ReportSource = erp;
    CrystalReportViewer1.DataBind();

    //直接打印
    //CrystalReportSource1.ReportDocument.PrintToPrinter(1, false, 0, 0);
    }
    }

  • 相关阅读:
    C语言源代码——计算任何一天是星期几
    计算任意一天是星期几
    wpf利用线程制作初始界面和关闭窗体特效
    实用的 集合工具类 和 String工具类
    从“关于Java堆与栈的思考”一帖看错误信息的传播
    web.xml 配置中classpath: 与classpath*:的区别
    git的安装-环境变量配置
    解决Oracle安装时报错“SID已在使用”办法
    ORACLE日期时间函数
    Java 开发环境配置
  • 原文地址:https://www.cnblogs.com/txws1119/p/6004107.html
Copyright © 2011-2022 走看看