public class PageUtil
{
// Methods
public static DataView GetListForPage(int index, int pagesize, string tabname, string key, string condition, string sortindex, ref int count)
{
int rscount = 0;
StringBuilder strSql = new StringBuilder();
OracleDataReader sdr = null;
if (condition.Length > 0)
{
condition = " and " + condition;
}
strSql.Append("select count(*) from " + tabname + " where 1=1" + condition);
sdr = DbHelperOra.ExecuteReader(strSql.ToString());
if (sdr.Read())
{
rscount = Convert.ToInt32(sdr[0]);
}
sdr.Close();
count = rscount;
int maxpage = ((rscount + pagesize) - 1) / pagesize;
if ((index + 1) >= maxpage)
{
index = maxpage - 1;
}
if (index < 0)
{
index = 0;
}
int start = (index * pagesize) + 1;
int end = ((index + 1) * pagesize) + 1;
string sql = "SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM " + tabname + " where 1=1 " + condition + " order by " + sortindex + " desc) A WHERE ROWNUM < " + end.ToString() + ") WHERE RN >= " + start.ToString();
DataSet ds = new DataSet();
ds = DbHelperOra.Query(sql);
if (ds.Tables.Count > 0)
{
return ds.Tables[0].DefaultView;
}
return null;
}
}