Ir ao conteúdo
  • Cadastre-se

C# Problema em identificar qual variavel será lida do Banco para validar os dados


Posts recomendados

Recentemente criei um programa de Portaria para minha empresa, utilizando a SDK da Digital Persona em C#..

Estou travado na parte de "Autenticar" os dados, exemplo:

João cadastrou a digital>Quando a Digital de João ser lida, o programa busca no DB se é correspondente com a que ele tem cadastrada.. ou deveria, o que acontece é que ele apenas "valida" se existe a digital cadastrada, no caso quando eu precisar coletar os outros dados da pessoa (Nome,ID) ele coleta um nome aleatório que a digital não está corresponde. para melhor entendimento, coloquei o código abaixo (Desculpe a falta de indentação, usei o template fornecido pela empresa):

 

Recentemente criei um programa de Portaria para minha empresa, utilizando a SDK da Digital Persona em C#..

Estou travado na parte de "Autenticar" os dados, exemplo:

João cadastrou a digital>Quando a Digital de João ser lida, o programa busca no DB se é correspondente com a que ele tem cadastrada.. ou deveria, o que acontece é que ele apenas "valida" se existe a digital cadastrada, no caso quando eu precisar coletar os outros dados da pessoa (Nome,ID) ele coleta um nome aleatório que a digital não está corresponde. para melhor entendimento, coloquei o código abaixo (Desculpe a falta de indentação, usei o template fornecido pela empresa):

using DPFP;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyAttendance
{
    public partial class teste : Form, IComponent, DPFP.Capture.EventHandler
    {
        public teste()
        {
            InitializeComponent();
            this.Load += new EventHandler(FingerPrintVerificationUserControl_Load);
            this.HandleDestroyed += new EventHandler(FingerPrintVerificationUserControl_HandleDestroyed);
            Stop();
        }
        int cont = 0;

        private bool isVerificationComplete = false;
        public bool IsVerificationComplete
        {
            get { return this.isVerificationComplete; }
            set
            {
                if (value != this.isVerificationComplete)
                {
                    this.isVerificationComplete = value;
                    if (this.VerificationStatusChanged != null)
                    {
                        this.VerificationStatusChanged(this, new StatusChangedEventArgs(value));
                    }
                }
            }

        }





        public object VerifiedObject
        {
            get;
            private set;
        }


        private DPFP.Capture.Capture Capturer;
        public Dictionary<DPFP.Template, object> Samples = new Dictionary<DPFP.Template, object>();
        private DPFP.Verification.Verification Verificator;

        public event StatusChangedEventHandler VerificationStatusChanged;

        delegate void Function();

        #region Form Event Handlers:
        private void FingerPrintVerificationUserControl_Load(object sender, EventArgs e)
        {

        }

        private void FingerPrintVerificationUserControl_HandleDestroyed(object sender, EventArgs e)
        {
            Stop();
        }

        #endregion

        #region FingerPrint Handlers

        protected virtual void Process(DPFP.Sample Sample)
        {
            DrawPicture(FingerPrintUtility.ConvertSampleToBitmap(Sample));

            //try
            //{
            DPFP.FeatureSet features = FingerPrintUtility.ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification);
            SetPanelColor(System.Drawing.SystemColors.Control);
            SetPrompt("Verifying...");
            if (features != null)
            {
                // Compare the feature set with our template
                bool verified = false;
                foreach (DPFP.Template template in this.Samples.Keys)
                {

                    DPFP.Verification.Verification.Result result = new DPFP.Verification.Verification.Result();
                    Verificator.Verify(features, template, ref result);
                    if (result.Verified)
                    {
                        this.VerifiedObject = Samples[template];
                        verified = true;
                        SetPrompt("Verified.");

                        Stop();
                    }
                }
                this.IsVerificationComplete = verified;
                if (!verified)
                {
                    SetPrompt("Finger print not recognised.");
                }
            }
            else
            {
                SetPrompt("Can't recognize as a fingerprint.");
            }
            //}
            //catch (Exception)
            //{
            //    SetPrompt("Error!");
            //}
        }

        protected virtual void Init()
        {
            try
            {
                Capturer = new DPFP.Capture.Capture();
                Verificator = new DPFP.Verification.Verification();
                if (null != Capturer)
                {
                    Capturer.EventHandler = this;
                }
                else
                {
                    MessageBox.Show("Can't initiate capture operation!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch
            {
                MessageBox.Show("Can't initiate capture operation!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        protected void Start()
        {
            if (null != Capturer)
            {
                try
                {
                    Capturer.StartCapture();
                    SetPrompt("Give fingerprint samples.");
                }
                catch
                {
                    SetPrompt("Can't initiate capture!");
                }
            }
        }

        protected void Stop()
        {
            if (null != Capturer)
            {
                try
                {
                    Capturer.StopCapture();

                }
                catch
                {
                    SetPrompt("Can't terminate capture!");
                }
            }
        }

        public void OnComplete(object Capture, string ReaderSerialNumber, DPFP.Sample Sample)
        {
            SetPrompt("Fingerprint scan complete.");
            Process(Sample);
        }

        public void OnFingerGone(object Capture, string ReaderSerialNumber)
        {
            SetPrompt("Finger removed.");
            SetPanelColor(System.Drawing.SystemColors.Control);
        }

        public void OnFingerTouch(object Capture, string ReaderSerialNumber)
        {

            SetPrompt("Finger touched.");
            SetPanelColor(Color.Red);
        }

        public void OnReaderConnect(object Capture, string ReaderSerialNumber)
        {
            SetPrompt("Fingerprint reader connected.");
        }

        public void OnReaderDisconnect(object Capture, string ReaderSerialNumber)
        {
            SetPrompt("Fingerprint reader disconnected.");
        }

        public void OnSampleQuality(object Capture, string ReaderSerialNumber, DPFP.Capture.CaptureFeedback CaptureFeedback)
        {
            if (CaptureFeedback == DPFP.Capture.CaptureFeedback.Good)
                SetPrompt("Good scan.");
            else
                SetPrompt("Poor scan.");
        }

        #endregion

        private void SetPrompt(string prompt)
        {
            this.Invoke(new Function(delegate ()
            {
                Prompt.Text = prompt;
            }));
        }

        private void SetPanelColor(Color color)
        {
            this.Invoke(new Function(delegate ()
            {
                this.BackColor = color;
            }));
        }

        private void DrawPicture(Bitmap bitmap)
        {
            this.Invoke(new Function(delegate ()
            {
                FingerPrintPicture.Image = new Bitmap(bitmap, FingerPrintPicture.Size); // fit the image into the picture box
            }));
        }

        private void ClearFPSamples_Click(object sender, EventArgs e)
        {

        }

        #region classes
        void ValidateUser()
        {
            using (MySqlConnection con = new MySqlConnection(Helper.GetConnection()))
            {
                con.Open();
                string query = @"SELECT * FROM user ";
                using (MySqlCommand cmd = new MySqlCommand(query, con))

                using (MySqlDataReader data = cmd.ExecuteReader())
                {

                    while (data.Read())
                    {
                        byte[] fingerPrint = (byte[])data["FingerPrint"];
                        Samples.Add(new DPFP.Template(new MemoryStream(fingerPrint)), null);

                        if (isVerificationComplete == true)
                        {
                            string query2 = @"SELECT * FROM user WHERE FingerPrint LIKE '" +   + "'";
                            tb_id.Text = data["id"].ToString();
                            tb_nome.Text = data["nome"].ToString();
                        }





                    }





                }

            }
        }

        void ValidateUser2()
        {
            using (MySqlConnection con = new MySqlConnection(Helper.GetConnection()))
            {
                con.Open();
                string query = @"SELECT * FROM user where FingerPrint like '" + Samples + "'";
                using (MySqlCommand cmd = new MySqlCommand(query, con))

                using (MySqlDataReader data = cmd.ExecuteReader())
                {

                    while (data.Read())
                    {

                            tb_id.Text = data["id"].ToString();
                            tb_nome.Text = data["nome"].ToString();

                    }
                }

            }
        }
        #endregion

        private void button1_Click(object sender, EventArgs e)
        {
            Init();
            Start();
            ValidateUser();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ValidateUser2();
        }

        private void FingerPrintPicture_BackgroundImageChanged(object sender, EventArgs e)
        {

        }

        private void FingerPrintPicture_ControlAdded(object sender, ControlEventArgs e)
        {

        }

        private void FingerPrintPicture_Layout(object sender, LayoutEventArgs e)
        {

        }
    }
}

 

 

agradeço desde já.

Segue também print da tabela onde está os dados no DB..

Meu problema está na parte:

void ValidateUser2()
    {
        using (MySqlConnection con = new MySqlConnection(Helper.GetConnection()))
        {
            con.Open();
            string query = @"SELECT * FROM user where FingerPrint like '" + Samples + "'";
            using (MySqlCommand cmd = new MySqlCommand(query, con))

            using (MySqlDataReader data = cmd.ExecuteReader())
            {

Não sei o que colocar entre os "+"..

 

agradeço desde já.

Segue também print da tabela onde está os dados no DB..

image.png.9df33277888f890529e767c629e68118.png

 

Link para o comentário
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...