Пример #1
0
 public BorrrowerGUI()
 {
     borrowerList = new BorrowerList();
 }
Пример #2
0
        public void reserve(List<Reservation> xreserveList, BorrowerList bl, BookList booklist)
        {
            Console.WriteLine("---- Reserve a Book ----");
            Queue<int> BorrowerQueue = new Queue<int>();
            int BorNum = 0;
            bool found2 = false;
            while (true)
            {
                Console.Write("Borrower Number (0 to quit) : ");
                try
                {
                    //kiem tra xem Borrower number co dung khong
                    BorNum = int.Parse(Console.ReadLine());
                    if ( BorNum == 0) { return; }
                    for (int i = 0; i < bl.t.Count; i++)
                    {
                        if (bl.t[i].brNumber != BorNum)
                        {
                            found2 = false;
                        }
                        else
                        {
                            found2 = true;
                            break;
                        }
                    }

                    if (found2 == false)
                    {
                        Console.WriteLine("{0} doesn't match with any borrower ! Please try again.", BorNum);
                    }
                    else
                    {
                        break;
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Invalid Borrower Number ! Please try again");
                }
            }

            DateTime date;
            while (true)
            {
                Console.Write("Enter borrow date (Format : dd/mm/yyyy) : ");
                String s = Console.ReadLine();
                try
                {
                    date = BorrowGUI.GetDate(s);
                    break;
                }
                catch (Exception)
                {
                    Console.WriteLine("Invalid Date ! Please try again !");
                }
            }

            int BookNum = 0;
            Book book = new Book();
            bool found1 = false;
            while (true)
            {
                Console.Write("Book Number (0 to quit) : ");
                try
                {
                    BookNum = int.Parse(Console.ReadLine());
                    if (BookNum == 0) {
                        Console.WriteLine("Enter to continue !");
                        return; }
                    for (int i = 0; i < booklist.q.Count; i++)
                    {
                        if (booklist.q[i].bNumber != BookNum)
                        {
                            found1 = false;//khong tim thay
                        }
                        else
                        {
                            book = booklist.q[i];
                            found1 = true;//tim that la break
                            break;
                        }

                    }
                    bool thoat = false;
                    if (found1 == false)
                    {
                        Console.WriteLine("{0} doesn't match with any book ! Please try again.", BookNum);
                    }
                    else
                    {
                        for (int i = 0; i < book.k.Count; i++)
                        {
                            if (book.k[i].type == 'A')
                            {
                                Console.WriteLine("This book still has available copy book ! You cannot reserve this book !");
                                return;
                                thoat = false;
                                break;
                            }
                            else
                            {
                                thoat = true;
                            }
                        }
                    }
                    if (thoat == true)
                        break;
                }
                catch (Exception)
                {
                    Console.WriteLine("Invalid Copy Book Number ! Please try again");
                }
            }
            bool add = true;
            for (int i = 0; i < xreserveList.Count; i++)
            {
                if (xreserveList[i].booknumber == BookNum && xreserveList[i].borrowNum.Count >= 0)
                {
                    Console.Write("This book was reserved by " + xreserveList[i].borrowNum.Count + " people. Do you wanna become the next one ! (Y/N):");
                    char chon = char.Parse(Console.ReadLine());
                    if (chon == 'Y' || chon == 'y')
                    {
                        add = false;
                        xreserveList[i].borrowNum.Enqueue(BookNum);
                        Console.WriteLine("Added Successfull ! Enter to continue !");
                    }
                    else
                    {
                        return; // neu khong muon reserve tiep
                        Console.WriteLine("Enter to continue !");
                    }
                    break;
                }
                else
                {
                    add = true;
                }
            }
            if (add == true)
            {
                Queue<int> nguoi_muon = new Queue<int>();
                nguoi_muon.Enqueue(BorNum);
                Reservation re = new Reservation(nguoi_muon, BookNum, date, 'A');
                xreserveList.Add(re);
                Console.WriteLine("Reserve successfull ! Enter to continue !");

            }
        }
Пример #3
0
        public void borrowBook(List<Reservation> xreserveList, BookList booklist, BorrowerList borrowerlist)
        {
            //sua cac bien o BookList va BorrowerList thanh public
            Console.WriteLine("---- Borrow a Book ----");

            int BorNum = 0;
            bool found2 = false;
            int damuon = 0;
            Borrower br = new Borrower();
            while (true)
            {
                Console.Write("Enter Borrower Number ( 0 to quit ) : ");
                try
                {
                    //kiem tra xem Borrower number co dung khong
                    BorNum = int.Parse(Console.ReadLine());
                    if (BorNum == 0)
                    {
                        Console.WriteLine("Enter to continue !");
                        return;
                    }

                    for (int i = 0; i < borrowerlist.t.Count; i++)
                    {
                        if (borrowerlist.t[i].brNumber != BorNum)
                        {
                            found2 = false;
                        }
                        else
                        {
                            br = borrowerlist.t[i];
                            damuon = br.borrowing.Count;
                            found2 = true;
                            break;
                        }
                    }

                    if (found2 == false)
                    {
                        Console.WriteLine("{0} doesn't match with any borrower ! Please try again.", BorNum);
                    }
                    else
                    {
                        if (damuon >= 5)
                        {
                            Console.WriteLine(BorNum + "has borrowed 5 books ! Please try again.");
                            found2 = false;
                        }
                        else
                        {
                            break;
                        }
                        //else
                        //{
                        //    br.borrowing.Add(copbook);
                        //    break;
                        //}
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Invalid Borrower Number ! Please try again");
                }
            }

            int CopNum = 0;
            bool found1 = false;
            Copy copbook = new Copy();
            Book book = new Book();

            while (true)
            {
                Console.Write("Enter Copy Number ( 0 to quit ): ");
                try
                {
                    CopNum = int.Parse(Console.ReadLine());
                    if (CopNum == 0)
                    {
                        Console.WriteLine("Enter to continue !");
                        return;
                    }
                    for (int i = 0; i < booklist.q.Count; i++)
                    {
                        for (int j = 0; j < booklist.q[i].k.Count; j++)
                        {
                            if (booklist.q[i].k[j].cNumber == CopNum)
                            {
                                book = booklist.q[i];
                                copbook = booklist.q[i].k[j];
                                found1 = true;
                                break;
                            }
                            else
                            {
                                found1 = false;
                            }
                        }
                        if (found1 == true) break;
                    }
                    if (found1 == false)
                    {
                        Console.WriteLine("{0} doesn't match with any copy book ! Please try again.", CopNum);
                    }
                    else
                    {
                        if (copbook.type != 'A')
                        {
                            Console.WriteLine("This copy book is not available ! Please try with another copy book !");
                        }
                        else
                        {
                            bool canBorrow = false ;
                            if (xreserveList.Count == 0)
                            {
                                br.borrowing.Add(copbook);
                                for (int n = 0; n < booklist.q.Count; n++)
                                {
                                    for (int j = 0; j < booklist.q[n].k.Count; j++)
                                    {
                                        if (booklist.q[n].k[j].cNumber == CopNum)
                                        {
                                            booklist.q[n].k[j].type = 'B';//set lai la da muon B = borrowed
                                            break;
                                        }
                                    }
                                }
                                canBorrow = true;
                            }
                            else
                            {
                                //xet xem no co reserve quen sach nay khong
                                for (int i = 0; i < xreserveList.Count; i++)
                                {
                                    if (xreserveList[i].borrowNum.Peek() == BorNum)
                                    {
                                        br.borrowing.Add(copbook);
                                        xreserveList[i].borrowNum.Dequeue();
                                        for (int n = 0; n < booklist.q.Count; n++)
                                        {
                                            for (int j = 0; j < booklist.q[n].k.Count; j++)
                                            {
                                                if (booklist.q[n].k[j].cNumber == CopNum)
                                                {
                                                    booklist.q[n].k[j].type = 'B';//set lai la da muon B = borrowed
                                                    break;
                                                }
                                            }
                                        }
                                        canBorrow = true;
                                        break;
                                    }
                                    else
                                    {
                                        canBorrow = false;
                                    }
                                }
                            }
                            if (canBorrow == false)
                            {
                                Console.WriteLine("This book was reserved by another people !");
                                return;
                            }
                            //them
                            break;
                        }
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Invalid Copy Book Number ! Please try again");
                }
            }

            DateTime xborrowDate;
            while (true)
            {
                Console.Write("Enter borrow date (Format : dd/mm/yyyy) : ");
                String s = Console.ReadLine();
                try
                {
                    xborrowDate = GetDate(s);
                    break;
                }
                catch (Exception)
                {
                    Console.WriteLine("Invalid Date ! Please try again !");
                }
            }

            DateTime xdueDate;
            while (true)
            {
                Console.Write("Due date (Format : dd/mm/yyyy) : ");
                String s = Console.ReadLine();
                try
                {
                    xdueDate = GetDate(s);
                    TimeSpan day = xdueDate - xborrowDate;
                    double ngay = day.TotalDays;
                    if (ngay > 0)
                    { break; }
                    else
                    {
                        Console.WriteLine("Due date must after borrow date !");
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Invalid Date ! Please try again !");
                }
            }
            CirculatedCopy cc = new CirculatedCopy(BorNum, CopNum, xborrowDate, xdueDate);
            borrowList.borrowlist.Add(cc);

            display(br);
        }
Пример #4
0
 public ReturnGUI(BorrowerList brl, BookList bol, BorrowList brl1)
 {
     this.bookList = bol;
     this.borrowerList = brl;
     this.borrowList = brl1;
 }