Beispiel #1
0
        /*done*/ private void friendButton_Click(object sender, EventArgs e)
        {
            yesnoMessageBox messageBox = new yesnoMessageBox("would you like to create a chat with this person?");

            messageBox.ShowDialog();

            if (messageBox.yes == true)
            {
                InputForm newform = new InputForm("what would you like to name this group", "group name", "okay");
                newform.ShowDialog();
                string groupname = newform.SubmittedText;

                InputForm form = new InputForm("what would you like the password to be", "password", "all good");
                form.ShowDialog();
                string password = form.SubmittedText;

                connection.Open();
                SqlCommand command = new SqlCommand();
                command.Connection  = connection;
                command.CommandText = "usp_createChatGroup";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@name", groupname);
                command.Parameters.AddWithValue("@password", password);
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                DataTable      table   = new DataTable();
                adapter.Fill(table);

                int newGroupID = int.Parse(table.Rows[0]["groupID"].ToString());
                command             = new SqlCommand();
                command.Connection  = connection;
                command.CommandText = "usp_addGroupAccess";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@accountID", accountID);
                command.Parameters.AddWithValue("@groupID", newGroupID);
                command.ExecuteNonQuery();

                string username = ((Button)sender).Text;
                command             = new SqlCommand();
                command.Connection  = connection;
                command.CommandText = "usp_getIDbyUsername";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@username", username);
                command.ExecuteNonQuery();

                connection.Close();

                LoadChats();
            }
        }
Beispiel #2
0
        /*done*/ private void deleteFriendButton_Click(object sender, EventArgs e)
        {
            InputForm form = new InputForm("delete friends", "delete friend", "delete");

            form.ShowDialog();
            string friendUsername = form.SubmittedText;

            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)
                {
                    CustomMessageBox error = new CustomMessageBox("there was an error deleting this friend");
                    error.Show();
                }
                LoadFriends();
            }
            else
            {
                CustomMessageBox error = new CustomMessageBox("you are not friends with this user");
                error.Show();
            }
        }