/// <summary>
/// DataSet转化为序列化类函数,类定义参考cXTM_User
/// </summary>
private void DataTableReturnOO(DataRow row, cXTM_User objModel)
{
Hashtable hTable = new Hashtable();
hTable = ReturnHashtable(row);
Type entitytype = Type.GetType(objModel.GetType().AssemblyQualifiedName);
for (int j = 0; j < objModel.Propertylist.Length; j++)
{
PropertyInfo propertyinfo = entitytype.GetProperty(objModel.Propertylist[j]);
propertyinfo.SetValue(objModel, hTable[objModel.Propertylist[j]], null);
}
}
/// <summary>
/// 转换为DataTable
/// </summary>
/// <param name="Source">数据源</param>
/// <param name="DataMember">数据表名称</param>
public static DataTable ConvertDataTable(object Source, string DataMember)
{
DataTable baseTable = new DataTable();
if (Source is DataTable)
{
baseTable = (DataTable)Source;
return baseTable;
}
if (Source is DataSet)
{
DataSet set1 = (DataSet)Source;
if ((set1.Tables.Count > 1) && ((DataMember == null) || (DataMember == "")))
{
throw new Exception("If there is more than one table in your dataset, you must define the DataMember property to specify which table to use.");
}
if (set1.Tables.Count < 1)
{
throw new Exception("There are no tables in the datasource.");
}
if ((DataMember != null) && (DataMember != ""))
{
baseTable = set1.Tables[DataMember];
return baseTable;
}
else
{
baseTable = set1.Tables[0];
return baseTable;
}
}
return baseTable;
}
/// <summary>
/// 返回DataTable为哈希表键值对
/// </summary>
/// <param name="SourceTable">数据行对象</param>
/// <returns></returns>
public static Hashtable ReturnHashtable(DataRow SourceRow)
{
Hashtable hTable = new Hashtable();
IList list = SourceRow.ItemArray;
object[] tObj = new object[SourceRow.Table.Columns.Count];
for (int i = 0; i < SourceRow.Table.Columns.Count; i++)
{
tObj[SourceRow.Table.Columns.IndexOf(SourceRow.Table.Columns[i].ColumnName)] = SourceRow.Table.Columns[i].ColumnName;
}
for (int x = 0; x < list.Count; x++)
{
hTable.Add(tObj[x].ToString(), list[x]);
}
return hTable;
}
}
5. PageBase.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HTMLControls;
using System.Reflection;
using System.Text;
using System.Collections;
//namespace可要可不要
//namespace Framework.Web.UIProcess
//{
/// <summary>
/// PageBase 的摘要说明
/// </summary>
/// <summary>
/// 页面层(表示层)基类,所有页面继承该页面
/// </summary>
public class PageBase : System.Web.UI.Page
{
#region 整个系统存在部分
private string _baseselect;
/// <summary>
/// 查询字段
/// </summary>
protected string baseselect
{
get
{
// TODO: 添加 BaseRule.OperationCode getter 实现
return _baseselect;
}
set
{
// TODO: 添加 BaseRule.OperationCode setter 实现
_baseselect = value;
}
}
/// <summary>
/// 基类哈希表,在整个系统中存在
/// </summary>
protected Hashtable baseHashtable = new Hashtable();
/// <summary>
/// 界面哈希表,获取UI工厂获取的控件和控件值
/// </summary>
protected Hashtable UIhashtable = new Hashtable();
/// <summary>
/// 出错提示,默认值""
/// </summary>
protected string errMsg = "";
/// <summary>
/// 出错状态,默认值false
/// </summary>
protected bool errState = false;
/// <summary>
/// 私有变量_UISet
/// </summary>
private DataSet _UISet = new DataSet();
/// <summary>
/// 界面层数据集
/// </summary>
protected DataSet UISet
{
get
{
// TODO: 添加 BaseRule.OperationCode getter 实现
return _UISet;
}
set
{
// TODO: 添加 BaseRule.OperationCode setter 实现
_UISet = value;
}
}
private DataTable _UITable = new DataTable();
/// <summary>
/// 界面层数据表
/// </summary>
protected DataTable UITable
{
get
{
// TODO: 添加 BaseRule.OperationCode getter 实现
return _UITable;
}
set
{
// TODO: 添加 BaseRule.OperationCode setter 实现
_UITable = value;
}
}
private string _pageTitle = "";
/// <summary>
/// 页面标题
/// </summary>
protected string pageTitle
{
get
{
// TODO: 添加 BaseRule.OperationCode getter 实现
return _pageTitle;
}
set
{
// TODO: 添加 BaseRule.OperationCode setter 实现
_pageTitle = value;
}
}
#endregion
#region 查询页面存在部分
/// <summary>
/// List页面基类哈希表
/// </summary>
protected Hashtable baseListHashtable = new Hashtable();
/// <summary>
/// 页面总数.变量.1000w、10000w数据集使用
/// </summary>
protected int pageCount;
/// <summary>
/// 记录总数.变量.1000w、10000w数据集使用
/// </summary>
protected int recordCount;
/// <summary>
/// 记录总数.属性.1000w、10000w数据集使用
/// </summary>
protected int RecordCount
{
get
{
return recordCount;
}
}
#endregion
#region 编辑页面存在部分
/// <summary>
/// Edit页面基类哈希表
/// </summary>
protected Hashtable baseEditHashtable = new Hashtable();
/// <summary>
/// Edit页面,编辑数据哈希表
/// </summary>
protected Hashtable baseEditFillHashtable = new Hashtable();
#endregion
/// <summary>
/// 构造函数
/// </summary>
public PageBase()
{
this.Load += new EventHandler(PageBase_Load);
}
private void PageBase_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//整个流程需要的控制部分
if (Session["baseHashtable"] != null)
{
//从Session中获取哈希对象列表
baseHashtable = (Hashtable)Session["baseHashtable"];
}
//编辑页面访问权限和访问控制,只在第一次载入页面的时候有效
if (Session["baseEditHashtable"] != null)
{
//获取Edit页面哈希对象列表
baseEditHashtable = (Hashtable)Session["baseEditHashtable"];
//获取完后释放对应Session对象
Session.Remove("baseEditHashtable");
}
else
{
//如果为初始状态,新增是否安全编辑状态值,默认值false,不安全
baseEditHashtable.Add("EditSafeState", false);
}
}
//查询页面访问控制
if (Session["baseListHashtable"] != null)
{
//获取Edit页面哈希对象列表
baseListHashtable = (Hashtable)Session["baseListHashtable"];
//获取完后释放对应Session对象
Session.Remove("baseListHashtable");
}
else
{
//如果为初始状态,新增是否刷新查询页面,默认值false,不刷新
baseListHashtable.Add("IsRefresh", false);
}
}
#region UI通用函数
/// <summary>
/// 抛出出错消息提示
/// </summary>
/// <param name="page">页面</param>
/// <param name="errMsg">出错消息</param>
protected void throwErrMsg(Page page, string errMsg)
{
page.Response.Write("<script>window.alert(\"" + errMsg.Replace("\"", "'") + "\");</script>");
}
/// <summary>
/// 刷新打开编辑窗体的List页面
/// </summary>
/// <param name="page">页面</param>
protected void parentPageRefresh(Page page)
{
StringBuilder scriptString = new StringBuilder();
scriptString.Append("<script language = javascript>");
//调用Function.js中的refresh()刷新父窗体
scriptString.Append("window.opener.refresh(false,\"\");");
scriptString.Append(" window.focus();");
scriptString.Append(" window.opener=null;");
scriptString.Append(" window.close(); ");
scriptString.Append("</" + "script>");
page.Response.Write(scriptString.ToString());
}
/// <summary>
/// 重置页面
/// </summary>
/// <param name="page">页面</param>
protected void pageReset(Page page)
{
StringBuilder scriptString = new StringBuilder();
scriptString.Append("<script language = javascript>");
scriptString.Append(" this.location.reset(); ");
scriptString.Append("</" + "script>");
page.Response.Write(scriptString.ToString());
}
/// <summary>
/// js界面工厂传入后生成Hashtable
/// </summary>
/// <param name="splitStr">js界面工厂传入字符串</param>
/// <returns></returns>
public Hashtable AjaxUIFactory(string splitStr)
{
string[] fristStr = splitStr.Split(',');
Hashtable table = new Hashtable();
for (int x = 0; x < fristStr.Length; x++)
{
string[] secondStr = fristStr[x].Split('|');
if (secondStr.Length == 3)
{
//取截取后字符串和值
table.Add(secondStr[1], secondStr[2]);
}
}
return table;
}
#endregion
}
http://www.cnblogs.com/mail-ricklee/archive/2006/11/23/569270.HTML
。