public async IAsyncEnumerable <string[]> ExecuteQueryReportsAsync(string function, DateTime date) { using (SqlConnection connection = new SqlConnection()) { SqlCommand command = this.SetUpSqlConnectionCommand(connection); command.CommandText = function; if (function.Contains("fn")) { var sqlDate = DateTimeParser.ToSqlFormat(date); command.CommandText = $"select * from {function}('{sqlDate}')"; } else { command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@datereport", SqlDbType.Date) { Value = date }); } await foreach (var item in DataSQLHelper.GetStringDataAsync(command)) { yield return(item); } } }
public async IAsyncEnumerable <string[]> ExecuteQueryTimeSeriesAsync(string function) { using (SqlConnection connection = new SqlConnection()) { connection.ConnectionString = this.configuration.GetConnectionString(GlobalConstants.DataGatevFinaleConnection); await connection.OpenAsync(); SqlCommand command = connection.CreateCommand(); command.CommandText = function; await foreach (var item in DataSQLHelper.GetStringDataAsync(command)) { yield return(item); } } }
public async IAsyncEnumerable <string[]> ExecuteQueryAsync(string function, DateTime?date, int?id, IEnumerable <string> columns) { using (SqlConnection connection = new SqlConnection()) { connection.ConnectionString = this.configuration.GetConnectionString(GlobalConstants.DataGatevFinaleConnection); await connection.OpenAsync(); SqlCommand command = connection.CreateCommand(); var sqlDate = DateTimeParser.ToSqlFormat(date); if (!date.HasValue) { command.CommandText = $"select * from {function}({id})"; } else if (id.HasValue && id != 0) { if (columns != null) { command.CommandText = $"select {string.Join(", ", columns)} from {function}('{sqlDate}', {id})"; } else { command.CommandText = $"select * from {function}('{sqlDate}', {id})"; } } else { if (columns != null) { command.CommandText = $"select {string.Join(", ", columns)} from {function}('{sqlDate}')"; } else { command.CommandText = $"select * from {function}('{sqlDate}')"; } } await foreach (var item in DataSQLHelper.GetStringDataAsync(command)) { yield return(item); } } }