Beispiel #1
0
        /// <summary>
        /// Put information form person type into personseeking type.
        /// </summary>
        /// <returns> A list of PersonSeeking type. </returns>
        public List <PersonSeeking> GetPersonSeeking2(string name, string query)
        {
            List <object>        translated = new List <object>();
            List <PersonSeeking> personS    = new List <PersonSeeking>();
            List <Person>        person     = new List <Person>();

            person = GetPerson(name, query);

            foreach (Person p in person)
            {
                // Populate the list of the translated information.
                translated = Translator(p);

                // Create a new person and populate it.
                PersonSeeking ps = new PersonSeeking
                {
                    Firstname = p.Firstname,
                    Lastname  = p.Lastname,
                    Mail      = p.Mail,
                    Seeking   = p.Seeking,
                    Picture   = p.Picture,
                    City      = translated[1].ToString()
                };

                // Add the new person to the list.
                personS.Add(ps);
            }

            return(personS);
        }
        /// <summary>
        /// Click handler for Query button.
        /// Has multiple query string into the databse based on the input given.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonQuery_Click(object sender, EventArgs e)
        {
            string box = nameIDBox.Text;

            // Columns - Empty for picture
            string[] columns = { "Name:150", "City:100", "Mail:100", "Seeks:50", ":0" };

            int testInput;

            try
            {
                try
                {
                    testInput = Convert.ToInt32(box);
                }
                catch
                {
                    testInput = -1;
                }

                if (box != "" && box != null)
                {
                    // If contain "-" then birthday is provided.
                    if (box.Contains("-"))
                    {
                        // Query by birthday
                        peopleSeeking = db.GetPersonSeeking2("DateApp", $"SELECT * FROM person WHERE birthday like '{box}%'");
                    }
                    // If the test int is higher then -1 (correct id) then an id is provided.
                    else if (testInput >= 0)
                    {
                        // Query ID - And call display image.
                        peopleSeeking = db.GetPersonSeeking("DateApp", "ID", box);

                        // Instaziate a new person to extract profile picture.
                        PersonSeeking person = peopleSeeking[0];

                        // Only call show picture code if there is an image.
                        if (person.Picture != null)
                        {
                            // Call the function to show the profile picture.
                            showProfilePicture(person.Picture);
                        }
                    }
                    // Name most be provided.
                    else
                    {
                        box           = box.Trim();
                        peopleSeeking = db.GetPersonSeeking("DateApp", "Name", $"'{box}%'");
                    }

                    gh.ListPeopleView(listViewPerson, peopleSeeking, columns);
                }
                else
                {
                    // Show message
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }