0srms Codes
0srms Codes
Imports MySql.Data.MySqlClient
Imports System.Drawing.Printing
txtSearchResident.Focus()
cmbFilterValue.Visible = False
btnAddResident.TabIndex = 1
btnUpdateResident.TabIndex = 2
btnPrint.TabIndex = 3
btnFind.TabIndex = 4
btnReset.TabIndex = 5
btnArchiveResident.TabIndex = 6
btnReports.TabIndex = 7
btnLogOut.TabIndex = 8
LoadResidents()
End Sub
Try
connection.Open()
Case "Sector"
filterColumn = "sector"
End If
filterColumn = "employment_status"
filterValue = cmbFilterValue.SelectedItem.ToString()
End If
filterColumn = "type_of_assistance"
filterValue = cmbFilterValue.SelectedItem.ToString()
End If
Case "All"
filterColumn = ""
End Select
End If
' Modify the query if there is a search input and filter option selected
query &= " AND (first_name LIKE @search OR last_name LIKE @search OR resident_number
LIKE @search)"
End If
query &= " AND " & filterColumn & " = @filterValue"
End If
' Create the command with the query and parameters
End If
cmd.Parameters.AddWithValue("@filterValue", filterValue)
End If
' Execute the query and fill the data into the DataGridView
adapter.Fill(table)
dgvResidents.DataSource = table
dgvResidents.Columns("age").HeaderText = "Age"
dgvResidents.Columns("sector").HeaderText = "Sector"
Catch ex As Exception
Finally
connection.Close()
End Try
End Sub
LoadResidents(txtSearchResident.Text.Trim())
End Sub
LoadResidents(txtSearchResident.Text.Trim())
e.Handled = True
End If
End Sub
PrintDocument1.DefaultPageSettings.Landscape = True
' Maximize the PrintPreviewDialog window
PrintDialog1.WindowState = FormWindowState.Maximized
Dim shortBondSize As New Printing.PaperSize("Short Bond", 850, 1300) ' 850 and 1300 are in
hundredths of an inch (8.5 x 13 inches)
PrintDocument1.DefaultPageSettings.PaperSize = shortBondSize
PrintDialog1.Document = PrintDocument1
PrintDialog1.ShowDialog()
End Sub
Dim fontTitle As New Font("Arial", 16, FontStyle.Bold) ' Larger font for the title
Dim topMargin As Integer = 40 ' Adjust this value for more or less space from the top
' Center the title horizontally and apply the top margin
Dim titleYPosition As Integer = topMargin ' Set Y position with top margin
' Adjust the start position for data to be below the title with additional spacing
' Calculate maximum width for each column based on data and headers
End If
Next
columnWidths.Add(maxColumnWidth)
Next
' Print column headers with scaling, borders, and center alignment
currentX += scaledColumnWidth
Next
offset += 20
currentX = startX
' Print data rows with scaling, borders, and center alignment
e.HasMorePages = True
currentPageIndex += 1
Return
End If
currentX += scaledColumnWidth
Next
offset += CInt(dgvResidents.RowTemplate.Height)
currentX = startX
rowsPrinted += 1
totalRowsPrinted += 1
e.HasMorePages = True
currentPageIndex += 1
Return
End If
Next
e.HasMorePages = False
currentPageIndex = 0
totalRowsPrinted = 0
End Sub
frmAddResident.Show()
Me.Close()
End Sub
frmUpdateResident.Show()
Me.Close()
End Sub
frmArchiveResident.Show()
Me.Close()
End Sub
frmReports.Show()
Me.Close()
End Sub
txtSearchResident.Clear()
' Reset the filter value ComboBox (cmbFilterValue) to its default state
cmbFilterValue.Visible = False
LoadResidents()
txtSearchResident.Focus()
End Sub
frmLogin.Show()
Me.Close()
End Sub
' ComboBox for FilterBy selected index change
cmbFilterValue.Items.Clear()
Case "Sector"
For i As Integer = 1 To 7
cmbFilterValue.Items.Add(i.ToString())
Next
cmbFilterValue.Items.Add("Employed")
cmbFilterValue.Items.Add("Unemployed")
cmbFilterValue.Items.Add("Self-Employed")
cmbFilterValue.Items.Add("Retired")
cmbFilterValue.Items.Add("Student")
cmbFilterValue.Items.Add("4P's")
cmbFilterValue.Items.Add("Pension")
Case "All" ' If "All" is selected, hide the filter value ComboBox
cmbFilterValue.Visible = False
Exit Sub
End Select
' Show the cmbFilterValue and enable it
cmbFilterValue.Visible = True
cmbFilterValue.SelectedIndex = 0
End If
Else
cmbFilterValue.Visible = False
End If
End Sub
txtSearchResident.Clear()
' Reset the ComboBox filter selection (clear it, set to default)
cmbFilterValue.Items.Clear()
dgvResidents.DataSource = Nothing
dgvResidents.Rows.Clear()
' Reload the data (optional) to reset the grid view without any filter
LoadResidents()
End Sub
Else
End If
End If
End Sub
End Sub
End Class