{
Int32 PageSize = 0;
Int32 PageCount, RecCount, CurrentPage, Pages;
bool isSorting = false; //True if the user is sorting a column
int sortColumn; //The column number the user is trying to sort
int sortBand;
string sortSequence = " ASC ";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
PageSize = this.uwgKeyWord.DisplayLayout.Pager.PageSize;
RecCount = Calc();
//Record Page count.
PageCount = RecCount / PageSize + OverPage();
//ViewState["PageCounts"] = RecCount / PageSize - ModPage();
ViewState["PageCounts"] = RecCount / PageSize;
ViewState["PageIndex"] = 0;
ViewState["JumpPages"] = PageCount;
ViewState["Order"] = " ORDER BY ID ASC ";
//TDataBind();
InitData();
this.CheckUserType();
}
}
public Int32 OverPage()
{
PageSize = this.uwgKeyWord.DisplayLayout.Pager.PageSize;
Int32 pages = 0;
if (RecCount % PageSize != 0)
pages = 1;
else
pages = 0;
return pages;
}
public Int32 ModPage()
{
PageSize = this.uwgKeyWord.DisplayLayout.Pager.PageSize;
Int32 pages = 0;
if (RecCount % PageSize == 0 && RecCount != 0)
pages = 1;
else
pages = 0;
return pages;
}
public static Int32 Calc()
{
Int32 RecordCount = 0;
SqlCommand MyCmd = new SqlCommand("select count(*) as co from failurelog ", MyCon());
SqlDataReader dr = MyCmd.ExecuteReader();
if (dr.Read())
RecordCount = Int32.Parse(dr["co"].ToString());
MyCmd.Connection.Close();
return RecordCount;
}
public static Int32 Calc(string sqlSearch)
{
Int32 RecordCount = 0;
SqlCommand MyCmd = new SqlCommand(sqlSearch, MyCon());
SqlDataReader dr = MyCmd.ExecuteReader();
if (dr.Read())
RecordCount = Int32.Parse(dr["co"].ToString());
MyCmd.Connection.Close();
return RecordCount;
}
public static SqlConnection MyCon()
{
SqlConnection MyConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
MyConnection.Open();
return MyConnection;
}
#region Bind UltraWebGrid
/// <summary>
/// Bind data to UltraWebGrid.
/// </summary>
private void BindData()
{
string querySql = "";
string sqlSearch = "";
PageSize = this.uwgKeyWord.DisplayLayout.Pager.PageSize;
if (!string.IsNullOrEmpty(QueryCondition()))
{
sqlSearch = "select Count(*) as co from failurelog " + QueryCondition();
RecCount = Calc(sqlSearch);
//Record Page count.
PageCount = RecCount / PageSize + OverPage();
}
else
{
RecCount = Calc();
}
ViewState["PageCounts"] = RecCount / PageSize;
CurrentPage = (int)ViewState["PageIndex"];
Pages = (int)ViewState["PageCounts"];
if (Pages == 0)
{
Pages = 1;
}
if (PageCount == 0)
{
PageCount = 1;
}