예제 #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Edit friend. </summary>
        ///
        /// <remarks>   , 16/08/2018. </remarks>
        ///
        /// <param name="friends">      The friends. </param>
        /// <param name="friend">       The friend. </param>
        /// <param name="comparison">   The comparison. </param>
        ///
        /// <returns>   A List&lt;Friend&gt; </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static List <Friend> EditFriend(List <Friend> friends, Friend friend, string comparison)
        {
            //first do a date check to see if it is valid
            if (DateCheck(friend.BirthDay, friend.BirthMonth))
            {
                foreach (Friend f in friends)
                {
                    //ToUpper is used so capitalization isn't an issue when comparing
                    if (f.Name.ToUpper() == comparison.ToUpper())
                    {
                        f.Name       = friend.Name;
                        f.Likes      = friend.Likes;
                        f.Dislikes   = friend.Dislikes;
                        f.BirthDay   = friend.BirthDay;
                        f.BirthMonth = friend.BirthMonth;

                        //update the csv file
                        CsvHandler write = new CsvHandler();
                        write.AlterCsv(friends);
                        break;
                    }
                }
            }
            else
            {
                //show a message if the friend try to be edited does not exist
                MessageBox.Show("The Birthday you have entered is invalid, please try again", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            return(friends);
        }
예제 #2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Shows all friends. </summary>
        ///
        /// <remarks>   , 16/08/2018. </remarks>
        ///
        /// <returns>   A List&lt;Friend&gt; </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static List <Friend> ShowAllFriends()
        {
            //create a new csv handler object
            CsvHandler getFriends = new CsvHandler();

            //get all the data from the csv and put it in the friends list
            List <Friend> friends = getFriends.ReadCsv();

            return(friends);
        }
예제 #3
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Adds a new friend. </summary>
        ///
        /// <remarks>   , 16/08/2018. </remarks>
        ///
        /// <param name="friend">   The friend. </param>
        ///
        /// <returns>   A Friend. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static Friend AddNewFriend(Friend friend)
        {
            //first do a date check to see if it is valid
            if (DateCheck(friend.BirthDay, friend.BirthMonth))
            {
                CsvHandler addNewFriend = new CsvHandler();
                addNewFriend.AppendCsv(friend);
                return(friend);
            }
            else
            {
                //show a message if the friend try to be edited does not exist
                MessageBox.Show("The Birthday you have entered is invalid, please try again", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(null);
            }
        }
예제 #4
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Deletes the friend. </summary>
        ///
        /// <remarks>   , 16/08/2018. </remarks>
        ///
        /// <param name="friends">  The friends. </param>
        /// <param name="name">     The name. </param>
        ///
        /// <returns>   A List&lt;Friend&gt; </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static List <Friend> DeleteFriend(List <Friend> friends, string name)
        {
            //Get all the data from the text boxes and update the list
            foreach (Friend f in friends)
            {
                if (f.Name == name)
                {
                    //remove the friend from the list
                    friends.Remove(f);

                    //update the csv file using the updated list
                    CsvHandler write = new CsvHandler();
                    write.AlterCsv(friends);

                    //break out of the for loop because the friend has been deleted
                    break;
                }
            }
            return(friends);
        }
예제 #5
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Friends in month. </summary>
        ///
        /// <remarks>   , 16/08/2018. </remarks>
        ///
        /// <param name="month">    The month. </param>
        ///
        /// <returns>   A List&lt;Friend&gt; </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static List <Friend> FriendsInMonth(int month)
        {
            //read the csv file and put all friends into the list
            CsvHandler    readCsv = new CsvHandler();
            List <Friend> friends = new List <Friend>();

            friends = readCsv.ReadCsv();

            //search through the friends and look at the month of their birthday and return a list
            List <Friend> birthdaysInMonth = new List <Friend>();

            foreach (Friend friend in friends)
            {
                if (friend.BirthMonth == month)
                {
                    birthdaysInMonth.Add(friend);
                }
            }
            return(birthdaysInMonth);
        }
예제 #6
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Searches for the first friend. </summary>
        ///
        /// <remarks>   , 16/08/2018. </remarks>
        ///
        /// <param name="friendName">   Name of the friend. </param>
        ///
        /// <returns>   The found friend. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static List <Friend> FindFriend(string friendName)
        {
            //read the csv file and put all of them into a list
            CsvHandler    readCsv = new CsvHandler();
            List <Friend> friends = new List <Friend>();

            friends = readCsv.ReadCsv();

            //search through list and return another list of friends using the search data
            List <Friend> search = new List <Friend>();

            foreach (Friend friend in friends)
            {
                //ToUpper is used so capitalization isnt an issue when searching
                if (friend.Name.ToUpper().Contains(friendName.ToUpper()))
                {
                    search.Add(friend);
                    Debug.WriteLine(friend.Name);
                }
            }
            //return the list to be displayed
            return(search);
        }