Esempio n. 1
0
 /// <summary>
 /// Handles the Save Invoice Button being clicked. Checks if items exists in the datagrid.
 /// If no items exist the Invoice will not be saved.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void saveInvoiceButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (invoiceNumberTextBox.Text == "TBD") //if invoiceNumberTextBox is TBD then the invoice is a new invoice.
         {                                       //and an INSERT INTO statement is required.
             if (dataGridList.Count == 0)
             {
                 noItemsAddedLabel.Visibility = (Visibility)0;
             }
             else
             {
                 mainLogic.AddInvoice(datePicker.SelectedDate.ToString(), totalCost.ToString(), dataGridList); //add invoice to the DB
                 addItemsCanvas.IsEnabled     = false;
                 invoiceNumberTextBox.Text    = "";
                 invoiceSavedLabel.Visibility = (Visibility)0;
                 itemsComboBox.Text           = "";
                 invoiceComboBox.Text         = "";
                 datePicker.Text = "Please select a date";
             }
         }
         else //if invoicenumbertextbox is not TBD then the invoice is one already in the database and
         {    // an UPDATE statement will be required.
             var selectedInvoice = (clsInvoices)invoiceComboBox.SelectedItem;
             mainLogic.UpdateInvoice(selectedInvoice.InvoiceNum, totalCost.ToString(), dataGridList);
             invoiceLookUpCanvas.IsEnabled = true;
             invoiceSavedLabel.Visibility  = (Visibility)0;
             itemsComboBox.Text            = "";
             invoiceComboBox.Text          = "";
             datePicker.Text = "Please select a date";
         }
         dataGridList.Clear();
         invoiceDataGrid.ItemsSource = dataGridList;
         Cost_TextBox.Text           = "";
         Total_TextBox.Text          = "";
     }
     catch (Exception ex)
     {               //this is reflection
         HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                     MethodInfo.GetCurrentMethod().Name, ex.Message);
     }
 }