/// <summary> /// BtnItemDelete_Click: Allows user to delete an item, Repopulates the Grid afterwards /// Date Version Name Comments /// 11/16/19 1.0 Dylan Created Method /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnItemDelete_Click(object sender, RoutedEventArgs e) { try { if (txtEditName.Text != "" || txtEditCost.Text != "") { if (clsItemsLogic.DeleteItem(sCurrentItemCode)) { //Deleted Successfully } else { txtCantDelete.Visibility = Visibility.Visible; } PopulateDataGrid(); } else { txtMissingEdit.Visibility = Visibility.Visible; } ClearFields(); } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// Edit mode decides which controls to disable /// </summary> /// <param name="editInvoiceMode"></param> private void EditMode(bool editInvoiceMode) { try { if (editInvoiceMode == false) { editInvoiceBtn.IsEnabled = false; addItemBtn.IsEnabled = false; removeSelectedBtn.IsEnabled = false; deleteInvoiceBtn.IsEnabled = false; saveInvoiceBtn.IsEnabled = false; cmbItems.IsEnabled = false; } else { editInvoiceBtn.IsEnabled = true; addItemBtn.IsEnabled = true; removeSelectedBtn.IsEnabled = true; editInvoiceBtn.IsEnabled = true; deleteInvoiceBtn.IsEnabled = true; saveInvoiceBtn.IsEnabled = true; cmbItems.IsEnabled = true; } } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// ItemDataGrid_CurrentCellChanged: Updates the Edit Name and Edit Cost textboxes /// Date Version Name Comments /// 12/06/19 1.0 Dylan Created Method /// </summary> /// /// <param name="sender"></param> /// <param name="e"></param> private void ItemDataGrid_CurrentCellChanged(object sender, EventArgs e) { try { if (ItemDataGrid.CurrentCell != null && ItemDataGrid.Items.IndexOf(ItemDataGrid.CurrentItem) != -1) { if (bIsDeleting == false) { //// <summary> /// iRowNum: Stores selected row index /// </summary> int iRowNum = ItemDataGrid.Items.IndexOf(ItemDataGrid.CurrentItem); if (iRowNum < ds.Tables[0].Rows.Count) { txtEditName.Text = ds.Tables[0].Rows[iRowNum][1].ToString(); txtEditCost.Text = ds.Tables[0].Rows[iRowNum].ItemArray[2].ToString(); sCurrentItemCode = db.ExecuteScalarSQL(clsItemsSQL.GetItemCode(txtEditName.Text)); } } } } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <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> /// BtnItemAdd_Click: Allows user to add an item, Repopulates the Grid afterwards /// Date Version Name Comments /// 11/16/19 1.0 Dylan Created Method /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnItemAdd_Click(object sender, RoutedEventArgs e) { try { if (txtAddName.Text != "" || txtAddCost.Text != "") { if (clsItemsLogic.AddItem(txtAddName.Text, txtAddCost.Text)) { PopulateDataGrid(); } else { txtDupName.Visibility = Visibility.Visible; } } else { txtMissingAdd.Visibility = Visibility.Visible; } ClearFields(); } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// Handles when the user clicks the save button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void saveInvoiceBtn_Click(object sender, RoutedEventArgs e) { try { if (newInvoiceMode == true) { currentInvoice.InvoiceDate = string.Format("{0:MM/dd/yyyy}", DateTime.Today); if (currentInvoice != null && currentInvoice.InvoiceNum != 0) { db.ExecuteNonQuery(clsMainSQL.DeleteOldInvoice(currentInvoice.InvoiceNum)); } //Get Invoice Number invoiceNumber = db.ExecuteScalarSQL(clsMainSQL.queryMaxInvoice()); //Set Invoice Number to Label invoiceLbl.Content = "Invoice Number: " + invoiceNumber; invoiceDateLbl.Content = string.Format("{0:MM/dd/yyyy}", DateTime.Today); //Insert new invoice string dateForInsert = currentInvoice.InvoiceDate; db.ExecuteNonQuery(clsMainSQL.insertInvoice(dateForInsert, getInvoiceItemsTotal(currentInvoiceItems))); //This will loop through the list to insert the items one at a time for (int i = 0; i < currentInvoiceItems.Count; i++) { db.ExecuteNonQuery(clsMainSQL.InsertNewInvoice(Convert.ToInt32(invoiceNumber), (i + 1), currentInvoiceItems[i].ItemCode)); } newInvoiceMode = false; } else { //Set Invoice Number to Label invoiceLbl.Content = "Invoice Number: " + invoiceNumber; string InvoiceDatePull = db.ExecuteScalarSQL(clsMainSQL.queryDate(Convert.ToInt32(invoiceNumber))); invoiceDateLbl.Content = InvoiceDatePull; //Delete invoice line items if (currentInvoiceItems.Count > 0) { db.ExecuteNonQuery(clsMainSQL.deleteInvoiceLineItem(Convert.ToInt32(invoiceNumber))); } //This will loop through the list to insert the items one at a time for (int i = 0; i < currentInvoiceItems.Count; i++) { db.ExecuteNonQuery(clsMainSQL.InsertNewInvoice(Convert.ToInt32(invoiceNumber), (i + 1), currentInvoiceItems[i].ItemCode)); } } } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// BtnItem_Close_Click: Handles when user clicks close button /// Date Version Name Comments /// 11/16/19 1.0 Dylan Created Method /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnItemClose_Click(object sender, RoutedEventArgs e) { try { this.Hide(); } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// this method is called when the cancel button is clicked which closes the window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cancelBtn_Click(object sender, RoutedEventArgs e) { try { clsSearchLogic.SetSelectedInvoice(""); this.Hide(); } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// Window_Closing: Handles when user clicks close button /// Date Version Name Comments /// 11/16/19 1.0 Dylan Created Method /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { try { this.Hide(); e.Cancel = true; } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// PopulateDataGrid: Populates DataGrid /// Date Version Name Comments /// 12/03/19 1.0 Dylan Created Method /// </summary> private void PopulateDataGrid() { try { ds = db.ExecuteSQLStatement(clsItemsSQL.GetItemList(), ref iRet); ItemDataGrid.ItemsSource = ds.Tables[0].AsDataView(); } catch (Exception ex) { ClsHandleError.HandleError(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> /// 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> /// sums prices of items in the Invoice Items list and returns the total amount /// </summary> /// <returns></returns> public decimal SumTotal() { decimal total = 0; try { foreach (clsItem item in InvoiceItems) { total += item.ItemCost; } } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } return(total); }
/// <summary> /// Handles when the user clicks the Edit Item Menu Option /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuEditItem_Click(object sender, RoutedEventArgs e) { try { if (editInvoiceMode == false && newInvoiceMode == false) { itemWindow = new wndItems(); this.Hide(); itemWindow.ShowDialog(); this.Show(); } } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// txtAnswer_PreviewKeyDown: Limits keystrokes to to numbers, the backspace, the delete, and will call SubmitAnswer when Enter is pressed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// private void Numberic_PreviewKeyDown(object sender, KeyEventArgs e) { try { if (!((e.Key >= Key.D0 && e.Key <= Key.D9) || e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9 || e.Key == Key.Decimal || e.Key == Key.OemPeriod)) { if (!(e.Key == Key.Back || e.Key == Key.Delete)) { e.Handled = true; } } } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// Open Main Window of the program /// </summary> public wndMain() { try { InitializeComponent(); Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose; db = new clsSQL(); itemList = clsMainLogic.GetItemsList(this); cmbItems.ItemsSource = itemList; //Void selections until menu item is selected EditMode(editInvoiceMode); } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// wndItems: Initializes Form, sets textboxes to "", and calls PopulateDataGrid /// Date Version Name Comments /// 11/16/19 1.0 Dylan Created Method /// </summary> public wndItems() { try { InitializeComponent(); txtAddName.Text = ""; txtAddCost.Text = ""; txtEditName.Text = ""; txtEditCost.Text = ""; db = new clsSQL(); PopulateDataGrid(); } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// Get Invoice Items total from observable list /// </summary> private decimal getInvoiceItemsTotal(ObservableCollection <clsItem> InvoiceList) { decimal total = 0; try { foreach (clsItem Item in InvoiceList) { total += Item.ItemCost; } } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } return(total); }
/// <summary> /// Handles when the user clicks the delete button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void deleteInvoiceBtn_Click(object sender, RoutedEventArgs e) { try { //Delete current invoice clsMainLogic.deleteInvoice(Convert.ToInt32(currentInvoice.InvoiceNum), this); //Refresh the datagrid invoiceItemDataGrid.ItemsSource = null; //Take out of edit mode editInvoiceMode = false; EditMode(editInvoiceMode); } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// Handles when the user clicks the Search Invoice menu item /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuSearchInvoice_Click(object sender, RoutedEventArgs e) { try { wndSearch searchWindow = new wndSearch(); this.Hide(); searchWindow.ShowDialog(); int iRet = 0; DataSet ds; // store data in dateset invoiceNumber = clsSearchLogic.strSelectedInvoice; if (invoiceNumber != "") { ds = db.ExecuteSQLStatement(clsMainSQL.queryInvoice(Convert.ToInt32(invoiceNumber)), ref iRet); string InvoiceDatePull = db.ExecuteScalarSQL(clsMainSQL.queryDate(Convert.ToInt32(invoiceNumber))); //update labels invoiceLbl.Content = "Invoice Number: " + invoiceNumber; invoiceDateLbl.Content = InvoiceDatePull; // extract dataset items into observable list currentInvoiceItems = clsMainLogic.ConvertDataSetToList(ds); // bind observable list to the data source invoiceItemDataGrid.ItemsSource = currentInvoiceItems; // set edit invoice to true editInvoiceMode = true; EditMode(editInvoiceMode); } this.Show(); } 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); } }
/// <summary> /// Handles when the user clicks the add item button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void addItemBtn_Click(object sender, RoutedEventArgs e) { try { if (cmbItems.SelectedItem != null) { //Add selected item to current invoice clsItem addItem = (clsItem)cmbItems.SelectedItem; currentInvoiceItems.Add(addItem); decimal total = getInvoiceItemsTotal(currentInvoiceItems); invoiceTotalLbl.Content = "Total: $" + total; } else { MessageBox.Show("You must select an Item to add."); } } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }