예제 #1
0
        public UsersDO ViewByUserName(string userName)
        {
            UsersDO        user       = new UsersDO();
            SqlConnection  connection = null;
            SqlDataAdapter adapter    = null;
            DataTable      table      = new DataTable();
            SqlCommand     command    = null;

            try
            {
                connection          = new SqlConnection(_ConnectionString);
                command             = new SqlCommand("View_By_UserName", connection);
                command.CommandType = CommandType.StoredProcedure;

                connection.Open();
                command.Parameters.AddWithValue("@UserName", userName);
                adapter = new SqlDataAdapter(command);
                adapter.Fill(table);
                user = UsersMap2.DataTableToList(table).FirstOrDefault();
            }
            catch (Exception ex)
            {
                logger.Log("Fatal", ex.Source, ex.TargetSite.ToString(), ex.Message, ex.StackTrace);
                throw ex;
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                    connection.Dispose();
                }
            }
            return(user);
        }
예제 #2
0
        public List <UsersDO> ViewUsers()
        {
            List <UsersDO> allUsers   = new List <UsersDO>();
            SqlConnection  connection = null;
            SqlDataAdapter adapter    = null;
            DataTable      table      = new DataTable();
            SqlCommand     command    = null;

            try
            {
                connection          = new SqlConnection(_ConnectionString);
                command             = new SqlCommand("VIEW_Users", connection);
                command.CommandType = CommandType.StoredProcedure;
                connection.Open();
                adapter = new SqlDataAdapter(command);
                adapter.Fill(table);
                allUsers = UsersMap2.DataTableToList(table);
            }
            catch (Exception ex)
            {
                logger.Log("Fatal", ex.Source, ex.TargetSite.ToString(), ex.Message, ex.StackTrace);
                throw ex;
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                    connection.Dispose();
                }
                if (adapter != null)
                {
                    adapter.Dispose();
                }
            }
            return(allUsers);
        }