private void editButton_Click(object sender, EventArgs e) { DialogResult result = CommonUserInteractionMethods.ConfirmAction(Constants.ConfirmMealEditMеssage); if (result.Equals(DialogResult.OK)) { SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen"); using (connection) { try { SqlCommand productEditCommand = CreateMealEditCommand(connection); connection.Open(); SqlDataReader reader = productEditCommand.ExecuteReader(); MessageBox.Show(Constants.MealEditеdSuccessfullyMеssage); } catch (FormatException formatException) { MessageBox.Show(Constants.InvalidMealDataFormat); } catch (SqlException se) { MessageBox.Show(se.ToString()); } finally { connection.Close(); } } } }
private void deleteButton_Click(object sender, EventArgs e) { DialogResult result = CommonUserInteractionMethods.ConfirmAction(Constants.ConfirmDeleteProductMessage); if (result.Equals(DialogResult.OK)) { SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen"); using (connection) { SqlCommand productInsertionCommand = CreateProductDeleteCommand(connection); try { connection.Open(); SqlDataReader reader = productInsertionCommand.ExecuteReader(); MessageBox.Show(Constants.ProductDeletedSuccessfullyMessage); } catch (SqlException se) { MessageBox.Show(se.ToString()); } finally { connection.Close(); } } } }
private void deleteProductButton_Click(object sender, EventArgs e) { newProductPanel.Hide(); SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen"); DialogResult result = CommonUserInteractionMethods.ConfirmAction( Constants.ConfirmDeleteRecipeProductMesssage); if (result.Equals(DialogResult.OK)) { using (connection) { try { SqlCommand deleteRecipeProductCommand = CreateDeleteRecipeProductCommand(connection); connection.Open(); deleteRecipeProductCommand.ExecuteNonQuery(); MessageBox.Show(Constants.RecipeProductDeletedSuccessfullyMessage); FillRecipeProductsTable(); } catch (SqlException sqlException) { MessageBox.Show(sqlException.ToString()); } } } }
private void addProductButton_Click(object sender, EventArgs e) { DialogResult result = CommonUserInteractionMethods.ConfirmAction(Constants.ConfirmAddProductToRecipeMessage); if (result.Equals(DialogResult.OK)) { SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen"); using (connection) { try { SqlCommand addProductToRecipeCommand = CreateAddProductToRecipeCommand(connection); connection.Open(); addProductToRecipeCommand.ExecuteNonQuery(); MessageBox.Show(Constants.ProductDeletedFromRecipeSuccessfullyMessage); FillRecipeProductsTable(); } catch (FormatException formatException) { MessageBox.Show(Constants.InvalidRecipeProductDataMessage); quantity.Clear(); } catch (SqlException se) { MessageBox.Show(se.ToString()); } } } }
private void newRecipeButton_Click(object sender, EventArgs e) { DialogResult result = CommonUserInteractionMethods.ConfirmAction(Constants.ConfirmInsertNewRecipeMessage); if (result.Equals(DialogResult.OK)) { bool isValidRecipeProductData = ValidateRecipeData(); if (isValidRecipeProductData) { SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen"); try { SqlCommand insertNewRecipeCommand = CreateInsertNewRecipeCommand(connection); using (connection) { connection.Open(); insertNewRecipeCommand.ExecuteNonQuery(); MessageBox.Show(Constants.RecipeInsertedSuccessfullyMessage); this.Close(); } } catch (FormatException formatException) { MessageBox.Show(Constants.InvalidRecipeProductQuantityMessage); } catch (SqlException sqlException) { MessageBox.Show(sqlException.ToString()); } } } }
private void deleteButton_Click(object sender, EventArgs e) { DialogResult result = CommonUserInteractionMethods.ConfirmAction(Constants.ConfimrDeleteMealMessage); if (result.Equals(DialogResult.OK)) { SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen"); using (connection) { SqlCommand mealDeleteCommand = CreateMealDeleteCommand(connection); try { connection.Open(); SqlDataReader reader = mealDeleteCommand.ExecuteReader(); MessageBox.Show(Constants.MealDeletedSuccessfullyMessage); this.mealsTableAdapter.Fill(this.canteenDataSet.Ястия); } catch (SqlException se) { MessageBox.Show(se.ToString()); } finally { connection.Close(); } } } }
private void newMealButton_Click(object sender, System.EventArgs e) { bool isValidMealData = ValidateMealData(); if (isValidMealData) { DialogResult confirmResult = CommonUserInteractionMethods.ConfirmAction(Constants.ConfirmCreateNewMealMessage); if (confirmResult.Equals(DialogResult.OK)) { SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen"); using (connection) { try { SqlCommand mealInsertionCommand = CreateMealInsertionCommand(connection); using (mealInsertionCommand) { connection.Open(); mealInsertionCommand.ExecuteNonQuery(); MessageBox.Show(Constants.NewMealCreatedSuccessfullyMessage); mealName.Clear(); quantity.Clear(); calories.Clear(); type.Clear(); portions.Clear(); connection.Close(); } } catch (FormatException) { MessageBox.Show(Constants.InvalidMealDataFormat); } catch (SqlException se) { MessageBox.Show(se.ToString()); } finally { connection.Close(); } } } } }
private void newProductButton_Click(object newProductButtonSender, EventArgs e) { bool isValidProductData = ValidateProductData(); if (isValidProductData) { DialogResult confirmResult = CommonUserInteractionMethods.ConfirmAction(Constants.ConfirmCreateNewProductMessage); if (confirmResult.Equals(DialogResult.OK)) { SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen"); using (connection) { SqlCommand productInsertionCommand = CreateProductInsertionCommand(connection); try { using (productInsertionCommand) { connection.Open(); productInsertionCommand.ExecuteNonQuery(); MessageBox.Show(Constants.NewProductCreatedSuccessfullyMessage); productName.Clear(); measurementUnit.Clear(); connection.Close(); } } catch (SqlException se) { MessageBox.Show(se.ToString()); } finally { connection.Close(); } } } } }
private void deleteRecipeButton_Click(object sender, EventArgs e) { DialogResult result = CommonUserInteractionMethods.ConfirmAction(Constants.ConfirmDeleteRecipeMessage); if (result.Equals(DialogResult.OK)) { SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen"); SqlCommand deleteRecipeCommand = CreateDeleteRecipeCommand(connection); try { using (connection) { connection.Open(); deleteRecipeCommand.ExecuteNonQuery(); MessageBox.Show(Constants.RecipeDeletedSuccessfullyMessage); BindRecipesData(); } } catch (SqlException sqlException) { MessageBox.Show(sqlException.ToString()); } } }