Пример #1
0
 //--------------------------------------------------------------------
 //	Method:                 searchYear
 //	Description:            Method that searches the list of 
 //                              philosophers for the year of birth
 //                              in the indicated range.
 //	Date Complete:         	11/27/2016
 //	Programmers:		    David Landry
 //	Parameters:             None
 //	Returns:                None
 //	Input:                  txtSearchString.Text
 //	Output:                 A philosopher's name and year of birth 
 //                              added to this form's lstPhilosophers 
 //                              list box.
 //	Calls:                  Philosophers.getName, 
 //                          Philosophers.getYear,
 //                          String.Contains
 //	Called by:              btnSearch_Click
 //	Pre/Post Condition:     The method works properly only if the
 //                              requisite search text box has been
 //                              filled.  After execution, an index
 //                              is added to the foundIndexes list
 //                              and a philosopher's name and 
 //                              year of birth is added to the list 
 //                              box.
 //	Exceptions:             None
 //	Notes:
 //--------------------------------------------------------------------
 private void searchYear()
 {
     Year fromTerm = Year.Parse(txtFrom.Text);
     Year toTerm = Year.Parse(txtTo.Text);
     for (int i = 0; i < searchList.Count; i++)
     {
         Year searchFor = searchList[i].getYear();
         if (searchFor <= toTerm && searchFor >= fromTerm)
         {
             lstPhilosophers.Items.Add(searchList[i].getName() + ", " + searchFor);
             foundIndexes.Add(i);
         }
     }
     if (lstPhilosophers.Items.Count > 0)
         btnSelect.Visible = true;
     else
         btnSelect.Visible = false;
 }
 //--------------------------------------------------------------------
 //	Method:                 btnAdd_Click
 //	Description:            Event handler for a click event on the
 //                              btnAdd button.
 //	Date Complete:          11/24/2016 	
 //	Programmers:		    David Landry
 //	Parameters:             object sender, EventArgs e
 //	Returns:                None
 //	Input:                  Text for each philosopher property.
 //	Output:                 None
 //	Calls:                  Validation.hasNumeral,
 //                          Philosopher.setName,
 //                          Philosopher.setCountry,
 //                          Philosopher.setYear,
 //                          Philosopher.setPhilosophy,
 //                          Philosopher.setWork
 //                          Philosopher.setLink, Year.Parse
 //	Called by:              btnAdd click event         
 //	Pre/Post Condition:     Before execution, all text fields should
 //                              be filled out.  After successful
 //                              execution, a philosopher object
 //                              will take on the properties of the
 //                              text boxes to be fetched by the
 //                              main form.
 //	Exceptions:             None
 //	Notes:                  This method doesn't actually "add" the
 //                              philosopher.  Rather, it puts a
 //                              philosopher together so that the
 //                              main form can fetch it via a call to
 //                              the fetchPhilosopher method.
 //--------------------------------------------------------------------
 private void btnAdd_Click(object sender, EventArgs e)
 {
     // Add a philosopher 
     if (txtName.Text != "" && txtCountry.Text != "" &&
         txtLink.Text != "" && txtPhilosophy.Text != "" &&
         txtWork.Text != "" && txtYear.Text != "")
     {
         if (!Validation.hasNumeral(txtName.Text))
         {
             philosopherToAdd.setName(txtName.Text);
             if (!Validation.hasNumeral(txtCountry.Text))
             {
                 philosopherToAdd.setCountry(txtCountry.Text);
                 philosopherToAdd.setYear(Year.Parse(txtYear.Text));
                 philosopherToAdd.setWork(txtWork.Text);
                 philosopherToAdd.setPhilosophy(txtPhilosophy.Text);
                 philosopherToAdd.setLink(txtLink.Text);
                 pressedAdd = true;
                 Close();
             }
             else
             {
                 MessageBox.Show
                     ("Country should not contain numbers.");
                 txtCountry.Focus();
                 txtCountry.SelectAll();
             }
         }
         else
         {
             MessageBox.Show("Name should not contain numbers.");
             txtName.Focus();
             txtName.SelectAll();
         }
     }
     else
     {
         MessageBox.Show("Please fill in each field.", "Attention!",
             MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }