|
|
|
C# ผมทำสแกนลายนิ้วมืออยู่ของ sdk ผมอยากเก็บลายนิ้วมือลงใน appserv ควรแก้ตรงไหนจากโค๊สข้างล่าง ผมอยากแปลง byte ให้เป็น string แล้วโชว์ในtextbox แล้วผมจะเอาค่าจากtextboxเก็บลง database แล้วไว้ดึงจากdatabase เทียบกับลายนิ้วมือ |
|
|
|
|
|
|
|
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Data.OleDb;
using System.Collections;
using MySql.Data.MySqlClient;
namespace Biokey01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private System.Timers.Timer showpicture = new System.Timers.Timer();
bool isConnected;
int FMatchType;
int fpcHandle;
object VerTemplate;
//object RegTemplate;
string izkfpver;
private void button2_Click(object sender, EventArgs e)
{
if (rdb10.Checked)
{
axZKFPEngX1.FPEngineVersion = "10";
}
else
axZKFPEngX1.FPEngineVersion = "9";
izkfpver = axZKFPEngX1.FPEngineVersion;
axZKFPEngX1.SensorIndex = 0;
if (axZKFPEngX1.InitEngine() == 0)
{
isConnected = true;
fpcHandle = axZKFPEngX1.CreateFPCacheDB();
statusBar1.Panels[1].Text = "Sensor Connected!";
txtb1.Text = axZKFPEngX1.SensorCount.ToString();
txtb2.Text = axZKFPEngX1.SensorIndex.ToString();
txtb3.Text = axZKFPEngX1.ImageWidth.ToString();
txtb4.Text = axZKFPEngX1.ImageHeight.ToString();
txtb5.Text = axZKFPEngX1.SensorSN;
FMatchType = 0;
btnCloseSensor.Enabled = true;
//groupBox5.Enabled = true;
//groupBox3.Enabled = true;
}
else
{
txtb1.Text = "";
txtb2.Text = "";
txtb3.Text = "";
txtb4.Text = "";
txtb5.Text = "";
isConnected = false;
btnCloseSensor.Enabled = false;
}
}
private void btnCloseSensor_Click(object sender, EventArgs e)
{
axZKFPEngX1.EndEngine();
isConnected = false;
//btnCloseSensor.Enabled = false;
//groupBox5.Enabled = false;
//groupBox3.Enabled = false;
}
private void btnbrowse_Click(object sender, EventArgs e) //save FP image
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
Cursor = Cursors.WaitCursor;
saveFileDialog1.FileName = "template";
saveFileDialog1.Filter = "";
}
private void button2_Click_1(object sender, EventArgs e)
{
if (isConnected)
{
if (axZKFPEngX1.IsRegister)
{
axZKFPEngX1.CancelEnroll();
}
axZKFPEngX1.EnrollCount = 1;
axZKFPEngX1.BeginEnroll();
}
else
MessageBox.Show("No sensor connected", "error");
}
private void btnVerify_Click(object sender, EventArgs e)
{
if (txtbThreshold1.Text == "" || txtbThrehold2.Text == "")
{
MessageBox.Show("The 1:1Threhold and the 1:N Threhold can not be null!", "error!");
return;
}
if (!isConnected)
{
MessageBox.Show("Please Initial sensor first!", "notice");
return;
}
if (axZKFPEngX1.IsRegister)
{
axZKFPEngX1.CancelEnroll();
}
if (radioButton3.Checked)
{
FMatchType = 1;
}
else
{
FMatchType = 2;
}
axZKFPEngX1.BeginCapture();
}
private void axZKFPEngX1_OnCapture(object sender, AxZKFPEngXControl.IZKFPEngXEvents_OnCaptureEvent e)
{
VerTemplate = e.aTemplate;
byte[] vertemplat = (byte[])VerTemplate;
int score = 9;
int processedFPNumber = 1;
int ID;
string tempstr;
string Template = axZKFPEngX1.GetTemplateAsString();
if (e.actionResult)
{
bool ddd = false;
string temp;
axZKFPEngX1.OneToOneThreshold = Convert.ToInt32(txtbThreshold1.Text);
axZKFPEngX1.Threshold = Convert.ToInt32(txtbThrehold2.Text);
temp = axZKFPEngX1.GetTemplateAsString();
if (FMatchType == 1)
{
try
{
FileStream stream1 = new FileStream(txtPass.Text.Trim() + "/" + txtfpID.Text.Trim() + ".dat", FileMode.OpenOrCreate, FileAccess.Read);
byte[] tmpbyte = File.ReadAllBytes(txtPass.Text.Trim() + "/" + txtfpID.Text.Trim() + ".dat");
object fuck = tmpbyte;
if (axZKFPEngX1.VerFinger(ref fuck, vertemplat, false, ref ddd)) //Ó¡¶ÈÉñÓÍ
//if (axZKFPEngX1.VerFingerFromStr(ref Template, temp, false, ref ddd))
{
tempstr = "1:1 verify sucess,fingerID:" + txtfpID.Text.Trim();
statusBar1.Panels[2].Text = tempstr;
}
else
{
statusBar1.Panels[2].Text = "1:1 Verfy fail!";
}
Template = "";
}
catch
{
statusBar1.Panels[2].Text = "no such a number template!";
}
}
if (FMatchType == 2)
{
ID = axZKFPEngX1.IdentificationInFPCacheDB(fpcHandle, VerTemplate, ref score, ref processedFPNumber);
if (ID > 0)
{
String connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=userinfo.mdb";
OleDbConnection css = new OleDbConnection(connString);
css.Open();
OleDbDataAdapter data1 = new OleDbDataAdapter("select * from userinfo where userid="+ID+"", css);
DataSet dt = new DataSet();
data1.Fill(dt, "f1");
string fingerid1 = (string)dt.Tables["f1"].Rows[0][1];
css.Close();
dt.Clear();
tempstr = "1£ºN verify success, fingerID:"+fingerid1;
statusBar1.Panels[2].Text = tempstr;
}
else
statusBar1.Panels[2].Text = "1:N Verify fail!";
}
}
}
private void axZKFPEngX1_OnEnroll(object sender, AxZKFPEngXControl.IZKFPEngXEvents_OnEnrollEvent e)
{
//int i = 0;
if (e.actionResult)
{
// RegTemplate = e.aTemplate;
byte[] tmp = new byte[0];
tmp =(byte[]) e.aTemplate;
// string sql2 = "INSERT INTO checkdate ";
// sql2 += "SET no = '" + ID + "',date = '" + textBox1.Text + "',time = '" + comboBox2.Text + "'";
// MySqlCommand cmd2 = new MySqlCommand(sql2, conn);
// cmd2.ExecuteNonQuery();
try
{
String connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=userinfo.mdb";
OleDbConnection css = new OleDbConnection(connString);
string sql = "insert into userinfo(fingerid) values('" + txtbIndex.Text.Trim() + "')";
OleDbCommand cmd = new OleDbCommand(sql, css);
css.Open();
int aa = cmd.ExecuteNonQuery();
css.Close();
}
catch
{
statusBar1.Panels[2].Text = "This ID have existed!";
return;
}
String connString1 = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=userinfo.mdb";
OleDbConnection css1 = new OleDbConnection(connString1);
string sql1 = "select * from userinfo where fingerid='" + txtbIndex.Text.Trim() + "'";
css1.Open();
OleDbDataAdapter data11 = new OleDbDataAdapter(sql1, css1);
DataSet dt = new DataSet();
data11.Fill(dt, "f1");
int UserID = (int)dt.Tables["f1"].Rows[0][0];
css1.Close();
dt.Clear();
axZKFPEngX1.AddRegTemplateToFPCacheDB(fpcHandle, UserID, e.aTemplate);
saveFileDialog1.Filter = "*.dat|*.dat";
saveFileDialog1.FileName ="./template data/"+ txtbIndex.Text.Trim()+".txt";
File.WriteAllBytes(saveFileDialog1.FileName, tmp);
// tmp = Convert.ToString();
// MessageBox.Show(tmp.ToString());
}
}
private void axZKFPEngX1_OnImageReceived(object sender, AxZKFPEngXControl.IZKFPEngXEvents_OnImageReceivedEvent e)
{
}
private void axZKFPEngX1_OnFeatureInfo(object sender, AxZKFPEngXControl.IZKFPEngXEvents_OnFeatureInfoEvent e)
{
string strTemp="FP Quality:";
if (e.aQuality == 0)
{
strTemp = strTemp + "Qualified";
}
else
{
if (e.aQuality == 1)
{
strTemp = strTemp + "Feature points not enough";
}
else
strTemp = strTemp + "Unqualified";
}
if (axZKFPEngX1.IsRegister)
if (axZKFPEngX1.EnrollIndex != 1)
//strTemp := strTemp + #13+ 'Register status: still press finger ' + IntToStr(ZKFPEngX1.EnrollIndex-1) + ' time!';
strTemp = strTemp + "\r\n finger enroll:press finger " + (axZKFPEngX1.EnrollIndex - 1).ToString() + " times again";
else
strTemp = strTemp + "\r\n finger enroll: success enroll";
statusBar1.Panels[2].Text = strTemp;
}
private void Form1_Load(object sender, EventArgs e)
{
}
/* ~Form1()
{
showpicture.Elapsed -= new System.Timers.ElapsedEventHandler(showpicture_Elapsed);
}
*/
private void btnselect_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "*.dat|*.dat";
openFileDialog1.FileName = "./";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filepaths = Directory.GetCurrentDirectory();
txtPass.Text = filepaths;
}
}
private void button1_Click(object sender, EventArgs e)
{
if (!isConnected)
{
MessageBox.Show("Please Initial sensor first!", "notice");
return;
}
string path = txtPass.Text.Trim();
string[] files = Directory.GetFiles("./template data", "*.dat*");
if (files.Length != 0)
{
foreach (string filename in files)
{
FileInfo inf = new FileInfo(filename);
string name = inf.Name;
int ddd = name.IndexOf('.');
string fingerid= name.Remove(ddd);
String connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=userinfo.mdb";
OleDbConnection css = new OleDbConnection(connString);
string sql = "select * from userinfo where fingerid='" + fingerid + "'";
css.Open();
OleDbDataAdapter data1 = new OleDbDataAdapter(sql, css);
DataSet dt = new DataSet();
data1.Fill(dt, "f1");
int count = dt.Tables["f1"].Rows.Count;
if (count == 0)
{
continue;
}
int UserID = (int)dt.Tables["f1"].Rows[0][0];
css.Close();
dt.Clear();
FileStream stream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read);
byte[] buffer = File.ReadAllBytes(filename);
axZKFPEngX1.AddRegTemplateToFPCacheDB(fpcHandle, UserID, buffer);
}
}
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
}
private void label11_Click(object sender, EventArgs e)
{
}
}
}
Tag : .NET, MySQL, C#, VS 2010 (.NET 4.x)
|
ประวัติการแก้ไข 2012-01-10 16:51:20 2012-01-10 17:42:19
|
|
|
|
|
Date :
2012-01-10 16:46:37 |
By :
techcom23 |
View :
5213 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ช่วยทีคับผมไม่ค่อยเป็นภาษานี้
รุ่นของเครื่องคับ U.are.U 4000b scanners
|
ประวัติการแก้ไข 2012-01-10 16:55:20
|
|
|
|
Date :
2012-01-10 16:48:45 |
By :
techcom23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กำลงัทำโปรแกรมกับเครื่องตัวนี้อยู่เลยครับ @ มาคุยกันได้ครับ [email protected]
|
|
|
|
|
Date :
2012-12-09 21:46:24 |
By :
pStudio |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|