private void MetroWindow_Loaded(object sender, RoutedEventArgs e) { if (customerID != null) { String[] addressParts = customer.getAddress().Split(); CustomerID.Text = customerID; FirstName.Text = customer.getFirstName(); LastName.Text = customer.getLastName(); Address1.Text = addressParts[0]; Address2.Text = addressParts[1]; Address3.Text = addressParts[2]; Email.Text = customer.getEmail(); MobileContact.Text = customer.getMobileNumber().ToString(); HomeContact.Text = customer.getFixedNumber().ToString(); } }
public int executeCustomerUpdate(CustomerData customer, String CustomerID) { String firstName = customer.getFirstName(); String lastName = customer.getLastName(); String address = customer.getAddress(); int mobile = customer.getMobileNumber(); int fixedNumber = customer.getFixedNumber(); String email = customer.getEmail(); String query = "UPDATE customer SET firstName = @firstName, lastName = @lastName, address = @Address, email = @email, mobile = @Mobile, fixedNumber = @fixedNumber WHERE ID = @CustomerID"; int affectedLines = 0; try { conn = new SqlConnection(connectionString); SqlCommand comm = new SqlCommand(query, conn); comm.Parameters.AddWithValue("@CustomerID", Convert.ToInt32(CustomerID)); comm.Parameters.AddWithValue("@firstName", firstName); comm.Parameters.AddWithValue("@lastName", lastName); comm.Parameters.AddWithValue("@Address", address); comm.Parameters.AddWithValue("@Mobile", mobile); comm.Parameters.AddWithValue("@fixedNumber", fixedNumber); comm.Parameters.AddWithValue("@email", email); conn.Open(); affectedLines = comm.ExecuteNonQuery(); } catch (SqlException ex) { throw ex; } finally { if (conn != null) { conn.Close(); } } return(affectedLines); }
public int executeCustomerEntry(CustomerData customer) { String firstName = customer.getFirstName(); String lastName = customer.getLastName(); String address = customer.getAddress(); int mobile = customer.getMobileNumber(); int fixedNumber = customer.getFixedNumber(); String email = customer.getEmail(); String query = "INSERT INTO customer(firstName, lastName, address, email, mobile, fixedNumber) VALUES (@firstName, @lastName, @Address, @email, @Mobile, @fixedNumber)"; int affectedLines = 0; try { conn = new SqlConnection(connectionString); SqlCommand comm = new SqlCommand(query, conn); comm.Parameters.AddWithValue("@firstName", firstName); comm.Parameters.AddWithValue("@lastName", lastName); comm.Parameters.AddWithValue("@Address", address); comm.Parameters.AddWithValue("@Mobile", mobile); comm.Parameters.AddWithValue("@fixedNumber", fixedNumber); comm.Parameters.AddWithValue("@email", email); conn.Open(); affectedLines = comm.ExecuteNonQuery(); } catch (SqlException ex) { throw ex; } finally { if (conn != null) { conn.Close(); } } return(affectedLines); }