在运行时打印时,Crystal Reports为空(没有查看器) [英] Crystal Reports empty when printed during runtime(without viewer)

查看:70
本文介绍了在运行时打印时,Crystal Reports为空(没有查看器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VB.Net,MS Sql和Crystal Reports开发一个小型POS系统.我可以使用Cry Rep Viewer轻松查看报告.但是,当我尝试在运行时打印帐单时,报告将为空.以下是我在该过程中执行的顺序.

I'm developing a small POS system using VB.Net , MS Sql and Crystal Reports. I have no trouble viewing reports using Cry Rep Viewer. But when i try to print a bill during runtime the report becomes empty. Following is the sequence i'm executing within the procedure.

  • 生成帐单编号
  • 从库存中扣除数量
  • 将交易从临时表添加到最终销售表
  • 打印账单
  • 删除临时表事务
  • 清除下一笔交易

但是我的问题出在票据打印过程中.Bill不会从销售表中提取必要的记录.以下是我的最终交易代码.(我正在使用自己的一些方法和函数,这些方法和函数是来自另一个类的,并且我还使用了不用于测试的修订帐单)

But my problem comes during the bill printing. Bill does not pickup the necessary records from the sales table. Following is my code for the end transaction. (I am using few of my own methods and functions which are from another class and im also using a fix bill no for testing)

我还要附上2张帐单.前1个是从Cry Report Viewer中查看和导出的一个.第二个是有问题的,即使表中存在记录,它也为空.有人可以在这件事上给我建议吗?

I'm also attaching 2 bills. First 1 is the one viewed and exported from the Cry Report Viewer. The second one is the one with problem, and its empty even though the records exists in the table. Can some one kindly advice me on this matter?

   Private Sub endCurrentTransaction()
    Try
        Dim sqlTempBill As String = "SELECT * FROM tb_transactions where cur_user='" & curUser & "'"
        Dim sqlSales As String = "SELECT * FROM tb_sales where bill_no=''"

        'Get Bill No
        Dim newBillNo As String = generateBillNo()

        'Deduct IT qty
        Dim tempBill As DataTable
        tempBill = myTbClass.myFunctionFetchTbData(sqlTempBill)

        Dim i As Integer = 0
        Dim curQty As Double = 0
        Dim trQty As Double = 0
        Dim updatedQty As Double = 0

        For i = 0 To tempBill.Rows.Count - 1
            curQty = 0
            'Get the Current stock qty
            Dim sqlgetCurQty As String = "SElECT cur_qty FROM tb_stock where it_batch_code='" & tempBill.Rows(i).Item("it_batch_code") & "'"

            conn.Open()
            Dim SqlCmdCurQty As New SqlCommand(sqlgetCurQty, conn)
            Dim DataReadercurQty As SqlDataReader = SqlCmdCurQty.ExecuteReader
            While DataReadercurQty.Read()
                curQty = DataReadercurQty.Item(0)
            End While
            DataReadercurQty.Close()
            conn.Close()

            trQty = tempBill.Rows(i).Item("qty")
            updatedQty = curQty - trQty
            Dim sqlUpdateQtyString As String = "UPDATE tb_stock SET cur_qty=" & Math.Round((updatedQty), 3) & " Where it_batch_code='" & tempBill.Rows(i).Item("it_batch_code") & "'"
            conn.Open()
            Dim SqlCmdQty As New SqlCommand(sqlUpdateQtyString, conn)
            SqlCmdQty.ExecuteNonQuery()
            conn.Close()

            'add to sales
            Dim tempTbSales As DataTable
            tempTbSales = myTbClass.myFunctionFetchTbData(sqlSales)
            Dim dataRow As DataRow = tempTbSales.NewRow
            dataRow("it_code") = Trim(tempBill.Rows(i).Item("it_code"))
            dataRow("it_batch_code") = Trim(tempBill.Rows(i).Item("it_batch_code"))
            dataRow("it_name") = Trim(tempBill.Rows(i).Item("it_name"))
            dataRow("buy_price") = Math.Round(tempBill.Rows(i).Item("buy_price"), 3)
            dataRow("sell_price") = Math.Round(tempBill.Rows(i).Item("sell_price"), 3)
            dataRow("qty") = Math.Round(tempBill.Rows(i).Item("qty"), 3)
            dataRow("gross_val") = Math.Round(tempBill.Rows(i).Item("gross_val"), 3)
            dataRow("discount_val") = Math.Round(tempBill.Rows(i).Item("discount_val"), 3)
            dataRow("net_val") = Math.Round(tempBill.Rows(i).Item("net_val"), 3)
            dataRow("profit_profile") = Trim(tempBill.Rows(i).Item("profit_profile"))
            dataRow("discount_profile") = Trim(tempBill.Rows(i).Item("discount_profile"))
            dataRow("cus_name") = Trim(tempBill.Rows(i).Item("cus_name"))
            dataRow("tr_type") = Trim(cmbTrans.Text)
            dataRow("cr_card_type") = Trim(cmbCardType.Text)
            dataRow("card_no") = Trim(txtCardNo.Text)
            dataRow("bill_no") = newBillNo
            dataRow("discount_profile") = Trim(tempBill.Rows(i).Item("cus_name"))
            dataRow("cur_user") = curUser
            dataRow("added_date") = curServerDateTime
            tempTbSales.Rows.Add(dataRow)
            Call myTbClass.MyMethodUpdateTable(sqlSales, tempTbSales)
        Next

        i = 0

    'Print bill
    Dim cash, balance As Double
    Dim crepBill As New repBill
    crepBill.SetDatabaseLogon("sa", dbPwd)
    cash = Val(Me.txtCash.Text)
    balance = Val(Me.txtBalance.Text)

    crepBill.RecordSelectionFormula = "{TB_SALES.bill_no} ='" & "000015" & "'"
    crepBill.DataDefinition.FormulaFields("txtCash").Text = Format(cash, "#0.00")
    crepBill.DataDefinition.FormulaFields("txtBal").Text = Format(balance, "#0.00")

    crepBill.PrintToPrinter(1, False, 0, 0)
    crepBill.Dispose()

    'delete temp bill table
    For i = 0 To tempBill.Rows.Count - 1
        tempBill.Rows(i).Delete()
    Next
    Call myTbClass.MyMethodUpdateTable(sqlTempBill, tempBill)

    'reset front end
    Call loadBill()
    Call clearCurrentTransaction()
    Call clearCurrentSubTotals()
    Call clearCurCashBalance()

    'Íncrease the bill no by 1
    Call increaseBillNo()

    txtItCode.Focus()
    Catch ex As Exception
    MsgBox("This error was generated at endCurrentTransaction()")
    End Try
End Sub

推荐答案

我发现打印之前需要刷新报告.报表只有在刷新后才能获取数据.

I found out that report need to be refreshed before printing. Report will only take data if it is refreshed.

https://answers.sap.com/answers/13088178/view.html

这篇关于在运行时打印时,Crystal Reports为空(没有查看器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆