mercredi 17 septembre 2014

i want to get a data base table to a pdf file for reporting


Vote count:

0




I want to make a report of a data base table and send it to a pdf file. such as I add data to a DB table and take that data and send it to a table or grid make a pdf.


here is my code thus far:



Public Function selectOrders(ByVal order_Date As Date) As SqlCommand
Dim cmd As New SqlCommand
cmd.CommandText = String.Format("Select * from dbo.Order where orderDate = '{0}'", order_Date)
Return cmd
End Function


Public Function selectAllorders() As SqlCommand
Dim cmd As New SqlCommand
cmd.CommandText = String.Format("Select orderID ""Order ID"", orderDate as ""Date"", orderPizzaTotals as ""Pizza Totals"", orderDrinkTotals as ""Drink Totals"", orderPriceTotal as ""Total Sells"" from dbo.Order where orderDate = 'Date'")
Return cmd
End Function

Public Function deleteOrders(ByVal id As String) As Boolean
Dim cmd As New SqlCommand
cmd.CommandText = String.Format("DELETE FROM dbo.Order WHERE orderID='{0}';", id)
cmd.Connection = con
If cmd.Connection.State = ConnectionState.Closed Then cmd.Connection.Open()
Dim results = cmd.ExecuteNonQuery()
If results > 0 Then
Return True
Else
Return False
End If
End Function

Public Function addOrder(ByVal orderID As Integer, ByVal orderDate As Date, ByVal orderPizzaTotals As Integer, ByVal orderDrinkTotals As Integer, ByVal orderPriceTotal As Decimal) As Boolean
Dim cmd As New SqlCommand
cmd.CommandText = String.Format("INSERT INTO dbo.Order (orderID, orderDate, orderPizzaTotals, orderDrinkTotals, orderPriceTotal) VALUES ('{0}','{1}','{2}','{3}','{4}');", orderID, orderDate, orderPizzaTotals, orderDrinkTotals, orderPriceTotal)
cmd.Connection = con
If cmd.Connection.State = ConnectionState.Closed Then cmd.Connection.Open()
Dim results = cmd.ExecuteNonQuery()
If results > 0 Then
Return True
Else
Return False
End If
End Function


Private Sub btnReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.Click validateTextBoxes() Dim results = DataConnection.selectAllorders cleanTextBoxes() Try Dim pdfDoc As New Document() Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream ("C:\PizzaEmporium\Reports\Report.pdf", FileMode.Create))



Dim table As New PdfPTable(5)

'relative col widths in proportions - 1/3 and 2/3
Dim widths As Single() = New Single() {1.0F, 2.0F}
table.SetWidths(widths)
table.HorizontalAlignment = 0
table.SpacingBefore = 20.0F
table.SpacingAfter = 30.0F

Dim cell As New PdfPCell(New Phrase("Products"))
cell.Colspan = 5
cell.Border = 0
cell.HorizontalAlignment = 0
'0=left, 1=center, 2=right
table.AddCell(cell)

Try
pdfDoc.Open()
Using rdr As SqlDataReader = results.ExecuteReader()
While rdr.Read()
table.AddCell(rdr(0).ToString())
table.AddCell(rdr(1).ToString())
table.AddCell(rdr(2).ToString())
table.AddCell(rdr(3).ToString())
table.AddCell(rdr(4).ToString())

End While
End Using

Catch ex As Exception
Write(ex.Message)
End Try

pdfDoc.Add(table)
pdfDoc.Close()

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub


Private Sub btnTotalOrder_Click(sender As Object, e As EventArgs) Handles btnTotalOrder.Click



Dim runningPriceTotal As Decimal = 0
Dim taxRate As Decimal = 0.07
Dim tax As Decimal = 0.0
Dim total As Decimal = 0.0
Dim totalPizzas As Integer = 0
Dim totalDrinks As Integer = 0
Dim orderHasTotal As Boolean

orderHasTotal = True
lstOrder.Items.Add("")
Dim orderTotal = String.Join(" - ", "Total Pizzas: " & totalPizzas, "Total Drinks: " & totalDrinks)
lstOrder.Items.Add(orderTotal)
' "Total Price: " & "$" & runningPriceTotal

calculateTax()


End Sub


This is what I have so far I am stuck this is what happens, you make an order, then once you are finished you click total order button in the btnTotalOrder_click then adds the order to the DB table and then from the DB table orders a pdf is made from the data of the orders table. Sorry im only a 2nd year programming student so I apologize so slopy code and the examples that I was using were from c# and I have only done vb stuff



asked 58 secs ago







i want to get a data base table to a pdf file for reporting

Aucun commentaire:

Enregistrer un commentaire