private void btnSaveProduct_Click(object sender, EventArgs e)
        {
            if (Validator.IsPresent(txtModifyProduct))
            {
                string selectedProd = lstProductList.GetItemText(lstProductList.SelectedItem);
                string editedProd   = txtModifyProduct.Text;

                if (selectedProd != editedProd)
                {
                    DialogResult update =
                        MessageBox.Show("Change '" + selectedProd + "' to '" + editedProd + "'?"
                                        , "Confirm Change", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (update == DialogResult.OK)
                    {
                        ProductDB.UpdateProduct(selectedProd, editedProd);
                        // Refresh table adapter to display updated list
                        this.frmModifyProductSupplier_Load(this, null);

                        // Select the item that was just updated
                        int index = lstProductList.FindString(editedProd, -1);
                        if (index != -1)
                        {
                            lstProductList.SetSelected(index, true);
                        }
                    }
                }
            }
        }
        // Save button for the products tab
        private void btnSaveProduct_Click(object sender, EventArgs e)
        {
            string selectedProd = lstProductList.GetItemText(lstProductList.SelectedItem);
            string editedProd   = txtModifyProduct.Text;

            // Validation to see if the typed product is already in the list
            int index = lstProductList.FindString(editedProd, -1);

            if (editedProd != "" && index != -1)
            {
                MessageBox.Show("Warning: Product already exists.", "Duplicate Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                // Test for saving
                if (lstProductList.Enabled == false && editedProd != "") // Test if adding product
                {
                    DialogResult result = MessageBox.Show("Save '" + editedProd + "' as a new product?", "Confirm Add",
                                                          MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                    if (result == DialogResult.OK)
                    {
                        ProductDB.AddProductName(editedProd);
                        this.frmModifyProductSupplier_Load(this, null);

                        // Select the item that was just saved
                        SelectItem(editedProd, lstProductList);
                    }
                }
                else if (lstProductList.Enabled == false && editedProd == "")   // If adding product, check if textbox is empty
                {
                    MessageBox.Show("Please enter a new product name.", "Entry Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtModifyProduct.Focus();
                }
                else if (lstProductList.Enabled == true && selectedProd != editedProd) // Test if editing a selected product
                {
                    DialogResult update =
                        MessageBox.Show("Change '" + selectedProd + "' to '" + editedProd + "'?"
                                        , "Confirm Change", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (update == DialogResult.OK)
                    {
                        ProductDB.UpdateProduct(selectedProd, editedProd);
                        // Refresh table adapter to display updated list
                        this.frmModifyProductSupplier_Load(this, null);

                        // Select the item that was just updated
                        SelectItem(editedProd, lstProductList);
                    }
                }
                else if (lstProductList.Enabled == true && selectedProd == "") // Test if editing a product but nothing is selected
                {
                    MessageBox.Show("Please select a product to edit.", "Item Not Selected",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtModifyProduct.Focus();
                }
            }
        }
Exemplo n.º 3
0
        private void btnEditProduct_Click(object sender, EventArgs e)
        {
            string pronameText = textBoxEditProName.Text;

            pronameText = pronameText.Trim();
            if (pronameText != "")
            {
                //Get the product to edit
                int     selectedIndex = productDataGridView.CurrentCell.RowIndex;
                Product oldProd       = products[selectedIndex];
                //Make a copy
                Product newProd = oldProd.GetCopy();
                //Update the copy with new data
                newProd.ProdName = textBoxEditProName.Text;

                if (newProd.ProdName != oldProd.ProdName) //Check if a change was made
                {
                    //Write to DB
                    try
                    {
                        bool result = ProductDB.UpdateProduct(oldProd, newProd);

                        if (result)
                        {
                            //Update the UI
                            products = ProductDB.GetProducts();
                            productDataGridView.DataSource = products;

                            MessageBox.Show("The new product name has been saved", "Product Updated",
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("The changes were not saved", "Updated Failed",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString(),
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                //Hide the panel if updates were done
                panelProductEdit.Visible      = false;
                btnAddProductClick.Enabled    = true;
                btnDeleteProductClick.Enabled = true;
            }
            else //Display error message if Product name textbox was blank.
            {
                MessageBox.Show("Please provide product name.", "Missing Data",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 4
0
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     if (txtUpdate.Text != null)
     {
         ProductDB.UpdateProduct(txtUpdate.Text, oldprodname);
         txtUpdate.Text = "";
     }
     product = ProductDB.GetAllProducts();
     dataGridView1.DataSource = product;
     this.Refresh();
 }
Exemplo n.º 5
0
 private void btnDeactivate_Click(object sender, EventArgs e)
 {
     if (txtUpdate.Text != null)
     {
         string deactivate = ("inactive" + txtUpdate.Text);
         ProductDB.UpdateProduct(deactivate, oldprodname);
         txtUpdate.Text = "";
     }
     product = ProductDB.GetAllProducts();
     dataGridView1.DataSource = product;
     this.Refresh();
 }
Exemplo n.º 6
0
        private void BtnAccept_Click(object sender, EventArgs e)
        {
            if (IsValidData())
            {
                if (addproducts) // processing Add
                {
                    products = new Product();
                    PutProduct(products);

                    try
                    {
                        ProductDB.AddProduct(products);
                        MessageBox.Show("New Item with Product Id of " + products.ProductID + " and Product Name of " + products.ProdName + " was added");
                        this.DialogResult = DialogResult.OK;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
                else // processing Modify
                {
                    Product newProduct = new Product();
                    newProduct.ProductID = Convert.ToInt32(txtProductID.Text);
                    txtProductID.Enabled = false;
                    newProduct.ProdName  = txtProdName.Text;
                    PutProduct(newProduct);
                    try
                    {
                        if (!ProductDB.UpdateProduct(newProduct, modifyProduct))
                        {
                            MessageBox.Show("Another user has updated or " +
                                            "deleted that product.", "Database Error");
                            this.DialogResult = DialogResult.Retry;
                        }
                        else
                        {
                            products          = newProduct;
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }
Exemplo n.º 7
0
        // call the proper function for insertion of the the supplier of the product and put to upper for the suppliers
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (SelectedProductName != null)
            {
                if (Validator.IsProvided(txtProdSup, "A Product Name"))
                {
                    string newName = txtProdSup.Text;
                    bool   valid   = false;

                    foreach (Product p in products)
                    {
                        if (p.ProdName == newName)
                        {
                            MessageBox.Show("Product already exists, choose a unique product name");
                            valid = false;
                            break;
                        }
                        else
                        {
                            valid = true;
                        }
                    }
                    if (valid == true)
                    {
                        try
                        {
                            ProductDB.UpdateProduct(SelectedProductName, newName);
                            MessageBox.Show(SelectedProductName + " was updated to " + newName);
                            this.Close();
                        }
                        catch
                        {
                            MessageBox.Show("Update was unsuccessful, try again");
                        }
                    }
                }
            }
            else if (Validator.IsProvided(txtProdSup, "A Supplier name"))
            {
                string newName = txtProdSup.Text.ToUpper();
                bool   valid   = false;

                foreach (Supplier s in suppliers)
                {
                    if (s.SupName == newName)
                    {
                        MessageBox.Show("Supplier already exists, choose a unique supplier name");
                        valid = false;
                        break;
                    }
                    else
                    {
                        valid = true;
                    }
                }
                if (valid == true)
                {
                    try
                    {
                        SupplierDB.UpdateSupplier(SelectedSupplierName, newName);
                        MessageBox.Show(SelectedSupplierName + " was updated to " + newName);
                        this.Close();
                    }
                    catch
                    {
                        MessageBox.Show("Update was unsuccessful, try again");
                    }
                }
            }
        }