Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.OleDb
- Public Class frmOrderProduct
- Dim iPadCasePrice As String
- Dim iPad2Price As String
- Dim prod_list As List(Of String)
- Dim Total As Decimal
- Dim EachItemTotalPrice As Decimal
- Dim Quantity As Integer
- Dim PriceEach As Decimal
- Private Sub frmOrderProduct_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Call connection()
- cmboxProduct.Items.Add("iPad Case")
- cmboxProduct.Items.Add("iPad 2")
- iPadCasePrice = "$20.00"
- iPad2Price = "$200.00"
- txtUsername.Text = frmLogin.txtUsername.Text
- End Sub
- Private Sub btnAddToCart_Click(sender As Object, e As EventArgs) Handles btnAddToCart.Click
- Dim PricePerLine As Decimal
- If cmboxProduct.SelectedItem = "" Or txtQuantity.Text = "" Then
- MsgBox("Please fill out all required fields", MsgBoxStyle.OkOnly, "Invalid entered data")
- Else
- PricePerLine = txtQuantity.Text * txtPriceEach.Text
- ListBoxCart.Items.Add("x" & txtQuantity.Text & " " & cmboxProduct.SelectedItem & " " & txtPriceEach.Text & " " & "$" & PricePerLine)
- Quantity = Decimal.Parse(txtQuantity.Text)
- PriceEach = Decimal.Parse(txtPriceEach.Text.Remove(0, 1)) 'need to remove the $ before parse
- Total += PriceEach * Quantity
- txtTotalPrice.Text = String.Format("${0}", Total)
- 'txtShoppingCart.AppendText("x" & txtQuantity.Text & " " & Product1 & Environment.NewLine)
- End If
- End Sub
- Private Sub txtQuantity_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles txtQuantity.KeyPress
- If Asc(e.KeyChar) <> 8 Then
- If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
- e.Handled = True
- End If
- End If
- End Sub
- Private Sub btnOrderProducts_Click(sender As Object, e As EventArgs) Handles btnOrderProducts.Click
- Dim numberOfItems = ListBoxCart.Items.Count
- For Each item As String In ListBoxCart.Items
- Try
- cm = New OleDbCommand
- With cm
- .Connection = cn
- .CommandType = CommandType.Text
- .CommandText = "INSERT INTO tblOrders ([ProductName],[Quantity],[PriceEach],[OrderTotalPrice],[PricePerLine],[Username]) VALUES (@ProductName,@Quantity,@PriceEach,@TotalPrice,@Username)"
- prod_list = item.Split(" ").ToList
- Dim prod_name = prod_list.ElementAt(1)
- Dim prod_quantity = Integer.Parse(prod_list.ElementAt(0).Remove(0, 1))
- Dim price_each = prod_list.ElementAt(prod_list.Count - 1).Replace("$"c, "")
- Dim PricePerLine = prod_list.ElementAt(3)
- 'EachItemTotalPrice = Quantity * PriceEach
- .Parameters.Add(New OleDbParameter("@ProductName", OleDbType.VarChar, 255, prod_name))
- .Parameters.Add(New OleDbParameter("@Quantity", OleDbType.VarChar, 255, prod_quantity))
- .Parameters.Add(New OleDbParameter("@PriceEach", OleDbType.Currency, 255, price_each))
- .Parameters.Add(New OleDbParameter("@OrderTotalPrice", OleDbType.Currency, 255, Total))
- .Parameters.Add(New OleDbParameter("@PricePerLine", OleDbType.Currency, 255, PricePerLine))
- .Parameters.Add(New OleDbParameter("@Username", OleDbType.VarChar, 255, txtUsername.Text))
- prod_list = New List(Of String)
- cm.Parameters("@ProductName").Value = prod_name
- cm.Parameters("@Quantity").Value = prod_quantity
- cm.Parameters("@PriceEach").Value = price_each
- cm.Parameters("@OrderTotalPrice").Value = Total
- cm.Parameters("@Username").Value = txtUsername.Text
- cm.Parameters("@PricePerLine").Value = PricePerLine
- cm.ExecuteNonQuery()
- MsgBox("Record saved.", MsgBoxStyle.Information)
- cmboxProduct.SelectedItem = ""
- txtQuantity.Text = ""
- txtTotalPrice.Text = ""
- ListBoxCart.Items.Clear()
- Exit Sub
- End With
- Catch ex As Exception
- MsgBox(ex.Message, MsgBoxStyle.Critical)
- End Try
- Next
- End Sub
- Private Sub btnClearCart_Click(sender As Object, e As EventArgs) Handles btnClearCart.Click
- ListBoxCart.Items.Clear()
- Total = 0
- txtTotalPrice.Text = String.Empty
- End Sub
- Private Sub cmboxProduct_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmboxProduct.SelectedIndexChanged
- If cmboxProduct.SelectedItem = "iPad Case" Then
- txtPriceEach.Text = iPadCasePrice
- End If
- If cmboxProduct.SelectedItem = "iPad 2" Then
- txtPriceEach.Text = iPad2Price
- End If
- End Sub
- End Class
Add Comment
Please, Sign In to add comment