//function for updating records void Update() { clsProductCollection ProductCollect = new clsProductCollection(); String Error = ProductCollect.ThisProduct.Valid(txtProductName.Text, txtDescription.Text, txtPrice.Text); //if the data is OK then add it to the objct if (Error == "") { //find the record to update ProductCollect.ThisProduct.Find(ProductNo); //get data entered by the user ProductCollect.ThisProduct.ProductName = txtProductName.Text; ProductCollect.ThisProduct.Description = txtDescription.Text; ProductCollect.ThisProduct.Price = Convert.ToDecimal(txtPrice.Text); ProductCollect.ThisProduct.Active = chkActive.Checked; //update the record ProductCollect.Update(); //all done so redirect to the main page Response.Redirect("ProductDefault.aspx"); } else { //report an error lblError.Text = "There were problems with the data entered " + Error; } }
public void UpdateMethodOK() { clsProductCollection Products = new clsProductCollection(); clsProduct TestProduct = new clsProduct(); Int32 PrimaryKey = 0; TestProduct.ProductName = "Metal Gear Ray Figure"; TestProduct.ProductDescription = "A die-cast figurine of Metal Gear Ray from Metal Gear Solid 2."; TestProduct.UnitPrice = 90.00; TestProduct.InStock = true; TestProduct.StockAmount = 1; TestProduct.DiscountPercentage = 0; TestProduct.DiscountActive = false; Products.ThisProduct = TestProduct; PrimaryKey = Products.Add(); TestProduct.ProductNo = PrimaryKey; TestProduct.ProductName = "Metal Gear Solid Snake Figure"; TestProduct.ProductDescription = "A die-cast figurine of Solid Snake from Metal Gear Solid."; TestProduct.UnitPrice = 60.00; TestProduct.InStock = false; TestProduct.StockAmount = 0; TestProduct.DiscountPercentage = 20; TestProduct.DiscountActive = true; Products.ThisProduct = TestProduct; Products.Update(); Products.ThisProduct.Find(PrimaryKey); Assert.AreEqual(Products.ThisProduct, TestProduct); }
public void UpdateMethodOK() { //create an instance of the class we want to create clsProductCollection AllProducts = new clsProductCollection(); //create the item of test data clsProduct TestItem = new clsProduct(); Int32 PrimaryKey = 0; //set its properties TestItem.ProductName = "Samsung S9"; TestItem.Description = "Black"; TestItem.Price = 1234; TestItem.Active = true; //set ThisProduct to test the data AllProducts.ThisProduct = TestItem; //add the record PrimaryKey = AllProducts.Add(); //set primary key of TestItem.ProductNo = PrimaryKey; //modify the test data TestItem.ProductName = "IPhone"; TestItem.Description = "Gold"; TestItem.Price = 124; TestItem.Active = false; //set the record based on the new test data AllProducts.ThisProduct = TestItem; //update the record AllProducts.Update(); //find the record AllProducts.ThisProduct.Find(PrimaryKey); //test to see ThisStaff matches the test data Assert.AreEqual(AllProducts.ThisProduct, TestItem); }
protected void OK_Click(object sender, EventArgs e) { clsProduct AProduct = new clsProduct(); String ProductName = txtProductName.Text; String ProductDescription = txtProductDescription.Text; String UnitPrice = txtUnitPrice.Text; String StockAmount = txtStockAmount.Text; String DiscountPercentage = txtDiscountPercentage.Text; String Error = ""; Error = AProduct.Valid(ProductName, ProductDescription, UnitPrice, StockAmount, DiscountPercentage); if (Error == "") { if (Convert.ToInt32(StockAmount) == 0) { AProduct.InStock = false; } else { AProduct.InStock = true; } if (Convert.ToInt32(DiscountPercentage) == 0) { AProduct.DiscountActive = false; } else { AProduct.DiscountActive = true; } AProduct.ProductNo = ProductNo; AProduct.ProductName = ProductName; AProduct.ProductDescription = ProductDescription; AProduct.UnitPrice = Convert.ToDouble(UnitPrice); AProduct.StockAmount = Convert.ToInt32(StockAmount); AProduct.DiscountPercentage = Convert.ToInt32(DiscountPercentage); AProduct.Active = Active.Checked; clsProductCollection Products = new clsProductCollection(); if (ProductNo == -1) { Products.ThisProduct = AProduct; Products.Add(); } else { Products.ThisProduct.Find(ProductNo); Products.ThisProduct = AProduct; Products.Update(); } Response.Redirect("ProductList.aspx"); } else { lblError.Text = Error; } }
public void UpdateMethodOK() { clsProductCollection AllProducts = new clsProductCollection(); clsProduct TestProduct = new clsProduct(); Int32 PrimaryKey = 0; //set its propertieis TestProduct.Product_ID = 000022; TestProduct.Title = "Test"; TestProduct.Description = "Testing"; TestProduct.Unit_Price = Convert.ToDouble("50.00"); TestProduct.Release_Date = Convert.ToDateTime("12/08/1991"); TestProduct.Out_Of_Stock = "0"; TestProduct.Genre = "Horror"; TestProduct.Platform = "Sega Megadrive"; AllProducts.ThisProduct = TestProduct; //add test data PrimaryKey = AllProducts.Add(); //set primary key of test data TestProduct.Product_ID = PrimaryKey; //modify the test data TestProduct.Product_ID = 000007; TestProduct.Title = "Test2"; TestProduct.Description = "2Testing"; TestProduct.Unit_Price = Convert.ToDouble("60.00"); TestProduct.Release_Date = Convert.ToDateTime("12/08/1998"); TestProduct.Genre = "Rythem"; TestProduct.Platform = "Sega Saturn"; AllProducts.ThisProduct = TestProduct; //set the record based on the new test data AllProducts.ThisProduct = TestProduct; //update the record AllProducts.Update(); //find the record AllProducts.ThisProduct.Find(PrimaryKey); //test to see thisproduct matches the test data Assert.AreEqual(AllProducts.ThisProduct, TestProduct); }
public void UpdateMethodOK() { clsProductCollection AllProducts = new clsProductCollection(); clsProduct TestItem = new clsProduct(); Int32 PrimaryKey = 0; TestItem.Name = "Dave"; TestItem.Type = "Dave"; TestItem.Colour = "Dave"; TestItem.Cost = 1; TestItem.Stock_Count = 1; TestItem.Is_Available = true; TestItem.Next_Delivery = DateTime.Now.Date; AllProducts.ThisProduct = TestItem; PrimaryKey = AllProducts.Add(); TestItem.Product_ID = PrimaryKey; TestItem.Name = "Joe"; TestItem.Type = "Joe"; TestItem.Colour = "Joe"; TestItem.Cost = 21; TestItem.Stock_Count = 12; TestItem.Is_Available = false; TestItem.Next_Delivery = DateTime.Now.Date; AllProducts.ThisProduct = TestItem; AllProducts.Update(); AllProducts.ThisProduct.Find(PrimaryKey); Assert.AreEqual(AllProducts.ThisProduct, TestItem); }
//event handler for the ok button protected void btnOK_Click(object sender, EventArgs e) { //creates a new instance of clsProduct clsProduct AProduct = new clsProduct(); //capture product_id string ProductID = Convert.ToString(txtProductID); //capture title string Title = txtTitle.Text; //Capture Description string Description = txtDescription.Text; //Capture unit price string Unit_Price = txtUnitPrice.Text; //Capture Platform string Platform = txtPlatform.Text; //Capture Release_Date string Release_Date = txtReleaseDate.Text; //Capture Genre string Genre = txtGenre.Text; //Capture Out of stock string Out_Of_Stock = txtOut_Of_Stock.Text; //variable to store any error messages string Error = ""; //validate the data Error = AProduct.Valid(Title, Description, Unit_Price, Release_Date, Platform, Genre); if (Error == "") { //capture the product id AProduct.Product_ID = Product_ID; //capture the title AProduct.Title = Title; //capture the Description AProduct.Description = Description; //capture the Unit price AProduct.Unit_Price = Convert.ToDouble(Unit_Price); //capture the genre AProduct.Genre = Genre; //Capture the platform AProduct.Platform = Platform; //Capture the release date AProduct.Release_Date = Convert.ToDateTime(Release_Date); //capture the out of stock status AProduct.Out_Of_Stock = Out_Of_Stock; //Create a new instance of the address collection clsProductCollection ProductList = new clsProductCollection(); //if this is a new record then add the data if (Product_ID == -1) { //set the ThisProduct property ProductList.ThisProduct = AProduct; //Add the new record ProductList.Add(); } else//otherwise must be an update { //find the record to update ProductList.ThisProduct.Find(Product_ID); //set the thisproduct property ProductList.ThisProduct = AProduct; //update the record ProductList.Update(); } //Redirect back to the listpage Response.Redirect("ProductList.aspx"); } else { //display the error message lblError.Text = Error; } //store the product id in the session object Session["AProduct"] = AProduct; //Redirect to the viewer page Response.Redirect("ProductViewer.aspx"); }