首页 > 开发 > 综合 > 正文

页面无限跳转间如何保存页面状态(2)

2024-07-21 02:16:25
字体:
来源:转载
供稿:网友
解决方法的实现
以上分析过了之后,我们来看如何实现他:
class datainfo:这个类用于保存数据状态,一般而言,也就是每个datagrid对应一个:
[serializable()]
public class datainfo
{
private string dataname;
private hashtable searchparams;
private hashtable otherparams;
private int currentpage;
private string sortexpression;
private string itemid;

public datainfo(string dataname)
{
this.dataname = dataname;
}

/// <summary>
/// 数据名
/// </summary>
public string dataname
{
get { return dataname; }
}
/// <summary>
/// 查询参数
/// </summary>
public hashtable searchparams
{
get { return searchparams; }
set { searchparams = value; }
}

/// <summary>
/// 获取其他参数
/// </summary>
public hashtable otherparams
{
get { return otherparams; }
set { otherparams = value; }
}

/// <summary>
/// 获取当前页
/// </summary>
public int currentpage
{
get { return currentpage; }
set { currentpage = value; }
}

/// <summary>
///获取排序方式
/// </summary>
public string sortexpression
{
get { return sortexpression ;}
set { sortexpression = value; }
}

/// <summary>
/// 获取要显示在当前页的项的id
/// </summary>
public string itemid
{
get { return itemid; }
set { itemid = value; }
}
}

class datainfolist:这个类包装承载datainfo的动态数组,限定数组输入输出的数据类型
[serializable()]
public class datainfolist
{
private arraylist datainfolist = new arraylist();

public datainfo this[int index]
{
get
{
return (datainfo)datainfolist[index];
}
set
{
if (((datainfo)datainfolist[index]).dataname == value.dataname || this[value.dataname] == null)
{
datainfolist[index] = value;
}
else
{
throw new exception("there have a datainfo used this name yet!");
}
}
}

public datainfo this[string dataname]
{
get
{
for (int i = 0; i < datainfolist.count; i++)
{
if (this[i].dataname == dataname)
{
return this[i];
}
}
return null;
}
set
{
for (int i = 0; i < datainfolist.count; i++)
{
if (this[i].dataname == dataname)
{
this[i] = value;
return;
}
}
this.add(value);
}
}

public void remove(datainfo value)
{
datainfolist.remove(value);
}

public void remove(string dataname)
{
datainfo datainfo = this[dataname];
if (datainfo != null)
{
datainfolist.remove(datainfo);
}
}

public bool contains(datainfo value)
{
return datainfolist.contains(value);
}

public bool contains(string dataname)
{
datainfo datainfo = this[dataname];
if (datainfo != null)
{
return true;
}
return false;
}

public void clear()
{
datainfolist.clear();
}

public int add(datainfo value)
{
if (this[value.dataname] == null)
{
return datainfolist.add(value);
}
else
{
throw new exception("there have a datainfo used this name yet!");
}
}

public int count
{
get
{
return datainfolist.count;
}
}
}

interface ipageinfo:这个接口用在页面中,以实现页面间的数据通信。
public interface ipageinfo
{
/// <summary>
/// 页面名
/// </summary>
string pagename
{
get;
}
/// <summary>
/// 获取数据信息
/// </summary>
datainfolist datainfos
{
get;
}

/// <summary>
/// 获取其他参数
/// </summary>
hashtable otherparams
{
get;
}
}


(未完待续)
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表