void CreateConversartion() { //Opens dialog form window TextInputDialog dialog = new TextInputDialog(); dialog.SetDialogSettings("CONVERSATION NAME:", "Add Conversation"); dialog.ShowDialog(); //Checks if clicked OK if (dialog.DialogResult == DialogResult.OK) { if (dialog.input == "") { //The user didn't write anything as an input MessageBox.Show( "You have to name the conversation soemthing", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning ); return; } //Creates a conversation in the database string sql = @"INSERT INTO conversations(name, userIDsString) VALUES ('" + dialog.input + "'," + Connection.loggedInUserID + ")"; Connection.command = new MySqlCommand(sql, Connection.connection); Connection.reader = Connection.command.ExecuteReader(); //Execute query Connection.reader.Close(); //Updates the conversation list UpdateConversations(); } }
private void friendToolStripMenuItem_Click(object sender, EventArgs e) { //Opens the dialog window TextInputDialog aff = new TextInputDialog(); aff.SetDialogSettings("USERNAME:"******"Add Friend"); aff.ShowDialog(); //Checks if the user clicked OK if (aff.DialogResult == DialogResult.OK) { //Gets all data from the user with the specific ID String sql = @"SELECT * FROM `users` WHERE `ID`='" + Connection.loggedInUserID + @"';"; Connection.command = new MySqlCommand(sql, Connection.connection); Connection.reader = Connection.command.ExecuteReader(); //Executes the query Connection.reader.Read(); string frienduserIDsString = ""; //Stop if user can't be found if (!Connection.reader.HasRows) { MessageBox.Show("Can't find logged in user"); Connection.reader.Close(); return; } else { //Gets the user's current friends frienduserIDsString = Connection.reader[6].ToString(); } Connection.reader.Close(); //Selects the user that has the same username as the input sql = @"SELECT * FROM `users` WHERE `username`='" + aff.input + @"'"; Connection.command = new MySqlCommand(sql, Connection.connection); Connection.reader = Connection.command.ExecuteReader(); //Executes the query Connection.reader.Read(); if (Connection.reader.HasRows) //Checks if the table has any rows (if there are any users with that username) { //Updates the friend list String updateFriendSql = @"UPDATE `users` SET `frienduserIDsString`='" + frienduserIDsString + " " + Connection.reader[0] + "' WHERE `ID`='" + Connection.loggedInUserID + "';"; Connection.reader.Close(); Connection.command = new MySqlCommand(updateFriendSql, Connection.connection); Connection.reader = Connection.command.ExecuteReader(); //Executes the query } else { //There's no user with the same username as the input MessageBox.Show( "Can't find the user " + aff.input, "Something went wrong", MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); } Connection.reader.Close(); } }