Dim mintTotalRecords As Integer = 0
Dim mintPageSize As Integer = 0
Dim mintPageCount As Integer = 0
Dim mintCurrentPage As Integer = 1
Private Sub btnFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFirst.Click
mintCurrentPage = 0
loadPage()
End Sub
Private Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
If mintCurrentPage = mintPageCount Then mintCurrentPage = mintPageCount - 1
mintCurrentPage -= 1
If mintCurrentPage < 1 Then mintCurrentPage = 0
loadPage()
End Sub
Private Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
mintCurrentPage += 1
If mintCurrentPage > (mintPageCount - 1) Then mintCurrentPage = mintPageCount - 1
loadPage()
End Sub
Private Sub btnLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLast.Click
mintCurrentPage = mintPageCount - 1
loadPage()
End Sub
Private Sub FillGridB()
'فحص الاتصال بقاعدة البيانات
If SQL.conn.State = ConnectionState.Open Then
SQL.conn.Close()
End If
SQL.conn.Open()
' For Page view.
mintPageSize = Integer.Parse(tbPageSize.Text)
mintTotalRecords = GetRowsCount()
mintPageCount = (mintTotalRecords / mintPageSize)
' Adjust page count if the last page contains partial page.
If ((mintTotalRecords Mod mintPageSize) > 0) Then
mintPageCount = (mintPageCount + 1)
End If
mintCurrentPage = 0
loadPage()
SQL.conn.Close()
End Sub
Private Function GetRowsCount() As Integer
Dim strSqll As String = ""
If ComboBox1.SelectedItem = "الرجاء أختيار الصنف . . ." Or ComboBox1.SelectedItem = "أظهار الكل" Then
strSqll = "SELECT * FROM covers_goods_in_view Where date BETWEEN '" & DateTime1.Text & "' AND '" & DateTime2.Text & "'"
ElseIf ComboBox1.SelectedItem IsNot "الرجاء أختيار الصنف . . ." Or ComboBox1.SelectedItem IsNot "أظهار الكل" Then
strSqll = "SELECT * FROM covers_goods_in_view WHERE p_name =N'" & cover_name & "' AND date BETWEEN '" & DateTime1.Text & "' AND '" & DateTime2.Text & "'"
End If
Dim da As New SqlDataAdapter(strSqll, SQL.conn)
Dim ds As New DataSet
da.Fill(ds)
Return ds.Tables(0).Rows.Count
End Function
Private Sub loadPage()
Dim strSql As String = ""
Dim intSkip As Integer = 0
intSkip = (mintCurrentPage * mintPageSize)
If ComboBox1.SelectedItem = "الرجاء أختيار الصنف . . ." Or ComboBox1.SelectedItem = "أظهار الكل" Then
strSql = "SELECT TOP " & mintPageSize & " * FROM covers_goods_in_view WHERE ID NOT IN (SELECT TOP " & intSkip & " ID FROM covers_goods_in_view) and date BETWEEN '" & DateTime1.Text & "' AND '" & DateTime2.Text & "' ORDER BY Date DESC"
ElseIf ComboBox1.SelectedItem IsNot "الرجاء أختيار الصنف . . ." Or ComboBox1.SelectedItem IsNot "أظهار الكل" Then
strSql = "SELECT TOP " & mintPageSize & " * FROM covers_goods_in_view WHERE ID NOT IN (SELECT TOP " & intSkip & " ID FROM covers_goods_in_view) and p_name =N'" & cover_name & "' AND date BETWEEN '" & DateTime1.Text & "' AND '" & DateTime2.Text & "'ORDER BY Date DESC"
End If
Dim cmd As SqlCommand = SQL.conn.CreateCommand()
cmd.CommandText = strSql
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As DataSet = New DataSet()
RGridview.CancelEdit()
RGridview.Columns.Clear()
RGridview.DataSource = Nothing
Dim dt As New DataTable
da.Fill(dt)
'Delete Button
Dim btnDelete As New DataGridViewButtonColumn()
btnDelete.FlatStyle = FlatStyle.Flat
RGridview.Columns.Insert(0, btnDelete)
RGridview.Columns.Add("", "رقم الصنف")
RGridview.Columns.Add("", "الصنف")
RGridview.Columns.Add("", "الحجم")
RGridview.Columns.Add("", "سعر المتر")
RGridview.Columns.Add("", "سعر الشراء")
RGridview.Columns.Add("", "التاريخ")
RGridview.Columns.Add("", "الملاحظات")
RGridview.Columns.Add("", "ID")
RGridview.Columns(8).Visible = False
Dim i As Integer
For i = 0 To dt.Rows.Count - 1
RGridview.Rows.Add()
RGridview.Rows(i).Cells(1).Value = dt.Rows(i).ItemArray(1)
RGridview.Rows(i).Cells(2).Value = dt.Rows(i).ItemArray(2)
RGridview.Rows(i).Cells(3).Value = dt.Rows(i).ItemArray(3)
RGridview.Rows(i).Cells(4).Value = dt.Rows(i).ItemArray(4)
RGridview.Rows(i).Cells(5).Value = dt.Rows(i).ItemArray(5)
RGridview.Rows(i).Cells(6).Value = dt.Rows(i).ItemArray(6)
RGridview.Rows(i).Cells(7).Value = dt.Rows(i).ItemArray(7)
RGridview.Rows(i).Cells(8).Value = dt.Rows(i).ItemArray(0)
Next
SQL.conn.Close()
RGridview.Columns(7).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
RGridview.CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal
Me.RGridview.GridColor = Color.WhiteSmoke
lblStatus.Text = (mintCurrentPage + 1).ToString() & " / " + mintPageCount.ToString()
cmd.Dispose()
da.Dispose()
ds.Dispose()
End Sub