/// <summary> /// Open invoice /// </summary> /// <param name="id"></param> private void openInvoice(int id) { MI_Search.IsEnabled = true; MI_Close.IsEnabled = true; Btn_Create.IsEnabled = false; Btn_Edit.IsEnabled = true; Btn_Delete.IsEnabled = false; Btn_Edit.Visibility = Visibility.Visible; Btn_Save.Visibility = Visibility.Hidden; Btn_Delete.Visibility = Visibility.Visible; Btn_Cancel.Visibility = Visibility.Hidden; Main.Visibility = Visibility.Hidden; Invoice.Visibility = Visibility.Visible; Search.Visibility = Visibility.Hidden; Item.Visibility = Visibility.Hidden; try { mn.GetInvoice(id); lbl_InvoiceNumber.Content = mn.CurrentInvoice.InvoiceNumber; dp_InvoiceDate.SelectedDate = mn.CurrentInvoice.InvoiceDate; lbl_InvoiceTotalCost.Content = string.Format("{0:C}", Convert.ToDecimal(mn.CurrentInvoice.Cost)); DG_Items.ItemsSource = mn.CurrentInvoice.Items; cb_InvoiceItems.ItemsSource = mn.GetLineItems(); cb_InvoiceItems.SelectedIndex = -1; } catch (Exception ex) // throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); { HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
private void LoadInvoice(int invoiceID) { try { invoice = sqlProvider.GetInvoice(invoiceID.ToString()); if (invoice == null) { throw new Exception("Failed to retrieve the invoice from the database"); } lineItems = sqlProvider.GetInvoiceLineItems(invoiceID.ToString()); if (lineItems == null) { throw new Exception("Failed to retrieve line items from the database"); } DateTime invoiceDate; if (DateTime.TryParse(invoice.sInvoiceDate, out invoiceDate)) { dpInvoiceDate.SelectedDate = invoiceDate; } else { MessageBox.Show("Failed to load invoice date."); } int totalCost; if (int.TryParse(invoice.sTotalCost, out totalCost)) { lblTotalCost.Content = $"{totalCost:C}"; } else { MessageBox.Show("Failed to load the invoice total cost"); } dgInvoiceItems.ItemsSource = lineItems; btnEditInvoice.IsEnabled = true; btnDeleteInvoice.IsEnabled = true; lblInvoiceNum.Content = $"Invoice #{invoiceID}"; } 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); } }