Esempio n. 1
0
        public LibraryForm()
        {
            InitializeComponent();

            // we create only one context in our application, which gets shared among repositories
            LibraryContext context = new LibraryContext();
            // we use a factory object that will create the repositories as they are needed, it also makes
            // sure all the repositories created use the same context.
            RepositoryFactory repFactory = new RepositoryFactory(context);

            this.bookService     = new BookService(repFactory);
            this.bookCopyService = new BookCopyService(repFactory);
            this.authorService   = new AuthorService(repFactory);
            this.memberService   = new MemberService(repFactory);
            this.loanService     = new LoanService(repFactory);

            //Can we do this another way?
            ShowAllBooks(bookService.All());
            AuthorTabShowAllAuthors(authorService.All());
            BookTabShowAllAuthors(authorService.All());
            MemberTabShowAllMembers(memberService.All());
            BookTabBooksByAuthor(authorService.All());
            ShowAllBooksInComboBox(bookService.All());
            LoanTabShowMembers(memberService.All());
            LoanTabShowCopies(bookCopyService.GetAvailableBookCopies(loanService.All(), bookCopyService.All()));
            ShowAllLoans(loanService.GetAllCurrentLoans(), loanService.GetAllPreviousLoans(), loanService.GetAllOverdueLoans());
            LoanTabShowLoansByMember(memberService.All());

            TEST(loanService.All(), bookCopyService.All());
        }
Esempio n. 2
0
 private void RefreshAuthor(object sender, EventArgs e)
 {
     Show(authorService.All());
     author_select_combo_box.Items.Clear();
     foreach (Author a in authorService.All())
     {
         author_select_combo_box.Items.Add(a.ToString());
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Constructor of form.
        /// </summary>
        public LibraryForm()
        {
            InitializeComponent();

            // Register derived strategy with seed method
            Database.SetInitializer <LibraryContext>(new LibraryDbInit());

            // We create only one context in our application, which gets shared among repositories
            LibraryContext context = new LibraryContext();

            // We use a factory object that will create the repositories as they are needed, it also makes
            // sure all the repositories created use the same context.
            RepositoryFactory repFactory = new RepositoryFactory(context);

            this.bookService   = new BookService(repFactory);
            this.authorService = new AuthorService(repFactory);
            this.copyService   = new BookCopyService(repFactory);
            this.memberService = new MemberService(repFactory);
            this.loanService   = new LoanService(repFactory);

            // All objects that should show up at the start.
            ShowAllAuthors(authorService.All());
            ShowAllBooks(bookService.All(), lbBooks);
            ShowAllBooks(bookService.All(), lbOfBooks);
            ShowAllMembers(memberService.All());
            ShowAllLoans(loanService.All());
            ShowAllCopies(CopyNotOnLoan(), lbCopies);

            // Subscribe to event
            bookService.Updated   += BookService_Updated;
            copyService.Updated   += CopyService_Updated;
            authorService.Updated += AuthorService_Updated;
            memberService.Updated += MemberService_Updated;
            loanService.Updated   += LoanService_Updated;
        }
Esempio n. 4
0
        public LibraryForm()
        {
            InitializeComponent();

            // we create only one context in our application, which gets shared among repositories
            LibraryContext context = new LibraryContext();
            // we use a factory object that will create the repositories as they are needed, it also makes
            // sure all the repositories created use the same context.
            RepositoryFactory repFactory = new RepositoryFactory(context);

            bookService         = new BookService(repFactory);
            copyService         = new BookCopyService(repFactory);
            authorService       = new AuthorService(repFactory);
            memberService       = new MemberService(repFactory);
            returnedLoanService = new ReturnedLoanService(repFactory);
            loanService         = new LoanService(repFactory, returnedLoanService);

            ShowAllBooks(bookService.All());
            ShowAllBookCopies(copyService.All());
            ShowAllMembers(memberService.All());
            ShowAllAuthors(authorService.All());
            ShowAllLoans(loanService.All());
            ShowAllAvailableBooks(copyService.All(), loanService.All());
            ShowAllOverDueBooks(copyService.All());

            bookService.Updated                  += BookService_Updated;
            authorService.Updated                += AuthorService_Updated;
            copyService.Updated                  += CopyService_Updated;
            memberService.Updated                += MemberService_Updated;
            loanService.Updated                  += LoanService_Updated;
            backgroundWorker1.DoWork             += BackgroundWorker1_DoWork;
            backgroundWorker1.RunWorkerCompleted += BackgroundWorker1_RunWorkerCompleted;
        }
Esempio n. 5
0
        /// <summary>
        /// Constructor
        /// </summary>
        public LibraryForm()
        {
            InitializeComponent();

            // we create only one context in our application, which gets shared among repositories
            LibraryContext context = new LibraryContext();
            // we use a factory object that will create the repositories as they are needed, it also makes
            // sure all the repositories created use the same context.
            RepositoryFactory repFactory = new RepositoryFactory(context);

            this.bookService     = new BookService(repFactory);
            this.authorService   = new AuthorService(repFactory);
            this.memberService   = new MemberService(repFactory);
            this.loanService     = new LoanService(repFactory);
            this.bookCopyService = new BookCopyService(repFactory);
            ShowAllBooks(bookService.All());
            ShowAllAuthors(authorService.All());
            ShowAllMembers(memberService.All());
            ShowActiveLoans(loanService.GetActiveLoans());

            //Observers
            bookService.Updated       += OnChanged;
            authorService.Updated     += OnChanged;
            memberService.Updated     += OnChanged;
            loanService.Updated       += OnChanged;
            bookCopyService.Updated   += OnChanged;
            loanService.Updated       += new EventHandler(OnChangedLoanState);
            rbActive.CheckedChanged   += new EventHandler(OnChangedLoanState);
            rbReturned.CheckedChanged += new EventHandler(OnChangedLoanState);
            rbOverdue.CheckedChanged  += new EventHandler(OnChangedLoanState);
        }
Esempio n. 6
0
        public LibraryForm()
        {
            InitializeComponent();

            // we create only one context in our application, which gets shared among repositories
            LibraryContext context = new LibraryContext();
            // we use a factory object that will create the repositories as they are needed, it also makes
            // sure all the repositories created use the same context.
            RepositoryFactory repFactory = new RepositoryFactory(context);

            // Service intialization
            this.bookService     = new BookService(repFactory);
            this.authorService   = new AuthorService(repFactory);
            this.bookCopyService = new BookCopyService(repFactory);
            this.memberService   = new MemberService(repFactory);
            this.loanService     = new LoanService(repFactory);

            // Event declaration
            this.bookService.Updated     += BookService_Updated;
            this.authorService.Updated   += AuthorService_Updated;
            this.memberService.Updated   += MemberService_Updated;
            this.loanService.Updated     += LoanService_Updated;
            this.bookCopyService.Updated += BookCopyService_Updated;

            // Start up methods that populate the lists
            ShowAllBooks(bookService.All());
            ShowAllAuthors(authorService.All());
            ShowAvailableCopies(bookCopyService.AllAvailable());
        }
        public AddBookForm(BookService bookService, AuthorService authorService)
        {
            InitializeComponent();

            this.bookService   = bookService;
            this.authorService = authorService;

            FillDropDownAuthors(authorService.All());
        }
Esempio n. 8
0
        public void ListAllAuthors(object sender, EventArgs e)
        {
            lbAuthors.Items.Clear();

            foreach (Author author in _authorService.All())
            {
                lbAuthors.Items.Add(author);
            }
        }
Esempio n. 9
0
        public void GetAllAuthors()
        {
            var allAuthors = authorService.All();

            foreach (var author in allAuthors)
            {
                AuthorComboBox.Items.Add(author.Name);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Form constructor.
        /// </summary>
        /// <param name="auths"></param>
        /// <param name="bs"></param>
        public CreateNewBook(AuthorService auths, BookService bs)
        {
            authorService = auths;
            bookService   = bs;

            InitializeComponent();

            authorService.Updated += AuthorService_Updated;
            ShowAllAuthors(authorService.All());
        }
Esempio n. 11
0
 private void updateAuthorList()
 {
     lbAuthor.Items.Clear();
     authorComboBox.Items.Clear();
     foreach (Author author in _authorService.All())
     {
         lbAuthor.Items.Add(author);
         authorComboBox.Items.Add(author);
     }
 }
Esempio n. 12
0
        /// <summary>
        /// "Add new author"-knapp
        /// </summary>
        private void btnAddNewAuthor_Click(object sender, EventArgs e)
        {
            if (textBoxAuthorName.Text == "")
            {
                MessageBox.Show("You need to enter a name of the author.", "Error!");
            }
            else if (!textBoxAuthorName.Text.All(char.IsLetter))
            {
                MessageBox.Show("Name can only contain letters.", "Error!");
            }
            else
            {
                Author author = new Author(textBoxAuthorName.Text);
                authorService.Add(author);

                MessageBox.Show("You have now added the author: " + textBoxAuthorName.Text);
                textBoxAuthorName.Clear();
                AuthorTabShowAllAuthors(authorService.All());
                BookTabShowAllAuthors(authorService.All());
                BookTabBooksByAuthor(authorService.All());
            }
        }
Esempio n. 13
0
        /// <summary>
        /// The button that adds the book and check all the fields.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_AddBook_Click(object sender, EventArgs e)
        {
            var author = AS.All().Where(a => a.Name == txt_Author.Text.Trim()).FirstOrDefault();

            if (txt_ISBN.Text.Trim() == "" || txt_Title.Text.Trim() == "" || txt_Description.Text.Trim() == "" || txt_Author.Text.Trim() == "")
            {
                MessageBox.Show("Please enter all the fields.");
            }
            else if (BS.BookAlreadyExists(txt_ISBN.Text.Trim()))
            {
                MessageBox.Show("This Book already exists");
            }
            else
            {
                if (author != null)
                {
                    Book book = new Book()
                    {
                        ISBN        = txt_ISBN.Text.Trim(),
                        Title       = txt_Title.Text.Trim(),
                        Description = txt_Description.Text.Trim(),
                        Author      = author
                    };
                    try
                    {
                        BS.Add(book);
                    } catch (ArgumentNullException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    Author author2 = new Author()
                    {
                        Name = txt_Author.Text.Trim()
                    };
                    Book book = new Book()
                    {
                        ISBN        = txt_ISBN.Text.Trim(),
                        Title       = txt_Title.Text.Trim(),
                        Description = txt_Description.Text.Trim(),
                        Author      = author2
                    };
                    AS.Add(author2);
                    BS.Add(book);
                    this.Close();
                }
            }
        }
        public BookAndAuthorForm(LibraryForm libraryForm)
        {
            InitializeComponent();

            LibraryContext context = new LibraryContext();

            RepositoryFactory repFactory = new RepositoryFactory(context);


            this.bookService   = new BookService(repFactory);
            this.authorService = new AuthorService(repFactory);
            this.libraryForm   = libraryForm;

            ShowAllAuthors(authorService.All());
            ShowAllBooks(bookService.All());

            authorService.Updated += Service_Updated;
            bookService.Updated   += Service_Updated;
        }
Esempio n. 15
0
        public LibraryForm()
        {
            InitializeComponent();

            // We create only one context in our application, which gets shared among repositories
            LibraryContext context = new LibraryContext();

            // We use a factory object that will create the repositories as they are needed, it also makes
            // sure all the repositories created use the same context.
            RepositoryFactory repFactory = new RepositoryFactory(context);

            this.bookService     = new BookService(repFactory);
            this.authorService   = new AuthorService(repFactory);
            this.bookCopyService = new BookCopyService(repFactory);
            this.loanService     = new LoanService(repFactory);
            this.memberService   = new MemberService(repFactory);

            //Set all starting values.
            ShowAllBooks(bookService.All());
            ShowAllBookCopies(bookCopyService.All());
            IEnumerable <Loan> allCurrentLoans = loanService.AllBookCopiesOnLoan();

            ShowAllCurrentLoans(allCurrentLoans);
            IEnumerable <BookCopy> bookCopiesNotOnLoan = bookCopyService.AllExcept(allCurrentLoans);

            ShowAllAvailableCopies(bookCopiesNotOnLoan);
            FillDropDownMembers(memberService.All().OrderBy(m => m.Name));
            FillDropDownAuthors(authorService.All().OrderBy(a => a.Name));

            //Subscribe to the Updated() event in each service to update the GUI when changes in the database has been made.
            bookService.Updated     += bookUpdated;
            bookCopyService.Updated += bookCopyUpdated;
            authorService.Updated   += authorUpdated;
            memberService.Updated   += memberUpdated;
            loanService.Updated     += loanUpdated;
        }
Esempio n. 16
0
        public LoanForm(LibraryForm libraryForm)
        {
            InitializeComponent();

            LibraryContext context = new LibraryContext();

            RepositoryFactory repFactory = new RepositoryFactory(context);

            this.bookService     = new BookService(repFactory);
            this.authorService   = new AuthorService(repFactory);
            this.memberService   = new MemberService(repFactory);
            this.bookCopyService = new BookCopyService(repFactory);
            this.loanService     = new LoanService(repFactory);
            this.libraryForm     = libraryForm;

            ShowAllBooks(bookService.All());
            ShowAllBookCopies(bookCopyService.AllAvailableCopies());
            ShowAllMembers(memberService.All());
            ShowAllAuthors(authorService.All());
            ShowAllLoans(loanService.AllCurrentLoans());
            ShowAllReturns(loanService.Returns());

            loanService.Updated += LoanService_Updated;
        }
Esempio n. 17
0
 private void authorUpdated(object sender, EventArgs e)
 {
     dropDown_authors.SelectedIndex = -1;
     dropDown_authors.Items.Clear();
     FillDropDownAuthors(authorService.All());
 }
Esempio n. 18
0
 /// <summary>
 /// Observer event
 /// </summary>
 /// <param name="sender">
 /// Object reference
 /// </param>
 /// <param name="e">
 /// Event data
 /// </param>
 private void OnChanged(object sender, EventArgs args)
 {
     ShowAllBooks(bookService.All());
     ShowAllAuthors(authorService.All());
     ShowAllMembers(memberService.All());
 }
 private void Service_Updated(object sender, EventArgs e)
 {
     ShowAllAuthors(authorService.All());
     ShowAllBooks(bookService.All());
 }