public void register() { Random rand = new Random(); Console.WriteLine("\nRegister a book"); Console.WriteLine("Enter information to registry:"); Console.Write("Title: "); String tit = Console.ReadLine(); Console.Write("Publisher: "); String pub = Console.ReadLine(); Console.Write("Authors: "); String au = Console.ReadLine(); Book abc = new Book(bn, tit, au, pub); foreach (Book k in bookList.q) { if (k.bNumber.Equals(abc.bNumber)) { Console.WriteLine("Can't Register this book (bookNumber is unique)"); Console.ReadKey(); return; } } bookList.q.Add(abc); Console.WriteLine("Add completed !"); bool kq = true; char ab1; while (true) { Console.Write("Do you want to create copy of this book ? (Y/N) : "); try { ab1 = char.Parse(Console.ReadLine()); if (ab1 == 'n' || ab1 == 'N') { bn = bn + 1; kq = false; break; } else if (ab1 == 'y' || ab1 == 'Y') { kq = true; break; } } catch { Console.WriteLine("You must enter Y or N!"); } } while (kq) { bool test = true; Console.WriteLine("\nEnter information of its copies"); Console.WriteLine("Enter information to registry:"); char ty; while (true) { Console.Write("Type ( A: Available or R: Referenced ): "); try { ty = char.Parse(Console.ReadLine()); //string s1 = ty.ToString(); //s1 = s1.ToLower(); if (ty == 'a' || ty == 'r' || ty == 'A' || ty == 'R') { break; } else Console.WriteLine("You must enter A or R!"); } catch { Console.WriteLine("You must enter A or R!"); } } double pr = 0; Boolean t = false; while (t == false) { Console.Write("Price: "); try { pr = double.Parse(Console.ReadLine()); t = true; } catch { Console.WriteLine("Price must be a number!"); t = false; } } Copy z = new Copy(cn, bn, seq, ty, pr); foreach (Copy k in copyList.q) { if (k.cNumber.Equals(z.cNumber)) { Console.WriteLine("Can't Register this Copy (copyNumber is unique)"); test = false; } } if (test) { cn = cn + 1; seq = seq + 1; abc.k.Add(z); copyList.q.Add(z); } Console.Write("Continue to create copy of this book ? (Y/N) : "); string ab = Console.ReadLine(); if (!ab.Equals("Y") && !ab.Equals("y")) { bn = bn + 1; break; } } }
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); }