Пример #1
0
        public static List <Hiker> GetFiltered(int inputtedGender, int inputtedCar)
        {
            List <Hiker> filteredHikers = new List <Hiker> {
            };
            MySqlConnection conn        = DB.Connection();

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

            cmd.CommandText = @"SELECT * FROM hikers WHERE gender = @gender AND car = @car;";

            MySqlParameter genderFilter = new MySqlParameter();

            genderFilter.ParameterName = "@gender";
            genderFilter.Value         = inputtedGender;
            cmd.Parameters.Add(genderFilter);

            MySqlParameter carFilter = new MySqlParameter();

            carFilter.ParameterName = "@car";
            carFilter.Value         = inputtedCar;
            cmd.Parameters.Add(carFilter);

            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int    HikerId        = rdr.GetInt32(0);
                string HikerHikerName = rdr.GetString(1);
                string HikerFirstName = rdr.GetString(2);
                string HikerLastName  = rdr.GetString(3);
                int    HikerZip       = rdr.GetInt32(4);
                string HikerPhone     = rdr.GetString(5);
                string HikerEmail     = rdr.GetString(6);
                int    HikerGender    = rdr.GetInt32(7);
                int    HikerCar       = rdr.GetInt32(8);
                Hiker  newHiker       = new Hiker(HikerHikerName, HikerFirstName, HikerLastName, HikerZip, HikerPhone, HikerEmail, HikerGender, HikerCar, HikerId);
                filteredHikers.Add(newHiker);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(filteredHikers);
        }
Пример #2
0
 public override bool Equals(System.Object otherHiker)
 {
     if (!(otherHiker is Hiker))
     {
         return(false);
     }
     else
     {
         Hiker newHiker          = (Hiker)otherHiker;
         bool  idEquality        = this.GetId() == newHiker.GetId();
         bool  hikerNameEquality = this.GetHikerName() == newHiker.GetHikerName();
         bool  firstNameEquality = this.GetFirstName() == newHiker.GetFirstName();
         bool  lastNameEquality  = this.GetLastName() == newHiker.GetLastName();
         bool  zipEquality       = this.GetZipCode() == newHiker.GetZipCode();
         bool  phoneEquality     = this.GetPhone() == newHiker.GetPhone();
         bool  emailEquality     = this.GetEmail() == newHiker.GetEmail();
         bool  genderEquality    = this.GetGender() == newHiker.GetGender();
         bool  carEquality       = this.GetCar() == newHiker.GetCar();
         return(idEquality && hikerNameEquality && firstNameEquality && lastNameEquality && zipEquality && phoneEquality && emailEquality && genderEquality && carEquality);
     }
 }
Пример #3
0
        public static Hiker Find(int hikerId)
        {
            MySqlConnection conn = DB.Connection();

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

            cmd.CommandText = @"SELECT * FROM hikers WHERE id = (@id);";
            MySqlParameter id = new MySqlParameter("@id", hikerId);

            cmd.Parameters.Add(id);
            MySqlDataReader rdr           = cmd.ExecuteReader() as MySqlDataReader;
            int             readId        = 0;
            string          readHikerName = "";
            string          readFirstName = "";
            string          readLastName  = "";
            int             readZip       = 0;
            string          readPhone     = "";
            string          readEmail     = "";
            int             readGender    = 0;
            int             readCar       = 0;

            while (rdr.Read())
            {
                readId        = rdr.GetInt32(0);
                readHikerName = rdr.GetString(1);
                readFirstName = rdr.GetString(2);
                readLastName  = rdr.GetString(3);
                readZip       = rdr.GetInt32(4);
                readPhone     = rdr.GetString(5);
                readEmail     = rdr.GetString(6);
                readGender    = rdr.GetInt32(7);
                readCar       = rdr.GetInt32(8);
            }
            Hiker foundHiker = new Hiker(readHikerName, readFirstName, readLastName, readZip, readPhone, readEmail, readGender, readCar, readId);

            return(foundHiker);
        }