Sie sind auf Seite 1von 14

Imports MySql.Data.

MySqlClient
Delegate Sub FunctionCall(ByVal param)
Public Class MainForm
Private Sub EnrollButton_Click(ByVal sender As System.Object, ByVal e As Sys
tem.EventArgs) Handles EnrollButton.Click
Dim Enroller As New EnrollmenForm()
AddHandler Enroller.OnTemplate, AddressOf OnTemplate
Enroller.ShowDialog()
End Sub
Private Sub VerifyButton_Click(ByVal sender As System.Object, ByVal e As Sys
tem.EventArgs) Handles VerifyButton.Click
If txtfullname.Text = "" Then
MsgBox("Please input your fullname no.", MsgBoxStyle.Information)
Else
objconn.Open()
Dim cmd As New MySqlCommand("SELECT * FROM employeefp where fname ='
" & txtfullname.Text & "'", objconn)
Dim rdr As MySqlDataReader = cmd.ExecuteReader()
rdr.Read()
If rdr.HasRows Then
Dim Verifier As New VerificationForm
' Verifier.Verify(Template)
verification.Show()
Else
MsgBox("The id doesn`t exist", MsgBoxStyle.Information)
End If
End If
objconn.Close()
End Sub
Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As Syste
m.EventArgs) Handles SaveButton.Click
Using files As New IO.MemoryStream
Template.Serialize(files)
objconn.Open()
If Not Template Is Nothing Then
Dim cmd = New MySqlCommand("INSERT INTO employeefp SET FP=@FP,fn
ame=@fname,lname=@lname", objconn)
cmd.Parameters.Add(New MySqlParameter("@FP", Template.Bytes))
cmd.Parameters.Add(New MySqlParameter("@fname", txtfullname.Text
))
cmd.Parameters.Add(New MySqlParameter("@lname", txtprisno.Text))
cmd.ExecuteNonQuery()
objconn.Close()
MessageBox.Show("Template Successfuly Saved.", "Finger Enrolled"
)
End If
End Using
End Sub
Private Sub CloseButton_Click(ByVal sender As System.Object, ByVal e As Syst
em.EventArgs)
End Sub
Private Sub OnTemplate(ByVal template)
Invoke(New FunctionCall(AddressOf _OnTemplate), template)
End Sub

Private Sub _OnTemplate(ByVal template)


Me.Template = template
VerifyButton.Enabled = (Not template Is Nothing)
SaveButton.Enabled = (Not template Is Nothing)
If Not template Is Nothing Then
MessageBox.Show("The fingerprint template is ready for fingerprint v
erification.", "Fingerprint Enrollment")
Else
MessageBox.Show("The fingerprint template is not valid. Repeat finge
rprint enrollment.", "Fingerprint Enrollment")
End If
End Sub
Private Template As DPFP.Template
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles MyBase.Load
constr()
End Sub
Private Sub Closex_Click(ByVal sender As System.Object, ByVal e As System.Ev
entArgs) Handles Closex.Click
End
End Sub
End Class

-----------------------------------------SAVING-------------------------------------Protected Overrides Sub Process(Sample As DPFP.Sample)


MyBase.Process(Sample)
' Process the sample and create a feature set for the enrollment purpose
.
Dim features As DPFP.FeatureSet = ExtractFeatures(Sample, DPFP.Processin
g.DataPurpose.Enrollment)
' Check quality of the sample and add to enroller if it's good
If features IsNot Nothing Then
Try
MakeReport("The fingerprint feature set was created.")
' Add feature set to template.
Enroller.AddFeatures(features)
Finally
UpdateStatus()
' Check if template has been created.
Select Case Enroller.TemplateStatus
Case DPFP.Processing.Enrollment.Status.Ready
' report success and stop capturing
Dim serializedTemplate As Byte() = Nothi
ng
Dim str_temp As String = Nothing

Dim cur_date As DateTime = DateTime.Now


Enroller.Template.Serialize(serializedTe
mplate)
'Enroller.Template.Serialize(ref str_tem
p);
If serializedTemplate IsNot Nothing Then
Dim result As String = System.Te
xt.Encoding.UTF8.GetString(serializedTemplate)
Console.Write(result)
Try
Using conn As New Npgsql
Connection("Host=127.0.0.1;Port=5432;User Id=UserName;Password=*****;Database=fi
nger_print_db;")
conn.Open()
Dim dbcmd As Npg
sqlCommand = conn.CreateCommand()
Try
' Store
TemplateSerialize as string data
dbcmd.Co
mmandText = "INSERT INTO tbl_fptable( fp_data ) VALUES ( @serializedTemplate )"
dbcmd.Pa
rameters.AddWithValue("@serializedTemplate ", serializedTemplate)
dbcmd.Ex
ecuteNonQuery()
Finally
conn.Clo
se()
End Try
End Using
Catch ex As Exception
Throw ex
End Try
End If
OnTemplate(Enroller.Template)
SetPrompt("Click Close, and then click F
ingerprint Verification.")
[Stop]()
Exit Select
Case DPFP.Processing.Enrollment.Status.Failed
' report failure and restart capturing
Enroller.Clear()
[Stop]()
UpdateStatus()
OnTemplate(Nothing)
Start()
Exit Select
End Select
End Try
End If
End Sub

=========================
CODE FOR SAVING FINGERPRINT
Private Sub SaveButton_Click(sender As Object, e As EventArgs)
Dim fingerprintData As New MemoryStream()
Template.Serialize(fingerprintData)
fingerprintData.Position = 0
Dim br As New BinaryReader(fingerprintData)
Dim bytes As [Byte]() = br.ReadBytes(DirectCast(fingerprintData.Length,
Int32))
'Insert the file into database
Dim cn As New SqlConnection("Data Source=10.115.5.3; Initial Catalog=Enr
ollmentSampledb;Integrated Security=SSPI;")
Dim cmd As New SqlCommand("INSERT INTO tblUser VALUES(@ID_NUMBER, @FIRST
NAME, @LASTNAME, @FINGERPRINT, @DATE_ADDED, @DATE_MODIFIED)", cn)
cmd.Parameters.Add("ID_NUMBER", SqlDbType.NVarChar).Value = tboxIdNum.Te
xt
cmd.Parameters.Add("FIRSTNAME", SqlDbType.NVarChar).Value = tboxFname.Te
xt
cmd.Parameters.Add("LASTNAME", SqlDbType.NVarChar).Value = tboxLname.Tex
t
cmd.Parameters.Add("FINGERPRINT", SqlDbType.Image).Value = bytes
cmd.Parameters.Add("DATE_ADDED", SqlDbType.DateTime).Value = DateTime.No
w
cmd.Parameters.Add("DATE_MODIFIED", SqlDbType.DateTime).Value = DateTime
.Now
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
tboxIdNum.Text = ""
tboxFname.Text = ""
tboxLname.Text = ""
End Sub

----------------------------VERIFY-----------------------------Protected Overrides Sub Process(Sample As DPFP.Sample)


MyBase.Process(Sample)
' Process the sample and create a feature set for the enrollment purpose
.

Dim features As DPFP.FeatureSet = ExtractFeatures(Sample, DPFP.Processin


g.DataPurpose.Verification)
' Check quality of the sample and start verification if it's good
' TODO: move to a separate task
If features IsNot Nothing Then
Try
Using conn As New NpgsqlConnection("Host=127.0.0.1;Port=
5432;User Id=UserName;Password=*****;Database=finger_print_db;")
conn.Open()
Try
Dim cmd As New NpgsqlCommand("SELECT * F
ROM tbl_fptable ORDER BY enr_id DESC LIMIT 1", conn)
Dim dr As NpgsqlDataReader = cmd.Execute
Reader()
While (dr.Read())
Dim fpid As Long = Convert.ToInt
64(dr("id"))
Dim fpbyte As Byte() = DirectCas
t(dr("finger_data"), Byte())
Dim stream As Stream = New Memor
yStream(fpbyte)
Dim tmpObj As New DPFP.Template(
stream)
Dim result As New DPFP.Verificat
ion.Verification.Result()
' Compare the feature set with o
ur template
Verificator.Verify(features, tmp
Obj, result)
UpdateStatus(result.FARAchieved)
If result.Verified Then
MakeReport("The fingerpr
int was VERIFIED.")
Else
MakeReport("The fingerpr
int was NOT VERIFIED.")
End If
End While
Finally
conn.Close()
End Try
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub

----------------------------------------------VERIFICATION 1---------------------------------------------------

Imports System.IO
Imports DPFP.Processing
Imports MySql.Data.MySqlClient
Public Class verificationMainForm
Inherits capturemain
Dim no As Integer
Dim now As String
Private Template As DPFP.Template
Private Verificator As DPFP.Verification.Verification
Public Sub Verify(ByVal template As DPFP.Template)
Me.Template = template
ShowDialog()
End Sub
Protected Overrides Sub Init()
MyBase.Init()
MyBase.Text = "Fingerprint Verification"
Verificator = New DPFP.Verification.Verification()
UpdateStatus(0)
End Sub
Protected Overrides Sub Process(ByVal Sample As DPFP.Sample)
MyBase.Process(Sample)
' Process the sample and create a feature set for the enrollment purpose
.
Dim features As DPFP.FeatureSet = ExtractFeatures(Sample, DPFP.Processin
g.DataPurpose.Verification)
' Check quality of the sample and start verification if it's good
' TODO: move to a separate task
' If features IsNot Nothing Then
Try
Using conn As New MySqlConnection("Server = 127.0.0.1;port=3307;user
id=account;password=;database=oass;")
conn.Open()
Try
Dim cmd As New MySqlCommand("SELECT * FROM employee order by
no asc ", conn)
Dim dr As MySqlDataReader = cmd.ExecuteReader()
Dim resulttext As String
While (dr.Read())
Dim fpno As Long = Convert.ToInt64(dr("no"))
Dim fpbyte As Byte() = DirectCast(dr("fingerprint"), Byt
e())

Dim stream As Stream = New MemoryStream(fpbyte)


Dim tmpObj As New DPFP.Template(stream)
Dim result As New DPFP.Verification.Verification.Result(
)
'Compare the feature set with our template
Verificator.Verify(features, tmpObj, result)
UpdateStatus(result.FARAchieved)
If result.Verified Then
resulttext = "verified"
no = fpno
End If
End While
If resulttext = "verified" Then
conn.Close()
SetStatus("The fingerprint was VERIFIED.")

Dim fname As String


Dim idno As String
Try
conn.Open()
Dim cmd2 As New MySqlCommand("SELECT FullName, EmpID
FROM employee where no = '" & no & "'", conn)
Dim dr2 As MySqlDataReader = cmd2.ExecuteReader()
While (dr2.Read())
fname = dr2.GetString("FullName")
idno = dr2.GetString("EmpID")
End While
'MessageBox.Show(fname)
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
conn.Dispose()
End Try

Try
conn.Open()
Dim query As String
Dim command As MySqlCommand
Dim reader As MySqlDataReader
query = "select * from access where EmpID = '" & idn
o & "' and name = '" & fname & "' and date = '" & Today & "'"
command = New MySqlCommand(query, conn)
reader = command.ExecuteReader

Dim count As Integer


count = 0
While reader.Read
count = count + 1
End While
If count = 0 Then
conn.Close()
Try
conn.Open()
Dim cmd3 As New MySqlCommand("INSERT INTO ac
cess(empid,name,date,timein) values ('" & idno & "','" & fname & "', '" & Today
& "', '" & TimeOfDay & "' )", conn)
cmd3.ExecuteNonQuery()
MessageBox.Show("Access Granted. Date and Ti
me were recorded.")
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
conn.Dispose()
End Try

ElseIf count = 1 Then


conn.Close()

Try
conn.Open()
Dim cmd4 As New MySqlCommand("UPDATE access
set timeout = '" & TimeOfDay & "' where name = '" & fname & "' ", conn)
cmd4.ExecuteNonQuery()
MessageBox.Show("Access Granted. Date and Ti
me were recorded.")
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
conn.Dispose()
End Try
Else
MessageBox.Show("Nothing")
End If

Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
conn.Dispose()
End Try

Else
SetStatus("The fingerprint was NOT VERIFIED.")
End If
Finally
conn.Close()
End Try

End Using

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

' End If
End Sub
Protected Sub UpdateStatus(ByVal FAR As Integer)
' Show "False accept rate" value
SetStatus(String.Format("False Accept Rate (FAR) = {0}", FAR))
End Sub
Private Sub verificationMainForm_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
End Sub
End Class

-------------------------------------------SAVING IMAGE TO BLOB-----------------------------------------Imports


Imports
Imports
Imports

System.IO
System.Data
System.Configuration
MySql.Data.MySqlClient

Protected Sub UploadFile(sender As Object, e As EventArgs)


Dim filename As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
Dim contentType As String = FileUpload1.PostedFile.ContentType
Using fs As Stream = FileUpload1.PostedFile.InputStream
Using br As New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(DirectCast(fs.Length, Long))
Dim constr As String = ConfigurationManager.ConnectionStrings("const
r").ConnectionString
Using con As New MySqlConnection(constr)
Dim query As String = "INSERT INTO Files(FileName, ContentType,
Content) VALUES (@FileName, @ContentType, @Content)"
Using cmd As New MySqlCommand(query)
cmd.Connection = con
cmd.Parameters.AddWithValue("@FileName", filename)
cmd.Parameters.AddWithValue("@ContentType", contentType)

cmd.Parameters.AddWithValue("@Content", bytes)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
End Using
End Using
Response.Redirect(Request.Url.AbsoluteUri)
End Sub

------------------------------------DISPLAYING THE IMAGE IN PICTURE BOX------------------------------------Dim ServerString As String = "Server=localhost;User=root;Password='';Database=L


ogSys"
Dim SQLConnection As MySqlConnection = New MySqlConnection
'Dim connection As New SqlConnection("connection string here")
Dim command As New MySqlCommand("SELECT file FROM emp WHERE `ClockNo` L
IKE '%" & txtClockNo.Text & "%'", CONNECTION)
CONNECTION.Open()
Dim pictureData As Byte() = DirectCast(command.ExecuteScalar(), Byte())
connection.Close()
Dim picture As Image = Nothing
'Create a stream in memory containing the bytes that comprise the image.
Using stream As New IO.MemoryStream(pictureData)
'Read the stream and create an Image object from the data.
PictureBox1.Image = Image.FromStream(stream)
End Using
----------------------------FITTING THE IMAGE------------------------Picturebox1.SizeMode=PictureBoxSizeMode.StretchImage

---------------------------CAPTURE---------------------Imports System.IO
Public Class FrmCap
'Create constant using attend in function of DLL file.
Const
Const
Const
Const

CAP As Short = &H400S


CAP_DRIVER_CONNECT As Integer = CAP + 10
CAP_DRIVER_DISCONNECT As Integer = CAP + 11
CAP_EDIT_COPY As Integer = CAP + 30

Const
Const
Const
Const
Const
Const
Const
Const
Const

CAP_SET_PREVIEW As Integer = CAP + 50


CAP_SET_PREVIEWRATE As Integer = CAP + 52
CAP_SET_SCALE As Integer = CAP + 53
WS_CHILD As Integer = &H40000000
WS_VISIBLE As Integer = &H10000000
SWP_NOMOVE As Short = &H2S
SWP_NOSIZE As Short = 1
SWP_NOZORDER As Short = &H4S
HWND_BOTTOM As Short = 1

Dim iDevice As Integer = 0 ' Normal device ID


Dim hHwnd As Integer ' Handle value to preview window
' Declare function from AVI capture DLL.
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
ByVal lParam As Object) As Integer
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As I
nteger, _
ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, _
ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean
Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _
(ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Short, ByVal hWndParent As Integer, _
ByVal nID As Integer) As Integer
Private Sub OpenForm()
Dim iHeight As Integer = picCapture.Height
Dim iWidth As Integer = picCapture.Width
' Open Preview window in picturebox .
' Create a child window with capCreateCaptureWindowA so you can display it in a
picturebox.
hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, _
480, picCapture.Handle.ToInt32, 0)
' Connect to device
If SendMessage(hHwnd, CAP_DRIVER_CONNECT, iDevice, 0) Then
' Set the preview scale
SendMessage(hHwnd, CAP_SET_SCALE, True, 0)
' Set the preview rate in milliseconds
SendMessage(hHwnd, CAP_SET_PREVIEWRATE, 66, 0)
' Start previewing the image from the camera
SendMessage(hHwnd, CAP_SET_PREVIEW, True, 0)
' Resize window to fit in picturebox
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, picCapture.Width, picCapture.Height, _
SWP_NOMOVE Or SWP_NOZORDER)
Else
' Error connecting to device close window

DestroyWindow(hHwnd)
End If
End Sub
' Use SendMessage to copy the data to the clipboard Then transfer the image to t
he picture box.
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.Event
Args) Handles btnSave.Click
Dim data As IDataObject
Dim bmap As Image
' Copy image to clipboard
SendMessage(hHwnd, CAP_EDIT_COPY, 0, 0)
' Get image from clipboard and convert it to a bitmap
data = Clipboard.GetDataObject()
If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image)
picCapture.Image = bmap
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "Jpeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif"
saveFileDialog1.Title = "Save an Image File"
saveFileDialog1.FileName = "Image001"
saveFileDialog1.ShowDialog()
' If the file name is not an empty string open it for saving.
If saveFileDialog1.FileName <> "" Then
' Saves the Image via a FileStream created by the OpenFile method.
Dim fs As System.IO.FileStream = CType _
(saveFileDialog1.OpenFile(), System.IO.FileStream)
picCapture.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg)
fs.Close()
End If
End If
End Sub
Private Sub frmcap_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Ha
ndles Me.Leave
' Disconnect from device
SendMessage(hHwnd, CAP_DRIVER_DISCONNECT, iDevice, 0)
' close window
DestroyWindow(hHwnd)
End Sub
Private Sub FRMCAP_Load(ByVal sender As System.Object, ByVal e As System.EventAr
gs) Handles MyBase.Load
OpenForm()
End Sub
End Class
--------------------------------CRYSTAL REPORT SELECT--------------------Imports CrystalDecisions.CrystalReports.Engine
Imports System.IO
Public Class Form1

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


.EventArgs) Handles Button1.Click
Dim cryReport As New ReportDocument
RepLocation = Path.GetFullPath( _
Path.Combine(Application.StartupPath, "..\..")) & _
"\CrystalReport1.rpt"
cryReport.Load(RepLocation)
If TextBox1.Text <> "" Then
cryReport.RecordSelectionFormula = "{Customer.CustomerID} = " & Text
Box1.Text
End If
CrystalReportViewer1.ReportSource = cryReport
CrystalReportViewer1.Refresh()
End Sub
End Class

Das könnte Ihnen auch gefallen