Example #1
0
        public static List <ClientClass> GetAll()
        {
            List <ClientClass> allClients = new List <ClientClass>();
            MySqlConnection    conn       = DB.Connection();

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

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

            while (rdr.Read())
            {
                int         clientId    = rdr.GetInt32(0);
                string      name        = rdr.GetString(1);
                string      phoneNumber = rdr.GetString(2);
                int         stylistId   = rdr.GetInt32(3);
                ClientClass newClient   = new ClientClass(name, phoneNumber, stylistId, clientId);
                allClients.Add(newClient);
            }

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

            return(allClients);
        }
Example #2
0
        public static ClientClass Find(int id)
        {
            MySqlConnection conn = DB.Connection();

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

            cmd.CommandText = @"SELECT * FROM clients WHERE Id = @thisId;";
            MySqlParameter thisId = new MySqlParameter();

            thisId.ParameterName = "@thisId";
            thisId.Value         = id;
            cmd.Parameters.Add(thisId);
            var    rdr         = cmd.ExecuteReader() as MySqlDataReader;
            int    clientId    = 0;
            string name        = "";
            string phoneNumber = "";
            int    stylistId   = 0;

            while (rdr.Read())
            {
                clientId    = rdr.GetInt32(0);
                name        = rdr.GetString(1);
                phoneNumber = rdr.GetString(2);
                stylistId   = rdr.GetInt32(3);
            }
            ClientClass foundClient = new ClientClass(name, phoneNumber, stylistId, clientId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(foundClient);
        }
Example #3
0
        public List <ClientClass> GetClients()
        {
            List <ClientClass> allStylistClients = new List <ClientClass>();
            MySqlConnection    conn = DB.Connection();

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

            cmd.CommandText = @"SELECT * FROM clients WHERE stylistId = @stylistId;";
            MySqlParameter stylistId = new MySqlParameter();

            stylistId.ParameterName = "@stylistId";
            stylistId.Value         = this._id;
            cmd.Parameters.Add(stylistId);
            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int         clientId    = rdr.GetInt32(0);
                string      name        = rdr.GetString(1);
                string      phoneNumber = rdr.GetString(2);
                ClientClass newClient   = new ClientClass(name, phoneNumber, _id, clientId);
                allStylistClients.Add(newClient);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allStylistClients);
        }
Example #4
0
 public override bool Equals(System.Object otherClient)
 {
     if (!(otherClient is ClientClass))
     {
         return(false);
     }
     else
     {
         ClientClass newClient      = (ClientClass)otherClient;
         bool        clientEquality = (this.GetName() == newClient.GetName() && this.GetPhoneNumber() == newClient.GetPhoneNumber() && this.GetId() == newClient.GetId() && this.GetStylistId() == newClient.GetStylistId());
         return(clientEquality);
     }
 }
Example #5
0
        public static void ClearAll()
        {
            MySqlConnection conn = DB.Connection();

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

            cmd.CommandText = @"DELETE FROM stylists;";
            cmd.ExecuteNonQuery();
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            ClientClass.ClearAll();
        }