2nd page not populate

dammam2024

New member
Joined
Apr 25, 2024
Messages
2
Programming Experience
1-3
VB.NET:
Imports System.Data.OleDb
Imports System.Drawing
Imports System.Windows.Forms

Public Class FrmRoom
    Inherits Form
    Private pageIndex As Integer = 0 ' Declare pageIndex as a class-level variable
    Private Const roomWidth As Integer = 50
    Private Const roomHeight As Integer = 50
    Private Const paddingX As Integer = 10
    Private Const paddingY As Integer = 10
    Private Const columnsPerPage As Integer = 16
    Private ReadOnly connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\db_billing.accdb;"
    Private roomData As New List(Of Room)()

    Public Sub New()
        InitializeComponent()
        LoadRoomData()
        DrawRoomRectangles()
    End Sub

    Private Sub LoadRoomData()
        roomData.Clear()
        Using connection As New OleDbConnection(connectionString)
            Dim query As String = "SELECT TOP 336 * FROM tblRoom" ' Assuming first page has 336 rooms
            ' Dim query As String = "SELECT * FROM tblRoom"
            Dim command As New OleDbCommand(query, connection)

            connection.Open()
            Dim reader As OleDbDataReader = command.ExecuteReader()

            While reader.Read()
                Dim roomNo As String = reader("room_no").ToString()
                Dim status As String = reader("status").ToString()
                Dim dateIn As DateTime = Convert.ToDateTime(reader("datein"))
                Dim dateOut As DateTime = Convert.ToDateTime(reader("dateot"))
                Dim remarks As String = reader("remarks").ToString()

                Dim room As New Room(roomNo, status, dateIn, dateOut, remarks)
                roomData.Add(room)
            End While
        End Using
    End Sub

    Private Sub DrawRoomRectangles()
      
        Dim startX As Integer = 20
        Dim startY As Integer = 20
        Dim pageIndex As Integer = 0
        Dim roomsPerPage As Integer = 336 ' Assuming 336 rooms per page

        Dim startIndex As Integer = pageIndex * roomsPerPage
        Dim endIndex As Integer = Math.Min(startIndex + roomsPerPage, roomData.Count)
        Dim font As New Font("Calibri", 14, FontStyle.Bold)
        For i As Integer = startIndex To endIndex - 1
            Dim room As Room = roomData(i)
            Dim rect As New Rectangle(startX, startY, roomWidth, roomHeight)
            Dim brush As Brush = If(room.Status = "VACCANT", Brushes.Green, Brushes.Yellow)
            Me.CreateGraphics().FillRectangle(brush, rect)
            Me.CreateGraphics().DrawString(room.RoomNo, font, Brushes.Red, startX, startY)
            'Dim font As New Font("Calibri", 14, FontStyle.Bold)
            '        '        g.DrawString(room.RoomNo, font, Brushes.Black, startX, startY)
            startX += roomWidth + paddingX

            If startX + roomWidth + paddingX > Me.ClientSize.Width Then
                startX = 20
                startY += roomHeight + paddingY
            End If
          
          
        Next
      
    End Sub

  

    Private Sub FrmRoom_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
        Dim mouseX As Integer = e.X
        Dim mouseY As Integer = e.Y

        For Each room As Room In roomData
            Dim rect As New Rectangle(room.X, room.Y, roomWidth, roomHeight)
            If rect.Contains(mouseX, mouseY) Then
                'MessageBox.Show($"Room {room.RoomNo} clicked.")
                MessageBox.Show(String.Format("Room {0} clicked.", room.RoomNo))
                Exit For
            End If
        Next
    End Sub

    Private Class Room
        Public Property RoomNo As String
        Public Property Status As String
        Public Property DateIn As DateTime
        Public Property DateOut As DateTime
        Public Property Remarks As String
        Public Property X As Integer
        Public Property Y As Integer

        Public Sub New(ByVal roomNo As String, ByVal status As String, ByVal dateIn As DateTime, ByVal dateOut As DateTime, ByVal remarks As String)
            Me.RoomNo = roomNo
            Me.Status = status
            Me.DateIn = dateIn
            Me.DateOut = dateOut
            Me.Remarks = remarks
        End Sub
    End Class

    Private Sub FrmRoom_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LoadRoomData()
        DrawRoomRectangles()
    End Sub
    'Private Sub LoadNextPage()
    '    ' Clear previous room data

    '    pageIndex += 1

    '    ' Clear previous room data
    '    Me.Controls.Clear()
    '    DrawRoomRectangles()
    '    ' Load rooms for the next page
    '    Dim roomsPerPage As Integer = 336 ' Assuming 336 rooms per page

    '    Dim startIndex As Integer = pageIndex * roomsPerPage
    '    Dim endIndex As Integer = Math.Min(startIndex + roomsPerPage, roomData.Count)

    '    Dim startX As Integer = 20
    '    Dim startY As Integer = 20

    '    For i As Integer = startIndex To endIndex - 1
    '        If i < roomData.Count Then
    '            Dim room As Room = roomData(i)
    '            Dim rect As New Rectangle(startX, startY, roomWidth, roomHeight)
    '            Dim brush As Brush = If(room.Status = "VACCANT", Brushes.Green, Brushes.Red)
    '            Me.CreateGraphics().FillRectangle(brush, rect)
    '            Me.CreateGraphics().DrawString(room.RoomNo, Me.Font, Brushes.Black, startX, startY)

    '            startX += roomWidth + paddingX

    '            If startX + roomWidth + paddingX > Me.ClientSize.Width Then
    '                startX = 20
    '                startY += roomHeight + paddingY
    '            End If
    '        End If
    '    Next

    '    ' Refresh the form to redraw the rooms
    '    Me.Refresh()
    'End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'DrawRoomRectangles()
        LoadNextPage()
    End Sub
    Private Sub LoadNextPage()
        ' Clear previous room data
        Me.Controls.Clear()

        ' Increment the page index
        pageIndex += 1

        ' Draw rooms for the next page
        DrawRoomRectangles()

        ' Refresh the form to redraw the rooms
        Me.Refresh()
    End Sub
End Class

2nd page not display please help
 
Last edited by a moderator:
There's far too much code there - it's certainly not all relevant to the issue, especially the method that is commented out - and far too little explanation of the problem.
 
Back
Top