Exemple #1
0
        //private double f(int i)
        //{
        //    var f1 = 59894 - (8128 * i) + (262 * i * i) - (1.6 * i * i * i);
        //    return f1;
        //}

        private double age(Idp person)
        {
            if (person.YoB > 0)
            {
                return(DateTime.Now.Year - person.YoB);
            }
            else
            {
                return(DateTime.Now.Year - person.DoB.Year);
            }
        }
Exemple #2
0
        private void VerificationControl_OnComplete(object Control, DPFP.FeatureSet FeatureSet,
                                                    ref DPFP.Gui.EventHandlerStatus EventHandlerStatus)
        {
            FoundPerson     = null;
            picBox.Image    = null;
            btnCard.Visible = false;
            lblName.ResetText();
            lblAge.ResetText();
            lblGender.ResetText();
            lblMaritalStatus.ResetText();
            lblState.ResetText();
            lblLGA.ResetText();

            IdpDb db         = new IdpDb();
            bool  breakOuter = false;
            var   persons    = db.GetPersons();

            foreach (Idp person in persons)
            {
                int finger = 0;
                foreach (var template in person.FingerTemplates)
                {
                    finger++;
                    if (template != null)
                    {
                        matcher     = new DPFP.Verification.Verification();
                        matchResult = new DPFP.Verification.Verification.Result();
                        matcher.Verify(FeatureSet, template, ref matchResult);
                        if (matchResult.Verified)
                        {
                            //MessageBox.Show(person.FirstName + ", finger: " + finger);

                            FoundPerson = person;

                            //pic
                            if (person.Photo != null)
                            {
                                picBox.Image = new Bitmap(person.Photo, picBox.Size);
                            }

                            btnCard.Visible = true;

                            string nm = (!string.IsNullOrEmpty(person.FirstName) ? person.FirstName + " " : "") +
                                        (!string.IsNullOrEmpty(person.LastName) ? person.LastName + " " : "") +
                                        (!string.IsNullOrEmpty(person.OtherNames) ? person.OtherNames + " " : "");
                            lblName.Text = nm;
                            if (person.YoB > 0)
                            {
                                int age = DateTime.Now.Year - person.YoB;
                                lblAge.Text = "About " + age + " year(s) old";
                            }
                            else
                            {
                                int age = DateTime.Now.Year - person.DoB.Year;
                                lblAge.Text = person.DoB.Day + "/" + person.DoB.Month + "/" + person.DoB.Year +
                                              " (" + age + " year(s) old)";
                            }
                            lblGender.Text        = person.Gender;
                            lblMaritalStatus.Text = person.MaritalStatus;
                            lblState.Text         = person.State;
                            lblLGA.Text           = person.LGA;
                            breakOuter            = true;
                            break;
                        }
                    }
                }
                if (breakOuter)
                {
                    break;
                }
            }
            if (!breakOuter)
            {
                MessageBox.Show("Could not identify user!");
            }
        }
        public IdCardWindow(Idp person)
        {
            InitializeComponent();

            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.MinimizeBox     = this.MaximizeBox = false;
            this.Icon            = Properties.Resources.Icon;
            this.Size            = new Size(310, 520);
            this.StartPosition   = FormStartPosition.CenterParent;

            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            var             content     = "ID: " + person.ID + "\n" +
                                          "Name: " + person.FirstName + " " + person.LastName;

            QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(content, QRCodeGenerator.ECCLevel.M);
            Image qrcodeImg = qrCode.GetGraphic(20);

            saveDialog = new SaveFileDialog()
            {
                Filter = "Bitmap|*.bmp|JPEG|*.jpg,*.jpeg|PNG|*.png|All|*.*"
            };

            picBox = new PictureBox()
            {
                Location = new Point(2, 2),
                Size     = new Size(this.Width - 20, this.Height - 70)
            };
            this.Controls.Add(picBox);

            //draw card
            Size     size = picBox.Size;
            Bitmap   bmp  = new Bitmap(qrcodeImg, size);
            Graphics g    = Graphics.FromImage(bmp);

            //paint background
            g.Clear(Color.White);
            //paint border
            Rectangle outerRect = new Rectangle(new Point(1, 1), new Size(size.Width - 2, size.Height - 2));
            Rectangle innerRect = new Rectangle(new Point(3, 3), new Size(size.Width - 6, size.Height - 6));

            g.DrawRectangles(new Pen(Color.Black, 1f), new Rectangle[] { outerRect, innerRect });
            //paint photo
            Rectangle photoRect = new Rectangle(new Point(innerRect.X, innerRect.Y),
                                                new Size(innerRect.Width, innerRect.Height / 2));

            g.DrawImage(person.Photo, photoRect);
            //paint below photo
            Rectangle  belowRect = new Rectangle(new Point(photoRect.X, photoRect.Bottom), photoRect.Size);
            SolidBrush br        = new SolidBrush(Color.FromArgb(02, 93, 171));

            g.FillRectangle(br, belowRect);
            //write info
            string info = person.FirstName + " " + person.LastName;
            int    age  = 0;

            if (person.YoB > 0)
            {
                age   = DateTime.Now.Year - person.YoB;
                info += "\nAbout " + age + " year(s) old";
            }
            else
            {
                age   = DateTime.Now.Year - person.DoB.Year;
                info += "\n" + age + " year(s) old";
            }
            info += "\n" + person.Gender +
                    (!string.IsNullOrEmpty(person.MaritalStatus)? ", " + person.MaritalStatus: "");
            g.DrawString(info, new Font(this.Font.FontFamily, 16.0f, FontStyle.Regular), Brushes.White,
                         new Point(belowRect.Left + 10, belowRect.Top + 10));
            //draw qr code
            Rectangle qrRect = new Rectangle(new Point(belowRect.Left + 10, (belowRect.Bottom - ((2 * belowRect.Height / 5) + 30))),
                                             new Size((2 * belowRect.Width / 5), (2 * belowRect.Height / 5)));

            g.DrawImage(qrcodeImg, qrRect);
            //draw logo
            Rectangle logoRect = new Rectangle(new Point(qrRect.Left + 15, qrRect.Bottom + 2), new Size(26, 26));

            g.DrawImage(Properties.Resources.LogoWhite, logoRect);
            //write card footer
            g.DrawString("IDPs Relief Support Card", new Font(this.Font.FontFamily, 12.0f, FontStyle.Regular), Brushes.White,
                         new Point(logoRect.Right + 10, logoRect.Top + 5));
            picBox.Image = bmp;

            btnSave = new Button()
            {
                Location = new Point(picBox.Left, picBox.Bottom + 2),
                Text     = "Save"
            };
            btnSave.Click += delegate
            {
                if (picBox.Image != null)
                {
                    if (saveDialog.ShowDialog() == DialogResult.OK)
                    {
                        picBox.Image.Save(saveDialog.FileName);
                    }
                }
            };
            this.Controls.Add(btnSave);
        }
Exemple #4
0
        public Idp[] GetPersons()
        {
            MySqlCommand selectJoin = new MySqlCommand();

            selectJoin.Connection  = mySqlConnection;
            selectJoin.CommandText =
                "SELECT b.id, first_name, last_name, other_names, dob, yob, gender, marital_status, state, lga, " +
                "f.finger_1, finger_2, finger_3, finger_4, finger_5, finger_6, finger_7, finger_8, finger_9, finger_10, " +
                "p.photo " +
                "from bios as b join photos as p on b.id = p.id join fingers as f on b.id = f.id";

            List <Idp> persons = new List <Idp>();

            try
            {
                mySqlConnection.Open();
                MySqlDataReader dr = selectJoin.ExecuteReader(System.Data.CommandBehavior.SequentialAccess);
                while (dr.Read())
                {
                    Idp person = new Idp();

                    if (!dr.IsDBNull(dr.GetOrdinal("id")))
                    {
                        person.ID = dr.GetString("id");
                    }

                    if (!dr.IsDBNull(dr.GetOrdinal("first_name")))
                    {
                        person.FirstName = dr.GetString("first_name");
                    }
                    if (!dr.IsDBNull(dr.GetOrdinal("last_name")))
                    {
                        person.LastName = dr.GetString("last_name");
                    }
                    if (!dr.IsDBNull(dr.GetOrdinal("other_names")))
                    {
                        person.OtherNames = dr.GetString("other_names");
                    }
                    if (!dr.IsDBNull(dr.GetOrdinal("dob")))
                    {
                        person.DoB = dr.GetDateTime("dob");
                    }
                    if (!dr.IsDBNull(dr.GetOrdinal("yob")))
                    {
                        person.YoB = dr.GetInt32("yob");
                    }
                    if (!dr.IsDBNull(dr.GetOrdinal("gender")))
                    {
                        person.Gender = dr.GetString("gender");
                    }
                    if (!dr.IsDBNull(dr.GetOrdinal("marital_status")))
                    {
                        person.MaritalStatus = dr.GetString("marital_status");
                    }
                    if (!dr.IsDBNull(dr.GetOrdinal("state")))
                    {
                        person.State = dr.GetString("state");
                    }
                    if (!dr.IsDBNull(dr.GetOrdinal("lga")))
                    {
                        person.LGA = dr.GetString("lga");
                    }

                    for (int index = 0; index < person.FingerTemplates.Length; index++)
                    {
                        int realIndex = index + 1;
                        int ordinal   = dr.GetOrdinal("finger_" + realIndex);
                        if (!(dr.IsDBNull(ordinal)))
                        {
                            byte[]        deserializedTemplate = (byte[])dr["finger_" + realIndex];
                            DPFP.Template template             = new DPFP.Template();
                            template.DeSerialize(deserializedTemplate);
                            person.FingerTemplates[index] = template;
                        }
                    }

                    int phOrdinal = dr.GetOrdinal("photo");
                    if (!(dr.IsDBNull(phOrdinal)))
                    {
                        byte[] imgBytes = GetBytes(dr, phOrdinal);
                        person.Photo = ByteArrayToImage(imgBytes);
                    }

                    persons.Add(person);
                }
                dr.Close();
            }
            catch (Exception ex) { }
            finally
            {
                mySqlConnection.Close();
            }
            return(persons.ToArray());
        }
Exemple #5
0
        public bool SavePerson(Idp person, out string id)
        {
            MySqlCommand insertBio     = new MySqlCommand(),
                         insertPhoto   = new MySqlCommand(),
                         insertFingers = new MySqlCommand();

            insertBio.Connection = insertPhoto.Connection = insertFingers.Connection = mySqlConnection;
            id = "IDP-" + DateTime.Now.ToString();
            id = id.Replace(' ', '-').Replace('/', '|');

            insertBio.CommandText =
                "INSERT INTO bios VALUES(@id, @first_name, @last_name, @other_names, @dob, @yob, @gender, @marital_status, @state, @lga)";
            insertBio.Parameters.Add("id", MySqlDbType.VarChar).Value             = id;
            insertBio.Parameters.Add("first_name", MySqlDbType.VarChar).Value     = person.FirstName;
            insertBio.Parameters.Add("last_name", MySqlDbType.VarChar).Value      = person.LastName;
            insertBio.Parameters.Add("other_names", MySqlDbType.VarChar).Value    = person.OtherNames;
            insertBio.Parameters.Add("dob", MySqlDbType.DateTime).Value           = person.DoB;
            insertBio.Parameters.Add("yob", MySqlDbType.Int32).Value              = person.YoB;
            insertBio.Parameters.Add("gender", MySqlDbType.VarChar).Value         = person.Gender;
            insertBio.Parameters.Add("marital_status", MySqlDbType.VarChar).Value = person.MaritalStatus;
            insertBio.Parameters.Add("state", MySqlDbType.VarChar).Value          = person.State;
            insertBio.Parameters.Add("lga", MySqlDbType.VarChar).Value            = person.LGA;

            insertPhoto.CommandText =
                "INSERT INTO photos VALUES(@id, @photo)";
            insertPhoto.Parameters.Add("id", MySqlDbType.VarChar).Value = id;
            if (person.Photo != null)
            {
                var imagBytes = ImageToByteArray(person.Photo);
                //insertPhoto.Parameters.Add("photo_size", MySqlDbType.Int32).Value = imagBytes.Length;
                insertPhoto.Parameters.Add("photo", MySqlDbType.LongBlob).Value = imagBytes;
            }
            else
            {
                //insertPhoto.Parameters.Add("photo_size", MySqlDbType.Int32).Value = 0;
                insertPhoto.Parameters.Add("photo", MySqlDbType.LongBlob).Value = null;
            }

            insertFingers.CommandText =
                "INSERT INTO fingers VALUES(@id, @finger_1, @finger_2, @finger_3, @finger_4, @finger_5, @finger_6, @finger_7, @finger_8, @finger_9, @finger_10)";
            insertFingers.Parameters.Add("id", MySqlDbType.VarChar).Value = id;
            for (int index = 0; index < person.FingerTemplates.Length; index++)
            {
                var template  = person.FingerTemplates[index];
                int realIndex = index + 1;
                if (template != null)
                {
                    byte[] serializedTemplate = null;
                    template.Serialize(ref serializedTemplate);
                    insertFingers.Parameters.Add("finger_" + realIndex, MySqlDbType.Blob).Value = serializedTemplate;

                    //string stringTemplate = System.Text.Encoding.UTF8.GetString(serializedTemplate);
                    //insertFingers.Parameters.Add("finger_" + (index + 1), MySqlDbType.LongText).Value = stringTemplate;
                }
                else
                {
                    insertFingers.Parameters.Add("finger_" + realIndex, MySqlDbType.Blob).Value = null;
                }
            }

            bool noErrorOccured = true;

            try
            {
                mySqlConnection.Open();
                insertBio.ExecuteNonQuery();
                insertPhoto.ExecuteNonQuery();
                insertFingers.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                noErrorOccured = false;
            }
            finally
            {
                mySqlConnection.Close();
            }
            return(noErrorOccured);
        }
Exemple #6
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            Idp person = new Idp();

            person.Photo           = camControl.CapturedBitmap;
            person.FirstName       = txtFirstname.Text;
            person.LastName        = txtLastName.Text;
            person.OtherNames      = txtOtherNames.Text;
            person.FingerTemplates = capturedTemplates;
            if (btnDob.Checked)
            {
                person.DoB = datePicker.Value;
            }
            if (btnYoB.Checked)
            {
                int currentYear = DateTime.Now.Year;
                person.YoB = currentYear - (int)txtAge.Value;
            }
            if (genderList.SelectedItem != null)
            {
                person.Gender = genderList.SelectedItem.ToString();
            }
            if (maritalStatusList.SelectedItem != null)
            {
                person.MaritalStatus = maritalStatusList.SelectedItem.ToString();
            }
            if (statesList.SelectedItem != null)
            {
                person.State = statesList.SelectedItem.ToString();
            }
            if (lgaList.SelectedItem != null)
            {
                person.LGA = lgaList.SelectedItem.ToString();
            }

            //QRCodeGenerator qrGenerator = new QRCodeGenerator();
            //var content = "IDP-BOR-001";
            //QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(content, QRCodeGenerator.ECCLevel.M);
            //Image img = qrCode.GetGraphic(20);
            //img.Save(@"C:\Users\frank\Pictures\IDP-BOR-001.jpg");

            IdpDb  db = new IdpDb();
            string id;

            if (db.SavePerson(person, out id))
            {
                person.ID = id;

                camControl.Reset();
                txtFirstname.ResetText();
                txtFirstname.ShowHint();
                txtLastName.ResetText();
                txtLastName.ShowHint();
                txtOtherNames.ResetText();
                txtOtherNames.ShowHint();
                datePicker.Value               = DateTime.Now;
                txtAge.Value                   = txtAge.Minimum;
                genderList.SelectedItem        = null;
                genderList.Text                = "select gender";
                maritalStatusList.SelectedItem = null;
                maritalStatusList.Text         = "select marital status";
                statesList.SelectedItem        = null;
                statesList.Text                = "select state";
                lgaList.SelectedItem           = null;
                lgaList.Text                   = "select LGA";
                lgaList.Items.Clear();
                RecreateEnrollmentControl();

                capturedTemplates = null;
                capturedTemplates = new DPFP.Template[10];

                IdCardWindow idCardWin = new TestForm1.IdCardWindow(person);
                idCardWin.ShowDialog();
            }
            else
            {
                MessageBox.Show("Could not save data successfully!");
            }
        }