private void btnSaveSupplier_Click(object sender, EventArgs e)
        {
            if (Validator.IsPresent(txtModifySupplier))
            {
                string selectedSup = lstSupplierList.GetItemText(lstSupplierList.SelectedItem);
                string editedSup   = txtModifySupplier.Text;

                if (selectedSup != editedSup)
                {
                    DialogResult update =
                        MessageBox.Show("Change '" + selectedSup + "' to '" + editedSup + "'?"
                                        , "Confirm Change", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (update == DialogResult.OK)
                    {
                        SupplierDB.UpdateSupplier(selectedSup, editedSup);
                        // Refresh table adapter to display updated list
                        this.frmModifyProductSupplier_Load(this, null);
                        lstSupplierList.GetItemText(lstSupplierList.SelectedItem);

                        // Select the item that was just updated
                        int index = lstSupplierList.FindString(editedSup, -1);
                        if (index != -1)
                        {
                            lstSupplierList.SetSelected(index, true);
                        }
                    }
                }
            }
        }
        // Save button for the suppliers tab
        private void btnSaveSupplier_Click(object sender, EventArgs e)
        {
            string selectedSup = lstSupplierList.GetItemText(lstSupplierList.SelectedItem);
            string editedSup   = txtModifySupplier.Text;

            // Validation to see if the typed item is already in the list
            int index = lstSupplierList.FindString(editedSup, -1);

            if (editedSup != "" && index != -1)
            {
                MessageBox.Show("Warning: Supplier already exists.", "Duplicate Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                // Test for saving or editing
                if (lstSupplierList.Enabled == false && editedSup != "")
                {
                    DialogResult result = MessageBox.Show("Save '" + editedSup + "' as a new supplier?", "Confirm Add",
                                                          MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                    if (result == DialogResult.OK)
                    {
                        SupplierDB.AddSupplierName(editedSup);
                        this.frmModifyProductSupplier_Load(this, null);

                        // Select the item that was just saved
                        SelectItem(editedSup, lstSupplierList);
                    }
                }
                else if (lstSupplierList.Enabled == false && editedSup == "")
                {
                    MessageBox.Show("Please enter a new supplier name.", "Entry Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtModifySupplier.Focus();
                }
                else if (lstSupplierList.Enabled == true && selectedSup != editedSup)
                {
                    DialogResult update =
                        MessageBox.Show("Change '" + selectedSup + "' to '" + editedSup + "'?"
                                        , "Confirm Change", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (update == DialogResult.OK)
                    {
                        SupplierDB.UpdateSupplier(selectedSup, editedSup);
                        // Refresh table adapter to display updated list
                        this.frmModifyProductSupplier_Load(this, null);
                        lstSupplierList.GetItemText(lstSupplierList.SelectedItem);

                        // Select the item that was just updated
                        SelectItem(editedSup, lstSupplierList);
                    }
                }
                else if (lstSupplierList.Enabled == true && selectedSup == "")
                {
                    MessageBox.Show("Please select a supplier name to edit.", "Item Not Selected",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtModifySupplier.Focus();
                }
            }
        }
Example #3
0
        private void btnEditSupplier_Click(object sender, EventArgs e)
        {
            //Get the supplier name value from the textbox.
            string updatedSupName = txtboxEditSupName.Text;

            updatedSupName = updatedSupName.Trim();

            if (updatedSupName != "")//check if a value was provided
            {
                Supplier oldSupplier = suppliers[supplierDataGridView.CurrentCell.RowIndex];
                if (updatedSupName != oldSupplier.SupplierName)
                {
                    //Make a copy of the supplier we are updating
                    Supplier newSupplier = oldSupplier.GetCopy();

                    //Update the information in the new supplier;
                    newSupplier.SupplierName = updatedSupName;

                    try
                    {
                        bool result = SupplierDB.UpdateSupplier(oldSupplier, newSupplier);
                        if (result)
                        {
                            //Update the UI
                            suppliers = SupplierDB.GetAllSuppliers();
                            supplierDataGridView.DataSource = suppliers;


                            MessageBox.Show("The new supplier name has been saved", "Supplier Updated",
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("The changes were not saved", "Updated Failed",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        panelEditSupplier.Visible  = false;
                        btnDelelteSupClick.Enabled = true;
                        btnAddSupClick.Enabled     = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString(),
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Example #4
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");
                    }
                }
            }
        }