public ActionResult Create(ScheduleViewModel ScheduleView) { Schedule schedule = new Schedule(); Route route = routeManager.GetRoute().FirstOrDefault(r => r.FromCityId == ScheduleView.FromCity && r.ToCityId == ScheduleView.ToCity); schedule.Route = route; schedule.RouteId = route.RouteID; Flight flight = flightMgr.GetFlight().FirstOrDefault(f => f.FlightID == ScheduleView.Flight); schedule.Flight = flight; schedule.FlightID = flight.FlightID; schedule.ArrivalTime = ScheduleView.ArrivalTime; schedule.DepartureTime = ScheduleView.DepartureTime; schedule.DurationInMins = ScheduleView.DurationInMins; FlightCost f1 = new FlightCost(); f1.TravelClassId = 1; f1.Schedule = schedule; f1.CostPerTicket = ScheduleView.Business.CostPerTicket; fcostMgr.AddFlightCost(f1); FlightCost f2 = new FlightCost(); f2.TravelClassId = 2; f2.CostPerTicket = ScheduleView.Business.CostPerTicket; f2.Schedule = schedule; fcostMgr.AddFlightCost(f2); //schMgr.AddSchedule(schedule); return(RedirectToAction("Index")); }
/// <summary> /// Update the existing flight cost for the specific schedule id for the database /// </summary> /// <parameter name="flightCostInfo"></parameter> /// <parameter name="scheduleInfo"></parameter> /// <returns>Returns the number of rows affected by the update</returns> public int UpdateScheduleFlightCost(long ScheduleId, FlightCost flightCostInfo) { try { return(ExecuteStoredProcedure("UpdateFlightCost", new SqlParameter() { ParameterName = "@scheduleid", DbType = DbType.Int32, Value = ScheduleId }, new SqlParameter() { ParameterName = "@classid", DbType = DbType.Int32, Value = flightCostInfo.Class }, new SqlParameter() { ParameterName = "@cost", DbType = DbType.Decimal, Value = flightCostInfo.CostPerTicket } )); } catch (Common.ConnectToDatabaseException) { throw new ScheduleDAOException("Unable to update schedule flight cost"); } catch (Exception) { throw new ScheduleDAOException("Unable to update schedule flight cost"); } }
/// <summary> /// Update the existing flight cost for a given schedule /// </summary> /// <parameter name="flightcost"></parameter> /// <parameter name="scheduleInfo"></parameter> /// <exception cref="ScheduleManagerException">Thorwn when unable to update the schedule cost</exception> /// <returns>Returns the number of rows being affected by the update</returns> public int UpdateScheduleFlightCost(long ScheduleId, FlightCost flightCostInfo) { try { return(scheduleDAO.UpdateScheduleFlightCost(ScheduleId, flightCostInfo)); } catch (ScheduleDAOException ex) { throw new ScheduleManagerException("Unable to update schedule flight cost", ex); } }
public void BindData() { scheduleid = Request.QueryString["scheduleid"].ToString(); IScheduleManager scheduleManager = (IScheduleManager)AirTravelManagerFactory.Create("ScheduleManager"); schedule = scheduleManager.GetSchedule(int.Parse(scheduleid)); FlightCost flightclass = new FlightCost(); GridView1.DataSource = schedule.GetFlightCosts(); GridView1.DataBind(); }
/// <summary> /// Update the existing flight cost for the specific schedule id for the database /// </summary> /// <parameter name="flightCostInfo"></parameter> /// <parameter name="scheduleInfo"></parameter> /// <returns>Returns the number of rows affected by the update</returns> public int UpdateScheduleFlightCost(Schedule scheduleInfo, FlightCost flightCostInfo) { try { db = GetDatabaseConnection(); return(db.ExecuteNonQuery("UpdateFlightCost", scheduleInfo.ID, flightCostInfo.Class, flightCostInfo.CostPerTicket)); } catch (Common.ConnectToDatabaseException) { throw new ScheduleDAOException("Unable to update schedule flight cost"); } catch (Exception) { throw new ScheduleDAOException("Unable to update schedule flight cost"); } }
/// <summary> /// Gets the flight costs for a given schedule /// </summary> /// <param name="scheduleId"></param> /// <returns></returns> public List <FlightCost> GetFlightCostsForSchedule(long scheduleId) { List <FlightCost> flightCosts = null; IDbConnection conn = null; try { conn = this.GetConnection(); conn.Open(); IDbCommand cmd = conn.CreateCommand(); cmd.CommandText = "getScheduleFlightCost"; cmd.CommandType = CommandType.StoredProcedure; IDataParameter p1 = cmd.CreateParameter(); p1.ParameterName = "@scheduleid"; p1.Value = scheduleId; cmd.Parameters.Add(p1); using (IDataReader Reader2 = cmd.ExecuteReader()) { flightCosts = new List <FlightCost>(); 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()); flightCosts.Add(classCost); } } } catch (Common.ConnectToDatabaseException ex) { throw new ScheduleDAOException("Unable to get the schedule cost details", ex); } catch (Exception ex) { throw new ScheduleDAOException("Unable to get the schedule cost details", ex); } return(flightCosts); }
/// <summary> /// Update the existing flight cost for the specific schedule id for the database /// </summary> /// <parameter name="FlightCostInfo"></parameter> /// <parameter name="ScheduleInfo"></parameter> /// <returns>int</returns> public int UpdateScheduleFlightCost(Schedule ScheduleInfo, FlightCost FlightCostInfo) { IDbConnection conn = null; try { conn = this.GetConnection(); conn.Open(); IDbCommand cmd = conn.CreateCommand(); cmd.CommandText = "UpdateFlightCost"; cmd.CommandType = CommandType.StoredProcedure; IDataParameter p1 = cmd.CreateParameter(); p1.ParameterName = "@scheduleid"; p1.Value = ScheduleInfo.ID; cmd.Parameters.Add(p1); IDataParameter p2 = cmd.CreateParameter(); p2.ParameterName = "@classid"; p2.Value = FlightCostInfo.Class; cmd.Parameters.Add(p2); IDataParameter p3 = cmd.CreateParameter(); p3.ParameterName = "@cost"; p3.Value = FlightCostInfo.CostPerTicket; cmd.Parameters.Add(p3); return(cmd.ExecuteNonQuery()); } catch (Common.ConnectToDatabaseException) { throw new ScheduleDAOException("Unable to update schedule flight cost"); } catch (Exception) { throw new ScheduleDAOException("Unable to update schedule flight cost"); } finally { conn.Close(); } }
/// <summary> /// Update the existing flight cost for the specific schedule id for the database /// </summary> /// <parameter name="flightCostInfo"></parameter> /// <parameter name="scheduleInfo"></parameter> /// <returns>Returns the status of the update</returns> public bool UpdateScheduleFlightCost(Schedule scheduleInfo, FlightCost flightCostInfo) { bool isUpdated = false; try { db = GetDatabaseConnection(); db.ExecuteNonQuery("UpdateFlightCost", scheduleInfo.ID, flightCostInfo.Class, flightCostInfo.CostPerTicket); isUpdated = true; } catch (Common.ConnectToDatabaseException) { throw new ScheduleDAOException("Unable to update schedule flight cost"); } catch (Exception) { throw new ScheduleDAOException("Unable to update schedule flight cost"); } return(isUpdated); }
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; } } } }
/// <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()); }
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; } } } }
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; } }
/// <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); }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { GridViewRow row = GridView1.Rows[e.RowIndex]; if (((TextBox)row.FindControl("txtCost")).Text.Length == 0) { lblError.Text = "Cost Cannot be Empty"; ((TextBox)row.FindControl("txtCost")).Focus(); } else { string txtClass = ((TextBox)row.FindControl("txtClass")).Text; int txtCost = Convert.ToInt32((((TextBox)row.FindControl("txtCost")).Text.ToString())); FlightCost _class = new FlightCost(); switch (txtClass) { case "Economy": _class.Class = TravelClass.Economy; break; case "Business": _class.Class = TravelClass.Business; break; default: break; } _class.CostPerTicket = txtCost; ScheduleManager obj = new ScheduleManager(); Schedule schedule = new Schedule(); Route route = new Route(); 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; Flight flight = new Flight(); flight.ID = long.Parse(dpFlightName.SelectedItem.Value); flight.Name = dpFlightName.SelectedItem.Text; scheduleId = Convert.ToInt64(Request.QueryString["scheduleid"]); schedule.ID = scheduleId; schedule.RouteInfo = route; schedule.FlightInfo = flight; obj.UpdateScheduleFlightCost(schedule, _class); e.Cancel = true; GridView1.EditIndex = -1; BindData(); lblError.Text = "Flight Cost Updated"; } } catch (ScheduleManagerException ex) { throw ex; } }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { GridViewRow row = GridView1.Rows[e.RowIndex]; TextBox txtCost = (TextBox)row.FindControl("txtCost"); decimal decCost = 0; if (!decimal.TryParse(txtCost.Text, out decCost)) { lblErrorMessageLocal.InnerText = "Cost should be a positive currency value"; txtCost.Focus(); } else if (decCost <= 0) { lblErrorMessageLocal.InnerText = "Cost should be a positive currency value"; txtCost.Focus(); } else { string txtClass = ((TextBox)row.FindControl("txtClass")).Text; FlightCost _class = new FlightCost(); switch (txtClass) { case "Economy": _class.Class = TravelClass.Economy; break; case "Business": _class.Class = TravelClass.Business; break; default: break; } _class.CostPerTicket = decCost; IScheduleManager scheduleManager = (IScheduleManager)AirTravelManagerFactory.Create("ScheduleManager"); //Schedule schedule = new Schedule(); //Route route = null; //string rid = dpRoute.SelectedValue; //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; //} //Flight flight = new Flight(); //flight.ID = long.Parse(dpFlightName.SelectedItem.Value); //flight.Name = dpFlightName.SelectedItem.Text; scheduleid = Request.QueryString["scheduleid"].ToString(); //schedule.ID = long.Parse(scheduleid); //schedule.RouteInfo = route; //schedule.FlightInfo = flight; scheduleManager.UpdateScheduleFlightCost(long.Parse(scheduleid), _class); e.Cancel = true; GridView1.EditIndex = -1; BindData(); //lblErrorMessageLocal.InnerText = "Flight Cost Updated"; } } catch (ScheduleManagerException ex) { lblErrorMessageLocal.InnerText = ex.Message; } }
///// <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); }