Example #1
0
        // Login Button (MouseClick)
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            // If the username or password box are empty, print error
            if (txtUsername.Text.Length < 1 || txtPassword.Password.Length < 1)
            {
                MessageBox.Show("Please enter a username and password before continuing!");
                return;
            }

            try
            {
                // Create and open connection to DB
                var sqliteCon = new SQLiteConnection(DbConnectionString);
                sqliteCon.Open();
                // Lookup username + password from textboxes in the DB
                var query = "SELECT * FROM userinfo WHERE username = '******' AND password = '******'";
                // Create a command with the SQL query and pass to the DB connection
                var createCommand = new SQLiteCommand(query, sqliteCon);
                // Execute the query
                createCommand.ExecuteNonQuery();

                // Create data reader
                var dr = createCommand.ExecuteReader();
                // Keep track of attempted login count
                var count = 0;
                while (dr.Read())
                {
                    count++;
                }
                // Login logic processes username and password
                switch (count)
                {
                    case 1:
                        sqliteCon.Close(); // Close SQLite connection
                        var profile = new ProfileWindow(GetUsername); // Create new window
                        profile.Show(); // Show the new window
                        Close(); // Close the current window
                        break;
                    default:
                        MessageBox.Show("Username and password is incorrect! Try again!");
                        break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 // Back button (Click)
 private void btnBack_Click(object sender, RoutedEventArgs e)
 {
     var profile = new ProfileWindow(GetUsername); // Create new window
     profile.Show(); // Show the new window
     Close(); // Close the current window
 }