public void UpdateMethodOK() { clsCarsCollection AllCars = new clsCarsCollection(); clsCars TestCar = new clsCars(); Int32 PrimaryKey = 0; TestCar.CarMake = "Mercedes"; TestCar.CarModel = "S Class"; TestCar.CarModelNumber = "VRi122"; TestCar.CarColour = "Blue"; TestCar.CarPrice = 1; TestCar.CarTypeNumber = 1; TestCar.CarReleaseDate = "11/10/2001"; AllCars.ThisCar = TestCar; PrimaryKey = AllCars.Add(); TestCar.CarNo = PrimaryKey; TestCar.CarMake = "Mer"; TestCar.CarModel = "SAClass"; TestCar.CarModelNumber = "Vi122"; TestCar.CarColour = "Black"; TestCar.CarPrice = 2; TestCar.CarTypeNumber = 3; TestCar.CarReleaseDate = "30/11/2015"; AllCars.ThisCar = TestCar; AllCars.Update(); AllCars.ThisCar.Find(PrimaryKey); Assert.AreEqual(AllCars.ThisCar, TestCar); }
void Update() //function for updating records. { //create an instance. clsCarsCollection Cars = new clsCarsCollection(); //validate the data on the web form. Boolean OK = Cars.ThisCar.Valid(txtReceptionistCarManufacturer.Text, txtReceptionistCarModel.Text, txtReceptionistCarRegistrationPlate.Text, txtReceptionistCarColour.Text, txtReceptionistCarNumberOfDoors.Text, txtReceptionistCarNumberOfSeats.Text, txtReceptionistSupplierID.Text); //if the data is OK then add it to the object. if (OK == true) { //find the record to update. Cars.ThisCar.Find(CarID); //get the data entered by the user. Cars.ThisCar.CarManufacturer = txtReceptionistCarManufacturer.Text; Cars.ThisCar.CarModel = txtReceptionistCarModel.Text; Cars.ThisCar.CarRegistrationPlate = txtReceptionistCarRegistrationPlate.Text; Cars.ThisCar.CarColour = txtReceptionistCarColour.Text; Cars.ThisCar.CarNumberOfDoors = Convert.ToInt32(txtReceptionistCarNumberOfDoors.Text); Cars.ThisCar.CarNumberOfSeats = Convert.ToInt32(txtReceptionistCarNumberOfSeats.Text); Cars.ThisCar.CarNeedsRepair = ChkBoxReceptionistNeedsRepair.Checked; Cars.ThisCar.CarSold = ChkBoxReceptionistSold.Checked; Cars.ThisCar.SupplierID = Convert.ToInt32(txtReceptionistSupplierID.Text); //update the record Cars.Update(); lblError.Text = ""; Response.Redirect("ReceptionistHomepage.aspx"); } else { //report an error lblError.Text = "There were problems with the data you have entered."; } }
public void CarUpdateMethodOk() { //create an instance of the class we want to create. clsCarsCollection AllCars = new clsCarsCollection(); //create the item of test data clsCar TestItem = new clsCar(); //variable to store the primary key. Int32 PrimaryKey = 0; //set it's properties. TestItem.CarManufacturer = "BMW"; TestItem.CarModel = "i8"; TestItem.CarRegistrationPlate = "FE17 GTE"; TestItem.CarColour = "yellow"; TestItem.CarNumberOfDoors = 5; TestItem.CarNumberOfSeats = 5; TestItem.CarNeedsRepair = false; TestItem.CarSold = true; //set thiscar to the test date AllCars.ThisCar = TestItem; //add the record PrimaryKey = AllCars.Add(); //set the primary key of the test data. TestItem.CarID = PrimaryKey; //Modify the test data TestItem.CarManufacturer = "Audi"; TestItem.CarModel = "s5"; TestItem.CarRegistrationPlate = "FE15 EDS"; TestItem.CarColour = "White"; TestItem.CarNumberOfDoors = 3; TestItem.CarNumberOfSeats = 5; TestItem.CarNeedsRepair = true; TestItem.CarSold = false; //set the record based on the new test data AllCars.ThisCar = TestItem; //update the record AllCars.Update(); //find the record AllCars.ThisCar.Find(PrimaryKey); //test to see ThisCar matches the test data. Assert.AreEqual(AllCars.ThisCar, TestItem); }
void Update() { clsCarsCollection CarShop = new clsCarsCollection(); String Error = CarShop.ThisCar.Valid(txtCarMake.Text, txtCarModel.Text, txtCarModelNumber.Text, txtCarColour.Text, txtCarRDate.Text, Convert.ToInt32(txtCarPrice.Text)); if (Error == "") { CarShop.ThisCar.Find(CarNo); CarShop.ThisCar.CarMake = txtCarMake.Text; CarShop.ThisCar.CarModel = txtCarModel.Text; CarShop.ThisCar.CarModelNumber = txtCarModelNumber.Text; CarShop.ThisCar.CarColour = txtCarColour.Text; CarShop.ThisCar.CarReleaseDate = txtCarRDate.Text; CarShop.ThisCar.CarPrice = Convert.ToInt32(txtCarPrice.Text); CarShop.ThisCar.CarTypeNumber = Convert.ToInt32(drpCarType.SelectedValue); CarShop.Update(); Response.Redirect("Default.aspx"); } else { lblError.Text = "There was a problem with he data entered" + Error; } }