Exemple #1
0
        private void FillProductComboBox()
        {
            SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen");
            SqlCommand    getAvailableProductsCommand = new SqlCommand("GetAvailableRecipeProducts", connection);

            getAvailableProductsCommand.CommandType = CommandType.StoredProcedure;
            getAvailableProductsCommand.CommandText = "GetAvailableRecipeProducts";

            SqlParameter RecipeCode = new SqlParameter("@recipeCode", DbType.Int32);

            RecipeCode.Value = recipe.SelectedValue;
            getAvailableProductsCommand.Parameters.Add(RecipeCode);

            using (connection)
            {
                try
                {
                    connection.Open();
                    SqlDataReader reader    = getAvailableProductsCommand.ExecuteReader();
                    DataTable     dataTable = new DataTable();
                    dataTable.Load(reader);
                    product.DisplayMember = "Наименование";
                    product.ValueMember   = "Код";
                    product.DataSource    = dataTable;
                }
                catch (SqlException se)
                {
                    MessageBox.Show(se.ToString());
                }
            }
        }
Exemple #2
0
        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());
                    }
                }
            }
        }
Exemple #3
0
        private void registerButton_Click(object sender, EventArgs e)
        {
            bool isValidUSerData = ValidateUserData();

            if (isValidUSerData)
            {
                SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen");
                using (connection)
                {
                    SqlCommand registerCommand = CreateRegisterCommand(connection);
                    try
                    {
                        connection.Open();
                        SqlDataReader reader = registerCommand.ExecuteReader();
                        int           authenticationResult = (Int32)registerCommand.Parameters["@ProcedureResult"].Value;
                        if (authenticationResult != -1)
                        {
                            MessageBox.Show(Constants.SuccessfulRegisterMessage);
                            Login.Username = username.Text;
                            Login.Password = password.Text;
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show(Constants.UsernameTakenMessage);
                        }
                    }
                    catch (SqlException sqlException)
                    {
                        MessageBox.Show(sqlException.ToString());
                    }
                }
            }
        }
Exemple #4
0
        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();
                    }
                }
            }
        }
Exemple #5
0
        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();
                    }
                }
            }
        }
Exemple #6
0
        private void enterButton_Click(object enterButtonSender, EventArgs e)
        {
            bool isValidUserData = ValidateUserData();

            if (isValidUserData)
            {
                SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen");
                using (connection)
                {
                    SqlCommand authenticationCommand = CreateAuthenticationCommand(connection);
                    try
                    {
                        connection.Open();
                        SqlDataReader reader = authenticationCommand.ExecuteReader();
                        int           authenticationResult = (Int32)authenticationCommand.Parameters["@result"].Value;
                        if (authenticationResult != -1)
                        {
                            this.Hide();
                            var mainScreen = new MainScreen();
                            // Ensure that the current open form will close when main screen is closed
                            mainScreen.Closed += (sender, args) => this.Close();
                            mainScreen.Show();
                        }
                        else
                        {
                            MessageBox.Show(Constants.InvalidLoginDataMessage);
                        }
                    }
                    catch (SqlException se)
                    {
                        MessageBox.Show(se.ToString());
                    }
                }
            }
        }
Exemple #7
0
        private void searchButton_Click(object sender, System.EventArgs e)
        {
            SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen");

            using (connection)
            {
                SqlCommand productEditCommand = CreateSearchProductsCommand(connection);
                try
                {
                    connection.Open();
                    SqlDataReader reader = productEditCommand.ExecuteReader();
                    productsTable.DataSource = null;
                    if (reader.HasRows)
                    {
                        DataTable dataTable = new DataTable();
                        dataTable.Load(reader);
                        productsTable.DataSource = dataTable;
                    }
                }
                catch (SqlException se)
                {
                    MessageBox.Show(se.ToString());
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Exemple #8
0
        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());
                    }
                }
            }
        }
Exemple #9
0
        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();
                    }
                }
            }
        }
Exemple #10
0
        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());
                    }
                }
            }
        }
Exemple #11
0
        private void FillProductsComboBox()
        {
            SqlConnection connection         = CommonDatabaseActions.CreateDatabaseConnection("Canteen");
            SqlCommand    getProductsCommand = new SqlCommand("GetProducts", connection);

            getProductsCommand.CommandType = CommandType.StoredProcedure;
            getProductsCommand.CommandText = "GetProducts";
            using (connection)
            {
                try
                {
                    connection.Open();
                    SqlDataReader reader    = getProductsCommand.ExecuteReader();
                    DataTable     dataTable = new DataTable();
                    dataTable.Load(reader);
                    products.DisplayMember = "Наименование";
                    products.ValueMember   = "Код";
                    products.DataSource    = dataTable;
                }
                catch (SqlException se)
                {
                    MessageBox.Show(se.ToString());
                }
            }
        }
Exemple #12
0
        private DataTable GetRecipes()
        {
            SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen");
            SqlCommand    getRecipes = new SqlCommand("GetRecipes", connection);

            getRecipes.CommandType = CommandType.StoredProcedure;
            getRecipes.CommandText = "GetRecipes";

            try
            {
                using (connection)
                {
                    connection.Open();
                    SqlDataReader reader    = getRecipes.ExecuteReader();
                    DataTable     dataTable = new DataTable();
                    dataTable.Load(reader);
                    return(dataTable);
                }
            }
            catch (SqlException sqlException)
            {
                MessageBox.Show(sqlException.ToString());
                throw;
            }
        }
Exemple #13
0
        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();
                        }
                    }
                }
            }
        }
Exemple #14
0
        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();
                        }
                    }
                }
            }
        }
Exemple #15
0
        private void editRecipeProductButton_Click(object sender, System.EventArgs e)
        {
            SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen");

            using (connection)
            {
                try
                {
                    SqlCommand editrRecipeCommand = CreateEditRecipeProductCommand(connection);
                    connection.Open();
                    editrRecipeCommand.ExecuteNonQuery();
                    MessageBox.Show(Constants.RecipeProductEditedSuccessfullyMessage);
                    this.Close();
                }
                catch (FormatException formatException)
                {
                    MessageBox.Show(Constants.InvalidRecipeProductQuantityMessage);
                }
                catch (SqlException sqlException)
                {
                    MessageBox.Show(sqlException.ToString());
                }
            }
        }
Exemple #16
0
        private void FillRecipeProductsTable()
        {
            SqlConnection connection = CommonDatabaseActions.CreateDatabaseConnection("Canteen");

            using (connection)
            {
                SqlCommand authenticationCommand = CreateGetRecipesCommand(connection);
                try
                {
                    connection.Open();
                    SqlDataReader reader = authenticationCommand.ExecuteReader();
                    if (reader.HasRows)
                    {
                        DataTable dataTable = new DataTable();
                        dataTable.Load(reader);
                        recipeProducts.DataSource = dataTable;
                    }
                }
                catch (SqlException se)
                {
                    MessageBox.Show(se.ToString());
                }
            }
        }
Exemple #17
0
        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());
                }
            }
        }