namespace WinFormsApp1
{
public partial class Form1 : Form
{
public class Order
{
public string name { get; set; } = null;
public string size { get; set; } = null;
public string additives { get; set; } = null;
public double cost { get; set; } = 0;
public double kef { get; set; } = 0;
}
public Dictionary<string, int> Costs = new Dictionary<string, int>();
public Dictionary<string, double> Sizes = new Dictionary<string, double>();
public Form1()
{
InitializeComponent();
InitCosts();
InitSizes();
dataGridView1.AutoGenerateColumns = false;
dataGridView1.Columns.Add("name", "Название");
dataGridView1.Columns.Add("size", "Размер");
dataGridView1.Columns.Add("additives", "Добавки");
dataGridView1.Columns.Add("endCost", "Конечная цена");
}
private void InitCosts()
{
Costs.Add("Сыр", 100);
Costs.Add("Сироп", 75);
Costs.Add("Бекон", 150);
Costs.Add("Кетчуп", 50);
}
private void InitSizes()
{
Sizes.Add("S", 1.0);
Sizes.Add("M", 1.5);
Sizes.Add("L", 2.0);
}
private double getCost(Order order)
{
int cost = 0;
double kef = 1;
if (order.size == "S") { kef = 1; }
else if (order.size == "M") { kef = 1.5; }
else { kef = 2; }
if (order.additives == "Сироп") { cost += 100; }
else if (order.additives == "Сыр") { cost += 75; }
else if (order.additives == "Бекое") { cost += 125; }
else if (order.additives == "С собой") { cost += 0; }
return cost * kef;
}
private void showGridView(Order order)
{
double cost = getCost(order);
dataGridView1.Rows.Add(order.name, order.size, order.additives, cost);
}
private void saveOrder(object sender, EventArgs e)
{
if (textBox1.Text.Trim() == "")
{
MessageBox.Show("Введите название блюда/напитка!", MessageBoxButtons.OK.ToString());
}
string name = textBox1.Text;
string size = "";
if(radioButton1.Checked == true)
{
size = "S";
}
else if(radioButton2.Checked == true)
{
size = "M";
}
else if(radioButton3.Checked == true)
{
size = "L";
}
else
{
MessageBox.Show("Введите размер!", MessageBoxButtons.OK.ToString());
}
string additives = "";
if(checkBox1.Checked == true)
{
additives = "Сироп";
}
else if(checkBox2.Checked == true)
{
additives = "Сыр";
}
else if(checkBox3.Checked == true)
{
additives = "Бекон";
}
else if(checkBox4.Checked == true)
{
additives = "С собой";
}
else
{
additives = "Ничего";
}
Order order = new Order();
order.name = name;
order.size = size;
order.additives = additives;
showGridView(order);
}
}
}