public static Trail Find(int trailId) { MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM trails WHERE id = (@id);"; MySqlParameter id = new MySqlParameter("@id", trailId); cmd.Parameters.Add(id); MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; int readId = 0; string readName = ""; int readDifficulty = 0; int readSummits = 0; bool readWaterfalls = false; bool readStreams = false; bool readMountainViews = false; bool readMeadows = false; bool readLakes = false; string readLocation = ""; while (rdr.Read()) { readId = rdr.GetInt32(0); readName = rdr.GetString(1); readDifficulty = rdr.GetInt32(2); readSummits = rdr.GetInt32(3); readWaterfalls = rdr.GetBoolean(4); readStreams = rdr.GetBoolean(5); readMountainViews = rdr.GetBoolean(6); readMeadows = rdr.GetBoolean(7); readLakes = rdr.GetBoolean(8); readLocation = rdr.GetString(9); } Trail foundTrail = new Trail(readName, readDifficulty, readSummits, readWaterfalls, readStreams, readMountainViews, readMeadows, readLakes, readLocation, readId); return(foundTrail); }
public override bool Equals(System.Object otherTrail) { if (!(otherTrail is Trail)) { return(false); } else { Trail newTrail = (Trail)otherTrail; bool idEquality = this.GetId() == newTrail.GetId(); bool nameEquality = this.GetName() == newTrail.GetName(); bool difficultyEquality = this.GetDifficulty() == newTrail.GetDifficulty(); bool waterfallsEquality = this.GetWaterfalls() == newTrail.GetWaterfalls(); bool summitsEquality = this.GetSummits() == newTrail.GetSummits(); bool streamsEquality = this.GetStreams() == newTrail.GetStreams(); bool mountainViewsEquality = this.GetMountainViews() == newTrail.GetMountainViews(); bool meadowsEquality = this.GetMeadows() == newTrail.GetMeadows(); bool lakesEquality = this.GetLakes() == newTrail.GetLakes(); bool locationEquality = this.GetLocation() == newTrail.GetLocation(); return(idEquality && nameEquality && difficultyEquality && waterfallsEquality && summitsEquality && streamsEquality && mountainViewsEquality && lakesEquality && meadowsEquality && locationEquality); } }
public static List <Trail> GetPartialMatches(int inputtedDifficulty, int inputtedSummits, bool inputtedWaterfalls, bool inputtedStreams, bool inputtedMountainViews, bool inputtedMeadows, bool inputtedLakes) { List <Trail> filteredTrails = new List <Trail> { }; MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM trails WHERE difficulty = @difficulty AND waterfalls = @waterfalls OR summits = @summits OR streams = @streams OR mountain_views = @mountainViews OR meadows = @meadows OR lakes = @lakes;"; MySqlParameter difficultyFilter = new MySqlParameter(); difficultyFilter.ParameterName = "@difficulty"; difficultyFilter.Value = inputtedDifficulty; cmd.Parameters.Add(difficultyFilter); MySqlParameter waterfallsFilter = new MySqlParameter(); waterfallsFilter.ParameterName = "@waterfalls"; waterfallsFilter.Value = inputtedWaterfalls; cmd.Parameters.Add(waterfallsFilter); MySqlParameter summitsFilter = new MySqlParameter(); summitsFilter.ParameterName = "@summits"; summitsFilter.Value = inputtedSummits; cmd.Parameters.Add(summitsFilter); MySqlParameter streamsFilter = new MySqlParameter(); streamsFilter.ParameterName = "@streams"; streamsFilter.Value = inputtedStreams; cmd.Parameters.Add(streamsFilter); MySqlParameter mountainFilter = new MySqlParameter(); mountainFilter.ParameterName = "@mountainViews"; mountainFilter.Value = inputtedMountainViews; cmd.Parameters.Add(mountainFilter); MySqlParameter meadowFilter = new MySqlParameter(); meadowFilter.ParameterName = "@meadows"; meadowFilter.Value = inputtedMeadows; cmd.Parameters.Add(meadowFilter); MySqlParameter lakeFilter = new MySqlParameter(); lakeFilter.ParameterName = "@lakes"; lakeFilter.Value = inputtedLakes; cmd.Parameters.Add(lakeFilter); MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { int TrailId = rdr.GetInt32(0); string TrailName = rdr.GetString(1); int TrailDifficulty = rdr.GetInt32(2); int TrailSummits = rdr.GetInt32(3); bool TrailWaterfalls = rdr.GetBoolean(4); bool TrailStreams = rdr.GetBoolean(5); bool TrailMountainViews = rdr.GetBoolean(6); bool TrailMeadows = rdr.GetBoolean(7); bool TrailLakes = rdr.GetBoolean(8); string TrailLocation = rdr.GetString(9); Trail newTrail = new Trail(TrailName, TrailDifficulty, TrailSummits, TrailWaterfalls, TrailStreams, TrailMountainViews, TrailMeadows, TrailLakes, TrailLocation, TrailId); filteredTrails.Add(newTrail); } conn.Close(); if (conn != null) { conn.Dispose(); } return(filteredTrails); }