示例#1
0
 private void updateMemberInfo()
 {
     try
     {
         string text = string.Format("{0}\r\nPersonalnr: {1}\r\nLoans: \r\n",
                                     ((Member)comboBox1.SelectedItem).Name,
                                     ((Member)comboBox1.SelectedItem).personalNr);
         List <Loan> loans = new List <Loan>(_loanService.All().Where(m => m.member.Equals((Member)comboBox1.SelectedItem)).OrderByDescending(d => d.time));
         foreach (Loan element in loans)
         {
             if (element.bookCopy.Loan == true)
             {
                 text += string.Format("{0}\r\n - Loan date: {1}\r\n - Due date: {2}\r\n",
                                       element.bookCopy,
                                       element.time.ToShortDateString(),
                                       element.dueDate.ToShortDateString());
             }
             else
             {
                 text += string.Format("{0}\r\n - Loan date: {1}\r\n - Return date: {2}\r\n",
                                       element.bookCopy,
                                       element.time.ToShortDateString(),
                                       element.returnTime.ToShortDateString());
                 if (element.returnTime > element.dueDate)
                 {
                     text += string.Format(" - Late: {0} days\r\n",
                                           (element.returnTime - element.dueDate).TotalDays);
                 }
             }
             text += "\r\n";
         }
         textBox2.Text = text;
     }
     catch { }
 }
示例#2
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;
        }
示例#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);

            //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());
        }
        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.
        }
示例#5
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;
        }
        public LoanHistory(LoanService ls)
        {
            loanService = ls;
            InitializeComponent();

            loanService.Updated += LoanService_Updated;
            ShowAllLoans(loanService.All());
        }
示例#7
0
        private void ListAllLoans(object sender, EventArgs e)
        {
            lbLoans.Items.Clear();

            foreach (Loan loan in _loanService.All())
            {
                lbLoans.Items.Add(loan);
            }
        }
示例#8
0
 /// <summary>
 /// "Add new copy"-button
 /// </summary>
 private void button1_Click(object sender, EventArgs e)
 {
     if ((Book)comboBoxBook.SelectedItem != null)
     {
         try
         {
             BookCopy copy = new BookCopy((Book)comboBoxBook.SelectedItem, Convert.ToInt32(numericUpDownCopies.Value));
             bookCopyService.Add(copy);
             ShowAllBooks(bookService.All());
             LoanTabShowCopies(bookCopyService.GetAvailableBookCopies(loanService.All(), bookCopyService.All()));
             TEST(loanService.All(), bookCopyService.All());
         }
         catch (ArgumentNullException)
         {
             MessageBox.Show("Value can not be null.", "ArgumentNullException");
         }
     }
     else
     {
         MessageBox.Show("You need to choose a book.", "Error!");
     }
 }
示例#9
0
 private void show_loans_btn_Click(object sender, EventArgs e)
 {
     Show(loanService.All());
 }
示例#10
0
 // Event.
 private void LoanService_Updated(object sender, EventArgs e)
 {
     ShowAllLoans(loanService.All());
     ShowAllCopies(CopyNotOnLoan(), lbCopies);
 }
示例#11
0
 private void LoanService_Updated(object sender, EventArgs e)
 {
     ShowAllLoans(loanService.FindAllBooksOnLoan());
     ShowAllAvailableBooks(copyService.All(), loanService.All());
     ShowAllOverDueBooks(copyService.All());
 }
示例#12
0
 private void LoanService_Updated(object sender, EventArgs e)
 {
     ShowAllLoans(loanService.All());
 }
示例#13
0
        /// <summary>
        /// Creates a Loan object
        /// </summary>
        /// <param name="sender">
        /// Object reference
        /// </param>
        /// <param name="e">
        /// Event data
        /// </param>
        private void btn_Create_Loan_Click(object sender, EventArgs e)
        {
            MakeLoanDialog mld = new MakeLoanDialog(memberService.All(), bookCopyService.GetAvailableBookCopies(loanService.All()));

            if (mld.ShowDialog() == DialogResult.OK)
            {
                if (mld._LoanBookCopy == null)
                {
                    MessageBox.Show("No loan created: You must choose a book from the drop-down-list to loan", "Error: Book Copy", MessageBoxButtons.OK);
                }
                else if (mld._LoanMember == null)
                {
                    MessageBox.Show("No loan created: You must choose a member from the drop-down-list for the loan", "Error: Member", MessageBoxButtons.OK);
                }
                else
                {
                    loanService.CreateNewLoan(mld._TimeOfLoan, mld._DueDate, mld._LoanBookCopy, mld._LoanMember);
                }
            }
        }