Advertisement
grhey

Untitled

May 30th, 2023
896
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 16.79 KB | None | 0 0
  1. Imports System.Text ' Imports System.Text namespace
  2.  
  3. Public Class btnOrderNow ' Declare public class btnOrderNow
  4.  
  5.     Private userNote As String = "" ' Declaration and initialization of a private string variable userNote, which stores the user's note.
  6.     Private isDarkMode As Boolean = False ' Declaration and initialization of a private boolean variable isDarkMode, which indicates whether dark mode is enabled or not.
  7.     Private orderAdded As Boolean = False ' Declaration and initialization of a private boolean variable orderAdded, which indicates whether an order has been added or not.
  8.     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.
  9.  
  10.     Private Sub UpdatePizzaDescription() ' Declaration of the UpdatePizzaDescription Subroutine.
  11.  
  12.         Dim pizzaDescription As String = "Pizza: " ' Declaration and initialization of a string variable pizzaDescription to store the pizza description.
  13.  
  14.         ' Add the selected pizza to the pizzaDescription string, or "None" if no selection has been made.
  15.         pizzaDescription &= If(cmbPizza.SelectedIndex > -1, cmbPizza.SelectedItem.ToString(), "None")
  16.         pizzaDescription &= vbNewLine & "Crust: " ' Add a new line and "Crust: " to the pizzaDescription string.
  17.  
  18.         pizzaDescription &= If(radThin.Checked, "Thin", If(radThick.Checked, "Thick", "None"))
  19.         pizzaDescription &= vbNewLine & "Quantity: " ' Add a new line and "Quantity: " to the pizzaDescription string.
  20.  
  21.         ' Add the quantity to the pizzaDescription string, or "None" if the quantity is zero.
  22.         pizzaDescription &= If(numQuantity.Value > 0, numQuantity.Value.ToString(), "None")
  23.  
  24.         ' If the cheese checkbox is checked, add "With Cheese" to the pizzaDescription string.
  25.         If chkCheese.Checked Then pizzaDescription &= vbNewLine & "With Cheese"
  26.  
  27.         ' If the toppings checkbox is checked, add "With Toppings" to the pizzaDescription string.
  28.         If chkToppings.Checked Then pizzaDescription &= vbNewLine & "With Toppings"
  29.  
  30.         ' If the userNote is not empty, add "Note: " and the user's note to the pizzaDescription string.
  31.         If userNote <> "" Then pizzaDescription &= vbNewLine & "Note: " & userNote
  32.  
  33.         ' Update the text in rtbPizzaDetails with the pizzaDescription.
  34.         rtbPizzaDetails.Text = pizzaDescription
  35.     End Sub ' End of the UpdatePizzaDescription Subroutine.
  36.  
  37.     Private Sub UpdateTheme() ' Declaration of the UpdateTheme Subroutine.
  38.         If isDarkMode Then
  39.             ' Dark Mode
  40.             Me.BackColor = Color.FromArgb(40, 40, 40)
  41.             ' Change colors of other controls to match dark theme
  42.             rtbPizzaDetails.BackColor = Color.FromArgb(60, 60, 60)
  43.             rtbPizzaDetails.ForeColor = Color.White
  44.             rtbOrderDetails.BackColor = Color.FromArgb(60, 60, 60)
  45.             rtbOrderDetails.ForeColor = Color.White
  46.             txtCustName.ForeColor = Color.Black
  47.             txtPhoneNumber.ForeColor = Color.Black
  48.             txtAddress.ForeColor = Color.Black
  49.             lblTitle.ForeColor = Color.White
  50.             lblCustName.ForeColor = Color.White
  51.             lblPhoneNumber.ForeColor = Color.White
  52.             lblAddress.ForeColor = Color.White
  53.             lblMembership.ForeColor = Color.White
  54.             gbxDiscount.ForeColor = Color.White
  55.             radYes.ForeColor = Color.White
  56.             radNo.ForeColor = Color.White
  57.             gbxPickPizza.ForeColor = Color.White
  58.             gbxCrust.ForeColor = Color.White
  59.             gbxQuantity.ForeColor = Color.White
  60.             lblTheme.ForeColor = Color.White
  61.             radDark.ForeColor = Color.White
  62.             radLight.ForeColor = Color.White
  63.             lblDevider.ForeColor = Color.White
  64.             gbxOrder.ForeColor = Color.White
  65.             rtbOrderDetails.ForeColor = Color.White
  66.         Else
  67.             ' Light Mode
  68.             Me.BackColor = Color.FromKnownColor(KnownColor.Control)
  69.             ' Change colors of other controls to match light theme
  70.             rtbPizzaDetails.BackColor = Color.White
  71.             rtbPizzaDetails.ForeColor = Color.Black
  72.             rtbOrderDetails.BackColor = Color.White
  73.             rtbOrderDetails.ForeColor = Color.Black
  74.             txtCustName.ForeColor = Color.Black
  75.             txtPhoneNumber.ForeColor = Color.Black
  76.             txtAddress.ForeColor = Color.Black
  77.             lblTitle.ForeColor = Color.Black
  78.             lblCustName.ForeColor = Color.Black
  79.             lblPhoneNumber.ForeColor = Color.Black
  80.             lblAddress.ForeColor = Color.Black
  81.             lblMembership.ForeColor = Color.Black
  82.             gbxDiscount.ForeColor = Color.Black
  83.             radYes.ForeColor = Color.Black
  84.             radNo.ForeColor = Color.Black
  85.             gbxPickPizza.ForeColor = Color.Black
  86.             gbxCrust.ForeColor = Color.Black
  87.             gbxQuantity.ForeColor = Color.Black
  88.             lblTheme.ForeColor = Color.Black
  89.             radDark.ForeColor = Color.Black
  90.             radLight.ForeColor = Color.Black
  91.             lblDevider.ForeColor = Color.Black
  92.             gbxOrder.ForeColor = Color.Black
  93.             rtbOrderDetails.ForeColor = Color.Black
  94.         End If
  95.     End Sub ' End of the UpdateTheme Subroutine.
  96.  
  97.     Private Sub UpdateOrderDetails() ' Declaration of the UpdateOrderDetails Subroutine.
  98.         rtbOrderDetails.Clear()
  99.  
  100.         Dim totalOrderPrice As Double = 0
  101.         rtbOrderDetails.AppendText("Customer Name: " & txtCustName.Text & Environment.NewLine)
  102.         rtbOrderDetails.AppendText("Phone Number: " & txtPhoneNumber.Text & Environment.NewLine)
  103.         rtbOrderDetails.AppendText("Address: " & txtAddress.Text & Environment.NewLine)
  104.         rtbOrderDetails.AppendText("------------------------------------------" & Environment.NewLine)
  105.         rtbOrderDetails.AppendText("Orders: " & Environment.NewLine)
  106.         For Each order In orders
  107.             rtbOrderDetails.AppendText($"{order.Key} @ {order.Value.Quantity} order/s = {order.Value.Price:C2}" & Environment.NewLine)
  108.             totalOrderPrice += order.Value.Price
  109.         Next
  110.  
  111.         rtbOrderDetails.AppendText("---------------------------------------" & Environment.NewLine)
  112.         rtbOrderDetails.AppendText($"Total = {totalOrderPrice:C2}")
  113.     End Sub ' End of the UpdateOrderDetails Subroutine.
  114.  
  115.     Private Sub lblCustName_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  116.         numQuantity.Value = 1
  117.         radNo.Checked = True
  118.         radThin.Checked = True
  119.         radLight.Checked = True
  120.     End Sub
  121.  
  122.     Private Sub chkTopings_CheckedChanged(sender As Object, e As EventArgs) Handles chkToppings.CheckedChanged
  123.         UpdatePizzaDescription()
  124.     End Sub
  125.  
  126.     Private Sub cmbPizza_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbPizza.SelectedIndexChanged
  127.         UpdatePizzaDescription()
  128.     End Sub
  129.  
  130.     Private Sub cmbQuantity_SelectedIndexChanged(sender As Object, e As EventArgs)
  131.         UpdatePizzaDescription()
  132.     End Sub
  133.  
  134.     Private Sub radThin_CheckedChanged(sender As Object, e As EventArgs) Handles radThin.CheckedChanged
  135.         UpdatePizzaDescription()
  136.     End Sub
  137.  
  138.     Private Sub radThick_CheckedChanged(sender As Object, e As EventArgs) Handles radThick.CheckedChanged
  139.         UpdatePizzaDescription()
  140.     End Sub
  141.  
  142.     Private Sub chkCheese_CheckedChanged(sender As Object, e As EventArgs) Handles chkCheese.CheckedChanged
  143.         UpdatePizzaDescription()
  144.     End Sub
  145.  
  146.     Private Sub numQuantity_ValueChanged(sender As Object, e As EventArgs) Handles numQuantity.ValueChanged
  147.         UpdatePizzaDescription()
  148.     End Sub
  149.  
  150.     Private Sub btnOrder_Click(sender As Object, e As EventArgs) Handles btnOrder.Click
  151.  
  152.         Dim pizzaPrices As New Dictionary(Of String, Double) From {
  153.         {"Classic Hawaiian", 200},
  154.         {"Garden Special", 350},
  155.         {"Full House Pizza", 550},
  156.         {"Meat Lovers", 480}
  157.     }
  158.         Dim orderDetails As New StringBuilder
  159.         Dim pizzaPrice As Double = 0
  160.         Dim cheesePrice As Double = 29.99
  161.         Dim toppingsPrice As Double = 49.99
  162.  
  163.         ' Validations
  164.         If String.IsNullOrEmpty(txtCustName.Text.Trim()) Then
  165.             MessageBox.Show("Please enter the customer name.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  166.             txtCustName.Focus()
  167.             Return
  168.         End If
  169.  
  170.         For Each c As Char In txtCustName.Text
  171.             If Not Char.IsLetter(c) AndAlso Not Char.IsWhiteSpace(c) Then
  172.                 MessageBox.Show("The customer name should only contain letters.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  173.                 txtCustName.Focus()
  174.                 Return
  175.             End If
  176.         Next
  177.  
  178.         If String.IsNullOrEmpty(txtPhoneNumber.Text.Trim()) Then
  179.             MessageBox.Show("Please enter the phone number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  180.             txtPhoneNumber.Focus()
  181.             Return
  182.         End If
  183.  
  184.         For Each c As Char In txtPhoneNumber.Text
  185.             If Not Char.IsDigit(c) Then
  186.                 MessageBox.Show("The phone number should only contain numbers.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  187.                 txtPhoneNumber.Focus()
  188.                 Return
  189.             End If
  190.         Next
  191.  
  192.  
  193.         If String.IsNullOrEmpty(txtAddress.Text.Trim()) Then
  194.             MessageBox.Show("Please enter the address.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  195.             txtAddress.Focus()
  196.             Return
  197.         End If
  198.  
  199.         If cmbPizza.SelectedIndex = -1 Then
  200.             MessageBox.Show("Please select a pizza type.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  201.             cmbPizza.Focus()
  202.             Return
  203.         End If
  204.  
  205.         If Not radThin.Checked And Not radThick.Checked Then
  206.             MessageBox.Show("Please select a crust type.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  207.             Return
  208.         End If
  209.  
  210.         If numQuantity.Value <= 0 Then
  211.             MessageBox.Show("Quantity should be more than zero.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  212.             numQuantity.Focus()
  213.             Return
  214.         End If
  215.  
  216.         ' Add customer details
  217.         orderDetails.AppendLine("Customer Name: " & txtCustName.Text)
  218.         orderDetails.AppendLine("Phone Number: " & txtPhoneNumber.Text)
  219.         orderDetails.AppendLine("Address: " & txtAddress.Text)
  220.         orderDetails.AppendLine("------------------------------------------")
  221.  
  222.         Dim pizzaName As String = cmbPizza.SelectedItem.ToString()
  223.         Dim pizzaQuantity As Integer = numQuantity.Value
  224.         pizzaPrice += pizzaPrices(cmbPizza.SelectedItem.ToString())
  225.         pizzaPrice += If(chkCheese.Checked, cheesePrice, 0)
  226.         pizzaPrice += If(chkToppings.Checked, toppingsPrice, 0)
  227.         pizzaPrice *= pizzaQuantity ' multiply the pizza price by the quantity
  228.  
  229.         ' Apply membership discount
  230.         If radYes.Checked Then
  231.             pizzaPrice *= 0.95 ' Apply a 5% discount
  232.         End If
  233.  
  234.         Dim totalPrice As Double = pizzaPrice
  235.  
  236.         If orders.ContainsKey(pizzaName) Then
  237.             ' Add to the existing quantity and price
  238.             Dim existingOrder = orders(pizzaName)
  239.             orders(pizzaName) = (existingOrder.Quantity + pizzaQuantity, existingOrder.Price + totalPrice)
  240.         Else
  241.             ' Add a new order to the dictionary
  242.             orders.Add(pizzaName, (pizzaQuantity, totalPrice))
  243.         End If
  244.  
  245.         ' Clear and reset comboboxes
  246.         cmbPizza.SelectedIndex = -1
  247.         cmbPizza.Text = ""
  248.  
  249.         ' Reset numeric updown
  250.         numQuantity.Value = 1
  251.  
  252.         ' Uncheck checkboxes
  253.         chkCheese.Checked = False
  254.         chkToppings.Checked = False
  255.  
  256.         ' Reset radio buttons
  257.         radThin.Checked = True
  258.         radThick.Checked = False
  259.         radYes.Checked = False
  260.         radNo.Checked = True
  261.  
  262.         ' Clear rich text boxes
  263.         rtbPizzaDetails.Text = ""
  264.  
  265.  
  266.         UpdateOrderDetails() ' Update the RichTextBox with the new order details
  267.         orderAdded = True
  268.  
  269.     End Sub
  270.  
  271.     Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
  272.         Dim result As DialogResult = MessageBox.Show("Are you sure you want to clear the current order and start a new one?", "Confirmation", MessageBoxButtons.YesNo)
  273.  
  274.         If result = DialogResult.Yes Then
  275.             ' Clear textboxes
  276.             txtCustName.Text = ""
  277.             txtPhoneNumber.Text = ""
  278.             txtAddress.Text = ""
  279.  
  280.             ' Clear and reset comboboxes
  281.             cmbPizza.SelectedIndex = -1
  282.             cmbPizza.Text = ""
  283.  
  284.             ' Reset numeric updown
  285.             numQuantity.Value = 1
  286.  
  287.             ' Uncheck checkboxes
  288.             chkCheese.Checked = False
  289.             chkToppings.Checked = False
  290.  
  291.             ' Reset radio buttons
  292.             radThin.Checked = True
  293.             radThick.Checked = False
  294.             radYes.Checked = False
  295.             radNo.Checked = True
  296.  
  297.             ' Clear rich text boxes
  298.             rtbPizzaDetails.Text = ""
  299.             rtbOrderDetails.Text = "" ' This line clears the order details
  300.  
  301.             ' Clear the orders dictionary
  302.             orders.Clear()
  303.         End If
  304.     End Sub
  305.  
  306.     Private Sub txtCustName_TextChanged(sender As Object, e As EventArgs) Handles txtCustName.TextChanged
  307.     End Sub
  308.  
  309.     Private Sub btnNote_Click(sender As Object, e As EventArgs) Handles btnNote.Click
  310.         userNote = InputBox("Enter A Note For Your Order:", "Add Note")
  311.         UpdatePizzaDescription()
  312.     End Sub
  313.  
  314.     Private Sub formOrderPicker_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
  315.         If Not orderAdded Then
  316.             Dim result As DialogResult = MessageBox.Show("You have unsaved changes. Are you sure you want to exit?", "Exit Confirmation", MessageBoxButtons.YesNo)
  317.  
  318.             If result = DialogResult.No Then
  319.                 e.Cancel = True
  320.             End If
  321.         End If
  322.     End Sub
  323.  
  324.     Private Sub radLight_CheckedChanged(sender As Object, e As EventArgs) Handles radLight.CheckedChanged
  325.         isDarkMode = Not radLight.Checked ' If radLight is checked, isDarkMode is false
  326.         UpdateTheme()
  327.     End Sub
  328.  
  329.     Private Sub radDark_CheckedChanged(sender As Object, e As EventArgs) Handles radDark.CheckedChanged
  330.         isDarkMode = radDark.Checked ' If radDark is checked, isDarkMode is true
  331.         UpdateTheme()
  332.     End Sub
  333.  
  334.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  335.         If orders.Count = 0 Then
  336.             MessageBox.Show("No pizzas have been added to the order. Please add pizzas before ordering.", "Order Empty", MessageBoxButtons.OK, MessageBoxIcon.Information)
  337.             Return
  338.         End If
  339.  
  340.         Dim orderDetails As New StringBuilder("You are about to order the following:" & vbNewLine)
  341.  
  342.         Dim totalOrderPrice As Double = 0
  343.         For Each order In orders
  344.             orderDetails.AppendLine($"{order.Key} {order.Value.Quantity} orders = {order.Value.Price:C2}")
  345.             totalOrderPrice += order.Value.Price
  346.         Next
  347.  
  348.         orderDetails.AppendLine("---------------------------------------")
  349.         orderDetails.AppendLine($"Total = {totalOrderPrice:C2}")
  350.         orderDetails.AppendLine(vbNewLine & "Confirm?")
  351.  
  352.         Dim result As DialogResult = MessageBox.Show(orderDetails.ToString(), "Order Confirmation", MessageBoxButtons.OKCancel)
  353.  
  354.         If result = DialogResult.OK Then
  355.             ' User has confirmed the order, so we can clear the existing orders
  356.             orders.Clear()
  357.             MessageBox.Show("Your order has been placed successfully.", "Order Placed", MessageBoxButtons.OK, MessageBoxIcon.Information)
  358.             ' Reset the UI
  359.             txtCustName.Text = ""
  360.             txtPhoneNumber.Text = ""
  361.             txtAddress.Text = ""
  362.  
  363.             ' Clear and reset comboboxes
  364.             cmbPizza.SelectedIndex = -1
  365.             cmbPizza.Text = ""
  366.  
  367.             ' Reset numeric updown
  368.             numQuantity.Value = 1
  369.  
  370.             ' Uncheck checkboxes
  371.             chkCheese.Checked = False
  372.             chkToppings.Checked = False
  373.  
  374.             ' Reset radio buttons
  375.             radThin.Checked = True
  376.             radThick.Checked = False
  377.             radYes.Checked = False
  378.             radNo.Checked = True
  379.  
  380.             ' Clear rich text boxes
  381.             rtbPizzaDetails.Text = ""
  382.             rtbOrderDetails.Text = "" ' This line clears the order details
  383.  
  384.             result = MessageBox.Show("Would you like to make another order?", "New Order", MessageBoxButtons.YesNo)
  385.  
  386.             If result = DialogResult.No Then
  387.                 ' User doesn't want to make another order, so we can close the application
  388.                 Me.Close()
  389.             End If
  390.  
  391.         End If
  392.     End Sub
  393. End Class
  394.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement