Exemplo n.º 1
0
        public static List <ArrivalCity> GetAll()
        {
            List <ArrivalCity> allArrivalCities = new List <ArrivalCity> {
            };
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM arrival_cities;";
            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int         id = rdr.GetInt32(0);
                string      arrivalCityName = rdr.GetString(1);
                ArrivalCity newArrivalCity  = new ArrivalCity(arrivalCityName, id);
                allArrivalCities.Add(newArrivalCity);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allArrivalCities);
        }
Exemplo n.º 2
0
        public static ArrivalCity Find(int arrivalId)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM arrival_cities WHERE id = (@searchId);";

            MySqlParameter searchId = new MySqlParameter();

            searchId.ParameterName = "@searchId";
            searchId.Value         = arrivalId;
            cmd.Parameters.Add(searchId);

            var    rdr             = cmd.ExecuteReader() as MySqlDataReader;
            int    id              = 0;
            string arrivalCityName = "";

            while (rdr.Read())
            {
                id = rdr.GetInt32(0);
                arrivalCityName = rdr.GetString(1);
            }
            ArrivalCity newArrivalCity = new ArrivalCity(arrivalCityName, id);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(newArrivalCity);
        }
Exemplo n.º 3
0
//saves input to join table
        public void SetArrivals(ArrivalCity newArrivalCity)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"INSERT INTO flights (arrival_city_id, departure_city_id) VALUES (@ArrivalCityId, @DepartureCityId);";

            MySqlParameter arrival_city_id = new MySqlParameter();

            arrival_city_id.ParameterName = "@ArrivalCityId";
            arrival_city_id.Value         = newArrivalCity.GetId();
            cmd.Parameters.Add(arrival_city_id);

            MySqlParameter departure_city_id = new MySqlParameter();

            departure_city_id.ParameterName = "@DepartureCityId";
            departure_city_id.Value         = _id;
            cmd.Parameters.Add(departure_city_id);

            cmd.ExecuteNonQuery();
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Exemplo n.º 4
0
 public override bool Equals(System.Object otherArrivalCity)
 {
     if (!(otherArrivalCity is ArrivalCity))
     {
         return(false);
     }
     else
     {
         ArrivalCity newArrivalCity = (ArrivalCity)otherArrivalCity;
         bool        idEquality     = this.GetId() == newArrivalCity.GetId();
         bool        nameEquality   = this.GetArrivalCityName() == newArrivalCity.GetArrivalCityName();
         return(idEquality && nameEquality);
     }
 }
        public List <ArrivalCity> GetArrivals()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT arrival_cities.* FROM departure_cities
                JOIN flights ON (departure_cities.id = flights.departure_city_id)
                JOIN arrival_cities ON (flights.arrival_city_id = arrival_cities.id)
                WHERE departure_cities.id = @DepartureCityId;";

            MySqlParameter departureCityIdParameter = new MySqlParameter();

            departureCityIdParameter.ParameterName = "@DepartureCityId";
            departureCityIdParameter.Value         = _id;
            cmd.Parameters.Add(departureCityIdParameter);

            MySqlDataReader    rdr           = cmd.ExecuteReader() as MySqlDataReader;
            List <ArrivalCity> arrivalCities = new List <ArrivalCity> {
            };

            while (rdr.Read())
            {
                int         arrivalCityId   = rdr.GetInt32(0);
                string      arrivalCityName = rdr.GetString(1);
                ArrivalCity newArrivalCity  = new ArrivalCity(arrivalCityName, arrivalCityId);
                arrivalCities.Add(newArrivalCity);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(arrivalCities);
        }