public void DeleteMethodOK() { clsItemCollection AllItems = new clsItemCollection(); clsStock TestItem = new clsStock(); Int32 PrimaryKey = 0; //set properties TestItem.ItemID = 20; //This will only work once because it adds the test item to the list meaning there is now a duplicate, so change this value each time or remove it from the database TestItem.Available = true; TestItem.ItemName = "DeleteTestItem"; TestItem.ItemType = "Monitor"; TestItem.StockQuantity = 10; TestItem.Price = 10.00; TestItem.Supplier = "KappaInc"; TestItem.NextRestock = DateTime.Now.Date.AddDays(1); //set ThisItem to the test data AllItems.ThisItem = TestItem; //add the record PrimaryKey = AllItems.Add(); //set the primary key of the test data TestItem.ItemID = PrimaryKey; //find the record AllItems.ThisItem.Find(PrimaryKey); //delete the record AllItems.Delete(); //Test to see if the item is there (It shouldnt be) Assert.IsFalse(AllItems.ThisItem.Find(PrimaryKey)); }
protected void btnYes_Click1(object sender, EventArgs e) { //create a new instance of the item list clsItemCollection ItemList = new clsItemCollection(); //find the record to delete ItemList.ThisItem.Find(ItemID); //delete the record ItemList.Delete(); //redirect back to the main page Response.Redirect("StockList.aspx"); }