/// <summary> /// Gets the schedules from the database /// </summary> /// <returns>A Collection of Schedules</returns> public Model.Entities.AirTravel.Schedule[] GetSchedules() { List <Schedule> _schedulelist = new List <Schedule>(); try { IDbConnection conn = this.GetConnection(); IDbConnection conn2 = this.GetConnection(); conn.Open(); conn2.Open(); IDbCommand cmd = conn.CreateCommand(); cmd.CommandText = "GetScheduleFlight"; cmd.CommandType = CommandType.StoredProcedure; using (IDataReader Reader = cmd.ExecuteReader()) { while (Reader.Read()) { Schedule _schedule = new Schedule(); _schedule.ID = long.Parse(Reader["ScheduleId"].ToString()); Airline _airline = new Airline(); _airline.Id = int.Parse(Reader["AirlineId"].ToString()); _airline.Name = Reader["AirlineName"].ToString(); Flight _flight = new Flight(); _flight.ID = long.Parse(Reader["FlightId"].ToString()); _flight.AirlineForFlight = _airline; _flight.Name = Reader["FlightName"].ToString(); _schedule.FlightInfo = _flight; City _fromcity = new City(); _fromcity.CityId = long.Parse(Reader["FromId"].ToString()); _fromcity.Name = Reader["FromCity"].ToString(); City _tocity = new City(); _tocity.CityId = long.Parse(Reader["ToId"].ToString()); _tocity.Name = Reader["ToCity"].ToString(); Route _route = new Route(); _route.ID = long.Parse(Reader["RouteId"].ToString()); _route.FromCity = _fromcity; _route.ToCity = _tocity; _route.DistanceInKms = long.Parse(Reader["DistanceInKms"].ToString()); _schedule.RouteInfo = _route; DateTime dateTime = DateTime.Parse(Reader["DepartureTime"].ToString()); TimeSpan dtime = new TimeSpan(dateTime.Hour, dateTime.Minute, dateTime.Second); _schedule.DepartureTime = dtime; dateTime = DateTime.Parse(Reader["ArrivalTime"].ToString()); TimeSpan atime = new TimeSpan(dateTime.Hour, dateTime.Minute, dateTime.Second); _schedule.ArrivalTime = atime; _schedule.DurationInMins = int.Parse(Reader["DurationInMins"].ToString()); _schedule.IsActive = bool.Parse(Reader["Status"].ToString()); IDbCommand cmd2 = conn2.CreateCommand(); cmd2.CommandText = "getScheduleFlightCost"; cmd2.CommandType = CommandType.StoredProcedure; IDataParameter param = cmd2.CreateParameter(); param.Direction = ParameterDirection.Input; param.ParameterName = "@scheduleid"; param.Value = _schedule.ID; cmd2.Parameters.Add(param); using (IDataReader Reader2 = cmd2.ExecuteReader()) { try { while (Reader2.Read()) { FlightCost _classcost = new FlightCost(); int classid = int.Parse(Reader2["ClassId"].ToString()); _classcost.Class = (TravelClass)classid; _classcost.CostPerTicket = int.Parse(Reader2["CostPerTicket"].ToString()); _schedule.AddFlightCost(_classcost); } } catch (Exception ex) { throw ex; } } _schedulelist.Add(_schedule); } } } catch (Common.ConnectToDatabaseException) { throw new ScheduleDAOException("Unable to get schedules"); } catch (Exception) { throw new ScheduleDAOException("Unable to get schedules"); } return(_schedulelist.ToArray()); }
/// <summary> /// Get the schedule details for a given schedule id from the database /// </summary> /// <parameter name="ScheduleId"></parameter> /// <returns>Returns the schedule information<Schedule></returns> public Model.Entities.AirTravel.Schedule GetSchedule(long scheduleId) { Schedule schedule = null; IDbConnection conn = null; try { conn = this.GetConnection(); conn.Open(); IDbCommand cmd = conn.CreateCommand(); cmd.CommandText = "getScheduleDetails_BasedID"; cmd.CommandType = CommandType.StoredProcedure; IDataParameter p1 = cmd.CreateParameter(); p1.ParameterName = "@scheduleid"; p1.Value = scheduleId; cmd.Parameters.Add(p1); using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { schedule = new Schedule(); schedule.ID = long.Parse(reader["ScheduleId"].ToString()); Airline airline = new Airline(); airline.Id = int.Parse(reader["AirlineId"].ToString()); airline.Name = reader["AirlineName"].ToString(); Flight flight = new Flight(); flight.ID = long.Parse(reader["FlightId"].ToString()); flight.AirlineForFlight = airline; flight.Name = reader["FlightName"].ToString(); schedule.FlightInfo = flight; City fromcity = new City(); fromcity.CityId = long.Parse(reader["FromId"].ToString()); fromcity.Name = reader["FromCity"].ToString(); City tocity = new City(); tocity.CityId = long.Parse(reader["ToId"].ToString()); tocity.Name = reader["ToCity"].ToString(); Route route = new Route(); route.ID = long.Parse(reader["RouteId"].ToString()); route.FromCity = fromcity; route.ToCity = tocity; route.DistanceInKms = long.Parse(reader["DistanceInKms"].ToString()); schedule.RouteInfo = route; DateTime dtime = Convert.ToDateTime(reader["DepartureTime"]); TimeSpan sp1 = new TimeSpan(dtime.Hour, dtime.Minute, dtime.Second); DateTime atime = Convert.ToDateTime(reader["ArrivalTime"]); TimeSpan sp2 = new TimeSpan(atime.Hour, atime.Minute, atime.Second); schedule.DepartureTime = sp1; schedule.ArrivalTime = sp2; schedule.DurationInMins = int.Parse(reader["DurationInMins"].ToString()); schedule.IsActive = bool.Parse(reader["Status"].ToString()); //Method call to get flight costs List <FlightCost> flightCosts = GetFlightCostsForSchedule(schedule.ID); foreach (FlightCost cost in flightCosts) { schedule.AddFlightCost(cost); } } } } catch (Common.ConnectToDatabaseException) { throw new ScheduleDAOException("Unable to get the schedule details"); } catch (ScheduleDAOException ex) { throw ex; } catch (Exception) { throw new ScheduleDAOException("Unable to get the schedule details"); } return(schedule); }
protected void btnAdd_Click(object sender, EventArgs e) { ScheduleManager obj = new ScheduleManager(); Schedule schedule = new Schedule(); Route route = new Route(); City fromcity = new City(); if (dpFromCity.SelectedItem.Value != "None" && dpFromCity.SelectedItem.Value != "none") { fromcity.CityId = long.Parse(dpFromCity.SelectedItem.Value); } fromcity.Name = dpFromCity.SelectedItem.Text; route.FromCity = fromcity; City tocity = new City(); if (dpToCity.SelectedItem.Value != "None" && dpToCity.SelectedItem.Value != "none") { tocity.CityId = long.Parse(dpToCity.SelectedItem.Value); } tocity.Name = dpToCity.SelectedItem.Text; route.ToCity = tocity; schedule.RouteInfo = route; TimeSpan t1 = new TimeSpan(0, 0, 0); if (DropDownList4.SelectedItem.ToString() != "None" && DropDownList4.SelectedItem.ToString() != "none") { t1 = TimeSpan.Parse(DropDownList4.SelectedItem.ToString() + ":" + DropDownList5.SelectedItem.ToString()); } TimeSpan t2 = new TimeSpan(0, 0, 0); if (DropDownList1.SelectedItem.ToString() != "None" && DropDownList1.SelectedItem.ToString() != "none") { TimeSpan.Parse(DropDownList1.SelectedItem.ToString() + ":" + DropDownList2.SelectedItem.ToString()); } total = int.Parse((t1 - t2).TotalMinutes.ToString()); txtDuration.Text = total.ToString(); Flight flight = new Flight(); if (dpFlightName.SelectedItem != null && dpFlightName.SelectedItem.Text != "None") { flight.ID = long.Parse(dpFlightName.SelectedItem.Value); } if (dpFlightName.SelectedItem != null) { flight.Name = dpFlightName.SelectedItem.Text; } schedule.RouteInfo = route; schedule.FlightInfo = flight; TimeSpan tempT1; TimeSpan.TryParse(DropDownList1.SelectedItem.ToString() + ":" + DropDownList2.SelectedItem.ToString(), out tempT1); schedule.DepartureTime = tempT1; TimeSpan.TryParse(DropDownList4.SelectedItem.ToString() + ":" + DropDownList5.SelectedItem.ToString(), out tempT1); schedule.ArrivalTime = tempT1; schedule.DurationInMins = total; schedule.IsActive = chkStatus.Checked; foreach (RepeaterItem item in Repeater1.Items) { Label lblclassname = (Label)item.FindControl("ClassName"); TextBox txtcost = (TextBox)item.FindControl("txtCostPerTicket"); if (txtcost != null || lblclassname != null) { string classname = lblclassname.Text; string val = txtcost.Text; FlightCost fc = new FlightCost(); fc.Class = (TravelClass)Enum.Parse(typeof(TravelClass), classname); fc.CostPerTicket = decimal.Parse(txtcost.Text); schedule.AddFlightCost(fc); } } try { if (obj.AddSchedule(schedule)) { lblError.Text = "Schedule Added Successfully"; } else { lblError.Text = "Unable to add schedule"; } } catch (ScheduleManagerException ex) { lblError.Text = ex.Message; } catch (Exception ex) { lblError.Text = ex.Message; } }
protected void btnAdd_Click(object sender, EventArgs e) { IScheduleManager scheduleManager = (IScheduleManager)AirTravelManagerFactory.Create("Schedule"); Schedule schedule = new Schedule(); Route route = new Route(); if (dpFromCity.Text.Equals("None") == true) { lblError.Text = "Select From City"; dpFromCity.Focus(); } else if (dpToCity.Text.Equals("None") == true) { lblError.Text = "Select To City"; dpToCity.Focus(); } else if (dpAirlineName.Text.Equals("None") == true) { lblError.Text = "Select Airline Name"; dpAirlineName.Focus(); } else if (dpFlightName.Text.Equals("None") == true) { lblError.Text = "Select Flight Name"; dpFlightName.Focus(); } else if (DropDownList1.Text.Equals("None") == true) { lblError.Text = "Select Departure Hours"; DropDownList1.Focus(); } else if (DropDownList2.Text.Equals("None") == true) { lblError.Text = "Select Departure Minutes"; DropDownList2.Focus(); } else if (DropDownList4.Text.Equals("None") == true) { lblError.Text = "Select Arrival Hours"; DropDownList4.Focus(); } else if (DropDownList5.Text.Equals("None") == true) { lblError.Text = "Select Arrival Minutes"; DropDownList5.Focus(); } else { City fromcity = new City(); fromcity.CityId = long.Parse(dpFromCity.SelectedItem.Value); fromcity.Name = dpFromCity.SelectedItem.Text; route.FromCity = fromcity; City tocity = new City(); tocity.CityId = long.Parse(dpToCity.SelectedItem.Value); tocity.Name = dpToCity.SelectedItem.Text; route.ToCity = tocity; schedule.RouteInfo = route; int routeID = scheduleManager.GetRouteID(schedule); schedule.RouteInfo.ID = routeID; if (routeID == 0) { lblError.Text = "Select the Existing Route"; dpFromCity.Focus(); } else { TimeSpan t1 = TimeSpan.Parse(DropDownList4.SelectedItem.ToString() + ":" + DropDownList5.SelectedItem.ToString()); TimeSpan t2 = TimeSpan.Parse(DropDownList1.SelectedItem.ToString() + ":" + DropDownList2.SelectedItem.ToString()); total = int.Parse((t1 - t2).TotalMinutes.ToString()); txtDuration.Text = total.ToString(); Flight flight = new Flight(); flight.ID = long.Parse(dpFlightName.SelectedItem.Value); flight.Name = dpFlightName.SelectedItem.Text; schedule.RouteInfo = route; schedule.FlightInfo = flight; schedule.DepartureTime = TimeSpan.Parse(DropDownList1.SelectedItem.ToString() + ":" + DropDownList2.SelectedItem.ToString()); schedule.ArrivalTime = TimeSpan.Parse(DropDownList4.SelectedItem.ToString() + ":" + DropDownList5.SelectedItem.ToString()); schedule.DurationInMins = total; schedule.IsActive = chkStatus.Checked; foreach (RepeaterItem item in Repeater1.Items) { Label lblclassname = (Label)item.FindControl("ClassName"); TextBox txtcost = (TextBox)item.FindControl("txtCostPerTicket"); if (txtcost.Text.Length == 0) { lblError.Text = "Flight Cost Can't be Empty"; txtcost.Focus(); break; } else { if (txtcost != null || lblclassname != null) { string classname = lblclassname.Text; string val = txtcost.Text; FlightCost fc = new FlightCost(); fc.Class = (TravelClass)Enum.Parse(typeof(TravelClass), classname); fc.CostPerTicket = decimal.Parse(txtcost.Text); schedule.AddFlightCost(fc); } } } try { scheduleManager.AddSchedule(schedule); lblError.Text = "Schedule Added Successfully"; } catch (ScheduleManagerException ex) { lblError.Text = ex.Message; } } } }
/// <summary> /// Gets the schedules from the database /// </summary> /// <returns>Returns the list of schedules from the database<Schedule></returns> public List <Model.Entities.AirTravel.Schedule> GetSchedules() { List <Schedule> schedules = new List <Schedule>(); try { using (IDataReader reader = GetDatabaseConnection().ExecuteReader("getScheduleFlight")) { while (reader.Read()) { Schedule schedule = new Schedule(); schedule.ID = long.Parse(reader["ScheduleId"].ToString()); Airline airline = new Airline(); airline.Id = int.Parse(reader["AirlineId"].ToString()); airline.Name = reader["AirlineName"].ToString(); Flight flight = new Flight(); flight.ID = long.Parse(reader["FlightId"].ToString()); flight.AirlineForFlight = airline; flight.Name = reader["FlightName"].ToString(); schedule.FlightInfo = flight; City fromCity = new City(); fromCity.CityId = long.Parse(reader["FromId"].ToString()); fromCity.Name = reader["FromCity"].ToString(); City toCity = new City(); toCity.CityId = long.Parse(reader["ToId"].ToString()); toCity.Name = reader["ToCity"].ToString(); Route route = new Route(); route.ID = long.Parse(reader["RouteId"].ToString()); route.FromCity = fromCity; route.ToCity = toCity; route.DistanceInKms = long.Parse(reader["DistanceInKms"].ToString()); schedule.RouteInfo = route; DateTime dtime = Convert.ToDateTime(reader["DepartureTime"]); TimeSpan sp1 = new TimeSpan(dtime.Hour, dtime.Minute, dtime.Second); schedule.DepartureTime = sp1; DateTime atime = Convert.ToDateTime(reader["ArrivalTime"]); TimeSpan sp2 = new TimeSpan(atime.Hour, atime.Minute, atime.Second); schedule.ArrivalTime = sp2; schedule.DurationInMins = int.Parse(reader["DurationInMins"].ToString()); schedule.IsActive = bool.Parse(reader["Status"].ToString()); using (IDataReader reader2 = GetDatabaseConnection().ExecuteReader("getScheduleFlightCost", schedule.ID)) { try { while (reader2.Read()) { FlightCost classCost = new FlightCost(); int classid = int.Parse(reader2["ClassId"].ToString()); classCost.Class = (TravelClass)classid; classCost.CostPerTicket = int.Parse(reader2["CostPerTicket"].ToString()); schedule.AddFlightCost(classCost); } } catch (Exception ex) { throw ex; } } schedules.Add(schedule); } } } catch (Common.ConnectToDatabaseException) { throw new ScheduleDAOException("Unable to get schedules"); } catch (Exception) { throw new ScheduleDAOException("Unable to get schedules"); } return(schedules); }
///// <summary> ///// Gets the flight schedules for the search made by the user ///// </summary> ///// <param name="searchInformation"></param> ///// <exception cref="SearchFlightDAOException">Throws SearchFlightDAOException if flights are not available or if there is any other exception</exception> ///// <returns>Returns the schedules for the given search - which is a custom collection</returns> //public Schedules SearchForFlight(SearchInfo searchInformation) //{ // Schedules schCollection = null; // try // { // Database db = GetDatabaseConnection(); // TimeSpan ts; // int hours = 0; // int minutes = 0; // int seconds = 0; // using (IDataReader reader = db.ExecuteReader("GetFlightSchedules", searchInformation.FromCity.CityId, searchInformation.ToCity.CityId, (int)searchInformation.Class)) // { // schCollection = new Schedules(); // while (reader.Read()) // { // Schedule sch = new Schedule(); // sch.ID = Convert.ToInt64(reader["ScheduleId"]); // hours = Convert.ToDateTime(reader["ArrivalTime"]).Hour; // minutes = Convert.ToDateTime(reader["ArrivalTime"]).Minute; // seconds = Convert.ToDateTime(reader["ArrivalTime"]).Second; // ts = new TimeSpan(hours, minutes, seconds); // sch.ArrivalTime = ts; // hours = Convert.ToDateTime(reader["DepartureTime"]).Hour; // minutes = Convert.ToDateTime(reader["DepartureTime"]).Minute; // seconds = Convert.ToDateTime(reader["DepartureTime"]).Second; // ts = new TimeSpan(hours, minutes, seconds); // sch.DepartureTime = ts; // sch.DurationInMins = Convert.ToInt16(reader["DurationInMins"]); // sch.IsActive = Convert.ToBoolean(reader["IsActive"]); // Airline objAirlineForFlight = new Airline(); // objAirlineForFlight.Code = reader["AirlineCode"].ToString(); // objAirlineForFlight.Id = Convert.ToInt16(reader["AirlineId"]); // objAirlineForFlight.Logo = reader["AirlineLogo"].ToString(); // objAirlineForFlight.Name = reader["AirlineName"].ToString(); // Flight objFlight = new Flight(); // objFlight.ID = Convert.ToInt16(reader["FlightId"]); // objFlight.Name = reader["FlightName"].ToString(); // objFlight.AirlineForFlight = objAirlineForFlight; // FlightClass fc = new FlightClass(); // fc.ClassInfo = (TravelClass)(Convert.ToInt16(reader["ClassId"])); // fc.NoOfSeats = Convert.ToInt32(reader["NoOfSeats"]); // objFlight.AddClass(fc); // FlightCost objFlightCost = new FlightCost(); // objFlightCost.CostPerTicket = Convert.ToDecimal(reader["CostPerTicket"]); // objFlightCost.Class = (TravelClass)(Convert.ToInt16(reader["ClassId"])); // City objFromCity = new City(); // objFromCity.CityId = Convert.ToInt64(reader["FromCityId"]); // objFromCity.Name = reader["FromCityName"].ToString(); // City objToCity = new City(); // objToCity.CityId = Convert.ToInt64(reader["ToCityId"]); // objToCity.Name = reader["ToCityName"].ToString(); // Route objRoute = new Route(); // objRoute.DistanceInKms = Convert.ToDouble(reader["DistanceInKms"]); // objRoute.FromCity = objFromCity; // objRoute.ToCity = objToCity; // sch.FlightInfo = objFlight; // sch.AddFlightCost(objFlightCost); // sch.RouteInfo = objRoute; // schCollection.AddSchedule(sch); // } // } // } // catch (Common.ConnectToDatabaseException ex) // { // throw new SearchFlightDAOException("Unable to Search for Flight", ex); // } // catch (Exception ex) // { // throw new SearchFlightDAOException("Unable to Search for Flight", ex); // } // return schCollection; //} #endregion #region Method to get the flights for the search made by a user /// <summary> /// Gets the flight schedules for the search made by the user /// </summary> /// <param name="searchInformation"></param> /// <exception cref="SearchFlightDAOException">Throws SearchFlightDAOException if flights are not available or if there is any other exception</exception> /// <returns>Returns the schedules for the given search - which is a custom collection</returns> public Schedules SearchForFlight(SearchInfo searchInformation) { Schedules schCollection = null; try { IDbConnection conn = this.GetConnection(); conn.Open(); TimeSpan ts; int hours = 0; int minutes = 0; int seconds = 0; IDbCommand cmd = conn.CreateCommand(); cmd.CommandText = "GetFlightSchedules"; cmd.CommandType = CommandType.StoredProcedure; IDataParameter fromCityId = cmd.CreateParameter(); fromCityId.ParameterName = "FromCityId"; fromCityId.Value = searchInformation.FromCity.CityId; IDataParameter toCityId = cmd.CreateParameter(); toCityId.ParameterName = "ToCityId"; toCityId.Value = searchInformation.ToCity.CityId; IDataParameter classId = cmd.CreateParameter(); classId.ParameterName = "ClassId"; classId.Value = (int)searchInformation.Class; cmd.Parameters.Add(fromCityId); cmd.Parameters.Add(toCityId); cmd.Parameters.Add(classId); using (IDataReader reader = cmd.ExecuteReader()) { schCollection = new Schedules(); while (reader.Read()) { Schedule sch = new Schedule(); sch.ID = Convert.ToInt64(reader["ScheduleId"]); hours = Convert.ToDateTime(reader["ArrivalTime"]).Hour; minutes = Convert.ToDateTime(reader["ArrivalTime"]).Minute; seconds = Convert.ToDateTime(reader["ArrivalTime"]).Second; ts = new TimeSpan(hours, minutes, seconds); sch.ArrivalTime = ts; hours = Convert.ToDateTime(reader["DepartureTime"]).Hour; minutes = Convert.ToDateTime(reader["DepartureTime"]).Minute; seconds = Convert.ToDateTime(reader["DepartureTime"]).Second; ts = new TimeSpan(hours, minutes, seconds); sch.DepartureTime = ts; sch.DurationInMins = Convert.ToInt16(reader["DurationInMins"]); sch.IsActive = Convert.ToBoolean(reader["IsActive"]); Airline objAirlineForFlight = new Airline(); objAirlineForFlight.Code = reader["AirlineCode"].ToString(); objAirlineForFlight.Id = Convert.ToInt16(reader["AirlineId"]); objAirlineForFlight.Logo = reader["AirlineLogo"].ToString(); objAirlineForFlight.Name = reader["AirlineName"].ToString(); Flight objFlight = new Flight(); objFlight.ID = Convert.ToInt16(reader["FlightId"]); objFlight.Name = reader["FlightName"].ToString(); objFlight.AirlineForFlight = objAirlineForFlight; FlightClass fc = new FlightClass(); fc.ClassInfo = (TravelClass)(Convert.ToInt16(reader["ClassId"])); fc.NoOfSeats = Convert.ToInt32(reader["NoOfSeats"]); objFlight.AddClass(fc); FlightCost objFlightCost = new FlightCost(); objFlightCost.CostPerTicket = Convert.ToDecimal(reader["CostPerTicket"]); objFlightCost.Class = (TravelClass)(Convert.ToInt16(reader["ClassId"])); City objFromCity = new City(); objFromCity.CityId = Convert.ToInt64(reader["FromCityId"]); objFromCity.Name = reader["FromCityName"].ToString(); City objToCity = new City(); objToCity.CityId = Convert.ToInt64(reader["ToCityId"]); objToCity.Name = reader["ToCityName"].ToString(); Route objRoute = new Route(); objRoute.DistanceInKms = Convert.ToDouble(reader["DistanceInKms"]); objRoute.FromCity = objFromCity; objRoute.ToCity = objToCity; sch.FlightInfo = objFlight; sch.AddFlightCost(objFlightCost); sch.RouteInfo = objRoute; schCollection.AddSchedule(sch); } } } catch (Common.ConnectToDatabaseException ex) { throw new SearchFlightDAOException("Unable to Search for Flight", ex); } catch (Exception ex) { throw new SearchFlightDAOException("Unable to Search for Flight", ex); } return(schCollection); }
/// <summary> /// Get the schedule details for a given schedule id from the database /// </summary> /// <parameter name="scheduleId"></parameter> /// <returns>A Schedule for a given schedule id<Schedule></returns> public Model.Entities.AirTravel.Schedule GetSchedule(int scheduleId) { Schedule schedule = null; try { using (db = GetConnection()) { using (IDataReader reader = ExecuteStoredProcedureResults(db, "GetScheduleFlightAndCosts", new SqlParameter() { ParameterName = "@scheduleid", DbType = DbType.Int32, Value = scheduleId } )) { reader.Read(); schedule = new Schedule(); schedule.ID = long.Parse(reader["ScheduleId"].ToString()); Airline airline = new Airline(); airline.Id = int.Parse(reader["AirlineId"].ToString()); airline.Name = reader["AirlineName"].ToString(); Flight flight = new Flight(); flight.ID = long.Parse(reader["FlightId"].ToString()); flight.AirlineForFlight = airline; flight.Name = reader["FlightName"].ToString(); schedule.FlightInfo = flight; City fromCity = new City(); fromCity.CityId = long.Parse(reader["FromId"].ToString()); fromCity.Name = reader["FromCity"].ToString(); City toCity = new City(); toCity.CityId = long.Parse(reader["ToId"].ToString()); toCity.Name = reader["ToCity"].ToString(); Route route = new Route(); route.ID = long.Parse(reader["RouteId"].ToString()); route.FromCity = fromCity; route.ToCity = toCity; route.DistanceInKms = long.Parse(reader["DistanceInKms"].ToString()); schedule.RouteInfo = route; DateTime dtime = Convert.ToDateTime(reader["DepartureTime"]); TimeSpan dTS = new TimeSpan(dtime.Hour, dtime.Minute, dtime.Second); DateTime atime = Convert.ToDateTime(reader["ArrivalTime"]); TimeSpan aTS = new TimeSpan(atime.Hour, atime.Minute, atime.Second); schedule.DepartureTime = dTS; schedule.ArrivalTime = aTS; schedule.DurationInMins = int.Parse(reader["DurationInMins"].ToString()); schedule.IsActive = bool.Parse(reader["Status"].ToString()); reader.NextResult(); while (reader.Read()) { FlightCost classCost = new FlightCost(); int classid = int.Parse(reader["ClassId"].ToString()); classCost.Class = (TravelClass)classid; classCost.CostPerTicket = Convert.ToDecimal(reader["CostPerTicket"].ToString()); schedule.AddFlightCost(classCost); } } } } catch (Common.ConnectToDatabaseException) { throw new ScheduleDAOException("Unable to get the schedule details"); } catch (Exception) { throw new ScheduleDAOException("Unable to get the schedule details"); } return(schedule); }
/// <summary> /// Gets the schedules from the database /// </summary> /// <returns>Returns the list of schedules from the database<Schedule></returns> public List <Model.Entities.AirTravel.Schedule> GetSchedules() { List <Schedule> schedules = new List <Schedule>(); try { using (db = GetConnection()) { using (IDataReader reader = ExecuteStoredProcedureResults(db, "GetScheduleFlightsAndCosts")) { while (reader.Read()) { Schedule schedule = new Schedule(); schedule.ID = long.Parse(reader["ScheduleId"].ToString()); Airline airline = new Airline(); airline.Id = int.Parse(reader["AirlineId"].ToString()); airline.Name = reader["AirlineName"].ToString(); Flight flight = new Flight(); flight.ID = long.Parse(reader["FlightId"].ToString()); flight.AirlineForFlight = airline; flight.Name = reader["FlightName"].ToString(); schedule.FlightInfo = flight; City fromCity = new City(); fromCity.CityId = long.Parse(reader["FromId"].ToString()); fromCity.Name = reader["FromCity"].ToString(); City toCity = new City(); toCity.CityId = long.Parse(reader["ToId"].ToString()); toCity.Name = reader["ToCity"].ToString(); Route route = new Route(); route.ID = long.Parse(reader["RouteId"].ToString()); route.FromCity = fromCity; route.ToCity = toCity; route.DistanceInKms = long.Parse(reader["DistanceInKms"].ToString()); schedule.RouteInfo = route; DateTime dtime = Convert.ToDateTime(reader["DepartureTime"]); TimeSpan dTS = new TimeSpan(dtime.Hour, dtime.Minute, dtime.Second); DateTime atime = Convert.ToDateTime(reader["ArrivalTime"]); TimeSpan aTS = new TimeSpan(atime.Hour, atime.Minute, atime.Second); schedule.DepartureTime = dTS; schedule.ArrivalTime = aTS; schedule.DurationInMins = int.Parse(reader["DurationInMins"].ToString()); schedule.IsActive = bool.Parse(reader["Status"].ToString()); schedules.Add(schedule); } Schedule CurrentSchedule = new Schedule(); reader.NextResult(); while (reader.Read()) { FlightCost classCost = new FlightCost(); int classid = int.Parse(reader["ClassId"].ToString()); classCost.Class = (TravelClass)classid; classCost.CostPerTicket = Convert.ToDecimal(reader["CostPerTicket"]); if (CurrentSchedule.ID != (int)reader["ClassId"]) { CurrentSchedule = schedules.Where(s => s.ID == (long)reader["ScheduleId"]).First(); } CurrentSchedule.AddFlightCost(classCost); } } } } catch (Common.ConnectToDatabaseException) { throw new ScheduleDAOException("Unable to get schedules"); } catch (Exception) { throw new ScheduleDAOException("Unable to get schedules"); } return(schedules); }
protected void btnAdd_Click(object sender, EventArgs e) { IScheduleManager scheduleManager = (IScheduleManager)AirTravelManagerFactory.Create("ScheduleManager"); Schedule schedule = new Schedule(); Route route = null; if (dpAirlineName.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select Airline Name"; dpAirlineName.Focus(); } else if (dpFlightName.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select Flight Name"; dpFlightName.Focus(); } else if (dpDepartHours.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select Departure Hours"; dpDepartHours.Focus(); } else if (dpDepartMins.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select Departure Minutes"; dpDepartMins.Focus(); } else if (dpArrivalHours.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select Arrival Hours"; dpArrivalHours.Focus(); } else if (dpArrivalMins.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select Arrival Minutes"; dpArrivalMins.Focus(); } else { string rid = dpRoute.SelectedValue; if (rid.Equals("-1")) { ctlAdminMaster.ErrorMessage = "Select a route"; return; } IRouteManager routeManager = (IRouteManager)BusinessObjectManager.GetRouteManager(); try { List <Route> routes = routeManager.GetRoutes(); foreach (Route r in routes) { if (r.ID == Convert.ToInt32(rid)) { route = r; break; } } } catch (RouteManagerException ex) { ctlAdminMaster.ErrorMessage = ex.Message; } schedule.RouteInfo = route; if (scheduleManager.GetRouteID(schedule) == 0) { ctlAdminMaster.ErrorMessage = "Select the Existing Route"; //dpFromCity.Focus(); } else { TimeSpan t1 = TimeSpan.Parse(dpArrivalHours.SelectedItem.ToString() + ":" + dpArrivalMins.SelectedItem.ToString()); TimeSpan t2 = TimeSpan.Parse(dpDepartHours.SelectedItem.ToString() + ":" + dpDepartMins.SelectedItem.ToString()); total = int.Parse((t1 - t2).TotalMinutes.ToString()); if (total == 0) { ctlAdminMaster.ErrorMessage = "The departure time and the arrival time cannot be same"; return; } if (total < 0) { total = (24 * 60) + total; } txtDuration.Text = total.ToString(); Flight flight = new Flight(); flight.ID = long.Parse(dpFlightName.SelectedItem.Value); flight.Name = dpFlightName.SelectedItem.Text; schedule.RouteInfo = route; schedule.FlightInfo = flight; schedule.DepartureTime = TimeSpan.Parse(dpDepartHours.SelectedItem.ToString() + ":" + dpDepartMins.SelectedItem.ToString()); schedule.ArrivalTime = TimeSpan.Parse(dpArrivalHours.SelectedItem.ToString() + ":" + dpArrivalMins.SelectedItem.ToString()); schedule.DurationInMins = total; schedule.IsActive = chkStatus.Checked; foreach (RepeaterItem item in Repeater1.Items) { Label lblclassname = (Label)item.FindControl("ClassName"); TextBox txtcost = (TextBox)item.FindControl("txtCostPerTicket"); decimal cost = 0; try { cost = Convert.ToDecimal(txtcost.Text); } catch (FormatException) { ctlAdminMaster.ErrorMessage = "Cost should be a positive currency value"; txtcost.Focus(); return; } if (cost <= 0) { ctlAdminMaster.ErrorMessage = "Cost should be a positive currency value"; txtcost.Focus(); return; } else { if (txtcost != null || lblclassname != null) { string classname = lblclassname.Text; string val = txtcost.Text; FlightCost fc = new FlightCost(); fc.Class = (TravelClass)Enum.Parse(typeof(TravelClass), classname); fc.CostPerTicket = decimal.Parse(txtcost.Text); schedule.AddFlightCost(fc); } } } //Extracted from the loop preventing a potential exception try { scheduleManager.AddSchedule(schedule); ctlAdminMaster.ErrorMessage = "Schedule Added Successfully"; //Response.Redirect("~/Admin/Home.aspx"); } catch (ScheduleManagerException ex) { ctlAdminMaster.ErrorMessage = ex.Message; } } } }