// function for adding car park reservations void Add() { // create an instance of the car park collection class clscarparkCollection Reservation = new clscarparkCollection(); DateTime startDate = Convert.ToDateTime(txtStartDate.Text); DateTime endDate = Convert.ToDateTime(txtEndDate.Text); Int32 NOD = Convert.ToInt32((endDate - startDate).Days); // validate the data Boolean OK = Reservation.ThisCarPark.Valid(txtBookingDate.Text, txtCarReg.Text, txtStartDate.Text, txtEndDate.Text, ddlLocation.Text); // if the date is OK then add it to the object if (OK == true) { // get the data entered by the user //DateTime startDate = Convert.ToDateTime(txtStartDate.Text); //DateTime endDate = Convert.ToDateTime(txtEndDate.Text); //Int32 NOD = Convert.ToInt32((endDate - startDate).Days); Reservation.ThisCarPark.BookingDate = Convert.ToDateTime(txtBookingDate.Text); Reservation.ThisCarPark.CarReg = txtCarReg.Text; Reservation.ThisCarPark.StartDate = Convert.ToDateTime(txtStartDate.Text); Reservation.ThisCarPark.EndDate = Convert.ToDateTime(txtEndDate.Text); Reservation.ThisCarPark.Location = Convert.ToString(ddlLocation.SelectedValue); Reservation.ThisCarPark.Price = Convert.ToDecimal(NOD * 10); // add the record Reservation.Add(); //Response.Redirect("CarResDefault.aspx"); } else { // state error lblError.Text = "There were problems, bro!"; } }
void DeleteReservation() { //fucntion to delete the selected record //create an instance of the car park reservation clscarparkCollection AReservation = new clscarparkCollection(); //find a record to delete AReservation.ThisCarPark.Find(CarParkID); //delete the record AReservation.Delete(); }
void DisplayReg() { //create an instance of the car reg clscarparkCollection Reservation = new clscarparkCollection(); //find the record to update Reservation.ThisCarPark.Find(CarParkID); //display the data for this record txtBookingDate.Text = Reservation.ThisCarPark.BookingDate.ToString(); txtCarReg.Text = Reservation.ThisCarPark.CarReg; txtStartDate.Text = Reservation.ThisCarPark.StartDate.ToString(); txtEndDate.Text = Reservation.ThisCarPark.EndDate.ToString(); ddlLocation.SelectedValue = Reservation.ThisCarPark.Location; }
//void DisplayCarReg() //{ // //create an instance of the car park collection // clscarparkCollection carpark = new clscarparkCollection(); // //set the data source to the list box // LstCarReg.DataSource = carpark.CarParkList; // //set the name of the primary key // LstCarReg.DataValueField = "CarParkID"; // //Set the data field to display // LstCarReg.DataTextField = "CarReg"; // //bind the data to the text // LstCarReg.DataBind(); //} // function to populate the list box Int32 DisplayCarReg(string CarRegFilter) { // create an instance of the car park cloolection clscarparkCollection carreg = new clscarparkCollection(); // var for record count Int32 RecordCount; // var for first name string CarReg; Int32 CarParkId; DateTime BookingDate; DateTime StartDate; DateTime EndDate; string Price; // var for Index Int32 Index = 0; // clear the list of any existing item LstCarReg.Items.Clear(); // call the filter method by staff last name carreg.FilterByCarReg(CarRegFilter); // get the count of records RecordCount = carreg.Count; // loop through each record found using the index while (Index < RecordCount) { // get the first name of the staff member CarReg = Convert.ToString(carreg.CarParkList[Index].CarReg); CarParkId = Convert.ToInt32(carreg.CarParkList[Index].carparkid); BookingDate = Convert.ToDateTime(carreg.CarParkList[Index].BookingDate.ToShortDateString()); StartDate = Convert.ToDateTime(carreg.CarParkList[Index].StartDate); EndDate = Convert.ToDateTime(carreg.CarParkList[Index].EndDate); Price = Convert.ToString(carreg.CarParkList[Index].Price); ListItem NewItem = new ListItem(CarReg + "........................." + BookingDate.ToShortDateString() + ".................................." + StartDate.ToShortDateString() + ".............................." + EndDate.ToShortDateString() + "................." + Price, CarParkId.ToString()); // add the item to the list LstCarReg.Items.Add(NewItem); // increment the index Index++; } // return the number of records found return(RecordCount); }
//Function for updating record void Update() { //create an instance of the car reg clscarparkCollection Reservation = new clscarparkCollection(); DateTime startDate = Convert.ToDateTime(txtStartDate.Text); DateTime endDate = Convert.ToDateTime(txtEndDate.Text); Int32 NOD = Convert.ToInt32((endDate - startDate).Days); // validate the data //validate the data on the web form Boolean OK = Reservation.ThisCarPark.Valid(txtBookingDate.Text, txtCarReg.Text, txtStartDate.Text, txtEndDate.Text, ddlLocation.Text); //if the data is ok then add to the object if (OK == true) { //DateTime startDate = Convert.ToDateTime(txtStartDate.Text); //DateTime endDate = Convert.ToDateTime(txtEndDate.Text); //Int32 NOD = Convert.ToInt32((endDate - startDate).Days); //find the record to update Reservation.ThisCarPark.Find(CarParkID); //get the data entered by the user Reservation.ThisCarPark.BookingDate = Convert.ToDateTime(txtBookingDate.Text); Reservation.ThisCarPark.CarReg = txtCarReg.Text; Reservation.ThisCarPark.StartDate = Convert.ToDateTime(txtStartDate.Text); Reservation.ThisCarPark.EndDate = Convert.ToDateTime(txtEndDate.Text); Reservation.ThisCarPark.Location = Convert.ToString(ddlLocation.SelectedValue); Reservation.ThisCarPark.Price = Convert.ToDecimal(NOD * 10); //update the record Reservation.Update(); //Response.Redirect("CarResDefault.aspx"); } else { //report an error lblError.Text = "There wre problem with the date entered"; } }