/// <summary>
/// <para> </para>
///  常用工具类——直接在浏览器输出数据
/// <para> -------------------------------------------------------------</para>
/// <para> DumpDataTable:接在浏览器输出数据DataTable</para>
/// <para> DumpListItemILIST:直接在浏览器输出数据ILIST<ListItem></para>
/// <para> DumpDataTableILIST:直接在浏览器输出数据DataTableILIST</para>
/// <para> DumpIntArrILIST:直接在浏览器输出数据整型数组ILIST<int[]></para>
/// <para> DumpStrArrILIST:直接在浏览器输出数据字符串数组的ILIST<string[]></para>
/// <para> DumpDataSet:直接在浏览器输出数据DataSet对象</para>
/// <para> DumpObjectArr2:直接在浏览器中输出二维数组</para>
/// </summary>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using System.Resources;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics; namespace Utils
{
/// <summary>
/// <para> </para>
///  常用工具类——直接在浏览器输出数据
/// <para> -------------------------------------------------------------</para>
/// <para> DumpDataTable:接在浏览器输出数据DataTable</para>
/// <para> DumpListItemILIST:直接在浏览器输出数据ILIST<ListItem></para>
/// <para> DumpDataTableILIST:直接在浏览器输出数据DataTableILIST</para>
/// <para> DumpIntArrILIST:直接在浏览器输出数据整型数组ILIST<int[]></para>
/// <para> DumpStrArrILIST:直接在浏览器输出数据字符串数组的ILIST<string[]></para>
/// <para> DumpDataSet:直接在浏览器输出数据DataSet对象</para>
/// <para> DumpObjectArr2:直接在浏览器中输出二维数组</para>
/// </summary> public class DumpHelper
{
#region 构造方法设置
/// <summary>
/// 数据类型颜色
/// </summary>
protected static string ColorDataType = "red";
/// <summary>
/// 行数颜色
/// </summary>
protected static string ColorRowCount = "red";
/// <summary>
/// 列数颜色
/// </summary>
protected static string ColorColumnsCount = "red";
/// <summary>
/// 无数据时颜色
/// </summary>
protected static string ColorNoData = "red";
/// <summary>
/// 序号颜色
/// </summary>
protected static string ColorSerial = "black";
/// <summary>
/// 字段名颜色
/// </summary>
protected static string ColorFieldName = "blue";
/// <summary>
/// 字段类型颜色
/// </summary>
protected static string ColorFieldType = "#cc9999";
/// <summary>
/// 字段值颜色
/// </summary>
protected static string ColorFieldValue = "#9933ff";
/// <summary>
/// 最终输出字符串
/// </summary>
protected static string DumpStr = string.Empty;
/// <summary>
/// 输出字符串DIV开始
/// </summary>
protected static string DivRef = "<div style='font-size:14px;line-height:20px;margin:5px 0 0 5px;'>";
#endregion #region 直接在浏览器输出数据DataTable
/// <summary>
/// 直接在浏览器输出数据DataTable
/// </summary>
/// <param name="Dt">DataTable表格</param>
public static void DumpDataTable(DataTable Dt)
{
if (Dt != null)
{
int DtRowsCount = Dt.Rows.Count;
int DtColumnsCount = Dt.Columns.Count;
DumpStr = DivRef + "数据类型:<font color=" + ColorDataType + ">TableDate</font> [ 表名:" + Dt.TableName + " 行数:<font color=" + ColorRowCount + ">" + DtRowsCount + "</font>,列数:<font color=" + ColorColumnsCount + ">" + DtColumnsCount + "</font> ] <hr>";
if (DtRowsCount < 1) DumpStr += " <font color=" + ColorNoData + ">无表格行数据!</font>";
else
{
for (int i = 0; i < DtRowsCount; i++)
{
DumpStr += "( Row:<font color=" + ColorSerial + ">" + i + "</font> ) => ";
for (int j = 0; j < DtColumnsCount; j++)
{
string ColumnName = Dt.Columns[j].ColumnName.ToString();
string ColumnType = Dt.Columns[j].DataType.ToString();
DumpStr += "  [" + j + "] <font color=" + ColorFieldName + ">" + ColumnName + "</font> ( <font color=" + ColorFieldType + ">" + ColumnType + "</font> ) => \"<font color=" + ColorFieldValue + ">" + Dt.Rows[i][ColumnName].ToString() + "</font>\"";
}
DumpStr += "<p>";
}
}
}
HttpContext.Current.Response.Write(DumpStr + "</div>");
}
#endregion #region 直接在浏览器输出数据ILIST<ListItem>
/// <summary>
/// 直接在浏览器输出数据ILIST<ListItem>
/// </summary>
/// <param name="ListItems">ILIST<ListItem>泛型数据</param>
public static void DumpListItemILIST(IList<ListItem> ListItems)
{
if (ListItems != null)
{
int ListCount = ListItems.Count;
DumpStr = DivRef + "数据类型:<font color=" + ColorDataType + ">IList<ListItem></font> [ 项目数:<font color=" + ColorRowCount + ">" + ListCount + "</font> ] <hr>";
if (ListCount < 1) DumpStr += " <font color=" + ColorNoData + ">泛型中无数据!</font>";
else
{
for (int i = 0; i < ListCount; i++)
{
DumpStr += "( " + i + " ) => ";
string Texts = ListItems[i].Text.ToString();
string Values = ListItems[i].Value.ToString();
DumpStr += "  <font color=" + ColorFieldName + ">[ Text ]</font> => \"<font color=" + ColorFieldValue + ">" + Texts + "</font>\"";
DumpStr += "  <font color=" + ColorFieldName + ">[ Value ]</font> => \"<font color=" + ColorFieldValue + ">" + Values + "</font>\"";
}
}
}
HttpContext.Current.Response.Write(DumpStr + "</div>");
}
#endregion #region 直接在浏览器输出数据DataTableILIST
/// <summary>
/// 直接在浏览器输出数据DataTableILIST
/// </summary>
/// <param name="ListDataTable">ILIST<ListDataTable>泛型数据</param>
public static void DumpDataTableILIST(IList<DataTable> ListDataTable)
{
if (ListDataTable != null)
{
int ListCount = ListDataTable.Count;
DumpStr = DivRef + "数据类型:<font color=" + ColorDataType + ">IList<DataTable></font> [ DataTable数:<font color=" + ColorRowCount + ">" + ListCount + "</font> ] <hr>";
if (ListCount < 1) DumpStr += " <font color=" + ColorNoData + ">泛型中无数据!</font>";
else
{
for (int i = 0; i < ListCount; i++)
{
if (i > 0) DumpStr += "<hr>";
DataTable Dt = ListDataTable[i];
int DtRowsCount = Dt.Rows.Count;
int DtColumnsCount = Dt.Columns.Count;
DumpStr += "( 表序号:" + i + " 表名:" + Dt.TableName + " ) => [ 行数:<font color=" + ColorRowCount + ">" + DtRowsCount + "</font>,列数:<font color=" + ColorColumnsCount + ">" + DtColumnsCount + "</font> ]";
if (DtRowsCount < 1) DumpStr += " <font color=" + ColorNoData + ">表格中无数据!</font><p>";
else
{
for (int k = 0; k < DtRowsCount; k++)
{
DumpStr += "  ( Row:<font color=" + ColorSerial + ">" + k + "</font> ) => ";
for (int j = 0; j < DtRowsCount; j++)
{
string ColumnName = Dt.Columns[j].ColumnName.ToString();
string ColumnType = Dt.Columns[j].DataType.ToString();
DumpStr += "    [" + j + "] <font color=" + ColorFieldName + ">" + ColumnName + "</font> ( <font color=" + ColorFieldType + ">" + ColumnType + "</font> ) => \"<font color=" + ColorFieldValue + ">" + Dt.Rows[k][ColumnName].ToString() + "</font>\"";
}
DumpStr += "<p>";
}
}
}
}
}
HttpContext.Current.Response.Write(DumpStr + "</div>");
}
#endregion #region 直接在浏览器输出数据整型数组ILIST<int[]>
/// <summary>
/// 直接在浏览器输出数据整型数组ILIST<int[]>
/// </summary>
/// <param name="IntList">ILIST<Int[]>泛型数据</param>
public static void DumpIntArrILIST(IList<int[]> IntList)
{
if (IntList != null)
{
int ListCount = IntList.Count;
DumpStr = DivRef + "数据类型:<font color=" + ColorDataType + ">IList<Int[]></font> [ Int[]个数:<font color=" + ColorRowCount + ">" + ListCount + "</font> ] <hr>";
if (ListCount < 1) DumpStr += " <font color=" + ColorNoData + ">泛型中无数据!</font>";
else
{
for (int i = 0; i < ListCount; i++)
{
int[] IntArr = IntList[i];
int IntArrCount = IntArr.Length;
DumpStr += "( Int[]:<font color=" + ColorSerial + ">" + i + "</font> ) => 数组元素个数:<font color=" + ColorSerial + ">" + IntArrCount + "</font>";
if (IntArrCount < 1) DumpStr += "  <font color=" + ColorNoData + ">数组中无数据</font><p>";
else
{
for (int j = 0; j < IntArrCount; j++)
{
DumpStr += "  [" + j + "] ( <font color=" + ColorFieldType + ">Int</font> ) => \"<font color=" + ColorFieldValue + ">" + IntArr[j].ToString() + "</font>\"";
}
}
}
}
}
HttpContext.Current.Response.Write(DumpStr + "</div>");
}
#endregion #region 直接在浏览器输出数据字符串数组的ILIST<string[]>
/// <summary>
/// 直接在浏览器输出数据字符串数组的ILIST<string[]>
/// </summary>
/// <param name="StrList">ILIST<String[]>泛型数据</param>
public static void DumpStrArrILIST(IList<string[]> StrList)
{
if (StrList != null)
{
int ListCount = StrList.Count;
DumpStr = DivRef + "数据类型:<font color=" + ColorDataType + ">IList<String[]></font> [ String[]个数:<font color=" + ColorRowCount + ">" + ListCount + "</font> ] <hr>";
if (ListCount < 1) DumpStr += " <font color=" + ColorNoData + ">泛型中无数据!</font>";
else
{
for (int i = 0; i < ListCount; i++)
{
string[] StrArr = StrList[i];
int StrArrCount = StrArr.Length;
DumpStr += "( String[]:<font color=" + ColorSerial + ">" + i + "</font> ) => 数组元素个数:<font color=" + ColorSerial + ">" + StrArrCount + "</font>";
if (StrArrCount < 1) DumpStr += "  <font color=" + ColorNoData + ">数组中无数据</font><p>";
else
{
for (int j = 0; j < StrArrCount; j++)
{
DumpStr += "  [" + j + "] ( <font color=" + ColorFieldType + ">Int</font> ) => \"<font color=" + ColorFieldValue + ">" + StrArr[j].ToString() + "</font>\"";
}
}
}
}
}
HttpContext.Current.Response.Write(DumpStr + "</div>");
}
#endregion #region 直接在浏览器输出数据DataSet对象
/// <summary>
/// 直接在浏览器输出数据DataSet对象
/// </summary>
/// <param name="DS">DataSet对象</param>
public static void DumpDataSet(DataSet DS)
{
if (DS != null)
{
int DtCount = DS.Tables.Count;
DumpStr = DivRef + "数据类型:<font color=" + ColorDataType + ">DataSet对象</font> [ DataSet中表格个数:<font color=" + ColorRowCount + ">" + DtCount + "</font> ] <hr>";
if (DtCount < 1) DumpStr += " <font color=" + ColorNoData + ">DataSet对象中无表格!</font>";
else
{
for (int i = 0; i < DtCount; i++)
{
if (i > 0) DumpStr += "<hr>";
DataTable Dt = DS.Tables[i];
int DtRowsCount = Dt.Rows.Count;
int DtColumnsCount = Dt.Columns.Count;
DumpStr += "( 表序号:" + i + " 表名:" + Dt.TableName + " ) => [ 行数:<font color=" + ColorRowCount + ">" + DtRowsCount + "</font>,列数:<font color=" + ColorColumnsCount + ">" + DtColumnsCount + "</font> ]";
if (DtRowsCount < 1) DumpStr += " <font color=" + ColorNoData + ">表格中无数据!</font><p>";
else
{
for (int k = 0; k < DtRowsCount; k++)
{
DumpStr += "  ( Row:<font color=" + ColorSerial + ">" + k + "</font> ) => ";
for (int j = 0; j < DtColumnsCount; j++)
{
string ColumnName = Dt.Columns[j].ColumnName.ToString();
string ColumnType = Dt.Columns[j].DataType.ToString();
DumpStr += "    [" + j + "] <font color=" + ColorFieldName + ">" + ColumnName + "</font> ( <font color=" + ColorFieldType + ">" + ColumnType + "</font> ) => \"<font color=" + ColorFieldValue + ">" + Dt.Rows[k][ColumnName].ToString() + "</font>\"";
}
DumpStr += "<p>";
}
}
}
}
}
HttpContext.Current.Response.Write(DumpStr + "</div>");
}
#endregion #region 直接在浏览器中输出二维数组
/// <summary>
/// 直接在浏览器中输出二维数组
/// </summary>
/// <param name="ObjArr">二维数组</param>
public static void DumpObjectArr2(object[] ObjArr)
{
if (ObjArr != null)
{
int ObjLength = ObjArr.Length;
DumpStr = DivRef + "数据类型:<font color=" + ColorDataType + ">Object数组</font> [ 数组中元素个数:<font color=" + ColorRowCount + ">" + ObjLength + "</font> ] <hr>";
for (int i = 0; i < ObjLength; i++)
{
DumpStr += "  ( <font color=" + ColorSerial + ">" + i + "</font> ) ";
object Arri = ObjArr[i];
DumpStr += " ( ";
DumpStr += "<font color=" + ColorFieldType + ">" + Arri.GetType().ToString() + "</font>";
DumpStr += " ) ";
DumpStr += " => <font color=" + ColorFieldValue + ">\"" + Arri + "\"</font>";
}
}
HttpContext.Current.Response.Write(DumpStr + "</div>");
}
#endregion public static void DumpObjectArr(object[] ObjArr)
{
if (ObjArr != null)
{
HttpContext.Current.Response.Write(ObjArr.GetType());
}
}
}
}

  

[C#] 常用工具类——直接在浏览器输出数据的更多相关文章

  1. [C#] 常用工具类——文件操作类

    /// <para> FilesUpload:工具方法:ASP.NET上传文件的方法</para> /// <para> FileExists:返回文件是否存在&l ...

  2. PHP常用工具类

    <?php namespace isslib\Util; use think\Config; /** * 常用工具类 * User: xaxiong * Date: 2016/12/19 * T ...

  3. javascript常用工具类整理(copy)

    JavaScript常用工具类 类型 日期 数组 字符串 数字 网络请求 节点 存储 其他 1.类型 isString (o) { //是否字符串 return Object.prototype.to ...

  4. commons-lang常用工具类StringEscapeUtils使用--转

    https://my.oschina.net/ydsakyclguozi/blog/341496 在apache commons-lang(2.3以上版本)中为我们提供了一个方便做转义的工具类,主要是 ...

  5. Java项目案例之---常用工具类练习

    常用工具类练习 1. 请根据控制台输入的特定日期格式拆分日期,如:请输入一个日期(格式如:**月**日****年),经过处理得到:****年**月**日 import java.util.Scanne ...

  6. JavaEE-实验一 Java常用工具类编程

    该博客仅专为我的小伙伴提供参考而附加,没空加上代码具体解析,望各位谅解 1.  使用类String类的分割split 将字符串  “Solutions to selected exercises ca ...

  7. 简单了解Spring中常用工具类_java - JAVA

    文章来源:嗨学网 敏而好学论坛www.piaodoo.com 欢迎大家相互学习 文件资源操作 Spring 定义了一个 org.springframework.core.io.Resource 接口, ...

  8. 浅谈集合框架三、Map常用方法及常用工具类

    最近刚学完集合框架,想把自己的一些学习笔记与想法整理一下,所以本篇博客或许会有一些内容写的不严谨或者不正确,还请大神指出.初学者对于本篇博客只建议作为参考,欢迎留言共同学习. 之前有介绍集合框架的体系 ...

  9. Maven基础&&Spring框架阶段常用工具类整理

    常用工具类 1.密码加密工具类: package com.itheima.utils; import java.security.MessageDigest; import sun.misc.BASE ...

随机推荐

  1. 用Python和Django实现多用户博客系统——UUBlog

    又过了一周,把代码整个的优化和完善了一下,也把TBlog更名为UUBlog.这次基本是把上次的整个更新了一下具体的功能大家可以下载后自己看看说一下主要的变化增加了频道表.博客表. 功能方面主要有增加频 ...

  2. c# .net使用SqlDataReader注意的几点

    转自:http://blog.knowsky.com/258608.htm 1.当SqlDataReader没有关闭之前,数据库连接会一直保持open状态,所以在使用SqlDataReader时,使用 ...

  3. 第 8 章 适配器模式【Adapter Pattern】

    以下内容出自:<<24种设计模式介绍与6大设计原则>> 好,请安静,后排聊天的同学别吵醒前排睡觉的同学了,大家要相互理解嘛.今天讲适配器模式,这个模式也很简单,你笔记本上的那个 ...

  4. python学习之---匿名函数,返回函数,偏函数

    1. 返回函数: 所谓的返回函数,指的是函数作为返回值.高阶函数除了可以接受函数作为参数外,同样可以接受函数作为结果返回.以下是一个可变参数的求和例子,一般求和函数是如此这般定义的: >> ...

  5. Ubuntu配置apache

    http://blog.csdn.net/ljchlx/article/details/21978431 http://www.2cto.com/os/201110/107283.html

  6. *string++优先级的问题

    这个东西困扰了我几天,关于优先级问题确实是个恼人的东西,为了这个专门翻了C语言课本,得知 所有一目运算符都是第二级优先级 结合性是从右到左 那么*string++应该就是*(string++),也就是 ...

  7. CodePen避免自动刷新导致的JS卡死

    经常需要做一些前端代码的实验, 这时候我往往会用JSFiddle或CodePen. 最近用CodePen更多一些, 里面提供的选项更加丰富, 提供了各种各样的HTML/Javascript/CSS P ...

  8. IronPython 源码剖析系列(2):IronPython 引擎的运作流程

    http://blog.csdn.net/inelm/article/details/4612987 一.入口点 Python 程序的执行是从 hosting 程序 ipy.exe 开始的,而他的入口 ...

  9. [译]GotW #1: Variable Initialization 续

    Answer 2. 下面每行代码都做了什么? 在Q2中,我们创建了一个vector<int>且传了参数10和20到构造函数中,第一种情况下(10,20),第二种情况是{10, 20}. 它 ...

  10. android 世界各国英文简写代码 资源文件

    今日又用到这段代码,忽然感觉到如果是第一次用的人肯定也会很麻烦.故在此上传一份.后人再用就不必重复做此工作.跟体育老师学过语文,见谅. 提供下载地址 http://download.csdn.net/ ...