/// <summary> /// Handle the delete invoice button being clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDeleteInvoice_Click(object sender, RoutedEventArgs e) { try { if (!sqlProvider.DeleteInvoiceLineItems(invoice)) { MessageBox.Show("Failed to remove line items from the database."); return; } if (!sqlProvider.DeleteInvoice(invoice)) { MessageBox.Show("Failed to remove the invoice from the database. Line items removed successfully"); return; } isNewInvoice = false; lblInvoiceNum.Content = "Invoice"; dgInvoiceItems.ItemsSource = null; dgInvoiceItems.Items.Refresh(); invoice = null; btnEditInvoice.IsEnabled = false; btnDeleteInvoice.IsEnabled = false; dpInvoiceDate.SelectedDate = null; lblTotalCost.Content = ""; btnEditInvoice.IsEnabled = false; btnDeleteInvoice.IsEnabled = false; UpdateIsEnabledField(false); MessageBox.Show("Invoice deleted successfully."); } catch (Exception ex) { //This is the top level method so we want to handle the exception HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// handles the delete invoice button click by deleteing the currently selected invoice. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void deleteInvoiceButton_Click(object sender, RoutedEventArgs e) { try { if (datePicker.SelectedDate == null) { selectDateErrorLabel.Visibility = (Visibility)0; } else if (invoiceComboBox.SelectedItem == null) { Selecet_Invoice_Error_Label.Visibility = (Visibility)0; } else { clsInvoices selectedInvoice = (clsInvoices)invoiceComboBox.SelectedItem; invoiceDataGrid.ItemsSource = dataGridList; selectDateErrorLabel.Visibility = (Visibility)1; Selecet_Invoice_Error_Label.Visibility = (Visibility)1; invoiceNumberTextBox.Text = selectedInvoice.InvoiceNum; mainLogic.DeleteInvoice(selectedInvoice.InvoiceNum); dataGridList.Clear(); invoiceDataGrid.ItemsSource = dataGridList; itemsComboBox.Text = ""; invoiceComboBox.Text = ""; datePicker.Text = "Please select a date"; invoice_Deleted_Label.Visibility = (Visibility)0; } } catch (Exception ex) { //this is reflection HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// This will delete an existing Invoice /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDeleteInvoice_Click(object sender, RoutedEventArgs e) { try { clsInvoice invoice = (clsInvoice)dgInvoices.SelectedItem; string invoiceNum = invoice.InvoiceNum.ToString(); ml.DeleteLineItems(invoiceNum); ml.DeleteInvoice(invoiceNum); dgInvoices.ClearValue(ItemsControl.ItemsSourceProperty); //Populate DataGrid with Invoices List <clsInvoice> refresh = ml.GetAllInvoices(); dgInvoices.ItemsSource = refresh; //disable Delete and Edit Buttons btnDeleteInvoice.IsEnabled = false; btnEditInvoice.IsEnabled = false; } catch (Exception ex) { HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// Delete Invoice /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_Delete_Click(object sender, RoutedEventArgs e) { if ((MessageBoxResult)MessageBox.Show("Are you sure you want to delete this invoice?", "Delete Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { mn.DeleteInvoice(); } MI_Close_Click(); }