/// <summary> /// Deletes the seelcted item from the list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteItem_Click(object sender, RoutedEventArgs e) { //If the user tries to delete an item that is on an invoice, don't allow the user //to do so. //Give the user a warning message that tells them which invoices that item is used on. try { DataSet ds = new DataSet(); ds = queries.GetInvoicesContainingItem(txtbCode.Text); //if (ds.IsInitialized) //Count Seems to work better if (ds.Tables[0].Rows.Count > 0) { MessageBox.Show("Cannot delete this item for it is in an invoice."); } else { queries.DeleteItem(txtbCode.Text); listOfItems = queries.GetAllFromItemDesc(); dgListOfItems.ItemsSource = listOfItems; } } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }
/// <summary> /// Select Item from combobox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmbItems_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (cmbItems.SelectedValue != null) { DataSet ds = new DataSet(); ds = query.GetItemInfo(cmbItems.SelectedValue.ToString()); lblItemCode.Content = ds.Tables[0].Rows[0]["ItemCode"].ToString(); lblItemDesc.Content = ds.Tables[0].Rows[0]["ItemDesc"].ToString(); lblItemCost.Content = $"{ds.Tables[0].Rows[0]["Cost"]:C}"; ds = query.GetInvoicesContainingItem(cmbItems.SelectedValue.ToString()); dgInvoicesWithItem.ItemsSource = ds.Tables[0].AsDataView(); } } catch (System.Exception ex) { HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }