日期:2014-05-18 浏览次数:20465 次
private int pageSize = 0; //每页显示行数 private int pageCurrent = 0; //当前页号 private int pageCount = 0; //页数=总记录数/每页显示行数 private int nCurrent = 0; //当前记录行号 private int nMax = 0; //总记录数 private DataTable srcTable = null; //元数据 private void First_Click(object sender, EventArgs e) { try { pageCurrent = 1; //当前页数从1开始 nCurrent = 0; //当前记录数从0开始 if (srcTable == null || srcTable.Rows.Count == 0) return; DataTable table = LoadPageData(); ChangeDataSoure(table); First.Enabled =false; Prev.Enabled = false; Next.Enabled = true; End.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Prev_Click(object sender, EventArgs e) { try { pageCurrent--; nCurrent = pageSize * (pageCurrent - 1); if (srcTable == null || srcTable.Rows.Count == 0) return; DataTable table = LoadPageData(); ChangeDataSoure(table); bool b = pageCurrent <= 1 ? false : true; First.Enabled = b; Prev.Enabled = b; Next.Enabled = true; End.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Next_Click(object sender, EventArgs e) { try { pageCurrent++; nCurrent = pageSize * (pageCurrent - 1); if (srcTable == null || srcTable.Rows.Count == 0) return; DataTable table = LoadPageData(); ChangeDataSoure(table); bool b = pageCurrent >= pageCount ? false : true; Next.Enabled = b; End.Enabled = b; First.Enabled = true; Prev.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void End_Click(object sender, EventArgs e) { try { pageCurrent = pageCount; nCurrent = pageSize * (pageCurrent - 1); if (srcTable == null || srcTable.Rows.Count == 0) return; DataTable table = LoadPageData(); ChangeDataSoure(table); Next.Enabled =false; End.Enabled = false; First.Enabled = true; Prev.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void InitPageSet() { pageSize = 30; //设置页面行数 nMax = srcTable.Rows.Count; pageCount = (nMax / pageSize); //计算出总页数 if ((nMax % pageSize) > 0) { pageCount++; } pageCurrent = 1; //当前页数从1开始 nCurrent = 0; //当前记录数从0开始 First.Enabled =false; Prev.Enabled = false; bool b = pageCurrent == pageCount ? false : true; Next