コード例 #1
0
        public void UpdateMethod()
        {
            //create an instance of a class
            clsPlaneCollection AllPlane = new clsPlaneCollection();
            //create the item of test data
            clsPlane TestItem = new clsPlane();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.LocationID = 2;
            TestItem.PlaneName  = "Emirates";
            TestItem.HoursFly   = 12;
            //set thisplane to the test data
            AllPlane.ThisPlane = TestItem;
            //add the record
            PrimaryKey = AllPlane.Add();
            //set the primary key of the test data
            TestItem.PlaneID = PrimaryKey;
            //modify the test data
            TestItem.LocationID = 3;
            TestItem.PlaneName  = "FlyDubai";
            TestItem.HoursFly   = 2;
            //set the record based on the new test data
            AllPlane.ThisPlane = TestItem;
            //update the record
            AllPlane.Update();
            //find the record
            AllPlane.ThisPlane.Find(PrimaryKey);
            //test to see thisplane matches the test data
            Assert.AreEqual(AllPlane.ThisPlane, TestItem);
        }
コード例 #2
0
    //function for updating new records
    void Update()
    {
        //create an instance of a class
        clsPlaneCollection PlaneBook = new clsPlaneCollection();
        //validate the data on the web form
        string Error = PlaneBook.ThisPlane.Valid(txtPlaneName.Text, txtHoursFly.Text);

        //if the data is ok then add it to the object
        if (Error == "")
        {
            //find the record to update
            PlaneBook.ThisPlane.Find(PlaneID);
            //get the data entered by the user
            PlaneBook.ThisPlane.PlaneName = txtPlaneName.Text;
            PlaneBook.ThisPlane.HoursFly  = Convert.ToInt32(txtHoursFly.Text);
            //Update the record
            PlaneBook.Update();
            //all done so redirect back to the main page
            Response.Redirect("PlaneList.aspx");
        }
        else
        {
            //report the error
            lblError.Text = "There were problems with the data entered " + Error;
        }
    }