Ejemplo n.º 1
0
 /// <summary>
 /// On accept button click
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnAccept_Click(object sender, EventArgs e)
 {
     if (IsValidData()) // first validate
     {
         if (addSupplier)
         {
             supplier = new Suppliers();
             this.PutSupplierData(supplier);
             try
             {
                 if (SuppliersDB.AddSuppliers(supplier))
                 {
                     this.DialogResult = DialogResult.OK;
                 }
                 else
                 {
                     MessageBox.Show("There was an error adding that supplier", "Database Error");
                     this.DialogResult = DialogResult.Retry;
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.GetType().ToString());
             }
         }
         else
         {
             Suppliers newSupplier = new Suppliers();
             newSupplier.SupplierId = supplier.SupplierId;
             this.PutSupplierData(newSupplier);
             try
             {
                 if (!SuppliersDB.UpdateSupplier(supplier, newSupplier))
                 {
                     MessageBox.Show("Another user has updated or " +
                                     "deleted that supplier.", "Database Error");
                     this.DialogResult = DialogResult.Retry;
                 }
                 else
                 {
                     supplier          = newSupplier;
                     this.DialogResult = DialogResult.OK;
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.GetType().ToString());
             }
         }
     }
 }
Ejemplo n.º 2
0
        private void btnAccept_Click_1(object sender, EventArgs e)
        {
            if (IsValidData())
            {
                if (addSuppliers) // processing Add
                {
                    psp = new Suppliers();
                    PutSuppliers_Data(psp);

                    try
                    {
                        SuppliersDB.AddSuppliers(psp);
                        MessageBox.Show("New Item with Supplier Id of " + psp.SuppliersId + " and SupName " + psp.SupName + " was added");
                        this.DialogResult = DialogResult.OK;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
                else // processing Modify
                {
                    Suppliers newSuppliers = new Suppliers();
                    newSuppliers.SupName = txtSupName.Text;
                    PutSuppliers_Data(newSuppliers);
                    try
                    {
                        if (!SuppliersDB.UpdateSuppliers(modifySuppliers, newSuppliers))
                        {
                            MessageBox.Show("Another user has updated or " +
                                            "deleted that Supplier.", "Database Error");
                            this.DialogResult = DialogResult.Retry;
                        }
                        else
                        {
                            psp = newSuppliers;
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }