Ejemplo n.º 1
0
        public int GetTotalRowsAuthorizations(Connections connections, AuthorizationSearch authorizationSearch)
        {
            QueryWarehouseAuthorizations _query = new QueryWarehouseAuthorizations();
            int    totalRows        = 0;
            string connectionString = $"Server={connections.ServerName};Database={connections.DatabaseName};User Id={connections.DatabaseUsername};Password={connections.DatabasePassword};";
            string queryString      = _query.CrateQueryStringCountRowsAuthorization(authorizationSearch);

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);

                command = _query.EmbedParameters(command, authorizationSearch);

                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        totalRows = Convert.ToInt32(reader[0]);
                    }
                    reader.Close();

                    return(totalRows);
                }
                catch (Exception ex)
                {
                    connection.Close();
                    Console.WriteLine(ex.ToString());
                    return(0);
                }
            }
        }
Ejemplo n.º 2
0
        public List <AuthorizationResult> GetAuthorizationResults(Connections connections, AuthorizationSearch authorizationSearch, Paging paging)
        {
            QueryWarehouseAuthorizations _query = new QueryWarehouseAuthorizations();

            string connectionString = $"Server={connections.ServerName};Database={connections.DatabaseName};User Id={connections.DatabaseUsername};Password={connections.DatabasePassword};";
            string queryString      = _query.CrateQueryStringAuthorization(authorizationSearch, paging);

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);

                command = _query.EmbedParameters(command, authorizationSearch);

                try
                {
                    List <AuthorizationResult> results = new List <AuthorizationResult>();
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        AuthorizationResult authorizationResult = new AuthorizationResult();
                        authorizationResult.SetValuesFromReader(reader);
                        results.Add(authorizationResult);
                    }
                    reader.Close();

                    return(results);
                }
                catch (Exception ex)
                {
                    connection.Close();
                    Console.WriteLine(ex.ToString());
                    return(null);
                }
            }
        }