【问题标题】:Printing SSRS report to label printer x times将 SSRS 报告打印到标签打印机 x 次
【发布时间】:2017-09-27 17:39:09
【问题描述】:

如果这是一个重复的问题,我很抱歉,如果是,请指出答案。

这是我的情况:

我有一个使用 SQL Server 数据库作为其数据源的 ASP.NET Web 表单站点。最终用户想要将标签打印到 Zebra 标签打印机。 (旧打印机 Zebra 110XiIIIPlus-200dpi)我可以将这台打印机安装在最终用户系统上,也可以从 Web 服务器运行,不管它是网络打印机。

我可以从数据库中检索数据了。当我需要打印时,我的问题就开始了。假设我有四个部分,p1 p2 p3 和 p4。所有标签的格式相同:

Job #、Mark #、Customer、Width(in)、Length(in)(均来自 SQL DB)

在查询中提取但未打印的唯一字段是数量。标记# 是零件编号(不知道为什么它不只是称为零件#)。现在假设 p1 的数量为 12,p2 的数量为 25,p3 的数量为 321,p4 的数量为 35。

打印时,我需要为 p1 发送 12 个“副本”标签,为 p2 发送 25 个“副本”,为 p3 发送 321 个“副本”,为 p4 发送 35 个“副本”。

如何发送 12 个标签供 p1 打印,然后使用下一条记录的数据并发送 24 个标签等?

我还没有任何打印代码,因为我不知道该怎么做!!有谁知道我可以做到的方法。

我确实在这里找到了一篇关于 SO:Print a report Multiple times, (SSRS reporting services) 的文章,但我不知道如何使它工作,如果它甚至可以的话)我需要什么。

最后一点我在后面的代码中使用 VB.Net,如果它有所作为的话。

非常感谢任何帮助!

【问题讨论】:

    标签: asp.net vb.net ssrs-2008-r2


    【解决方案1】:

    我必须做完全相同的事情,我想出的解决方案是循环选择并按数量中的项目数联合相同的选择。通过这样做,您应该为 P1 获得 12 行,因为那是框的数量,所有数据都应该相同,除了 Page# 应该自动增加 1 直到数量结束。

    结果会是这样的:

    Job# | Mark# | Quantity | Page
    ------------------------------
    1    |  P1   |   12     |   1
    1    |  P1   |   12     |   2
    1    |  P1   |   12     |   3
    1    |  P1   |   12     |   4
    .....
    1    |  P1   |   12     |   12
    

    然后您将在 Mark# 和 Page 上进行分组,并在组的每个实例之间创建一个分页符,这样您就可以根据数量获得页数。

    【讨论】:

    • 你在SQ​​L语句中使用了while循环吗?
    • 是的,我这样做的方法是使用动态 sql 添加相同查询乘以产品数量的联合,因此如果项目有 12 个项目,您将执行主要查询和然后循环添加 11 个并集,得到 12 行。然后添加页码列。
    • 可以给我看代码吗?我只是没有得到。我明白你在做什么我似乎无法工作。
    【解决方案2】:

    感谢 SO 用户 newGuy 的帮助,我能够弄清楚如何做到这一点。这是我想出的可行的解决方案。

        --Drop Temp tables if exists
    If OBJECT_ID('tempdb..#Labels') Is Not Null Drop Table #Labels
    If OBJECT_ID('tempdb..#Pieces') Is Not Null Drop Table #Pieces
    
    --Declare variables
    Declare @MarkNumber varchar(10)
    Declare @Qty int
    Declare @RowCount int = 0
    
    Create Table #Labels
    (
        vjobnum varchar(12),
        marknumber varchar(25),
        customer varchar(25),
        pwidth decimal(18,4),
        plength decimal(18,4)
    )
    Create Table #Pieces
    (
        marknum varchar(25),
        totqty int,
        customer varchar(50),
        jobnum varchar(12),
        plength decimal(18,4),
        pwidth decimal(18,4)
    )
    
    Insert Into #Pieces(marknum, totqty, customer, jobnum, plength, pwidth)
    Select od.marknum, od.qty, oh.customer, oh.van_job_num, od.bbin, od.cbin From tbl_order_detail od Join tbl_order_head oh On oh.ordernum = od.ordernum Where od.ordernum = (Select Distinct ordernum From tbl_BearingBarRpt)
    
    Set @RowCount = (Select COUNT(*) From #Pieces)
    While @RowCount > 0 --Exists (Select marknum From #piecelabels)
    Begin
        Select @MarkNumber = (Select a.marknum From (Select ROW_NUMBER() OVER (Order By marknum) as RowNumbers, *From #Pieces) a Where a.RowNumbers = @RowCount)
        Select @Qty = (Select totqty From #Pieces Where marknum = @MarkNumber)
        While @Qty > 0
            Begin
                Insert Into #Labels(vjobnum, marknumber, customer, pwidth, plength)
                Select pc.jobnum, pc.marknum, pc.customer, pwidth, plength
                From #Pieces pc
                Where pc.marknum = @MarkNumber
    
                --Decrement the Qty counter
                Set @Qty = @Qty - 1
    
            End
    
        Set @RowCount = @RowCount - 1
    End
    

    它可能不是最好的,但它绝对有效!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多