internal static void GetCustomers(CustomerRepository customerRepository) { try { conn.Open(); customerRepository.Clear(); SqlCommand cmd = new SqlCommand("SP_GET_ALL_CUSTOMERS", conn); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { customerRepository.Create(Convert.ToInt32(rdr["CUSTOMER_ID"]), rdr["NAME"].ToString(), rdr["ADDRESS"].ToString()); } } } catch (SqlException e) { UI.WriteL(e.Message.ToString()); UI.Wait(); } finally { conn.Close(); } }
public void RefreshCuRepository() { using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); SqlCommand cmdShowAllCustomers = new SqlCommand("SP_SHOW_ALL_CUSTOMERS", con); cmdShowAllCustomers.CommandType = CommandType.StoredProcedure; SqlDataReader reader = cmdShowAllCustomers.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { string customerFirstName = reader["FIRST_NAME"].ToString(); string customerLastName = reader["LAST_NAME"].ToString(); string customerPhoneNumber = reader["PHONE_NUMBER"].ToString(); cuRepo.Create(customerFirstName, customerLastName, customerPhoneNumber); } } } }