/// <summary> /// Deletes an item from the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDeleteItem_Click(object sender, RoutedEventArgs e) { try { LineItem = itemsLogic.GetLineItems(itemsSQL.GetLineItems()); //Verify none of the item codes are currently being used by an invoice foreach (var element in LineItem) { if (element.ItemCode == txtItemCode.Text) { MessageBox.Show("You cannot delete this item, it is invoice #" + element.InvoiceNum.ToString(), "Cannot delete item", MessageBoxButton.OK, MessageBoxImage.Warning); return; } } //Execute the delete statement if none of the elements are in an invoice DA.ExecuteNonQuery(itemsSQL.DeleteItem(txtItemCode.Text)); //Empty the current items out of the text boxes txtItemCode.Text = ""; txtItemDesc.Text = ""; txtItemCost.Text = ""; //Updates the Data grid FillBox(); } catch (System.Exception ex) { HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// Deletes the given item in the database /// </summary> /// <param name="toDelete"></param> public void DeleteItem(Item toDelete) { try { SQL.DeleteItem(toDelete.ItemCode.ToString()); } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " --> " + ex.Message); } }