public void retrieveSchools(int inUserID) { Array.Resize(ref lstCurSchools, 0); //replace 1 with the variable for the currently selected user SQL_Connection_Functions.retrieveSchools(inUserID); DataTable dt = new DataTable(); SQL_Connection_Functions.sqlDA.Fill(dt); int curSchool = 0; foreach (DataRow row in dt.Rows) { Array.Resize(ref lstCurSchools, lstCurSchools.Length + 1); int userID = row.Field <int>(0); string placename = row.Field <string>(1); string startTime = row.Field <string>(2); string endTime = row.Field <string>(3); lstCurSchools[curSchool] = new School(userID, placename, startTime, endTime); curSchool++; } for (int i = 0; i < lstCurSchools.Length; i++) { lstBoxSchools.Items.Add(lstCurSchools[i].getName()); } }
public void searchUser(string inSearch) { selectedUser = -1; lstBoxUsers.Items.Clear(); try { int userID = Convert.ToInt32(inSearch); Array.Resize(ref lstUsers, 0); SQL_Connection_Functions.searchUsers(userID); DataTable dt = new DataTable(); SQL_Connection_Functions.sqlDA.Fill(dt); createUsers(dt); } catch { Array.Resize(ref lstUsers, 0); SQL_Connection_Functions.searchUserFName(inSearch); DataTable dt = new DataTable(); SQL_Connection_Functions.sqlDA.Fill(dt); createUsers(dt); } finally { if (inSearch == "") { Array.Resize(ref lstUsers, 0); SQL_Connection_Functions.retrieveUsers(); DataTable dt = new DataTable(); SQL_Connection_Functions.sqlDA.Fill(dt); createUsers(dt); } } }
public void retrieveRecMessages(int inUserID) { if (lstUsers[inUserID - 1].getRecMessages() == null) { Array.Resize(ref lstCurRecMsgs, 0); //replace 1 with the variable for the currently selected user SQL_Connection_Functions.retrieveRecMsgs(inUserID); DataTable dt = new DataTable(); SQL_Connection_Functions.sqlDA.Fill(dt); int curRecMsg = 0; foreach (DataRow row in dt.Rows) { Array.Resize(ref lstCurRecMsgs, lstCurRecMsgs.Length + 1); int senderID = row.Field <int>(0); int recID = row.Field <int>(1); string dateTime = row.Field <string>(2);; string msg = row.Field <string>(3);; lstCurRecMsgs[curRecMsg] = new Backend.Message(senderID, recID, dateTime, msg); curRecMsg++; } lstUsers[inUserID - 1].setRecMessages(lstCurRecMsgs); } else { lstCurRecMsgs = lstUsers[inUserID - 1].getRecMessages(); } for (int i = 0; i < lstCurRecMsgs.Length; i++) { int senderID = lstCurRecMsgs[i].getSenderID(); string recFName = SQL_Connection_Functions.returnFName(senderID); string recLName = SQL_Connection_Functions.returnLName(senderID); lstBoxFrom.Items.Add(recFName + " " + recLName); } }
public void retrieveFriends(int inUserID) { //If users friends not added create the list if (lstUsers[inUserID - 1].getFriends() == null) { Array.Resize(ref lstCurFriends, 0); //replace 1 with the variable for the currently selected user SQL_Connection_Functions.retrieveFriends(inUserID); DataTable dt = new DataTable(); SQL_Connection_Functions.sqlDA.Fill(dt); int curFriend = 0; foreach (DataRow row in dt.Rows) { Array.Resize(ref lstCurFriends, lstCurFriends.Length + 1); int friendID = row.Field <int>(1); lstCurFriends[curFriend] = new Friend(friendID); curFriend++; } lstUsers[inUserID - 1].setFriends(lstCurFriends); } //Otherwise retrieve the list else { lstCurFriends = lstUsers[inUserID - 1].getFriends(); } //Show the list for (int i = 0; i < lstCurFriends.Length; i++) { string friendsName = lstCurFriends[i].getFName() + " " + lstCurFriends[i].getLName(); Console.WriteLine(friendsName); lstBoxFriends.Items.Add(friendsName); } }
public Form1() { InitializeComponent(); try { Array.Resize(ref lstUsers, 0); SQL_Connection_Functions.retrieveUsers(); DataTable dt = new DataTable(); SQL_Connection_Functions.sqlDA.Fill(dt); createUsers(dt); } catch (Exception err) { MessageBox.Show("Could not connect due to the following error. " + err.Message); } }