private void button1_Click(object sender, EventArgs e) { TareRepository tareRepository = new TareRepository(); try { Tare newTare = new Tare(textBox1.Text, 0); tareRepository.Create(newTare); updateInformation(); MessageBox.Show("Операція успішно виконана.", "Sucsess", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Button1_Click(object sender, EventArgs e) { try { if (radioButton1.Checked) { var productRepository = new ProductRepository(); var conteinerRepository = new ConteinerRepository(); var productConteiner = productRepository.GetProductConteinerDataSource(). First(element => $"{element.Name} {element.Weight}" == comboBox1.SelectedItem.ToString()); var product = productRepository.GetDataSource().First(element => element.Name == productConteiner.Name); var conteiner = conteinerRepository.GetDataSource().First(elem => elem.ProductId == product.Id & elem.Weight == productConteiner.Weight); conteinerRepository.Remove(conteiner.Id, dateTimePicker1.Value, 1, Decimal.ToInt32(numericUpDown1.Value)); } else if (radioButton2.Checked) { var ingredientRepository = new IngredientRepository(); var packageRepository = new PackageRepository(); var ingredientPackage = ingredientRepository.GetIngredientPackageDataSource(). First(element => $"{element.Name} {element.Weight}" == comboBox1.SelectedItem.ToString()); var ingredient = ingredientRepository.GetDataSource().First(element => element.Name == ingredientPackage.Name); var conteiner = packageRepository.GetDataSource().First(elem => elem.IngredientId == ingredient.Id & elem.Weight == ingredientPackage.Weight); packageRepository.Remove(conteiner.Id, dateTimePicker1.Value, Double.Parse(maskedTextBox1.Text)); } else { TareRepository tareRepository = new TareRepository(); Tare tareForRemoving = tareRepository.GetDataSource(). First(elem => $"{elem.Name} {elem.Amount}" == comboBox1.SelectedItem.ToString()); tareForRemoving.Amount = Decimal.ToInt32(numericUpDown1.Value); tareRepository.Remove(tareForRemoving); } RadioButton1_CheckedChanged(null, null); MessageBox.Show(@"Об'єкт успішно списано.", "Sucsess", MessageBoxButtons.OK, MessageBoxIcon.Information); updateInformation(); } catch (Exception) { MessageBox.Show(@"Помилка списання", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Button1_Click(object sender, EventArgs e) { try { TareRepository tareRepository = new TareRepository(); Tare tareForAdding = tareRepository.GetDataSource().First(n => n.Name == comboBox1.SelectedItem.ToString()); tareForAdding.Amount = Decimal.ToInt32(numericUpDown1.Value); tareRepository.Add(tareForAdding); updateInformation(); MessageBox.Show(@"Тару було успішно додано.", "Sucsess", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (NullReferenceException) { MessageBox.Show($"Тару не вибрано.\nБудь ласка виберіть потрібну тару.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception exception) { //TODO: Program thrown message on english when user try to add some product. Also check this problem with ingredient. MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Button1_Click(object sender, EventArgs e) { try { if (radioButton1.Checked) { ProductRepository repos = new ProductRepository(); var product = repos.GetDataSource().First(element => element.Name == listBox1.SelectedItem.ToString()); repos.Delete(product); listBox1.DataSource = repos.GetDataSource(); updateInformation(); } else if (radioButton2.Checked) { IngredientRepository ingredientRepository = new IngredientRepository(); IngredientsForProductRepository ingredientsForProductRepository = new IngredientsForProductRepository(); Ingredient ingredient = ingredientRepository.GetDataSource().First(element => element.Name == listBox1.SelectedItem.ToString()); var receiptsWithCurrIngredient = ingredientsForProductRepository.GetDataSource().Where(n => n.IngredientId == ingredient.Id).ToList(); if (receiptsWithCurrIngredient.Count != 0) { DeleteMessage deleteMessage = new DeleteMessage(ingredient, updateInformation); deleteMessage.ShowDialog(); } else { ingredientRepository.Delete(ingredient); updateInformation(); MessageBox.Show(@"Видалення успішне.", "Sucsess", MessageBoxButtons.OK, MessageBoxIcon.Information); } RadioButton1_CheckedChanged(this, null); } else if (radioButton3.Checked) { TareRepository tareRepository = new TareRepository(); Tare tareForDeleting = tareRepository.GetDataSource().First(n => n.Name == listBox1.SelectedItem.ToString()); tareRepository.DeleteById(tareForDeleting.Id); updateInformation(); MessageBox.Show(@"Видалення успішне.", "Sucsess", MessageBoxButtons.OK, MessageBoxIcon.Information); RadioButton1_CheckedChanged(this, null); } else { ClientRepository clientRepository = new ClientRepository(); Client clientForDeleting = clientRepository.GetDataSource().First(n => n.Name == listBox1.SelectedItem.ToString()); clientRepository.DeleteById(clientForDeleting.Id); MessageBox.Show(@"Видалення успішне.", "Sucsess", MessageBoxButtons.OK, MessageBoxIcon.Information); RadioButton1_CheckedChanged(this, null); } } catch (InvalidOperationException exeption) { MessageBox.Show(exeption.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }