// Precondition: User clicks on the edit patron control // Postcondition: Edited patron is saved to the library. private void patronToolStripMenuItem1_Click(object sender, EventArgs e) { // new edit patron form EditPatronForm newEditPatForm = new EditPatronForm(_lib.GetPatronsList()); DialogResult result = newEditPatForm.ShowDialog(); // Show form as dialog and store result if (result == DialogResult.OK) // Only add if OK { // The patron object to be edited LibraryPatron selectedPatron = _lib.GetPatronsList().ElementAt(newEditPatForm.PatronIndex); // Walk thru array in search of patron foreach (LibraryPatron i in _lib.GetPatronsList()) { // Condition that patron is found if (selectedPatron == i) { i.PatronID = newEditPatForm.PatronID; // Set new ID i.PatronName = newEditPatForm.PatronName; // Set new Name } } } newEditPatForm.Dispose(); // Good .NET practice - will get garbage collected anyway }
private void PatronToolStripMenuItem1_Click(object sender, EventArgs e) { List <LibraryPatron> patrons; // List of patrons patrons = _lib.GetPatronsList(); if ((patrons.Count() == 0)) { MessageBox.Show("Must have a patron to edit!"); } else { PatronSelectionForm patronSelectionForm = new PatronSelectionForm(patrons); DialogResult result = patronSelectionForm.ShowDialog(); // Show form as dialog and store result if (result == DialogResult.OK) { LibraryPatron p = _lib._patrons[patronSelectionForm.PatronIndex]; PatronForm pf = new PatronForm(); pf.PatronName = p.PatronName; pf.PatronID = p.PatronID; DialogResult result1 = pf.ShowDialog(); if (result1 == DialogResult.OK) { p.PatronName = pf.PatronName; p.PatronID = pf.PatronID; } } patronSelectionForm.Dispose(); } }
// Precondition: PatronEdit, Edit menu item activated // Postcondition: The PatronEdit dialog box is displayed. If data entered // are OK, file is opened private void patronToolStripMenuItem1_Click(object sender, EventArgs e) { List <LibraryPatron> patrons; //list of patrons patrons = _lib.GetPatronsList(); if (patrons.Count == 0) { MessageBox.Show("Must select a patron!"); } else { PatronEdit pEdit = new PatronEdit(patrons); DialogResult result = pEdit.ShowDialog(); // Displays form as dialogbox if (result == DialogResult.OK) //Only allows selection if ok { LibraryPatron libraryPatron = patrons[pEdit.PatronIndex]; PatronForm patronEditor = new PatronForm(); //seperate form but same format from patron form DialogResult edited = patronEditor.ShowDialog(); //Opens the patron form to edit if (edited == DialogResult.OK) //If Ok only { libraryPatron.PatronName = patronEditor.PatronName; libraryPatron.PatronID = patronEditor.PatronID; } patronEditor.Dispose(); } } }
// Precondition: clicked on edit patron on menu // Postcondition: dialog box will appear to choose patron that is going to be edited // user will make selection, then patron form will appear that is populated // with patron data that is to be edited private void patronToolStripMenuItem1_Click(object sender, EventArgs e) { PatronSelectionForm editPatronForm = new PatronSelectionForm(_lib.GetPatronsList()); // form to choose patron DialogResult result = editPatronForm.ShowDialog(); // result from patron selection form int patronIndex; // selected patron index if (result == DialogResult.OK) // did they click ok? { patronIndex = editPatronForm.SelectedPatronIndex; LibraryPatron patron = _lib._patrons[patronIndex]; // selected library patron PatronForm patronForm = new PatronForm(); // patron form to edit data with // passing object data to form patronForm.PatronID = patron.PatronID; patronForm.PatronName = patron.PatronName; DialogResult result2 = patronForm.ShowDialog(); // patron form with data loaded into it if (result2 == DialogResult.OK) // did they click ok? { // get edited data from form and update object data patron.PatronID = patronForm.PatronID; patron.PatronName = patronForm.PatronName; } } }
//Pre Condition: invoked when Patron, Edit menu is activated // Post Condition: The file is opened private void patronToolStripMenuItem1_Click(object sender, EventArgs e) { List <LibraryPatron> patrons; // List of patrons patrons = _lib.GetPatronsList(); if ((patrons.Count() == 0)) // Must have patrons { MessageBox.Show("Must have patrons to edit!", "Edit Patron Error"); } else { SelectPatronForm selectPatronForm = new SelectPatronForm(patrons); // The Select Patron dialog box form DialogResult result = selectPatronForm.ShowDialog(); // Show form as dialog and store result if (result == DialogResult.OK) // Only add if OK { try { PatronForm patronForm = new PatronForm(); // The patron dialog box form LibraryPatron selected = patrons[selectPatronForm.PatronIndex]; //carry over the selection into the form patronForm.PatronName = selected.PatronName; // sets Forms Patron Name property to one the user selects patronForm.PatronID = selected.PatronID; // sets Form's Patron Id property to one the user selects patronForm.ShowDialog(); // Show form as dialog and store result if (result == DialogResult.OK) // Only add if OK { // Uses the forms properties to edit patron selected.PatronName = patronForm.PatronName; // set patron's name to user's input selected.PatronID = patronForm.PatronID; // set patron's id to user's input } patronForm.Dispose(); // Good .NET practice - will get garbage collected anyway } catch (ArgumentOutOfRangeException) { MessageBox.Show("Enter Input into the Proper Field", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (InvalidOperationException) { MessageBox.Show("Invalid Operation", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (FormatException) { MessageBox.Show("Please Enter Correct Format", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } selectPatronForm.Dispose(); // Good .NET practice - will get garbage collected anyway } }
// Precondition: thePatron != null // Postcondition: The book is checked out public void CheckOut(LibraryPatron thePatron) { _checkedOut = true; if (thePatron != null) Patron = thePatron; else throw new ArgumentNullException($"{nameof(thePatron)}", $"{nameof(thePatron)} must not be null"); }
// Precondition: thePatron != null // Postcondition: The book is checked out by the specified patron public void CheckOut(LibraryPatron thePatron) { if (thePatron != null) { Patron = thePatron; } else { throw new ArgumentNullException($"{nameof(thePatron)}", $"{nameof(thePatron)} must not be null"); } }
// Precondition: Edit, Patron menu item activated // Postcondition: The patron selected from the library has been edited // with the new information replacing the existing object's // properties private void patronToolStripMenuItem1_Click(object sender, EventArgs e) { List <LibraryPatron> patrons; // List of patrons patrons = _lib.GetPatronsList(); if ((patrons.Count() == 0)) // Must have checked out items { MessageBox.Show("Must have patrons to edit!", "Edit Error"); } else { SelectPatronForm spForm = new SelectPatronForm(patrons); // The select patron dialog box form DialogResult result = spForm.ShowDialog(); // Show form as dialog and store result if (result == DialogResult.OK) // Only edit if OK { int editIndex; // Index of patron to edit editIndex = spForm.PatronIndex; if (editIndex >= 0) // -1 if didn't select item from combo box (should never happen!) { LibraryPatron editPatron = patrons[editIndex]; // The patron being edited PatronForm patronForm = new PatronForm(); // The patron dialog box form // Populate form fields from selected patron patronForm.PatronName = editPatron.PatronName; patronForm.PatronID = editPatron.PatronID; DialogResult editResult = patronForm.ShowDialog(); // Show form as dialog and store result if (editResult == DialogResult.OK) // Only update patron if OK { //Edits the dictionary so that it isn't corrupted due to the keys changing //_lib.ChangePatronKey(patrons[editIndex].PatronID, editPatron.PatronID, editPatron); // Edit patron properties using form fields editPatron.PatronName = patronForm.PatronName; //editPatron.PatronID = patronForm.PatronID; //(Edited out to prevent corruption of dictionary) } patronForm.Dispose(); // Good .NET practice - will get garbage collected anyway } } spForm.Dispose(); // Good .NET practice - will get garbage collected anyway } }
// Precondition: None // Postcondition: A patron has been created with the specified values for name and ID. // The patron has been added to the Library. public bool AddPatron(String patronId, String name) { LibraryPatron newPatron = new LibraryPatron(name, patronId); if (libraryPatrons.ContainsKey(patronId)) { Console.WriteLine("didn't work"); return(FAILED_ADD); } else { libraryPatrons.Add(patronId, newPatron); Console.WriteLine("it did work"); return(SUCCESSFUL_ADD); } }
// Precondition: 0 <= itemIndex < GetItemCount() // 0 <= patronIndex < GetPatronCount() // Postcondition: The specified item will be checked out by // the specifed patron public bool CheckOut(string callNum, string patId) { LibraryItem BookToCheckOut = null; // holder for book LibraryPatron PatronToCheckOut = null; // holder for patron // Are they valid paramenters if (libraryItems.ContainsKey(callNum) && libraryPatrons.ContainsKey(patId)) { // Walk thru get the patron for (int i = 0; i < libraryPatrons.Count; i++) { if (libraryPatrons.ElementAt(i).Key == patId) { PatronToCheckOut = libraryPatrons.ElementAt(i).Value; break; } } // walk thru get the item for (int i = 0; i < libraryItems.Count; i++) { if (libraryItems.ElementAt(i).Key == callNum) { BookToCheckOut = libraryItems.ElementAt(i).Value; // set book to object break; } } // Is the book not checked out if (!BookToCheckOut.IsCheckedOut()) { BookToCheckOut.CheckOut(PatronToCheckOut); transactions.Add(BookToCheckOut.CallNumber, DateTime.Now.AddDays(-21)); return(SUCCESSFUL_ADD); } // the book is already checked out else { return(FAILED_ADD); } } // They're not valid Parameters else { return(FAILED_ADD); } }
//Precondition: none //Postcondition: Outputs the values of the selected patron into the edit book form private void editButton_Click(object sender, EventArgs e) { LibraryPatron b = _lib._patrons[PatronIndex]; PatronForm pf = new PatronForm(); pf.PatronID = b.PatronID; pf.PatronName = b.PatronName; DialogResult result = pf.ShowDialog(); if (result == DialogResult.OK) { b.PatronID = pf.PatronID; b.PatronName = pf.PatronName; } }
// Precondition: Edit, Patron menu item activated // Postcondition: The edit patron dialog box is displayed. // and a patron can be selected from the combobox private void patronToolStripMenuItem1_Click(object sender, EventArgs e) { List <LibraryPatron> patrons;//List of Patrons patrons = lib.GetPatronsList(); //Opens editPatron dialog box EditPatron editPatron = new EditPatron(patrons); DialogResult result = editPatron.ShowDialog(); int PatronIndex; PatronIndex = editPatron.PatronIndex;//Get the index of the editpatron combobox //Precondition:User selects a patron //Postcondition: Patron infomration is set to patron form textboxes if (result == DialogResult.OK) { LibraryPatron patron = lib._patrons[PatronIndex]; //sets patron to patron index PatronForm patronForm = new PatronForm(); // Opens the patron dialog box form patronForm.PatronName = patron.PatronName; //Sets textboxs to have information from selected patron patronForm.PatronID = patron.PatronID; DialogResult result2 = patronForm.ShowDialog(); //Precondition:User clicks ok on patron form //Postcondition:Populates list with new patron information if (result2 == DialogResult.OK) { patron.PatronName = patronForm.PatronName;//Sets list to equal new edited patron patron.PatronID = patronForm.PatronID; } } }
private void patronToolStripMenuItem1_Click(object sender, EventArgs e) { List <LibraryPatron> patrons; // List of patrons patrons = _lib.GetPatronsList(); // gets list of patrons from library EditPatronForm editPatronForm = new EditPatronForm(patrons); // pass patrons to the form PatronForm editSelectedPatron = new PatronForm(); // create a new patron form DialogResult result = editPatronForm.ShowDialog(); // Show form as dialog and store result // ensure that user clicked Ok if (result == DialogResult.OK) { try { LibraryPatron selectedPatron = patrons[editPatronForm.PatronIndex]; // stores selected patron editSelectedPatron.PatronName = selectedPatron.PatronName; // name of the selected patron editSelectedPatron.PatronID = selectedPatron.PatronID; // ID of the selected patron result = editSelectedPatron.ShowDialog(); // show form as dialog for selected patron _lib._patrons.RemoveAt(editPatronForm.PatronIndex); // the patron being edited is removed LibraryPatron editedPatron = new LibraryPatron(editSelectedPatron.PatronName, editSelectedPatron.PatronID); _lib._patrons.Insert(editPatronForm.PatronIndex, editedPatron); // patron with edited information is added } catch (ArgumentOutOfRangeException) { MessageBox.Show("Select Patron!"); // error is no patron is selected } } editPatronForm.Dispose(); // Good .NET practice - will get garbage collected anyway }
// Precondition: None // Postcondition: The book is not checked out public void ReturnToShelf() { Patron = null; // Remove previously stored reference to patron }
// Precondition: None // Postcondition: The book is not checked out public void ReturnToShelf() { _checkedOut = false; Patron = null; // Remove previously stored reference to patron }
// Precondition: None // Postcondition: The item is checked out by thePatron public void CheckOut(LibraryPatron thePatron) { _checkedOut = true; Patron = thePatron; }
//Precondition: The PatronForm has returned OK //Postcondition: The old patron reference is removed from the dictionary and one with the new information is added public void ChangePatronKey(string oldKey, string newKey, LibraryPatron patron) { _patronDict.Remove(oldKey); _patronDict.Add(newKey, patron); }
// Precondition: None // Postcondition: The item is not checked out (by any patron) public void ReturnToShelf() { itemCheckedOut = false; patron = null; // No longer associated with anyone }
// Precondition: None // Postcondition: The item is checked out by thePatron public void CheckOut(LibraryPatron thePatron) { itemCheckedOut = true; patron = thePatron; }