public static bool DeleteCustomer(Customer customer) { SqlConnection connection = TravelExpertsDB.GetConnection(); string deleteStatement = "DELETE FROM Customers " + "WHERE CustFirstName = @CustFirstName " + "CustLastName = @CustLastName " + "AND CustAddress = @CustAddress " + "AND CityCity = @CityCity " + "AND CustProv = @CustProv " + "AND CustPostal = @CustPostal " + "AND CustCountry = @CustCountry " + "AND CustHomePhone = @CustHomePhone " + "AND CustBusPhone = @CustBusPhone " + "AND CustEmail = @CustEmail " + "AND AgentId = @AgentId"; SqlCommand deleteCommand = new SqlCommand(deleteStatement, connection); deleteCommand.Parameters.AddWithValue( "@CustFirstName", customer.CustFirstName); deleteCommand.Parameters.AddWithValue( "@CustLastName", customer.CustLastName); deleteCommand.Parameters.AddWithValue( "@CustAddress", customer.CustAddress); deleteCommand.Parameters.AddWithValue( "@CustCity", customer.CustCity); deleteCommand.Parameters.AddWithValue( "@CustProv", customer.CustProv); deleteCommand.Parameters.AddWithValue( "@CustPostal", customer.CustPostal); deleteCommand.Parameters.AddWithValue( "@CustCountry", customer.CustCountry); deleteCommand.Parameters.AddWithValue( "@CustHomePhone", customer.CustHomePhone); deleteCommand.Parameters.AddWithValue( "@CustBusPhone", customer.CustBusPhone); deleteCommand.Parameters.AddWithValue( "@CustEmail", customer.CustEmail); deleteCommand.Parameters.AddWithValue( "@AgentId", customer.AgentId); try { connection.Open(); int count = deleteCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public static bool UpdateCustomer(Customer original_customer, Customer customer) { SqlConnection connection = TravelExpertsDB.GetConnection(); string updateStatement = "UPDATE Customers SET " + "CustFirstName = @CustFirstName, " + "CustLastName = @CustLastName, " + "CustAddress = @CustAddress, " + "CustCity = @CustCity, " + "CustProv = @CustProv, " + "CustPostal = @CustPostal, " + "CustCountry = @CustCountry, " + "CustHomePhone = @CustHomePhone, " + "CustBusPhone = @CustBusPhone, " + "CustEmail = @CustEmail " + //"AgentId = @AgentId " + "WHERE CustFirstName = @original_CustFirstName " + "AND CustLastName = @original_CustLastName " + "AND CustAddress = @original_CustAddress " + "AND CustCity = @original_CustCity " + "AND CustProv = @original_CustProv " + "AND CustPostal = @original_CustPostal " + "AND CustCountry = @original_CustCountry " + "AND CustHomePhone = @original_CustHomePhone " + "AND CustBusPhone = @original_CustBusPhone " + "AND CustEmail = @original_CustEmail "; //"AND AgentId = @original_AgentId "; SqlCommand updateCommand = new SqlCommand(updateStatement, connection); updateCommand.Parameters.AddWithValue( "@CustFirstName", customer.CustFirstName); updateCommand.Parameters.AddWithValue( "@CustLastName", customer.CustLastName); updateCommand.Parameters.AddWithValue( "@CustAddress", customer.CustAddress); updateCommand.Parameters.AddWithValue( "@CustCity", customer.CustCity); updateCommand.Parameters.AddWithValue( "@CustProv", customer.CustProv); updateCommand.Parameters.AddWithValue( "@CustPostal", customer.CustPostal); updateCommand.Parameters.AddWithValue( "@CustCountry", customer.CustCountry); updateCommand.Parameters.AddWithValue( "@CustHomePhone", customer.CustHomePhone); updateCommand.Parameters.AddWithValue( "@CustBusPhone", customer.CustBusPhone); updateCommand.Parameters.AddWithValue( "@CustEmail", customer.CustEmail); //updateCommand.Parameters.AddWithValue( // "@AgentId", newCustomer.AgentId); updateCommand.Parameters.AddWithValue( "@original_CustFirstName", original_customer.CustFirstName); updateCommand.Parameters.AddWithValue( "@original_CustLastName", original_customer.CustLastName); updateCommand.Parameters.AddWithValue( "@original_CustAddress", original_customer.CustAddress); updateCommand.Parameters.AddWithValue( "@original_CustCity", original_customer.CustCity); updateCommand.Parameters.AddWithValue( "@original_CustProv", original_customer.CustProv); updateCommand.Parameters.AddWithValue( "@original_CustPostal", original_customer.CustPostal); updateCommand.Parameters.AddWithValue( "@original_CustCountry", original_customer.CustCountry); updateCommand.Parameters.AddWithValue( "@original_CustHomePhone", original_customer.CustHomePhone); updateCommand.Parameters.AddWithValue( "@original_CustBusPhone", original_customer.CustBusPhone); updateCommand.Parameters.AddWithValue( "@original_CustEmail", original_customer.CustEmail); //updateCommand.Parameters.AddWithValue( // "@original_AgentId", original_customer.AgentId); try { connection.Open(); int count = updateCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }