public void UpdateMethod() { //create an instance of a class clsFlightCollection AllFlight = new clsFlightCollection(); //create the item of test data clsFlight TestItem = new clsFlight(); //var to store the primary key Int32 PrimaryKey = 0; //set its properties TestItem.TicketID = 2; TestItem.DateOfBirth = "1st May 2000"; TestItem.Gate = "12B"; TestItem.DepartureDate = DateTime.Now.Date; //set thisflight to the test data AllFlight.ThisFlight = TestItem; //add the record PrimaryKey = AllFlight.Add(); //set the primary key of the test data TestItem.FlightID = PrimaryKey; //modify the test data TestItem.TicketID = 3; TestItem.DateOfBirth = "11th April 2001"; TestItem.Gate = "1D"; TestItem.DepartureDate = DateTime.Now.Date; //set the record based on the new test data AllFlight.ThisFlight = TestItem; //update the record AllFlight.Update(); //find the record AllFlight.ThisFlight.Find(PrimaryKey); //test to see thisflight matches the test data Assert.AreEqual(AllFlight.ThisFlight, TestItem); }
//function for updating new records void Update() { //create an instance of the Ticket Book clsFlightCollection FlightBook = new clsFlightCollection(); //validate the data on the web form string Error = FlightBook.ThisFlight.Valid(txtDateOfBirth.Text, txtGate.Text, txtDepartureDate.Text); //if the data is ok then add it to the object if (Error == "") { //get the data entered by the user FlightBook.ThisFlight.DateOfBirth = txtDateOfBirth.Text; FlightBook.ThisFlight.Gate = txtGate.Text; FlightBook.ThisFlight.DepartureDate = Convert.ToDateTime(txtDepartureDate.Text); //update the record FlightBook.Update(); //all done so redirect back to the main page Response.Redirect("FlightList.aspx"); } else { //report the error lblError.Text = "There were problems with the data entered " + Error; } }
void Update40() { //create an instance of the flight book MyClassLibrary.clsFlightCollection Flights = new clsFlightCollection(); //validate the data on the web form //Valid(string flightNo, string airline, string destination, string arrival, string arrivalAirport, string departure, string departureAirport) string Error = Flights.ThisFlight.Valid(txtFlightNo.Text, txtAirline.Text, txtDestination.Text, txtArrivalTime.Text, txtArrival.Text, txtDepartureTime.Text, txtDeparture.Text); //if the data is OK then add it to the object if (Error == "") { //get the data entered by the user Flights.ThisFlight.Find(FlightID); Flights.ThisFlight.FlightNo = txtFlightNo.Text; Flights.ThisFlight.Airline = txtAirline.Text; Flights.ThisFlight.Destination = txtDestination.Text; Flights.ThisFlight.ArrivalAirport = txtArrivalTime.Text; Flights.ThisFlight.Arrival = Convert.ToDateTime(txtArrivalTime.Text); Flights.ThisFlight.Departure = Convert.ToDateTime(txtDepartureTime.Text); Flights.ThisFlight.DepartureAirport = txtDepartureTime.Text; //add the record Flights.Update(); //all done so redirect back to the main page //Response.Redirect("frmFlightsMain.cs"); } else { //report an error lblError.Text = "There were problems with the data entered" + Error; } }
public void UpdateMethodOK() { //create an instance of the class we want to create clsFlightCollection AllFlights = new clsFlightCollection(); //create the item of test data clsFlights TestItem = new clsFlights(); //var to store the primary key Int32 PrimaryKey = 0; //set its properties TestItem.FlightNo = "AA11"; TestItem.Airline = "Air India"; TestItem.ArrivalAirport = "DXB"; TestItem.Arrival = DateTime.Now.Date; TestItem.Departure = DateTime.Now.Date; TestItem.DepartureAirport = "MCR"; TestItem.Destination = "Dubai"; //set ThisFlights to the test data AllFlights.ThisFlight = TestItem; //add the record PrimaryKey = AllFlights.Add(); //set the primary key of the test data TestItem.FlightID = PrimaryKey; //modify the test data TestItem.FlightNo = "AA30"; TestItem.Airline = "Air France"; TestItem.ArrivalAirport = "LHR"; TestItem.Arrival = DateTime.Now.Date; TestItem.Departure = DateTime.Now.Date; TestItem.DepartureAirport = "DHL"; TestItem.Destination = "Germany"; //set the record based on the new test data AllFlights.ThisFlight = TestItem; //update the record AllFlights.Update(); //find the record AllFlights.ThisFlight.Find(PrimaryKey); //test to see ThisFlights matches the test data Assert.AreEqual(AllFlights.ThisFlight, TestItem); }