コード例 #1
0
 private void HideLoginWindow()
 {
     Destroy(loginWindowInstance.gameObject);
     loginWindowInstance = null;
 }
コード例 #2
0
 public void ShowLoginWindow()
 {
     loginWindowInstance = Instantiate(loginWindowPrefab, transform);
 }
コード例 #3
0
 // Back button (Click)
 private void btnBack_Click(object sender, RoutedEventArgs e)
 {
     var login = new LoginWindow(); // Create new window
     login.Show(); // Show the new window
     Close(); // Close the current window
 }
コード例 #4
0
        // Register button (Click)
        private void btnRegister_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Only update details if all fields are populated
                if (txtUsername.Text.Length > 0 && txtPassword.Text.Length > 0 && txtForename.Text.Length > 0 && txtSurname.Text.Length > 0 && txtAge.Text.Length > 0)
                {
                    try
                    {
                        // Create and open connection to DB
                        var sqliteCon = new SQLiteConnection(DbConnectionString);
                        sqliteCon.Open();
                        // Lookup username in the database
                        var query = "SELECT * FROM userinfo WHERE username = '******'";
                        // 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 username count
                        var count = 0;
                        while (dr.Read())
                        {
                            count++;
                        }
                        // Login logic processes username and password
                        if (count > 0)
                        {
                            MessageBox.Show("Username already exists! Please try again!");
                        }
                        else
                        {
                            // Insert new user into database
                            query = "INSERT INTO userinfo (forename, surname, age, username, password) VALUES('" + txtForename.Text + "','" + txtSurname.Text + "','"
                                + txtAge.Text + "','" + txtUsername.Text + "','" + txtPassword.Text + "')";
                            // Create a command with the SQL query and pass to the DB connection
                            createCommand = new SQLiteCommand(query, sqliteCon);
                            // Execute the query
                            createCommand.ExecuteNonQuery();
                            MessageBox.Show("User has been created!");
                            var login = new LoginWindow(); // Create new window
                            login.Show(); // Show the new window
                            Close(); // Close the current window
                        }
                        sqliteCon.Close(); // Close SQLite connection
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else // If a field is left incomplete
                {
                    MessageBox.Show("Please complete all form fields!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #5
0
        // Delete account button (Click)
        private void btnDeleteAccount_Click(object sender, RoutedEventArgs e)
        {
            // If the password box is empty, print error
            if (txtPassword.Password.Length < 1)
            {
                MessageBox.Show("Please enter password to continue!");
                return;
            }

            // Dialog box to confirm account deletion
            var msgResult = MessageBox.Show("Are you sure you want to delete your account?", "Delete Account", MessageBoxButton.YesNo);
            if (msgResult == MessageBoxResult.Yes)
            {
                // Create and open connection to DB
                var sqliteCon = new SQLiteConnection(DbConnectionString);
                try
                {
                    sqliteCon.Open();
                    // Delete user from database
                    var query = "DELETE FROM userinfo WHERE username = '******'";
                    // Create a command with the SQL query and pass to the DB connection
                    var createCommand = new SQLiteCommand(query, sqliteCon);
                    // Execute the query
                    createCommand.ExecuteNonQuery();
                    MessageBox.Show("Account successfully deleted!");
                    sqliteCon.Close(); // Close SQLite connection
                    var login = new LoginWindow(); // Create new window
                    login.Show(); // Show the new window
                    Close(); // Close the current window
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }