Ejemplo n.º 1
0
        private void btFilterPattern_Click(object sender, EventArgs e)
        {
            string        str     = "";
            List <Person> persons = new List <Person>();

            persons.Add(new Person("Robert", "Male", "Single"));
            persons.Add(new Person("John", "Male", "Married"));
            persons.Add(new Person("Laura", "Female", "Married"));
            persons.Add(new Person("Diana", "Female", "Single"));
            persons.Add(new Person("Mike", "Male", "Single"));
            persons.Add(new Person("Bobby", "Male", "Single"));

            ICriteria male           = new CriteriaMale();
            ICriteria female         = new CriteriaFemale();
            ICriteria single         = new CriteriaSingle();
            ICriteria singleMale     = new AndCriteria(single, male);
            ICriteria singleOrFemale = new OrCriteria(single, female);

            str += "Males:\r\n ";
            str += printPersons(male.meetCriteria(persons)) + "\r\n";

            str += "Females:\r\n ";
            str += printPersons(female.meetCriteria(persons)) + "\r\n";

            str += "Single Males:\r\n ";
            str += printPersons(singleMale.meetCriteria(persons)) + "\r\n";

            str += "Single Or Females:\r\n ";
            str += printPersons(singleOrFemale.meetCriteria(persons)) + "\r\n";
            tbOutWindow.Text = str;
        }