exampleasp.cs
int RecordCount = FunctionClass.BindData2Gridview("BOOKING_DETAILDAL", "SelectBookongStat", rptContiner, ViewState["Filter"].ToString(), DispartPage1.PageSize, curPage);
/// <summary>
/// 绑定数据到GridView
/// </summary>
/// <param name="DalClass">数据访问层的类名称</param>
/// <param name="methodName">要调用的方法名</param>
/// <param name="myGridView">要绑定的GridView</param>
/// <param name="fitler">筛选条件</param>
/// <param name="pagesize">分页大小</param>
/// <param name="curPage">当前页</param>
/// <returns>返回总记录数</returns>
public static int BindData2Gridview(string DalClass, string methodName, GridView myGridView, string fitler, int pagesize, int curPage)
{
int count = 0;
DataSet ds;
if (curPage != 0 && pagesize != 0)
{
object[] parm ={ fitler, pagesize, curPage, count };
ds = (DataSet)MethodInvoke(DalClass, methodName, parm);
count = (int)parm[3];
}
else
{
ds = (DataSet)MethodInvoke(DalClass, methodName, new object[] { fitler });
count = ds.Tables[0].Rows.Count;
}
FunctionClass.BindData(myGridView, ds);
return count;
}
/// <summary>
///
/// </summary>
/// <param name="myGridView">要绑定的GridView</param>
/// <param name="DalClass">数据访问层的类名称</param>
/// <param name="method">要执行的方法</param>
/// <param name="parm">方法带的参数</param>
/// <returns>返回记录数</returns>
public static int BindData2Gridview(GridView myGridView, string DalClass, string method, object[] parm)
{
DataSet ds = (DataSet)MethodInvoke(DalClass, method, parm);
FunctionClass.BindData(myGridView, ds);
return ds.Tables[0].Rows.Count;
}
#region 数据层方法调用
/// <summary>
/// 数据层方法调用
/// </summary>
/// <param name="DalClass">数据类</param>
/// <param name="methodName">要调用的方法</param>
/// <param name="parm">方法的参数</param>
/// <returns>方法返回结果</returns>
public static object MethodInvoke(string DalClass, string methodName, object[] parm)
{
string assemblyName = "PHY.CY.DAL";
return MethodInvoke(assemblyName, DalClass, methodName, parm);
}
#endregion
#region 反射方法调用
/// <summary>
/// 反射方法调用
/// </summary>
/// <param name="assemblyName">命名空间</param>
/// <param name="DalClass">方法类名</param>
/// <param name="methodName">方法名</param>
/// <param name="parm">方法的参数</param>
/// <returns>方法的结果集Object</returns>
public static object MethodInvoke(string assemblyName, string DalClass, string methodName, object[] parm)
{
Assembly assembly = Assembly.Load(assemblyName);
Type type = assembly.GetType(assemblyName + "." + DalClass);
MethodInfo method = type.GetMethod(methodName);
return method.Invoke(null, parm);//调用SelectBookongStat
}
#endregion
#endregion
#region BindData函数
/// <summary>
/// 将查询出的数据绑定到webc_InControl控件,并返回记录条数
/// </summary>
/// <param name="webc_InControl">要绑定数据的控件</param>
/// <param name="str_CmdText">要绑定的数据</param>
/// <returns></returns>
public static int BindData(WebControl webc_InControl, DataSet dst_InitDst)
{
webc_InControl.GetType().GetProperty("DataSource").SetValue(webc_InControl, dst_InitDst, null);
webc_InControl.DataBind();
return dst_InitDst.Tables[0].Rows.Count;
}
#endregion