效果图:
技术实现:
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RuKD.aspx.cs" Inherits="HuoDGL_DaY_RuKD" %>
<!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>
<style>
@media print{
.noprint{
display:none
}
}
</style>
</head>
<body>
<form /></p>
</form>
</body>
</html>
后台:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Common;
using System.Collections.Generic;
public partial class HuoDGL_DaY_RuKD : System.Web.UI.Page
{
SqlGetDataBinder SqlGetDataBinder = new SqlGetDataBinder();
int PageRows = 0;
int PageCount = 0;
string BeiZ, ShuL;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["LiuSDH"] != null)
{
ViewState["LiuSDH"] = Request.QueryString["LiuSDH"];
ViewState["UserName"] = Request.QueryString["username"].Replace("td", "");
this.GetDataMessage();
}
}
}
//获取要绑定的报表数据
protected void GetDataMessage()
{
if (SqlGetDataBinder.GetDataHasRows("select DanH from ChuRKD where LiuSDH='" + ViewState["LiuSDH"].ToString() + "'"))
{
//获取数据总数
double count = Convert.ToDouble(SqlGetDataBinder.GetFirst("select count(*) from ChuLKDMXB where DanH='" + ViewState["LiuSDH"].ToString() + "'"));
PageCount = Convert.ToInt32(count);
count = count /8;
count = Math.Ceiling(count);
List<string> str = null;
str = SqlGetDataBinder.GetStrList("select ShangJHZXX.ShangJMC,DanH,ChuRKD.BeiZ,CangKMC,SongHXZ,RiQ,CaoZR,JiaoHDH from ChuRKD inner join ShangJHZXX on ShangJHZXX.ShangJBH=ChuRKD.HuoZBH where LiuSDH='" + ViewState["LiuSDH"].ToString() + "'");
ShuL=SqlGetDataBinder.GetFirst("select sum(ShuL) from ChuLKDMXB where DanH='" + ViewState["LiuSDH"].ToString() + "'").ToString();
DataTable table = new DataTable();
table.Columns.Add("HuoZ", typeof(string)); //货主
table.Columns.Add("ZhiDRQ", typeof(string)); //制单日期
table.Columns.Add("DanJH", typeof(string)); //单据号
table.Columns.Add("ZhiDR", typeof(string)); //制单人
table.Columns.Add("DaYSJ", typeof(string)); //打印时间
table.Columns.Add("Title", typeof(string)); //标题
table.Columns.Add("ShuL",typeof(string)); //数量
table.Columns.Add("BeiZ", typeof(string)); //备注
table.Columns.Add("CangKMC",typeof(string)); //仓库名称
table.Columns.Add("SongHXZ",typeof(string)); //送货性质
table.Columns.Add("DaYR",typeof(string)); //打印人
table.Columns.Add("JiaoHDH",typeof(string)); //交货单号
for (double n = 0; n <count; n++)
{
DataRow row = table.NewRow();
row[0] = str[0];
row[1] = Convert.ToDateTime(str[5]).ToShortDateString();
row[2] = str[1];
row[3] = str[6].ToString();
row[4] = DateTime.Now.ToString("g");
row["BeiZ"] = str[2];
row["ShuL"] = ShuL;
row["CangKMC"] = str[3];
row["SongHXZ"] = str[4];
row["DaYR"] = ViewState["UserName"].ToString();
row["JiaoHDH"] = str[7];
table.Rows.Add(row);
}
PageRows = table.Rows.Count;
this.DaYGridView.DataSource = table;
this.DaYGridView.DataBind();
//编号
int BianH=1;
for (int n = 0; n < this.DaYGridView.Rows.Count; n++)
{
GridView grid = (GridView)this.DaYGridView.Rows[n].FindControl("MingXGridView");
for (int p = 0; p < grid.Rows.Count; p++)
{
if (grid.Rows[p].Cells[2].Text.Replace(" ", "").Trim().Length > 0)
{
grid.Rows[p].Cells[1].Text = str[0];
}
grid.Rows[p].Cells[0].Text = BianH.ToString();
BianH++;
}
}
}
}
protected void DaYGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当前页码
int count2 = e.Row.RowIndex;
count2 = count2 *8;
//绑定明细信息
GridView grid = (GridView)e.Row.FindControl("MingXGridView");
if (e.Row.RowIndex == PageRows - 1)
{
grid.ShowFooter = true;
int p = PageCount % 8;
if (p == 0)
{
p =8;
}
DataTable table = new DataTable();
table.Columns.Add("PinMXH", typeof(string));
table.Columns.Add("GuiG", typeof(string));
table.Columns.Add("ShuL", typeof(string));
table.Columns.Add("BeiZ", typeof(string));
table.Columns.Add("XuH",typeof(int)); //序号
for (int n = 0; n < 8- p; n++)
{
DataRow row = table.NewRow();
row[0] = "";
row[1] = "";
row[2] = "";
row[3] = "";
row[4] = 10000000 + n;
table.Rows.Add(row);
}
table.Merge(SqlGetDataBinder.GetDataTable("select top 8 PinMXH,GuiG,cast(ShuL as varchar(10)) as ShuL,BeiZ,XuH from ChuLKDMXB where DanH='" + ViewState["LiuSDH"].ToString() + "' and PinMXH not in (select top " + count2 + " PinMXH from ChuLKDMXB where DanH='" + ViewState["LiuSDH"].ToString() + "' order by XuH asc) order by XuH asc"));
table.DefaultView.Sort = " XuH asc";
grid.DataSource = table;
grid.DataBind();
grid.FooterRow.Cells[1].ColumnSpan = 3;
grid.FooterRow.Cells[2].Visible = false;
grid.FooterRow.Cells[3].Visible = false;
grid.FooterRow.Cells[1].Text = BeiZ;
grid.FooterRow.Cells[5].Text = ShuL;
}
else
{
grid.DataSource = SqlGetDataBinder.GetDataTable("select top 8 PinMXH,GuiG,ShuL,BeiZ from ChuLKDMXB where DanH='" + ViewState["LiuSDH"].ToString() + "' and PinMXH not in (select top " + count2 + " PinMXH from ChuLKDMXB where DanH='" + ViewState["LiuSDH"].ToString() + "' order by XuH asc) order by XuH asc");
grid.DataBind();
}
//设置页码
int index = e.Row.RowIndex + 1;
((Label)e.Row.FindControl("YeMLabel")).Text = "第"+index.ToString()+"页,共"+PageRows+"页";
}
}
protected void DaYButton_Click(object sender, EventArgs e)
{
RegisterStartupScript("c", "<script>window.print();</script>");
}
}
注:此文章转载至白衣轩