예제 #1
0
 private void GetVendor(int vendorID)
 {
     try
     {
         vendor = VendorDB.GetVendor(vendorID);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.GetType().ToString());
     }
 }
예제 #2
0
        private void BtnDelete_Click(object sender, EventArgs e)
        {
            if (vendorIDTextBox.Text.Length == 0)
            {
                MessageBox.Show("Please select a vendor first.");
                return;
            }


            int vendorID = Convert.ToInt32(vendorIDTextBox.Text);

            this.GetVendor(vendorID);

            DialogResult result = MessageBox.Show("Delete " + vendor.vendorName + "?",
                                                  "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                try
                {
                    if (!VendorDB.DeleteVendor(vendor))
                    {
                        MessageBox.Show("Another user has updated or deleted " +
                                        "that vendor.", "Database Error");
                        this.GetVendor(vendor.vendorID);
                        if (vendor != null)
                        {
                            this.DisplayVendor();
                        }
                        else
                        {
                            this.ClearControls();
                        }
                    }
                    else
                    {
                        this.ClearControls();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Can't delete due to referencial integrity.");
                    //MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }
예제 #3
0
 private void Button1_Click(object sender, EventArgs e)
 {
     if (IsValidData())
     {
         if (addVendor)
         {
             vendor = new Vendor();
             this.PutData(vendor);
             try
             {
                 vendor.vendorID   = VendorDB.AddVendor(vendor);
                 this.DialogResult = DialogResult.OK;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.GetType().ToString());
             }
         }
         else
         {
             Vendor newVendor = new Vendor();
             newVendor.vendorID = vendor.vendorID;
             this.PutData(newVendor);
             try
             {
                 if (!VendorDB.UpdateVendor(vendor, newVendor))
                 {
                     MessageBox.Show("Another user has updated or " +
                                     "deleted that vendor.", "Database Error");
                     this.DialogResult = DialogResult.Retry;
                 }
                 else
                 {
                     vendor            = newVendor;
                     this.DialogResult = DialogResult.OK;
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.GetType().ToString());
             }
         }
     }
 }