Crystal 在运行时打印时报告为空(无查看器)

Crystal Reports empty when printed during runtime(without viewer)

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

但我的问题出现在账单打印过程中。 Bill 没有从销售 table 中提取必要的记录。以下是我的结束交易代码。 (我使用了一些我自己的方法和函数,它们来自另一个 class 并且我还使用了一个 fix bill no 来测试)

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

   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

我发现报告需要在打印前刷新。报告只会在刷新时获取数据。

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