/// <summary> /// Adds an Item to the invoice /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddItemButton_Click(object sender, RoutedEventArgs e) { try { var invoice = App.InvoiceService.CurrentInvoice; if (invoice == null) { MessageBox.Show(this, "Please create or select an Invoice.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); return; } var itemViewModel = (ItemViewModel)ItemsComboBox.SelectedItem; if (itemViewModel == null) { MessageBox.Show(this, "Please select an item to add to the invoice.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); return; } var item = itemViewModel.Item; var lineItemNumber = DataStore.AddItemToInvoice(invoice, item); var lineItem = new LineItem { InvoiceNumber = invoice.InvoiceNum, ItemCode = item.ItemCode, LineItemNumber = lineItemNumber }; var currentInvoiceItemViewModel = new CurrentInvoiceItemViewModel(lineItem, item); ViewModel.CurrentInvoiceItems.Add(currentInvoiceItemViewModel); ViewModel.RefreshInvoice(); } catch (Exception ex) { Error.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex); } }