Exemplo n.º 1
0
        public void removeClick(object sender, EventArgs e)
        {
            int           row         = favoriteTableLayoutPanel.GetRow(((Label)sender));
            Label         titleLabel  = (Label)favoriteTableLayoutPanel.GetControlFromPosition(0, row);
            FavoriteLemma toBeRemoved = null;

            foreach (FavoriteLemma f in FavoriteLemmas)
            {
                if (f.Title == titleLabel.Text)
                {
                    toBeRemoved = f;
                    break;
                }
            }
            int result = DBConnect.Delete(toBeRemoved, StartPage.account.User);

            if (result != 1)
            {
                MessageBox.Show("  Something went wrong trying to remove that Lemma.");
            }
            else
            {
                //now remove and update
                FavoriteLemmas.Remove(toBeRemoved);
                StartPage.favoriteLemmaList = FavoriteLemmas;
                SetLemmas();
            }
        }
Exemplo n.º 2
0
        public static void addToFavorites(int userID, string lemmaTitle)
        {
            // Get the properties needed for the creation of Lemma object
            byte[] lemmaBody     = DBConnect.GetLemmaBodyByTitle(lemmaTitle);
            int    lemmaCategory = DBConnect.GetLemmaCategoryByTitle(lemmaTitle);
            Lemma  lemma         = new Lemma(lemmaTitle, lemmaBody, lemmaCategory);

            // Get the properties needed for the creation of User object.
            string   userName    = DBConnect.GetUserNameByID(userID);
            string   userSurname = DBConnect.GetUserSurnameByID(userID);
            DateTime dateOfBirth = DBConnect.GetUserDateOfBirthByID(userID);
            User     user        = new User(userID, userName, userSurname, dateOfBirth);

            DateTime createdAt = DateTime.Now;

            // Create a FavoriteLemma object with the above properties.
            FavoriteLemma fLemma = new FavoriteLemma(lemma.Title, user, createdAt);

            // Insert the favorite lemma to DB.
            int result = DBConnect.Insert(fLemma);

            if (result == 1) // If result=1 then everything is OK.
            {
                FavouriteLemmataUserControl.Instance.FavoriteLemmas.Add(fLemma);
                FavouriteLemmataUserControl.Instance.SetLemmas();
            }
            else // If result!=1 then something went wrong.
            {
                MessageBox.Show("  The Lemma wasn't added to Favorites. Try again!");
            }
        }