Im now having issues with writing the code that takes the calculations from my txt boxes and inserts them as a new row in my access database.
I used the Visual Studio 2005 Wizard to create my DB connections, so im struggling to work it all out.
Here is the code for my form:
Expand|Select|Wrap|Line Numbers
- Public Class frmCalculator
- Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
- 'ends application
- Me.Close()
- End Sub
- Private Sub TblPurchaseBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Me.Validate()
- Me.TblPurchaseBindingSource.EndEdit()
- Me.TblPurchaseTableAdapter.Update(Me.DsLeopard.tblPurchase)
- End Sub
- Private Sub frmCalculator_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
- 'have the user confirm that they want to exitt he application
- e.Cancel = (MessageBox.Show("Are you sure you want to exit?", "Closing Application", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No)
- End Sub
- Private Sub frmCalculator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- 'fills the dataset for the tblProducts with Data
- Me.TblProductsTableAdapter.Fill(Me.DsLeopard.tblProducts)
- 'fills the dataset for the tblPurchase with data
- Me.TblPurchaseTableAdapter.Fill(Me.DsLeopard.tblPurchase)
- lblProductIDCombo.Visible = False
- cmbProductID.Visible = False
- End Sub
- Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
- 'calls the PrintForm method
- PrintForm()
- End Sub
- Public Sub PrintForm()
- ' Takes a screenshot, then initiates the print
- GrabScreen()
- myPrintDialog.Document = myPrintDocument
- If myPrintDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
- myPrintDocument.Print()
- End If
- End Sub
- ' API call to help generate final screenshot
- Private Declare Auto Function BitBlt Lib "gdi32.dll" (ByVal _
- hdcDest As IntPtr, ByVal _
- nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth _
- As Integer, ByVal nHeight _
- As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc _
- As Integer, _
- ByVal nYSrc As Integer, ByVal dwRop As System.Int32) _
- As Boolean
- ' Variable to store screenshot
- Private bmpScreenshot As Bitmap
- Private Sub GrabScreen()
- ' Performs a screenshot, saving results to bmpScreenshot
- Dim objGraphics As Graphics = Me.CreateGraphics
- Dim objSize As Size = Me.Size
- Const SRCCOPY As Integer = &HCC0020
- bmpScreenshot = New Bitmap(objSize.Width, objSize.Height, _
- objGraphics)
- Dim objGraphics2 As Graphics = _
- Graphics.FromImage(bmpScreenshot)
- Dim deviceContext1 As IntPtr = objGraphics.GetHdc
- Dim deviceContext2 As IntPtr = objGraphics2.GetHdc
- BitBlt(deviceContext2, 0, 0, Me.ClientRectangle.Width, _
- Me.ClientRectangle.Height, deviceContext1, 0, 0, SRCCOPY)
- objGraphics.ReleaseHdc(deviceContext1)
- objGraphics2.ReleaseHdc(deviceContext2)
- End Sub
- Private Sub myPrintDocument_PrintPage(ByVal sender _
- As System.Object, _
- ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
- Handles myPrintDocument.PrintPage
- ' Method that handles the printing
- Dim objImageToPrint As Graphics = e.Graphics
- objImageToPrint.DrawImage(bmpScreenshot, 0, 0)
- bmpScreenshot.Dispose()
- objImageToPrint.Dispose()
- e.HasMorePages = False
- End Sub
- Private Sub Compute()
- 'This Sub Procedure calculates the Shipping, tax and Total Cost
- prodPrice = txtProdPrice.Text
- prodQuantity = txtOrderQuant.Text
- 'Total price of items, minus tax and shipping
- totalPrice = prodPrice * prodQuantity
- 'Calculates the shipping cost
- shipCost = totalPrice * 0.1
- 'Displays Shipping cost in text box
- txtShipCost.Text = shipCost.ToString("C2")
- 'Calculates the tax
- salesTax = totalPrice * 0.05
- 'displays Tax in text box
- txtTax.Text = salesTax.ToString("C2")
- 'Calculates total cost of purchase including Tax and shipping
- totalCost = totalPrice + shipCost + salesTax
- 'Displays total cost in text box
- txtTotalCost.Text = totalCost.ToString("C2")
- End Sub
- Private Sub ComputeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComputeToolStripMenuItem.Click
- 'When the compute button is selected the cost calculation is made
- Call Compute()
- End Sub
- Private Sub CalculateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateToolStripMenuItem.Click
- 'Ensures that the clear button is not available unless a value is in the appropriate text boxes
- If txtOrderQuant.Text = Nothing Then
- menuItemClear.Enabled = False
- Else : menuItemClear.Enabled = True
- End If
- If txtShipCost.Text = Nothing Then
- menuItemClear.Enabled = False
- Else : menuItemClear.Enabled = True
- End If
- If txtTax.Text = Nothing Then
- menuItemClear.Enabled = False
- Else : menuItemClear.Enabled = True
- End If
- If txtTotalCost.Text = Nothing Then
- menuItemClear.Enabled = False
- Else : menuItemClear.Enabled = True
- End If
- End Sub
- Private Sub TextClear()
- 'Clears all of the text boxes used in calculating cost
- txtOrderQuant.Text = Nothing
- txtShipCost.Text = Nothing
- txtTax.Text = Nothing
- txtTotalCost.Text = Nothing
- End Sub
- Private Sub menuItemClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuItemClear.Click
- 'When the clear button is selected the calculation boxes are cleared
- Call TextClear()
- End Sub
- Private Sub ByProductIDToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ByProductIDToolStripMenuItem.Click
- 'hides the product description label and combo box when this option is selected
- lblProductIDCombo.Visible = True
- lblPurchProdDesc.Visible = False
- cmbProductID.Visible = True
- cmbProdDesc.Visible = False
- End Sub
- Private Sub ByProductDescriptionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ByProductDescriptionToolStripMenuItem.Click
- 'hides the Product ID combo box and label when this button is selected.
- lblProductIDCombo.Visible = False
- lblPurchProdDesc.Visible = True
- cmbProductID.Visible = False
- cmbProdDesc.Visible = True
- End Sub
- Private Sub RecordsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RecordsToolStripMenuItem.Click
- 'ensure that the accept order button is disabled unless there has been a calculation made.
- If txtTotalCost.Text = Nothing Then
- MenuItemAccept.Enabled = False
- Else
- MenuItemAccept.Enabled = True
- End If
- End Sub
- Private Sub MenuItemAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemAccept.Click
- End Sub
- End Class
Thanks