1:
创建数据源文件 UoOrderDS.xsd
只在数据源中添加相应的列,不添加查询语句,在程序中添加
为了方便条件查询,所以在程序中添加
2:
添加报表文件 prtUpOrder.rdlc
然后给报表文件指定数据集 就是上面的xsd文件
3:也可给报表中的table添加参数
3:
创建.aspx文件
在页面中添加ReportViewer 报表空间(添加前要引用using Microsoft.Reporting.WebForms;命名空间)
然后添加ScriptManager控件 否则可能会报错
前台添加打印和打印预览按钮,并添加click事件
<input type="button" value="打印预览" οnclick="Preview()" class="button" />
<input type="button" value="打 印 " οnclick="Print()" class="button" /></div>
<script language="javascript">
function Preview() {
if (document.all.eprint.defaultPrinterName.length == 0) {
alert("请先安装打印机,再执行此功能!");
return;
}
document.all.eprint.InitPrint();
document.all.eprint.paperSize = "erp";
document.all.eprint.setMarginMeasure(1); //毫米mm
document.all.eprint.orientation = 2; //1为纵向,2为横向
document.all.eprint.marginTop=5;
document.all.eprint.marginLeft=5;
document.all.eprint.marginRight=5;
document.all.eprint.marginBottom=5;
document.all.eprint.Preview();
}
function Print() {
if (document.all.eprint.defaultPrinterName.length == 0) {
alert("请先安装打印机,再执行此功能!");
return;
}
document.all.eprint.InitPrint();
document.all.eprint.paperSize = "erp";
document.all.eprint.setMarginMeasure(1); //毫米mm
document.all.eprint.orientation = 2; //1为纵向,2为横向
document.all.eprint.marginTop=5;
document.all.eprint.marginLeft=5;
document.all.eprint.marginRight=5;
document.all.eprint.marginBottom=5;
document.all.eprint.Print(true); //不弹出打印对话框直接打印
//打印记录
var OrderId=<%=Request.QueryString["OrderId"] %>;
var State=<%=Request.QueryString["state"] %>;
var Year=<%=Request.QueryString["year"] %>;
var Month=<%=Request.QueryString["month"] %>;
var DepartId=<%=departid %>;
var UserId=<%=userid %>;
var PrintSerialNo='<%=ViewState["OrderPrintSerialNo"] %>';
$.ajax({
async: false,
url: "../../Order/AddUserDownLog.ashx",
data: { orderid: OrderId,state:State,departid:DepartId,userid:UserId,year:Year,month:Month,printserialno:PrintSerialNo,rom: Math.random() },
success: function (data, textStatus) {Ret=data;}
})
}
</Script>
<script language="javascript">
function Preview() {
if (document.all.eprint.defaultPrinterName.length == 0) {
alert("请先安装打印机,再执行此功能!");
return;
}
document.all.eprint.InitPrint();
document.all.eprint.paperSize = "erp";
document.all.eprint.setMarginMeasure(1); //毫米mm
document.all.eprint.orientation = 2; //1为纵向,2为横向
document.all.eprint.marginTop=5;
document.all.eprint.marginLeft=5;
document.all.eprint.marginRight=5;
document.all.eprint.marginBottom=5;
document.all.eprint.Preview();
}
function Print() {
if (document.all.eprint.defaultPrinterName.length == 0) {
alert("请先安装打印机,再执行此功能!");
return;
}
document.all.eprint.InitPrint();
document.all.eprint.paperSize = "erp";
document.all.eprint.setMarginMeasure(1); //毫米mm
document.all.eprint.orientation = 2; //1为纵向,2为横向
document.all.eprint.marginTop=5;
document.all.eprint.marginLeft=5;
document.all.eprint.marginRight=5;
document.all.eprint.marginBottom=5;
document.all.eprint.Print(true); //不弹出打印对话框直接打印
//打印记录
var OrderId=<%=Request.QueryString["OrderId"] %>;
var State=<%=Request.QueryString["state"] %>;
var Year=<%=Request.QueryString["year"] %>;
var Month=<%=Request.QueryString["month"] %>;
var DepartId=<%=departid %>;
var UserId=<%=userid %>;
var PrintSerialNo='<%=ViewState["OrderPrintSerialNo"] %>';
$.ajax({
async: false,
url: "../../Order/AddUserDownLog.ashx",
data: { orderid: OrderId,state:State,departid:DepartId,userid:UserId,year:Year,month:Month,printserialno:PrintSerialNo,rom: Math.random() },
success: function (data, textStatus) {Ret=data;}
})
}
</Script>
然后添加后台代码,在后台的Load事件里完成数据的绑定添加然后添加后台代码,在后台的Load事件里完成数据的绑定添加然后添加后台代码,在后台的Load事件里完成数据的绑定添加然后添加后台代码,在后台的Load事件里完成数据的绑定添加
然后添加后台代码,在后台的Load事件里完成数据的绑定添加
BLL.Report.Report Bll = new BLL.Report.Report(); //实例化BLL对象,用来操作查询数据的方法
ERP.BLL.Org.UserDownLogs Option = new ERP.BLL.Org.UserDownLogs(); //添加日志要用到的类
ReportDataSource rds = new ReportDataSource("UpOrderDS"); //创建数据源对象,并指定数据源名称UpOrderDS,就是刚刚创建的.xsd文件
DataTable dt;
object[] par; //存储过程要用到的查询条件数组
string State;
int OrderId;
protected string departid;
protected string userid;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.Params["year"] != null && Request.Params["month"] != null && Request.Params["OrderId"] != null && Request.Params["state"] != null)
{
departid = DepartId.ToString();
userid = UserId.ToString();
Bindrpt();
}
}
}
void Bindrpt() //绑定数据方法
{
string Year = Request.Params["year"]; //往数组中添加条件
string Month = Request.Params["month"];
OrderId = int.Parse(Request.Params["OrderId"]);
State = Request.Params["state"];
par = new object[]
{
null,
Year,
Month,
OrderId
};
#region 初始化报表
//给ReportViewer指定报表文件
rptViewer.LocalReport.ReportPath = Server.MapPath("~/Report/rpt/rptUpOrder.rdlc");
//数据源
rds.Value = Bll.rptUpOrder(par);
rptViewer.LocalReport.DataSources.Clear();
//给控件添加数据源
rptViewer.LocalReport.DataSources.Add(rds);
//设置参数,报表文件要用到的参数
string strState = Request.Params["state"];
rptViewer.LocalReport.SetParameters(new ReportParameter("strState", strState));
string SerialNo = Bll.GetPrintOrderCode(strState, DepartId);
if (departid.IndexOf("*") == -1)
{
SerialNo = "";
}
ViewState["OrderPrintSerialNo"] = SerialNo;
rptViewer.LocalReport.SetParameters(new ReportParameter("SerialNo", SerialNo));
//子报表
rptViewer.LocalReport.ShowDetailedSubreportMessages = false;
//子报表
rptViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SubRptBindEventHandler);
//外部图片是否可见
rptViewer.LocalReport.EnableExternalImages = true;
rptViewer.LocalReport.Refresh();
#endregion
}