private void deleteFriend_Click(object sender, RoutedEventArgs e)
        {
            customMessageBox deleteFriendBox = new customMessageBox("delete friend");

            deleteFriendBox.ShowDialog();
            string friendUsername = deleteFriendBox.typedMessage;

            yesnoMessageBox areyousure = new yesnoMessageBox("are you sure you want to delete this friend?");

            areyousure.ShowDialog();

            if (areyousure.yes == true)
            {
                connection.Open();
                SqlCommand command = new SqlCommand();
                command.Connection  = connection;
                command.CommandText = "usp_getIDbyUsername";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@username", friendUsername);
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                DataTable      table   = new DataTable();
                adapter.Fill(table);
                connection.Close();

                if (table.Rows.Count > 0)
                {
                    try
                    {
                        connection.Open();
                        SqlCommand command2 = new SqlCommand();
                        command2.Connection  = connection;
                        command2.CommandText = "usp_deleteFriend";
                        command2.CommandType = CommandType.StoredProcedure;
                        command2.Parameters.AddWithValue("@accountID", accountID);
                        command2.Parameters.AddWithValue("@friendID", table.Rows[0]["accountId"]);
                        command2.ExecuteNonQuery();
                        connection.Close();
                    }
                    catch (SqlException ex)
                    {
                        errorMessagesBox error = new errorMessagesBox("there was an error deleting this friend");
                        error.Show();
                    }
                    LoadFriends();
                }
                else
                {
                    errorMessagesBox error = new errorMessagesBox("you are not friends with this user");
                    error.Show();
                }
            }
            else
            {
                areyousure.Close();
            }
        }
        private void addFriend_Click(object sender, RoutedEventArgs e)
        {
            customMessageBox addFriendBox = new customMessageBox("add friend");

            addFriendBox.ShowDialog();
            string friendUsername = addFriendBox.typedMessage;

            connection.Open();
            SqlCommand command = new SqlCommand();

            command.Connection  = connection;
            command.CommandText = "usp_getIDbyUsername";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@username", friendUsername);
            SqlDataAdapter adapter = new SqlDataAdapter(command);
            DataTable      table   = new DataTable();

            adapter.Fill(table);
            connection.Close();

            if (table.Rows.Count > 0)
            {
                connection.Open();
                try
                {
                    SqlCommand command2 = new SqlCommand();
                    command2.Connection  = connection;
                    command2.CommandText = "usp_addFriend";
                    command2.CommandType = CommandType.StoredProcedure;
                    command2.Parameters.AddWithValue("@accountID", accountID);
                    command2.Parameters.AddWithValue("@friendID", table.Rows[0]["accountID"].ToString());
                    command2.ExecuteNonQuery();
                }
                catch (SqlException ex)
                {
                    errorMessagesBox error = new errorMessagesBox("there was an error adding this friend");
                    error.Show();
                }
                connection.Close();
                LoadFriends();
            }
            else
            {
                customMessageBox command2 = new customMessageBox("username doesn't exist");
                command2.ShowDialog();
            }
        }
        //various click events
        void chatbutton_Click(object sender, RoutedEventArgs e)/////////////make the chat names so when they click it you can get the details of the chat///////////////////
        {
            messages.Text = "";
            connection.Open();
            SqlCommand command = new SqlCommand();

            command.Connection  = connection;
            command.CommandText = "usp_getMessages";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@lastRecieved", lastRecieved);
            command.Parameters.AddWithValue("@groupID", groupID);
            SqlDataAdapter adapter = new SqlDataAdapter(command);
            DataTable      table   = new DataTable();

            adapter.Fill(table);
            //MessageBox.Show(table.ToString());
            //connection.Close();

            Button clickedButton = sender as Button;

            //connection.Open();
            command             = new SqlCommand();
            command.Connection  = connection;
            command.CommandText = String.Format("SELECT * FROM [chat access]  WHERE  groupID = {0}", clickedButton.Tag);
            command.CommandType = CommandType.Text;
            adapter             = new SqlDataAdapter(command);
            table = new DataTable();
            adapter.Fill(table);

            List <string> peopleInGroup = new List <string>();

            foreach (DataRow row in table.Rows)
            {
                int accountID = Convert.ToInt32(row["accountID"]);
                command             = new SqlCommand();
                command.Connection  = connection;
                command.CommandText = "usp_getUsernameByID";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@accountID", accountID);
                SqlDataAdapter swagAdapter = new SqlDataAdapter(command);
                DataTable      userTable   = new DataTable();
                swagAdapter.Fill(userTable);

                if (userTable.Rows.Count > 0)
                {
                    peopleInGroup.Add(userTable.Rows[0]["username"].ToString());
                }
            }

            SqlCommand commandtwo = new SqlCommand();

            commandtwo.Connection  = connection;
            commandtwo.CommandText = "usp_getChatGroup";
            commandtwo.CommandType = CommandType.StoredProcedure;
            commandtwo.Parameters.AddWithValue("@name", chatname);
            adapter = new SqlDataAdapter(commandtwo);
            DataTable chatgrouptable = new DataTable();

            adapter.Fill(chatgrouptable);
            groupID = (int)clickedButton.Tag;
            connection.Close();

            string message = "DETAILS \n ";

            foreach (string name in peopleInGroup)
            {
                message += String.Format("{0} \n", name);
            }

            errorMessagesBox detailsBox = new errorMessagesBox(message);

            detailsBox.Show();
        }