Documente Academic
Documente Profesional
Documente Cultură
Press once on C#
2008
Lab 1
Press once on
Windows Form
Applications
Properties of Form1
Text: Fingerprint
Biometrics
Size : 712, 497
Lab 1
Step 5 Design the Form according to the graphic user interface below:
Properties of
Properties of
Properties of
Properties of
groupBox
button1
button2
button3
Name: groupBox1
Name: btnEnroll
Name: btnStop
Name: btnExit
Location: 12, 12
Location: 16, 32
Location: 97, 90
Location: 619, 431
Size : 184, 124
Size : 75, 23
Size : 75, 23
Size : 75, 23
Text: Operations
Text: Enroll
Text: Stop
Text: Exit
Properties of
Properties of
Properties of
PictureBox1
PictureBox2
PictureBox3
Name: FingerPrint1
Name: FingerPrint2
Name: FingerPrint3
BorderStyle: Fixed3D
BorderStyle: Fixed3D
BorderStyle: Fixed3D
Location: 202, 8
Location: 368, 8
Location: 534, 8
Size : 160, 210
Size : 160, 210
Size : 160, 210
SizeMode:
SizeMode:
SizeMode:
Properties of Label
Name: lblMessage
AutoSize: False
BorderStyle: FixedSingle
Location: 10, 221
Size : 684, 23
Text:
Lab 1
Lab 1
Browse through
the harddisk to
find the programs
for DbRecord.cs
Lab 1
Browse through
the harddisk to
find the programs
for
EnrollmentName.
Lab 1
Step 8a coding.
Step 8b coding.
Lab 1
/// <summary>
/// A directory name to write user's information.
/// </summary>
private String m_DatabaseDir;
/// <summary>
/// This delegate enables asynchronous calls for setting
/// the Image property on a PictureBox control.
/// </summary>
/// <param name="hBitmap">the instance of Bitmap class</param>
delegate void SetImageCallback(Bitmap hBitmap);
///
///
///
///
<summary>
This int allows the program to count the number of finger print
template has been captured.
</summary>
int FingerPrintNum = 1;
Step 8c coding.
try
{
m_DatabaseDir = GetDatabaseDir();
}
catch (IOException)
{
MessageBox.Show(this, "Initialization failed. Application will be
close.\nCan not create database folder",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
Lab 1
///
///
///
///
{
<summary>
Get the database directory.
</summary>
<returns>returns the database directory.</returns>
public static String GetDatabaseDir()
String szDbDir;
szDbDir = Path.Combine(Directory.GetCurrentDirectory(), "Database");
//Create the directory of the database at the Bin folder of the program.
if (!Directory.Exists(szDbDir))
{
Directory.CreateDirectory(szDbDir);
//Create the directory of the database at the Bin folder
}
return szDbDir;
Lab 1
Step 8f. Double click on the enroll button to type the coding for enrollment.
FingerPrint1.BackgroundImage = null;
FingerPrint2.BackgroundImage = null;
FingerPrint3.BackgroundImage = null;
DbRecord User = new DbRecord();
// Get user name
EnrollmentName frmName = new EnrollmentName();
frmName.ShowDialog( this );
if (frmName.DialogResult != DialogResult.OK )
{
return;
}
if( frmName.UserName.Length == 0)
{
MessageBox.Show( this, "You must enter a username.", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
return;
}
// Try creat the file for user's information
if( isUserExists(frmName.UserName) )
{
DialogResult nResponse;
nResponse = MessageBox.Show("User already exists. Do you want replace it?",
"C# example for Futronic SDK", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (nResponse == DialogResult.No)
return;
10
Lab 1
else
{
try
{
CreateFile(frmName.UserName);
}
catch (DirectoryNotFoundException)
{
MessageBox.Show(this, "Can not create file to save an user's information.",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
catch (IOException )
{
MessageBox.Show(this, String.Format("Bad user name '{0}'.", frmName.UserName),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
User.UserName = frmName.UserName;
m_OperationObj = User;
if (m_Operation != null)
{
m_Operation.Dispose();
m_Operation = null;
}
m_Operation = new FutronicEnrollment();
// Set control properties
m_Operation.FakeDetection = true;
m_Operation.FFDControl = true;
m_Operation.FARN = 166;
((FutronicEnrollment)m_Operation).MIOTControl = true;
((FutronicEnrollment)m_Operation).MaxModels = 3;
EnableControls(false);
// register events
m_Operation.OnPutOn += new OnPutOnHandler(this.OnPutOn);
m_Operation.OnTakeOff += new OnTakeOffHandler(this.OnTakeOff);
m_Operation.UpdateScreenImage += new UpdateScreenImageHandler(this.UpdateScreenImage);
m_Operation.OnFakeSource += new OnFakeSourceHandler(this.OnFakeSource);
((FutronicEnrollment)m_Operation).OnEnrollmentComplete += new
OnEnrollmentCompleteHandler(this.OnEnrollmentComplete);
// start enrollment process
((FutronicEnrollment)m_Operation).Enrollment();
11
Lab 1
private void
Progress)
protected
boolOnTakeOff(FTR_PROGRESS
isUserExists(String UserName)
{{
this.SetStatusText("Remove
thumb/finger from device");
String
szFileName;
}
szFileName = Path.Combine(m_DatabaseDir, UserName );
return File.Exists(szFileName);
}private void UpdateScreenImage(Bitmap hBitmap)
{
Do not
change the state bEnable)
control during application closing.
private//void
EnableControls(bool
if (m_bExit)
{
return;
// Do not
change the state control during application closing.
if (m_bExit)
if (FingerPrintNum
== 1)
return;
{
if (this.InvokeRequired)
if (FingerPrint1.InvokeRequired)
{
{
EnableControlsCallback
d = new EnableControlsCallback(this.EnableControls);
SetImageCallback
= new SetImageCallback(this.UpdateScreenImage);
this.Invoke(d,
new object[] { dbEnable
});
this.Invoke(d, new object[] { hBitmap });
}
}
else
else
{
{
btnEnroll.Enabled
= bEnable;
FingerPrint1.Image
= hBitmap;
btnStop.Enabled
= !bEnable;
FingerPrintNum++;
}
}
}
}
private void OnPutOn(FTR_PROGRESS Progress)
else if (FingerPrintNum == 2)
{
{
this.SetStatusText("Place
thumb/finger on device.");
if (FingerPrint2.InvokeRequired)
}
{
SetImageCallbacktext)
d = new SetImageCallback(this.UpdateScreenImage);
private void SetStatusText(String
this.Invoke(d,
new
object[] { hBitmap });
{
}
// Do not change the state control during application closing.
else )
if( m_bExit
{
return;
FingerPrint2.Image = hBitmap;
FingerPrintNum++;
if( this. lblMessage.InvokeRequired
)
}
{
SetTextCallback d = new SetTextCallback(this.SetStatusText);
}
this.Invoke( d, new object[] { text } );
}
else if (FingerPrintNum == 3)
else
{{
if (FingerPrint3.InvokeRequired)
this.
lblMessage.Text = text;
{ this.Update();
SetImageCallback d = new SetImageCallback(this.UpdateScreenImage);
}
this.Invoke(d, new object[] { hBitmap });
}
}
else
{
ITE College WestFingerPrint3.Image = hBitmap;
12
FingerPrintNum
= 1;
EC5004PA Integrated
Security System
Design
}
}
}
Lab 1
);
}
DialogResult result;
result = MessageBox.Show("Fake source detected. Do you want continue process?",
"C# example for Futronic SDK",MessageBoxButtons.YesNo, MessageBoxIcon.Question
return (result == DialogResult.No);
13
Lab 1
14
Lab 1
m_Operation.OnCalcel();
15
Lab 1
base.Hide();
m_bExit = true;
this.Close();
Step 9. Build the solution by keying F5, and run debug by pressing F6.
Step 10: When there is no error, test your program with the Finger Print Scanner.
Step 11: Save your project.
Conclusion
ITE College West
EC5004PA Integrated Security System Design
16
Lab 1
What they do
SetStatusText(Hello)
Close()
String szFileName;
szFileName =
Path.Combine(m_DatabaseDir, UserName);
File.Create(szFileName).Close();
File.Delete(szFileName);
FingerPrint1.BackgroundImage = null;
MessageBox.Show(Welcome)
szDbDir =
Path.Combine(Directory.GetCurrentDirectory()
, "Database");
szMessage.Append("Enrollment process
failed.");
szMessage.Append("Error description: ");
17