Hello all! I made some time ago a not very well organized question about my database driven application. My primary language is Spanish so I will try to be concise and clear. I have an ADD button in a MENU form, 4 TABS with each TAB having its own NUMERICUPDOWN, COMBOBOX and PRICE LABEL. When you open the COMBOBOX it fills up with different food names from a database made in MySQL. You choose one of the names in the combo box and AUTOMATICALLY the labels display it's price (Stored in the database). The problem is that if I press ADD a Sub Total label outside the TabControl keeps record of the added prices, and it works fine between tabs, but when I press ADD when selecting ANOTHER item from the SAME COMBOBOX inside one tab, the price in subtotal gets overridden by the new value (Only happens when selecting items between one combobox). How do I stop this? How to I sum the different prices coming from one combobox with only a global ADD button?
This is the code for the button ADD:
Code:Private Sub btnAddAll_Click(sender As System.Object, e As System.EventArgs) Handles btnAddAll.Click Dim winesPrice As Decimal Dim appetizersPrice As Decimal Dim dishesPrice As Decimal Dim dessertsPrice As Decimal dessertsPrice = dessertsPrice + (numDesserts.Value * CDec(Val(lblPriceDesserts.Text))) dishesPrice = dishesPrice + (numDishes.Value * CDec(Val(lblPriceDishes.Text))) winesPrice = winesPrice + (numWines.Value * CDec(Val(lblPriceWines.Text))) appetizersPrice = appetizersPrice + (numAppetizers.Value * CDec(Val(lblPriceAppetizers.Text))) globalDesserts = dessertsPrice globalWines = winesPrice globalDishes = dishesPrice globalAppetizers = appetizersPrice globalSubTotal = globalDishes + globalDesserts + globalWines + globalAppetizers lblSubTotal.Text = globalSubTotal End Sub
This is the CODE for one of the comboboxes (They all share the same kind of code):
Code:Try MySQLConn.Open() Dim query As String query = "select * from database.meals where MealName = '" & cmbDesserts.Text & "'" 'Se busca la tabla de meals command = New MySqlCommand(query, MySQLConn) reader = command.ExecuteReader While reader.Read lblDesDesserts.Text = reader.GetString("Description") lblPriceDesserts.Text = reader.GetDecimal("Price") If cmbDesserts.Text = "Panna Cotta" Then Me.picDesserts.Image = Image.FromFile(driveLetter & imagePath & "\Panna Cotta (Dessert).jpg") ElseIf cmbDesserts.Text = "Bellini Granita" Then Me.picDesserts.Image = Image.FromFile(driveLetter & imagePath & "\Bellini Granita (Desserts).jpg") ElseIf cmbDesserts.Text = "Della Parfait" Then Me.picDesserts.Image = Image.FromFile(driveLetter & imagePath & "\Parfait (Dessert).jpg") End If End While MySQLConn.Close() 'Cerrar coneccion Catch ex As Exception MessageBox.Show(ex.Message) Finally MySQLConn.Dispose() End Try End Sub
This is the final ORDER BUTTON:
Code:Private Sub btnOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOrder.Click Dim winesPrice As Decimal Dim appetizersPrice As Decimal Dim dishesPrice As Decimal Dim dessertsPrice As Decimal dessertsPrice = dessertsPrice + (numDishes.Value * CDec(Val(lblPriceDesserts.Text))) dishesPrice = dishesPrice + (numDishes.Value * CDec(Val(lblPriceDishes.Text))) winesPrice = winesPrice + (numWines.Value * CDec(Val(lblPriceWines.Text))) appetizersPrice = appetizersPrice + (numAppetizers.Value * CDec(Val(lblPriceAppetizers.Text))) globalDesserts = dessertsPrice globalWines = winesPrice globalDishes = dishesPrice globalAppetizers = appetizersPrice globalSubTotal = globalDishes + globalDesserts + globalWines + globalAppetizers lblSubTotal.Text = globalSubTotal GlobalVariables.globalPrice = globalSubTotal If GlobalVariables.globalPrice = 0 Then MsgBox("You haven't chosen any dishes!", MsgBoxStyle.Critical) Else Me.Hide() frmPayment.Show() 'Ir a ventana de pago End If End Sub
This is the FORM LOAD CODES and Global Variables that pass values to the next form:
Code:Imports MySql.Data.MySqlClient 'Añade como referencia MySQL.Data.dll Imports System.IO Public Class frmMenu Public Class GlobalVariables Public Shared globalPrice As Decimal 'Variable de acceso global End Class Dim reader As MySqlDataReader Dim MySQLConn As MySqlConnection Dim command As MySqlCommand Dim drivePath As DriveInfo 'Direccion actual del proyecto Dim imagePath As String = "\Universidad\Systems Development & Implementation\Asignaciones\Proyecto Final\Iconos y Fotos" Dim driveLetter As String Dim globalSubTotal As Decimal Dim globalDishes As Decimal 'Variables de acceso local Dim globalWines As Decimal Dim globalAppetizers As Decimal Dim globalDesserts As Decimal Private Sub frmMenu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For Each Me.drivePath In DriveInfo.GetDrives 'Busca la letra del "drive" del USB/CDROM y lo pasa a una variable If drivePath.IsReady Then If drivePath.DriveType = IO.DriveType.Removable Then driveLetter = drivePath.Name ElseIf drivePath.DriveType = IO.DriveType.CDRom Then driveLetter = drivePath.Name End If End If Next




Reply With Quote
