示例#1
0
        public static List <Yacht> GetAll()
        {
            List <Yacht> allYachts = new List <Yacht> {
            };
            MySqlConnection conn   = DB.Connection();

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

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

            while (rdr.Read())
            {
                int    itemId    = rdr.GetInt32(0);
                string itemYacht = rdr.GetString(1);
                Yacht  newYacht  = new Yacht(itemYacht, itemId);
                allYachts.Add(newYacht);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allYachts);
        }
示例#2
0
 public override bool Equals(System.Object otherYacht)
 {
     if (!(otherYacht is Yacht))
     {
         return(false);
     }
     else
     {
         Yacht newYacht      = (Yacht)otherYacht;
         bool  idEquality    = (this.GetId() == newYacht.GetId());
         bool  yachtEquality = (this.GetYacht() == newYacht.GetYacht());
         return(idEquality && yachtEquality);
     }
 }
示例#3
0
        public static Yacht Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();

            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM `yachts` WHERE id = @thisId;";

            MySqlParameter thisId = new MySqlParameter();

            thisId.ParameterName = "@thisId";
            thisId.Value         = id;
            cmd.Parameters.Add(thisId);

            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            int    itemId    = 0;
            string itemYacht = "";

            while (rdr.Read())
            {
                itemId    = rdr.GetInt32(0);
                itemYacht = rdr.GetString(1);
            }

            Yacht foundYacht = new Yacht(itemYacht, itemId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }

            return(foundYacht);
        }