コード例 #1
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;
        }
コード例 #2
0
ファイル: LibraryForm.cs プロジェクト: lvlindv/OOP2-project-
        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());
        }
コード例 #3
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);

            //Adds event listener to bookService.
            this.bookService.Updated     += UpdateBookListEvent;
            this.bookCopyService.Updated += UpdateBookCopyListEvent;
            this.authorService.Updated   += UpdatedAuthorEvent;
            this.memberService.Updated   += UpdateMemberListEvent;
            this.loanService.Updated     += UpdatedLoansEvent;

            UpdateBookList(bookService.All().ToList());
            currentBookDisplay     = bookService.All().ToList();
            currentBookCopyDisplay = new List <BookCopy>();
            currentMemberDisplay   = memberService.All().ToList();
            currentLoanDisplay     = loanService.All().ToList();

            SetAllColors();
            editAuthorTB.AutoCompleteCustomSource.AddRange(authorService.GetAllAuthorNames().ToArray()); //Adds all the current authors to autocomplete list.
        }
コード例 #4
0
 private void updateBookList()
 {
     lbBooks.Items.Clear();
     if (lbAuthor.SelectedItem == null || authorChkBox.Checked == false)
     {
         foreach (Book element in _bookService.All())
         {
             if (element.copies.Exists(b => b.Loan.Equals(false)) || availChkBox.Checked == false)
             {
                 if ((element.Title.ToLower()).Contains(searchField.Text.ToLower()) || (element.author.Name.ToLower()).Contains(searchField.Text.ToLower()))
                 {
                     lbBooks.Items.Add(element);
                 }
             }
         }
     }
     if (lbAuthor.SelectedItem != null && authorChkBox.Checked == true)
     {
         foreach (Book element in _bookService.ByAuthor((Author)lbAuthor.SelectedItem))
         {
             if (element.copies.Exists(b => b.Loan.Equals(false)) || availChkBox.Checked == false)
             {
                 if ((element.Title.ToLower()).Contains(searchField.Text.ToLower()) || (element.author.Name.ToLower()).Contains(searchField.Text.ToLower()))
                 {
                     lbBooks.Items.Add(element);
                 }
             }
         }
     }
     updateBookInfo();
 }
コード例 #5
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;
        }
コード例 #6
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);
        }
コード例 #7
0
ファイル: LibraryForm.cs プロジェクト: backadd/Projekt
 private void ListAllBooks()
 {
     foreach (Book book in _bookService.All())
     {
         lbBooks.Items.Add(book);
     }
 }
コード例 #8
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());
        }
コード例 #9
0
        /// <summary>
        /// Filling Como Boxes (on change)
        /// </summary>
        private void FillComboBoxes()
        {
            ShowAllBooks(_bookService.All());
            ShowAllLoans(_loanService.AllLoans());

            AddBookAuthor_ComboBox.Items.Clear();
            Member_ComboBox.Items.Clear();
            AllMembers_listbox.Items.Clear();

            foreach (var author in _authorService.AllAuthors())
            {
                AddBookAuthor_ComboBox.Items.Add(author);
            }

            SearchBookByAuthor_combobox.Items.Clear();

            foreach (var author in _authorService.AllAuthors())
            {
                SearchBookByAuthor_combobox.Items.Add(author);
            }

            // Notera: Går bra att ej köra Member.Name här eftersom jag overridar ToString i modellen istället.
            // Därför blir det smidigare att casta när jag ska låna.
            foreach (var member in _memberService.AllMembers())
            {
                Member_ComboBox.Items.Add(member);
                AllMembers_listbox.Items.Add(member);
            }
        }
コード例 #10
0
ファイル: LibraryForm.cs プロジェクト: Becc-s/super-barnacle
        //All print methods that are subscribed to the event

        public void ListAllBooks(object sender, EventArgs e)
        {
            lbBooks.Items.Clear();

            foreach (Book book in _bookService.All())
            {
                lbBooks.Items.Add(book);
            }
        }
コード例 #11
0
ファイル: LibraryForm.cs プロジェクト: lvlindv/OOP2-project-
        /// <summary>
        /// "Add book"-button
        /// </summary>
        private void btnAddNewBook_Click(object sender, EventArgs e)
        {
            if (textBoxISBN.Text == "" || textBoxTitle.Text == "" || textBoxDescription.Text == "" || (Author)comboBoxAuthor.SelectedItem == null)
            {
                MessageBox.Show("You need to fill in all book details.", "Error!");
            }
            else
            {
                var  author = (Author)comboBoxAuthor.SelectedItem;
                Book book   = new Book(textBoxISBN.Text, textBoxTitle.Text, textBoxDescription.Text, author);
                author.Books.Add(book);
                bookService.Add(book);

                MessageBox.Show("You have now added the book: " + textBoxTitle.Text);
                textBoxISBN.Clear();
                textBoxTitle.Clear();
                textBoxDescription.Clear();
                ShowAllBooks(bookService.All());
                ShowAllBooksInComboBox(bookService.All());
            }
        }
コード例 #12
0
        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;
        }
コード例 #13
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.memberService   = new MemberService(repFactory);
            this.bookCopyService = new BookCopyService(repFactory);
            this.loanService     = new LoanService(repFactory);

            ShowAllBooks(bookService.All());

            bookService.Updated += BookService_Updated;
        }
コード例 #14
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;
        }
コード例 #15
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;
        }
コード例 #16
0
ファイル: LibraryForm.cs プロジェクト: EmilK85/Projektarbete
 private void button1_Click(object sender, EventArgs e)
 {
     _bookService.All();
 }
コード例 #17
0
 private void bookUpdated(object sender, EventArgs e)
 {
     lbCopies.Items.Clear();
     ShowAllBooks(bookService.All());
 }
コード例 #18
0
ファイル: LibraryForm.cs プロジェクト: Vildmusen/OOP2PROJECT
 private void RefreshBook(object sender, EventArgs e)
 {
     Show(bookService.All());
 }
コード例 #19
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());
 }
コード例 #20
0
 private void ShowAllBooks_button_Click(object sender, EventArgs e)
 {
     ShowAllBooks(bookService.All());
     ShowAllBookCopies(bookCopyService.AllAvailableCopies());
 }
コード例 #21
0
 private void BookService_Updated(object sender, EventArgs e)
 {
     ShowAllBooks(bookService.All());
 }
コード例 #22
0
 private void Service_Updated(object sender, EventArgs e)
 {
     ShowAllAuthors(authorService.All());
     ShowAllBooks(bookService.All());
 }
コード例 #23
0
 /// <summary>
 /// Book service event method
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BookService_Updated(object sender, EventArgs e)
 {
     ShowAvailableCopies(bookCopyService.AllAvailable());
     ShowAllBooks(bookService.All());
 }