Exemplo n.º 1
0
        facebookUsers[] dbConnectandPopulate()
        {
            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                string       query = "SELECT * FROM isad157_jharrison.facebook_usersn";
                MySqlCommand cmd   = new MySqlCommand(query, connection);
                connection.Open();
                MySqlDataAdapter sqlDA             = new MySqlDataAdapter(cmd);
                DataTable        facebookUserTable = new DataTable();
                sqlDA.Fill(facebookUserTable);

                int endOfRecords = facebookUserTable.Rows.Count; // Get total number of rows

                // Prepare variables for use
                int    fbID = 0000; string fbFirstName = "zeep"; string fbLastName = "zeep"; string fbGender = "zeep";
                string fbHometown = "zeep"; string fbCity = "zeep"; int count = 0;

                foreach (DataRow row in facebookUserTable.Rows)
                {
                    // Get data for each user to populate into its class
                    fbID        = (int)row["userID"];
                    fbFirstName = row["FirstName"].ToString();
                    fbLastName  = row["LastName"].ToString();
                    fbGender    = row["Gender"].ToString();
                    fbHometown  = row["Hometown"].ToString();
                    fbCity      = row["City"].ToString();

                    // Add one more space in the array for a new facebookUsers class
                    Array.Resize(ref fbUsers, fbUsers.Length + 1);

                    // Populate the class and increase the record counter
                    fbUsers[count] = new facebookUsers(fbID, fbFirstName, fbLastName, fbGender, fbHometown, fbCity);
                    count++;
                }

                // Close connection to DB
                connection.Close();
                // Tell the listbox what data it displays and how to display it.
                lstUserList.DataSource    = fbUsers;
                lstUserList.DisplayMember = "displayFormat";
                // Tells the listbox what the unique value (userID) for each item is, so we can get the value when the user clicks a listbox item
                lstUserList.ValueMember = "identifier";
                return(fbUsers);
            }
        }
Exemplo n.º 2
0
        private void getFBUser(string userIDF) // Calling currently selected User ID for reference
        {
            if (userIDF != "Prototype.facebookUsers")
            {
                // Emptying boxes and lists in case any info isn't updated
                lbUserInfoName.Text     = " ";
                lbUserInfoGender.Text   = " ";
                lbUserInfoHometown.Text = " ";
                lbUserInfoCity.Text     = " ";
                lbUserInfoUni.Text      = " ";
                lstUserFriends.Items.Clear();
                lstUserMessages.Items.Clear();

                // User info being called
                facebookUsers selectedfbuser = fbUsers.FirstOrDefault(i => i.identifier == userIDF);
                lbUserInfoName.Text     = selectedfbuser.getFirstName() + " " + selectedfbuser.getLastName();
                lbUserInfoGender.Text   = selectedfbuser.getGender();
                lbUserInfoCity.Text     = selectedfbuser.getCity();
                lbUserInfoHometown.Text = selectedfbuser.getHometown();

                // User uni being called
                universities tempuni = fbUni.FirstOrDefault(u => u.identifier == userIDF.ToString());
                if (tempuni.uniName != " ")
                {
                    lbUserInfoUni.Text = tempuni.uniName;
                }

                // User work place being called
                workplace tempwork = fbWork.FirstOrDefault(w => w.identifier == userIDF.ToString());
                if (tempwork.workName != " ")
                {
                    lbUserInfoWork.Text = tempwork.workName;
                }

                // Message list being called before calling messages
                mList tempList = fbmList.FirstOrDefault(l => l.identifier2 == userIDF.ToString());
                if (tempList.identifier2 == null)
                {
                    lbUserInfoName.Text = "Nope";
                }
                else
                {
                    // Putting each identifier in string
                    string messID = tempList.identifier2;
                    string uID    = tempList.identifier;
                    string combo  = tempList.identifier3;
                    using (MySqlConnection connection = new MySqlConnection(connectionString))
                    {
                        string       query = "SELECT * FROM isad157_jharrison.messagesn WHERE UMessageID =" + messID;
                        MySqlCommand cmd   = new MySqlCommand(query, connection);
                        connection.Open();
                        MySqlDataAdapter sqlDA = new MySqlDataAdapter(cmd);
                        DataTable        facebookUserMessTable = new DataTable();
                        sqlDA.Fill(facebookUserMessTable);
                        int endOfRecord = facebookUserMessTable.Rows.Count;

                        foreach (DataRow row in facebookUserMessTable.Rows)
                        {
                            // User Messages being called
                            messages tempmessages = fbMessages.FirstOrDefault(m => m.identifier == messID.ToString());
                            lstUserMessages.Items.Add(tempmessages.getsetRecipient);
                            lstUserMessages.Items.Add(tempmessages.getsetDateTime);
                            lstUserMessages.Items.Add(tempmessages.getsetMessage);
                        }
                        connection.Close();
                    }
                }

                using (MySqlConnection connection = new MySqlConnection(connectionString))
                {
                    string       query = "SELECT * FROM isad157_jharrison.facebook_friendshipsn WHERE UserID =" + userIDF;
                    MySqlCommand cmd   = new MySqlCommand(query, connection);
                    connection.Open();
                    MySqlDataAdapter sqlDA = new MySqlDataAdapter(cmd);
                    DataTable        facebookFriendsTable = new DataTable();
                    sqlDA.Fill(facebookFriendsTable);
                    int endOfRecord = facebookFriendsTable.Rows.Count;

                    int fbID1 = 0000;
                    int fbID2 = 0000;

                    foreach (DataRow row in facebookFriendsTable.Rows)
                    {
                        fbID1 = (int)row["UserID"];
                        fbID2 = (int)row["UserID_2"];

                        // User Friends being called
                        facebookUsers tempfbuser = fbUsers.FirstOrDefault(i => i.identifier == fbID2.ToString());
                        string        fbfName    = tempfbuser.displayFormat;
                        lstUserFriends.Items.Add(fbfName);
                    }
                    connection.Close();
                }
            }
        }