// Place the given JSON on the report public static void JSON(string Request, string Highlight, string XML = null) { Reporting.TestStep((XML == null ? "Get the JSON response:<br>" + HighlightJSON(Request, Highlight) : "Get the JSON response:<br>" + HighlightJSON(Request, "").Replace("<SolutionExport", "<xmp><SolutionExport").Replace("</SolutionExport>", "</SolutionExport></xmp>")) + "<br>"); }
// Check the Event log solution defined field. public static bool ReportDataFromTheDatabase(string Query, string Database, string Highlight = "", bool ShowQuery = false) { Console.WriteLine(Query); DataTable MyDataTable = new DataTable("MyTable"); string Table = null; bool HeaderRow = true; bool Data = false; if (Query.Substring(0, 6).ToLower().Contains("select")) { // If we need to show the query on the report, show it. if (ShowQuery) { Reporting.InformationBox(Query); } // Try connecting to the database try { // Setup the connection and fill the data table with the data SqlConnection Connection = new SqlConnection(GenericFunctions.goAndGet("DBCONNECTION").Replace("DBNAME", Database)); SqlCommand cmd = new SqlCommand(Query, Connection); Connection.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(MyDataTable); Connection.Close(); // For each row within the data table foreach (DataRow row in MyDataTable.Rows) { // If this is the header row, add in the header formatting if (HeaderRow) { Table = "<table class=\"matrix\"><tr>"; // For each column, add it into the table foreach (DataColumn column in MyDataTable.Columns) { Table = Table + "<th>" + column.ColumnName + "</th>"; } Table = Table + "</tr>"; } // Switch the header row off HeaderRow = false; // Create a new row Table = Table + "<tr>"; // For each column, add it into the report foreach (DataColumn column in MyDataTable.Columns) { Table = Table + "<td>" + (Highlight.Contains(column.ColumnName) ? "<mark>" : "") + (row[column].ToString().Length != 0 ? row[column] : "NULL") + (Highlight.Contains(column.ColumnName) ? "</mark>" : "") + "</td>"; Data = true; } // Finish the table row Table = Table + "</tr>"; } // Finish off the table Table = Table + "</table>"; // Destroy the datatable da.Dispose(); } // Catch any exceptions here catch (Exception e) { Console.WriteLine("Something went wrong...\n" + e); } // Add the data into the report Reporting.TestStep("<br>" + (Data ? Table : "No data to display.")); } return(Data); }