You are on page 1of 65

frmAddaccounts

Imports MySql.Data.MySqlClient
Public Class frmAddaccounts
Public arrImage() As Byte
Public loadpic As Boolean = False
Public sLoadImg As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
btnSave.Click
If txIdnum.BackColor = Color.Red Then
Dim MsgBox_ As New frmCustomMessageBox("ID Number already
exist!", My.Resources.MsgBoxStyle_Information, "Ok", "Cancel", False) :
Dim result = MsgBox_.ShowDialog()
Else
If btnSave.Text = "Save" Then
If txPassword.Text = txConpass.Text Then
AddAccount() : Me.Close() :
frmMain.LvwLoad_Accounts()
Else
MsgBox("Incorrect password")
End If
Else
If txPassword.Text = txConpass.Text Then
UpdateAccount() : Me.Close() :
frmMain.LvwLoad_Accounts()
Else
MsgBox("Incorrect password")
End If
End If
End If
End Sub
Private Sub AddAccount()
If arrImage Is Nothing Then
sql = "INSERT INTO tblaccounts (Sidnum, Sfirstname,
Smidname, Slastname, Sacctype, Susername, Spassword, SsecQues, Sanswer,
Sstatus) VALUES ('" & txIdnum.Text & "','" & txFirstname.Text & "','" &
txMidname.Text & "','" & txLastname.Text & "','" & txAcctype.Text &
"','" & txUsername.Text & "','" & txPassword.Text & "','" &
txSecques.Text & "','" & txAnswer.Text & "','Inactive')"
dbcom = New MySqlCommand(sql, dbcon)
dbcom.ExecuteNonQuery()
Else
sql = "INSERT INTO tblaccounts (Sidnum, Sfirstname,
Smidname, Slastname, Sacctype, Susername, Spassword, SsecQues, Sanswer,
Sstatus, Sacctimg) VALUES ('" & txIdnum.Text & "','" & txFirstname.Text
& "','" & txMidname.Text & "','" & txLastname.Text & "','" &
txAcctype.Text & "','" & txUsername.Text & "','" & txPassword.Text &
"','" & txSecques.Text & "','" & txAnswer.Text & "','Inactive',@File)"
dbcom = New MySqlCommand
With dbcom
.CommandText = sql
.Connection = dbcon
.Parameters.AddWithValue("@File", arrImage)
.ExecuteNonQuery()
End With
End If
End Sub

STI College Puerto Princesa 60


Private Sub UpdateAccount()
If arrImage Is Nothing Then
sql = "UPDATE tblaccounts SET Sidnum='" & txIdnum.Text &
"',Sfirstname='" & txFirstname.Text & "',Smidname='" & txMidname.Text &
"',Slastname='" & txLastname.Text & "',Sacctype='" & txAcctype.Text &
"',Susername='" & txUsername.Text & "',Spassword='" & txPassword.Text &
"',SsecQues='" & txSecques.Text & "',Sanswer='" & txAnswer.Text & "'
WHERE Sid=" & frmMain.LvwAccounts.FocusedItem.Text
dbcom = New MySqlCommand(sql, dbcon)
dbcom.ExecuteNonQuery()
Else
sql = "UPDATE tblaccounts SET Sidnum='" & txIdnum.Text &
"',Sfirstname='" & txFirstname.Text & "',Smidname='" & txMidname.Text &
"',Slastname='" & txLastname.Text & "',Sacctype='" & txAcctype.Text &
"',Susername='" & txUsername.Text & "',Spassword='" & txPassword.Text &
"',SsecQues='" & txSecques.Text & "',Sanswer='" & txAnswer.Text & "',
Sacctimg=@File WHERE Sid=" & frmMain.LvwAccounts.FocusedItem.Text
dbcom = New MySqlCommand
With dbcom
.CommandText = sql
.Connection = dbcon
.Parameters.AddWithValue("@File", arrImage)
.ExecuteNonQuery()
End With
End If
End Sub

Public Sub SaveImageCapture(ByVal image As System.Drawing.Image)


arrImage = ConvertImage(picAccimg.Image)
End Sub
'image
Private Sub Picover_LoadCompleted(ByVal sender As Object, ByVal e
As System.ComponentModel.AsyncCompletedEventArgs) Handles
picAccimg.LoadCompleted
If loadpic = True Then arrImage = ConvertImage(picAccimg.Image)
End Sub

Private Sub picAccimg_Click(sender As Object, e As EventArgs)


Handles picAccimg.Click
arrImage = Nothing
Dim odlg As New OpenFileDialog()
odlg.FileName = Nothing
odlg.DefaultExt = "Image(.jpg)|*.jpg"
odlg.ShowDialog()
If Not odlg.FileName = Nothing Then
loadpic = True
Me.picAccimg.ImageLocation = odlg.FileName
sLoadImg = odlg.FileName
End If
End Sub

Private Sub CheckBox1_CheckedChanged(sender As Object, e As


EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
txAnswer.PasswordChar = Nothing
Else

STI College Puerto Princesa 61


txAnswer.PasswordChar = "*"
End If
End Sub

Private Sub txIdnum_TextChanged(sender As Object, e As EventArgs)


Handles txIdnum.TextChanged
Check_Duplicate_ID("tblaccounts", "Sidnum", txIdnum)
End Sub

Private Sub btnCancel_Click(sender As Object, e As EventArgs)


Handles btnCancel.Click
Dim msg As New frmCustomMessageBox("Are you sure you want to
cancel?", My.Resources.MsgBoxStyle_Question, "Yes", "No") : Dim result
= msg.ShowDialog()
If result = Windows.Forms.DialogResult.Yes Then
ClearFields(pnlMain) : Me.Hide()
ElseIf result = Windows.Forms.DialogResult.No Then
Me.Show()
Else
Me.Show()
End If
End Sub

Private Sub LblClose_Click(sender As Object, e As EventArgs)


Handles LblClose.Click
Me.Hide()
End Sub
End Class

frmBooks

Imports MySql.Data.MySqlClient

Public Class frmBooks

#Region " Load Event "

Private Sub frmCustomers_Activated(sender As Object, e As


EventArgs) Handles Me.Activated
txBook_accesion_number.Focus()
End Sub

Private Sub frmCustomers_Load(sender As Object, e As EventArgs)


Handles Me.Load
AutoComplete("Book_tittle", "tblbooks", txBook_tittle)
If BookID = Nothing Then
ClearFields(pnlDetails)
ElseIf BookID <> Nothing Then
Fill_Fields_Update()
End If
End Sub

Private Sub Fill_Fields_Update()


On Error Resume Next

STI College Puerto Princesa 62


sql = "SELECT * FROM tblbooks WHERE Book_tittle='" &
BookNameeeeee_ & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader

While dbRead.Read
BookID = dbRead("BookID")
txBook_accesion_number.Text =
dbRead("Book_accesion_number")
txBook_date_recieve.Text = dbRead("Book_date_recieve")
txBook_class.Text = dbRead("Book_class")
txBook_autor.Text = dbRead("Book_autor")
txBook_tittle.Text = dbRead("Book_tittle")
txBook_edition.Text = dbRead("Book_edition")
txBook_volume.Text = dbRead("Book_volume")
txBook_pages.Text = dbRead("Book_pages")
txBook_sourceoffund.Text = dbRead("Book_sourceoffund")
txBook_publisher.Text = dbRead("Book_publisher")
txBook_remarks.Text = dbRead("Book_remarks")
txBook_Quantity.Text = dbRead("Book_Quantity")
cbBook_Section.Text = dbRead("Book_Section")
End While
dbRead.Close()

End Sub

#End Region

#Region " Control Event "

Private Sub btnSubmit_Click(sender As Object, e As EventArgs)


Handles btnSubmit.Click
CheckFields(pnlDetails)

If txBook_accesion_number.BackColor = Color.Red Then


Dim MsgBox_ As New frmCustomMessageBox("Accesion Number
already exist!", My.Resources.MsgBoxStyle_Information, "Ok", "Cancel",
False) : Dim result = MsgBox_.ShowDialog()
Else
If Field_Count = 0 Then

If frmCustomersContainer.Text = "ADD NEW BOOK" Then

If Val(txBook_Quantity.Text) >= 2 Then


Dim x As Integer = Val(txBook_Quantity.Text)

For y = 0 To x - 1
Accession_No_Quantity(txBook_tittle.Text,
txBook_accesion_number, txBook_Quantity)
sql = "INSERT INTO tblbooks (
Book_accesion_number, Book_date_recieve, Book_class, Book_autor,
Book_tittle, Book_edition, Book_volume, Book_pages, Book_sourceoffund,
Book_publisher, Book_remarks, Book_Status, Book_Quantity,
Book_Received_Date, Book_Section ) VALUES ('" & _

txBook_accesion_number.Text & "','" & txBook_date_recieve.Text & "','"


& txBook_class.Text & "','" & txBook_autor.Text & "','" &

STI College Puerto Princesa 63


txBook_tittle.Text & "','" & txBook_edition.Text & "','" &
txBook_volume.Text & "','" & txBook_pages.Text & "','" &
txBook_sourceoffund.Text & "','" & txBook_publisher.Text & "','" &
txBook_remarks.Text & "','Available', '" & txBook_Quantity.Text & "','"
& Format(Date.Now, "yyyy-MM-dd") & "', '" & cbBook_Section.Text & "' )"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()
Next

ElseIf Val(txBook_Quantity.Text) = 1 Then


sql = "INSERT INTO tblbooks (
Book_accesion_number, Book_date_recieve, Book_class, Book_autor,
Book_tittle, Book_edition, Book_volume, Book_pages, Book_sourceoffund,
Book_publisher, Book_remarks, Book_Status, Book_Quantity,
Book_Received_Date, Book_Section ) VALUES ('" & _

txBook_accesion_number.Text & "','" & txBook_date_recieve.Text & "','"


& txBook_class.Text & "','" & txBook_autor.Text & "','" &
txBook_tittle.Text & "','" & txBook_edition.Text & "','" &
txBook_volume.Text & "','" & txBook_pages.Text & "','" &
txBook_sourceoffund.Text & "','" & txBook_publisher.Text & "','" &
txBook_remarks.Text & "','Available', '" & txBook_Quantity.Text & "','"
& Format(Date.Now, "yyyy-MM-dd") & "', '" & cbBook_Section.Text & "' )"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()
End If

Dim MsgBox_ As New frmCustomMessageBox("New Book


has been successfully saved!", My.Resources.MsgBoxStyle_Information,
"Ok", "Cancel", False) : Dim result = MsgBox_.ShowDialog()
LogsHistory("Added New Book - " &
txBook_accesion_number.Text) : ClearFields(pnlDetails)
txBook_accesion_number.Focus() :
LblClose_Click(Nothing, Nothing) : Field_Count = 0

ElseIf frmCustomersContainer.Text = "UPDATE BOOK" Then

If Val(txBook_Quantity.Text) >= 2 Then


Dim x As Integer = Val(txBook_Quantity.Text)

For y = 0 To x - 1
sql = "UPDATE tblbooks SET Book_class='" &
txBook_class.Text & "', Book_autor='" & txBook_autor.Text & "',
Book_tittle='" & txBook_tittle.Text & "', Book_edition='" &
txBook_edition.Text & "', Book_volume='" & txBook_volume.Text & "',
Book_pages='" & txBook_pages.Text & "', Book_sourceoffund='" &
txBook_sourceoffund.Text & "',Book_publisher='" & txBook_publisher.Text
& "',Book_remarks='" & txBook_remarks.Text & "', Book_Quantity='" &
txBook_Quantity.Text & "', Book_Section='" & cbBook_Section.Text & "'
WHERE Book_tittle='" & BookNameeeeee_ & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()
MsgBox(sql)
Next

ElseIf Val(txBook_Quantity.Text) = 1 Then

STI College Puerto Princesa 64


sql = "UPDATE tblbooks SET Book_date_recieve='"
& txBook_date_recieve.Text & "', Book_class='" & txBook_class.Text &
"', Book_autor='" & txBook_autor.Text & "', Book_tittle='" &
txBook_tittle.Text & "', Book_edition='" & txBook_edition.Text & "',
Book_volume='" & txBook_volume.Text & "', Book_pages='" &
txBook_pages.Text & "', Book_sourceoffund='" & txBook_sourceoffund.Text
& "',Book_publisher='" & txBook_publisher.Text & "',Book_remarks='" &
txBook_remarks.Text & "', Book_Quantity='" & txBook_Quantity.Text & "',
Book_Section='" & cbBook_Section.Text & "' WHERE BookID='" & BookID &
"'"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()
End If

Dim MsgBox_ As New frmCustomMessageBox("Book has


been successfully updated!", My.Resources.MsgBoxStyle_Information,
"Ok", "Cancel", False) : Dim result = MsgBox_.ShowDialog()
LogsHistory("Updated a Book - " &
txBook_accesion_number.Text) : ClearFields(pnlDetails)
txBook_accesion_number.Focus() :
LblClose_Click(Nothing, Nothing) : Field_Count = 0

End If

ElseIf Field_Count <> 0 Then


Dim MsgBox_ As New frmCustomMessageBox("Please fill-up
all of the remaining field(s): " & Field_Count & "!",
My.Resources.MsgBoxStyle_Information, "Ok", "Cancel", False) : Dim
result = MsgBox_.ShowDialog()
txBook_accesion_number.Focus() : Field_Count = 0
End If
End If

End Sub

Private Sub frmFMEmployee_FormClosing(sender As Object, e As


FormClosingEventArgs) Handles Me.FormClosing
LblClose_Click(Nothing, Nothing)
End Sub

Private Sub LblClose_Click(sender As Object, e As EventArgs)


Handles LblClose.Click
Me.Hide() : ClearFields(pnlDetails)
End Sub

Private Sub btnCancel_Click(sender As Object, e As EventArgs)


Handles btnCancel.Click
Dim msg As New frmCustomMessageBox("Are you sure you want to
cancel?", My.Resources.MsgBoxStyle_Question, "Yes", "No") : Dim result
= msg.ShowDialog()
If result = Windows.Forms.DialogResult.Yes Then
ClearFields(pnlDetails) : BooksID = Nothing :
txBook_accesion_number.Focus() : Me.Hide()
ElseIf result = Windows.Forms.DialogResult.No Then
Me.Show()
Else

STI College Puerto Princesa 65


Me.Show()
End If
End Sub

Private Sub txBook_accesion_number_Leave(sender As Object, e As


EventArgs) Handles txBook_accesion_number.Leave
ProperCase(txBook_accesion_number)
End Sub

#End Region

Private Sub txBook_accesion_number_TextChanged(sender As Object, e


As EventArgs) Handles txBook_accesion_number.TextChanged
Check_Duplicate_ID("tblbooks", "Book_accesion_number",
txBook_accesion_number)
End Sub

Private Sub txBook_tittle_GotFocus(sender As Object, e As


EventArgs) Handles txBook_tittle.GotFocus, txBook_tittle.Leave,
txBook_tittle.TextChanged
Accession_No(txBook_tittle.Text, txBook_accesion_number,
txBook_Quantity)
End Sub

Private Sub btnBook_Click(sender As Object, e As EventArgs) Handles


btnBook.Click
isBookAvailability = False : frmBooksList.ShowDialog() :
txBook_tittle_GotFocus(Nothing, Nothing)

If BookID <> Nothing Then


Fill_Fields_Books()
End If
End Sub

Private Sub Fill_Fields_Books()


On Error Resume Next

sql = "SELECT * FROM tblbooks WHERE BookID=" & BookID


dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader

While dbRead.Read
BookID = dbRead("BookID")
txBook_accesion_number.Text =
dbRead("Book_accesion_number")
txBook_date_recieve.Text = dbRead("Book_date_recieve")
txBook_class.Text = dbRead("Book_class")
txBook_autor.Text = dbRead("Book_autor")
txBook_tittle.Text = dbRead("Book_tittle")
txBook_edition.Text = dbRead("Book_edition")
txBook_volume.Text = dbRead("Book_volume")
txBook_pages.Text = dbRead("Book_pages")
txBook_sourceoffund.Text = dbRead("Book_sourceoffund")
txBook_publisher.Text = dbRead("Book_publisher")
txBook_remarks.Text = dbRead("Book_remarks")
cbBook_Section.Text = dbRead("Book_Section")
End While

STI College Puerto Princesa 66


dbRead.Close()

End Sub

Private Sub btnClear_Click(sender As Object, e As EventArgs)


Handles btnClear.Click
ClearFields(pnlDetails)
End Sub

End Class

frmBooksList

Imports MySql.Data.MySqlClient

Public Class frmBooksList

#Region " BOOKS LIST "

#Region "Form Load and Search"

Dim xSortx_GuestList As String = "Book_tittle"

Private Sub frmBooksList_Activated(sender As Object, e As


EventArgs) Handles Me.Activated
If isBookAvailability = False Then
LvwBooksList.ContextMenuStrip = Nothing
ElseIf isBookAvailability = True Then
LvwBooksList.ContextMenuStrip = cms_Book
End If
LvwLoad_BooksList()
End Sub

Private Sub LvwLoad_BooksList()


On Error Resume Next
sql = "SELECT * FROM tblbooks WHERE Book_tittle = '" &
BookNameeeeee_ & "' ORDER BY " & xSortx_GuestList & " ASC"

LvwSearch_GuestList()
End Sub

Private Sub LvwSearch_GuestList()


dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader()

LvwBooksList.Items.Clear()
While dbRead.Read
LvwBooksList.Items.Add(dbRead("BookID"))
LvwBooksList.Items(LvwBooksList.Items.Count -
1).SubItems.Add(dbRead("Book_accesion_number"))
LvwBooksList.Items(LvwBooksList.Items.Count -
1).SubItems.Add(dbRead("Book_tittle"))
LvwBooksList.Items(LvwBooksList.Items.Count -
1).SubItems.Add(dbRead("Book_autor"))
LvwBooksList.Items(LvwBooksList.Items.Count -
1).SubItems.Add(dbRead("Book_Status"))

STI College Puerto Princesa 67


End While
dbRead.Close()

Dim Item As ListViewItem


For Each Item In LvwBooksList.Items
Item.UseItemStyleForSubItems = False
If Item.SubItems(4).Text = "Available" Then
Item.SubItems(4).BackColor = Color.FromArgb(53, 203,
103)
Item.SubItems(4).ForeColor = Color.FromArgb(60, 70, 73)
ElseIf Item.SubItems(4).Text = "Borrowed" Then
Item.SubItems(4).BackColor = Color.FromArgb(217, 83,
79)
Item.SubItems(4).ForeColor = Color.White
End If
Next
LvwBooksList.Refresh()

LblRecords_GuestList.Text = "Records Found: " &


LvwBooksList.Items.Count
End Sub

Private Sub btnSearch_GuestList_Click(sender As Object, e As


EventArgs) Handles btnSearch_GuestList.Click
On Error Resume Next
sql = "SELECT * FROM tblbooks WHERE Book_tittle LIKE '%" &
txSearch_GuestList.Text & "%' OR Book_autor LIKE '%" &
txSearch_GuestList.Text & "%' OR Book_class LIKE '%" &
txSearch_GuestList.Text & "%' ORDER BY " & xSortx_GuestList & " AND
Book_Status = 'Available' ASC"
LvwSearch_GuestList()
End Sub

Private Sub btnShowAll_GuestList_Click(sender As Object, e As


EventArgs) Handles btnShowAll_GuestList.Click
LvwLoad_BooksList() : ClearText_GuestList()
End Sub

Private Sub txSearch_GuestList_KeyPress(sender As Object, e As


KeyPressEventArgs) Handles txSearch_GuestList.KeyPress
If e.KeyChar = Chr(13) Then
btnSearch_GuestList_Click(Nothing, Nothing)
End If
End Sub

#End Region

#Region "Lisview Click"

Private Sub tsmRefresh_Supplier_Click(sender As Object, e As


EventArgs) Handles tsmRefresh_Supplier.Click
LvwLoad_BooksList() : ClearFields(pnlMain) : BookID = Nothing
End Sub

Private Sub LvwGuestList_Click(sender As Object, e As EventArgs)


Handles LvwBooksList.Click
BookID = LvwBooksList.FocusedItem.Text

STI College Puerto Princesa 68


isBorrowed = LvwBooksList.FocusedItem.SubItems(4).Text
End Sub

Private Sub LvwGuestList_DoubleClick(sender As Object, e As


EventArgs) Handles LvwBooksList.DoubleClick
isBookAvailability = False : Me.Hide() : ClearFields(pnlMain)
End Sub

Private Sub ClearText_GuestList()


txSearch_GuestList.Clear()
End Sub

Private Sub LblClose_Click(sender As Object, e As EventArgs)


Handles LblClose.Click
Me.Hide() : ClearFields(pnlMain) : BookID = Nothing :
isBookAvailability = False
End Sub

#End Region

#End Region

Private Sub tsmBorrowBook_Click(sender As Object, e As EventArgs)


Handles tsmBorrowBook.Click
If isBorrowed = "Available" Then
If BookID <> Nothing Then
Me.Hide() : frmBooksTransaction.ShowDialog() :
Books_Status() : tsmRefresh_Supplier_Click(Nothing, Nothing)
Else
Dim MsgBox_ As New frmCustomMessageBox("Please choose a
book first.", My.Resources.MsgBoxStyle_Information, "Ok", "Cancel",
False) : Dim result = MsgBox_.ShowDialog()
End If
ElseIf isBorrowed = "Borrowed" Then
Dim MsgBox_ As New frmCustomMessageBox("Books Status is
still Borrowed.", My.Resources.MsgBoxStyle_Information, "Ok", "Cancel",
False) : Dim result = MsgBox_.ShowDialog()
End If

End Sub

End Class

frmBooksTransaction

Imports MySql.Data.MySqlClient

Public Class frmBooksTransaction

#Region " Load Event "

Private Sub frmCustomers_Activated(sender As Object, e As


EventArgs) Handles Me.Activated
txBook_accesion_number.Focus()
End Sub

STI College Puerto Princesa 69


Private Sub frmCustomers_Load(sender As Object, e As EventArgs)
Handles Me.Load
Dim srcCheckout As Date = dtpBorrowDate.Value
dtpReturnDate.Value = srcCheckout.AddDays(1)
If BookID = Nothing Then
ClearFields(pnlDetails) : Clear_All()
ElseIf BookID <> Nothing Then
Fill_Fields_Books()
End If
End Sub

Private Sub Fill_Fields_Books()


On Error Resume Next

sql = "SELECT * FROM tblbooks WHERE BookID = '" & BookID & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader

While dbRead.Read
BookID = dbRead("BookID")
txBook_accesion_number.Text =
dbRead("Book_accesion_number")
txBook_date_recieve.Text = dbRead("Book_date_recieve")
txBook_class.Text = dbRead("Book_class")
txBook_autor.Text = dbRead("Book_autor")
txBook_tittle.Text = dbRead("Book_tittle")
txBook_edition.Text = dbRead("Book_edition")
txBook_volume.Text = dbRead("Book_volume")
txBook_pages.Text = dbRead("Book_pages")
txBook_sourceoffund.Text = dbRead("Book_sourceoffund")
txBook_publisher.Text = dbRead("Book_publisher")
txBook_remarks.Text = dbRead("Book_remarks")
End While
dbRead.Close()

End Sub

Private Sub Fill_Fields_Student()


On Error Resume Next

sql = "SELECT * FROM tblstudent WHERE Sid=" & StudentID


dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader

While dbRead.Read
txIDnum.Text = dbRead("Sidnum")
txFullname.Text = dbRead("Sfname") & " " &
dbRead("Slastname")
txCourse.Text = dbRead("Scourse")
txYrlvl.Text = dbRead("Syrlvl")
txFname.Text = dbRead("Sfname")
txMname.Text = dbRead("Smidname")
txLname.Text = dbRead("Slastname")
txAddress.Text = dbRead("Saddress")
txDateofb.Text = dbRead("Sdateofb")
txPlaceofb.Text = dbRead("Splaceofb")

STI College Puerto Princesa 70


txContnum.Text = dbRead("Scontnum")
End While
dbRead.Close()

End Sub

#End Region

#Region " Control Event "

Private Sub btnSubmit_Click(sender As Object, e As EventArgs)


Handles btnSubmit.Click
CheckFields(pnlDetails)

Dim Still_Exist_Today As String = Nothing

sql = "SELECT StudentID FROM tblbookstransaction WHERE


TransStatus ='Borrowed' and StudentID ='" & txIDnum.Text & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader()
While dbRead.Read
Still_Exist_Today = dbRead("StudentID")
End While
dbRead.Close()

If Still_Exist_Today = txIDnum.Text Then


Dim MsgBox_ As New frmCustomMessageBox("You still havent
returned the book that you borrowed last time.",
My.Resources.MsgBoxStyle_Information, "Ok", "Cancel", False) : Dim
result = MsgBox_.ShowDialog()
Else
If Field_Count = 0 Then

If frmBorrowContainer.Text = "BOOK BORROWING DETAILS"


Then

sql = "INSERT INTO tblBooksTransaction ( StudentID,


StudentName, BookID, Borrowed_Title, Borrowed_Type, Borrowed_Date,
ExpectedReturn_Date, Penalty, PenaltyAmount, PenaltyPaid,
PenaltyRemaining, SMS_Notified, Date_Returned, TransStatus,
Transaction_Date ) VALUES ('" & _

txIDnum.Text & "','" & txFullname.Text & "','" & BookID & "','" &
txBook_tittle.Text & "','" & txBook_class.Text & "','" &
dtpBorrowDate.Text & "','" & dtpReturnDate.Text &
"','No','0','0','0','N/A','N/A','Borrowed','" & Format(Date.Now, "yyyy-
MM-dd") & "')"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()

sql = "UPDATE tblbooks SET Book_Status='Borrowed'


WHERE Book_accesion_number='" & txBook_accesion_number.Text & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()

Dim MsgBox_ As New frmCustomMessageBox("Book has


been successfully lent to " & txFullname.Text & ".",

STI College Puerto Princesa 71


My.Resources.MsgBoxStyle_Information, "Ok", "Cancel", False) : Dim
result = MsgBox_.ShowDialog()
LogsHistory("Lent a Book to - " & txFullname.Text)
: ClearFields(pnlDetails) : Clear_All()
frmMain.tsmRefresh_Borrowed_Click(Nothing, Nothing)
: frmMain.tsmRefresh_Supplier_Click(Nothing, Nothing)
txBook_accesion_number.Focus() :
LblClose_Click(Nothing, Nothing) : Field_Count = 0

End If

ElseIf Field_Count <> 0 Then


Dim MsgBox_ As New frmCustomMessageBox("Please fill-up
all of the remaining field(s): " & Field_Count & "!",
My.Resources.MsgBoxStyle_Information, "Ok", "Cancel", False) : Dim
result = MsgBox_.ShowDialog()
txBook_accesion_number.Focus() : Field_Count = 0
End If
End If

End Sub

Private Sub frmFMEmployee_FormClosing(sender As Object, e As


FormClosingEventArgs) Handles Me.FormClosing
LblClose_Click(Nothing, Nothing)
End Sub

Private Sub LblClose_Click(sender As Object, e As EventArgs)


Handles LblClose.Click
Me.Hide() : ClearFields(pnlDetails) : Clear_All()
End Sub

Private Sub btnCancel_Click(sender As Object, e As EventArgs)


Handles btnCancel.Click
Dim msg As New frmCustomMessageBox("Are you sure you want to
cancel?", My.Resources.MsgBoxStyle_Question, "Yes", "No") : Dim result
= msg.ShowDialog()
If result = Windows.Forms.DialogResult.Yes Then
ClearFields(pnlDetails) : Clear_All() : BooksID = Nothing :
txBook_accesion_number.Focus() : Me.Hide()
ElseIf result = Windows.Forms.DialogResult.No Then
Me.Show()
Else
Me.Show()
End If
End Sub

Private Sub Clear_All()


txBook_accesion_number.Text = Nothing
txBook_date_recieve.Text = Nothing
txBook_class.Text = Nothing
txBook_autor.Text = Nothing
txBook_tittle.Text = Nothing
txBook_edition.Text = Nothing
txBook_volume.Text = Nothing
txBook_pages.Text = Nothing

STI College Puerto Princesa 72


txBook_sourceoffund.Text = Nothing
txBook_publisher.Text = Nothing
txBook_remarks.Text = Nothing

txIDnum.Text = Nothing
txFullname.Text = Nothing
txCourse.Text = Nothing
txYrlvl.Text = Nothing
txFname.Text = Nothing
txMname.Text = Nothing
txLname.Text = Nothing
txAddress.Text = Nothing
txDateofb.Text = Nothing
txPlaceofb.Text = Nothing
txContnum.Text = Nothing
End Sub

Private Sub txBook_accesion_number_Leave(sender As Object, e As


EventArgs) Handles txBook_accesion_number.Leave
ProperCase(txBook_accesion_number)
End Sub

Private Sub dtpBorrowDate_ValueChanged(sender As Object, e As


EventArgs) Handles dtpBorrowDate.ValueChanged
Dim srcCheckout As Date = dtpBorrowDate.Value
dtpReturnDate.Value = srcCheckout.AddDays(1)
End Sub

Private Sub btnStudent_Click(sender As Object, e As EventArgs)


Handles btnStudent.Click
frmStudentsList.ShowDialog() : Fill_Fields_Student()
End Sub

Private Sub btnBook_Click(sender As Object, e As EventArgs) Handles


btnBook.Click
isBookAvailability = False : frmBooksList.ShowDialog() :
Fill_Fields_Books()
End Sub

#End Region

End Class

frmCustomMessageBox

Public Class frmCustomMessageBox

Public Sub New(ByVal MsgBox_ As String, ByVal MsgIcon_ As Object,


ByVal btnYes_ As String, ByVal btnNo_ As String, Optional ByVal
Condition_ As Boolean = True)

InitializeComponent()

LblMessage.Text = MsgBox_
LblIcon.Image = MsgIcon_

STI College Puerto Princesa 73


btnYes.Text = btnYes_
btnNo.Text = btnNo_
DialogResult = Windows.Forms.DialogResult.Cancel

If Condition_ = True Then


btnYes.Location = New Point(116, 129)
btnNo.Location = New Point(228, 129)
btnNo.Visible = True
Else
btnYes.Location = New Point(149, 129)
btnNo.Visible = False
End If
End Sub

Private Sub frmCustomMessageBox_KeyDown(ByVal sender As Object,


ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Escape Then
LblClose_Click(Nothing, Nothing)
End If
End Sub

Private Sub btnYes_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnYes.Click
DialogResult = Windows.Forms.DialogResult.Yes : Close()
End Sub

Private Sub btnNo_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnNo.Click
DialogResult = Windows.Forms.DialogResult.No : Close()
End Sub

Private Sub frmCustomMessageBox_Load(sender As Object, e As


EventArgs) Handles Me.Load
btnYes.Focus()
End Sub

Private Sub frmCustomMessageBox_LostFocus(sender As Object, e As


EventArgs) Handles Me.LostFocus
Me.Focus()
End Sub

Private Sub LblClose_Click(sender As Object, e As EventArgs)


Handles LblClose.Click
Close()
End Sub

Private Sub frmCustomMessageBox_Shown(sender As Object, e As


EventArgs) Handles Me.Shown
Beep()
End Sub

End Class

frmHolidays

Imports MySql.Data.MySqlClient

STI College Puerto Princesa 74


Public Class frmHolidays

#Region " Load Event "

Private Sub frmCustomers_Activated(sender As Object, e As


EventArgs) Handles Me.Activated
txHoliday.Focus()
End Sub

Private Sub frmCustomers_Load(sender As Object, e As EventArgs)


Handles Me.Load
If HolidayID = Nothing Then
ClearFields(pnlDetails)
ElseIf HolidayID <> Nothing Then
Fill_Fields_Update()
End If
End Sub

Private Sub Fill_Fields_Update()


On Error Resume Next

sql = "SELECT * FROM tblholidays WHERE HolidayID='" & HolidayID


& "'"
dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader

While dbRead.Read
dtpDate.Text = dbRead("HolidayDate")
txHoliday.Text = dbRead("HolidayName")
txReason.Text = dbRead("HolidayReason")
End While
dbRead.Close()

End Sub

#End Region

#Region " Control Event "

Private Sub btnSubmit_Click(sender As Object, e As EventArgs)


Handles btnSubmit.Click
CheckFields(pnlDetails)

If Field_Count = 0 Then
If frmTitle.Text = "ADD NEW HOLIDAY" Then
sql = "INSERT INTO tblholidays ( HolidayName,
HolidayDate, HolidayReason, File_By, File_Date, File_Year ) VALUES ('"
& _
txHoliday.Text & "','" &
Format(dtpDate.Value, "yyyy-MM-dd") & "','" & txReason.Text & "','" &
xFullName & "','" & Format(Date.Now, "yyyy-MM-dd") & "','" &
Format(Date.Now, "yyyy") & "' )"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()

STI College Puerto Princesa 75


Dim MsgBox_ As New frmCustomMessageBox("Holiday has
been successfully saved!", My.Resources.MsgBoxStyle_Information, "Ok",
"Cancel", False) : Dim result = MsgBox_.ShowDialog()
LogsHistory("Added a Holiday - " & txHoliday.Text) :
ClearFields(pnlDetails)
txHoliday.Focus() : LblClose_Click(Nothing, Nothing) :
Field_Count = 0 :
BookingTransaction_and_RoomStatus(frmMain.CalBookingTransaction)
ElseIf frmTitle.Text = "UPDATE HOLIDAY" Then
sql = "UPDATE tblholidays SET HolidayName='" &
txHoliday.Text & "', HolidayDate='" & Format(dtpDate.Value, "yyyy-MM-
dd") & "', HolidayReason='" & txReason.Text & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()

Dim MsgBox_ As New frmCustomMessageBox("Holiday has


been successfully updated!", My.Resources.MsgBoxStyle_Information,
"Ok", "Cancel", False) : Dim result = MsgBox_.ShowDialog()
LogsHistory("Updated a Holiday - " & txHoliday.Text) :
ClearFields(pnlDetails)
txHoliday.Focus() : LblClose_Click(Nothing, Nothing) :
Field_Count = 0 :
BookingTransaction_and_RoomStatus(frmMain.CalBookingTransaction)
End If

ElseIf Field_Count <> 0 Then


Dim MsgBox_ As New frmCustomMessageBox("Please fill-up all
of the remaining field(s): " & Field_Count & "!",
My.Resources.MsgBoxStyle_Information, "Ok", "Cancel", False) : Dim
result = MsgBox_.ShowDialog()
txHoliday.Focus() : Field_Count = 0
End If
End Sub

Private Sub frmFMEmployee_FormClosing(sender As Object, e As


FormClosingEventArgs) Handles Me.FormClosing
LblClose_Click(Nothing, Nothing)
End Sub

Private Sub LblClose_Click(sender As Object, e As EventArgs)


Handles LblClose.Click
Me.Hide() : ClearFields(pnlDetails)
End Sub

Private Sub btnCancel_Click(sender As Object, e As EventArgs)


Handles btnCancel.Click
Dim msg As New frmCustomMessageBox("Are you sure you want to
cancel?", My.Resources.MsgBoxStyle_Question, "Yes", "No") : Dim result
= msg.ShowDialog()
If result = Windows.Forms.DialogResult.Yes Then
ClearFields(pnlDetails) : BooksID = Nothing : Me.Hide()
ElseIf result = Windows.Forms.DialogResult.No Then
Me.Show()
Else
Me.Show()
End If

STI College Puerto Princesa 76


End Sub

#End Region

End Class

frmHolidaysList

Public Class frmHolidaysList

Private Sub frmBookingCalendar_FormClosing(sender As Object, e As


FormClosingEventArgs) Handles Me.FormClosing
Me.Hide()
End Sub

Private Sub LvwAppointment_KeyPress(sender As Object, e As


KeyPressEventArgs) Handles LvwGuestTransactions.KeyPress
If e.KeyChar = Chr(27) Then
Me.Close() : Appointed_dateBold = False
End If
End Sub

Private Sub LblClose_Click(sender As Object, e As EventArgs)


Handles LblClose.Click
Me.Close() : Appointed_dateBold = False
End Sub

End Class

frmLogin

Public Class frmLogin

Private Sub btnLogin_Click(sender As Object, e As EventArgs)


Handles btnLogin.Click
Dim x As String = Nothing
'x = TimeDiff(DateTimePicker1.Value, DateTimePicker2.Value)
'MsgBox(x)

'Dim day As String = Format(Today, "dddd")


'Dim time As Date
'Dim CurrHour As Integer
'Dim CurrMinute As Integer
'time = DateTime.Now
'CurrHour = time.Hour ' Get current hour value
'CurrMinute = time.Minute ' Get current minute value

'If CurrHour <= 14 AndAlso CurrMinute <= 55 Then


' MsgBox("£4.50 Please")
'ElseIf CurrHour >= 14 AndAlso CurrMinute >= 56 Then
' MsgBox("Coffee Morning:" & vbCr & "£3.00 Please")
'End If
MsgBox(DateTimePicker1.Value)
Dim countsun As Integer = 0
Dim countsat As Integer = 0

STI College Puerto Princesa 77


Dim NonHoliday As Integer
Dim TotalDay As String
TotalDay = DateDiff("d", DateTimePicker1.Value,
DateTimePicker2.Value)
For i As Integer = 0 To TotalDay
Dim Weekday As DayOfWeek =
DateTimePicker1.Value.AddDays(i).DayOfWeek
If Weekday = DayOfWeek.Saturday Then
countsat += 1
End If
If Weekday = DayOfWeek.Sunday Then
countsun += 1
End If
If Weekday <> DayOfWeek.Saturday AndAlso Weekday <>
DayOfWeek.Sunday Then
NonHoliday += 1
End If
Next
'Insert another query for Holidays
LblSaturday.Text = countsat & " Day(s)"
LblSunday.Text = countsun & " Day(s)"
LblHoliday.Text = countsat + countsun & " Day(s)"
LblNonHoliday.Text = NonHoliday & " Day(s)"
LblTotalDays.Text = TotalDay & " Day(s)"

End Sub

Private Function TimeDiff(Time1 As String, Time2 As String) As


String
Dim MinsDiff As String
Dim TheHours As String
MinsDiff = DateDiff("n", Time1, Time2)

MinsDiff = IIf(MinsDiff < 0, MinsDiff + 1440, MinsDiff)


TheHours = Format(Int(MinsDiff / 60), "00")
MinsDiff = Format(MinsDiff Mod 60, "00")
TimeDiff = TheHours & ":" & MinsDiff
End Function

Private Sub DateTimePicker1_ValueChanged(sender As Object, e As


EventArgs) Handles DateTimePicker1.ValueChanged
Dim srcCheckout As Date = DateTimePicker1.Value
DateTimePicker2.Value = srcCheckout.AddDays(1)
End Sub

End Class

frmMain

Imports MySql.Data.MySqlClient

Public Class frmMain

#Region " Login "

STI College Puerto Princesa 78


#Region " WaterMark "

Private Sub frmLogin_Load(sender As Object, e As EventArgs) Handles


Me.Load
dbCheck()
BookingTransaction_and_RoomStatus(CalBookingTransaction)
Watermark(txUsername, "Username", False) :
Watermark(txPassword, "Password", True)
End Sub

Private Sub txUsername_Enter(sender As Object, e As EventArgs)


Handles txUsername.Enter
WaterMark_Enter(txUsername, "Username", Color.Black)
End Sub

Private Sub txUsername_Leave(sender As Object, e As EventArgs)


Handles txUsername.Leave
WaterMark_Leave(txUsername, "Username", False)
End Sub

Private Sub txPassword_Enter(sender As Object, e As EventArgs)


Handles txPassword.Enter
If txPassword.Text = "Password" Then
txPassword.Text = "" : txPassword.PasswordChar = "*" :
txPassword.ForeColor = Color.Black
End If
End Sub

Private Sub txPassword_Leave(sender As Object, e As EventArgs)


Handles txPassword.Leave
If txPassword.Text = "" Then
Watermark(txPassword, "Password", True)
End If
End Sub

#End Region

#Region " Login Function "

Private Sub txUsername_TextChanged(sender As Object, e As


EventArgs) Handles txUsername.TextChanged
On Error GoTo heLL

sql = "SELECT * FROM tblAccounts WHERE Susername='" &


txUsername.Text & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader()

While dbRead.Read
xUsername = dbRead("Susername")
End While
dbRead.Close()

If xUsername = Nothing Then


GoTo heLL
ElseIf txUsername.Text = xUsername Then
txUsername.BackColor = Color.LightYellow

STI College Puerto Princesa 79


Else
heLL: txUsername.BackColor = Color.White
End If
End Sub

Private Sub txPassword_KeyPress(ByVal sender As Object, ByVal e As


KeyPressEventArgs) Handles txPassword.KeyPress
If e.KeyChar = Chr(13) Then
btnLogin_Click(Nothing, Nothing)
End If
End Sub

Private Sub btnLogin_Click(sender As Object, e As EventArgs)


Handles btnLogin.Click
sql = "SELECT * FROM tblAccounts WHERE Susername='" &
txUsername.Text & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader()

While dbRead.Read
SystemUserID = dbRead("Sid")
xFullName = dbRead("Sfirstname") & " " &
dbRead("Slastname") : xPosition = dbRead("Sacctype")
xPassword = dbRead("Spassword") : xAcctStatus =
dbRead("Sstatus") : AcctID = dbRead("Sid")
xAcctLastLog = dbRead("Slastlogin")
End While
dbRead.Close()

If txUsername.Text = Nothing Or txUsername.Text = "" Then


GoTo Prompt
ElseIf txUsername.Text = xUsername Then
If txPassword.Text = xPassword Then
If xPosition = "Administrator" Then
'With frmMain
pnlImageSystem.Visible = False
pnlLogin.Visible = False
xLogin() : AcctLastLog()
frmSMS.Configure_SMS_Notification() :
Books_Status()
tsbBorrowed_Click(Nothing, Nothing)
tabRecords.SelectedIndex = 0 : LvwLoad_Borrowed() :
ClearText_Borrowed()
GoTo frmLst
Else
MsgBox("Due to accounts restriction, you dont have
an access to the Server System.", 64, "Server System") : GoTo frmLst
End If
Else
GoTo Prompt
End If
End If

Prompt: Dim MsgBox_ As New frmCustomMessageBox("The Username or


Password that you have entered was incorrect!",
My.Resources.MsgBoxStyle_Warning, "Ok", "Cancel", False) : Dim
MsgResult = MsgBox_.ShowDialog()

STI College Puerto Princesa 80


frmLst:
txUsername.Text = Nothing : txPassword.Text = Nothing :
txUsername.Focus()

End Sub

#End Region

#Region " Password Recovery "

Private Sub LblForgotPass_Click(sender As Object, e As EventArgs)


Handles LblForgotPass.Click
frmPassRecovery.Show() : Me.Hide() : txUsername.Focus()
End Sub

Private Sub LblForgotPass_MouseHover(sender As Object, e As


EventArgs) Handles LblForgotPass.MouseHover
LblForgotPass.ForeColor = Color.FromArgb(23, 160, 94)
End Sub

Private Sub LblForgotPass_MouseLeave(sender As Object, e As


EventArgs) Handles LblForgotPass.MouseLeave
LblForgotPass.ForeColor = Color.White
End Sub

#End Region

#End Region

#Region " SETTINGS "

Private Sub tsmYear_Sem_Click(sender As Object, e As EventArgs)


Handles tsmYear_Sem.Click
frmYear_Semester.ShowDialog()
End Sub

Private Sub tsmConsumableTime_Click(sender As Object, e As


EventArgs) Handles tsmConsumableTime.Click
frmConsumables.ShowDialog()
End Sub

Private Sub tsmBackup_Click(sender As Object, e As EventArgs)


Handles tsmBackup.Click
xDatabaseNotex = "BackUp"
Dim xdlgFilex As New SaveFileDialog()
xdlgFilex.Filter = "SQL Backup Files|*.sql|All Files(*.*)|*.*"
xdlgFilex.FileName = "dbLibrarySystem Backup (" &
Format(Date.Now, "MMM dd, yyyy - hh mm tt ") & ")"

BackUp_Restore(xdlgFilex, "mysqldump", "-r")


End Sub

Private Sub tsmRestore_Click(sender As Object, e As EventArgs)


Handles tsmRestore.Click
xDatabaseNotex = "Restore"
Dim xdlgFilex As New OpenFileDialog()

STI College Puerto Princesa 81


xdlgFilex.Filter = "SQL Files|*.sql|All Files(*.*)|*.*"

BackUp_Restore(xdlgFilex, "mysql", "<")


End Sub

Private Sub tsmAbout_Click(sender As Object, e As EventArgs)


Handles tsmAbout.Click
frmAbout.ShowDialog()
End Sub

Private Sub LblClose_Click(sender As Object, e As EventArgs)


Handles LblClose.Click
Dim msg As New frmCustomMessageBox("Are you sure you want to
Logout?", My.Resources.MsgBoxStyle_Question, "Yes", "No") : Dim result
= msg.ShowDialog()
If result = Windows.Forms.DialogResult.Yes Then
pnlImageSystem.Visible = True
pnlLogin.Visible = True
txUsername.Focus()
ElseIf result = Windows.Forms.DialogResult.No Then
Me.Show()
Else
Me.Show()
End If
End Sub

#End Region

#Region " BORROWED BOOKS "

#Region "Form Load and Search"

Dim xSortx_Borrowed As String = "TransactionID"

Private Sub tsbBorrowed_Click(sender As Object, e As EventArgs)


Handles tsbBorrowed.Click
tabRecords.SelectedIndex = 0 : LvwLoad_Borrowed() :
ClearText_Borrowed()
End Sub

Public Sub LvwLoad_Borrowed()


'On Error Resume Next
sql = " SELECT *, BookID AS Book_ID_, (SELECT
Book_accesion_number FROM tblbooks WHERE BookID=Book_ID_) as
Accession_No " & _
" FROM tblbookstransaction WHERE TransStatus='Borrowed'
ORDER BY " & xSortx_Borrowed & " ASC"
LvwSearch_Borrowed()
End Sub

Private Sub LvwSearch_Borrowed()

'Dim DateTimePicker1 As New DateTimePicker, DateTimePicker2 As


New DateTimePicker, Expected__return As New DateTimePicker
'Dim DateBorrowed As String = 0, DateNow As String = 0
'Dim HolidayDays As Integer = 0

STI College Puerto Princesa 82


'DateNow = Format(Date.Now, "yyyy-MM-dd")

'sql = "SELECT TransactionID as TransID, (SELECT


Transaction_Date FROM tblbookstransaction WHERE TransactionID=TransID)
FROM tblbookstransaction"
'dbCom = New MySqlCommand(sql, dbCon)
'dbRead = dbCom.ExecuteReader

'While dbRead.Read
' DateBorrowed = Format(dbRead(1), "yyyy-MM-dd")
'End While
'dbRead.Close()

'DateTimePicker1.Text = DateBorrowed
'DateTimePicker2.Text = DateNow

'sql = "SELECT COUNT(HolidayID) FROM tblholidays WHERE


HolidayDate BETWEEN '" & DateBorrowed & "' AND '" & DateNow & "'"
'dbCom = New MySqlCommand(sql, dbCon)
'dbRead = dbCom.ExecuteReader

'While dbRead.Read
' HolidayDays = dbRead(0)
'End While
'dbRead.Close()

dbCom = New MySqlCommand(sql, dbCon)


dbRead = dbCom.ExecuteReader()
LvwBorrowed.Items.Clear()
While dbRead.Read
LvwBorrowed.Items.Add(dbRead("TransactionID"))
LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add(dbRead("Accession_No"))
LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add(dbRead("Borrowed_Title"))
LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add(dbRead("Borrowed_Type"))
LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add(dbRead("StudentName"))
LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add(dbRead("Borrowed_Date"))
LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add(dbRead("ExpectedReturn_Date"))

'Dim Total_Penalty As Integer = 0


'Dim countsun As Integer = 0
'Dim countsat As Integer = 0
'Dim NonHoliday As Integer
'Dim TotalDay As String
'TotalDay = DateDiff("d", DateTimePicker1.Value,
DateTimePicker2.Value)
'For i As Integer = 0 To TotalDay
' Dim Weekday As DayOfWeek =
DateTimePicker1.Value.AddDays(i).DayOfWeek
' If Weekday = DayOfWeek.Saturday Then
' countsat += 1

STI College Puerto Princesa 83


' End If
' If Weekday = DayOfWeek.Sunday Then
' countsun += 1
' End If
' If Weekday <> DayOfWeek.Saturday AndAlso Weekday <>
DayOfWeek.Sunday Then
' NonHoliday += 1
' End If
'Next

'Total_Penalty = NonHoliday - HolidayDays

'Dim srcCheckout As Date = DateTimePicker1.Value


'Expected__return.Value = srcCheckout.AddDays(1)

'If Total_Penalty <= 1 Then


LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add(dbRead("Penalty"))
LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add(dbRead("PenaltyAmount"))
'ElseIf Total_Penalty >= 2 Then
' Dim panelty_Amount As Integer, Penalty_Days As Integer
' panelty_Amount = (Total_Penalty - 1) * 5
' Penalty_Days = Total_Penalty - 1
' LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add("Yes")
' LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add(Format(CDbl(panelty_Amount), "#,##0.00"))
'End If

LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add(dbRead("PenaltyPaid"))
LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add(dbRead("PenaltyRemaining"))
LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add(dbRead("Date_Returned"))
LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add(dbRead("TransStatus"))
LvwBorrowed.Items(LvwBorrowed.Items.Count -
1).SubItems.Add(dbRead("BookID"))
End While
dbRead.Close()
LvwColor(LvwBorrowed) : LblRecords_Borrowed.Text = " BORROWED
RECORDS FOUND: " & LvwBorrowed.Items.Count
End Sub

Private Sub btnSearch_Borrowed_Click(sender As Object, e As


EventArgs) Handles btnSearch_Borrowed.Click
On Error Resume Next
If cbBorrowed.Text = "Book Name" Then
sql = "SELECT *, BookID AS Book_ID_, (SELECT
Book_accesion_number FROM tblbooks WHERE BookID=Book_ID_) as
Accession_No FROM tblbookstransaction WHERE Borrowed_Title LIKE '%" &
txSearch_Borrowed.Text & "%' AND TransStatus='Borrowed' ORDER BY " &
xSortx_Borrowed & " ASC"
ElseIf cbBorrowed.Text = "Book Type" Then

STI College Puerto Princesa 84


sql = "SELECT *, BookID AS Book_ID_, (SELECT
Book_accesion_number FROM tblbooks WHERE BookID=Book_ID_) as
Accession_No FROM tblbookstransaction WHERE Borrowed_Type LIKE '%" &
txSearch_Borrowed.Text & "%' AND TransStatus='Borrowed' ORDER BY " &
xSortx_Borrowed & " ASC"
ElseIf cbBorrowed.Text = "Student Name" Then
sql = "SELECT *, BookID AS Book_ID_, (SELECT
Book_accesion_number FROM tblbooks WHERE BookID=Book_ID_) as
Accession_No FROM tblbookstransaction WHERE StudentName LIKE '%" &
txSearch_Borrowed.Text & "%' AND TransStatus='Borrowed' ORDER BY " &
xSortx_Borrowed & " ASC"
ElseIf cbBorrowed.Text = "Borrowed Date" Then
sql = "SELECT *, BookID AS Book_ID_, (SELECT
Book_accesion_number FROM tblbooks WHERE BookID=Book_ID_) as
Accession_No FROM tblbookstransaction WHERE Borrowed_Date LIKE '%" &
txSearch_Borrowed.Text & "%' AND TransStatus='Borrowed' ORDER BY " &
xSortx_Borrowed & " ASC"
Else
sql = "SELECT *, BookID AS Book_ID_, (SELECT
Book_accesion_number FROM tblbooks WHERE BookID=Book_ID_) as
Accession_No FROM tblbookstransaction WHERE Borrowed_Title LIKE '%" &
txSearch_Borrowed.Text & "%' AND TransStatus='Borrowed' ORDER BY " &
xSortx_Borrowed & " ASC"
End If
LvwSearch_Borrowed()
End Sub

Private Sub btnShowAll_Borrowed_Click(sender As Object, e As


EventArgs) Handles btnShowAll_Borrowed.Click
LvwLoad_Borrowed() : ClearText_Borrowed()
End Sub

Private Sub txSearch_Borrowed_KeyPress(sender As Object, e As


KeyPressEventArgs) Handles txSearch_Borrowed.KeyPress
If e.KeyChar = Chr(13) Then
btnSearch_Borrowed_Click(Nothing, Nothing)
End If
End Sub

#End Region

#Region "Lisview Click"

Private Sub LvwBorrowed_Click(sender As Object, e As EventArgs)


Handles LvwBorrowed.Click
TransactionID = LvwBorrowed.FocusedItem.Text
Return_BookID = LvwBorrowed.FocusedItem.SubItems(13).Text
End Sub

#End Region

#Region "ToolStrip Menu"

Private Sub tstsmNew_Borrowed_Click(sender As Object, e As


EventArgs)
StudentID = Nothing
Dim frmRegistration As New frmRegistration

STI College Puerto Princesa 85


With frmRegistration
.ShowDialog() : Books_Status()
End With
tsmRefresh_Borrowed_Click(Nothing, Nothing) : Books_Status()
End Sub

Private Sub tsmUpdate_Borrowed_Click(sender As Object, e As


EventArgs)
frmRegistration.LoadEdit() : frmRegistration.ShowDialog() :
Books_Status()
'If StudentID = Nothing Then
' Dim MsgBox_ As New frmCustomMessageBox("Please choose a
record.", My.Resources.MsgBoxStyle_Information, "Ok", "Cancel", False)
: Dim result = MsgBox_.ShowDialog()
'Else
' If LvwBorrowed.FocusedItem.Text = Nothing Or
LvwBorrowed.FocusedItem.Text = "" Then Exit Sub
' If StudentID <> Nothing Or StudentID <> "" Then
' Dim frmRegistration As New frmRegistration
' With frmRegistration
' .ShowDialog()
' End With
' End If
' tsmRefresh_Borrowed_Click(Nothing, Nothing)
'End If
End Sub

Public Sub tsmRefresh_Borrowed_Click(sender As Object, e As


EventArgs) Handles tsmRefresh_Borrowed.Click
LvwLoad_Borrowed() : ClearText_Borrowed() : StudentID = Nothing
: Books_Status()
End Sub

Private Sub tsmSort_Borrowed_Name_Click(sender As Object, e As


EventArgs) Handles tsmSort_Borrowed_Name.Click
xDisable_Borrowed(tsmSort_Borrowed) :
tsmSort_Borrowed_Name.Checked = True : xSortx_Borrowed =
"Borrowed_Title" : btnShowAll_Borrowed_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Borrowed_Contact_Click(sender As Object, e As


EventArgs) Handles tsmSort_Borrowed_Contact.Click
xDisable_Borrowed(tsmSort_Borrowed) :
tsmSort_Borrowed_Contact.Checked = True : xSortx_Borrowed =
"Borrowed_Type" : btnShowAll_Borrowed_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Borrowed_Email_Click(sender As Object, e As


EventArgs) Handles tsmSort_Borrowed_Email.Click
xDisable_Borrowed(tsmSort_Borrowed) :
tsmSort_Borrowed_Email.Checked = True : xSortx_Borrowed = "StudentName"
: btnShowAll_Borrowed_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Borrowed_Address_Click(sender As Object, e As


EventArgs) Handles tsmSort_Borrowed_Address.Click

STI College Puerto Princesa 86


xDisable_Borrowed(tsmSort_Borrowed) :
tsmSort_Borrowed_Address.Checked = True : xSortx_Borrowed =
"Borrowed_Date" : btnShowAll_Borrowed_Click(Nothing, Nothing)
End Sub

Private Sub xDisable_Borrowed(ByVal xtsm As Object)


For Each x As ToolStripMenuItem In xtsm.DropDownItems
If x.Checked = True Then x.Checked = False
Next
End Sub

Private Sub ClearText_Borrowed()


cbBorrowed.Text = Nothing : txSearch_Borrowed.Clear()
End Sub

#End Region

#End Region

#Region " STUDENTS "

#Region "Form Load and Search"

Dim xSortx_Customer As String = "Slastname"


Dim Totaltime As Integer

Private Sub tsbStudents_Click(sender As Object, e As EventArgs)


Handles tsbStudents.Click
tabRecords.SelectedIndex = 2 : LvwLoad_Customer() :
ClearText_Customer()
End Sub

Public Sub LvwLoad_Customer()


On Error Resume Next
sql = "SELECT * FROM tblstudent ORDER BY " & xSortx_Customer &
" ASC"
LvwSearch_Customer()
End Sub

Private Sub LvwSearch_Customer()


dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader()
LvwStudents.Items.Clear()
While dbRead.Read
Totaltime = dbRead("StimeRem")
Dim Hours As Integer = Math.Floor(Totaltime / 60)
Dim Minutes As Integer = Totaltime Mod 60

LvwStudents.Items.Add(dbRead("Sid"))
LvwStudents.Items(LvwStudents.Items.Count -
1).SubItems.Add(dbRead("Sidnum"))
LvwStudents.Items(LvwStudents.Items.Count -
1).SubItems.Add(dbRead("Sfname"))
LvwStudents.Items(LvwStudents.Items.Count -
1).SubItems.Add(dbRead("Slastname"))
LvwStudents.Items(LvwStudents.Items.Count -
1).SubItems.Add(dbRead("Scourse"))

STI College Puerto Princesa 87


LvwStudents.Items(LvwStudents.Items.Count -
1).SubItems.Add(dbRead("Syrlvl"))
LvwStudents.Items(LvwStudents.Items.Count -
1).SubItems.Add(Hours & ":" & Minutes)
End While
dbRead.Close()
LvwColor(LvwStudents) : LblRecords_Customer.Text = " CUSTOMERS
RECORDS FOUND: " & LvwStudents.Items.Count
End Sub

Private Sub btnSearch_Customer_Click(sender As Object, e As


EventArgs) Handles btnSearch_Customer.Click
On Error Resume Next
If cbCustomer.Text = "Student ID No." Then
sql = "SELECT * FROM tblCustomer WHERE Sidnum LIKE '%" &
txSearch_Customer.Text & "%' ORDER BY " & xSortx_Customer & " ASC"
ElseIf cbCustomer.Text = "First Name" Then
sql = "SELECT * FROM tblCustomer WHERE Sfname LIKE '%" &
txSearch_Customer.Text & "%' ORDER BY " & xSortx_Customer & " ASC"
ElseIf cbCustomer.Text = "Last Name" Then
sql = "SELECT * FROM tblCustomer WHERE Slastname LIKE '%" &
txSearch_Customer.Text & "%' ORDER BY " & xSortx_Customer & " ASC"
ElseIf cbCustomer.Text = "Course" Then
sql = "SELECT * FROM tblCustomer WHERE Scourse LIKE '%" &
txSearch_Customer.Text & "%' ORDER BY " & xSortx_Customer & " ASC"
ElseIf cbCustomer.Text = "Year Level" Then
sql = "SELECT * FROM tblCustomer WHERE Syrlvl LIKE '%" &
txSearch_Customer.Text & "%' ORDER BY " & xSortx_Customer & " ASC"
Else
sql = "SELECT * FROM tblCustomer WHERE Sfname LIKE '%" &
txSearch_Customer.Text & "%' ORDER BY " & xSortx_Customer & " ASC"
End If
LvwSearch_Customer()
End Sub

Private Sub btnShowAll_Customer_Click(sender As Object, e As


EventArgs) Handles btnShowAll_Customer.Click
LvwLoad_Customer() : ClearText_Customer()
End Sub

Private Sub txSearch_Customer_KeyPress(sender As Object, e As


KeyPressEventArgs) Handles txSearch_Customer.KeyPress
If e.KeyChar = Chr(13) Then
btnSearch_Customer_Click(Nothing, Nothing)
End If
End Sub

#End Region

#Region "Lisview Click"

Private Sub LvwCustomer_Click(sender As Object, e As EventArgs)


Handles LvwStudents.Click
StudentID = LvwStudents.FocusedItem.Text
End Sub

#End Region

STI College Puerto Princesa 88


#Region "ToolStrip Menu"

Private Sub tstsmNew_Customer_Click(sender As Object, e As


EventArgs) Handles tsmNew_Customer.Click
StudentID = Nothing
Dim frmRegistration As New frmRegistration
With frmRegistration
.ShowDialog()
End With
tsmRefresh_Customer_Click(Nothing, Nothing)
End Sub

Private Sub tsmUpdate_Customer_Click(sender As Object, e As


EventArgs) Handles tsmUpdate_Customer.Click
frmRegistration.LoadEdit() : frmRegistration.ShowDialog()
'If StudentID = Nothing Then
' Dim MsgBox_ As New frmCustomMessageBox("Please choose a
record.", My.Resources.MsgBoxStyle_Information, "Ok", "Cancel", False)
: Dim result = MsgBox_.ShowDialog()
'Else
' If LvwCustomer.FocusedItem.Text = Nothing Or
LvwCustomer.FocusedItem.Text = "" Then Exit Sub
' If StudentID <> Nothing Or StudentID <> "" Then
' Dim frmRegistration As New frmRegistration
' With frmRegistration
' .ShowDialog()
' End With
' End If
' tsmRefresh_Customer_Click(Nothing, Nothing)
'End If

End Sub

Private Sub tsmRefresh_Customer_Click(sender As Object, e As


EventArgs) Handles tsmRefresh_Customer.Click
LvwLoad_Customer() : ClearText_Customer() : StudentID = Nothing
End Sub

Private Sub tsmSort_Cust_Name_Click(sender As Object, e As


EventArgs) Handles tsmSort_Cust_Name.Click
xDisable_Customer(tsmSort_Customer) : tsmSort_Cust_Name.Checked
= True : xSortx_Customer = "Cust_Name" :
btnShowAll_Customer_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Cust_Contact_Click(sender As Object, e As


EventArgs) Handles tsmSort_Cust_Contact.Click
xDisable_Customer(tsmSort_Customer) :
tsmSort_Cust_Contact.Checked = True : xSortx_Customer = "Cust_Contact"
: btnShowAll_Customer_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Cust_Email_Click(sender As Object, e As


EventArgs) Handles tsmSort_Cust_Email.Click

STI College Puerto Princesa 89


xDisable_Customer(tsmSort_Customer) :
tsmSort_Cust_Email.Checked = True : xSortx_Customer = "Cust_Email" :
btnShowAll_Customer_Click(Nothing, Nothing)
End Sub

Private Sub ttsmSort_Cust_Address_Click(sender As Object, e As


EventArgs) Handles tsmSort_Cust_Address.Click
xDisable_Customer(tsmSort_Customer) :
tsmSort_Cust_Address.Checked = True : xSortx_Customer = "Cust_Address"
: btnShowAll_Customer_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Cust_File_Click(sender As Object, e As


EventArgs) Handles tsmSort_Cust_File.Click
xDisable_Customer(tsmSort_Customer) : tsmSort_Cust_File.Checked
= True : xSortx_Customer = "File_By" :
btnShowAll_Customer_Click(Nothing, Nothing)
End Sub

Private Sub xDisable_Customer(ByVal xtsm As Object)


For Each x As ToolStripMenuItem In xtsm.DropDownItems
If x.Checked = True Then x.Checked = False
Next
End Sub

Private Sub ClearText_Customer()


cbCustomer.Text = Nothing : txSearch_Customer.Clear()
End Sub

#End Region

#End Region

#Region " BOOKS "

#Region "Form Load and Search"

Dim xSortx_Book_Listing As String = "Title_Books"

Private Sub tsbBooks_Click(sender As Object, e As EventArgs)


Handles tsbBooks.Click
tabRecords.SelectedIndex = 1 : LvwLoad_Supplier() :
ClearText_Supplier()
End Sub

Private Sub LvwLoad_Supplier()


On Error Resume Next
sql = " SELECT DISTINCT Book_tittle as Title_Books, Book_class,
Book_autor, Book_edition, Book_Section, " & _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_Status='Available' AND Book_tittle=Title_Books) as Avail_Books, "
& _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_Status='Borrowed' AND Book_tittle=Title_Books) as Borrowed_Books,
" & _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_tittle=Title_Books) as Total_Books " & _

STI College Puerto Princesa 90


" FROM tblbooks ORDER BY " & xSortx_Book_Listing & " ASC
"
LvwSearch_Supplier()
End Sub

Private Sub LvwSearch_Supplier()


dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader()

LvwBooks.Items.Clear()
While dbRead.Read
LvwBooks.Items.Add(dbRead("Avail_Books"))
LvwBooks.Items(LvwBooks.Items.Count -
1).SubItems.Add(dbRead("Avail_Books") & " Out of " &
dbRead("Total_Books"))
LvwBooks.Items(LvwBooks.Items.Count -
1).SubItems.Add(dbRead("Title_Books"))
LvwBooks.Items(LvwBooks.Items.Count -
1).SubItems.Add(dbRead("Book_class"))
LvwBooks.Items(LvwBooks.Items.Count -
1).SubItems.Add(dbRead("Book_autor"))
LvwBooks.Items(LvwBooks.Items.Count -
1).SubItems.Add(dbRead("Book_edition"))
LvwBooks.Items(LvwBooks.Items.Count -
1).SubItems.Add(dbRead("Book_Section"))
LvwBooks.Items(LvwBooks.Items.Count -
1).SubItems.Add(dbRead("Avail_Books"))
End While
dbRead.Close()
LvwColor(LvwBooks) : LblRecords_Supplier.Text = " BOOK RECORDS
FOUND: " & LvwBooks.Items.Count
End Sub

Private Sub btnSearch_Supplier_Click(sender As Object, e As


EventArgs) Handles btnSearch_Supplier.Click
On Error Resume Next
If cbSupplier.Text = "Book Title" Then
sql = " SELECT DISTINCT Book_tittle as Title_Books,
Book_class, Book_autor, Book_edition, Book_Section, " & _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_Status='Available' AND Book_tittle=Title_Books) as Avail_Books, "
& _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_Status='Borrowed' AND Book_tittle=Title_Books) as Borrowed_Books,
" & _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_tittle=Title_Books) as Total_Books " & _
" FROM tblbooks WHERE Title_Books LIKE '%" &
txSearch_Supplier.Text & "%' ORDER BY " & xSortx_Book_Listing & " ASC"
ElseIf cbSupplier.Text = "Book Class" Then
sql = " SELECT DISTINCT Book_tittle as Title_Books,
Book_class, Book_autor, Book_edition, Book_Section, " & _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_Status='Available' AND Book_tittle=Title_Books) as Avail_Books, "
& _

STI College Puerto Princesa 91


" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_Status='Borrowed' AND Book_tittle=Title_Books) as Borrowed_Books,
" & _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_tittle=Title_Books) as Total_Books " & _
" FROM tblbooks WHERE Book_class LIKE '%" &
txSearch_Supplier.Text & "%' ORDER BY " & xSortx_Book_Listing & " ASC"
ElseIf cbSupplier.Text = "Book Author" Then
sql = " SELECT DISTINCT Book_tittle as Title_Books,
Book_class, Book_autor, Book_edition, Book_Section, " & _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_Status='Available' AND Book_tittle=Title_Books) as Avail_Books, "
& _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_Status='Borrowed' AND Book_tittle=Title_Books) as Borrowed_Books,
" & _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_tittle=Title_Books) as Total_Books " & _
" FROM tblbooks WHERE Book_autor LIKE '%" &
txSearch_Supplier.Text & "%' ORDER BY " & xSortx_Book_Listing & " ASC"
ElseIf cbSupplier.Text = "Book Edition" Then
sql = " SELECT DISTINCT Book_tittle as Title_Books,
Book_class, Book_autor, Book_edition, Book_Section, " & _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_Status='Available' AND Book_tittle=Title_Books) as Avail_Books, "
& _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_Status='Borrowed' AND Book_tittle=Title_Books) as Borrowed_Books,
" & _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_tittle=Title_Books) as Total_Books " & _
" FROM tblbooks WHERE Book_edition LIKE '%" &
txSearch_Supplier.Text & "%' ORDER BY " & xSortx_Book_Listing & " ASC"
ElseIf cbSupplier.Text = "Book Remarks" Then
sql = " SELECT DISTINCT Book_tittle as Title_Books,
Book_class, Book_autor, Book_edition, Book_Section, " & _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_Status='Available' AND Book_tittle=Title_Books) as Avail_Books, "
& _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_Status='Borrowed' AND Book_tittle=Title_Books) as Borrowed_Books,
" & _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_tittle=Title_Books) as Total_Books " & _
" FROM tblbooks WHERE Book_remarks LIKE '%" &
txSearch_Supplier.Text & "%'ORDER BY " & xSortx_Book_Listing & " ASC"
Else
sql = " SELECT DISTINCT Book_tittle as Title_Books,
Book_class, Book_autor, Book_edition, Book_Section, " & _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_Status='Available' AND Book_tittle=Title_Books) as Avail_Books, "
& _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_Status='Borrowed' AND Book_tittle=Title_Books) as Borrowed_Books,
" & _
" (SELECT COUNT(BookID) FROM tblbooks WHERE
Book_tittle=Title_Books) as Total_Books " & _

STI College Puerto Princesa 92


" FROM tblbooks WHERE Title_Books LIKE '%" &
txSearch_Supplier.Text & "%' ORDER BY " & xSortx_Book_Listing & " ASC"
End If
LvwSearch_Supplier()
End Sub

Private Sub btnShowAll_Supplier_Click(sender As Object, e As


EventArgs) Handles btnShowAll_Supplier.Click
LvwLoad_Supplier() : ClearText_Supplier()
End Sub

Private Sub txSearch_Supplier_KeyPress(sender As Object, e As


KeyPressEventArgs) Handles txSearch_Supplier.KeyPress
If e.KeyChar = Chr(13) Then
btnSearch_Supplier_Click(Nothing, Nothing)
End If
End Sub

#End Region

#Region "Lisview Click"

Private Sub LvwSupplier_Click(sender As Object, e As EventArgs)


Handles LvwBooks.Click
BookID = LvwBooks.FocusedItem.Text
'BookStatus_ = LvwBooks.FocusedItem.SubItems(8).Text
BookNameeeeee_ = LvwBooks.FocusedItem.SubItems(2).Text
End Sub

#End Region

#Region "ToolStrip Menu"

Private Sub tsmAvailability_Click(sender As Object, e As EventArgs)


Handles tsmAvailability.Click
isBookAvailability = True : frmBooksList.Show() :
Books_Status() : tsmRefresh_Supplier_Click(Nothing, Nothing)
End Sub

Private Sub tstsmNew_Supplier_Click(sender As Object, e As


EventArgs) Handles tsmNew_Supplier.Click
BookID = Nothing
Dim frmSupplier As New frmBooks
With frmSupplier
.frmCustomersContainer.Text = "ADD NEW BOOK"
.ShowDialog() : Books_Status()
End With
tsmRefresh_Supplier_Click(Nothing, Nothing) : Books_Status()
End Sub

Private Sub tsmUpdate_Supplier_Click(sender As Object, e As


EventArgs) Handles tsmUpdate_Supplier.Click
If BookID = Nothing Then
Dim MsgBox_ As New frmCustomMessageBox("Please choose a
record.", My.Resources.MsgBoxStyle_Information, "Ok", "Cancel", False)
: Dim result = MsgBox_.ShowDialog()
Else

STI College Puerto Princesa 93


If LvwBooks.FocusedItem.Text = Nothing Or
LvwBooks.FocusedItem.Text = "" Then Exit Sub
If BookID <> Nothing Or BookID <> "" Then
Dim frmSupplier As New frmBooks
With frmSupplier
.frmCustomersContainer.Text = "UPDATE BOOK"
.ShowDialog() : Books_Status()
End With
End If
tsmRefresh_Supplier_Click(Nothing, Nothing) :
Books_Status()
End If
End Sub

Public Sub tsmRefresh_Supplier_Click(sender As Object, e As


EventArgs) Handles tsmRefresh_Supplier.Click
LvwLoad_Supplier() : ClearText_Supplier() : BookID = Nothing :
Books_Status()
End Sub

Private Sub tsmSort_Sup_Name_Click(sender As Object, e As


EventArgs) Handles tsmSort_Sup_Name.Click
xDisable_Supplier(tsmSort_Supplier) : tsmSort_Sup_Name.Checked
= True : xSortx_Book_Listing = "Title_Books" :
btnShowAll_Supplier_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Sup_Contact_Click(sender As Object, e As


EventArgs) Handles tsmSort_Sup_Contact.Click
xDisable_Supplier(tsmSort_Supplier) :
tsmSort_Sup_Contact.Checked = True : xSortx_Book_Listing = "Book_class"
: btnShowAll_Supplier_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Sup_Email_Click(sender As Object, e As


EventArgs) Handles tsmSort_Sup_Email.Click
xDisable_Supplier(tsmSort_Supplier) : tsmSort_Sup_Email.Checked
= True : xSortx_Book_Listing = "Book_autor" :
btnShowAll_Supplier_Click(Nothing, Nothing)
End Sub

Private Sub ttsmSort_Sup_Address_Click(sender As Object, e As


EventArgs) Handles tsmSort_Sup_Address.Click
xDisable_Supplier(tsmSort_Supplier) :
tsmSort_Sup_Address.Checked = True : xSortx_Book_Listing =
"Book_edition" : btnShowAll_Supplier_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Sup_File_Click(sender As Object, e As


EventArgs) Handles tsmSort_Sup_File.Click
xDisable_Supplier(tsmSort_Supplier) : tsmSort_Sup_File.Checked
= True : xSortx_Book_Listing = "Book_remarks" :
btnShowAll_Supplier_Click(Nothing, Nothing)
End Sub

Private Sub xDisable_Supplier(ByVal xtsm As Object)


For Each x As ToolStripMenuItem In xtsm.DropDownItems

STI College Puerto Princesa 94


If x.Checked = True Then x.Checked = False
Next
End Sub

Private Sub ClearText_Supplier()


cbSupplier.Text = Nothing : txSearch_Supplier.Clear()
End Sub

#End Region

#End Region

#Region " ACCOUNTS "

#Region "Form Load and Search"

Dim xSortx_Accounts As String = "Sfirstname"

Private Sub tsmAccounts_Click(sender As Object, e As EventArgs)


Handles tsmAccounts.Click
tabRecords.SelectedIndex = 4 : LvwLoad_Accounts() :
ClearText_Accounts()
End Sub

Public Sub LvwLoad_Accounts()


On Error Resume Next
sql = "SELECT * FROM tblaccounts ORDER BY " & xSortx_Accounts &
" ASC"
LvwSearch_Accounts()
End Sub

Private Sub LvwSearch_Accounts()


dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader()

LvwAccounts.Items.Clear()
While dbRead.Read
LvwAccounts.Items.Add(dbRead("Sid"))
LvwAccounts.Items(LvwAccounts.Items.Count -
1).SubItems.Add(dbRead("Sfirstname") & " " & dbRead("Slastname"))
LvwAccounts.Items(LvwAccounts.Items.Count -
1).SubItems.Add(dbRead("Sacctype"))
LvwAccounts.Items(LvwAccounts.Items.Count -
1).SubItems.Add(dbRead("Sstatus"))
LvwAccounts.Items(LvwAccounts.Items.Count -
1).SubItems.Add(dbRead("Slastlogin"))
End While
dbRead.Close()
LvwColor(LvwAccounts) : LblRecords_Account.Text = " ACCOUNT
RECORDS FOUND: " & LvwAccounts.Items.Count
End Sub

Private Sub btnSearch_Account_Click(sender As Object, e As


EventArgs) Handles btnSearch_Account.Click
On Error Resume Next
If cbAccount.Text = "Fullname" Then

STI College Puerto Princesa 95


sql = "SELECT * FROM tblaccounts WHERE Sfirstname LIKE '%"
& txSearch_Account.Text & "%' OR Slastname '%" & txSearch_Account.Text
& "%' ORDER BY " & xSortx_Accounts & " ASC"
ElseIf cbAccount.Text = "Position" Then
sql = "SELECT * FROM tblaccounts WHERE Sacctype LIKE '%" &
txSearch_Account.Text & "%' ORDER BY " & xSortx_Accounts & " ASC"
ElseIf cbAccount.Text = "Status" Then
sql = "SELECT * FROM tblaccounts WHERE Sstatus LIKE '%" &
txSearch_Account.Text & "%' ORDER BY " & xSortx_Accounts & " ASC"
ElseIf cbAccount.Text = "Last Login" Then
sql = "SELECT * FROM tblaccounts WHERE Slastlogin LIKE '%"
& txSearch_Account.Text & "%' ORDER BY " & xSortx_Accounts & " ASC"
Else
sql = "SELECT * FROM tblaccounts WHERE Fullname LIKE '%" &
txSearch_Account.Text & "%' ORDER BY " & xSortx_Accounts & " ASC"
End If
LvwSearch_Accounts()
End Sub

Private Sub btnShowAll_Account_Click(sender As Object, e As


EventArgs) Handles btnShowAll_Account.Click
LvwLoad_Accounts() : ClearText_Accounts()
End Sub

Private Sub txSearch_Account_KeyPress(sender As Object, e As


KeyPressEventArgs) Handles txSearch_Account.KeyPress
If e.KeyChar = Chr(13) Then
btnSearch_Account_Click(Nothing, Nothing)
End If
End Sub

#End Region

#Region "Lisview Click"

Private Sub LvwAccounts_Click(sender As Object, e As EventArgs)


Handles LvwAccounts.Click
AccountID = LvwAccounts.FocusedItem.Text
End Sub

#End Region

#Region "ToolStrip Menu"

Private Sub tsmNew_Account_Click(sender As Object, e As EventArgs)


Handles tsmNew_Account.Click
AccountID = Nothing
Dim frmAccounts As New frmAddaccounts
With frmAccounts
.frmTitle.Text = "ADD NEW ACCOUNT"
.ShowDialog()
End With
tsmRefresh_Accounts_Click(Nothing, Nothing)
End Sub

Private Sub tsmUpdate_Account_Accounts_Click(sender As Object, e As


EventArgs) Handles tsmUpdate_Account.Click

STI College Puerto Princesa 96


If AccountID = Nothing Then
Dim MsgBox_ As New frmCustomMessageBox("Please choose a
record.", My.Resources.MsgBoxStyle_Information, "Ok", "Cancel", False)
: Dim result = MsgBox_.ShowDialog()
Else
If LvwAccounts.FocusedItem.Text = Nothing Or
LvwAccounts.FocusedItem.Text = "" Then Exit Sub
If AccountID <> Nothing Or AccountID <> "" Then
Dim frmAccounts As New frmAddaccounts
With frmAccounts
.frmTitle.Text = "UPDATE ACCOUNT"
.ShowDialog()
End With
End If
tsmRefresh_Accounts_Click(Nothing, Nothing)
End If
End Sub

Private Sub tsmRefresh_Accounts_Click(sender As Object, e As


EventArgs) Handles tsmRefresh_Account.Click
LvwLoad_Accounts() : ClearText_Accounts() : AccountID = Nothing
End Sub

Private Sub tsmSort_Acct_Name_Click(sender As Object, e As


EventArgs) Handles tsmSort_Acct_Name.Click
xDisable_Accounts(tsmSort_Account) : tsmSort_Acct_Name.Checked
= True : xSortx_Accounts = "Sfirstname" :
btnShowAll_Account_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Acct_Position_Click(sender As Object, e As


EventArgs) Handles tsmSort_Acct_Position.Click
xDisable_Accounts(tsmSort_Account) :
tsmSort_Acct_Position.Checked = True : xSortx_Accounts = "Sacctype" :
btnShowAll_Account_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Acct_Status_Click(sender As Object, e As


EventArgs) Handles tsmSort_Acct_Status.Click
xDisable_Accounts(tsmSort_Account) :
tsmSort_Acct_Status.Checked = True : xSortx_Accounts = "Sstatus" :
btnShowAll_Account_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Acct_LastLog_Click(sender As Object, e As


EventArgs) Handles tsmSort_Acct_LastLog.Click
xDisable_Accounts(tsmSort_Account) :
tsmSort_Acct_LastLog.Checked = True : xSortx_Accounts = "Slastlogin" :
btnShowAll_Account_Click(Nothing, Nothing)
End Sub

Private Sub xDisable_Accounts(ByVal xtsm As Object)


For Each x As ToolStripMenuItem In xtsm.DropDownItems
If x.Checked = True Then x.Checked = False
Next
End Sub

STI College Puerto Princesa 97


Private Sub ClearText_Accounts()
cbAccount.Text = Nothing : txSearch_Account.Clear()
End Sub

#End Region

#End Region

#Region " HOLIDAYS "

#Region "Form Load and Search"

Dim xSortx_Holiday As String = "HolidayName"

Private Sub tsmHolidays_Click(sender As Object, e As EventArgs)


Handles tsmHolidays.Click
tabRecords.SelectedIndex = 5 : LvwLoad_Holiday() :
ClearText_Holiday()
End Sub

Public Sub LvwLoad_Holiday()


On Error Resume Next
sql = "SELECT * FROM tblholidays ORDER BY " & xSortx_Holiday &
" ASC"
LvwSearch_Holiday()
End Sub

Private Sub LvwSearch_Holiday()


dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader()

LvwHoliday.Items.Clear()
While dbRead.Read
LvwHoliday.Items.Add(dbRead("HolidayID"))
LvwHoliday.Items(LvwHoliday.Items.Count -
1).SubItems.Add(dbRead("HolidayName"))
LvwHoliday.Items(LvwHoliday.Items.Count -
1).SubItems.Add(dbRead("HolidayReason"))
LvwHoliday.Items(LvwHoliday.Items.Count -
1).SubItems.Add(dbRead("HolidayDate"))
LvwHoliday.Items(LvwHoliday.Items.Count -
1).SubItems.Add(dbRead("File_By"))
End While
dbRead.Close()
LvwColor(LvwHoliday) : LblRecords_Holiday.Text = " HOLIDAY
RECORDS FOUND: " & LvwHoliday.Items.Count
End Sub

Private Sub btnSearch_Holiday_Click(sender As Object, e As


EventArgs) Handles btnSearch_Holiday.Click
On Error Resume Next
If cbHoliday.Text = "Name" Then
sql = "SELECT * FROM tblholidays WHERE HolidayName LIKE '%"
& txSearch_Holiday.Text & "%' ORDER BY " & xSortx_Holiday & " ASC"
ElseIf cbHoliday.Text = "Reason" Then
sql = "SELECT * FROM tblholidays WHERE HolidayReason LIKE
'%" & txSearch_Holiday.Text & "%' ORDER BY " & xSortx_Holiday & " ASC"

STI College Puerto Princesa 98


ElseIf cbHoliday.Text = "Filed By" Then
sql = "SELECT * FROM tblholidays WHERE File_By LIKE '%" &
txSearch_Holiday.Text & "%' ORDER BY " & xSortx_Holiday & " ASC"
Else
sql = "SELECT * FROM tblholidays WHERE HolidayName LIKE '%"
& txSearch_Holiday.Text & "%' ORDER BY " & xSortx_Holiday & " ASC"
End If
LvwSearch_Holiday()
End Sub

Private Sub btnShowAll_Holiday_Click(sender As Object, e As


EventArgs) Handles btnShowAll_Holiday.Click
LvwLoad_Holiday() : ClearText_Holiday()
End Sub

Private Sub txSearch_Holiday_KeyPress(sender As Object, e As


KeyPressEventArgs) Handles txSearch_Holiday.KeyPress
If e.KeyChar = Chr(13) Then
btnSearch_Holiday_Click(Nothing, Nothing)
End If
End Sub

#End Region

#Region "Lisview Click"

Private Sub LvwHoliday_Click(sender As Object, e As EventArgs)


Handles LvwHoliday.Click
HolidayID = LvwHoliday.FocusedItem.Text
End Sub

#End Region

#Region "ToolStrip Menu"

Private Sub tsmNew_Holiday_Click(sender As Object, e As EventArgs)


Handles tsmNew_Holiday.Click
HolidayID = Nothing
Dim frmHoliday As New frmHolidays
With frmHoliday
.frmTitle.Text = "ADD NEW HOLIDAY"
.ShowDialog()
End With
tsmRefresh_Holiday_Click(Nothing, Nothing)
End Sub

Private Sub tsmUpdate_Holiday_Holiday_Click(sender As Object, e As


EventArgs) Handles tsmUpdate_Holiday.Click
If HolidayID = Nothing Then
Dim MsgBox_ As New frmCustomMessageBox("Please choose a
record.", My.Resources.MsgBoxStyle_Information, "Ok", "Cancel", False)
: Dim result = MsgBox_.ShowDialog()
Else
If LvwHoliday.FocusedItem.Text = Nothing Or
LvwHoliday.FocusedItem.Text = "" Then Exit Sub
If HolidayID <> Nothing Or HolidayID <> "" Then
Dim frmHoliday As New frmHolidays

STI College Puerto Princesa 99


With frmHoliday
.frmTitle.Text = "UPDATE HOLIDAY"
.ShowDialog()
End With
End If
tsmRefresh_Holiday_Click(Nothing, Nothing)
End If
End Sub

Private Sub tsmRefresh_Holiday_Click(sender As Object, e As


EventArgs) Handles tsmRefresh_Holiday.Click
LvwLoad_Holiday() : ClearText_Holiday() : HolidayID = Nothing
End Sub

Private Sub ClearText_Holiday()


cbHoliday.Text = Nothing : txSearch_Holiday.Clear()
End Sub

#End Region

#End Region

#Region " LOGS HISTORY "

#Region "Form Load and Search"

Dim xSortx_Logs As String = "LogsFullname"

Private Sub tsbLogs_Click(sender As Object, e As EventArgs) Handles


tsbLogs.Click
frmTimeIn.Show()
End Sub

Private Sub LvwLoad_LogsHistory()


'On Error Resume Next
sql = "SELECT * FROM tbllogshistory ORDER BY " & xSortx_Logs &
" ASC"
LvwSearch_LogsHistory()
End Sub

Private Sub LvwSearch_LogsHistory()


dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader()

LvwLogsHistory.Items.Clear()
While dbRead.Read
LvwLogsHistory.Items.Add(dbRead("IDLogs"))
LvwLogsHistory.Items(LvwLogsHistory.Items.Count -
1).SubItems.Add(dbRead("LogsFullname"))
LvwLogsHistory.Items(LvwLogsHistory.Items.Count -
1).SubItems.Add(dbRead("LogsAcctName"))
LvwLogsHistory.Items(LvwLogsHistory.Items.Count -
1).SubItems.Add(dbRead("LogsPosition"))
LvwLogsHistory.Items(LvwLogsHistory.Items.Count -
1).SubItems.Add(dbRead("LogsDate"))
LvwLogsHistory.Items(LvwLogsHistory.Items.Count -
1).SubItems.Add(dbRead("LogsTime"))

STI College Puerto Princesa 100


LvwLogsHistory.Items(LvwLogsHistory.Items.Count -
1).SubItems.Add(dbRead("LogsEvent"))
End While
dbRead.Close()
LvwColor(LvwLogsHistory) : LblRecords_LogsHistory.Text = " LOGS
HISTORY RECORDS FOUND: " & LvwLogsHistory.Items.Count
End Sub

Private Sub btnSearch_LogsHistory_Click(sender As Object, e As


EventArgs) Handles btnSearch_LogsHistory.Click
On Error Resume Next
If cbLogsHistory.Text = "Full Name" Then
sql = "SELECT * FROM tbllogshistory WHERE LogsFullname LIKE
'%" & txSearch_LogsHistory.Text & "%' ORDER BY " & xSortx_Logs & " ASC"
ElseIf cbLogsHistory.Text = "Account Name" Then
sql = "SELECT * FROM tbllogshistory WHERE LogsAcctName LIKE
'%" & txSearch_LogsHistory.Text & "%' ORDER BY " & xSortx_Logs & " ASC"
ElseIf cbLogsHistory.Text = "Position" Then
sql = "SELECT * FROM tbllogshistory WHERE LogsPosition LIKE
'%" & txSearch_LogsHistory.Text & "%' ORDER BY " & xSortx_Logs & " ASC"
ElseIf cbLogsHistory.Text = "Date" Then
sql = "SELECT * FROM tbllogshistory WHERE LogsDate LIKE '%"
& txSearch_LogsHistory.Text & "%' ORDER BY " & xSortx_Logs & " ASC"
ElseIf cbLogsHistory.Text = "Time" Then
sql = "SELECT * FROM tbllogshistory WHERE LogsTime LIKE '%"
& txSearch_LogsHistory.Text & "%' ORDER BY " & xSortx_Logs & " ASC"
ElseIf cbLogsHistory.Text = "Event" Then
sql = "SELECT * FROM tbllogshistory WHERE LogsEvent LIKE
'%" & txSearch_LogsHistory.Text & "%' ORDER BY " & xSortx_Logs & " ASC"
Else
sql = "SELECT * FROM tbllogshistory WHERE LogsFullname LIKE
'%" & txSearch_LogsHistory.Text & "%' ORDER BY " & xSortx_Logs & " ASC"
End If
LvwSearch_LogsHistory()
End Sub

Private Sub btnShowAll_LogsHistory_Click(sender As Object, e As


EventArgs) Handles btnShowAll_LogsHistory.Click
LvwLoad_LogsHistory() : ClearText_LogsHistory()
End Sub

Private Sub txSearch_LogsHistory_KeyPress(sender As Object, e As


KeyPressEventArgs) Handles txSearch_LogsHistory.KeyPress
If e.KeyChar = Chr(13) Then
btnSearch_LogsHistory_Click(Nothing, Nothing)
End If
End Sub

#End Region

#Region "Lisview Click"

Private Sub LvwLogsHistory_Click(sender As Object, e As EventArgs)


Handles LvwLogsHistory.Click
IDLogs = LvwLogsHistory.FocusedItem.Text
End Sub

STI College Puerto Princesa 101


#End Region

#Region "ToolStrip Menu"

Private Sub tsmRefresh_LogsHistory_Click(sender As Object, e As


EventArgs) Handles tsmRefresh_LogsHistory.Click
LvwLoad_LogsHistory() : ClearText_LogsHistory() : IDLogsID =
Nothing
End Sub

Private Sub tsmSort_Logs_Name_Click(sender As Object, e As


EventArgs) Handles tsmSort_Logs_Name.Click
xDisable_Logs(tsmSort_LogsHistory) : tsmSort_Logs_Name.Checked
= True : xSortx_Logs = "LogsFullname" :
btnShowAll_LogsHistory_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Logs_Acct_Click(sender As Object, e As


EventArgs) Handles tsmSort_Logs_Acct.Click
xDisable_Logs(tsmSort_LogsHistory) : tsmSort_Logs_Acct.Checked
= True : xSortx_Logs = "LogsAcctName" :
btnShowAll_LogsHistory_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Logs_Position_Click(sender As Object, e As


EventArgs) Handles tsmSort_Logs_Position.Click
xDisable_Logs(tsmSort_LogsHistory) :
tsmSort_Logs_Position.Checked = True : xSortx_Logs = "LogsPosition" :
btnShowAll_LogsHistory_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Logs_Date_Click(sender As Object, e As


EventArgs) Handles tsmSort_Logs_Date.Click
xDisable_Logs(tsmSort_LogsHistory) : tsmSort_Logs_Date.Checked
= True : xSortx_Logs = "LogsDate" :
btnShowAll_LogsHistory_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Logs_Time_Click(sender As Object, e As


EventArgs) Handles tsmSort_Logs_Time.Click
xDisable_Logs(tsmSort_LogsHistory) : tsmSort_Logs_Time.Checked
= True : xSortx_Logs = "LogsTime" :
btnShowAll_LogsHistory_Click(Nothing, Nothing)
End Sub

Private Sub tsmSort_Logs_Event_Click(sender As Object, e As


EventArgs) Handles tsmSort_Logs_Event.Click
xDisable_Logs(tsmSort_LogsHistory) : tsmSort_Logs_Event.Checked
= True : xSortx_Logs = "LogsEvent" :
btnShowAll_LogsHistory_Click(Nothing, Nothing)
End Sub
Private Sub xDisable_Logs(ByVal xtsm As Object)
For Each x As ToolStripMenuItem In xtsm.DropDownItems
If x.Checked = True Then x.Checked = False
Next
End Sub

STI College Puerto Princesa 102


Private Sub ClearText_LogsHistory()
cbLogsHistory.Text = Nothing : txSearch_LogsHistory.Clear()
End Sub

#End Region

#End Region

Private Sub tsmBorrowBook_Click(sender As Object, e As EventArgs)


Handles tsmBorrowBook.Click
'If BookStatus_ = "Available" Then
frmBooksTransaction.ShowDialog() : Books_Status() :
tsmRefresh_Supplier_Click(Nothing, Nothing)
'Else
' Dim MsgBox_ As New frmCustomMessageBox("This book is still
unavailable.", My.Resources.MsgBoxStyle_Information, "Ok", "Cancel",
False) : Dim result = MsgBox_.ShowDialog()
'End If
End Sub

Private Sub tsmStudentID_Click(sender As Object, e As EventArgs)


PrintPreviewReport = "Student ID" : frmReports.ShowDialog()
End Sub

Private Sub tsmLogRecords_Click(sender As Object, e As EventArgs)


PrintPreviewReport = "Student Records" :
frmReports.ShowDialog()
End Sub

Private Sub tsmStudentsLogin_Click(sender As Object, e As


EventArgs) Handles tsmStudentsLogin.Click
tabRecords.SelectedIndex = 3 : LvwLoad_LogsHistory() :
ClearText_LogsHistory()
End Sub

Private Sub tsmReturnBook_Click(sender As Object, e As EventArgs)


Handles tsmReturnBook.Click
If Return_BookID <> Nothing Then
On Error Resume Next

Dim DateTimePicker1 As New DateTimePicker, DateTimePicker2


As New DateTimePicker, Expected__return As New DateTimePicker
Dim DateBorrowed As String = 0, DateNow As String = 0
Dim HolidayDays As Integer = 0

DateNow = Format(Date.Now, "yyyy-MM-dd")

sql = "SELECT Transaction_Date FROM tblbookstransaction


WHERE TransactionID ='" & TransactionID & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader

While dbRead.Read
DateBorrowed = Format(dbRead(0), "yyyy-MM-dd")
End While
dbRead.Close()

STI College Puerto Princesa 103


DateTimePicker1.Text = DateBorrowed
DateTimePicker2.Text = DateNow

sql = "SELECT COUNT(HolidayID) FROM tblholidays WHERE


HolidayDate BETWEEN '" & DateBorrowed & "' AND '" & DateNow & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader

While dbRead.Read
HolidayDays = dbRead(0)
End While
dbRead.Close()

Dim Total_Penalty As Integer = 0


Dim countsun As Integer = 0
Dim countsat As Integer = 0
Dim NonHoliday As Integer
Dim TotalDay As String
TotalDay = DateDiff("d", DateTimePicker1.Value,
DateTimePicker2.Value)
For i As Integer = 0 To TotalDay
Dim Weekday As DayOfWeek =
DateTimePicker1.Value.AddDays(i).DayOfWeek
If Weekday = DayOfWeek.Saturday Then
countsat += 1
End If
If Weekday = DayOfWeek.Sunday Then
countsun += 1
End If
If Weekday <> DayOfWeek.Saturday AndAlso Weekday <>
DayOfWeek.Sunday Then
NonHoliday += 1
End If
Next

Total_Penalty = NonHoliday - HolidayDays

Dim srcCheckout As Date = DateTimePicker1.Value


Expected__return.Value = srcCheckout.AddDays(1)

If Total_Penalty >= 2 Then


Dim panelty_Amount As Integer, Penalty_Days As Integer
panelty_Amount = (Total_Penalty - 1) * 5
Penalty_Days = Total_Penalty - 1
Dim MsgBox__ As New frmCustomMessageBox("You havent
returned the book within the expected date!" & vbCrLf & _
"Borrowed Date:
" & DateTimePicker1.Value & vbCrLf & "Expected Return Date: " &
Expected__return.Value & vbCrLf & _
"Total Penalty
Amount for " & Penalty_Days & " day(s) : ₱" &
Format(CDbl(panelty_Amount), "#,##0.00"),
My.Resources.MsgBoxStyle_Warning, "Ok", "Cancel", False) : Dim result__
= MsgBox__.ShowDialog()

End If

STI College Puerto Princesa 104


sql = "UPDATE tblbooks SET Book_Status='Available' WHERE
BookID='" & Return_BookID & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()

sql = "UPDATE tblbookstransaction SET


TransStatus='Returned' WHERE TransactionID='" & TransactionID & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()

Dim MsgBox_ As New frmCustomMessageBox("Book has been


Successfully returned.", My.Resources.MsgBoxStyle_Information, "Ok",
"Cancel", False) : Dim result = MsgBox_.ShowDialog()
Else
Dim MsgBox_ As New frmCustomMessageBox("Please Select a
borrowed book first.", My.Resources.MsgBoxStyle_Information, "Ok",
"Cancel", False) : Dim result = MsgBox_.ShowDialog()
End If
tsmRefresh_Borrowed_Click(Nothing, Nothing) : Books_Status()
tsmRefresh_Supplier_Click(Nothing, Nothing) : Books_Status()
End Sub

Private Sub CalBooking_DateSelected(ByVal sender As Object, ByVal e


As System.Windows.Forms.DateRangeEventArgs) Handles
CalBookingTransaction.DateSelected
CalBookingTransaction_DateSelected(CalBookingTransaction)
End Sub

Private Sub tsbLogout_Click(sender As Object, e As EventArgs)


Handles tsbLogout.Click
frmReportSelector.ShowDialog()
End Sub

End Class

frmStudentLogin

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Imports AForge.Video.DirectShow
Imports BarcodeLib.BarcodeReader
Imports System.Data.OleDb
Imports System.IO.Ports
Imports MySql.Data.MySqlClient

Public Class frmStudentLogin

Dim Filter As FilterInfoCollection


Dim Disp As VideoCaptureDevice

STI College Puerto Princesa 105


Public IDnum As String
Dim cnt As Integer = 0

Private Sub LblClose_Click(sender As Object, e As EventArgs)


Handles LblClose.Click
Me.Close()
End Sub

Private Sub tmCount_Tick(sender As Object, e As EventArgs)


txDate.Text = Format(Date.Now, "MMM dd, yyyy")
txTime.Text = Format(Date.Now, "hh:mm tt")
End Sub

Private Sub frmStudentLogin_Load(sender As Object, e As EventArgs)


Handles MyBase.Load
Filter = New
FilterInfoCollection(FilterCategory.VideoInputDevice)
For Each x As FilterInfo In Filter
ComboBox1.Items.Add(x.Name)
Next
ComboBox1.SelectedIndex = 0 'StartQR()
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click
Studlogin()
Timer1.Enabled = True
Timer1.Start()
Disp = New
VideoCaptureDevice(Filter(ComboBox1.SelectedIndex).MonikerString)
videoSourcePlayer1.VideoSource = Disp
videoSourcePlayer1.Start()
End Sub

Private Sub StartQR()


Timer1.Enabled = True
Timer1.Start()
Disp = New
VideoCaptureDevice(Filter(ComboBox1.SelectedIndex).MonikerString)
videoSourcePlayer1.VideoSource = Disp
videoSourcePlayer1.Start()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles


Timer1.Tick
If videoSourcePlayer1.GetCurrentVideoFrame() IsNot Nothing Then
Dim img As Bitmap = New
Bitmap(videoSourcePlayer1.GetCurrentVideoFrame())
Dim resultados As String() = BarcodeReader.read(img,
BarcodeReader.QRCODE)
img.Dispose()
If resultados IsNot Nothing Then
Beep()
IDnum = resultados(0) : Studlogin()
'Timer1.Stop()

STI College Puerto Princesa 106


'MsgBox(IDnum)
End If
End If
End Sub

Private Sub Studlogin()


sql = "SELECT * FROM tblstudent WHERE Sidnum = '" & IDnum & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader()
While dbRead.Read
xIDnum = dbRead("Sidnum")
xStudfullname = dbRead("Sfname") + " " +
dbRead("Slastname")
xCourse = dbRead("Scourse")
xYearlvl = dbRead("Syrlvl")
xTimeRem = dbRead("StimeRem")
xStat = dbRead("SLogStat")
End While
dbRead.Close()
'MsgBox(sql)
If IDnum = Nothing Then Return
If IDnum = xIDnum Then
grpDetails.Visible = True : tmCount.Start() : IDnum =
Nothing
If xStat = "1" Then
txFullname.Text = xStudfullname
txCourse.Text = xCourse
txDate.Text = Format(Date.Now, "MMM dd, yyyy")
txTime.Text = Format(Date.Now, "hh:mm tt")
Timeout() : txStatus.Text = "Signed out"
Else
txFullname.Text = xStudfullname
txCourse.Text = xCourse
txDate.Text = Format(Date.Now, "MMM dd, yyyy")
txTime.Text = Format(Date.Now, "hh:mm tt")
TimeIn() : txStatus.Text = "Signed in"
End If
End If
End Sub
Private Sub TimeIn()
sql = "INSERT INTO tblstudtime (Sidnum, Sfullname, Scourse,
Syearlvl, Stimein, Sstat, Logs_Date) VALUES ('" & xIDnum & "','" &
xStudfullname & "','" & xCourse & "','" & xYearlvl & "','" &
Format(Date.Now, "hh:mm tt") & "','1','" & Format(Date.Now, "yyyy-MM-
dd") & "')"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()

sql = "UPDATE tblstudent SET SLogStat = '1' WHERE Sidnum = '" &
xIDnum & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()
End Sub
Private Sub Timeout()
Dim timein As DateTime
Dim timeout As DateTime

STI College Puerto Princesa 107


sql = "UPDATE tblstudtime SET Stimeout = '" & Format(Date.Now,
"hh:mm tt") & "' WHERE Sidnum = '" & xIDnum & "' and Sstat = '1'"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()

sql = "SELECT * FROM tblstudtime WHERE Sstat ='1' and Sidnum


='" & xIDnum & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader()
While dbRead.Read
timein = dbRead("Stimein")
timeout = dbRead("Stimeout")
End While
dbRead.Close()

sql = "SELECT Sfname, Scontnum FROM tblstudent WHERE Sidnum ='"


& xIDnum & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader()
While dbRead.Read
SMS_Notif_No_ = dbRead("Scontnum")
SMS_Notif_Name_ = dbRead("Sfname")
End While
dbRead.Close()

Dim CompMin As Integer = DateDiff(DateInterval.Minute, timein,


timeout)
xTimeRem = xTimeRem - CompMin

sql = "UPDATE tblstudent SET StimeRem = '" & xTimeRem & "'
WHERE Sidnum = '" & xIDnum & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()

Dim Hours As Integer = Math.Floor(xTimeRem / 60)


Dim Minutes As Integer = xTimeRem Mod 60

sql = "UPDATE tblstudtime SET Sstat = '0', Scontime='" & Hours


& ":" & Minutes & "' WHERE Sidnum = '" & xIDnum & "' and Sstat = '1'"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()

sql = "UPDATE tblstudent SET SLogStat = '0' WHERE Sidnum = '" &
xIDnum & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbCom.ExecuteNonQuery()

If Hours <= 0 Then


frmSMS.Send_SMS_Notification(SMS_Notif_No_, "Hi " &
SMS_Notif_Name_ & ", Congratulations, you have consumed all of your
remaining time this semester. You are now eligible for clearance.
Please visit the librarian for more information." & vbCrLf & vbCrLf & "
STI Library System ")
Else
frmSMS.Send_SMS_Notification(SMS_Notif_No_, "Hi " &
SMS_Notif_Name_ & ", your remaining time is: " & Hours & "hrs and " &

STI College Puerto Princesa 108


Minutes & " mins " & vbCrLf & vbCrLf & " STI Library
System ")
End If

End Sub

Private Sub tmCount_Tick_1(sender As Object, e As EventArgs)


Handles tmCount.Tick
cnt += 1
If cnt = 3 Then
grpDetails.Visible = False : cnt = 0 : tmCount.Stop() :
IDnum = Nothing

End If
End Sub

Private Sub frmStudentLogin_Shown(sender As Object, e As EventArgs)


Handles Me.Shown
If ComboBox1.Items.Count <> 0 Then
ComboBox1.SelectedIndex = 0
Button1_Click(Nothing, Nothing)
End If
End Sub

Private Sub Label2_Click(sender As Object, e As EventArgs) Handles


Label2.Click
videoSourcePlayer1.Stop()
Me.Hide()
End Sub

End Class

frmSMS

Imports System.Management
Imports MySql.Data.MySqlClient

Public Class frmSMS


Dim rcvdata As String = ""

Private Sub frmSMS_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Dim ports() As String
ports = Split(ModemsConnected(), "***")
For i As Integer = 0 To ports.Length - 2
ComboBox1.Items.Add(ports(i))
Next

If ComboBox1.Text = "" Then


Label1.Text = "No Connection!"
End If
End Sub

Public Function ModemsConnected() As String


Dim modems As String = ""

STI College Puerto Princesa 109


Try
Dim searcher As New ManagementObjectSearcher("root\CIMV2",
"SELECT * FROM Win32_POTSModem")
For Each queryObj As ManagementObject In searcher.Get()
If queryObj("Status") = "OK" Then
modems = modems & (queryObj("AttachedTo") & " - " &
queryObj("Description") & "***")
End If
Next
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI
data: " & err.Message)
Return ""
End Try
Return modems
End Function

Public Sub ComboBox1_SelectedValueChanged(ByVal sender As Object,


ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
Label1.Text = Trim(Mid(ComboBox1.Text, 1, 5))
End Sub

Private Sub serialport1_datareceived(ByVal sender As Object, ByVal


e As System.IO.Ports.SerialDataReceivedEventArgs) Handles
SerialPort1.DataReceived
Dim datain As String = ""
Dim numbytes As Integer = SerialPort1.BytesToRead
For i As Integer = 1 To numbytes
datain &= Chr(SerialPort1.ReadChar)
Next
test(datain)
End Sub

Private Sub test(ByVal indata As String)


rcvdata &= indata
End Sub

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles button1.Click
Try
With SerialPort1
.PortName = Label1.Text
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
.Handshake = IO.Ports.Handshake.None
.RtsEnable = True
.ReceivedBytesThreshold = 1
.NewLine = vbCr
.ReadTimeout = 1000
.Open()
End With
If SerialPort1.IsOpen Then
Label3.Text = "Connected!"
Else
Label3.Text = "Not Connected!"

STI College Puerto Princesa 110


End If

Catch ex As Exception
MsgBox("No Connection Found, Make Sure The Device is
Plugged-In!", 16, " SMS ")
End Try
End Sub

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnSend.Click
Send_SMS_Notification(txRecipients.Text, txMessage.Text)
End Sub

Private Sub frmSMS_Shown(sender As Object, e As EventArgs) Handles


Me.Shown
Configure_SMS_Notification()
End Sub

Public Sub Configure_SMS_Notification()


Dim ports() As String
ports = Split(ModemsConnected(), "***")
For i As Integer = 0 To ports.Length - 2
ComboBox1.Items.Add(ports(i))
Next

If ComboBox1.Items.Count <> 0 Then


ComboBox1.SelectedIndex = 0
ComboBox1_SelectedValueChanged(Nothing, Nothing)
Button1_Click(Nothing, Nothing)
End If
End Sub

Public Sub Send_SMS_Notification(ByVal xRecipientx As String, ByVal


xMessagex As String)
If Label3.Text = "Not Connected!" Then MsgBox("Please check
modem connection!", 64, "SMS")
Try
With SerialPort1
.Write("at" & vbCrLf)
.Write("at+cmgf=1" & vbCrLf)
.Write("at+cmgs=" & Chr(34) & xRecipientx & Chr(34) &
vbCrLf)
.Write(xMessagex & Chr(26))
Threading.Thread.Sleep(1000)
End With
Catch ex As Exception
'LogsHistory("message failed")
'MsgBox("Message Successfully failed!", 64, "Sent")
Finally
'MsgBox("Message Successfully Sent!", 64, "Sent")
End Try
End Sub

STI College Puerto Princesa 111


End Class

frmSMS

Imports System.Management
Imports MySql.Data.MySqlClient

Public Class frmSMS


Dim rcvdata As String = ""

Private Sub frmSMS_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Dim ports() As String
ports = Split(ModemsConnected(), "***")
For i As Integer = 0 To ports.Length - 2
ComboBox1.Items.Add(ports(i))
Next

If ComboBox1.Text = "" Then


Label1.Text = "No Connection!"
End If
End Sub

Public Function ModemsConnected() As String


Dim modems As String = ""
Try
Dim searcher As New ManagementObjectSearcher("root\CIMV2",
"SELECT * FROM Win32_POTSModem")
For Each queryObj As ManagementObject In searcher.Get()
If queryObj("Status") = "OK" Then
modems = modems & (queryObj("AttachedTo") & " - " &
queryObj("Description") & "***")
End If
Next
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI
data: " & err.Message)
Return ""
End Try
Return modems
End Function

Public Sub ComboBox1_SelectedValueChanged(ByVal sender As Object,


ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
Label1.Text = Trim(Mid(ComboBox1.Text, 1, 5))
End Sub

Private Sub serialport1_datareceived(ByVal sender As Object, ByVal


e As System.IO.Ports.SerialDataReceivedEventArgs) Handles
SerialPort1.DataReceived
Dim datain As String = ""
Dim numbytes As Integer = SerialPort1.BytesToRead
For i As Integer = 1 To numbytes
datain &= Chr(SerialPort1.ReadChar)
Next

STI College Puerto Princesa 112


test(datain)
End Sub

Private Sub test(ByVal indata As String)


rcvdata &= indata
End Sub

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles button1.Click
Try
With SerialPort1
.PortName = Label1.Text
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
.Handshake = IO.Ports.Handshake.None
.RtsEnable = True
.ReceivedBytesThreshold = 1
.NewLine = vbCr
.ReadTimeout = 1000
.Open()
End With
If SerialPort1.IsOpen Then
Label3.Text = "Connected!"
Else
Label3.Text = "Not Connected!"
End If

Catch ex As Exception
MsgBox("No Connection Found, Make Sure The Device is
Plugged-In!", 16, " SMS ")
End Try
End Sub

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnSend.Click
Send_SMS_Notification(txRecipients.Text, txMessage.Text)
End Sub

Private Sub frmSMS_Shown(sender As Object, e As EventArgs) Handles


Me.Shown
Configure_SMS_Notification()
End Sub

Public Sub Configure_SMS_Notification()


Dim ports() As String
ports = Split(ModemsConnected(), "***")
For i As Integer = 0 To ports.Length - 2
ComboBox1.Items.Add(ports(i))
Next

STI College Puerto Princesa 113


If ComboBox1.Items.Count <> 0 Then
ComboBox1.SelectedIndex = 0
ComboBox1_SelectedValueChanged(Nothing, Nothing)
Button1_Click(Nothing, Nothing)
End If
End Sub

Public Sub Send_SMS_Notification(ByVal xRecipientx As String, ByVal


xMessagex As String)
If Label3.Text = "Not Connected!" Then MsgBox("Please check
modem connection!", 64, "SMS")
Try
With SerialPort1
.Write("at" & vbCrLf)
.Write("at+cmgf=1" & vbCrLf)
.Write("at+cmgs=" & Chr(34) & xRecipientx & Chr(34) &
vbCrLf)
.Write(xMessagex & Chr(26))
Threading.Thread.Sleep(1000)
End With
Catch ex As Exception
'LogsHistory("message failed")
'MsgBox("Message Successfully failed!", 64, "Sent")
Finally
'MsgBox("Message Successfully Sent!", 64, "Sent")
End Try
End Sub

End Class

frmRegistration

Imports MySql.Data.MySqlClient

Public Class frmRegistration


Dim QR_Generator As New MessagingToolkit.QRCode.Codec.QRCodeEncoder

Public arrImage() As Byte


Public loadpic As Boolean = False
Public sLoadImg As String

Public StudID As String

Private Sub LblClose_Click(sender As Object, e As EventArgs)


Handles LblClose.Click
Me.Hide()
End Sub

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles


btnSave.Click
Try
PicQR.Image = QR_Generator.Encode(txIDnum.Text)
Catch ex As Exception
MsgBox(ex.Message)
End Try

STI College Puerto Princesa 114


arrImage = ConvertImage(PicQR.Image)

If btnSave.Text = "Save" Then


CheckDuplicate()
If StudID = txIDnum.Text Then
Dim MsgBox_ As New frmCustomMessageBox("Duplicate ID
Number", My.Resources.MsgBoxStyle_Information, "Ok", "Cancel", False) :
Dim result = MsgBox_.ShowDialog() : Return
Return
End If

sql = "INSERT INTO tblstudent(Sidnum, Scourse, Syrlvl,


Sfname, Smidname, Slastname, Saddress, Sdateofb, Splaceofb, Scontnum,
Syear, Ssems, Sbarimg, StimeRem, Student_Date_Inputted) VALUES ('" &
txIDnum.Text & "','" & txCourse.Text & "','" & txYrlvl.Text & "','" &
txFname.Text & "','" & txMname.Text & "','" & txLname.Text & "','" &
txAddress.Text & "','" & txDateofb.Text & "','" & txPlaceofb.Text &
"','" & txContnum.Text & "','" & SchYear & "','" & Sschsem &
"',@File,'600','" & Format(Date.Now, "yyyy-MM-dd") & "')"
dbCom = New MySqlCommand
With dbCom
.CommandText = sql
.Connection = dbCon
.Parameters.AddWithValue("@File", arrImage)
.ExecuteNonQuery()
End With
Else
sql = "UPDATE tblstudent SET Sidnum='" & txIDnum.Text &
"',Scourse='" & txCourse.Text & "',Syrlvl='" & txYrlvl.Text &
"',Sfname='" & txFname.Text & "',Smidname='" & txMname.Text &
"',Slastname='" & txLname.Text & "',Saddress='" & txAddress.Text &
"',Sdateofb='" & txDateofb.Text & "',Splaceofb='" & txPlaceofb.Text &
"',Scontnum='" & txContnum.Text & "',Sbarimg=@File WHERE Sid='" &
frmMain.LvwStudents.FocusedItem.Text & "'"
dbCom = New MySqlCommand
With dbCom
.CommandText = sql
.Connection = dbCon
.Parameters.AddWithValue("@File", arrImage)
.ExecuteNonQuery()
End With
End If
Me.Close() : btnSave.Text = "Save" : frmMain.LvwLoad_Customer()
End Sub

Private Sub CheckDuplicate()


sql = "SELECT * FROM tblstudent WHERE Sidnum = '" &
txIDnum.Text & "'"
dbcom = New MySqlCommand(sql, dbcon)
dbread = dbcom.ExecuteReader()
While dbread.Read
StudID = dbread("Sidnum")
End While
dbread.Close()
End Sub
Public Sub LoadEdit()

STI College Puerto Princesa 115


sql = "SELECT * FROM tblstudent WHERE Sid = '" &
frmMain.LvwStudents.FocusedItem.Text & "'"
dbcom = New MySqlCommand(sql, dbcon)
dbread = dbcom.ExecuteReader()
While dbread.Read
txIDnum.Text = dbread(1) : txCourse.Text = dbread(2) :
txYrlvl.Text = dbread(3) : txFname.Text = dbread(4)
txMname.Text = dbread(5) : txLname.Text = dbread(6) :
txAddress.Text = dbread(7) : txDateofb.Text = dbread(8)
txPlaceofb.Text = dbread(9) : txContnum.Text = dbread(10)
End While
dbread.Close() : btnSave.Text = "Update"
End Sub
Public Sub SaveImageCapture(ByVal image As System.Drawing.Image)
arrImage = ConvertImage(PicQR.Image)
End Sub

Private Sub txIDnum_TextChanged(sender As Object, e As EventArgs)


Handles txIDnum.TextChanged
txStudnum.Text = txIDnum.Text
End Sub

Private Sub txCourse_SelectedIndexChanged(sender As Object, e As


EventArgs) Handles txCourse.SelectedIndexChanged
txCourseID.Text = txCourse.Text
End Sub

Private Sub txLname_TextChanged(sender As Object, e As EventArgs)


Handles txLname.TextChanged
txFullname.Text = txFname.Text & " " & txLname.Text
End Sub

Private Sub btnCancel_Click(sender As Object, e As EventArgs)


Handles btnCancel.Click
Dim msg As New frmCustomMessageBox("Are you sure you want to
cancel?", My.Resources.MsgBoxStyle_Question, "Yes", "No") : Dim result
= msg.ShowDialog()
If result = Windows.Forms.DialogResult.Yes Then
ClearFields(pnlMain) : Me.Hide()
ElseIf result = Windows.Forms.DialogResult.No Then
Me.Show()
Else
Me.Show()
End If
End Sub

End Class

frmReports

Imports Microsoft.Reporting.WinForms
Imports MySql.Data.MySqlClient

Public Class frmReports

STI College Puerto Princesa 116


Private Sub frmReports_Load(sender As Object, e As EventArgs)
Handles MyBase.Load
Me.rptViewer.RefreshReport()

If PrintPreviewReport = "List of Library ID's" Then


PrintPreview_Students_ID("SELECT * FROM tblstudent WHERE
Student_Date_Inputted BETWEEN '" & xShowDateFrom & "' AND '" &
xShowDateTo & "'")
Me.rptViewer.RefreshReport()
ElseIf PrintPreviewReport = "List of Students" Then
PrintPreview_Students("SELECT * FROM tblstudent WHERE
Student_Date_Inputted BETWEEN '" & xShowDateFrom & "' AND '" &
xShowDateTo & "' ORDER BY Sidnum ASC")
Me.rptViewer.RefreshReport()
ElseIf PrintPreviewReport = "List of Books" Then
PrintPreview_Books("SELECT * FROM tblbooks WHERE
Book_Received_Date BETWEEN '" & xShowDateFrom & "' AND '" & xShowDateTo
& "' ORDER BY BookID ASC")
Me.rptViewer.RefreshReport()
ElseIf PrintPreviewReport = "Students Logs" Then
PrintPreview_Purchase_Order("SELECT * FROM tblstudtime
WHERE Logs_Date BETWEEN '" & xShowDateFrom & "' AND '" & xShowDateTo &
"' ORDER BY Sid ASC")
Me.rptViewer.RefreshReport()
End If
Me.rptViewer.RefreshReport()

End Sub

Public Sub PrintPreview_Students_ID(ByVal sql As String)

Dim VarSemester As String = Nothing

Dim dIndex As New DataSet()


Dim dtIndex As New DataTable()
Dim dr As DataRow

Dim dc1 As New DataColumn("Sidnum",


Type.GetType("System.String"))
Dim dc2 As New DataColumn("Sfname",
Type.GetType("System.String"))
Dim dc3 As New DataColumn("Slastname",
Type.GetType("System.String"))
Dim dc4 As New DataColumn("Sbarimg",
Type.GetType("System.Object"))
Dim dc5 As New DataColumn("Scourse",
Type.GetType("System.Object"))

dtIndex.Columns.Add(dc1)
dtIndex.Columns.Add(dc2)
dtIndex.Columns.Add(dc3)
dtIndex.Columns.Add(dc4)
dtIndex.Columns.Add(dc5)

dbCom = New MySqlCommand(sql, dbCon)


dbRead = dbCom.ExecuteReader()

STI College Puerto Princesa 117


While dbRead.Read
dr = dtIndex.NewRow()
dr(0) = dbRead("Sidnum")
dr(1) = dbRead("Sfname")
dr(2) = dbRead("Slastname")
dr(3) = dbRead("Sbarimg")
dr(4) = dbRead("Scourse")
dtIndex.Rows.Add(dr)
End While
dbRead.Close()

dIndex.Tables.Add(dtIndex)

rptViewer.RefreshReport()
rptViewer.ProcessingMode =
Microsoft.Reporting.WinForms.ProcessingMode.Local
rptViewer.LocalReport.ReportPath = Environment.CurrentDirectory
+ "\StudentID.rdlc"

rptViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.Norma
l)

Dim rds As New


Microsoft.Reporting.WinForms.ReportDataSource("DataSet1",
dIndex.Tables(0))
rptViewer.LocalReport.DataSources.Clear()
rptViewer.LocalReport.DataSources.Add(rds)

rptViewer.LocalReport.Refresh()
rptViewer.DocumentMapCollapsed = True
rptViewer.RefreshReport()

LogsHistory("Generated a Students ID")


End Sub

Public Sub PrintPreview_Students(ByVal sql As String)

Dim VarSemester As String = Nothing

Dim dIndex As New DataSet()


Dim dtIndex As New DataTable()
Dim dr As DataRow

Dim dc1 As New DataColumn("Sidnums",


Type.GetType("System.String"))
Dim dc2 As New DataColumn("Sfullnames",
Type.GetType("System.String"))
Dim dc3 As New DataColumn("Scourses",
Type.GetType("System.String"))
Dim dc4 As New DataColumn("Syrlvls",
Type.GetType("System.String"))
Dim dc5 As New DataColumn("Scontnum",
Type.GetType("System.String"))

dtIndex.Columns.Add(dc1)
dtIndex.Columns.Add(dc2)

STI College Puerto Princesa 118


dtIndex.Columns.Add(dc3)
dtIndex.Columns.Add(dc4)
dtIndex.Columns.Add(dc5)

dbCom = New MySqlCommand(sql, dbCon)


dbRead = dbCom.ExecuteReader()

While dbRead.Read
dr = dtIndex.NewRow()
dr(0) = dbRead("Sidnum")
dr(1) = dbRead("Sfname") & " " & dbRead("Slastname")
dr(2) = dbRead("Scourse")
dr(3) = dbRead("Syrlvl")
dr(4) = dbRead("Scontnum")

dtIndex.Rows.Add(dr)
End While
dbRead.Close()

dIndex.Tables.Add(dtIndex)

rptViewer.RefreshReport()
rptViewer.ProcessingMode =
Microsoft.Reporting.WinForms.ProcessingMode.Local
rptViewer.LocalReport.ReportPath = Environment.CurrentDirectory
+ "\List of Students.rdlc"

rptViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.Norma
l)

Dim rds As New


Microsoft.Reporting.WinForms.ReportDataSource("dsReports",
dIndex.Tables(0))
rptViewer.LocalReport.DataSources.Clear()
rptViewer.LocalReport.DataSources.Add(rds)

rptViewer.LocalReport.Refresh()
rptViewer.DocumentMapCollapsed = True
rptViewer.RefreshReport()

LogsHistory("Generated a Students List")


End Sub

Public Sub PrintPreview_Books(ByVal sql As String)

Dim VarSemester As String = Nothing

Dim dIndex As New DataSet()


Dim dtIndex As New DataTable()
Dim dr As DataRow

Dim dc1 As New DataColumn("Book_accesion_number",


Type.GetType("System.String"))
Dim dc2 As New DataColumn("Book_tittle",
Type.GetType("System.String"))

STI College Puerto Princesa 119


Dim dc3 As New DataColumn("Book_autor",
Type.GetType("System.String"))
Dim dc4 As New DataColumn("Book_edition",
Type.GetType("System.String"))
Dim dc5 As New DataColumn("Book_publisher",
Type.GetType("System.String"))

dtIndex.Columns.Add(dc1)
dtIndex.Columns.Add(dc2)
dtIndex.Columns.Add(dc3)
dtIndex.Columns.Add(dc4)
dtIndex.Columns.Add(dc5)

dbCom = New MySqlCommand(sql, dbCon)


dbRead = dbCom.ExecuteReader()

While dbRead.Read
dr = dtIndex.NewRow()
dr(0) = dbRead("Book_accesion_number")
dr(1) = dbRead("Book_tittle")
dr(2) = dbRead("Book_autor")
dr(3) = dbRead("Book_edition")
dr(4) = dbRead("Book_publisher")

dtIndex.Rows.Add(dr)
End While
dbRead.Close()

dIndex.Tables.Add(dtIndex)

rptViewer.RefreshReport()
rptViewer.ProcessingMode =
Microsoft.Reporting.WinForms.ProcessingMode.Local
rptViewer.LocalReport.ReportPath = Environment.CurrentDirectory
+ "\List of Books.rdlc"

rptViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.Norma
l)

Dim rds As New


Microsoft.Reporting.WinForms.ReportDataSource("dsReports",
dIndex.Tables(0))
rptViewer.LocalReport.DataSources.Clear()
rptViewer.LocalReport.DataSources.Add(rds)

rptViewer.LocalReport.Refresh()
rptViewer.DocumentMapCollapsed = True
rptViewer.RefreshReport()

LogsHistory("Generated a Books List")


End Sub

Public Sub PrintPreview_Purchase_Order(ByVal sql As String)


Dim VarGrandTotal As Integer = Nothing

Dim dIndex As New DataSet()


Dim dtIndex As New DataTable()

STI College Puerto Princesa 120


Dim dr As DataRow

Dim dc1 As New DataColumn("Sidnumx",


Type.GetType("System.String"))
Dim dc2 As New DataColumn("Sfullnamex",
Type.GetType("System.String"))
Dim dc3 As New DataColumn("Syearlvlx",
Type.GetType("System.String"))
Dim dc4 As New DataColumn("Scoursex",
Type.GetType("System.String"))
Dim dc5 As New DataColumn("Stimeinx",
Type.GetType("System.String"))
Dim dc6 As New DataColumn("Stimeoutx",
Type.GetType("System.String"))
Dim dc7 As New DataColumn("SRemainingx",
Type.GetType("System.String"))
Dim dc8 As New DataColumn("sDatesssss",
Type.GetType("System.String"))

dtIndex.Columns.Add(dc1)
dtIndex.Columns.Add(dc2)
dtIndex.Columns.Add(dc3)
dtIndex.Columns.Add(dc4)
dtIndex.Columns.Add(dc5)
dtIndex.Columns.Add(dc6)
dtIndex.Columns.Add(dc7)
dtIndex.Columns.Add(dc8)

Dim x_sql As String = sql, TransactionsPO As New List(Of


String)

dbCom = New MySqlCommand(sql, dbCon)


dbRead = dbCom.ExecuteReader()

While dbRead.Read
TransactionsPO.Add(dbRead("Sidnum"))
End While
dbRead.Close()

Dim POchecking As List(Of KeyValuePair(Of String, Integer)) =


New List(Of KeyValuePair(Of String, Integer))

For Each POs As String In TransactionsPO


sql = "SELECT StimeRem FROM tblstudent WHERE Sidnum='" &
POs.ToString & "'"
dbCom = New MySqlCommand(sql, dbCon)
dbRead = dbCom.ExecuteReader()

While dbRead.Read
If POchecking.Contains(New KeyValuePair(Of String,
Integer)(POs.ToString, dbRead("StimeRem"))) Then

Else
POchecking.Add(New KeyValuePair(Of String,
Integer)(POs.ToString, dbRead("StimeRem")))
End If
End While

STI College Puerto Princesa 121


dbRead.Close()
Next

dbCom = New MySqlCommand(x_sql, dbCon)


dbRead = dbCom.ExecuteReader()

While dbRead.Read
Dim CheckedPO As String = Nothing

dr = dtIndex.NewRow()
dr(0) = dbRead("Sidnum")
CheckedPO = dbRead("Sidnum")
For Each POGrandTotal As KeyValuePair(Of String, Integer)
In POchecking
Dim POwithTotal As String = POGrandTotal.Key,
POwithTotal2 As Integer = POGrandTotal.Value
If POwithTotal = CheckedPO Then
VarGrandTotal = POwithTotal2
End If
Next
dr(1) = dbRead("Sfullname")
dr(2) = dbRead("Scourse")
dr(3) = dbRead("Syearlvl")
dr(4) = dbRead("Stimein")
dr(5) = dbRead("Stimeout")
dr(6) = dbRead("Scontime")
dr(7) = Format(dbRead("Logs_Date"), "yyyy-MM-dd")

dtIndex.Rows.Add(dr)
End While
dbRead.Close()

dIndex.Tables.Add(dtIndex)

rptViewer.RefreshReport()
rptViewer.ProcessingMode =
Microsoft.Reporting.WinForms.ProcessingMode.Local
rptViewer.LocalReport.ReportPath = Environment.CurrentDirectory
+ "\Students Logs.rdlc"

rptViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.Norma
l)

Dim rds As New


Microsoft.Reporting.WinForms.ReportDataSource("dsReports",
dIndex.Tables(0))
rptViewer.LocalReport.DataSources.Clear()
rptViewer.LocalReport.DataSources.Add(rds)

rptViewer.LocalReport.Refresh()
rptViewer.DocumentMapCollapsed = True
rptViewer.RefreshReport()

LogsHistory("Generated a Students Logs")


End Sub

STI College Puerto Princesa 122


Private Sub Report_rds(ByVal ReportViewer As ReportViewer, ByVal
Index As DataSet, ByVal NameRDLC As String)

ReportViewer.RefreshReport()
ReportViewer.ProcessingMode =
Microsoft.Reporting.WinForms.ProcessingMode.Local
ReportViewer.LocalReport.ReportPath =
Environment.CurrentDirectory + NameRDLC

ReportViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.No
rmal)

Dim rds As New


Microsoft.Reporting.WinForms.ReportDataSource("dsReports",
Index.Tables(0))
ReportViewer.LocalReport.DataSources.Clear()
ReportViewer.LocalReport.DataSources.Add(rds)

ReportViewer.LocalReport.Refresh()
ReportViewer.DocumentMapCollapsed = True
ReportViewer.RefreshReport()

End Sub

Private Sub LblClose_Click(sender As Object, e As EventArgs)


Handles LblClose.Click
Me.Hide()
End Sub

End Class

frmReportSelector

Public Class frmReportSelector

Private Sub btnUndock_Click(sender As Object, e As EventArgs)


Handles btnUndock.Click

xShowDateFrom = Format(dtpFrom.Value, "yyyy-MM-dd")


xShowDateTo = Format(dtpTo.Value, "yyyy-MM-dd")

If cbType.Text = "Monthly Reports" Then


xShowDateFrom = Format(dtpFrom.Value, "yyyy-MM") & "-01"
xShowDateTo = Format(dtpTo.Value, "yyyy-MM") & "-31"
ElseIf cbType.Text = "Yearly Reports" Then
xShowDateFrom = dtpFrom.Text & "-01-01"
xShowDateTo = dtpTo.Text & "-12-31"
End If

PrintPreviewReport = cbReport.Text
frmReports.ShowDialog()

End Sub

Private Sub LblClose_Click(sender As Object, e As EventArgs)


Handles LblClose.Click

STI College Puerto Princesa 123


Me.Hide()
End Sub

Private Sub cbType_SelectedIndexChanged(sender As Object, e As


EventArgs) Handles cbType.SelectedIndexChanged, cbType.DropDown
If cbType.Text = "Daily Reports" Then
dtpFrom.CustomFormat = "MMMMM dd, yyyy"
dtpTo.Enabled = False
ElseIf cbType.Text = "Weekly Reports" Then
dtpTo.Enabled = True
dtpFrom.CustomFormat = "MMMMM dd, yyyy"
dtpTo.Value = dtpFrom.Value.AddDays(7)
dtpTo.Enabled = False
ElseIf cbType.Text = "Monthly Reports" Then
dtpFrom.CustomFormat = "MMMMM yyyy"
dtpTo.CustomFormat = "MMMMM yyyy"
ElseIf cbType.Text = "Yearly Reports" Then
dtpFrom.CustomFormat = "yyyy"
dtpTo.CustomFormat = "yyyy"
dtpTo.Enabled = False
ElseIf cbType.Text = "Date Range" Then
dtpFrom.CustomFormat = "MMMMM dd, yyyy"
dtpTo.CustomFormat = "MMMMM dd, yyyy"
dtpFrom.Enabled = True
dtpTo.Enabled = True
End If
End Sub

Private Sub dtpFrom_ValueChanged(sender As Object, e As EventArgs)


Handles dtpFrom.ValueChanged
If cbType.Text = "Daily Reports" Then
dtpTo.Value = dtpFrom.Value.AddDays(0)
ElseIf cbType.Text = "Weekly Reports" Then
dtpTo.Value = dtpFrom.Value.AddDays(7)
ElseIf cbType.Text = "Monthly Reports" Then
dtpTo.Value = dtpFrom.Value.AddMonths(0)
ElseIf cbType.Text = "Yearly Reports" Then
dtpTo.Value = dtpFrom.Value.AddYears(0)
End If
End Sub

End Class

STI College Puerto Princesa 124