Ejemplo n.º 1
0
 // Method for when the login button is clicked that looks at the entered data and checks continues the application to the next window.
 private void loginButton_Click(object sender, EventArgs e)
 {
     try
     {
         // Connects to the database.
         using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Data.accdb;Jet OLEDB:Database Password=01827711125;"))
         {
             // Selects the password from the database where the profile name is equal to the entered profile name.
             OleDbCommand command = new OleDbCommand("SELECT userPassword FROM Login WHERE Profile = \"" + textBox1.Text + "\";", connection);
             connection.Open();
             OleDbDataReader reader = command.ExecuteReader();
             if (reader.Read())
             {
                 // Checks if the entered password is equal to the password.
                 if (reader.GetString(0) == textBox2.Text)
                 {
                     // Opens the next window carrying the profile name.
                     Encrpt en = new Encrpt();
                     en.profileName = textBox1.Text;
                     en.setFiles();
                     en.label1.Text = "Hello " + en.profileName;
                     this.Hide();
                     en.Show();
                     connection.Close();
                     connection.Close();
                 }
                 // Elses in case details are wrong.
                 else
                 {
                     MessageBox.Show("Sorry there was an error logging in!", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                     connection.Close();
                     textBox2.Text = "";
                 }
             }
             else
             {
                 MessageBox.Show("Sorry there was an error logging in!", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 connection.Close();
                 textBox2.Text = "";
             }
         }
     }
     // Exception in case any problems occur.
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 2
0
        // Method for scanning the NFC to continue to the next window.
        private void nfcScan_Click(object sender, EventArgs e)
        {
            try
            {
                // Connects to the database
                using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Data.accdb;Jet OLEDB:Database Password=01827711125;"))
                {
                    // Establishes connection with the card reader.
                    Card card = new Card();
                    card.SelectDevice();
                    card.establishContext();

                    // Selects the profile where the UID where the UID is the same as the UID from the database.
                    OleDbCommand command = new OleDbCommand("SELECT Profile FROM Login WHERE UID = \"" + card.searchForTag() + "\";", connection);
                    connection.Open();
                    OleDbDataReader reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        // Continues to the next window and transfers the Profile Name.
                        Encrpt en = new Encrpt();
                        en.profileName = reader.GetString(0);
                        en.setFiles();
                        en.label1.Text = "Hello " + en.profileName;
                        this.Hide();
                        en.Show();
                        connection.Close();
                    }
                    // Else in case the information is wrong.
                    else
                    {
                        connection.Close();
                        MessageBox.Show("Sorry no NFC Tag was found!", "Failed NFC Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            // Exception for if the NFC Reader is not connected.
            catch (ArgumentOutOfRangeException)
            {
                MessageBox.Show("Make sure your NFC reader to connected!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            // Exception if there are any errors.
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }