Skip to content

Commit

Permalink
refactor and cleaned up unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcongdon committed Dec 16, 2024
1 parent 2042bb5 commit f3106cf
Showing 1 changed file with 1 addition and 80 deletions.
81 changes: 1 addition & 80 deletions vHC/HC_Reporting/Functions/Collection/DB/CDbWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,14 @@ public CDbWorker()
_cString = dbs.DbAccessorString();
}

public void DoDbWork()
{

using (var connection = new SqlConnection(_cString))
{
string query = string.Format("Use {0} SELECT {1} from {2}"); //TODO: Find DB info and form string ahead of time
}
}

public DataTable ExecQuery(string query)
{
log.Info("executing sql query: " + query);
try
{
SqlConnection sqlConnection = new SqlConnection(_cString);
using var connection = sqlConnection;
using var connection = new SqlConnection(_cString); ;
using SqlCommand command = new SqlCommand(query, connection);
connection.Open();
DataTable t = new();
Expand All @@ -60,77 +52,6 @@ public DataTable ExecQuery(string query)
}


public string ExecSimpleQuery(string query)
{
log.Info("executing simple query: " + query);
using (var connection = new SqlConnection(_cString))
{
using (var command = new SqlCommand(query, connection))
{
connection.Open();
DataTable t = new();
SqlDataReader s = command.ExecuteReader();

log.Info("executing simple query..done!");
return s.GetString(1);
}
}
}
public void GetVbrJobsAll()
{
using (var connection = new SqlConnection(_cString))
{
string query = string.Format("USE VEEAMBACKUP SELECT * FROM [BJOBS]");

using (var command = new SqlCommand(query, connection))
{
connection.Open();

DataTable t = new DataTable();
//SqlDataReader _reader = command.ExecuteReader();

t.Load(command.ExecuteReader());

using (StreamWriter sw = new StreamWriter("output.txt", append: true))
{
StringBuilder sb = new StringBuilder();

IEnumerable<string> columnNames = t.Columns.Cast<DataColumn>().
Select(column => column.ColumnName);
sb.AppendLine(string.Join(",", columnNames));

foreach (DataRow row in t.Rows)
{
IEnumerable<string> fields = row.ItemArray.Select(field => field.ToString());
sb.AppendLine(string.Join(",", fields));
}

File.WriteAllText("test.csv", sb.ToString());

//sw.WriteLine(d.ToString());
// }
}

}
}
}
public void GetJobs()
{



/* DataTable temp = new DataTable();
adapter = new MySqlDataAdapter(command);
adapter.Fill(temp);
foreach(DataColumn column in temp.Columns)
{
foreach(DataRow row in temp.Rows)
{
Console.WriteLine(row[column]);
}
}
*/
}
}
}

0 comments on commit f3106cf

Please sign in to comment.