public void SetStylist(Stylist newStylist) { if (newStylist.GetID() == -1) { throw new Exception("Can't add an unsaved stylist to a client."); } else if (_id == -1) { _stylistID = newStylist.GetID(); } else { MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = $"UPDATE clients SET stylist_id = {newStylist.GetID()} WHERE id = {_id};"; cmd.ExecuteNonQuery(); DB.Close(conn); _stylistID = newStylist.GetID(); } }
public static Client[] GetClientsOfStylist(Stylist owner) { List <Client> result = new List <Client>(); MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = $"SELECT * FROM clients WHERE stylist_id = {owner.GetID()};"; MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { int newID = rdr.GetInt32(0); string newName = rdr.GetString(1); int newStylistID = rdr.GetInt32(2); Client newClient = new Client(newName, newStylistID); newClient._id = newID; result.Add(newClient); } DB.Close(conn); return(result.ToArray()); }
public void AddStylist(Stylist newStylist) { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"INSERT INTO stylists_specialties (stylist_ID, specialty_ID) VALUES (@stylistID, @specialtyID);"; MySqlParameter stylist_ID = new MySqlParameter(); stylist_ID.ParameterName = "@stylistID"; stylist_ID.Value = newStylist.GetID(); cmd.Parameters.Add(stylist_ID); MySqlParameter specialty_ID = new MySqlParameter(); specialty_ID.ParameterName = "@specialtyID"; specialty_ID.Value = MyID; cmd.Parameters.Add(specialty_ID); cmd.ExecuteNonQuery(); conn.Close(); if (conn != null) { conn.Dispose(); } }
public Client(string name, Stylist stylist, int id = -1) { _name = name; _stylistID = stylist.GetID(); _id = id; }
public override bool Equals(System.Object otherStylist) { if (!(otherStylist is Stylist)) { return(false); } else { Stylist newStylist = (Stylist)otherStylist; bool stylistEquality = (this.GetFirstName() == newStylist.GetFirstName() && this.GetLastName() == newStylist.GetLastName() && this.GetPhoneNumber() == newStylist.GetPhoneNumber() && this.GetEmail() == newStylist.GetEmail() && this.GetID() == newStylist.GetID()); return(stylistEquality); } }