/// <summary> /// Handles Delete Line Item Click Event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteLineItem_Click(object sender, RoutedEventArgs e) { try { //Check if an item is selected if (dtgrdInvoiceItems.SelectedItem != null) { //Grab currently selected item clsItem selected = (clsItem)dtgrdInvoiceItems.SelectedItem; //Delete Line Item selectedItems.Remove(selected); dtgrdInvoiceItems.Items.Refresh(); dtgrdInvoiceItems.SelectedItem = null; //Update the total cost currentTotal -= selected.Cost; lblInvoiceTotal.Content = $"{currentTotal:C}"; } } catch (Exception ex) { HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// Get all Items from the database /// </summary> /// <returns>Returns list of clsItem</returns> public List <clsItem> GetItems() { try { //Method Variables List <clsItem> items = new List <clsItem>(); string sSQL = sql.SelectAllItems(); int iNumReturned = 0; //Execute Query and return data as dataset DataSet ds = db.ExecuteSQLStatement(sSQL, ref iNumReturned); //Loop Through Dataset to fill "items" with list of each item in database for (int i = 0; i < iNumReturned; ++i) { currentItem = new clsItem(); currentItem.Code = ds.Tables[0].Rows[i]["ItemCode"].ToString(); currentItem.Description = ds.Tables[0].Rows[i]["ItemDesc"].ToString(); currentItem.Cost = (decimal)ds.Tables[0].Rows[i]["Cost"]; items.Add(currentItem); } //Return List of Items return(items); } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }
/// <summary> /// Handles Add Item Click Event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddItem_Click(object sender, RoutedEventArgs e) { try { //Check if an Item is selected if (cmbBoxItems.SelectedItem != null) { //Grab currently selected item clsItem selected = (clsItem)cmbBoxItems.SelectedItem; //Adds the Currently selected item to the data grid selectedItems.Add(selected); dtgrdInvoiceItems.Items.Refresh(); //Update the total cost currentTotal += selected.Cost; lblInvoiceTotal.Content = $"{currentTotal:C}"; } } catch (Exception ex) { HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// Get item in invoice /// </summary> /// <param name="sInvoiceNum">selected invoice number</param> /// <returns>data set containing invoice's items</returns> public List <clsItem> GetInvoiceContents(string sInvoiceNum) { try { int iNumReturned = 0; //create data set and execute sql statement DataSet ds = db.ExecuteSQLStatement(sql.GetInvoiceContents(sInvoiceNum), ref iNumReturned); List <clsItem> items = new List <clsItem>(); clsItem cItem; for (int i = 0; i < iNumReturned; i++) { cItem = new clsItem(); cItem.Code = ds.Tables[0].Rows[i]["ItemCode"].ToString(); cItem.Description = ds.Tables[0].Rows[i]["ItemDesc"].ToString(); cItem.Cost = (decimal)ds.Tables[0].Rows[i]["Cost"]; items.Add(cItem); } return(items); } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }
public wndEdit() { try { InitializeComponent(); queries = new clsDBQueries(); item = new clsItem(); listOfItems = queries.GetAllFromItemDesc(); isUpdateItem = false; dgListOfItems.ItemsSource = listOfItems; } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }