zoukankan      html  css  js  c++  java
  • 一个票据打印实例

    效果图:

    技术实现:

    前台:

    <%@ 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 id="form1" runat="server">
        <div>
            <asp:GridView ID="DaYGridView" runat="server" AutoGenerateColumns="False"
                onrowdatabound="DaYGridView_RowDataBound" BorderWidth="0" PageSize="1" BorderStyle="None" RowStyle-BorderStyle="None"  ShowHeader="False" GridLines="None" Width="100%">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                           <table>
                           <tr>
                           <td></td>
                           </tr>
                           </table>
                        <table align="center" width="100%" cellpadding="0" cellspacing="0" border="0">
                        <tr align="center">
                        <td>
                            <asp:Image ID="Image1" runat="server" ImageUrl="~/images/1.gif" Height="60px" Width="100px" />
                            </td>
                        <td colspan="2" align="center"><asp:Label ID="TitleLabel" runat="server"
                                Font-Size="18px" Text="中国外运江苏集团公司南通公司郭里头仓库" Font-Bold="True"/>
                        <br/><center><asp:Label ID="Label1" runat="server" Font-Size="18px" Text="商品入库单"
                                Font-Bold="True"/></center>
                        </td>
                     
                        <td></td>
                        </tr>
                        <tr>
                        <td width="25%">货主名称<asp:TextBox ID="HuoZTextBox" SkinID="hengx" Width="160" runat="server" Text='<%#Bind("HuoZ") %>'></asp:TextBox></td>
                        <td width="25%">单  号<asp:TextBox ID="DanJHMTextBox" SkinID="hengx" Width="160" runat="server" Text='<%#Bind("DanJH") %>'></asp:TextBox></td>
                        <td width="25%">制单日期<asp:TextBox ID="ZhiDRQTextBox" Width="160" SkinID="hengx" runat="server" Text='<%#Bind("ZhiDRQ") %>'></asp:TextBox></td>
                        <td width="25%"></td>
                        </tr>
                        <tr>
                        <td >提货仓库<asp:TextBox ID="CangKMCTextBox" runat="server" Width="160" SkinID="hengx" Text='<%#Bind("CangKMC") %>'/></td>
                        <td >送货性质<asp:TextBox ID="SongHXZTextBox" runat="server" Width="160" SkinID="hengx" Text='<%#Bind("SongHXZ") %>'/></td>
                        <td >车  号<asp:TextBox ID="CheHTextBox" Width="160" SkinID="hengx" runat="server"></asp:TextBox></td>
                        <td></td>
                        </tr>
                        <tr>
                          <td >封  号<asp:TextBox ID="HuoHTextBox" Width="160" SkinID="hengx" runat="server"></asp:TextBox></td> 
                            <td>交货单号<asp:TextBox ID="JiaoHDHTextBox" Width="160" SkinID="hengx" runat="server" Text='<%#Bind("JiaoHDH") %>'/></td>
                            <td colspan="2"></td>
                        </tr>
                        <tr>
                        <td colspan="4" align="center">
                        <asp:GridView ID="MingXGridView" runat="server" AutoGenerateColumns="False">
                                <Columns>
                                    <asp:BoundField HeaderText="NO" FooterText="备注">
                                        <ItemStyle HorizontalAlign="Center" />
                                    </asp:BoundField>
                                    <asp:BoundField HeaderText="商品名称">
                                        <ItemStyle HorizontalAlign="Left" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="PinMXH" HeaderText="型号">
                                        <ItemStyle HorizontalAlign="Left" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="GuiG" HeaderText="规格" />
                                    <asp:BoundField HeaderText="单位" FooterText="合计" />
                                    <asp:BoundField DataField="ShuL" HeaderText="数量" />
                                    <asp:BoundField HeaderText="实收数" />
                                    <asp:BoundField DataField="BeiZ" HeaderText="备注" />
                                </Columns>
                            </asp:GridView>
                        </td>
                      
                        </tr>
                        <tr>
                        <td ><asp:Label ID="BeiZLabel" runat="server"  Text="备 注" Visible="false"/><asp:TextBox ID="BeiZTextBox" SkinID="hengx" runat="server" Text='<%#Bind("BeiZ") %>' Visible="false" /></td>
                        <td><asp:Label ID="HeJLabel" runat="server"  Text="合 计" Visible="false"/><asp:TextBox ID="HeJTextBox" SkinID="hengx" runat="server" Text='<%#Bind("ShuL") %>' Visible="false" /></td>
                        <td colspan="2"></td>
                        </tr>
                        <tr>
                        <td>制单人<asp:TextBox ID="ZhiDRTextBox" runat="server" SkinID="hengx" Text='<%#Bind("ZhiDR") %>'/></td>
                        <td>收货人<asp:TextBox ID="ShouHRTextBox" SkinID="hengx" runat="server"/></td>
                        <td>协作人<asp:TextBox ID="XieZRTextBox" SkinID="hengx" runat="server"/></td>
                        <td></td>
                        </tr>
                        <tr>
                        <td colspan="3">说明:1.本入库单自签发日起7天内有效:<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.白联财务留存联,绿联为提货回单联,蓝联为收货单位留存,黄联为运费结算联,红联为仓库留存联<br/></td>
                        <td align="right">打印人 <asp:TextBox ID="TextBox1" Width="110" runat="server" SkinID="hengx" Text='<%#Bind("DaYR") %>'/><br />打印时间<asp:TextBox ID="DaYSJTextBox" Width="110" SkinID="hengx" runat="server" Text='<%#Bind("DaYSJ") %>'></asp:TextBox>
                        <br/><asp:Label runat="server" ID="YeMLabel" />
                        </td>
                        </tr>
                        </table>
                       </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <PagerStyle CssClass="noprint" />
                <RowStyle BorderStyle="None" />
            </asp:GridView>
       
        </div>
        <p align="center" class="noprint">
        &nbsp;<asp:Button ID="DaYButton" runat="server" Text="打印" onclick="DaYButton_Click" />
        <asp:Button ID="GuanBButton" runat="server" onclientclick="javascript:window.close();"
            Text="关闭" /></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("&nbsp;", "").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>");
        }
    }

    注:此文章转载至白衣轩

  • 相关阅读:
    vue中常用的属性标签
    Vue 基本简介
    ES6 Map 和 WeakMap
    ES6 set/weakset
    ES6 generator生成器函数 async
    ES6 promise对象
    信息论-熵-随机变量-泛函
    机器学习一
    RS-232接口
    图的存储结构
  • 原文地址:https://www.cnblogs.com/hailexuexi/p/1903584.html
Copyright © 2011-2022 走看看