Вы находитесь на странице: 1из 2

'Author: Michael Smith 'Description: ' This form uses the two GUI controls supplied by the OTW

SDK ' The DlgUserInfo form handles saving and updating user info to a database ' The database can be created using the CreateDB.sql script in the parent directory ' Or you can just create a new db with data similar to the below: ' ' ' ' Database Name: "Identification" Table Name: "Users" Column 1: Name: "Template" DataType: varbinary(2200) Column 2: Name: "ID" DataType: nvarchar(50)

' Remember to modify the connection string and variables accordingly in the app.config file

'IMPORTANT:

You may have to re-reference the DPFPShrNet assembly **************

Imports MySql.Data.MySqlClient Imports DPFP Public Class frmEnrollFinger Private WithEvents enrollControl As DPFP.Gui.Enrollment.EnrollmentControl Private allReaderSerial As String = "00000000-0000-0000-0000-000000000000" Private Sub MainForm_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed frmEdit.Show() End Sub Private Sub VBSampleForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try If enrollControl Is Nothing Then CreateDPControl(enrollControl) End If Catch ex As Exception MessageBox.Show("ex " & ex.Message) End Try End Sub Private Sub CreateDPControl(ByRef control As DPFP.Gui.Enrollment.EnrollmentControl) Try control = New DPFP.Gui.Enrollment.EnrollmentControl() control.AutoSize = False control.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowOnly control.MaxEnrollFingerCount = 10 control.Name = "enrollControl" control.Location = New System.Drawing.Point(grpBox.Bounds.Right + 5, 12) control.ReaderSerialNumber = "00000000-0000-0000-0000-000000000000" control.Visible = True control.Enabled = True Me.Controls.Add(control) Catch ex As Exception MessageBox.Show("exception") End Try End Sub Private Sub enrollControl_OnEnroll(ByVal Control As Object, ByVal FingerMask As Integer, ByVal Template As DPFP.Template, ByRef EventHandlerStatus As DPFP.Gui.EventHandlerStatus) Handles enrollControl.OnEnroll Try global_functions.db_connect() Dim transaction As MySqlTransaction transaction = connection.BeginTransaction() Dim sqlCommand As MySqlCommand = New MySqlCommand()

sqlCommand.CommandText = "Select * from `students_db`.`finger_template` where Employee_ID ='" & Me.txtID.Text & "' and Fingermask ='" & FingerMask & "'" sqlCommand.CommandType = CommandType.Text sqlCommand.Connection = connection Dim adapter As MySqlDataAdapter = New MySqlDataAdapter adapter.SelectCommand = sqlCommand Dim dataSet As New DataSet adapter.Fill(dataSet, "finger_template") 'Dim bldr As SqlCommandBuilder = New SqlCommandBuilder(adapter) Dim bytes As Byte() = Nothing If dataSet.Tables(0).Rows.Count = 0 Then by that ID Template.Serialize(bytes) sqlCommand = New MySqlCommand("insert into finger_template (byte_template, Employee_ID,Fingermask) values (?ImageData, '" & Me.txtID.Text & "', '" & FingerMask & "')", connection, transaction) sqlCommand.Parameters.Add(New MySqlParameter("?ImageData", bytes)) sqlCommand.ExecuteNonQuery() Else 'User already exists, replace template data Template.Serialize(bytes) sqlCommand = New MySqlCommand("UPDATE `students_db`.`finger_template` SET `byte_template` = ?ImageData WHERE (`Employee_ID` = '" & Me.txtID.Text & "') and (`Fingermask` = '" & FingerMask & "')", connection, transaction) sqlCommand.Parameters.Add(New MySqlParameter("?ImageData", bytes)) sqlCommand.ExecuteNonQuery() End If 'End of saving data for user MsgBox("Template Saved!", MsgBoxStyle.OkOnly, "Succesful!") Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub enrollControl_OnDelete(ByVal Control As Object, ByVal FingerMask As Integer, ByRef EventHandlerStatus As DPFP.Gui.EventHandlerStatus) Handles enrollControl.OnDelete MsgBox("Can't do changes in this part!", MsgBoxStyle.Exclamation, "Cannot Delete...") EventHandlerStatus = Gui.EventHandlerStatus.Failure End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Close() End Sub End Class 'If no rows return-hence no user exists

Вам также может понравиться