示例#1
0
        private void changeqnt_Click(object sender, EventArgs e)
        {
            try
            {
                String MatName = itembox.Text;
                int    Quant   = int.Parse(qtnBox.Text);
                dbTools = new DatabaseTools();

                if (dbTools.CheckMat(MatName).Equals(true))
                {
                    try
                    {
                        string message = "Are you sure you want to change the quantity of " + MatName + " to " + Quant + "?";
                        string title   = "Warning!";

                        MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                        DialogResult      result  = MessageBox.Show(message, title, buttons);
                        if (result == DialogResult.Yes)
                        {
                            dbTools.EditQuant(MatName, Quant);
                            dgTools.SqlCommand = "SELECT RawMaterialName, Quantity FROM RawMaterials"; // Viewing all data from RawMaterials database except the ID
                            dgTools.RefreshDataGrid(stockDataGridView);
                            itembox.Clear();
                            qtnBox.Clear();
                        }
                        else
                        {
                            return;
                        }
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(err.Message, "Warning!");
                    }
                }
                else
                {
                    MessageBox.Show("This item can not be found.");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("Please input a value and quantity", "Warning!");
            }
        }
示例#2
0
        private void ConfirmChanges(Object sender, EventArgs e)
        {
            if (addedItems.Equals(true))
            {
                // Pressing confirm after adding products
                if (dgTools.dbName.Equals("Products"))
                {
                    MessageBox.Show("Please Remove Necessary Raw Materials");

                    viewMatBtn_Click(sender, e); // Switch to Raw Materials data grid view

                    addItemLbl.Text = "Remove Materials";

                    // Switching from Add button to Remove button
                    addItemBtn.Visible    = false;
                    removeItemBtn.Visible = true;
                }

                // Pressing confirm after removing materials
                else
                {
                    // Creating a formatted string from the products and raw materials
                    string prod = String.Join("\n", strProductsBeingAdded); // Joining each item in the list with a newline at the end
                    string mat  = String.Join("\n", strMatsBeingRemoved);

                    // Listing the products and raw materials on the screen
                    string confirm = "You are adding:\n" +
                                     prod + "\n\n" +
                                     "You are removing:\n" +
                                     mat + "\n\n" +
                                     "Is this correct?";

                    // Yes or no to confirm
                    DialogResult result = MessageBox.Show(confirm, "Confirm Changes", MessageBoxButtons.YesNo); // Confirming changes

                    // If user selects yes, update the databases
                    if (result.Equals(DialogResult.Yes))
                    {
                        // Switching back to the Add button from the Remove button
                        addItemBtn.Visible    = true;
                        removeItemBtn.Visible = false;

                        try
                        {
                            // Clear items from list boxes
                            itemsView.Items.Clear();
                            rawMatsView.Items.Clear();

                            // Adding all new products to the database
                            foreach (Product p in newProducts)
                            {
                                if (dbTools.CheckProduct(p.productName).Equals(true)) // If product already exists, update the quantity on it
                                {
                                    // Adding the new product quantity to the existing product
                                    Product tempProduct = dbTools.GetProduct(p.productName); // Returns a product object with the current quantity before changes

                                    int newQuant = tempProduct.quantity + p.quantity;        // Calculating new quantity after removing items

                                    dbTools.EditProductQuant(p.productName, newQuant);       // Editing the product quantity in the database to reflect changes
                                }
                                else
                                {
                                    // If product is not already in the database, add a new entry
                                    dbTools.AddProduct(p);
                                }
                            }

                            // Updating the raw materials database to the new values
                            foreach (RawMaterial m in matsUpdatedQuantity)
                            {
                                dbTools.EditQuant(m.rawMaterialName, m.quantity);
                            }
                            //toolStripStatusLabel1.Text = "Successfully created new product(s) with raw material(s)!";
                        }
                        catch (Exception err)
                        {
                            MessageBox.Show(err.Message, "A database issue occurred. Please try again");
                        }

                        // Going back to product view
                        viewProdBtn_Click(sender, e);

                        // Clearing all lists
                        if (newProducts != null)
                        {
                            newProducts.Clear();
                        }
                        if (matsUpdatedQuantity != null)
                        {
                            matsUpdatedQuantity.Clear();
                        }
                        if (matsQuantityToRemove != null)
                        {
                            matsQuantityToRemove.Clear();
                        }
                        if (strMatsBeingRemoved != null)
                        {
                            strMatsBeingRemoved.Clear();
                        }
                        if (strProductsBeingAdded != null)
                        {
                            strProductsBeingAdded.Clear();
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Must add products before continuing.", "Warning!");
            }
        }