Beispiel #1
0
    void Update()
    {
        //create an instance of the car log
        Class_Library.clsCarCollection CarLog = new Class_Library.clsCarCollection();
        //validate the date on the web form
        String Error = CarLog.ThisCar.Valid(txtCarName.Text, txtModel.Text, txtBodyType.Text, txtYearMade.Text);

        //if the data is OK then add it to the object
        if (Error == "")
        {
            //find the record to update
            CarLog.ThisCar.Find(CarID);
            //get the data entered by the user
            CarLog.ThisCar.CarName  = txtCarName.Text;
            CarLog.ThisCar.Model    = txtModel.Text;
            CarLog.ThisCar.BodyType = txtBodyType.Text;
            CarLog.ThisCar.Price    = Convert.ToDecimal(txtPrice.Text);
            CarLog.ThisCar.Stock    = Convert.ToInt32(txtStock.Text);
            CarLog.ThisCar.YearMade = Convert.ToDateTime(txtYearMade.Text);
            CarLog.ThisCar.Fuel     = chkDiesel.Checked = true;
            CarLog.ThisCar.Fuel     = chkPetrol.Checked = false;
            CarLog.ThisCar.ColourNo = Convert.ToInt32(ddlColourNo.SelectedValue);
            //update the record
            CarLog.Update();
            //all  done to redirect back to the main page
            Response.Redirect("DefaultCar.aspx");
        }
        else
        {
            //report an error
            lblError.Text = "there were problems with the data entered" + Error;
        }
    }
Beispiel #2
0
 void DisplayCars()
 {
     //create an instance of the Car Collection
     Class_Library.clsCarCollection CarLog = new Class_Library.clsCarCollection();
     //set the data source to the list of cars in the colllection
     lstCars.DataSource = CarLog.CarList;
     //set the name of the primary key
     lstCars.DataValueField = "CarID";
     //set the data field to display
     lstCars.DataTextField = "Model";
     //bind the data to the list
     lstCars.DataBind();
 }