// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Text; using System.IO; public partial class DisplayData : System.Web.UI.UserControl { private DataSet _DataSet; public void Display(string[] paramterPair, string dataSetLinkTemplate) { if (paramterPair[0].StartsWith("@") == true) { this.LiteralXML.Text = Spludlow.Text.FixNewLines(paramterPair[1], "
", true); } object data = Spludlow.Parameters.DecodeParameter(paramterPair); this.Display(data, dataSetLinkTemplate); } public void Display(object data) { this.Display(data, null); } private string _DataSetLinkTemplate = null; private int _DataSetIndex = 0; public void Display(object data, string dataSetLinkTemplate) { this._DataSetLinkTemplate = dataSetLinkTemplate; this._DataSetIndex = 0; this.Literal1.Visible = true; if (data == null) { this.Literal1.Text = "NULL"; return; } Type type = data.GetType(); if (typeof(DataSet).IsAssignableFrom(type) == true) { this.DataListDataSet.Visible = true; this.Literal1.Visible = false; this._DataSet = (DataSet)data; DataTable tables = Spludlow.Data.TextTable.ReadText(new string[] { "TableName", "String*", }); foreach (DataTable table in this._DataSet.Tables) tables.Rows.Add(table.TableName); this.DataListDataSet.DataSource = tables; this.DataListDataSet.DataBind(); return; } if (type == typeof(Spludlow.CallSet)) { Spludlow.CallSet callSet = (Spludlow.CallSet)data; this.Literal1.Text = this._WebLines(callSet.Write2()); return; } if (Spludlow.SimpleEncoding.IsSimple(type) == true) { string text = Spludlow.SimpleEncoding.Encode(data, type.Name); text = HttpUtility.HtmlEncode(text); if (type.Name.EndsWith("[]") == true) text = text.Replace("\t", Environment.NewLine); text = this._WebLines(text); this.Literal1.Text = text; return; } this.Literal1.Text = Convert.ToString(data); } private string _WebLines(string data) { StringBuilder text = new StringBuilder(); using (StringReader reader = new StringReader(data)) { string line; while ((line = reader.ReadLine()) != null) { text.Append(line); text.AppendLine("
"); } } return text.ToString(); } protected void Page_Load(object sender, EventArgs e) { } protected void DataListDataSet_ItemDataBound(object sender, DataListItemEventArgs e) { DataRow tableRow = ((DataRowView)e.Item.DataItem).Row; string tableName = (string)tableRow["TableName"]; GridView gridView = (GridView)e.Item.FindControl("GridViewTable"); HyperLink hyperLink = (HyperLink)e.Item.FindControl("HyperLinkTable"); hyperLink.Text = tableName + " (" + this._DataSet.Tables[tableName].Rows.Count + ")"; if (this._DataSetLinkTemplate != null) { hyperLink.NavigateUrl = this._DataSetLinkTemplate.Replace("@", this._DataSetIndex.ToString()); ++this._DataSetIndex; } gridView.DataSource = this._DataSet.Tables[tableName]; gridView.DataBind(); } }