Esempio n. 1
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);
                    }
                }
            }
        }