//function for updating new records
    void Update()
    {
        //create an instance of the Location Book
        clsLocationCollection LocationBook = new clsLocationCollection();
        //validate the data on the web form
        string Error = LocationBook.ThisLocation.Valid(txtCountryDeparture.Text, txtCountryDestination.Text, txtAirportDeparture.Text, txtAirportDestination.Text);

        //if the data is ok then add it to the object
        if (Error == "")
        {
            //get the data entered by the user
            LocationBook.ThisLocation.CountryDeparture   = txtCountryDeparture.Text;
            LocationBook.ThisLocation.CountryDestination = txtCountryDestination.Text;
            LocationBook.ThisLocation.AirportDeparture   = txtAirportDeparture.Text;
            LocationBook.ThisLocation.AirportDestination = txtAirportDestination.Text;
            //update the record
            LocationBook.Update();
            //all done so redirect back to the main page
            Response.Redirect("LocationList.aspx");
        }
        else
        {
            //report an error
            lblError.Text = "There are problems with the data entered " + Error;
        }
    }
Ejemplo n.º 2
0
        public void UpdateMethod()
        {
            //create an instance of a class
            clsLocationCollection AllLocation = new clsLocationCollection();
            //create the item of test data
            clsLocation TestItem = new clsLocation();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.PlaneID            = 2;
            TestItem.CountryDeparture   = "Bulgaria";
            TestItem.CountryDestination = "Africa";
            TestItem.AirportDeparture   = "Heathrow";
            TestItem.AirportDestination = "Gatwick";
            //set this location to the test data
            AllLocation.ThisLocation = TestItem;
            //add the record
            PrimaryKey = AllLocation.Add();
            //set the primary key of the test data
            TestItem.LocationID = PrimaryKey;
            //modify the test data
            TestItem.PlaneID            = 3;
            TestItem.CountryDeparture   = "Belgium";
            TestItem.CountryDestination = "Zimbabwe";
            TestItem.AirportDeparture   = "Lahore";
            TestItem.AirportDestination = "Heathrow";
            //set the record based on the new test data
            AllLocation.ThisLocation = TestItem;
            //update the record
            AllLocation.Update();
            //find the record
            AllLocation.ThisLocation.Find(PrimaryKey);
            //test to see thislocation matches the test data
            Assert.AreEqual(AllLocation.ThisLocation, TestItem);
        }