/// <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> /// Retrieve item list for combo box dropdown /// </summary> /// <param name="wndMain"></param> /// <returns></returns> public static BindingList <clsItem> GetItemsList(wndMain wndMain) { try { BindingList <clsItem> ItemList = new BindingList <clsItem>(); //Make Connection clsSQL dataAccess = new clsSQL(); DataSet ds = new DataSet(); int iRet = 0; //store query result in data set ds = dataAccess.ExecuteSQLStatement(clsMainSQL.queryItems(), ref iRet); //Loop through items creating item object and add to a bound list for (int i = 0; i < iRet; i++) { clsItem item = new clsItem(); item.ItemCode = ds.Tables[0].Rows[i][0].ToString(); item.ItemDescription = ds.Tables[0].Rows[i][1].ToString(); item.ItemCost = Convert.ToDecimal(ds.Tables[0].Rows[i][2].ToString()); ItemList.Add(item); } return(ItemList); } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + "->" + ex.Message); } }
/// <summary> /// Convert a data set to an observable list /// </summary> /// <param name="ds"></param> /// <returns></returns> public static ObservableCollection <clsItem> ConvertDataSetToList(DataSet ds) { ObservableCollection <clsItem> itemList = new ObservableCollection <clsItem>(); int countRows = ds.Tables[0].Rows.Count; //add row values to item list for (int i = 0; i < countRows; i++) { clsItem TempItem = new clsItem(); TempItem.ItemDescription = ds.Tables[0].Rows[i][0].ToString(); string sCost = ds.Tables[0].Rows[i][1].ToString(); int iCost = Convert.ToInt32(sCost); TempItem.ItemCost = iCost; itemList.Add(TempItem); } return(itemList); }
/// <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); } }
/// <summary> /// Add item to the Invoice Items list /// </summary> /// <param name="item"></param> public void AddItem(clsItem item) { InvoiceItems.Add(item); }