public void InsertComponent(CompComponent component) { component.ID = ShowNextId("components"); string query = "INSERT INTO components VALUE (0, @a, @b, -1, @d, @e)"; if (OpenConnection()) { using (MySqlCommand command = new MySqlCommand(query, connection)) { MySqlParameter parameter = new MySqlParameter("@a", MySqlDbType.String); parameter.Value = component.Name; command.Parameters.Add(parameter); parameter = new MySqlParameter("@b", MySqlDbType.Float); parameter.Value = component.Price; command.Parameters.Add(parameter); parameter = new MySqlParameter("@d", MySqlDbType.Int32); parameter.Value = component.StatusID; command.Parameters.Add(parameter); parameter = new MySqlParameter("@e", MySqlDbType.String); parameter.Value = component.SerialNumber; command.Parameters.Add(parameter); command.ExecuteNonQuery(); } CloseConnection(); } }
public void UpdateComponent(CompComponent component) { string query = $"UPDATE components SET component_name = @a, component_price = @b, computer_id = @c, serial_number = @d, status = @e WHERE id = {component.ID}"; if (OpenConnection()) { using (MySqlCommand command = new MySqlCommand(query, connection)) { MySqlParameter parameter = new MySqlParameter("@a", MySqlDbType.String); parameter.Value = component.Name; command.Parameters.Add(parameter); parameter = new MySqlParameter("@b", MySqlDbType.Float); parameter.Value = component.Price; command.Parameters.Add(parameter); parameter = new MySqlParameter("@c", MySqlDbType.Int32); parameter.Value = component.ComputerID; command.Parameters.Add(parameter); parameter = new MySqlParameter("@d", MySqlDbType.String); parameter.Value = component.SerialNumber; command.Parameters.Add(parameter); parameter = new MySqlParameter("@e", MySqlDbType.Int32); parameter.Value = component.StatusID; command.Parameters.Add(parameter); command.ExecuteNonQuery(); } CloseConnection(); } }
public void DeleteComponent(CompComponent component) { if (component == null) { return; } string query = $"DELETE FROM components WHERE id = {component.ID}"; ExecuteNonQuery(query); }