private void GetClassDetails(Flight flight)
        {
            IDbConnection db = GetConnection();

            db.Open();
            IDbCommand cmd2 = db.CreateCommand();

            cmd2.CommandText = "GetFlightClasses";
            cmd2.CommandType = CommandType.StoredProcedure;
            IDbDataParameter p1 = cmd2.CreateParameter();

            p1.ParameterName = "@FlightId";
            p1.Value         = flight.ID;
            cmd2.Parameters.Add(p1);
            using (IDataReader reader2 = cmd2.ExecuteReader())
            {
                try
                {
                    while (reader2.Read())
                    {
                        FlightClass _class  = new FlightClass();
                        int         classid = int.Parse(reader2["ClassId"].ToString());
                        _class.ClassInfo = (TravelClass)classid;

                        _class.NoOfSeats = int.Parse(reader2["NoOfSeats"].ToString());
                        flight.AddClass(_class);
                    }
                    db.Close();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string flightName  = txtName.Text;
            int    airlineid   = int.Parse(ddlAirLine.SelectedItem.Value);
            string airlinename = ddlAirLine.SelectedItem.Text;
            Flight _flight     = new Flight()
            {
                Name = flightName, AirlineForFlight = new Airline()
                {
                    Id = airlineid, Name = airlinename
                }
            };
            FlightManager _flightManger = new FlightManager();

            try
            {
                foreach (RepeaterItem item in dlClass.Items)
                {
                    TextBox txtNoOfSeats = (TextBox)item.FindControl("txtNoOfSeats");
                    Label   lblClass     = (Label)item.FindControl("lblClass");

                    if (txtNoOfSeats.Text.Length == 0)
                    {
                        txtNoOfSeats.Focus();
                        lblError.Text = "No of Seats Cannot be Empty";
                        break;
                    }
                    else
                    {
                        if (txtNoOfSeats != null)
                        {
                            TravelClass travelClass = (TravelClass)Enum.Parse(typeof(TravelClass), lblClass.Text.Trim());
                            int         NoOfSeats   = int.Parse(txtNoOfSeats.Text);
                            FlightClass _class      = new FlightClass()
                            {
                                ClassInfo = travelClass, NoOfSeats = NoOfSeats
                            };
                            _flight.AddClass(_class);
                        }
                    }
                }
                if (_flightManger.AddFlight(_flight) == false)
                {
                    lblError.Text = "Flight Name already exists";
                }
                else
                {
                    lblError.Text = "Flight Added Successfully";
                }
            }
            catch (FlightManagerException exc)
            {
                lblError.Text = exc.Message;
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }
Exemple #3
0
        /// <summary>
        /// Get the flight details from the database
        /// </summary>
        /// <exception cref="FlightDAOException">Thorws an exception when unable to get flights</exception>
        /// <returns>Returns the list of flights from the database</returns>
        public List <Flight> GetFlights()
        {
            List <Flight> flights = new List <Flight>();

            try
            {
                Database db = GetDatabaseConnection();

                using (IDataReader reader = db.ExecuteReader("GetFlights"))
                {
                    while (reader.Read())
                    {
                        Flight flight = new Flight();

                        flight.ID                    = long.Parse(reader["FlightId"].ToString());
                        flight.Name                  = reader["FlightName"].ToString();
                        flight.AirlineForFlight      = new Airline();
                        flight.AirlineForFlight.Id   = int.Parse(reader["AirlineId"].ToString());
                        flight.AirlineForFlight.Name = reader["AirlineName"].ToString();
                        flight.AirlineForFlight.Code = reader["AirlineCode"].ToString();

                        using (IDataReader reader2 = db.ExecuteReader("GetFlightClasses", flight.ID))
                        {
                            try
                            {
                                while (reader2.Read())
                                {
                                    FlightClass _class  = new FlightClass();
                                    int         classid = int.Parse(reader2["ClassId"].ToString());
                                    _class.ClassInfo = (TravelClass)classid;

                                    _class.NoOfSeats = int.Parse(reader2["NoOfSeats"].ToString());
                                    flight.AddClass(_class);
                                }
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }
                        flights.Add(flight);
                    }
                }
            }
            catch (ConnectToDatabaseException ex)
            {
                throw new FlightDAOException("Unable to connect to database", ex);
            }
            catch (Exception ex)
            {
                throw new FlightDAOException("Unable to get flights", ex);
            }

            return(flights);
        }
Exemple #4
0
        /// <summary>
        /// Get the flight details from the database
        /// </summary>
        /// <exception cref="FlightDAOException">Thorws an exception when unable to get flights</exception>
        /// <returns>Returns the list of flights from the database</returns>
        public List <Flight> GetFlights()
        {
            List <Flight> flights = new List <Flight>();

            try
            {
                using (IDbConnection conn = GetConnection())
                {
                    using (IDataReader reader = ExecuteStoredProcedureResults(conn, "GetFlightsAndFlightClasses"))
                    {
                        while (reader.Read())
                        {
                            Flight flight = new Flight();

                            flight.ID                    = long.Parse(reader["FlightId"].ToString());
                            flight.Name                  = reader["FlightName"].ToString();
                            flight.AirlineForFlight      = new Airline();
                            flight.AirlineForFlight.Id   = int.Parse(reader["AirlineId"].ToString());
                            flight.AirlineForFlight.Name = reader["AirlineName"].ToString();
                            flight.AirlineForFlight.Code = reader["AirlineCode"].ToString();

                            flights.Add(flight);
                        }

                        Flight CurrentFlight = new Flight();
                        reader.NextResult();
                        while (reader.Read())
                        {
                            FlightClass _class  = new FlightClass();
                            int         classid = int.Parse(reader["ClassId"].ToString());
                            _class.ClassInfo = (TravelClass)classid;
                            _class.NoOfSeats = int.Parse(reader["NoOfSeats"].ToString());

                            if (CurrentFlight.ID != (long)reader["FlightId"])
                            {
                                CurrentFlight = flights.Where(f => f.ID == (long)reader["FlightId"]).First();
                            }
                            CurrentFlight.AddClass(_class);
                        }
                    }
                }
            }
            catch (ConnectToDatabaseException ex)
            {
                throw new FlightDAOException("Unable to connect to database", ex);
            }
            catch (Exception ex)
            {
                throw new FlightDAOException("Unable to get flights", ex);
            }

            return(flights);
        }
Exemple #5
0
        /// <summary>
        /// Get the flights details for a given flight from the database
        /// </summary>
        /// <parameter name="FlightId"></parameter>
        /// <returns>Returns the flight for a given id from the database</returns>
        public Flight GetFlight(int flightId)
        {
            Flight flight = null;

            try
            {
                using (IDataReader Reader = GetDatabaseConnection().ExecuteReader("GetFlightsID", flightId))
                {
                    while (Reader.Read())
                    {
                        flight = new Flight();

                        flight.ID                    = long.Parse(Reader["FlightId"].ToString());
                        flight.Name                  = Reader["FlightName"].ToString();
                        flight.AirlineForFlight      = new Airline();
                        flight.AirlineForFlight.Id   = int.Parse(Reader["AirlineId"].ToString());
                        flight.AirlineForFlight.Name = Reader["AirlineName"].ToString();
                        flight.AirlineForFlight.Code = Reader["AirlineCode"].ToString();

                        using (IDataReader Reader2 = GetDatabaseConnection().ExecuteReader("GetFlightClasses", flight.ID))
                        {
                            try
                            {
                                while (Reader2.Read())
                                {
                                    FlightClass fClass  = new FlightClass();
                                    int         classId = int.Parse(Reader2["ClassId"].ToString());
                                    fClass.ClassInfo = (TravelClass)classId;

                                    fClass.NoOfSeats = int.Parse(Reader2["NoOfSeats"].ToString());
                                    flight.AddClass(fClass);
                                }
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                        }
                    }
                }
            }
            catch (Common.ConnectToDatabaseException)
            {
                throw new FlightDAOException("Unable to get the flight details");
            }
            catch (Exception)
            {
                throw new FlightDAOException("Unable to get the flight details");
            }
            return(flight);
        }
Exemple #6
0
        /// <summary>
        /// Get the flights details for a given flight from the database
        /// </summary>
        /// <parameter name="FlightId"></parameter>
        /// <returns>Returns the flight for a given id from the database</returns>
        public Flight GetFlight(int flightId)
        {
            Flight flight = null;

            try
            {
                using (IDbConnection conn = GetConnection())
                {
                    using (IDataReader Reader = ExecuteStoredProcedureResults(conn, "GetFlightAndClasses",
                                                                              new SqlParameter()
                    {
                        ParameterName = "@FlightID", DbType = DbType.Int32, Value = flightId
                    }
                                                                              ))
                    {
                        Reader.Read();

                        flight = new Flight();

                        flight.ID                    = long.Parse(Reader["FlightId"].ToString());
                        flight.Name                  = Reader["FlightName"].ToString();
                        flight.AirlineForFlight      = new Airline();
                        flight.AirlineForFlight.Id   = int.Parse(Reader["AirlineId"].ToString());
                        flight.AirlineForFlight.Name = Reader["AirlineName"].ToString();
                        flight.AirlineForFlight.Code = Reader["AirlineCode"].ToString();

                        Reader.NextResult();
                        while (Reader.Read())
                        {
                            FlightClass fClass  = new FlightClass();
                            int         classId = int.Parse(Reader["ClassId"].ToString());
                            fClass.ClassInfo = (TravelClass)classId;

                            fClass.NoOfSeats = int.Parse(Reader["NoOfSeats"].ToString());
                            flight.AddClass(fClass);
                        }
                    }
                }
            }
            catch (Common.ConnectToDatabaseException)
            {
                throw new FlightDAOException("Unable to get the flight details");
            }
            catch (Exception)
            {
                throw new FlightDAOException("Unable to get the flight details");
            }
            return(flight);
        }
Exemple #7
0
        ///// <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 flights details for a given flight from the database
        /// </summary>
        /// <parameter name="FlightId"></parameter>
        /// <returns>Returns a flight for a given flight id from the database</returns>
        public Flight GetFlight(int FlightId)
        {
            Flight        flight = null;
            IDbConnection conn   = null;
            IDbConnection conn2  = null;

            try
            {
                conn = this.GetConnection();
                conn.Open();
                IDbCommand cmd1 = conn.CreateCommand();
                cmd1.CommandText = "GetFlightsID";
                cmd1.CommandType = CommandType.StoredProcedure;

                IDataParameter p1 = cmd1.CreateParameter();
                p1.ParameterName = "@FlightID";
                p1.Value         = FlightId;
                cmd1.Parameters.Add(p1);


                conn2 = this.GetConnection();
                conn2.Open();
                IDbCommand cmd2 = conn2.CreateCommand();
                cmd2.CommandText = "GetFlightClasses";
                cmd2.CommandType = CommandType.StoredProcedure;
                IDataParameter p = cmd2.CreateParameter();
                p.ParameterName = "@FlightId";
                cmd2.Parameters.Add(p);

                using (IDataReader Reader = cmd1.ExecuteReader())
                {
                    while (Reader.Read())
                    {
                        flight                       = new Flight();
                        flight.ID                    = long.Parse(Reader["FlightId"].ToString());
                        flight.Name                  = Reader["FlightName"].ToString();
                        flight.AirlineForFlight      = new Airline();
                        flight.AirlineForFlight.Id   = int.Parse(Reader["AirlineId"].ToString());
                        flight.AirlineForFlight.Name = Reader["AirlineName"].ToString();
                        flight.AirlineForFlight.Code = Reader["AirlineCode"].ToString();

                        p.Value = flight.ID;

                        using (IDataReader reader2 = cmd2.ExecuteReader())
                        {
                            try
                            {
                                while (reader2.Read())
                                {
                                    FlightClass fClass  = new FlightClass();
                                    int         classid = int.Parse(reader2["ClassId"].ToString());
                                    fClass.ClassInfo = (TravelClass)classid;

                                    fClass.NoOfSeats = int.Parse(reader2["NoOfSeats"].ToString());
                                    flight.AddClass(fClass);
                                }
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                        }
                    }
                }
            }
            catch (Common.ConnectToDatabaseException)
            {
                throw new FlightDAOException("Unable to get the flight details");
            }
            catch (Exception)
            {
                throw new FlightDAOException("Unable to get the flight details");
            }
            finally
            {
                if (conn != null && conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }

                if (conn2 != null && conn2.State == ConnectionState.Open)
                {
                    conn2.Close();
                }
            }

            return(flight);
        }
Exemple #9
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                if (string.IsNullOrWhiteSpace(txtName.Text))
                {
                    ctlAdminMaster.ErrorMessage = "Flight Name Can't be Empty";
                    txtName.Focus();
                }
                else if (ddlAirLine.Text.Equals("None") == true)
                {
                    ctlAdminMaster.ErrorMessage = "Select Airline Name";
                    ddlAirLine.Focus();
                }
                else
                {
                    string flightName  = txtName.Text;
                    int    airlineid   = int.Parse(ddlAirLine.SelectedItem.Value);
                    string airlinename = ddlAirLine.SelectedItem.Text;
                    Flight _flight     = new Flight()
                    {
                        Name = flightName, AirlineForFlight = new Airline()
                        {
                            Id = airlineid, Name = airlinename
                        }
                    };
                    IFlightManager flightManager = (IFlightManager)AirTravelManagerFactory.Create("FlightManager");
                    bool           blnSeatsValid = true;

                    try
                    {
                        foreach (RepeaterItem item in dlClass.Items)
                        {
                            TextBox txtNoOfSeats     = (TextBox)item.FindControl("txtNoOfSeats");
                            Label   lblClass         = (Label)item.FindControl("lblClass");
                            int     intNumberOfSeats = 0;

                            if ((!int.TryParse(txtNoOfSeats.Text, out intNumberOfSeats)) || (intNumberOfSeats <= 0))
                            {
                                txtNoOfSeats.Focus();
                                ctlAdminMaster.ErrorMessage = "Seat count should be a positive number";
                                blnSeatsValid = false;
                                break;
                            }
                            else
                            {
                                if (txtNoOfSeats != null)
                                {
                                    TravelClass travelClass = (TravelClass)Enum.Parse(typeof(TravelClass), lblClass.Text.Trim());
                                    FlightClass _class      = new FlightClass()
                                    {
                                        ClassInfo = travelClass, NoOfSeats = intNumberOfSeats
                                    };
                                    _flight.AddClass(_class);
                                }
                            }
                        }
                        if (blnSeatsValid)
                        {
                            if (flightManager.AddFlight(_flight) == false)
                            {
                                ctlAdminMaster.ErrorMessage = "Flight Name already exists";
                            }
                            else
                            {
                                ctlAdminMaster.ErrorMessage = "Flight Added Successfully";
                            }
                        }
                    }
                    catch (FlightManagerException exc)
                    {
                        ctlAdminMaster.ErrorMessage = exc.Message;
                    }
                }
            }
        }