123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- 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.Data.SqlClient;
- namespace proba
- {
- public partial class BuyTools : Form
- {
- bool discount = false;
- public int razmer = 0;
- public static string[] buy = new string[1];
- string id_product;
- DataBase dataBase = new DataBase();
- public BuyTools(string id_product, string product, string description, string price, string year_publishing, string country, string edition, string genre, string performer, string supplier)
- {
- InitializeComponent();
- text_name.Text = product;
- text_description.Text = description;
- text_price.Text = Convert.ToString(Math.Round(Convert.ToDouble(price), 2));
- text_output.Text = text_price.Text;
- textBox_year_publishing.Text = year_publishing;
- text_country.Text = country;
- text_edition.Text = edition;
- text_genre.Text = genre;
- text_performer.Text = performer;
- text_id_suplier.Text = supplier;
- this.id_product = id_product;
- }
- private void button_back_Click(object sender, EventArgs e)
- {
- this.Hide();
- Sales sales = new Sales();
- sales.ShowDialog();
- }
- private void text_input_TextChanged(object sender, EventArgs e)
- {
- if(text_input.Text == "")
- {
- text_input.Text = "0";
- }
- text_output.Text = Convert.ToString(GetSurrender(Convert.ToDouble(text_input.Text), Convert.ToDouble(text_price.Text)));
- text_output.Text = Convert.ToString(Math.Round(Convert.ToDouble(text_output.Text), 2));
- if (Convert.ToDouble(text_input.Text) <= Convert.ToDouble(text_price.Text))
- {
- label_output1.Visible = true;
- label_output2.Visible = false;
- }
- else
- {
- label_output2.Visible = true;
- label_output1.Visible = false;
- }
- }
- private void button_buy_Click(object sender, EventArgs e)
- {
- dataBase.openConnection();
- string str = DateTime.Now.ToString("d MMMM yyyy");
- string str1;
- SqlCommand sqlCommand1 = new SqlCommand($"SELECT id_employee From Employee WHERE login = '{PosleVHODA.login}'", dataBase.GetConnection());
- str1 = sqlCommand1.ExecuteScalar().ToString();
- var addQuery = $"insert into Sales (id_product, date_sale, id_employee, summa) values ('{id_product}','{str}','{str1}', '{Convert.ToDouble(text_price.Text)}')";
- var command = new SqlCommand(addQuery, dataBase.GetConnection());
- command.ExecuteNonQuery();
- MessageBox.Show("Покупка совершена");
- Sales.countBuyProducts = GetCountBuyProducts(Sales.countBuyProducts);
- Sales.summaBuyProducts = GetSummaBuyProducts(Sales.summaBuyProducts, Convert.ToDouble(text_price.Text));
- buy[razmer] = text_name.Text;
- Array.Resize(ref buy, buy.Length + 1);
- razmer++;
- dataBase.closeConnection();
- this.Hide();
- Sales sales = new Sales();
- sales.ShowDialog();
- }
- public void global_FormClosed(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void text_input_KeyPress(object sender, KeyPressEventArgs e)
- {
- char number = e.KeyChar;
- if (!Char.IsDigit(number) && number != 8 && !(e.KeyChar == ',')) // цифры и клавиша BackSpace
- {
- e.Handled = true;
- }
- }
- public static int GetCountBuyProducts(int countBuyProducts)
- {
- countBuyProducts++;
- return countBuyProducts;
- }
- public static double GetSummaBuyProducts(double summaBuyProducts, double summa)
- {
- summaBuyProducts = summaBuyProducts + summa;
- return summaBuyProducts;
- }
- public static double ShareCount(double summa, double percent)
- {
- summa = summa - summa *(double)(percent/100);
- return summa;
- }
- public static double GetSurrender(double summaCustomer, double summaProduct)
- {
- summaProduct = summaProduct - summaCustomer;
- return summaProduct;
- }
- private void button_discount_Click(object sender, EventArgs e)
- {
- if (text_discount.Text == "")
- {
- MessageBox.Show("Поле скидка не заполнено");
- }
- else if (text_discount.Text == "0")
- {
- MessageBox.Show("Скидка не может быть равна 0");
- }
- else if (Convert.ToDouble(text_discount.Text) > 100)
- {
- MessageBox.Show("Скидка не может быть больше 100%");
- }
- else if (discount == true)
- {
- var confirmResult = MessageBox.Show("Вы точно хотите применить скидку?\nСкидка будет применена к уже уценённому товару", "Подтвердите применение скидки!", MessageBoxButtons.YesNo);
- if (confirmResult == DialogResult.Yes)
- {
- text_price.Text = Convert.ToString(ShareCount(Convert.ToDouble(text_price.Text), Convert.ToDouble(text_discount.Text)));
- text_price.Text = Convert.ToString(Math.Round(Convert.ToDouble(text_price.Text), 2));
- showDiscount.Visible = true;
- showDiscount.Text = showDiscount.Text + "+" + text_discount.Text + "%";
- text_discount.Text = "";
- }
- }
- else
- {
- text_price.Text = Convert.ToString(ShareCount(Convert.ToDouble(text_price.Text), Convert.ToDouble(text_discount.Text)));
- text_price.Text = Convert.ToString(Math.Round(Convert.ToDouble(text_price.Text), 2));
- showDiscount.Visible = true;
- showDiscount.Text = showDiscount.Text + text_discount.Text + "%";
- text_discount.Text = "";
- discount = true;
- }
- text_input_TextChanged(sender, e);
- }
- private void text_discount_KeyPress(object sender, KeyPressEventArgs e)
- {
- char number = e.KeyChar;
- if (!Char.IsDigit(number) && number != 8 && !(e.KeyChar == ',')) // цифры и клавиша BackSpace
- {
- e.Handled = true;
- }
- }
- }
- }
|