Exemplo n.º 1
0
        public int GetTotalRowsAuthorizations(Connections connections, HHAXAuthorizationsSearch authorizationsSearch)
        {
            QueryHHAXAuthorizations _query = new QueryHHAXAuthorizations();
            int    totalRows        = 0;
            string connectionString = $"Server={connections.ServerName};Database={connections.DatabaseName};User Id={connections.DatabaseUsername};Password={connections.DatabasePassword};";
            string queryString      = _query.CrateQueryStringCountRowsAuthorizations(authorizationsSearch);

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

                command = _query.EmbedParameters(command, authorizationsSearch);
                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);
                }
            }
        }
Exemplo n.º 2
0
        public List <HHAXAuthorizationsResult> GetHHAXAuthorizationResults(Connections connections, HHAXAuthorizationsSearch authorizationsSearch, Paging paging)
        {
            QueryHHAXAuthorizations _query = new QueryHHAXAuthorizations();
            string connectionString        = $"Server={connections.ServerName};Database={connections.DatabaseName};User Id={connections.DatabaseUsername};Password={connections.DatabasePassword};";
            string queryString             = _query.CreateQueryStringAuthorizations(authorizationsSearch, paging);

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection)
                {
                    CommandTimeout = 100
                };
                command = _query.EmbedParameters(command, authorizationsSearch);
                try
                {
                    List <HHAXAuthorizationsResult> results = new List <HHAXAuthorizationsResult>();
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        HHAXAuthorizationsResult authorizationResult = new HHAXAuthorizationsResult();
                        authorizationResult.SetValuesFromReader(reader);
                        results.Add(authorizationResult);
                    }
                    reader.Close();
                    connection.Close();

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