478 lines
15 KiB
C#
478 lines
15 KiB
C#
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;
|
|
|
|
namespace VendingMachine
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
Automat vendor;
|
|
Portfel wallet;
|
|
Produkt[] products = { new Produkt("Pepsi", 2.0f), new Produkt("Coca-Cola", 2.50f), new Produkt("M&Ms", 3.50f), new Produkt("Grzesiek", 1.89f), new Produkt("Prince Polo", 3.50f),
|
|
new Produkt("7 Days", 3.80f), new Produkt("Oshee", 1.50f), new Produkt("Żywiec zdrój", 3.50f), new Produkt("Tiger", 2.0f), new Produkt("WW", 2.0f),
|
|
new Produkt("Bułka z serem", 1.20f), new Produkt("Bułka z szynką", 1.7f), new Produkt("Corny", 2.30f), new Produkt("Lay's", 2.89f), new Produkt("Jeżyki", 3.20f),
|
|
new Produkt("Maxi King", 3.10f), new Produkt("Cappy", 2.70f), new Produkt("7Up", 2.10f), new Produkt("Monster", 4.0f), new Produkt("Snickers", 2.5f)};
|
|
List<Button> buttonGroup;
|
|
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
wallet = new Portfel(300.50f);
|
|
vendor = new Automat(products,wallet);
|
|
buttonGroup = new List<Button> { button2, button3, button4, button5, button6,button7, button8, button9,
|
|
button10, button11, button12, button13, button14, button15, button16,
|
|
button17, button18, button19, button20, button21};
|
|
int i = 0;
|
|
foreach (Button j in buttonGroup)
|
|
{
|
|
j.Text = products[i].getNazwa() + "\n" + products[i].getCena().ToString() + " zł";
|
|
i++;
|
|
}
|
|
balanceBox.Text = vendor.getBalance().ToString() + " zł";
|
|
screen.Text = "Zapraszamy do zakupów";
|
|
}
|
|
|
|
private void label2_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
vendor.setBalance(vendor.getBalance() + 0.5f);
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[0], wallet);
|
|
if(res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if(res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void fiveButton_Click(object sender, EventArgs e)
|
|
{
|
|
vendor.setBalance(vendor.getBalance() + 5);
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void twoButton_Click(object sender, EventArgs e)
|
|
{
|
|
vendor.setBalance(vendor.getBalance() + 2);
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void oneButton_Click(object sender, EventArgs e)
|
|
{
|
|
vendor.setBalance(vendor.getBalance() + 1);
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void twentyButton_Click(object sender, EventArgs e)
|
|
{
|
|
vendor.setBalance(vendor.getBalance() + 0.2f);
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button1_Click_1(object sender, EventArgs e)
|
|
{
|
|
vendor.setBalance(vendor.getBalance() + 0.1f);
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button22_Click(object sender, EventArgs e)
|
|
{
|
|
vendor.restock();
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[1], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button4_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[2], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button5_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[3], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button9_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[4], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button8_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[5], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button7_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[6], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button6_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[7], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button10_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[8], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button11_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[9], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button12_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[10], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button13_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[11], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button14_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[12], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button15_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[13], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button16_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[14], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button17_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[15], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button18_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[16], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button19_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[17], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button20_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[18], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void button21_Click(object sender, EventArgs e)
|
|
{
|
|
float res = vendor.buyProduct(products[19], wallet);
|
|
if (res == -1)
|
|
{
|
|
screen.Text = "Zbyt niski stan konta.";
|
|
}
|
|
else if (res == -2)
|
|
{
|
|
screen.Text = "Brakuje produktu.";
|
|
}
|
|
else
|
|
{
|
|
restBox.Text = res + " zł";
|
|
screen.Text = "Pomyślnie kupiono produkt.";
|
|
}
|
|
balanceBox.Text = vendor.getBalance() + " zł";
|
|
}
|
|
|
|
private void cardButton_Click(object sender, EventArgs e)
|
|
{
|
|
vendor.setCard(true);
|
|
}
|
|
}
|
|
}
|