/// <summary> /// Remove selected item from the data grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RemoveSelected_Click(object sender, RoutedEventArgs e) { if (invoiceItemDataGrid.SelectedItem != null) { try { clsInvoice tempInvoice = new clsInvoice(); currentInvoice = tempInvoice; int rowIndex = invoiceItemDataGrid.SelectedIndex; clsItem tempItem = (clsItem)invoiceItemDataGrid.SelectedItem; //Remove Item currentInvoiceItems.RemoveAt(rowIndex); //currentInvoice.InvoiceItems.RemoveAt(rowIndex); //Update labels and grid decimal total = getInvoiceItemsTotal(currentInvoiceItems); invoiceItemDataGrid.Items.Refresh(); invoiceTotalLbl.Content = "Total: $" + total; } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } } }
/// <summary> /// Creates a new invoice and updates the invoice label to show TBD /// </summary> public static clsInvoice newInvoice(wndMain wndMain) { try { //Clear DataGrid & fields //Instantiate Invoice, set date and total to 0 clsInvoice newInvoice = new clsInvoice(); //Edit Invoice Mode Activated wndMain.editInvoiceMode = true; // Set Labels wndMain.invoiceLbl.Content = "Invoice Number: TBD"; wndMain.invoiceTotalLbl.Content = "0"; wndMain.invoiceItemDataGrid.ItemsSource = newInvoice.InvoiceItems; return(newInvoice); } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + "->" + ex.Message); } }
/// <summary> /// Refresh the data grid /// </summary> /// <param name="Invoice"></param> private void RefreshDataGrid(clsInvoice Invoice) { try { invoiceItemDataGrid.ItemsSource = null; invoiceItemDataGrid.ItemsSource = currentInvoice.InvoiceItems; invoiceTotalLbl.Content = "Total: $" + currentInvoice.SumTotal(); } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// this method is called when the select invoice button is clicked and sets the selected invoice /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void selectInvBtn_Click(object sender, RoutedEventArgs e) { try { if (InvoiceList.SelectedItems.Count > 0) { clsInvoice invoice = (clsInvoice)InvoiceList.SelectedItem; clsSearchLogic.SetSelectedInvoice(invoice.InvoiceNum.ToString()); this.Hide(); } } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + "->" + ex.Message); } }
/// <summary> /// Handles when the user clicks the New Invoice Button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuNewInvoice_Click(object sender, RoutedEventArgs e) { try { //Setup window for new invoice and return new invoice currentInvoice = clsMainLogic.newInvoice(this); currentInvoiceItems = currentInvoice.InvoiceItems; // set edit invoice to true editInvoiceMode = true; newInvoiceMode = true; EditMode(editInvoiceMode); } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// Handles when the user clicks the edit button in the invoice group box /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EditInvoiceBtn_Click(object sender, RoutedEventArgs e) { try { // Set edit mode make sure there is an invoice to edit if (currentInvoice != null) { editInvoiceMode = true; EditMode(editInvoiceMode); } else { currentInvoice = new clsInvoice(); editInvoiceMode = true; EditMode(editInvoiceMode); } } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }