/// <summary> /// This method is called when the Add lender button is pressed. A new /// object of the BookLenderForm is created, and a new form is opened. /// If input is valid, the book lender is added to the book lender list and /// the GUI is updated. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_AddLender_Click(object sender, EventArgs e) { // A new book lender form is created with a title as parameter BookLenderForm formLender = new BookLenderForm("Add Book Lender"); // Is the Ok button pressed in the book lender form and is the input valid ? if ((formLender.ShowDialog() == DialogResult.OK) && formLender.ValidateInput()) { // The book lender is added to the book lender list bookLenderManager.AddBookLender(formLender.MyBookLender); // The book lender list is sorted by book lender ID bookLenderManager.SortListByID(); // Updates the GUI UpdateGUI(); } }
/// <summary> /// The method is called when the View and edit button is pressed in the GUI. /// It gives the possiblity to edit the book lender information. /// A book lender in the list have to be selected. The GUI of the server class /// is opened and possible changes read. If the input data is valid, the possible /// changed lender data is saved at the same index in the book lender list. And the /// list is updated in the GUI. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_ViewAndEdit_Click(object sender, EventArgs e) { // Index of the selected book lender in the list in the GUI int selectedIndex = lbx_LenderDetails.SelectedIndex; // Is a book lender selected in the listbox ? if (selectedIndex >= 0) { // A new object of the BookLenderForm class is created with a title and saved book lender at selected index as parameters BookLenderForm savedFormLender = new BookLenderForm("View And Edit", bookLenderManager.GetBookLenderAtIndex(selectedIndex)); // Is the OK button pressed and valid book lender input from the server class form ? if ((savedFormLender.ShowDialog() == DialogResult.OK) && savedFormLender.ValidateInput()) { // Changed book lender data is saved in book lender list at selected index bookLenderManager.ChangeBookLender(selectedIndex, savedFormLender.MyBookLender); // The book lender list is sorted by book lender ID bookLenderManager.SortListByID(); // The GUI is updated UpdateGUI(); } } }