//private void search()
        //{
        //    function = -1;
        //    System.Byte[] temp;
        //    int score = 0;
        //    templateSearch = extractTemplate(templateSearch); //the variable templateSearch receives the image

        //    GRConstants result = (GRConstants) grfingerx.IdentifyPrepare(ref templateSearch.tpt,
        //                                                                (int)GRConstants.GR_DEFAULT_CONTEXT);
        //    if (result < 0)
        //        return;

        //    currentRow = null;

        //    //linear search in the database, trying to match at least one fingerprint
        //    foreach (DBGriauleDataSet.tabelaRow rowAux in ds.tabela.Rows)
        //    {
        //        //first fingerprint test
        //        temp = rowAux.Template1;
        //        System.Array.Copy(temp, 0, template1.tpt, 0, temp.Length);
        //        template1.size = temp.Length;

        //        result = (GRConstants)grfingerx.Identify(ref template1.tpt, ref score, (int)GRConstants.GR_DEFAULT_CONTEXT);
        //        if (result == GRConstants.GR_MATCH)
        //        {
        //            currentRow = rowAux;
        //            break;
        //        }

        //        //second fingerprint test
        //        temp = rowAux.Template2;
        //        System.Array.Copy(temp, 0, template2.tpt, 0, temp.Length);
        //        template2.size = temp.Length;

        //        result = (GRConstants)grfingerx.Identify(ref template2.tpt, ref score, (int)GRConstants.GR_DEFAULT_CONTEXT);
        //        if (result == GRConstants.GR_MATCH)
        //        {
        //            currentRow = rowAux;
        //            break;
        //        }

        //        //third fingerprint test
        //        temp = rowAux.Template3;
        //        System.Array.Copy(temp, 0, template3.tpt, 0, temp.Length);
        //        template3.size = temp.Length;

        //        result = (GRConstants)grfingerx.Identify(ref template3.tpt, ref score, (int)GRConstants.GR_DEFAULT_CONTEXT);
        //        if (result == GRConstants.GR_MATCH)
        //        {
        //            currentRow = rowAux;
        //            break;
        //        }
        //    }

        //    frm.handleSearch();//the form handles the result, considering if the fingerprint was found or not
        //}

        //public int removeUser()
        //{
        //    function = -1;
        //    if (currentRow == null)
        //        return 0;

        //    currentRow.Delete();
        //    return 1;
        //}

        private void saveTemplates(System.Byte[] temp1, System.Byte[] temp2, System.Byte[] temp3)
        {
            try
            {
                //create the command
                command = connection.GetCommand("SELECT * FROM dbo.fingerprint F WHERE F.person_id=@person_id", CommandType.Text);
                // add the parameter
                command.AddParameter("@person_id", personId, SqlDbType.VarChar);
                command.AddParameter("@template1", temp1, SqlDbType.VarBinary);
                command.AddParameter("@template2", temp2, SqlDbType.VarBinary);
                command.AddParameter("@template3", temp3, SqlDbType.VarBinary);

                SqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Close();
                    if (Messaging.confirmAction("You already enrolled fingerprint! Do you want to overwrite existing ones?"))
                    {
                        command.CommandText = "UPDATE dbo.fingerprint SET "
                                              + "Template1=@template1, "
                                              + "Template2=@template2, "
                                              + "Template3=@template3 "
                                              + "WHERE person_id = @person_id";

                        int i = command.ExecuteNonQuery();
                        if (i > 0)
                        {
                            MessageBox.Show("Updated Fingerprint successfully!", title, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Update failed!", title, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else
                {
                    reader.Close();

                    command.CommandText = "INSERT INTO dbo.fingerprint (person_id, Template1, Template2, Template3) " +
                                          "VALUES (@person_id, @template1, @template2, @template3)";

                    int i = command.ExecuteNonQuery();
                    if (i > 0)
                    {
                        MessageBox.Show("Saved Fingerprint successfully!", title, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Saving failed!", title, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                Messaging.error(ex.ToString(), title);
            }
        }
Beispiel #2
0
        private string findPerson()
        {
            string act = "";

            if (txtId.Text.Equals(""))
            {
                Messaging.warning("Enter student national ID to proceed", title);
            }
            else
            {
                try
                {
                    command = connection.GetCommand("select p.action action, p.attendance_id attendance, p.time_in timeIn " +
                                                    "from dbo.time_attendance p where p.national_id=@national_id " +
                                                    "and dayDate=@dayDate", CommandType.Text);
                    //create the command
                    command.AddParameter("@national_id", txtId.Text, SqlDbType.VarChar);
                    command.AddParameter("@dayDate", dayDate, SqlDbType.Date);

                    using (command)
                    {
                        // initialize the reader and execute the command
                        SqlDataReader reader = command.ExecuteReader();

                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                act           = Convert.ToString(reader["action"]);
                                attendance_id = Convert.ToString(reader["attendance"]);
                                timeIn        = Convert.ToDateTime(reader["timeIn"]);
                            }
                        }
                        else
                        {
                            act = "2";
                        }
                        reader.Close();
                    }
                }
                catch (Exception ex)
                {
                    Messaging.error(ex.ToString(), title);
                }
            }
            return(act);
        }
Beispiel #3
0
        private bool isStaff()
        {
            bool isFound = false;

            if (txtId.Text.Equals(""))
            {
                Messaging.warning("Enter staff national ID to proceed", title);
            }
            else
            {
                try
                {
                    command = connection.GetCommand("select * from dbo.person p where p.national_id=@national_id ", CommandType.Text);
                    //create the command
                    command.AddParameter("@national_id", txtId.Text, SqlDbType.VarChar);

                    using (command)
                    {
                        // initialize the reader and execute the command
                        SqlDataReader reader = command.ExecuteReader();

                        if (reader.HasRows)
                        {
                            isFound = true;
                            while (reader.Read())
                            {
                                name = Convert.ToString(reader["surname"]) + " " + Convert.ToString(reader["first_name"]) + " "
                                       + Convert.ToString(reader["other_name"]);
                                txtName.Text = name;
                            }
                        }
                        else
                        {
                            Messaging.warning("Invalid ID number! Please re-enter ID number.", title);
                            txtId.Focus();
                        }
                        reader.Close();
                    }
                }
                catch (Exception ex)
                {
                    Messaging.error(ex.ToString(), title);
                }
            }
            return(isFound);
        }
Beispiel #4
0
        private void delete(string id)
        {
            try
            {
                command = connection.GetCommand("SELECT * FROM dbo.person WHERE national_id = @national_id", CommandType.Text);
                //create the command
                command.AddParameter("@national_id", id, SqlDbType.VarChar);
                using (command)
                {
                    // initialize the reader and execute the command
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            reader.Close();
                            command.CommandText = "DELETE FROM dbo.person WHERE national_id = @national_id";

                            int i = command.ExecuteNonQuery();
                            if (i > 0)
                            {
                                searchPerson("");
                                Messaging.information("Deleted successfully!", title);
                                clearControls();
                            }
                        }
                        else
                        {
                            Messaging.warning("No staff details found!", title);
                        }
                    }
                    studentList.searchPerson("");
                }
            }
            catch (Exception ex)
            {
                Messaging.error("Error! Failed deleting!\n" + ex.ToString(), title);
            }
        }
Beispiel #5
0
        private void savePhoto()
        {
            try
            {
                if (!txtPath.Text.Equals(""))
                {
                    //Read Image Bytes into a byte array
                    byte[] imageData = imageData = ReadFile(txtPath.Text);

                    command = connection.GetCommand("SELECT person_id = @personId FROM dbo.person_photo WHERE person_id = @personId", CommandType.Text);
                    // add the parameter
                    command.AddParameter("@personId", personId, SqlDbType.VarChar);
                    command.AddParameter("@photo", imageData, SqlDbType.Image);

                    SqlDataReader reader = command.ExecuteReader();
                    if (!reader.HasRows)
                    {
                        reader.Close();
                        command.CommandText = "INSERT INTO dbo.person_photo (person_id,photo) " +
                                              "VALUES (@personId, @photo)";
                        int i = command.ExecuteNonQuery();
                    }
                    else
                    {
                        reader.Close();
                        command.CommandText = "UPDATE dbo.person_photo SET " +
                                              "photo=@photo " +
                                              "WHERE person_id=@personId";
                        int i = command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                Messaging.error("Error! Failed to save photo!\n" + ex.ToString(), title);
            }
        }
Beispiel #6
0
        private void save()
        {
            string msg = "";

            try
            {
                if (getTextFieldValues() == true)
                {
                    //create the command
                    using (command = connection.GetCommand("SELECT national_id = @national_id FROM dbo.person WHERE national_id = @national_id", CommandType.Text))
                    {
                        // add the parameter
                        command.AddParameter("@personId", personId, SqlDbType.VarChar);
                        command.AddParameter("@surname", surname, SqlDbType.VarChar);
                        command.AddParameter("@first_name", firstName, SqlDbType.VarChar);
                        command.AddParameter("@other_name", otherName, SqlDbType.VarChar);
                        command.AddParameter("@national_id", nationalId, SqlDbType.VarChar);
                        command.AddParameter("@gender", gender, SqlDbType.VarChar);
                        command.AddParameter("@dob", dob, SqlDbType.Date);
                        command.AddParameter("@marital_status", maritalStatus, SqlDbType.VarChar);
                        command.AddParameter("@nationality", nationality, SqlDbType.VarChar);
                        command.AddParameter("@country", country, SqlDbType.VarChar);
                        command.AddParameter("@city", city, SqlDbType.VarChar);
                        command.AddParameter("@address", address, SqlDbType.VarChar);
                        command.AddParameter("@path", imagePath, SqlDbType.VarChar);
                        command.AddParameter("@email", email, SqlDbType.VarChar);
                        command.AddParameter("@mobile", mobile, SqlDbType.VarChar);
                        command.AddParameter("@landline", landline, SqlDbType.VarChar);


                        // initialize the reader and execute the command
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (isNew)
                            {
                                if (!reader.HasRows)
                                {
                                    msg = "Saving";

                                    command.CommandText = "INSERT INTO dbo.person (person_id, surname, first_name, other_name, " +
                                                          "national_id, gender, dob, marital_status, nationality, country, city, address, " +
                                                          "email,mobile,landline) " +
                                                          "VALUES (@personId, @surname, @first_name, @other_name, @national_id, @gender, @dob, " +
                                                          "@marital_status, @nationality, @country,@city,@address,@email, @mobile, " +
                                                          "@landline)";

                                    reader.Close();

                                    int i = command.ExecuteNonQuery();
                                    if (i > 0)
                                    {
                                        Messaging.information(msg + " successfully!", title);
                                        clearControls();
                                    }
                                }
                            }
                            else
                            {
                                msg = "Updating";
                                reader.Close();

                                command.CommandText = "UPDATE dbo.person SET " +
                                                      "surname= @surname," +
                                                      "first_name = @first_name, " +
                                                      "other_name= @other_name," +
                                                      "national_id= @national_id," +
                                                      "gender= @gender," +
                                                      "dob= @dob," +
                                                      "marital_status= @marital_status," +
                                                      "nationality= @nationality," +
                                                      "country= @country," +
                                                      "city= @city," +
                                                      "address= @address," +
                                                      "email= @email," +
                                                      "mobile= @mobile," +
                                                      "landline= @landline " +
                                                      "WHERE person_id = @personId";

                                int i = command.ExecuteNonQuery();
                                if (i > 0)
                                {
                                    Messaging.information(msg + " successfully!", title);
                                }
                            }
                        }

                        savePhoto();
                        studentList.searchPerson("");
                    }
                }
            }
            catch (Exception ex)
            {
                Messaging.error("Error! " + msg + " Failed!\n" + ex.ToString(), title);
            }
        }