Exemplo n.º 1
0
        /// <summary>
        /// This method is called when the Change button is pressed in the GUI.
        /// A new book object is saved with the changed book data at the same index
        /// in the bookList. This is only done if input is validated and if index
        /// is in the range of the bookList. If so, the GUI is updated.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Change_Click(object sender, EventArgs e)
        {
            // Read book data returns an assigned book object
            Book book = ReadData();
            // The selected index i the listbox
            int selectedIndex = lbx_BookList.SelectedIndex;

            // Is input validated and an index selected in the listbox?
            if (ValidateInput(book) && selectedIndex >= 0)
            {
                // The book data is changed at index in book list
                myBookManager.ChangeBook(selectedIndex, book);
                // The GUI is updated
                UpdateGUI();
                // The listbox is unselcted
                lbx_BookList.ClearSelected();
                // Add button is enabled
                btn_AddBook.Enabled = true;
            }
        }