Esempio n. 1
0
        }                                            //The Result of the dialog window

        /// <summary>
        /// Constructor for EditAuthorDialog
        /// Initializes the fields and Properties and preps the window for user interaction
        /// </summary>
        /// <param name="bookDetails"></param>
        /// <param name="controller"></param>
        public EditAuthorDialog(BookDetails bookDetails, LibraryClientController controller)
        {
            InitializeComponent();

            //Initialize fields and properties
            Owner           = bookDetails;
            this.controller = controller;

            LoadAuthors();
            DataContext = authorList;  //sets the DataContext to all available authors (shows all authors)

            //subscribe to OnDatabaseError event
            this.controller.OnDatabaseError += OnDatabaseErrorHandler;

            //prep controls for user interaction
            ResetSearchBar();
            SelectButton.IsEnabled = false;
        }
        /// <summary>
        /// Sets the CopiesResult Property to copies value passed in argument and closes the window if copies is a valid amount.
        /// If copies exceeds the amount of copis available for checkout, then displays an error and focuses back on NumberTextBox
        /// </summary>
        /// <param name="copies">number of copies to remove</param>
        private void RemoveCopy(int copies)
        {
            //Check if can remove that amount of copies
            BookDetails bd = Owner as BookDetails;

            if (bd != null)
            {
                if (copies <= bd.Book.CopiesAvailable)  //if copies is a valid number
                {
                    CopiesResult = copies;
                    DialogResult = true;
                    this.Close();
                }
                else  //if copies is not a valid number
                {
                    ErrorLabel.Content = String.Format("Only {0} copies are available to remove", bd.Book.CopiesAvailable);
                    NumberTextBox.Focus();
                    return;
                }
            }
        }
        }                                              //Copies of books inputted by the user

        //Constructor
        //Uses a BookDetails window as a parameter and AddOrRemove enum
        /// <summary>
        /// Constructor for BookCopiesDialog
        /// Initializes fields and preps the Window for user interaction
        /// </summary>
        /// <param name="bookDetails">BookDetails window that opened this window</param>
        /// <param name="addOrRemove">AddorRemove enum that preps the interaction for adding or removing Book copies</param>
        public BookCopiesDialog(BookDetails bookDetails, AddOrRemove addOrRemove)
        {
            InitializeComponent();

            //Initialize properties and fields
            Owner            = bookDetails;
            this.addOrRemove = addOrRemove;

            //Set the QuestionTextBlock content
            if (addOrRemove == AddOrRemove.Add)  //if user wants to add copies
            {
                QuestionTextBlock.Text = "How many copies would you like to add?";
            }
            else if (addOrRemove == AddOrRemove.Remove)  //if user wants to deletec copies
            {
                string question = string.Format("How many copies would you like to remove?\n\n({0} copies are available for removal)",
                                                (Owner as BookDetails).Book.CopiesAvailable);
                QuestionTextBlock.Text = question;
            }

            NumberTextBox.Text = "0";
            ErrorLabel.Content = string.Empty;
        }
        /// <summary>
        /// Opens a BookDetais window with the selectedBook as the Book to be displayed.
        /// </summary>
        private void ViewDetails()
        {
            BookDetails bookDetailsWindow = new BookDetails(selectedBook, controller, this);

            bookDetailsWindow.ShowDialog();
        }