private void dataGridView1ReLoad()
        {
            double totalCost   = 0;
            double totalProfit = 0;

            // Products = HelperProduct.LoadUsersFromFile();
            Products       = BridgeToBD.LoadProductShopFromDB(TypeBD.SQL);
            ProductsMoving = BridgeToBD.LoadProductMovingFromDB(TypeBD.SQL);
            string[] str = new string[7];
            dataGridView1.Rows.Clear();
            foreach (var item in Products)
            {
                str[0] = item.Name;
                str[1] = ProductsMoving.First(it => it.IDproduct == item.ID).CountStore.ToString();
                str[2] = ProductsMoving.First(it => it.IDproduct == item.ID).CountShop.ToString();
                str[3] = item.PriceBuy.ToString();
                str[4] = item.PriceSell.ToString();
                str[5] = ((double.Parse(str[1]) + double.Parse(str[2])) * double.Parse(str[4])).ToString();
                str[6] = ((double.Parse(str[1]) + double.Parse(str[2])) * (double.Parse(str[4]) - double.Parse(str[3]))).ToString();
                dataGridView1.Rows.Add(str);
                totalCost   += double.Parse(str[5]);
                totalProfit += double.Parse(str[6]);
            }
            textBoxTotalCost.Text   = totalCost.ToString() + " " + "руб.";
            textBoxTotalProfit.Text = totalProfit.ToString() + " " + "руб.";
        }
        private void dataGridView2ReLoad()
        {
            double totalCost   = 0;
            double totalProfit = 0;

            BridgeToBD.LoadProductShopFromDB(BridgeToBD.ChoiceBD);
            BridgeToBD.LoadProductMovingFromDB(BridgeToBD.ChoiceBD);
            string[] str    = new string[6];
            double[] result = new double[3];
            dataGridView2.Rows.Clear();
            foreach (var item in BridgeToBD.Products)
            {
                str[0]    = item.Name;
                str[1]    = BridgeToBD.ProductsMoving.First(it => it.IDproduct == item.ID).Sold.ToString() + " " + item.UoM.GetDescription();
                result[0] = BridgeToBD.ProductsMoving.First(it => it.IDproduct == item.ID).Sold;
                str[2]    = item.PriceSell.ToString();
                str[3]    = item.PriceBuy.ToString();
                str[4]    = (result[0] * double.Parse(str[2])).ToString();
                result[1] = (result[0] * double.Parse(str[2]));
                str[5]    = ((double.Parse(str[2]) - double.Parse(str[3])) * result[0]).ToString();
                result[2] = ((double.Parse(str[2]) - double.Parse(str[3])) * result[0]);
                dataGridView2.Rows.Add(str);
                totalCost   += result[1];
                totalProfit += result[2];
            }
            textBox1.Text = totalCost.ToString() + " " + "руб.";
            textBox2.Text = totalProfit.ToString() + " " + "руб.";
        }
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || comboBox1.Text == "" || comboBox2.Text == "")
     {
         MessageBox.Show("Вы не заполнили некоторые поля", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return;
     }
     // it need to check name
     Products       = BridgeToBD.LoadProductShopFromDB(TypeBD.SQL);
     ProductsMoving = BridgeToBD.LoadProductMovingFromDB(TypeBD.SQL);
     if (!Products.Any(it => it.Name == textBox3.Text))
     {
         ProductShop pr = new ProductShop();
         pr.ID        = Products.Last().ID + 1;
         pr.Name      = textBox3.Text;
         pr.PriceSell = (float)Convert.ToDouble(textBox5.Text);
         pr.PriceBuy  = (float)Convert.ToDouble(textBox4.Text);
         pr.UoM       = (UoM)Enum.Parse(typeof(UoM), comboBox1.Text);
         ProductMoving prmove = new ProductMoving();
         prmove.IDproduct = pr.ID;
         prmove.Sold      = 0;
         if (comboBox2.Text == "Warehouse")
         {
             prmove.CountStore = Convert.ToDouble(textBox6.Text);
         }
         else if (comboBox2.Text == "Shop")
         {
             prmove.CountShop = Convert.ToDouble(textBox6.Text);
         }
         else
         {
             MessageBox.Show("Некорректно выбран склад");
         }
         Products.Add(pr);
         ProductsMoving.Add(prmove);
         //HelperProduct.SaveUsersFromFile(Products);
         // this.Update(); // it doesn't work
         //HelperProduct.InsertToSql(pr);
         BridgeToBD.SaveProductShopToBD(Products, TypeBD.SQL);
         BridgeToBD.SaveProductMovingToSQL(ProductsMoving);
         dataGridView1ReLoad();
     }
     else
     {
         MessageBox.Show("Товар с таким именем уже есть на складе");
     }
 }
 private void button2_Click(object sender, EventArgs e)
 {
     BridgeToBD.LoadProductShopFromDB(BridgeToBD.ChoiceBD);
     BridgeToBD.LoadProductMovingFromDB(BridgeToBD.ChoiceBD);
     foreach (DataGridViewRow row in dataGridView1.Rows)
     {
         var product       = BridgeToBD.Products.First(it => it.Name == row.Cells[0].Value.ToString());
         var productMoving = BridgeToBD.ProductsMoving.First(it => it.IDproduct == product.ID);
         if (productMoving.CountShop < Convert.ToDouble(row.Cells[2].Value.ToString()))
         {
             MessageBox.Show("Товара " + row.Cells[0].Value.ToString() + " недостаточно в магазине", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             continue;
         }
         productMoving.CountShop -= Convert.ToDouble(row.Cells[2].Value.ToString());
         productMoving.Sold      += Convert.ToDouble(row.Cells[2].Value.ToString());
         BridgeToBD.SaveProductMovingToBD(productMoving, BridgeToBD.ChoiceBD);
     }
     panel1.Visible = false;
 }
 private void Cashier_Load(object sender, EventArgs e)
 {
     BridgeToBD.LoadProductShopFromDB(BridgeToBD.ChoiceBD);
     BridgeToBD.LoadProductMovingFromDB(BridgeToBD.ChoiceBD);
 }