Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

Source Code

Automated Voting System


dbConnect.php
<?php $conn = mysqli_connect("localhost","admin","MLGCL","dbvoting");
if(!$conn){die("Connection Failed:" .mysqli_connect_error());}?>

Login.php
<?php session_start(); include 'DBConnect.php'; $uid = $_POST['uid']; $pwd =
$_POST['pwd']; $sql = "SELECT * FROM tblstudentaccount WHERE Student_ID='$uid'
AND StudentPassword='$pwd'"; $result = $conn->query($sql); if (!$row = $result-
>fetch_assoc()){ echo "Username or Password is incorrect!";
//header("location:index.php"); }else{ $_SESSION['id']=$row['id']; $id=$_GET['id'];
$sql="select * FROM tblstudentaccount WHERE Student_ID='$id'"; $result = $conn-
>query($sql); for($i=0; $rows = $result->fetch_assoc();
$i++){}header("location:list.php");} ?>

Vote.php
<html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible"
content="IE=edge"><meta name="viewport" content="width=device-width, initial-
scale=1"><meta name="description" content=""><meta name="author" content="">
<?php include 'dbcon.php'; $sid = $_GET['e']; $sqlname = "SELECT * FROM
tblstudentinfo WHERE `Student ID`='$sid' ";$resultname=$connect->query($sqlname);
for($i=0; $rowname=$resultname->fetch_assoc(); $i++){?><title>WELCOME <?php
echo $rowname['First Name'];?> <?php echo $rowname['Last
Name'];?></title><?php}?><link rel="icon" type="image/png" href="favicon.png"
/><link href="style.css" rel="stylesheet"><!--<link href="css/vote.css" rel="stylesheet">-
-><link href="font-awesome.css" rel="stylesheet"><!--sa pop up--><link
href="Admin/src/facebox.css" media="screen"
rel="stylesheet"type="text/css"/><scriptsrc="Admin/lib/jquery.js"type="text/javascript">
</script><scriptsrc="Admin/src/facebox.js"type="text/javascript"></script><script src=
"js/jquery 3.1.1.min.js" type="text/javascript"></script><style class="csscreations">
/*basic reset* * {margin: 0; padding: 0;}html {height: 100%;background: #ffffff}body
{font-family: montserrat, arial, verdana;}/*form styles*/#msform {margin-
top:2%;margin-left:28%;margin-right:32%; text-align: center;position: relative;}#msform
fieldset {margin-bottom:10%;background: white;border: 0 none;border-radius: 3px;box-
shadow: 0 0 15px 1px #5ebcf2;padding: 5%;text-align: left;-moz-box-sizing: border-
box;width: 100%;/*stacking fieldsets above each other*/position: absolute;}#msform
label{/*float:left;*/margin-right:10px;}#msform .wrapper{/*display:inline-block;*//*new
code*/float: left;/*width:100%;*//*new code*/width: 44%;height:auto;margin-
bottom:10%;}#msform p.cname{/*padding-top:11%;*//*new code*/position:
relative;top:30px;}#msform label > input{ visibility:hidden; position:absolute;} #msform
label img.check{width:80px; visibility:hidden;margin-left:-105px;margin-bottom:-
10px;position:relative;}#msform label > input + img{ cursor:pointer;border:2px solid
transparent;}#msform label > input:checked + img + img.check{/*border:2px solid
blue;*/margin-left:-105px;/*margin-bottom:55px;*/visibility:visible;/*z-index:10;*/
margin-top:-75px;vertical-align: middle;/*position: relative;*/-webkit-
appearance:none;}#msform fieldset img{border-radius:50%;position: relative;left:
40px;}/*Hide all except first fieldset*/#msform fieldset:not(:first-of-type) {display:
none;}/*inputs*/#msform input, #msform textarea, #msform select {padding: 15px;border:
1px solid #ccc;border-radius: 3px;margin-bottom: 10px;width: 100%; -moz-box-sizing:
border-box;color: #2C3E50;font-size: 13px;}/*buttons*/#msform .action-button {width:
100px;background: #22b561;font-weight: bold;color: white; border:0 none;border-radius:
1px;cursor: pointer;padding: 10px 5px; margin: 10px 5px;}#msform .action-button:hover,
#msform .action-button:focus { box-shadow: 0 0 0 2px white, 0 0 0 3px
#27AE60;}#msform #submit {width: 100px; background: #22b561;font-weight:
bold;color: white;border: 0 none;border-radius: 1px; cursor: pointer;padding: 10px
5px;margin: 10px 5px;}#msform #submit:hover, #msform #submit:focus {box-shadow: 0
0 0 2px white, 0 0 0 3px #27AE60;}/*headings*/.fs-title { font-size: 15px;text-transform:
uppercase;color: #2C3E50;margin-bottom: 10px;}.fs-subtitle {font-weight: normal;font-
size: 13px;color: #666;margin-bottom: 20px;}/*progressbar*/#progressbar {margin-
bottom: 30px;overflow: hidden;/*CSS counters to number the steps*/counter-reset:
step;width: 100%;text-align: center;} #progressbar li {list-style-type: none;color:
white;text-transform: uppercase;font-size: 9px;width: 9.1%;float: left;position:
relative;text-align: center;}#progressbar li:before { content: counter(step);counter-
increment: step;width: 20px;line-height: 20px;display: block;font-size: 10px;color:
#333;background: white;border-radius: 3px;margin: 0 auto 5px auto;}/*progressbar
connectors*/#progressbar li:after {content: '';width: 100%;height: 2px;background:
white;position: absolute;left: -50%;top: 9px;z-index: -1; /*put it behind the
numbers*/}#progressbar li:first-child:after {/*connector not needed before the first
step*/content: none;}/*marking active/completed steps green*//*The number of the step
and the connector before it = green*/#progressbar li.active:before, #progressbar
li.active:after{background: #27AE60;color: white;}#logo {margin: 25px auto;width:
500px;}#logo img {float: left;}.clearfix {clear: both;}#logo span {display: inline-
block;font-size: 17px;vertical-align: middle;margin-top: 34px;color: #000000;}/* Ipad
@media (max-width: 1024px) {#msform {margin:0;padding:0;margin-
left:15%;}#msform fieldset{margin:2%;margin-bottom:5%;width: 65%;}}/* WXGA
Windows Phone Portrait@media (max-width: 768px) {#msform .wrapper{display: inline-
block; float: none;width: 100%}#msform p.cname{padding-top: 11%;position:
static;/*top:0;*/}#msform label{float: left;}#msform fieldset img{position: relative;left: 0;
}#msform {margin:0;padding:0;margin-left:5%;}#msform fieldset{margin:2%;margin-
bottom:5%;width: 80%;}}/* DVGA Iphone Portrait*/@media (max-width: 640px) {
#msform {margin:0;padding:0;margin-left:4%;}#msform fieldset{margin:2%;margin-
bottom:5%;width: 80%;}}/* Mobile View Portrait*/@media (max-width: 480px) {
#msform {margin:0; padding:0; width: 100%; } #msform fieldset{ margin:2%; margin-
bottom:5%; width: 85%; } } #clor{ width: 80%; } </style> <script type="text/javascript">
jQuery(document).ready(function($) { $('a[rel*=facebox]').facebox({ loadingImage
: 'src/loading.gif', closeImage : 'src/closelabel.png' }) }) </script> <script
type="text/javascript"> function UpdateCost() { var sum = 0; var gn, elem; for (i=0;
i<<?php echo $wapakpak?>;i++){gn = 'sum_m_'+i;elem= document.getElementById(gn);
if (elem.checked == true) { sum += 1; } //if (elem.checked == true) { sum +=
Number(elem.value); } } document.getElementById('totalcost' ).value = sum.toFixed(0);
} window.onload=UpdateCost </script> <script type="text/javascript">
$(document).ready(function () { $("input[name='Councilor[]']").change(function () {
var maxAllowed=$("#sel").val();var cnt = $("input[name='Councilor[]']:checked").length;
if (cnt > maxAllowed) {$(this).prop("checked", ""); alert('Select Only ' + maxAllowed + '
Candidates'); } }); }); </script> </head> <body> <!-- multistep form --> <form
id="msform" name="joe" action="preview.php" method="POST" onsubmit="return
sapatka()"> <!-- progressbar --> <!-- fieldsets --> <?php include 'DBConnect.php';
$sql="SELECT * FROM tblposition Order by Precedence"; $resultasa = $conn-
>query($sql); for($i=0; $rowasa = $resultasa->fetch_assoc(); $i++){
$exrxrxrx=$rowasa['Position']; if($exrxrxrx=='President'){ ?> <fieldset> <?php
include('DBConnect.php'); $dept=$_GET['d']; // var_dump($_GET); $studid =
$_GET['e']; // var_dump($dept); // $dept = rtrim($dept,$studid); // var_dump($dept); ?>
<h2 class="fs-title" style="color:#4a90db"><?php echo $studid; ?></h2><br> <input type
= "hidden" name = "department" value = "<?php echo $dept; ?>"> <input type = "hidden"
name = "student" value = "<?php echo $studid; ?>"> <h2 class="fs-title"><?php echo
$rowasa['Position']; ?></h2><br> <h3 class="fs-subtitle">Pls. Select Only One</h3>
<?php //echo $dept; $pos = $rowasa['Position']; // var_dump($dept); // var_dump($pos);
$sql="SELECT * FROM tblcandidates WHERE Department = '$dept' AND Position =
'$pos' "; $result = $conn->query($sql); for($i=0; $rows = $result->fetch_assoc(); $i++){
?> <div class="wrapper"> <label><INPUT TYPE="radio" NAME="<?php echo
$rows['Position']; ?>" value="<?php echo $rows['Name']; ?>" id="sum_m_<?php echo $i
?>" onclick="UpdateCost()" style="width: 21px;"> <img src="admin/candidates/<?php
echo $rows['image']; ?>" width="110" height="110" style="margin-bottom: -26px;" />
<img class="check" src="PictureAdmin/pic.png" alt="check"> </label> <p
class="cname"><?php echo $rows['Candidate_ID']; ?> - <?php echo $rows['Name']; ?> -
<?php echo $rows['Party']; ?></p> </div> <?php } ?> <br><br> <div style =
"clear:both;"></div> <input type="button" value="Next" class="next action-button"
name="next" id="n"> </fieldset> <?php } if(($exrxrxrx!='President') AND
($exrxrxrx!='Representative') AND ($exrxrxrx!='Councilor')){ ?> <fieldset> <?php
$dept=$_GET['d']; $studid = $_GET['e']; //$studid = substr($dept,-9); //$dept =
rtrim($dept,$studid); ?> <h2 class="fs-title" style="color:#4a90db"><?php echo $studid;
?></h2><br> <h2 class="fs-title"><?php echo $rowasa['Position']; ?></h2><br> <h3
class="fs-subtitle">Pls. Select Only One</h3> <?php include('DBConnect.php');
//$dept=$_GET['d']; $pos = $rowasa['Position']; $sql="SELECT * FROM tblcandidates
WHERE Department = '$dept' AND Position = '$pos' "; $result = $conn->query($sql);
for($i=0; $rows = $result->fetch_assoc(); $i++){ ?> <div class="wrapper">
<label><INPUT TYPE="radio" NAME="<?php echo $rows['Position']; ?>"
value="<?php echo $rows['Name']; ?>" id="sum_m_<?php echo $i ?>"
onclick="UpdateCost()" style="width: 21px;"> <img src="admin/candidates/<?php echo
$rows['image']; ?>" width="110" height="110" style="margin-bottom: -26px;" /> <img
class="check" src="PictureAdmin/pic.png"> </label> <p class="cname"><?php echo
$rows['Candidate_ID']; ?> - <?php echo $rows['Name']; ?> - <?php echo $rows['Party'];
?></p> </div> <?php } ?> <br><br> <div style = "clear:both;"></div> <input
type="button" value="Previous" class="previous action-button" name="previous"> <input
type="button" value="Next" class="next action-button" name="next" id="n"> </fieldset>
<?php } if($exrxrxrx=='Councilor'){ ?> <fieldset id = "clor" name="frm"> <input type =
"hidden" id = "sel" value = "<?php echo $rowasa['NumVotes']; ?>"> <?php
$dept=$_GET['d']; $studid = $_GET['e']; //$studid = substr($dept,-9); //$dept =
rtrim($dept,$studid); ?> <h2 class="fs-title" style="color:#4a90db"><?php echo $studid;
?></h2><br> <h2 class="fs-title">Councilor</h2> <h3 class="fs-subtitle">Pls. Select
Only 6 <span id="payment-total"></span></span></h3> <?php
include('DBConnect.php'); //$dept=$_GET['d']; $council=$rowasa['Position'];
$sql="SELECT * FROM tblcandidates WHERE Department = '$dept' AND
position='$council'"; $result = $conn->query($sql); for($i=0; $rows = $result-
>fetch_assoc(); $i++){ ?> <div class="wrapper"> <label><INPUT TYPE="checkbox"
NAME="Councilor[]" class = "votes" value="<?php echo $rows['Name']; ?>"
onclick="chkcontrol(<?php echo $i; ?>)" id="sum_m_<?php echo $i ?>"
onclick="UpdateCost()" style="width: 21px;"> <img src="admin/candidates/<?php echo
$rows['image']; ?>" width="110" height="110" style="margin-bottom: -26px;" /> <img
class="check" src="PictureAdmin/pic.png"> </label> <p class="cname"><?php echo
$rows['Candidate_ID']; ?> - <?php echo $rows['Name']; ?> - <?php echo $rows['Party'];
?> </div> <?php } ?> <div style = "clear:both;"></div> <input type="button"
value="Previous" class="previous action-button" name="previous"> <input type="button"
value="Next" class="next action-button" name="next" onclick="sapatka()"> <input
type="hidden" name="sen" id="totalcost" value=""> </fieldset> <?php }
if($exrxrxrx=='Representative'){ ?> <fieldset> <?php $dept=$_GET['d']; $studid =
$_GET['e']; //$studid = substr($dept,-9); //$dept = rtrim($dept,$studid); ?> <h2 class="fs-
title" style="color:#4a90db"><?php echo $studid; ?></h2><br> <h2 class="fs-
title"><?php echo $rowasa['Position']; ?></h2> <h3 class="fs-subtitle">Pls. Select Only
One</h3> <?php include('DBConnect.php'); //$dept=$_GET['d'];
$dsds=$rowasa['Position']; $sql="SELECT * FROM tblcandidates WHERE Department
= '$dept' AND Position= '$dsds' "; $result = $conn->query($sql); for($i=0; $rows = $result-
>fetch_assoc(); $i++){ ?> <div class="wrapper"> <label><INPUT TYPE="radio"
NAME="<?php echo $rows['Position']; ?>" value="<?php echo $rows['Name']; ?>"
id="sum_m_<?php echo $i ?>" onclick="UpdateCost()" style="width: 21px;"> <img
src="admin/candidates/<?php echo $rows['image']; ?>" width="110" height="110"
style="margin-bottom: -26px;" /> <img class="check" src="PictureAdmin/pic.png">
</label> <?php echo $rows['Candidate_ID']; ?> - <?php echo $rows['Name']; ?> - <?php
echo $rows['Party']; ?> </div> <?php } ?> <br><br> <input type="button"
value="Previous" class="previous action-button" name="previous"> <input type="button"
value="Next" class="next action-button" name="next" id="n"> </fieldset> <?php } } ?>
<fieldset> <h2 class="fs-title">You Are now About to Submit you votes</h2><br>
<p>Please note that once you sumbit your votes, it cannot be changed</p><br> <input
type="button" value="Previous" class="previous action-button" name="previous"> <input
type="submit" value="Submit" name="submit" id="submit"> </fieldset> </form> <!--
jQuery --> <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script> <!--
jQuery easing plugin--><scripttype="text/javascript" src="js/jquery.easing.min.js">
</script> <script>//jQuery time var current_fs, next_fs, previous_fs; //fieldsets var left,
opacity, scale; //fieldset properties which we will animate var animating; //flag to prevent
quick multi-click glitches $(".next").click(function(){ if(animating) return false;
animating = true; current_fs = $(this).parent(); next_fs = $(this).parent().next(); //activate
next step on progressbar using the index of next_fs $("#progressbar
li").eq($("fieldset").index(next_fs)).addClass("active"); //show the next fieldset
next_fs.show(); //hide the current fieldset with style current_fs.animate({opacity: 0}, {
step: function(now, mx) { //as the opacity of current_fs reduces to 0 - stored in "now" //1.
scale current_fs down to 80% scale = 1 - (1 - now) * 0.2; //2. bring next_fs from the
right(50%) left = (now * 50)+"%"; //3. increase opacity of next_fs to 1 as it moves in
opacity = 1 - now; current_fs.css({'transform': 'scale('+scale+')'}); next_fs.css({'left': left,
'opacity': opacity}); }, duration: 800, complete: function(){ current_fs.hide(); animating =
false; }, //this comes from the custom easing plugin easing: 'easeInOutBack' }); });
$(".previous").click(function(){ if(animating) return false; animating = true; current_fs =
$(this).parent(); previous_fs = $(this).parent().prev(); //de-activate current step on
progressbar$("#progressbarli").eq($("fieldset").index(current_fs)).removeClass("active");
//show the previous fieldset previous_fs.show(); //hide the current fieldset with style
current_fs.animate({opacity: 0}, { step: function(now, mx) { //as the opacity of current_fs
reduces to 0 - stored in "now" //1. scale previous_fs from 80% to 100% scale = 0.8 + (1 -
now) * 0.2; //2. take current_fs to the right(50%) - from 0% left = ((1-now) * 50)+"%"; //3.
increase opacity of previous_fs to 1 as it moves in opacity = 1 - now; current_fs.css({'left':
left}); previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity}); }, duration: 800,
complete: function(){ current_fs.hide(); animating = false; }, //this comes from the custom
easing plugin easing: 'easeInOutBack' }); }); $(".submit").click(function(){ return false;
}) </script> </body> </html>

AdminConsole.php
<!doctype html><html><head> <meta charset="utf-8"> <meta http-equiv="X-UA-
Compatible" content="IE=edge"> <meta name="viewport" content="width=device-
width, initial-scale=1"> <meta name="description" content=""> <meta name="author"
content=""> <title>Voting Sytem</title> <!-- Custom CSS --> <link href="style.css"
rel="stylesheet"> <link href="font-awesome.css" rel="stylesheet">
</head><body><header class="nav-brand"> <div class="nav-header"> <div
class="welcome"> <span>Howdy! </span> <a href="#"><img alt="Account Image"
src="icons/user.png"width="20px;"height="20px;"></a></div><divclass="log_out_toggl
e"> <ul> <li>Log out</li> </ul> </div> </div> </head><nav class="main-nav"> <ul
class="main-nav-ul"> <li class="nav-logo"> <a href="AdminConsole.html">Logo
Here</a> </li> <span class="nav_navigation"> <li><a
href="AdminConsole.php">Dashboard</a></li><li><a href="#">Results</a></li><li><a
href="#">Candidates</a></li><li><a href="#">Parties</a></li><li><a href="#">
Department </a></li> <li><a href="Registration.php">Student Information</a></li>
<li><a href="AdminAccount.php">Admin Account</a></li> <li><a
href="#">Position</a></li> <li><a href="#">Settings<span class="sub-
arrow"></span></a> <ul> <li><a href="ChangePassword.php">Change
Password</a></li> <li><a href="AddAccount.php">Add voter's Account</a></li> </ul>
</li> </span> </ul></nav><div class="content1"> <!-- Section Article --> <article
class="topcontent"> <h2> <a href="#" title="Logo">Logo</a> </h2> <h2>Results
Page</h2> </article> </div> </body>
VotesVerification.vb

Imports MySql.Data.MySqlClientPublic Class VotesVerification Implements


DPFP.Capture.EventHandler Dim strSQL As String Public Capturer As
DPFP.Capture.Capture = New DPFP.Capture.Capture() Private Enroller As
DPFP.Processing.Enrollment = New DPFP.Processing.Enrollment() Dim Template As
New DPFP.Template Public FingerprintSample As DPFP.Sample Private Sub
VotesVerification_FormClosed(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed End End Sub
Private Sub VotesVerification_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load FormSkin1.Dock = DockStyle.Fill
LoadPositions() LoadCurrentSYSem() lblTimeDate.Text = Now
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False If (Not
Capturer Is Nothing) Then Capturer.EventHandler = Me Capturer.StartCapture() End If If
lblElectionStatus.Text <> "OPEN" Then lblInformation.Text = "The election is closed.
Authentication is disabled" Exit Sub End If End Sub Private Sub LoadCurrentSYSem()
strSQL = "Select * from tblElection" dtdataCOMMAND = New MySqlCommand(strSQL,
cnVoting) dtDataReader = dtdataCOMMAND.ExecuteReader Do While
dtDataReader.Read lblSchoolYear.Text = dtDataReader.Item("SchoolYear")
lblSemester.Text = dtDataReader.Item("Semester") lblElectionStatus.Text =
dtDataReader.Item("ElectionStatus") Loop dtDataReader.Close() End Sub Sub
OnComplete(ByVal Capture As Object, ByVal ReaderSerialNumber As String, ByVal
Sample As DPFP.Sample) Implements DPFP.Capture.EventHandler.OnComplete
LoadCurrentSYSem() If lblElectionStatus.Text <> "OPEN" Then lblInformation.Text =
"The Election is CLOSED. Authentication is disabled." Exit Sub End If
Capturer.StopCapture() lblInformation.Text = "Authenticating fingerprint signature,
please wait..." ' Process the sample and create a feature set for the enrollment purpose. Dim
features As DPFP.FeatureSet = ExtractFeatures(Sample,
DPFP.Processing.DataPurpose.Verification) Dim Verificator = New
DPFP.Verification.Verification() ' If lblAttendanceTitle.Text = "Waiting for the scheduled
time..." Then Exit Sub features = ExtractFeatures(Sample,
DPFP.Processing.DataPurpose.Verification) ListEvents.Items.Insert(0, "The fingerprint
sample was captured.") Dim StudentID As String = "" Dim strStudentExist As String =
isFingerPrintExist(features, StudentID) If StudentID <> "" Then lblStudentID.Text =
StudentID If CheckVotes(StudentID) = False Then DisplayMessage("Sorry, you have no
votes to verified. Please log in to the voting system first and select your candidate.", 5) End
If Else ClearInfo() lblStudentID.Text = "" DisplayMessage("Your fingerprint is not
enrolled to the system or to the current school year and semester.", 5) PicStudent.Image =
picUnknown.Image End If Capturer.StartCapture() End Sub Private Function
isFingerPrintExist(ByVal features As DPFP.FeatureSet, Optional ByRef StudentID As
String = "") As String Dim Verificator = New DPFP.Verification.Verification() Dim result
= New DPFP.Verification.Verification.Result Dim DBTemplate As New DPFP.Template
Dim limit As Integer = 1 Dim isNotEOF As Boolean = True Dim strSQL As String =
"Select `School Year`, Semester, tblenrollment.`Student ID`, tblstudentinfo.`Last Name`,
tblStudentInfo.`First Name`, tblStudentInfo.`Middle Name`, tblstudentinfo.fingerprint,
tblstudentinfo.picture, tblenrollment.department, `Course Enrolled` From tblEnrollment "
& _ "INNER JOIN tblStudentInfo On tblEnrollment.`Student ID` =
tblStudentInfo.`Student ID` " & " where `school year` = '" & lblSchoolYear.Text & "' and
semester='" & lblSemester.Text & "' " & _ "order by department asc, `Course Enrolled`
asc, tblstudentinfo.`last name` asc" dtdataCOMMAND = New MySqlCommand(strSQL,
cnAttendance) dtDataReader = dtdataCOMMAND.ExecuteReader Dim MemStream As
IO.MemoryStream Dim fpBytes As Byte() Dim strStudent As String = "" While
dtDataReader.Read() fpBytes = dtDataReader.Item("FINGERPRINT") StudentID =
dtDataReader.Item("Student ID") strStudent = "[" & dtDataReader.Item("student id") & "]
- " & dtDataReader.Item("Last Name") & ", " & dtDataReader.Item("First Name")
MemStream = New IO.MemoryStream(fpBytes)
DBTemplate.DeSerialize(dtDataReader.Item("Fingerprint")) Verificator.Verify(features,
DBTemplate, result) If result.Verified Then Try Dim arrImage() As Byte arrImage =
dtDataReader.Item("Picture") Dim mstream As New
System.IO.MemoryStream(arrImage) PicStudent.Image = Image.FromStream(mstream)
Catch ex As Exception MsgBox(ex.Message) PicStudent.Image = picBlank.Image End Try
dtDataReader.Close() Return strStudent Exit Function Else StudentID = "" End If End
While dtDataReader.Close() Return Nothing End Function Private Function
CheckVotes(ByVal StudentID As String) As Boolean strSQL = "Select * from tblvotes
where student_id='" & StudentID & "'" dtdataCOMMAND = New
MySqlCommand(strSQL, cnVoting) dtDataReader = dtdataCOMMAND.ExecuteReader
Dim isVoteExist As Boolean = False Dim VerificationStatus As String = ""
lstStudentVotes.Items.Clear() Do While dtDataReader.Read VerificationStatus =
dtDataReader.Item("Verification") isVoteExist = True Loop dtDataReader.Close() If
isVoteExist = True Then If UCase(VerificationStatus) = "NOT VERIFIED" Then
'VERIFY THE VOTE strSQL = "Update tblVotes set Verification='Verified' where
Student_ID='" & lblStudentID.Text & "' and Verification='Not Verified'"
dtdataCOMMAND = New MySqlCommand(strSQL, cnVoting)
dtdataCOMMAND.ExecuteNonQuery() strSQL = "Update tblVoters set
Time_Verified=TIMESTAMP(CURRENT_TIMESTAMP) where StudentID='" &
StudentID & "' " dtdataCOMMAND = New MySqlCommand(strSQL, cnVoting)
dtdataCOMMAND.ExecuteNonQuery() DisplayMessage("CONGRATULATIONS!
Your Votes are now successfully casted and authenticated! Press enter to clear.", 20)
LoadVotes(StudentID) Else strSQL = "Select * from tblVoters where StudentID='" &
StudentID & "' " dtdataCOMMAND = New MySqlCommand(strSQL, cnVoting)
dtDataReader = dtdataCOMMAND.ExecuteReader dtDataReader.Read()
DisplayMessage("SORRY, you have already casted and authenticated your votes on " &
dtDataReader.Item("Time_Verified") & ".", 5) dtDataReader.Close() End If End If Return
isVoteExist End Function Private Sub LoadVotes(ByVal StudentID) Dim i As Integer
lstBallot.Items.Clear() For i = 0 To lstPositions.Items.Count - 1 strSQL = "Select
tblVotes.Student_ID, tblVotes.Candidate_ID, tblVotes.Verification, tblCandidates.Name,
tblCandidates.Position from tblVotes INNER JOIN tblCandidates ON
`tblvotes`.`Candidate_ID` = `tblCandidates`.`Candidate_ID` " & _ "Where Position='" &
lstPositions.Items(i).ToString & "' and Student_ID='" & StudentID & "' and
Verification='Verified'" dtdataCOMMAND = New MySqlCommand(strSQL, cnVoting)
dtDataReader = dtdataCOMMAND.ExecuteReader
lstBallot.Items.Add(lstPositions.Items(i).ToString) Dim VoteCount As Integer = 0 Do
While dtDataReader.Read lstBallot.Items.Add(vbTab & dtDataReader.Item("Name"))
VoteCount += 1 Loop If VoteCount = 0 Then lstBallot.Items.Add(vbTab & "Undervote")
End If dtDataReader.Close() Next End Sub Private Sub LoadPositions() strSQL = "Select
* from tblposition order by Precedence" dtdataCOMMAND = New
MySqlCommand(strSQL, cnVoting) dtDataReader = dtdataCOMMAND.ExecuteReader
lstPositions.Items.Clear() Do While dtDataReader.Read
lstPositions.Items.Add(dtDataReader.Item("Position")) Loop dtDataReader.Close() End
Sub Sub OnFingerGone(ByVal Capture As Object, ByVal ReaderSerialNumber As String)
Implements DPFP.Capture.EventHandler.OnFingerGone ListEvents.Items.Insert(0, "The
finger was Removed.") End Sub Sub OnFingerTouch(ByVal Capture As Object, ByVal
ReaderSerialNumber As String) Implements
DPFP.Capture.EventHandler.OnFingerTouch ListEvents.Items.Insert(0, "The fingerprint
reader was touched.") End Sub Sub OnReaderConnect(ByVal Capture As Object, ByVal
ReaderSerialNumber As String) Implements
DPFP.Capture.EventHandler.OnReaderConnect lblFingerPrintScannerStatus.Text =
("The fingerprint reader was connected.") End Sub Sub OnReaderDisconnect(ByVal
Capture As Object, ByVal ReaderSerialNumber As String) Implements
DPFP.Capture.EventHandler.OnReaderDisconnect lblFingerPrintScannerStatus.Text =
("The fingerprint reader was Disconnected.") End Sub Sub OnSampleQuality(ByVal
Capture As Object, ByVal ReaderSerialNumber As String, ByVal CaptureFeedback As
DPFP.Capture.CaptureFeedback) Implements
DPFP.Capture.EventHandler.OnSampleQuality ListEvents.Items.Insert(0, "The quality of
the fingerprint sample is good.") End Sub Protected Function ExtractFeatures(ByVal
Sample As DPFP.Sample, ByVal Purpose As DPFP.Processing.DataPurpose) As
DPFP.FeatureSet Dim extractor As New DPFP.Processing.FeatureExtraction() ' Create a
feature extractor Dim feedback As DPFP.Capture.CaptureFeedback =
DPFP.Capture.CaptureFeedback.None Dim features As New DPFP.FeatureSet()
extractor.CreateFeatureSet(Sample, Purpose, feedback, features) ' TODO: return features
as a result? If (feedback = DPFP.Capture.CaptureFeedback.Good) Then Return features
Else Return Nothing End If End Function Private Sub tmrTimeDate_Tick(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles tmrTimeDate.Tick
lblTimeDate.Text = Now End Sub Private Sub DisplayMessage(ByVal Msg As String,
ByVal timeToClose As Integer) lblInformation.Text = Msg lblTTC.Text = timeToClose
tmrClear.Enabled = True End Sub Private Sub ClearInfo() PicStudent.Image =
picBlank.Image lstBallot.Items.Clear() lstStudentVotes.Items.Clear() lblInformation.Text
= "To cast your vote, please put your registered finger in the scanner and press gently."
End Sub Private Sub tmrClear_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrClear.Tick lblTTC.Text = Val(lblTTC.Text) - 1 If
Val(lblTTC.Text) = 0 Then tmrClear.Enabled = False ClearInfo() End If End Sub Private
Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnClear.Click ClearInfo() End Sub Private Sub FlatClose1_Click(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles FlatClose1.Click End End
SubEnd Class
Attendance Monitoring System
LogIn.vb
Imports MySql.Data.MySqlClient Public Class LogIn Dim strName As String = "" Dim
strRole As String = "" Private Sub FlatClose1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles FlatClose1.Click End End Sub Private Sub
LogIn_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
conStringAttendance = "server=localhost;" _ & "uid=admin;" _ & "pwd=MLGCL;" _ &
"database=dbAttendance;" If ConnectToDB() = False Then
ManualConnectToDB.ShowDialog() End If txtUserName.Focus() End Sub Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click frmMain.Show() Me.Dispose() End Sub Private Sub
btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnLogIn.Click Dim strSQL As String strSQL = "Select * from tblUsers where
`User Name` = '" & txtUserName.Text & "' and Password = '" & txtPassword.Text & "'"
dtdataCOMMAND = New MySqlCommand(strSQL, cnAttendance) dtDataReader =
dtdataCOMMAND.ExecuteReader Dim RecCount As Integer = 0 While
dtDataReader.Read strName = dtDataReader.Item("Name") strRole =
dtDataReader.Item("Role") RecCount = RecCount + 1 End While dtDataReader.Close() If
RecCount = 0 Then MsgBox("The username or password is invalid or does not exist.",
vbCritical) txtUserName.Focus() Else MsgBox("Welcome " + strName & ".",
vbInformation + vbOKOnly) With frmMain Select Case strRole Case "SSC"
.DeToolStripMenuItem.Visible = False .SchoolYearToolStripMenuItem.Visible = False
.AccountsToolStripMenuItem.Visible = False Case "Attendance Checker"
.StudentMasterfileToolStripMenuItem.Visible = False .DeToolStripMenuItem.Visible =
False .EventsToolStripMenuItem.Visible = False .AccountsToolStripMenuItem.Visible =
False Case "Administrator" End Select .lbluser.Text = "You are currently logged in as: "
& strName & " - " & strRole & "." frmMain.Show() End With Me.Dispose() End If End
Sub End Class

frmMain.vb
Public Class frmMain Private Sub AddNewClassToolStripMenuItem_Click(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
AddNewClassToolStripMenuItem.Click Student_Management_Form.MdiParent = Me
Student_Management_Form.Show() Student_Management_Form.WindowState =
FormWindowState.Maximized Student_Management_Form.Dock = DockStyle.Fill
Me.MenuStrip1.Visible = False Me.MenuStrip1.Visible = True
Student_Management_Form.Focus() End Sub Private Sub ConnectDatabase()
lblDatabaseConnection.Text = "Database Connection: " & cnAttendance.State.ToString
End Sub Private Sub DepartmentsToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DepartmentsToolStripMenuItem.Click Department.ShowDialog() End Sub Private Sub
CoursesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CoursesToolStripMenuItem.Click
CourseTracks.ShowDialog() End Sub Private Sub
EventsManagementToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles EventsManagementToolStripMenuItem.Click
Events_Form.MdiParent = Me Events_Form.Show() Events_Form.WindowState =
FormWindowState.Maximized Events_Form.Dock = DockStyle.Fill
Events_Form.Focus() End Sub Private Sub SchoolYearToolStripMenuItem_Click(ByVal
sender As System.Object, ByVal e As System.EventArgs) Handles
SchoolYearToolStripMenuItem.Click School_Year.ShowDialog() End Sub Private Sub
EnrollmentToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles EnrollmentToolStripMenuItem.Click Enrollment.MdiParent
= Me Enrollment.Show() Enrollment.WindowState = FormWindowState.Maximized
Enrollment.Focus() End Sub Private Sub
AttendanceSheetToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AttendanceSheetToolStripMenuItem.Click
AttendanceSheet.MdiParent = Me AttendanceSheet.Show()
AttendanceSheet.WindowState = FormWindowState.Maximized
AttendanceSheet.Focus() End Sub Private Sub
CheckAttendanceToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CheckAttendanceToolStripMenuItem.Click
Attendance_Activator.ShowDialog() End Sub Private Sub
UserToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles UserToolStripMenuItem.Click End Sub Private Sub
FlatClose1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles FlatClose1.Click End End Sub Private Sub frmMain_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lblNow.Text =
Now FormSkin2.Dock = DockStyle.Top ConnectDatabase() End Sub Private Sub
FlatMax1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles FlatMax1.Click Me.BackgroundImageLayout = ImageLayout.Stretch End Sub
Private Sub tmrNow_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrNow.Tick lblNow.Text = Now End Sub Private Sub
AccountsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AccountsToolStripMenuItem.Click
UserAccountsManagement.ShowDialog() End Sub Private Sub
LogOutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles LogOutToolStripMenuItem.Click LogIn.Show()
Me.Dispose() End Sub End Class
Attendance Checker.vb
Imports MySql.Data.MySqlClientPublic Class Attendance_Checker Implements
DPFP.Capture.EventHandler Dim template2 As DPFP.Template Public Capturer As
DPFP.Capture.Capture = New DPFP.Capture.Capture() Private Enroller As
DPFP.Processing.Enrollment = New DPFP.Processing.Enrollment() Dim Template As
New DPFP.Template Public FingerprintSample As DPFP.Sample Dim ClearTimer As
Integer Private Sub Attendance_Checker_FormClosing(ByVal sender As Object, ByVal e
As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Attendance_Activator.Visible = True frmMain.Visible = True Capturer.StopCapture()
lblCapturerState.Text = 0 Me.Dispose() End Sub Private Sub
Attendance_Checker_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load FormSkin1.Dock = DockStyle.Fill LoadTimeDate()
ListEvents.Items.Clear() LoadTimeTable() System.Windows.Forms.Control.
CheckForIllegalCrossThreadCalls = False If (Not Capturer Is Nothing) Then
Capturer.EventHandler = Me Capturer.StartCapture() lblCapturerState.Text = 1 End If
LoadSavedLog() End Sub Public Sub LoadTimeTable() Dim strSQL As String = "Select
* from tbltimetable where `Event Code` = '" & lblEventCode.Text & "'"
dtdataCOMMAND = New MySqlCommand(strSQL, cnAttendance) dtDataReader =
dtdataCOMMAND.ExecuteReader() lvwTimeTable.Items.Clear() Do While
dtDataReader.Read Dim lv As ListViewItem = lvwTimeTable.Items.Add
(dtDataReader.Item("RecordNo")) lv.SubItems.Add (dtDataReader.Item("Caption"))
lv.SubItems.Add(dtDataReader.Item("Start Time")) lv.SubItems.Add(dtDataReader.Item
("End Time")) lv.SubItems.Add(dtDataReader.Item ("Status")) Loop
dtDataReader.Close() End Sub Private Sub CheckTimeTable() Dim TimeStart, TimeEnd,
CurrentTime As DateTime Dim i As Integer For i = 0 To lvwTimeTable.Items.Count - 1
TimeStart = lvwTimeTable.Items(i).SubItems(2).Text TimeEnd =
lvwTimeTable.Items(i).SubItems(3).Text CurrentTime = Now.TimeOfDay.ToString If
CurrentTime >= TimeStart And CurrentTime <= TimeEnd Then
Debug.Print(CurrentTime.ToString & ">=" & TimeStart.ToString & "=" & (CurrentTime
>= TimeEnd)) Debug.Print(CurrentTime.ToString & "<=" & TimeStart.ToString & "=" &
(CurrentTime <= TimeEnd)) lblCurrentTimeTableNo.Text = lvwTimeTable.Items(i).Text
lblAttendanceTitle.Text = "Checking Attendance for: " & lvwTimeTable.Items(i)
.SubItems(1).Text lblAttendanceName.Text = lvwTimeTable.Items(i).SubItems(1).Text
lvwTimeTable.Items(i).SubItems(4).Text = "Checking..." lblCheckingState.Text =
"Checking Attendance" ElseIf CurrentTime < TimeStart Then
lvwTimeTable.Items(i).SubItems(4).Text = "Queued" ElseIf CurrentTime > TimeEnd
Then lvwTimeTable.Items(i).SubItems(4).Text = "Done" If i = 0 Then
lblAttendanceTitle.Text = "Waiting for the schedule." lblCheckingState.Text = "Not
Checking Attendance" Else lblAttendanceTitle.Text = "Waiting for the next schedule."
lblCheckingState.Text = "Not Checking Attendance" End If End If lblTimerCheck.Text =
tmrAttendanceChecking.Enabled.ToString If i = lvwTimeTable.Items.Count - 1 And
lvwTimeTable.Items(i).SubItems(4).Text = "Done" Then lblAttendanceTitle.Text =
"FINISHED CHECKING ALL THE ATTENDANCE" lblCheckingState.Text = "Not
Checking Attendance" pnlFingerPrintReady.Visible = True lblRemarks.Text = "Sorry, No
more authentication is allowed at this moment." Dim strSQL As String strSQL =
"UPDATE tblEvents SET STATUS='FINISHED CHECKING' where `Event Code` = '" &
lblEventCode.Text & "'" dtdataCOMMAND = New MySqlCommand(strSQL,
cnAttendance) dtdataCOMMAND.ExecuteNonQuery() tmrAttendanceChecking.Enabled
= False Capturer.StopCapture() lblCapturerState.Text = 0 lblTimerCheck.Text =
tmrAttendanceChecking.Enabled.ToString End If Next End Sub Private Sub
LoadTimeDate() lblTime.Text = TimeOfDay lblDate.Text = Now.Date.ToLongDateString
End Sub Sub OnComplete(ByVal Capture As Object, ByVal ReaderSerialNumber As
String, ByVal Sample As DPFP.Sample) Implements
DPFP.Capture.EventHandler.OnComplete If lblAttendanceTitle.Text = "Waiting for the
scheduled time..." Then Exit Sub lblRemarks.Text = "Authenticating Fingerprint. Please
Wait..." Capturer.StopCapture() lblCapturerState.Text = 3 ClearTimer = 6 Dim features As
DPFP.FeatureSet = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification)
Dim Verificator = New DPFP.Verification.Verification() features =
ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification) ListEvents
.Items.Add("The fingerprint sample was captured.") features = ExtractFeatures(Sample,
DPFP.Processing.DataPurpose.Verification) Dim StudentID As String = "" Dim
strStudentExist As String = isFingerPrintExist(features, StudentID) If strStudentExist <>
"" Then If CheckStudentAttendance(StudentID, strStudentExist, lblEventCode.ToString,
lblCurrentTimeTableNo.Text) = False Then Dim strTimeLog As String = lblTime.Text
LogStudentAttendance(StudentID, lblEventCode.Text, lblCurrentTimeTableNo.Text,
strTimeLog) Dim lvw As ListViewItem lvw = lvwLog.Items.Insert(0, "[" & strTimeLog
& "]: " & strStudentExist.ToString & " has logged successfully.") lvw.ForeColor =
FormatLogEvent("Success") SaveLog("Success", lblEventCode.Text,
lblCurrentTimeTableNo.Text, lvwLog.Items(0).Text) PicStudent.Image = picTemp.Image
Enroller.Clear() End If Else Dim lvw As ListViewItem lvw = lvwLog.Items.Insert(0, "This
fingerprint is not recognized as one of the students enrolled in this current semester.")
lvw.ForeColor = FormatLogEvent("Unrecognized") SaveLog("Unrecognized",
lblEventCode.Text, lblCurrentTimeTableNo.Text, lvwLog.Items(0).Text)
PicStudent.Image = picBlank.Image End If lblRemarks.Text = "Please put your registered
finger on the scanner and press gently." Try Capturer.StartCapture() lblCapturerState.Text
= 1 Catch ex As Exception End Try End Sub Private Function isFingerPrintExist(ByVal
features As DPFP.FeatureSet, Optional ByRef StudentID As String = "") As String Dim
Verificator = New DPFP.Verification.Verification() Dim result = New
DPFP.Verification.Verification.Result Dim DBTemplate As New DPFP.Template Dim
strSQL As String = "Select `School Year`, Semester, tblenrollment.`Student ID`,
tblstudentinfo.`Last Name`, tblStudentInfo.`First Name`, tblStudentInfo.`Middle Name`,
tblstudentinfo.fingerprint, tblstudentinfo.picture, tblenrollment.department, `Course
Enrolled` From tblEnrollment " & _ "INNER JOIN tblStudentInfo On
tblEnrollment.`Student ID` = tblStudentInfo.`Student ID` " & " where `school year` = '" &
lblSchoolYear.Text & "' and semester='" & lblSemester.Text & "' " & _ "order by
department asc, `Course Enrolled` asc, tblstudentinfo.`last name` asc" dtdataCOMMAND
= New MySqlCommand(strSQL, cnAttendance) dtDataReader =
dtdataCOMMAND.ExecuteReader Dim MemStream As IO.MemoryStream Dim fpBytes
As Byte() Dim strStudent As String = "" While dtDataReader.Read() fpBytes =
dtDataReader.Item("FINGERPRINT") StudentID = dtDataReader.Item("Student ID")
strStudent = "(" & dtDataReader.Item("student id") & ") - " & dtDataReader.Item("Last
Name") & ", " & dtDataReader.Item("First Name") MemStream = New
IO.MemoryStream(fpBytes) DBTemplate.DeSerialize(dtDataReader.Item("Fingerprint"))
Verificator.Verify(features, DBTemplate, result) If result.Verified Then Try Dim
arrImage() As Byte arrImage = dtDataReader.Item("Picture") Dim mstream As New
System.IO.MemoryStream(arrImage) picTemp.Image = Image.FromStream(mstream)
Catch ex As Exception MsgBox(ex.Message) picTemp.Image = picBlank.Image End Try
dtDataReader.Close() Return strStudent End If End While dtDataReader.Close() Return
Nothing End Function Sub OnFingerGone(ByVal Capture As Object, ByVal
ReaderSerialNumber As String) Implements DPFP.Capture.EventHandler.OnFingerGone
ListEvents.Items.Add("The finger was Removed.") End Sub Sub OnFingerTouch(ByVal
Capture As Object, ByVal ReaderSerialNumber As String) Implements
DPFP.Capture.EventHandler.OnFingerTouch ListEvents.Items.Add("The fingerprint
reader was touched.") End Sub Sub OnReaderConnect(ByVal Capture As Object, ByVal
ReaderSerialNumber As String) Implements
DPFP.Capture.EventHandler.OnReaderConnect pnlFingerPrintReady.Visible = True
lblFingerPrintScannerStatus.Text = ("The fingerprint reader is connected.") End Sub Sub
OnReaderDisconnect(ByVal Capture As Object, ByVal ReaderSerialNumber As String)
Implements DPFP.Capture.EventHandler.OnReaderDisconnect If lblAttendanceTitle.Text
= "FINISHED CHECKING ALL THE ATTENDANCE" Then
pnlFingerPrintReady.Visible = True lblRemarks.Text = "Sorry, No more authentication is
allowed at this moment." btnLog.Enabled = False Else pnlFingerPrintReady.Visible =
False lblFingerPrintScannerStatus.Text = ("The fingerprint reader was Disconnected.")
End If End Sub Sub OnSampleQuality(ByVal Capture As Object, ByVal
ReaderSerialNumber As String, ByVal CaptureFeedback As
DPFP.Capture.CaptureFeedback) Implements
DPFP.Capture.EventHandler.OnSampleQuality ListEvents.Items.Add("The quality of the
fingerprint sample is good.") End Sub Protected Function ExtractFeatures(ByVal Sample
As DPFP.Sample, ByVal Purpose As DPFP.Processing.DataPurpose) As DPFP.FeatureSet
Dim extractor As New DPFP.Processing.FeatureExtraction() ' Create a feature extractor
Dim feedback As DPFP.Capture.CaptureFeedback =
DPFP.Capture.CaptureFeedback.None Dim features As New DPFP.FeatureSet()
extractor.CreateFeatureSet(Sample, Purpose, feedback, features) ' TODO: return features
as a result? If (feedback = DPFP.Capture.CaptureFeedback.Good) Then Return features
Else Return Nothing End If End Function Private Sub txtUser_KeyPress(ByVal sender As
Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles
txtUser.KeyPress If Asc(e.KeyChar) = 13 Then txtPass.Focus() End Sub Private Sub
txtPass_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtPass.KeyPress If
Asc(e.KeyChar) = 13 Then If btnLog.Enabled = True Then btnLog.PerformClick() End If
End Sub Private Sub btnLog_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLog.Click Dim strSQL As String = "Select `School Year`,
Semester, tblenrollment.`Student ID`, tblstudentinfo.`Last Name`, tblStudentInfo.`First
Name`, tblStudentInfo.`Middle Name`, tblstudentinfo.fingerprint, tblstudentinfo.picture,
tblstudentinfo.username, tblstudentinfo.password, tblenrollment.department, `Course
Enrolled` From tblEnrollment " & _ "INNER JOIN tblStudentInfo On
tblEnrollment.`Student ID` = tblStudentInfo.`Student ID` " & " where `school year` = '" &
lblSchoolYear.Text & "' and semester='" & lblSemester.Text & "' and Username='" &
txtUser.Text.Trim & "' and Password='" & txtPass.Text & "'" & _ " order by department
asc, `Course Enrolled` asc, tblstudentinfo.`last name` asc" 'MsgBox(strSQL)
dtdataCOMMAND = New MySqlCommand(strSQL, cnAttendance) dtDataReader =
dtdataCOMMAND.ExecuteReader Dim strStudent As String = "" Dim StudentID As
String = "" Dim recCount As Integer = 0 Dim arrImage() As Byte = Nothing Do While
dtDataReader.Read recCount += 1 StudentID = dtDataReader.Item("Student ID")
strStudent = "(" & StudentID & ") - " & dtDataReader.Item("Last Name") & ", " &
dtDataReader.Item("First Name") arrImage = dtDataReader.Item("Picture") Loop
dtDataReader.Close() If recCount = 0 Then Dim lvw As ListViewItem lvw =
lvwLog.Items.Insert(0, "This student account is not recognized as one of the students
enrolled in this current semester.") lvw.ForeColor = FormatLogEvent("Unrecognized")
SaveLog("Unrecognized", lblEventCode.Text, lblCurrentTimeTableNo.Text,
lvwLog.Items(0).Text) Else If CheckStudentAttendance(StudentID, strStudent,
lblEventCode.ToString, lblCurrentTimeTableNo.Text) = False Then Dim strTimeLog As
String = lblTime.Text LogStudentAttendance(StudentID, lblEventCode.Text,
lblCurrentTimeTableNo.Text, strTimeLog) Dim lvw As ListViewItem lvw =
lvwLog.Items.Insert(0, "[" & strTimeLog & "]: " & strStudent.ToString & " has logged
successfully.") lvw.ForeColor = FormatLogEvent("Success") SaveLog("Success",
lblEventCode.Text, lblCurrentTimeTableNo.Text, lvwLog.Items(0).Text) Try Dim
mstream As New System.IO.MemoryStream(arrImage) PicStudent.Image =
Image.FromStream(mstream) Catch ex As Exception MsgBox(ex.Message)
PicStudent.Image = picBlank.Image End Try End If End If dtDataReader.Close()
txtUser.Clear() txtPass.Clear() txtUser.Focus() End Sub Private Function
CheckStudentAttendance(ByVal StudentID As String, ByVal StudentName As String,
ByVal EventCode As String, ByVal TimeTableNo As String) As Boolean Dim strSQL As
String strSQL = "Select * from tblAttendance where `Student ID` ='" & StudentID & "'
and `Event Code`='" & EventCode & "' and tblTimeTableNo = '" & TimeTableNo & "'"
dtdataCOMMAND = New MySqlCommand(strSQL, cnAttendance) dtDataReader =
dtdataCOMMAND.ExecuteReader Dim RecordCounter As Integer = 0 Do While
dtDataReader.Read RecordCounter += 1 Loop If RecordCounter <> 0 Then Dim lvw As
ListViewItem lvw = lvwLog.Items.Insert(0, "[Duplicate Entry]:" & StudentName & " has
already logged for '" & lblAttendanceName.Text & "' at '" & dtDataReader.Item("Time
Log") & "'.") lvw.ForeColor = FormatLogEvent("Duplicate") SaveLog("Duplicate",
lblEventCode.Text, lblCurrentTimeTableNo.Text, lvwLog.Items(0).Text)
dtDataReader.Close() Return True Else dtDataReader.Close() Return False End If End
Function Private Sub LogStudentAttendance(ByVal StudentID As String, ByVal
EventCode As String, ByVal TimeTableNo As String, ByVal TimeLog As String) Dim
strSQL As String strSQL = "Insert into tblattendance values (NULL,'" & EventCode & "',
'" & StudentID & "', '" & TimeTableNo & "', '" & TimeLog & "')" dtdataCOMMAND =
New MySqlCommand(strSQL, cnAttendance) dtdataCOMMAND.ExecuteNonQuery()
End Sub Private Sub tmrAttendanceChecking_Tick(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles tmrAttendanceChecking.Tick CheckTimeTable()
End Sub Private Sub tmrTime_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrTime.Tick LoadTimeDate() If lblCheckingState.Text =
"Checking Attendance" Then btnLog.Enabled = True Try If lblCapturerState.Text = 0
Then Capturer.StartCapture() lblCapturerState.Text = 1 End If Catch ex As Exception
Capturer.StopCapture() lblCapturerState.Text = 0 MsgBox(ex.Message) End Try Else
btnLog.Enabled = False Capturer.StopCapture() lblCapturerState.Text = 0 End If If
ClearTimer > 0 Then ClearTimer -= 1 Else PicStudent.Image = PicClear.Image End If End
Sub Private Sub LoadSavedLog() Dim strSQL As String = "SELECT * FROM tblLog
where `Event Code` = '" & lblEventCode.Text & "'" dtdataCOMMAND = New
MySqlCommand(strSQL, cnAttendance) dtDataReader =
dtdataCOMMAND.ExecuteReader lvwLog.Items.Clear() Do While dtDataReader.Read
Dim lv As ListViewItem lv = lvwLog.Items.Insert(0, dtDataReader("Log Details"))
lv.SubItems.Add(dtDataReader.Item("LogCode")) lv.ForeColor =
FormatLogEvent(dtDataReader.Item("LogCode")) Loop lvwLog.AutoResizeColumn(0,
ColumnHeaderAutoResizeStyle.ColumnContent) dtDataReader.Close() End Sub Private
Sub SaveLog(ByVal LogCode As String, ByVal EventCode As String, ByVal
tblTimeTableNo As String, ByVal LogDetails As String) lvwLog.AutoResizeColumn(0,
ColumnHeaderAutoResizeStyle.ColumnContent) Dim dtDataCommand2 As
MySqlCommand Dim strSQL As String = "INSERT INTO `tblLog`
values(NULL,@LogCode, @EventCode, @tblTimeTableNo, @LogDetails)"
dtDataCommand2 = New MySqlCommand(strSQL, cnAttendance2)
dtDataCommand2.Parameters.AddWithValue("@LogCode"LogCode)
dtDataCommand2.Parameters. AddWithValue("@EventCode",EventCode)
dtDataCommand2.Parameters.AddWithValue ("@tblTimeTableNo",tblTimeTableNo)
dtDataCommand2.Parameters.AddWithValue("@LogDetails", LogDetails.ToString)
dtDataCommand2.ExecuteNonQuery() End Sub Private Function FormatLogEvent(ByVal
LogCode As String) As Color Dim i As Integer For i = 0 To lvwLog.Items.Count - 1 Select
Case LogCode Case "Unrecognized" Return Color.DarkGray Case "Duplicate" Return
Color.Gray Case "Success" Return Color.LimeGreen End Select Next End Function
Private Sub FlatClose1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles FlatClose1.Click Me.Dispose() End Sub Private Sub
picBlank_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
picBlank.Click End SubEnd Class

You might also like