0

I am developing a payroll system in which the attendance should be recorded from finger print machine.I have installed the SDK software, but I don't know how to deploy this in my web application. Also how can we save the finger print in our database so that we could save the attendance details according to finger print

thanks in advance Fareeda Hussain

2 Answers2

2

We have a project like this one before. You need an sdk (software development kit) to go to your device. Add that to your project references so you can communicate with it. And I believe there is a sample code in the SDK site that you could find in the case of your finger print reader which you could modify.

Anyway here is our sample code for saving fingerprint directly in the database.

private void SaveButton_Click(object sender, EventArgs e)
{
    MemoryStream fingerprintData = new MemoryStream();
    Template.Serialize(fingerprintData);
    fingerprintData.Position = 0;
    BinaryReader br = new BinaryReader(fingerprintData);
    Byte[] bytes = br.ReadBytes((Int32)fingerprintData.Length);

    //Insert the file into database
    SqlConnection cn = new SqlConnection("Data Source=10.115.5.3; Initial Catalog=EnrollmentSampledb;Integrated Security=SSPI;");
    SqlCommand cmd = new SqlCommand("INSERT INTO tblUser VALUES(@ID_NUMBER, @FIRSTNAME, @LASTNAME, @FINGERPRINT, @DATE_ADDED, @DATE_MODIFIED)", cn);
    cmd.Parameters.Add("ID_NUMBER", SqlDbType.NVarChar).Value = tboxIdNum.Text;
    cmd.Parameters.Add("FIRSTNAME", SqlDbType.NVarChar).Value = tboxFname.Text;
    cmd.Parameters.Add("LASTNAME", SqlDbType.NVarChar).Value = tboxLname.Text;
    cmd.Parameters.Add("FINGERPRINT", SqlDbType.Image).Value = bytes;
    cmd.Parameters.Add("DATE_ADDED", SqlDbType.DateTime).Value = DateTime.Now;
    cmd.Parameters.Add("DATE_MODIFIED", SqlDbType.DateTime).Value = DateTime.Now;

    cn.Open();
    cmd.ExecuteNonQuery();
    cn.Close();

    tboxIdNum.Text = "";
    tboxFname.Text = "";
    tboxLname.Text = "";
}   

see also my similar question here for saving fingerprint directly in the database.

Community
  • 1
  • 1
bot
  • 4,841
  • 3
  • 42
  • 67
0

region Funsional FingerPrint

    protected void ReaderFPMachine()
    {
        _readerCollection = ReaderCollection.GetReaders();
        foreach (Reader Reader in _readerCollection)
        {
            _fPMachineID = Reader.Description.SerialNumber;
            break;
        }

        this.CheckFingerPrint();
    }

    protected void CheckFingerPrint()
    {
        try
        {
            _finger = null;
            _reader = _readerCollection[0];
            if (!OpenReader())
            {
                //this.Close();
            }
            if (!StartCaptureAsync(this.OnCaptured))
            {
                //this.Close();
            }


        }
        catch (Exception ex)
        {

        }
    }

    private void OnCaptured(CaptureResult captureResult)
    {
        try
        {
            _finger = null;
            // Check capture quality and throw an error if bad.
            if (!CheckCaptureResult(captureResult)) return;

            //SendMessage(Action.SendMessage, "A finger was captured.");

            DataResult<Fmd> resultConversion = FeatureExtraction.CreateFmdFromFid(captureResult.Data, Constants.Formats.Fmd.ANSI);
            if (resultConversion.ResultCode != Constants.ResultCode.DP_SUCCESS)
            {
                _reset = true;
                throw new Exception(resultConversion.ResultCode.ToString());
            }

            _finger = resultConversion.Data;
            _fingerPrintID = Fmd.SerializeXml(_finger);
            //MsVisitorHd _msVisitorHd = this._vMSBL.GetSingleMsVisitorHdByFingerPrintID(_fingerXML);
            //List<MsVisitorHd> _listMsVisitorHd = this._vMSBL.GetListMsVisitorHd();
            bool _exist = false;
            //foreach (var _item in _listMsVisitorHd)
            //{

            //    Fmd _fmd = Fmd.DeserializeXml(_fingerPrintID);
            //    Fmd _fmd2 = Fmd.DeserializeXml(_item.FingerPrintID);
            //    CompareResult compareResult = Comparison.Compare(_fmd, 0, _fmd2, 0);
            //    if (compareResult.ResultCode != Constants.ResultCode.DP_SUCCESS)
            //    {
            //        _reset = true;
            //        throw new Exception(compareResult.ResultCode.ToString());
            //    }
            //    else
            //    {
            //        if (compareResult.Score < (PROBABILITY_ONE / 100000))
            //        {
            //            //_visitorExist = new MsVisitorHd();
            //            //_visitorExist = _item;
            //            _exist = true;
            //            break;
            //        }
            //        else
            //        {

            //        }

            //    }
            //}
            if (!CheckCaptureResult(captureResult)) return;

            // Create bitmap
            foreach (Fid.Fiv fiv in captureResult.Data.Views)
            {
                this.FingerPictureBox.BackgroundImage = CreateBitmap(fiv.RawImage, fiv.Width, fiv.Height);
            }
            if (_exist)
            {
                _fgMember = "Y";
                //MessageBox.Show("Sidik jadi terdaftar sebagai " + _visitorExist.VisitorName);
            }
            else
            {

                _fgMember = "N";
            }

            //SendMessage(Action.SendMessage, secondFinger.Bytes.ToString() + "Comparison resulted in a dissimilarity score of " + compareResult.Score.ToString() + (compareResult.Score < (PROBABILITY_ONE / 100000) ? " (fingerprints matched)" : " (fingerprints did not match)"));
            //SendMessage(Action.SendMessage, "Place a finger on the reader.");
            //    count = 0;
            //}
        }
        catch (Exception ex)
        {
            // Send error message, then close form
            //SendMessage(Action.SendMessage, "Error:  " + ex.Message);
        }
    }


    public bool OpenReader()
    {
        _reset = false;
        Constants.ResultCode result = Constants.ResultCode.DP_DEVICE_FAILURE;

        // Open reader
        result = _reader.Open(Constants.CapturePriority.DP_PRIORITY_COOPERATIVE);
        if (result != Constants.ResultCode.DP_SUCCESS)
        {
            MessageBox.Show("Error:  " + result);
            _reset = true;
            return false;
        }

        return _reset;
    }

    public void GetStatus()
    {
        Constants.ResultCode result = _reader.GetStatus();

        if ((result != Constants.ResultCode.DP_SUCCESS))
        {
            _reset = true;
            throw new Exception("" + result);
        }

        if ((_reader.Status.Status == Constants.ReaderStatuses.DP_STATUS_BUSY))
        {
            Thread.Sleep(50);
        }
        else if ((_reader.Status.Status == Constants.ReaderStatuses.DP_STATUS_NEED_CALIBRATION))
        {
            _reader.Calibrate();
        }
        else if ((_reader.Status.Status != Constants.ReaderStatuses.DP_STATUS_READY))
        {
            throw new Exception("Reader Status - " + _reader.Status.Status);
        }
    }

    public bool CheckCaptureResult(CaptureResult captureResult)
    {
        if (captureResult.Data == null)
        {
            if (captureResult.ResultCode != Constants.ResultCode.DP_SUCCESS)
            {
                _reset = true;
                throw new Exception(captureResult.ResultCode.ToString());
            }

            // Send message if quality shows fake finger
            if ((captureResult.Quality != Constants.CaptureQuality.DP_QUALITY_CANCELED))
            {
                throw new Exception("Quality - " + captureResult.Quality);
            }
            return false;
        }

        return true;
    }

    public bool CaptureFingerAsync()
    {
        try
        {
            GetStatus();

            Constants.ResultCode captureResult = _reader.CaptureAsync(Constants.Formats.Fid.ANSI, Constants.CaptureProcessing.DP_IMG_PROC_DEFAULT, _reader.Capabilities.Resolutions[0]);
            if (captureResult != Constants.ResultCode.DP_SUCCESS)
            {
                _reset = true;
                throw new Exception("" + captureResult);
            }

            return true;
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error:  " + ex.Message);
            return false;
        }
    }

    public Bitmap CreateBitmap(byte[] bytes, int width, int height)
    {
        byte[] rgbBytes = new byte[bytes.Length * 3];

        for (int i = 0; i <= bytes.Length - 1; i++)
        {
            rgbBytes[(i * 3)] = bytes[i];
            rgbBytes[(i * 3) + 1] = bytes[i];
            rgbBytes[(i * 3) + 2] = bytes[i];
        }
        Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);

        BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);

        for (int i = 0; i <= bmp.Height - 1; i++)
        {
            IntPtr p = new IntPtr(data.Scan0.ToInt64() + data.Stride * i);
            System.Runtime.InteropServices.Marshal.Copy(rgbBytes, i * bmp.Width * 3, p, bmp.Width * 3);
        }

        bmp.UnlockBits(data);

        return bmp;
    }

    public bool StartCaptureAsync(Reader.CaptureCallback OnCaptured)
    {
        // Activate capture handler
        _reader.On_Captured += new Reader.CaptureCallback(OnCaptured);

        // Call capture
        if (!CaptureFingerAsync())
        {
            return false;
        }

        return true;
    }

    #endregion
Community
  • 1
  • 1