public Flight(int id) //creates flight using a reservation ID { try { this.resId = id; this.planeName = DBPlanes.getName(DBReservations.getPlane(resId)); this.capacity = DBPlanes.getCapacity(DBReservations.getPlane(resId)); this.departureTime = DBReservations.getDate(resId); this.destination = DBDestinations.getLocation(DBReservations.getDestination(resId)); this.travelDistance = DBDestinations.getDistanceFromLR(this.destination); this.flightSpeed = DBPlanes.getSpeed(DBPlanes.getID(this.planeName)); this.passengerCount = 0; this.travelTime = ((this.travelDistance * 2) / this.flightSpeed) + 1; //Travel time to and from destination with 1 extra hour for refuling and acceleration/deceleration; List <string> flightResList = DBReservations.getReservationsByPlane(DBPlanes.getID(this.planeName)); foreach (String s in flightResList) // "Out of all the reservations made for the plane that this Flight belongs to..." -ksm { int resNum = Convert.ToInt32(s); if (this.departureTime == DBReservations.getDate(resNum) && this.destination == DBDestinations.getLocation(DBReservations.getDestination(resNum))) { this.passengerCount++; //"... Add 1 passenger for each reservation that matches this flight." -ksm } } this.seatsAvailable = this.capacity - this.passengerCount; this.returnTime = this.departureTime; TimeSpan time = TimeSpan.FromHours(travelTime); this.returnTime = this.returnTime + time; } catch (Exception ex) { throw ex; } }
protected void Page_Load(object sender, EventArgs e) { //login check CookieHandler.checkLogin(); CookieHandler.clearResultsCookies(); //clear cookies if second reservation or more this session //this populates the name of the current user into the Label1 textbox Label1.Text = CookieHandler.getUserFullName(); //destinationDropDownList.Items.Clear(); //jetsDropDownList.Items.Clear(); //String[] destList = DBDestinations.getDestinationsList().ToArray(); //foreach (string s in destList) //{ // destinationDropDownList.Items.Add(s); //automatically adds database items to dropdown list -ksm //} //foreach (var pair in planes) //{ // int key = pair.Key; // Plane p = pair.Value; // if (p.isAvailable()) // { // jetsDropDownList.Items.Add(p.name); //automatically adds available jets to dropdownlist -ksm // } //} if (!IsPostBack) { Dictionary <int, Plane> planes = (Dictionary <int, Plane>)Session["planes"]; String[] destList; destList = DBDestinations.getDestinationsList().ToArray(); foreach (string s in destList) { destinationDropDownList.Items.Add(s); //automatically adds database items to dropdown list -ksm } foreach (var pair in planes) { int key = pair.Key; Plane p = pair.Value; if (p.isAvailable()) { jetsDropDownList.Items.Add(p.name); //automatically adds available jets to dropdownlist -ksm } } } }
protected void Button1_Click(object sender, EventArgs e) { String jet = jetsDropDownList.SelectedValue; String dest = destinationDropDownList.SelectedValue; DateTime date = Calendar1.SelectedDate; if (ampmDropDownList.SelectedValue == "PM") { int hours; if (hourBox.Text == "12") { hours = Convert.ToInt32(hourBox.Text); } else { hours = Convert.ToInt32(hourBox.Text) + 12; } TimeSpan time = new TimeSpan(hours, Convert.ToInt32(minuteBox.Text), 0); date = date.Date + time; } else { int hours; if (hourBox.Text == "12") { hours = Convert.ToInt32(hourBox.Text) - 12; } else { hours = Convert.ToInt32(hourBox.Text); } TimeSpan time = new TimeSpan(hours, Convert.ToInt32(minuteBox.Text), 0); date = date.Date + time; } DBReservations.RegisterReservation(DBPlanes.getID(jet), CookieHandler.getID(), DBDestinations.getID(dest), date); //sets cookies for use in results page CookieHandler.setCookie("jet", DBPlanes.getName(DBPlanes.getID(jet))); CookieHandler.setCookie("dest", destinationDropDownList.SelectedValue); CookieHandler.setCookie("date", date.ToString()); //change page to results HttpContext.Current.Response.Redirect("Results.aspx"); }