Ejemplo n.º 1
0
        public bool SaveRecord(IdpRecord record, out string id)
        {
            MySqlCommand insertCommand = new MySqlCommand();

            insertCommand.Connection = mySqlConnection;
            if (record.ID != null)
            {
                id = record.ID;
            }
            else
            {
                string serverID = "LS1";//TODO: this shud not be here
                id = "IDPP-" + serverID + "-" + DateTime.Now.ToString();
                id = id.Replace(' ', '-').Replace('/', '-').Replace(':', '-').Replace("AM", "A").Replace("AM", "B");
            }

            insertCommand.CommandText =
                "INSERT INTO idp VALUES(@id, @date_registered, @dob, @first_name, @gender, @last_name, @lga, @marital_status, @other_names, @photo, @state, @yob, @finger_1, @finger_2, @finger_3, @finger_4, @finger_5, @finger_6, @finger_7, @finger_8, @finger_9, @finger_10)";

            insertCommand.Parameters.Add("id", MySqlDbType.VarChar).Value = id;
            insertCommand.Parameters.Add("date_registered", MySqlDbType.VarChar).Value = DateTime.Now.ToString("dd/MM/yyyy");

            insertCommand.Parameters.Add("dob", MySqlDbType.VarChar).Value            = record.DoB;
            insertCommand.Parameters.Add("first_name", MySqlDbType.VarChar).Value     = record.FirstName;
            insertCommand.Parameters.Add("gender", MySqlDbType.VarChar).Value         = record.Gender;
            insertCommand.Parameters.Add("last_name", MySqlDbType.VarChar).Value      = record.LastName;
            insertCommand.Parameters.Add("lga", MySqlDbType.VarChar).Value            = record.LGA;
            insertCommand.Parameters.Add("marital_status", MySqlDbType.VarChar).Value = record.MaritalStatus;
            insertCommand.Parameters.Add("other_names", MySqlDbType.VarChar).Value    = record.OtherNames;
            insertCommand.Parameters.Add("photo", MySqlDbType.VarChar).Value          = record.Photo;
            insertCommand.Parameters.Add("state", MySqlDbType.VarChar).Value          = record.State;
            insertCommand.Parameters.Add("yob", MySqlDbType.VarChar).Value            = record.YoB;
            for (int index = 0; index < record.Fingers.Length; index++)
            {
                int realIndex = index + 1;
                insertCommand.Parameters.Add("finger_" + realIndex, MySqlDbType.VarChar).Value = record.Fingers[index];
            }

            bool noErrorOccured = true;

            try
            {
                this.Open();
                insertCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                noErrorOccured = false;
            }
            finally
            {
                mySqlConnection.Close();
            }
            return(noErrorOccured);
        }
Ejemplo n.º 2
0
        static void Enroll(string data)
        {
            data = data.Trim();
            IdpRecord record = new IdpRecord();

            string[] dataParts = data.Split(';');
            dataParts.Where(part => part.Contains('=')).ToList().ForEach(part =>
            {
                var key   = part.Substring(0, part.IndexOf('=')).Trim();
                var value = part.Substring(part.IndexOf('=') + 1).Trim();

                if (key.ToLower() == "id")
                {
                    record.ID = value;
                }
                else if (key.ToLower() == "first_name")
                {
                    record.FirstName = value;
                }
                else if (key.ToLower() == "last_name")
                {
                    record.LastName = value;
                }
                else if (key.ToLower() == "other_names")
                {
                    record.OtherNames = value;
                }
                else if (key.ToLower() == "dob")
                {
                    record.DoB = value;
                }
                else if (key.ToLower() == "yob")
                {
                    record.YoB = value;
                }
                else if (key.ToLower() == "gender")
                {
                    record.Gender = value;
                }
                else if (key.ToLower() == "marital_status")
                {
                    record.MaritalStatus = value;
                }
                else if (key.ToLower() == "state")
                {
                    record.State = value;
                }
                else if (key.ToLower() == "lga")
                {
                    record.LGA = value;
                }
                else if (key.ToLower() == "photo")
                {
                    record.Photo = value;
                }
                else if (key.ToLower().StartsWith("finger_"))
                {
                    int position = int.Parse(key.Substring(7));
                    record.Fingers[position - 1] = value;
                }
            });
            string id;

            if (db.SaveRecord(record, out id))
            {
                Console.WriteLine("SourceAFISHelper.exe/enroll/success:" + id);
            }
            else
            {
                Console.WriteLine("SourceAFISHelper.exe/enroll/failure:Could not save record to the database");
            }
            //Console.Read();
        }