private bool DuplicateFriends(string userID, object sender) { var btn = (Button)sender; string friendID = btn.Name; var test = new List <string>(); MySQLFunctions.getInfo($"SELECT * FROM friendtable WHERE userID = {userID} AND friendID = {friendID}", ref test); if (friendID == userID) { MessageBox.Show("You cannot be friends with yourself"); return(false); } if (test.Count == 0) { return(true); } DialogResult dialogResult = MessageBox.Show("Would you like to remove them?", "You are currently friends,", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { MySQLFunctions.SQLCommand($"DELETE FROM friendtable WHERE userID = {userInfo.getCurrentUser()} AND friendID = {friendID}"); btn.BackColor = areNOTFriendsColor; btn.ForeColor = areNOTFriendsColor; } return(false); }
public ComparisonPage() { InitializeComponent(); var friendList = new List <Student>(); //List of all the users friends var timeBlocks = new List <timeBlock>(); //List of all friends available times var selectedFriendList = new List <string>(); // List of all friends you have selected to comapare var friendIDs = new List <string>(); //List of IDs of all friends of current user selectedFriendList.Add(userInfo.getCurrentUser().ToString()); MySQLFunctions.getInfo($"SELECT friendID FROM friendtable WHERE userID = {userInfo.getCurrentUser()};", ref friendIDs); foreach (var p in friendIDs) { MySQLFunctions.getFriendInfo($"SELECT userID, firstname, lastname, email FROM usertable WHERE userID = {p};", ref friendList); } showOverlap(ref timeBlocks, ref selectedFriendList); foreach (var t in friendList) { Button button = new Button(); button.Name = t.StudentID; button.Text = t.firstName + " " + t.lastName; button.Location = new Point(10, friendPanel.Controls.Count * 25); button.Size = new Size(120, 25); button.Font = new Font(button.Font.FontFamily, 12); button.BackColor = friendNOTSelected; button.ForeColor = Color.Black; button.Click += (s, e) => { //Changes color of buttons to show election if (button.BackColor == friendNOTSelected) { selectedFriendList.Add(t.StudentID.ToString()); button.BackColor = friendSelected; } else { selectedFriendList.Remove(t.StudentID.ToString()); button.BackColor = friendNOTSelected; } showOverlap(ref timeBlocks, ref selectedFriendList); }; friendPanel.Controls.Add(button); } }
private void searchButton_Click(object sender, EventArgs e) { resultsPanel.Controls.Clear(); var studentList = new List <Student>(); var studentIDs = new List <string>(); studentList.Clear(); MySQLFunctions.getInfo($"SELECT userID FROM usertable WHERE userID NOT LIKE '{userInfo.getCurrentUser()}';", ref studentIDs); foreach (var p in studentIDs) { string connectionString = null; MySqlConnection cnn; connectionString = $"server=localhost;database=jacobdb;uid=root;pwd={MySQLFunctions.MYSQLPassword};"; cnn = new MySqlConnection(connectionString); string query = $"SELECT userID, firstname, lastname, email FROM usertable WHERE userID = {p};"; MySqlCommand cmd = new MySqlCommand(query, cnn); MySqlDataReader dr; cnn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { var userID = dr["userID"]; var firstname = dr["firstname"]; var lastname = dr["lastname"]; var email = dr["email"]; studentList.Add(new Student() { StudentID = userID.ToString(), firstName = firstname.ToString(), lastName = lastname.ToString(), email = email.ToString() }); } dr.Close(); cnn.Close(); } //Filter the list if (firstnameSearch.Text != "") { studentList = studentList.FindAll(s => s.firstName.Equals(firstnameSearch.Text)); } if (lastnameSearch.Text != "") { studentList = studentList.FindAll(s => s.lastName.Equals(lastnameSearch.Text)); } if (emailSearch.Text != "") { studentList = studentList.FindAll(s => s.email.Equals(emailSearch.Text)); } int j = 0; foreach (var p in studentList) { var color = areNOTFriendsColor; var alreadyFriend = new List <String>(); //determin button color MySQLFunctions.getInfo($"SELECT * FROM friendtable WHERE userID = {userInfo.getCurrentUser()} AND friendID = {p.StudentID}", ref alreadyFriend); if (alreadyFriend.Count != 0) { color = areFriendsColor; } else { color = areNOTFriendsColor; } Button btn = new Button(); btn.Name = p.StudentID; btn.Text = ""; btn.Size = new Size(20, 20); btn.Location = new Point(10, j * 25 + 5); btn.BackColor = color; btn.ForeColor = color; btn.FlatStyle = FlatStyle.Flat; btn.Click += new EventHandler(this.MyButtonHandler); resultsPanel.Controls.Add(btn); counter++; //Show names Label lbl = new Label(); lbl.Text = p.firstName + " " + p.lastName; lbl.Location = new Point(400, j * 25); //here is the location of the box lbl.Size = new Size(400, 30); //here is the size of the box lbl.TextAlign = ContentAlignment.MiddleCenter; resultsPanel.Controls.Add(lbl); //Show emails Label lbl2 = new Label(); lbl2.Text = p.email; lbl2.Location = new Point(50, j * 25); //here is the location of the box lbl2.Size = new Size(400, 30); //here is the size of the box lbl2.TextAlign = ContentAlignment.MiddleCenter; resultsPanel.Controls.Add(lbl2); j++; } }