Guest User

Untitled

a guest
Dec 22nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. Imports System.Data.OleDb
  2. Public Class frmOrderProduct
  3. Dim iPadCasePrice As String
  4. Dim iPad2Price As String
  5. Dim prod_list As List(Of String)
  6. Dim Total As Decimal
  7. Dim EachItemTotalPrice As Decimal
  8. Dim Quantity As Integer
  9. Dim PriceEach As Decimal
  10.  
  11. Private Sub frmOrderProduct_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  12.  
  13. Call connection()
  14.  
  15. cmboxProduct.Items.Add("iPad Case")
  16. cmboxProduct.Items.Add("iPad 2")
  17.  
  18. iPadCasePrice = "$20.00"
  19. iPad2Price = "$200.00"
  20.  
  21.  
  22. txtUsername.Text = frmLogin.txtUsername.Text
  23.  
  24. End Sub
  25.  
  26. Private Sub btnAddToCart_Click(sender As Object, e As EventArgs) Handles btnAddToCart.Click
  27.  
  28. Dim PricePerLine As Decimal
  29.  
  30. If cmboxProduct.SelectedItem = "" Or txtQuantity.Text = "" Then
  31. MsgBox("Please fill out all required fields", MsgBoxStyle.OkOnly, "Invalid entered data")
  32. Else
  33.  
  34. PricePerLine = txtQuantity.Text * txtPriceEach.Text
  35. ListBoxCart.Items.Add("x" & txtQuantity.Text & " " & cmboxProduct.SelectedItem & " " & txtPriceEach.Text & " " & "$" & PricePerLine)
  36.  
  37. Quantity = Decimal.Parse(txtQuantity.Text)
  38. PriceEach = Decimal.Parse(txtPriceEach.Text.Remove(0, 1)) 'need to remove the $ before parse
  39. Total += PriceEach * Quantity
  40. txtTotalPrice.Text = String.Format("${0}", Total)
  41.  
  42.  
  43. 'txtShoppingCart.AppendText("x" & txtQuantity.Text & " " & Product1 & Environment.NewLine)
  44. End If
  45. End Sub
  46.  
  47. Private Sub txtQuantity_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles txtQuantity.KeyPress
  48.  
  49. If Asc(e.KeyChar) <> 8 Then
  50. If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
  51. e.Handled = True
  52. End If
  53. End If
  54.  
  55. End Sub
  56.  
  57. Private Sub btnOrderProducts_Click(sender As Object, e As EventArgs) Handles btnOrderProducts.Click
  58.  
  59. Dim numberOfItems = ListBoxCart.Items.Count
  60. For Each item As String In ListBoxCart.Items
  61.  
  62. Try
  63.  
  64. cm = New OleDbCommand
  65. With cm
  66. .Connection = cn
  67. .CommandType = CommandType.Text
  68. .CommandText = "INSERT INTO tblOrders ([ProductName],[Quantity],[PriceEach],[OrderTotalPrice],[PricePerLine],[Username]) VALUES (@ProductName,@Quantity,@PriceEach,@TotalPrice,@Username)"
  69.  
  70. prod_list = item.Split(" ").ToList
  71. Dim prod_name = prod_list.ElementAt(1)
  72. Dim prod_quantity = Integer.Parse(prod_list.ElementAt(0).Remove(0, 1))
  73. Dim price_each = prod_list.ElementAt(prod_list.Count - 1).Replace("$"c, "")
  74. Dim PricePerLine = prod_list.ElementAt(3)
  75. 'EachItemTotalPrice = Quantity * PriceEach
  76.  
  77. .Parameters.Add(New OleDbParameter("@ProductName", OleDbType.VarChar, 255, prod_name))
  78. .Parameters.Add(New OleDbParameter("@Quantity", OleDbType.VarChar, 255, prod_quantity))
  79. .Parameters.Add(New OleDbParameter("@PriceEach", OleDbType.Currency, 255, price_each))
  80. .Parameters.Add(New OleDbParameter("@OrderTotalPrice", OleDbType.Currency, 255, Total))
  81. .Parameters.Add(New OleDbParameter("@PricePerLine", OleDbType.Currency, 255, PricePerLine))
  82. .Parameters.Add(New OleDbParameter("@Username", OleDbType.VarChar, 255, txtUsername.Text))
  83. prod_list = New List(Of String)
  84.  
  85. cm.Parameters("@ProductName").Value = prod_name
  86. cm.Parameters("@Quantity").Value = prod_quantity
  87. cm.Parameters("@PriceEach").Value = price_each
  88. cm.Parameters("@OrderTotalPrice").Value = Total
  89. cm.Parameters("@Username").Value = txtUsername.Text
  90. cm.Parameters("@PricePerLine").Value = PricePerLine
  91.  
  92. cm.ExecuteNonQuery()
  93. MsgBox("Record saved.", MsgBoxStyle.Information)
  94. cmboxProduct.SelectedItem = ""
  95. txtQuantity.Text = ""
  96. txtTotalPrice.Text = ""
  97. ListBoxCart.Items.Clear()
  98.  
  99. Exit Sub
  100. End With
  101. Catch ex As Exception
  102. MsgBox(ex.Message, MsgBoxStyle.Critical)
  103. End Try
  104.  
  105. Next
  106.  
  107. End Sub
  108.  
  109. Private Sub btnClearCart_Click(sender As Object, e As EventArgs) Handles btnClearCart.Click
  110.  
  111. ListBoxCart.Items.Clear()
  112. Total = 0
  113. txtTotalPrice.Text = String.Empty
  114.  
  115. End Sub
  116.  
  117. Private Sub cmboxProduct_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmboxProduct.SelectedIndexChanged
  118.  
  119. If cmboxProduct.SelectedItem = "iPad Case" Then
  120. txtPriceEach.Text = iPadCasePrice
  121. End If
  122.  
  123. If cmboxProduct.SelectedItem = "iPad 2" Then
  124. txtPriceEach.Text = iPad2Price
  125. End If
  126.  
  127. End Sub
  128. End Class
Add Comment
Please, Sign In to add comment