public void Edit(string newName, string newAppt) { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"UPDATE clients SET name = @newName, raw_appt = @newAppt WHERE id = @searchId;"; MySqlParameter searchId = new MySqlParameter(); searchId.ParameterName = "@searchId"; searchId.Value = _id; cmd.Parameters.Add(searchId); MySqlParameter name = new MySqlParameter(); name.ParameterName = "@newName"; name.Value = newName; cmd.Parameters.Add(name); MySqlParameter rawAppt = new MySqlParameter(); rawAppt.ParameterName = "@newAppt"; rawAppt.Value = newAppt; cmd.Parameters.Add(rawAppt); cmd.ExecuteNonQuery(); _name = newName; conn.Close(); if (conn != null) { conn.Dispose(); } }
public List <SpecialtyClass> GetSpecialties() { List <SpecialtyClass> allSpecialties = new List <SpecialtyClass> { }; MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT specialties.* FROM specialties JOIN stylists_specialties ON (specialties.Id = stylists_specialties.specialty_Id) JOIN stylists ON (stylists_specialties.stylist_Id = stylists.Id) WHERE stylists.Id = (@specialtyId);"; MySqlParameter stylistId = new MySqlParameter(); stylistId.ParameterName = "@stylistId"; stylistId.Value = this._id; cmd.Parameters.Add(stylistId); MySqlParameter specialtyId = new MySqlParameter(); specialtyId.ParameterName = "@specialtyId"; specialtyId.Value = this._id; cmd.Parameters.Add(specialtyId); MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { int specialty_Id = rdr.GetInt32(0); string feature = rdr.GetString(1); SpecialtyClass newSpecialty = new SpecialtyClass(feature, specialty_Id); allSpecialties.Add(newSpecialty); } conn.Close(); if (conn != null) { conn.Dispose(); } return(allSpecialties); }
public void Update(string name, int stylistId) { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"UPDATE clients SET name = @name, stylistId = @stylistId WHERE id = @clientId;"; MySqlParameter tempName = new MySqlParameter("@name", name); MySqlParameter tempStylistId = new MySqlParameter("@stylistId", stylistId); MySqlParameter tempClientId = new MySqlParameter("@clientId", this.GetId()); cmd.Parameters.Add(tempName); cmd.Parameters.Add(tempStylistId); cmd.Parameters.Add(tempClientId); cmd.ExecuteNonQuery(); conn.Close(); if (conn != null) { conn.Dispose(); } }
public void Save() { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"INSERT INTO clients (name, notes, stylist_id) VALUES (@name, @notes, @stylistId);"; MySqlParameter name = new MySqlParameter(); name.ParameterName = "@name"; name.Value = this._name; cmd.Parameters.Add(name); MySqlParameter notes = new MySqlParameter(); notes.ParameterName = "@notes"; notes.Value = this._notes; cmd.Parameters.Add(notes); MySqlParameter stylistId = new MySqlParameter(); stylistId.ParameterName = "@stylistId"; stylistId.Value = this._stylistId; cmd.Parameters.Add(stylistId); cmd.ExecuteNonQuery(); _id = (int)cmd.LastInsertedId; conn.Close(); if (conn != null) { conn.Dispose(); } }