コード例 #1
0
 private void DeleteButton_Click(object sender, EventArgs e)
 {
     if (objectBox.SelectedIndex != -1)
     {
         if (type.Equals(typeof(Offer)))
         {
             int number = Convert.ToInt32(objectBox.SelectedItem.ToString().Split('.').First());
             try
             {
                 if (DatabaseMethods.DeleteOffer(number))
                 {
                     MessageBox.Show("Offer was deleted", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     _mainForm.StartThreadQuantityUpdate();
                     Dispose();
                 }
                 else
                 {
                     MessageBox.Show("Offer was not deleted!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             catch (DbUpdateException)
             {
                 MessageBox.Show("Cannot delete because of reference to order!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         if (type.Equals(typeof(Order)))
         {
             int number = Convert.ToInt32(objectBox.SelectedItem.ToString().Split('.').First());
             try
             {
                 if (DatabaseMethods.DeleteOrder(number))
                 {
                     MessageBox.Show("Order was deleted", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     _mainForm.StartThreadQuantityUpdate();
                     Dispose();
                 }
                 else
                 {
                     MessageBox.Show("Order was not deleted!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             catch (DbUpdateException)
             {
                 MessageBox.Show("Cannot delete because of reference to order!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         if (type.Equals(typeof(Client)))
         {
             int number = Convert.ToInt32(objectBox.SelectedItem.ToString().Split(' ').Last().Remove(objectBox.SelectedItem.ToString().Split(' ').Last().Length - 1));
             try
             {
                 if (DatabaseMethods.DeleteClient(number))
                 {
                     MessageBox.Show("Client was deleted", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     _mainForm.StartThreadQuantityUpdate();
                     Dispose();
                 }
                 else
                 {
                     MessageBox.Show("Client was not deleted!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             catch (DbUpdateException)
             {
                 MessageBox.Show("Cannot delete because of reference to order!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         if (type.Equals(typeof(Worker)))
         {
             int number = Convert.ToInt32(objectBox.SelectedItem.ToString().Split('.').First());
             try
             {
                 if (DatabaseMethods.DeleteWorker(number))
                 {
                     MessageBox.Show("Worker was deleted", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     _mainForm.StartThreadQuantityUpdate();
                     Dispose();
                 }
                 else
                 {
                     MessageBox.Show("Worker was not deleted!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             catch (DbUpdateException)
             {
                 MessageBox.Show("Cannot delete because of reference to order!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     else
     {
         MessageBox.Show("Not selected!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }