-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
127 lines (109 loc) · 6.53 KB
/
Program.cs
File metadata and controls
127 lines (109 loc) · 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Collections.Generic;
using LibraryApp.Classes;
using ConsoleTables;
class Program
{
static void Main()
{
Book book = new Book();
Library library = new Library();
int selectedAction = 0;
ulong ISBN = 0;
BorrowingTransaction borrowingTransaction = new BorrowingTransaction();
Console.WriteLine(" _ _ _ \r\n| (_) |__ _ __ __ _ _ __ _ _ \r\n| | | '_ \\| '__/ _` | '__| | | | \r\n| | | |_) | | | (_| | | | |_| | \r\n|_|_|_.__/|_| \\__,_|_| \\__, | \r\n |___/ \r\n _ \r\n _ __ ___ __ _ _ __ __ _ __ _ ___ _ __ ___ ___ _ __ | |_ \r\n| '_ ` _ \\ / _` | '_ \\ / _` |/ _` |/ _ \\ '_ ` _ \\ / _ \\ '_ \\| __|\r\n| | | | | | (_| | | | | (_| | (_| | __/ | | | | | __/ | | | |_ \r\n|_| |_| |_|\\__,_|_| |_|\\__,_|\\__, |\\___|_| |_| |_|\\___|_| |_|\\__|\r\n |___/ \r\n _ \r\n ___ _ _ ___| |_ ___ _ __ ___ \r\n/ __| | | / __| __/ _ \\ '_ ` _ \\ \r\n\\__ \\ |_| \\__ \\ || __/ | | | | | \r\n|___/\\__, |___/\\__\\___|_| |_| |_| \r\n |___/ ");
Console.WriteLine("\n\n Please press any key to start");
Console.ReadKey();
Console.Clear();
string c = "Please select the action you want to take:\n" +
"1-) Add a book.\n" +
"2-) Receive the book.\n" +
"3-) Lend a book.\n" +
"4-) Display all books.\n" +
"5-) Display books whose due dates have passed.\n" +
"6-) Find a book.\n";
while (true)
{
Console.WriteLine(c);
try
{
selectedAction = Convert.ToInt32(Console.ReadLine());
switch (selectedAction)
{
case 1:
Console.WriteLine("Please enter the ISBN of the book to add :\t\t");
book.ISBSN = ulong.Parse(Console.ReadLine());
Console.WriteLine("Please enter the Title of the book to add :\t\t");
book.Title = Console.ReadLine();
Console.WriteLine("Please enter the Author of the book to add :\t\t");
book.Author = Console.ReadLine();
Console.WriteLine("Please enter the NumberOfCoppies of the book to add :\t\t");
book.NumberOfCopies = int.Parse(Console.ReadLine());
Console.WriteLine("Please enter the BarrowedCoppies of the book to add :\t\t");
book.BarrowedCopies = int.Parse(Console.ReadLine());
library.AddBook(book);
break;
case 2:
Console.WriteLine("Please enter the ISBN of the returned book");
ISBN = ulong.Parse(Console.ReadLine());
Console.WriteLine("Please enter the ORDER ID");
int orderID = int.Parse(Console.ReadLine());
library.ReceiveBook(ISBN, orderID);
Console.WriteLine("\n The book was successfully retrieved\n");
break;
case 3:
Random random = new Random();
Console.WriteLine("Please enter the ISBN of the book to be given\t\t");
ISBN = ulong.Parse(Console.ReadLine());
Console.WriteLine("Please enter the number of books given");
int numberOfBooksGiven = int.Parse(Console.ReadLine());
Console.WriteLine("Please enter the name of the book to be given\t\t");
borrowingTransaction.BookName = Console.ReadLine();
borrowingTransaction.LoanDate = DateTime.Now.ToShortDateString();
borrowingTransaction.OrderID = random.Next(10000, 100000);
borrowingTransaction.Status = "not received";
borrowingTransaction.ISBN = ISBN;
Console.WriteLine("Please enter the name of borrower");
borrowingTransaction.NameOfBorrower = Console.ReadLine();
Console.WriteLine("Please enter the due date (DAY-MONTH-YEAR)");
borrowingTransaction.DueDate = Console.ReadLine();
library.LendBook(ISBN, numberOfBooksGiven, borrowingTransaction);
Console.WriteLine("\n The book has been lent successfully\n");
break;
case 4:
library.DisplayBooks();
break;
case 5:
library.FindOverdueBooks();
break;
case 6:
List<Book> books;
Console.WriteLine("1-)Find the books by author\n" +
"2-)Find the book by Title");
int findOption = Convert.ToInt32(Console.ReadLine());
if (findOption == 1)
{
Console.WriteLine("Please enter the author's name");
books = library.FindBooksByAuthor(Console.ReadLine());
library.DisplayBooks(books);
}
else if (findOption == 2)
{
Console.WriteLine("Please enter the title of the book");
books = library.FindBooksByTitle(Console.ReadLine());
library.DisplayBooks(books);
}
else
{
Console.WriteLine("Please make a valid choice. (1 or 2)");
}
break;
}
}
catch (Exception e)
{
Console.WriteLine($"Please enter data in the appropriate format. The error you get: {e.Message} ");
}
}
}
}