解决方法的实现
以上分析过了之后,我们来看如何实现他:
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;
}
}
(未完待续)