示例#1
0
 public BorrowGUI()
 {
     circulatedCopy = new CirculatedCopy();
     borrowList = new BorrowList();
 }
示例#2
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);
        }
示例#3
0
        public void Return()
        {
            String ac, bc, returnDateString;
            DateTime returnDate;

            while (true)
            {
                Console.Write("Enter copy number(0 to cancel): ");
                bc = Console.ReadLine();
                if (bc.Equals("0")) { return; }
                if (borrowList.searchCirByCopyNumber(bc) != null)
                {
                    cir = borrowList.searchCirByCopyNumber(bc);
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid copy! try again!");
                }
            }
            while (true)
            {
                Console.Write("Enter return date: ");
                returnDateString = Console.ReadLine();
                try
                {
                    cir.returnDate = BorrowGUI.GetDate(returnDateString);
                    break;
                }
                catch (Exception)
                {
                    Console.WriteLine("Invalid Date ! Please try again !");
                }
            }
            if (cir.returnDate.Date > cir.dueDate)
            {
                TimeSpan dayLater = cir.returnDate.Date - cir.dueDate;
                double ngay = dayLater.TotalDays;
                if (ngay > 0)
                {
                    Console.WriteLine("You need to pay ${0} for your book because your return it's late!", ngay);
                    while (true)
                    {
                        Console.Write("Do you agree? (Y/N): ");
                        String s = Console.ReadLine();
                        if (s.Trim().Equals("N") || s.Trim().Equals("n"))
                        {
                            return;
                        }
                        if (!s.Trim().Equals("N") && !s.Trim().Equals("n") && !s.Trim().Equals("y") && !s.Trim().Equals("Y"))
                        {
                            Console.WriteLine("please Y/N! Try again");
                        }
                        else { break; }
                    }
                }
            }
            bool thoat = false;
            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 == cir.copyNumber)
                    {
                        bookList.q[i].k[j].type = 'A';
                        thoat = true;
                        break;
                    }
                    else
                    {
                        thoat = false;
                    }
                }
                if (thoat == true)
                    break;
            }

            foreach (Borrower b in borrowerList.t)
            {
                if (b.brNumber==cir.borroNumber)
                {
                    for (int i = 0; i < b.borrowing.Count; i++)
                    {
                        if (b.borrowing[i].cNumber == cir.copyNumber)
                        {
                            b.borrowing.Remove(b.borrowing[i]);
                            break;
                        }
                    }
                }

            }

            Console.WriteLine("Borrower\tCopy\t\tBorrow date\tReturn date");
            foreach (CirculatedCopy cir1 in borrowList.borrowlist)
            {
                if (cir1.returnDate.Year!=0001 && cir1.borroNumber == cir.borroNumber)
                {
                    Console.WriteLine(cir1.ToString());
                }
            }
            Console.ReadKey();
        }