Group Project 2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace project1
{
enum Jobs
{
Chef, Cashier
}
public partial class AwsomePizzaForm : Form
{
// project1 3 Requirements
// x Add Arrays to store the pizza prices(You may use parallel arrays to store the name of the pizza and prices)
// x Use a button, when the user clicks on the button it shows the cheapest pizza name and price.For finding the cheapest price use the array and let the system search it.
// x Use Enumerated data type.
// • Use ImageList.
// x Add more features of your choice.
const double TAX = 0.08;
double subtotal;
double total;
string[] pizzaName = { "Pepperoni Pizza", "Mushroom Pizza", "Meat Lovers Pizza", "Supreme Pizza" };
double[] pizzaPrice = { 10.00, 11.00, 12.00, 13.50 };
string[] saladName = { "Caesar Salad", "Garden Salad", "Seafood Salad", "Side Salad" };
double[] saladPrice = { 8.00, 8.00, 12.00, 4.50 };
//var ordered = new List<int>();
public AwsomePizzaForm()
{
InitializeComponent();
prepareMenu();
panel_receipt.Visible = false;
}
public void prepareMenu()
{
//loop through labels in pizza panel and apply name/pizza from array to each label
int i = 0;
foreach (Control theLabel in panel_MenuPizza.Controls)
{
if (theLabel is Label)
{
theLabel.Text = pizzaName[i] + " $" + pizzaPrice[i];
}
i++;
}
//loop through labels in salad panel and apply name/pizza from array to each label
int j = 0;
foreach (Control theLabel in panel_MenuSalad.Controls)
{
if (theLabel is Label)
{
theLabel.Text = saladName[j] + " $" + saladPrice[j];
}
j++;
}
}
private void addPizza(int itemIn)
{
//ordered.Add(itemIn);
lb_orderQuantity.Items.Add(pizzaName[itemIn] + " $" + pizzaPrice[itemIn]);
}
private void addSalad (int itemIn)
{
//ordered.Add(itemIn);
lb_orderQuantity.Items.Add(saladName[itemIn] + " $" + saladPrice[itemIn]);
}
private double calculate_tax()
{
return subtotal * TAX;
}
private double calculate_total()
{
return subtotal + calculate_tax();
}
private int randomNumber()
{
Random rand = new Random();
int number = rand.Next(100);
return number;
}
private void calculateSubtotal()
{
subtotal = 0;
foreach (var listBoxItem in lb_orderQuantity.Items)
{
//MessageBox.Show(listBoxItem.ToString());
string item = listBoxItem.ToString().Substring(0, 3);
switch (item)
{
case "Pep": subtotal = subtotal + pizzaPrice[0]; break;
case "Mus": subtotal = subtotal + pizzaPrice[1]; break;
case "Mea": subtotal = subtotal + pizzaPrice[2]; break;
case "Sup": subtotal = subtotal + pizzaPrice[3]; break;
case "Cae": subtotal = subtotal + saladPrice[0]; break;
case "Gar": subtotal = subtotal + saladPrice[1]; break;
case "Sea": subtotal = subtotal + saladPrice[2]; break;
case "Sid": subtotal = subtotal + saladPrice[3]; break;
}
}
panel_receipt.Visible = true;
}
private void generateReceipt()
{
ReceiteLabel.Text = "Sub Total: $" + subtotal + "
Tax: $" + calculate_tax() + "
Total: $" + calculate_total();
}
private void enumeratedPart()
{
}
//-------
private void chefJobButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Congradulations! You have applied for chef job");
}
private void cashierJobButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Congradulations! You have applied for cashier job");
}
private void applyButton_Click(object sender, EventArgs e)
{
//Apply to positions button
if (jobOpeningListBox.SelectedIndex != -1)
{
MessageBox.Show("Congratulations! You applied to the " + jobOpeningListBox.SelectedItem.ToString() + " position"); //Job Application message
}
else
{
MessageBox.Show("Please select a job opening."); //error message
}
}
private void exitButton_Click(object sender, EventArgs e)
{
//Close program
this.Close();
}
private void button_calculateButton_Click(object sender, EventArgs e)
{
calculateSubtotal();
generateReceipt();
Random rand = new Random();
int index = rand.Next(imageList_pizza.Images.Count);
pictureBox_pizza.Image = imageList_pizza.Images[index];
}
private void button_remove_Click(object sender, EventArgs e)
{
if (lb_orderQuantity.SelectedIndex != -1)
{
lb_orderQuantity.Items.Remove(lb_orderQuantity.SelectedItem);
}
else
{
MessageBox.Show("Please select the item you want to remove.");
}
}
private void button_prize_Click(object sender, EventArgs e)
{
int rando = randomNumber();
if (rando == 12)
{
label_enterToWin.Text = "You won a free pizza!";
} else
{
label_enterToWin.Text = "Sorry your number " + rando + " did not win";
}
}
private void button_credit_Click(object sender, EventArgs e)
{
// MessageBox.Show("This will show a message from the file credit.txt");
try
{
string credits;
StreamReader inputFile;
inputFile = File.OpenText("credits.txt");
credits = inputFile.ReadLine();
while (!inputFile.EndOfStream)
{
credits += "
" + inputFile.ReadLine();
}
MessageBox.Show(credits);
inputFile.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button_clear2_Click(object sender, EventArgs e)
{
ReceiteLabel.Text = "";
lb_orderQuantity.Items.Clear();
panel_receipt.Visible = false;
}
private void label_aboutus_Click(object sender, EventArgs e)
{
}
private void tabPage2_Click(object sender, EventArgs e)
{
}
private void label_menuItem1_Click(object sender, EventArgs e)
{
addPizza(3);
}
private void label_menuItem2_Click(object sender, EventArgs e)
{
addPizza(2);
}
private void label_menuItem3_Click(object sender, EventArgs e)
{
addPizza(1);
}
private void label_menuItem4_Click(object sender, EventArgs e)
{
addPizza(0);
}
private void label4_Click(object sender, EventArgs e)
{
addSalad(3);
}
private void label3_Click(object sender, EventArgs e)
{
addSalad(2);
}
private void label2_Click(object sender, EventArgs e)
{
addSalad(1);
}
private void label1_Click(object sender, EventArgs e)
{
addSalad(0);
}
private void panel_receipt_Paint(object sender, PaintEventArgs e)
{
}
private void tabPage1_Click(object sender, EventArgs e)
{
}
private void label_job1_Click(object sender, EventArgs e)
{
displayJob(Jobs.Chef);
}
private void displayJob(Jobs job)
{
label_jobDisplay.Text = "Congratulations, you applied to " + job.ToString() + "job.";
}
private void label_job2_Click(object sender, EventArgs e)
{
displayJob(Jobs.Cashier);
}
private void button_cheapest_Click(object sender, EventArgs e)
{
findCheapest();
}
private void findCheapest()
{
double cheapest = pizzaPrice.Min();
int index = 0;
double min = pizzaPrice[0];
for (int i = 1; i < pizzaPrice.Length; i++)
{
if (pizzaPrice[i] < min)
{
min = pizzaPrice[i];
index = i;
}
}
MessageBox.Show("The cheapest pizza is " + pizzaName[index] + " for " + pizzaPrice[index].ToString("c"));
}
}
}