PageControl.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Windows.Forms;
  3. using DevExpress.XtraEditors;
  4. using UAS_DeviceMonitor.DataOperate;
  5. using UAS_DeviceMonitor.Entity;
  6. namespace UAS_DeviceMonitor.CustomerControl.PagingControl
  7. {
  8. public partial class PageControl : UserControl
  9. {
  10. DataHelper dh = SystemInf.dh;
  11. private AutoDataGridControl.AutoDataGridControl gridcontrol;
  12. public AutoDataGridControl.AutoDataGridControl Gridcontrol
  13. {
  14. get
  15. {
  16. return gridcontrol;
  17. }
  18. set
  19. {
  20. gridcontrol = value;
  21. }
  22. }
  23. public PageControl()
  24. {
  25. InitializeComponent();
  26. }
  27. private void PageControl_Load(object sender, EventArgs e)
  28. {
  29. gridcontrol.VisibleChanged += Gridcontrol_VisibleChanged;
  30. }
  31. private void Gridcontrol_VisibleChanged(object sender, EventArgs e)
  32. {
  33. PageCount.Text = (gridcontrol.RowCount / int.Parse(PageSize.Text) + 1).ToString();
  34. }
  35. private void GoPage_Click(object sender, EventArgs e)
  36. {
  37. SimpleButton button = sender as SimpleButton;
  38. string SQL = gridcontrol.GetDataSQL;
  39. int pagesize = int.Parse(PageSize.Text);
  40. int currentpage = int.Parse(CurrentPage.Text);
  41. int rowcount = gridcontrol.RowCount;
  42. switch (button.Name)
  43. {
  44. case "GoFirstPage":
  45. CurrentPage.Text = "1";
  46. currentpage = 1;
  47. break;
  48. case "GoFormerPage":
  49. if (currentpage == 1)
  50. {
  51. MessageBox.Show("当前已经是第一页");
  52. return;
  53. }
  54. CurrentPage.Text = (currentpage - 1).ToString();
  55. currentpage = currentpage - 1;
  56. break;
  57. case "GoNextPage":
  58. if (currentpage.ToString() == PageCount.Text)
  59. {
  60. MessageBox.Show("当前已经是最后一页");
  61. return;
  62. }
  63. CurrentPage.Text = (currentpage + 1).ToString();
  64. currentpage = currentpage + 1;
  65. break;
  66. case "GoLastPage":
  67. CurrentPage.Text = ((rowcount / pagesize) + 1).ToString();
  68. currentpage = int.Parse(PageCount.Text);
  69. break;
  70. default:
  71. break;
  72. }
  73. gridcontrol.DataSource = dh.ExecuteSql("select * from (select RowNum RN, A.* from(" + SQL + ")A) where RN<=" + pagesize * currentpage + "and RN >" + pagesize * (currentpage - 1), "select");
  74. }
  75. }
  76. }