Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Text ' Imports System.Text namespace
- Public Class btnOrderNow ' Declare public class btnOrderNow
- Private userNote As String = "" ' Declaration and initialization of a private string variable userNote, which stores the user's note.
- Private isDarkMode As Boolean = False ' Declaration and initialization of a private boolean variable isDarkMode, which indicates whether dark mode is enabled or not.
- Private orderAdded As Boolean = False ' Declaration and initialization of a private boolean variable orderAdded, which indicates whether an order has been added or not.
- Dim orders As New Dictionary(Of String, (Quantity As Integer, Price As Double))() ' Declaration and initialization of a dictionary variable orders to store order details.
- Private Sub UpdatePizzaDescription() ' Declaration of the UpdatePizzaDescription Subroutine.
- Dim pizzaDescription As String = "Pizza: " ' Declaration and initialization of a string variable pizzaDescription to store the pizza description.
- ' Add the selected pizza to the pizzaDescription string, or "None" if no selection has been made.
- pizzaDescription &= If(cmbPizza.SelectedIndex > -1, cmbPizza.SelectedItem.ToString(), "None")
- pizzaDescription &= vbNewLine & "Crust: " ' Add a new line and "Crust: " to the pizzaDescription string.
- pizzaDescription &= If(radThin.Checked, "Thin", If(radThick.Checked, "Thick", "None"))
- pizzaDescription &= vbNewLine & "Quantity: " ' Add a new line and "Quantity: " to the pizzaDescription string.
- ' Add the quantity to the pizzaDescription string, or "None" if the quantity is zero.
- pizzaDescription &= If(numQuantity.Value > 0, numQuantity.Value.ToString(), "None")
- ' If the cheese checkbox is checked, add "With Cheese" to the pizzaDescription string.
- If chkCheese.Checked Then pizzaDescription &= vbNewLine & "With Cheese"
- ' If the toppings checkbox is checked, add "With Toppings" to the pizzaDescription string.
- If chkToppings.Checked Then pizzaDescription &= vbNewLine & "With Toppings"
- ' If the userNote is not empty, add "Note: " and the user's note to the pizzaDescription string.
- If userNote <> "" Then pizzaDescription &= vbNewLine & "Note: " & userNote
- ' Update the text in rtbPizzaDetails with the pizzaDescription.
- rtbPizzaDetails.Text = pizzaDescription
- End Sub ' End of the UpdatePizzaDescription Subroutine.
- Private Sub UpdateTheme() ' Declaration of the UpdateTheme Subroutine.
- If isDarkMode Then
- ' Dark Mode
- Me.BackColor = Color.FromArgb(40, 40, 40)
- ' Change colors of other controls to match dark theme
- rtbPizzaDetails.BackColor = Color.FromArgb(60, 60, 60)
- rtbPizzaDetails.ForeColor = Color.White
- rtbOrderDetails.BackColor = Color.FromArgb(60, 60, 60)
- rtbOrderDetails.ForeColor = Color.White
- txtCustName.ForeColor = Color.Black
- txtPhoneNumber.ForeColor = Color.Black
- txtAddress.ForeColor = Color.Black
- lblTitle.ForeColor = Color.White
- lblCustName.ForeColor = Color.White
- lblPhoneNumber.ForeColor = Color.White
- lblAddress.ForeColor = Color.White
- lblMembership.ForeColor = Color.White
- gbxDiscount.ForeColor = Color.White
- radYes.ForeColor = Color.White
- radNo.ForeColor = Color.White
- gbxPickPizza.ForeColor = Color.White
- gbxCrust.ForeColor = Color.White
- gbxQuantity.ForeColor = Color.White
- lblTheme.ForeColor = Color.White
- radDark.ForeColor = Color.White
- radLight.ForeColor = Color.White
- lblDevider.ForeColor = Color.White
- gbxOrder.ForeColor = Color.White
- rtbOrderDetails.ForeColor = Color.White
- Else
- ' Light Mode
- Me.BackColor = Color.FromKnownColor(KnownColor.Control)
- ' Change colors of other controls to match light theme
- rtbPizzaDetails.BackColor = Color.White
- rtbPizzaDetails.ForeColor = Color.Black
- rtbOrderDetails.BackColor = Color.White
- rtbOrderDetails.ForeColor = Color.Black
- txtCustName.ForeColor = Color.Black
- txtPhoneNumber.ForeColor = Color.Black
- txtAddress.ForeColor = Color.Black
- lblTitle.ForeColor = Color.Black
- lblCustName.ForeColor = Color.Black
- lblPhoneNumber.ForeColor = Color.Black
- lblAddress.ForeColor = Color.Black
- lblMembership.ForeColor = Color.Black
- gbxDiscount.ForeColor = Color.Black
- radYes.ForeColor = Color.Black
- radNo.ForeColor = Color.Black
- gbxPickPizza.ForeColor = Color.Black
- gbxCrust.ForeColor = Color.Black
- gbxQuantity.ForeColor = Color.Black
- lblTheme.ForeColor = Color.Black
- radDark.ForeColor = Color.Black
- radLight.ForeColor = Color.Black
- lblDevider.ForeColor = Color.Black
- gbxOrder.ForeColor = Color.Black
- rtbOrderDetails.ForeColor = Color.Black
- End If
- End Sub ' End of the UpdateTheme Subroutine.
- Private Sub UpdateOrderDetails() ' Declaration of the UpdateOrderDetails Subroutine.
- rtbOrderDetails.Clear()
- Dim totalOrderPrice As Double = 0
- rtbOrderDetails.AppendText("Customer Name: " & txtCustName.Text & Environment.NewLine)
- rtbOrderDetails.AppendText("Phone Number: " & txtPhoneNumber.Text & Environment.NewLine)
- rtbOrderDetails.AppendText("Address: " & txtAddress.Text & Environment.NewLine)
- rtbOrderDetails.AppendText("------------------------------------------" & Environment.NewLine)
- rtbOrderDetails.AppendText("Orders: " & Environment.NewLine)
- For Each order In orders
- rtbOrderDetails.AppendText($"{order.Key} @ {order.Value.Quantity} order/s = {order.Value.Price:C2}" & Environment.NewLine)
- totalOrderPrice += order.Value.Price
- Next
- rtbOrderDetails.AppendText("---------------------------------------" & Environment.NewLine)
- rtbOrderDetails.AppendText($"Total = {totalOrderPrice:C2}")
- End Sub ' End of the UpdateOrderDetails Subroutine.
- Private Sub lblCustName_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- numQuantity.Value = 1
- radNo.Checked = True
- radThin.Checked = True
- radLight.Checked = True
- End Sub
- Private Sub chkTopings_CheckedChanged(sender As Object, e As EventArgs) Handles chkToppings.CheckedChanged
- UpdatePizzaDescription()
- End Sub
- Private Sub cmbPizza_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbPizza.SelectedIndexChanged
- UpdatePizzaDescription()
- End Sub
- Private Sub cmbQuantity_SelectedIndexChanged(sender As Object, e As EventArgs)
- UpdatePizzaDescription()
- End Sub
- Private Sub radThin_CheckedChanged(sender As Object, e As EventArgs) Handles radThin.CheckedChanged
- UpdatePizzaDescription()
- End Sub
- Private Sub radThick_CheckedChanged(sender As Object, e As EventArgs) Handles radThick.CheckedChanged
- UpdatePizzaDescription()
- End Sub
- Private Sub chkCheese_CheckedChanged(sender As Object, e As EventArgs) Handles chkCheese.CheckedChanged
- UpdatePizzaDescription()
- End Sub
- Private Sub numQuantity_ValueChanged(sender As Object, e As EventArgs) Handles numQuantity.ValueChanged
- UpdatePizzaDescription()
- End Sub
- Private Sub btnOrder_Click(sender As Object, e As EventArgs) Handles btnOrder.Click
- Dim pizzaPrices As New Dictionary(Of String, Double) From {
- {"Classic Hawaiian", 200},
- {"Garden Special", 350},
- {"Full House Pizza", 550},
- {"Meat Lovers", 480}
- }
- Dim orderDetails As New StringBuilder
- Dim pizzaPrice As Double = 0
- Dim cheesePrice As Double = 29.99
- Dim toppingsPrice As Double = 49.99
- ' Validations
- If String.IsNullOrEmpty(txtCustName.Text.Trim()) Then
- MessageBox.Show("Please enter the customer name.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- txtCustName.Focus()
- Return
- End If
- For Each c As Char In txtCustName.Text
- If Not Char.IsLetter(c) AndAlso Not Char.IsWhiteSpace(c) Then
- MessageBox.Show("The customer name should only contain letters.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- txtCustName.Focus()
- Return
- End If
- Next
- If String.IsNullOrEmpty(txtPhoneNumber.Text.Trim()) Then
- MessageBox.Show("Please enter the phone number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- txtPhoneNumber.Focus()
- Return
- End If
- For Each c As Char In txtPhoneNumber.Text
- If Not Char.IsDigit(c) Then
- MessageBox.Show("The phone number should only contain numbers.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- txtPhoneNumber.Focus()
- Return
- End If
- Next
- If String.IsNullOrEmpty(txtAddress.Text.Trim()) Then
- MessageBox.Show("Please enter the address.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- txtAddress.Focus()
- Return
- End If
- If cmbPizza.SelectedIndex = -1 Then
- MessageBox.Show("Please select a pizza type.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- cmbPizza.Focus()
- Return
- End If
- If Not radThin.Checked And Not radThick.Checked Then
- MessageBox.Show("Please select a crust type.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- Return
- End If
- If numQuantity.Value <= 0 Then
- MessageBox.Show("Quantity should be more than zero.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- numQuantity.Focus()
- Return
- End If
- ' Add customer details
- orderDetails.AppendLine("Customer Name: " & txtCustName.Text)
- orderDetails.AppendLine("Phone Number: " & txtPhoneNumber.Text)
- orderDetails.AppendLine("Address: " & txtAddress.Text)
- orderDetails.AppendLine("------------------------------------------")
- Dim pizzaName As String = cmbPizza.SelectedItem.ToString()
- Dim pizzaQuantity As Integer = numQuantity.Value
- pizzaPrice += pizzaPrices(cmbPizza.SelectedItem.ToString())
- pizzaPrice += If(chkCheese.Checked, cheesePrice, 0)
- pizzaPrice += If(chkToppings.Checked, toppingsPrice, 0)
- pizzaPrice *= pizzaQuantity ' multiply the pizza price by the quantity
- ' Apply membership discount
- If radYes.Checked Then
- pizzaPrice *= 0.95 ' Apply a 5% discount
- End If
- Dim totalPrice As Double = pizzaPrice
- If orders.ContainsKey(pizzaName) Then
- ' Add to the existing quantity and price
- Dim existingOrder = orders(pizzaName)
- orders(pizzaName) = (existingOrder.Quantity + pizzaQuantity, existingOrder.Price + totalPrice)
- Else
- ' Add a new order to the dictionary
- orders.Add(pizzaName, (pizzaQuantity, totalPrice))
- End If
- ' Clear and reset comboboxes
- cmbPizza.SelectedIndex = -1
- cmbPizza.Text = ""
- ' Reset numeric updown
- numQuantity.Value = 1
- ' Uncheck checkboxes
- chkCheese.Checked = False
- chkToppings.Checked = False
- ' Reset radio buttons
- radThin.Checked = True
- radThick.Checked = False
- radYes.Checked = False
- radNo.Checked = True
- ' Clear rich text boxes
- rtbPizzaDetails.Text = ""
- UpdateOrderDetails() ' Update the RichTextBox with the new order details
- orderAdded = True
- End Sub
- Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
- Dim result As DialogResult = MessageBox.Show("Are you sure you want to clear the current order and start a new one?", "Confirmation", MessageBoxButtons.YesNo)
- If result = DialogResult.Yes Then
- ' Clear textboxes
- txtCustName.Text = ""
- txtPhoneNumber.Text = ""
- txtAddress.Text = ""
- ' Clear and reset comboboxes
- cmbPizza.SelectedIndex = -1
- cmbPizza.Text = ""
- ' Reset numeric updown
- numQuantity.Value = 1
- ' Uncheck checkboxes
- chkCheese.Checked = False
- chkToppings.Checked = False
- ' Reset radio buttons
- radThin.Checked = True
- radThick.Checked = False
- radYes.Checked = False
- radNo.Checked = True
- ' Clear rich text boxes
- rtbPizzaDetails.Text = ""
- rtbOrderDetails.Text = "" ' This line clears the order details
- ' Clear the orders dictionary
- orders.Clear()
- End If
- End Sub
- Private Sub txtCustName_TextChanged(sender As Object, e As EventArgs) Handles txtCustName.TextChanged
- End Sub
- Private Sub btnNote_Click(sender As Object, e As EventArgs) Handles btnNote.Click
- userNote = InputBox("Enter A Note For Your Order:", "Add Note")
- UpdatePizzaDescription()
- End Sub
- Private Sub formOrderPicker_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
- If Not orderAdded Then
- Dim result As DialogResult = MessageBox.Show("You have unsaved changes. Are you sure you want to exit?", "Exit Confirmation", MessageBoxButtons.YesNo)
- If result = DialogResult.No Then
- e.Cancel = True
- End If
- End If
- End Sub
- Private Sub radLight_CheckedChanged(sender As Object, e As EventArgs) Handles radLight.CheckedChanged
- isDarkMode = Not radLight.Checked ' If radLight is checked, isDarkMode is false
- UpdateTheme()
- End Sub
- Private Sub radDark_CheckedChanged(sender As Object, e As EventArgs) Handles radDark.CheckedChanged
- isDarkMode = radDark.Checked ' If radDark is checked, isDarkMode is true
- UpdateTheme()
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- If orders.Count = 0 Then
- MessageBox.Show("No pizzas have been added to the order. Please add pizzas before ordering.", "Order Empty", MessageBoxButtons.OK, MessageBoxIcon.Information)
- Return
- End If
- Dim orderDetails As New StringBuilder("You are about to order the following:" & vbNewLine)
- Dim totalOrderPrice As Double = 0
- For Each order In orders
- orderDetails.AppendLine($"{order.Key} {order.Value.Quantity} orders = {order.Value.Price:C2}")
- totalOrderPrice += order.Value.Price
- Next
- orderDetails.AppendLine("---------------------------------------")
- orderDetails.AppendLine($"Total = {totalOrderPrice:C2}")
- orderDetails.AppendLine(vbNewLine & "Confirm?")
- Dim result As DialogResult = MessageBox.Show(orderDetails.ToString(), "Order Confirmation", MessageBoxButtons.OKCancel)
- If result = DialogResult.OK Then
- ' User has confirmed the order, so we can clear the existing orders
- orders.Clear()
- MessageBox.Show("Your order has been placed successfully.", "Order Placed", MessageBoxButtons.OK, MessageBoxIcon.Information)
- ' Reset the UI
- txtCustName.Text = ""
- txtPhoneNumber.Text = ""
- txtAddress.Text = ""
- ' Clear and reset comboboxes
- cmbPizza.SelectedIndex = -1
- cmbPizza.Text = ""
- ' Reset numeric updown
- numQuantity.Value = 1
- ' Uncheck checkboxes
- chkCheese.Checked = False
- chkToppings.Checked = False
- ' Reset radio buttons
- radThin.Checked = True
- radThick.Checked = False
- radYes.Checked = False
- radNo.Checked = True
- ' Clear rich text boxes
- rtbPizzaDetails.Text = ""
- rtbOrderDetails.Text = "" ' This line clears the order details
- result = MessageBox.Show("Would you like to make another order?", "New Order", MessageBoxButtons.YesNo)
- If result = DialogResult.No Then
- ' User doesn't want to make another order, so we can close the application
- Me.Close()
- End If
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement