private void button2_Click(object sender, EventArgs e) { //write from list cashier to xml string name = ""; double newCountProductSell = 0.00, newCountProduct = 0.00; foreach (DataGridViewRow row in dataGridView1.Rows) { if (Products.First(it => it.Name == row.Cells[0].Value.ToString()).CountMarket < Convert.ToDouble(row.Cells[2].Value.ToString())) { MessageBox.Show("Товара " + row.Cells[0].Value.ToString() + " недостаточно в магазине", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); continue; } // ProductsSell.First(it => it.Name == row.Cells[0].Value.ToString()).CountSell+=Convert.ToDouble(row.Cells[2].Value.ToString()); // Products.First(it => it.Name == row.Cells[0].Value.ToString()).CountMarket -= Convert.ToDouble(row.Cells[2].Value.ToString()); name = row.Cells[0].Value.ToString(); newCountProductSell = ProductsSell.First(it => it.Name == row.Cells[0].Value.ToString()).CountSell += Convert.ToDouble(row.Cells[2].Value.ToString()); newCountProduct = Products.First(it => it.Name == row.Cells[0].Value.ToString()).CountMarket -= Convert.ToDouble(row.Cells[2].Value.ToString()); HelperProductSell.UpdateCountToSql(name, newCountProductSell); HelperProduct.UpdateCountToSql(name, newCountProduct); } // HelperProductSell.SaveFromFile(ProductsSell); // HelperProduct.SaveUsersFromFile(Products); Products.ForEach(UpdateProduct); }
private void dataGridView1ReLoad() { double totalCost = 0; double totalProfit = 0; // Products = HelperProduct.LoadUsersFromFile(); Products = HelperProduct.LoadFromSql(); dataGridView1.Rows.Clear(); foreach (var item in Products) { dataGridView1.Rows.Add(item.setGridView1()); totalCost += (item.CountWarehouse + item.CountMarket) * item.Price; totalProfit += (item.CountWarehouse + item.CountMarket) * item.Price - (item.CountWarehouse + item.CountMarket) * item.PricePurchasing; } textBoxTotalCost.Text = totalCost.ToString() + " " + "руб."; textBoxTotalProfit.Text = totalProfit.ToString() + " " + "руб."; }
private void button2_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { foreach (DataGridViewRow row in dataGridView1.SelectedRows) { // MessageBox.Show(Products.First(it => it.Name == row.Cells[0].Value.ToString()).Name); // Products.Remove(Products.First(it => it.Name == row.Cells[0].Value.ToString())); HelperProduct.DeleteFromSql(row.Cells[0].Value.ToString()); } // HelperProduct.SaveUsersFromFile(Products); dataGridView1ReLoad(); } else { MessageBox.Show("Вы не выбрали строку с товаром для удаления", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void Cashier_Load(object sender, EventArgs e) { //Products = HelperProduct.LoadUsersFromFile(); Products = HelperProduct.LoadFromSql(); // for first creating file xml //Products.ForEach(it => { ProductSell pr = new ProductSell(); pr.Name = it.Name; pr.PriceSell = it.Price; pr.PriceBuy = it.PricePurchasing; pr.CountSell = 0; ProductsSell.Add(pr); }); //HelperProductSell.SaveFromFile(ProductsSell); //ProductsSell = HelperProductSell.LoadFromFile(); ProductsSell = HelperProductSell.LoadFromSql(); //int countEquals; foreach (Product product in Products) { // countEquals = 0; if (ProductsSell.Any(it => it.Name == product.Name)) { // countEquals++; continue; } HelperProductSell.InsertToSql(product); /*foreach (ProductSell productSell in ProductsSell) * { * if(product.Name == productSell.Name) * { * countEquals++; * } * }*/ /* if (countEquals == 0) * { * ProductSell prSell = new ProductSell(); * prSell.Name = product.Name; * prSell.PriceBuy = product.PricePurchasing; * prSell.PriceSell = product.Price; * prSell.CountSell = 0; * prSell.UoM = product.UoM; * ProductsSell.Add(prSell); * }*/ } // HelperProductSell.SaveFromFile(ProductsSell); ProductsSell = HelperProductSell.LoadFromSql(); }
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 if (!Products.Any(it => it.Name == textBox3.Text)) { Product pr = new Product(); pr.Name = textBox3.Text; pr.Price = (float)Convert.ToDouble(textBox5.Text); pr.PricePurchasing = (float)Convert.ToDouble(textBox4.Text); pr.UoM = (UoM)Enum.Parse(typeof(UoM), comboBox1.Text); if (comboBox2.Text == "Warehouse") { pr.CountWarehouse = Convert.ToDouble(textBox6.Text); } else if (comboBox2.Text == "Shop") { pr.CountMarket = Convert.ToDouble(textBox6.Text); } else { MessageBox.Show("Некорректно выбран склад"); } //Products.Add(pr); //HelperProduct.SaveUsersFromFile(Products); // this.Update(); // it doesn't work HelperProduct.InsertToSql(pr); dataGridView1ReLoad(); } else { MessageBox.Show("Товар с таким именем уже есть на складе"); } }