-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
819 lines (709 loc) · 27.1 KB
/
main.cpp
File metadata and controls
819 lines (709 loc) · 27.1 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
#include <iostream>
#include <memory>
#include <vector>
#include <limits>
#include <iomanip>
#include <algorithm>
#include "Core Classes/Book.h"
#include "Core Classes/User.h"
#include "Core Classes/LoanManager.h"
#include "Utils/ini/GlobalConfiguration.h"
#include "Utils/ini/ConfigManager.h"
#include "Utils/csv/CSVStorageManager.h"
#include "Utils/InputValidator.h"
#ifdef _WIN32
#include <direct.h>
#endif
class LibrarySystem {
private:
std::vector<std::unique_ptr<Book>> books;
std::vector<std::unique_ptr<User>> users;
std::unique_ptr<LoanManager> loanManager;
User* currentUser;
std::string usersCSVFile = "database/users.csv";
std::string booksCSVFile = "database/books.csv";
std::string transactionsCSVFile = "database/transactions.csv";
std::string reservationsCSVFile = "database/reservations.csv";
// Helper functions
void clearScreen() {
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
void waitForKey() {
std::cout << "\nPress Enter to continue...";
//causing two enters need for backing to menu
// std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cin.get();
}
void displayHeader(const std::string& title) {
clearScreen();
std::cout << "\n" << std::string(50, '=') << std::endl;
std::cout << std::setw(25 + title.length()/2) << title << std::endl;
std::cout << std::string(50, '=') << std::endl;
}
// Menu functions
void showMainMenu() {
while (true) {
displayHeader("Library Management System");
std::cout << "\n1. Login"
<< "\n2. Register New User"
<< "\n3. Exit"
<< "\n\n";
int choice = InputValidator::getInt("Choice: ", 1, 3);
switch (choice) {
case 1: handleLogin(); break;
case 2: handleRegistration(); break;
case 3: return;
default: std::cout << "Invalid choice. Please try again.\n";
}
}
}
void showUserMenu() {
while (true) {
displayHeader("User Menu - Welcome " + currentUser->getUsername());
std::cout << "\n1. Search Books"
<< "\n2. View Available Books"
<< "\n3. Borrow Book"
<< "\n4. Return Book"
<< "\n5. Reserve Book"
<< "\n6. View My Loans"
<< "\n7. View My Reservations"
<< "\n8. View My Fines"
<< "\n9. Logout"
<< "\n\n";
int choice = InputValidator::getInt("Choice: ", 1, 9);
switch (choice) {
case 1: searchBooks(); break;
case 2: viewAvailableBooks(); break;
case 3: borrowBook(); break;
case 4: returnBook(); break;
case 5: reserveBook(); break;
case 6: viewMyLoans(); break;
case 7: viewMyReservations(); break;
case 8: viewMyFines(); break;
case 9: return;
default: std::cout << "Invalid choice. Please try again.\n";
}
waitForKey();
}
}
void showLibrarianMenu() {
while (true) {
displayHeader("Librarian Menu - Welcome " + currentUser->getUsername());
std::cout << "\n1. Add New Book"
<< "\n2. Edit Book"
<< "\n3. Remove Book"
<< "\n4. View All Books"
<< "\n5. Manage Users"
<< "\n6. View All Loans"
<< "\n7. View All Reservations"
<< "\n8. Manage Fines"
<< "\n9. Generate Reports"
<< "\n10. System Settings"
<< "\n11. Register New Librarian"
<< "\n12. Logout"
<< "\n\n";
int choice = InputValidator::getInt("Choice: ", 1, 12);
switch (choice) {
case 1: addBook(); break;
case 2: editBook(); break;
case 3: removeBook(); break;
case 4: viewAllBooks(); break;
case 5: manageUsers(); break;
case 6: viewAllLoans(); break;
case 7: viewAllReservations(); break;
case 8: manageFines(); break;
case 9: generateReports(); break;
case 10: systemSettings(); break;
case 11: handleLibrarianRegistration(); break;
case 12: return;
default: std::cout << "Invalid choice. Please try again.\n";
}
waitForKey();
}
}
void handleLibrarianRegistration() {
std::string username, password;
displayHeader("Register New Librarian");
std::cout << "\nUsername: ";
std::getline(std::cin, username);
// Check if username already exists
for (const auto& user : users) {
if (user->getUsername() == username) {
std::cout << "\nUsername already exists. Please choose another.\n";
waitForKey();
return;
}
}
std::cout << "Password: ";
std::getline(std::cin, password);
int newId = users.size() + 1;
users.push_back(std::make_unique<Librarian>(newId, username, password));
std::cout << "\nLibrarian registered successfully!\n";
waitForKey();
}
// Authentication functions
void handleLogin() {
std::string username, password;
displayHeader("Login");
std::cout << "\nUsername: ";
std::getline(std::cin, username);
std::cout << "Password: ";
std::getline(std::cin, password);
for (const auto& user : users) {
if (user->getUsername() == username && user->authenticate(password)) {
currentUser = user.get();
if (dynamic_cast<Librarian*>(currentUser)) {
showLibrarianMenu();
} else {
showUserMenu();
}
currentUser = nullptr;
return;
}
}
std::cout << "\nInvalid username or password.\n";
waitForKey();
}
void handleRegistration() {
std::string username, password;
displayHeader("New User Registration");
std::cout << "\nUsername: ";
std::getline(std::cin, username);
// Check if username already exists
for (const auto& user : users) {
if (user->getUsername() == username) {
std::cout << "\nUsername already exists. Please choose another.\n";
waitForKey();
return;
}
}
std::cout << "Password: ";
std::getline(std::cin, password);
int newId = users.size() + 1;
users.push_back(std::make_unique<RegularUser>(newId, username, password));
std::cout << "\nUser registered successfully!\n";
waitForKey();
}
// Book management functions
void addBook() {
displayHeader("Add New Book");
std::cout << "\nSelect book type:"
<< "\n1. TextBook"
<< "\n2. Magazine"
<< "\n3. Reference Book"
<< "\n\nChoice: ";
int choice;
std::cin >> choice;
std::cin.ignore();
// Common book properties
std::string title, author, category, publicationDate;
int pageCount;
std::cout << "\nEnter book details:\n";
std::cout << "Title: ";
std::getline(std::cin, title);
std::cout << "Author: ";
std::getline(std::cin, author);
std::cout << "Category: ";
std::getline(std::cin, category);
std::cout << "Publication Date (YYYY-MM-DD): ";
std::getline(std::cin, publicationDate);
std::cout << "Page Count: ";
std::cin >> pageCount;
std::cin.ignore();
int id = books.size() + 1; // Simple ID generation
switch (choice) {
case 1: {
std::string academicLevel, field;
std::cout << "Academic Level: ";
std::getline(std::cin, academicLevel);
std::cout << "Field: ";
std::getline(std::cin, field);
books.push_back(std::make_unique<TextBook>(id, title, author, category,
publicationDate, pageCount, academicLevel, field));
break;
}
case 2: {
int issueNumber;
std::cout << "Issue Number: ";
std::cin >> issueNumber;
books.push_back(std::make_unique<Magazine>(id, title, author, category,
publicationDate, pageCount, issueNumber));
break;
}
case 3: {
books.push_back(std::make_unique<ReferenceBook>(id, title, author, category,
publicationDate, pageCount));
break;
}
default:
std::cout << "Invalid book type selected.\n";
return;
}
std::cout << "\nBook added successfully!\n";
}
void viewAllBooks() {
displayHeader("All Books");
if (books.empty()) {
std::cout << "\nNo books in the library.\n";
return;
}
for (const auto& book : books) {
book->printInfo();
std::cout << std::string(50, '-') << std::endl;
}
}
void viewAvailableBooks() {
displayHeader("Available Books");
bool found = false;
for (const auto& book : books) {
if (book->getStatus() == BookStatus::Available) {
book->printInfo();
std::cout << std::string(50, '-') << std::endl;
found = true;
}
}
if (!found) {
std::cout << "\nNo available books found.\n";
}
}
void searchBooks() {
displayHeader("Search Books");
std::cout << "\n1. Search by Title"
<< "\n2. Search by Author"
<< "\n3. Search by Category"
<< "\n\nChoice: ";
int choice;
std::cin >> choice;
std::cin.ignore();
std::string searchTerm;
std::cout << "Enter search term: ";
std::getline(std::cin, searchTerm);
bool found = false;
for (const auto& book : books) {
bool match = false;
switch (choice) {
case 1: match = (book->getTitle().find(searchTerm) != std::string::npos); break;
case 2: match = (book->getAuthor().find(searchTerm) != std::string::npos); break;
case 3: match = (book->getCategory().find(searchTerm) != std::string::npos); break;
}
if (match) {
book->printInfo();
std::cout << std::string(50, '-') << std::endl;
found = true;
}
}
if (!found) {
std::cout << "\nNo matching books found.\n";
}
}
void editBook() {
displayHeader("Edit Book");
viewAllBooks();
int id;
std::cout << "\nEnter book ID to edit (0 to cancel): ";
std::cin >> id;
std::cin.ignore();
if (id == 0) return;
auto it = std::find_if(books.begin(), books.end(),
[id](const auto& book) { return book->getId() == id; });
if (it == books.end()) {
std::cout << "Book not found.\n";
return;
}
std::cout << "\nCurrent book details:\n";
(*it)->printInfo();
std::cout << "\nWhat would you like to edit?"
<< "\n1. Title"
<< "\n2. Author"
<< "\n3. Category"
<< "\n4. Publication Date"
<< "\n5. Page Count"
<< "\n6. Status"
<< "\n0. Cancel"
<< "\n\nChoice: ";
int choice;
std::cin >> choice;
std::cin.ignore();
std::string newValue;
switch (choice) {
case 1:
std::cout << "New title: ";
std::getline(std::cin, newValue);
(*it)->setTitle(newValue);
break;
case 2:
std::cout << "New author: ";
std::getline(std::cin, newValue);
(*it)->setAuthor(newValue);
break;
case 3:
std::cout << "New category: ";
std::getline(std::cin, newValue);
(*it)->setCategory(newValue);
break;
case 4:
std::cout << "New publication date (YYYY-MM-DD): ";
std::getline(std::cin, newValue);
(*it)->setPublicationDate(newValue);
break;
case 5:
int newPages;
std::cout << "New page count: ";
std::cin >> newPages;
(*it)->setPageCount(newPages);
break;
case 6:
std::cout << "New status:"
<< "\n1. Available"
<< "\n2. Borrowed"
<< "\n3. Reserved"
<< "\n4. Lost"
<< "\nChoice: ";
int statusChoice;
std::cin >> statusChoice;
switch (statusChoice) {
case 1: (*it)->setStatus(BookStatus::Available); break;
case 2: (*it)->setStatus(BookStatus::Borrowed); break;
case 3: (*it)->setStatus(BookStatus::Reserved); break;
case 4: (*it)->setStatus(BookStatus::Lost); break;
default: std::cout << "Invalid status choice.\n"; return;
}
break;
case 0:
return;
default:
std::cout << "Invalid choice.\n";
return;
}
std::cout << "\nBook updated successfully!\n";
}
void removeBook() {
displayHeader("Remove Book");
viewAllBooks();
int id;
std::cout << "\nEnter book ID to remove (0 to cancel): ";
std::cin >> id;
std::cin.ignore();
if (id == 0) return;
auto it = std::find_if(books.begin(), books.end(),
[id](const auto& book) { return book->getId() == id; });
if (it == books.end()) {
std::cout << "Book not found.\n";
return;
}
books.erase(it);
std::cout << "\nBook removed successfully!\n";
}
void borrowBook() {
displayHeader("Borrow Book");
viewAvailableBooks();
int id;
std::cout << "\nEnter book ID to borrow (0 to cancel): ";
std::cin >> id;
std::cin.ignore();
if (id == 0) return;
auto it = std::find_if(books.begin(), books.end(),
[id](const auto& book) { return book->getId() == id; });
if (it == books.end()) {
std::cout << "Book not found.\n";
return;
}
if (loanManager->borrowBook(currentUser, it->get())) {
std::cout << "\nBook borrowed successfully!\n";
} else {
std::cout << "\nCould not borrow book. Please check your borrowing limits or book availability.\n";
}
}
void returnBook() {
displayHeader("Return Book");
// Show user's borrowed books
bool found = false;
for (const auto& book : books) {
if (book->getStatus() == BookStatus::Borrowed) {
book->printInfo();
std::cout << std::string(50, '-') << std::endl;
found = true;
}
}
if (!found) {
std::cout << "\nYou have no books to return.\n";
return;
}
int id;
std::cout << "\nEnter book ID to return (0 to cancel): ";
std::cin >> id;
std::cin.ignore();
if (id == 0) return;
auto it = std::find_if(books.begin(), books.end(),
[id](const auto& book) { return book->getId() == id; });
if (it == books.end()) {
std::cout << "Book not found.\n";
return;
}
if (loanManager->returnBook(currentUser, it->get())) {
std::cout << "\nBook returned successfully!\n";
} else {
std::cout << "\nCould not return book. Please check if you actually borrowed this book.\n";
}
}
void reserveBook() {
displayHeader("Reserve Book");
// Show books that can be reserved (currently borrowed)
bool found = false;
for (const auto& book : books) {
if (book->getStatus() == BookStatus::Borrowed) {
book->printInfo();
std::cout << std::string(50, '-') << std::endl;
found = true;
}
}
if (!found) {
std::cout << "\nNo books available for reservation.\n";
return;
}
int id;
std::cout << "\nEnter book ID to reserve (0 to cancel): ";
std::cin >> id;
std::cin.ignore();
if (id == 0) return;
auto it = std::find_if(books.begin(), books.end(),
[id](const auto& book) { return book->getId() == id; });
if (it == books.end()) {
std::cout << "Book not found.\n";
return;
}
if (loanManager->reserveBook(currentUser, it->get())) {
std::cout << "\nBook reserved successfully!\n";
} else {
std::cout << "\nCould not reserve book. The book might not be available for reservation.\n";
}
}
void viewMyLoans() {
displayHeader("My Loans");
loanManager->printUserLoans(currentUser->getUserId());
}
void viewMyReservations() {
displayHeader("My Reservations");
loanManager->printUserReservations(currentUser->getUserId());
}
void viewMyFines() {
displayHeader("My Fines");
std::cout << "Your current fines: $" << currentUser->getTotalFines() << std::endl;
}
void manageUsers() {
displayHeader("Manage Users");
for (const auto& user : users) {
std::cout << "ID: " << user->getUserId()
<< ", Username: " << user->getUsername()
<< ", Type: " << user->getType() << std::endl;
}
}
void viewAllLoans() {
displayHeader("All Loans");
loanManager->printAllLoans();
}
void viewAllReservations() {
displayHeader("All Reservations");
loanManager->printAllReservations();
}
void manageFines() {
displayHeader("Manage Fines");
manageUsers();
int userId;
std::cout << "\nEnter user ID to manage fines (0 to cancel): ";
std::cin >> userId;
std::cin.ignore();
if (userId == 0) return;
auto it = std::find_if(users.begin(), users.end(),
[userId](const auto& user) { return user->getUserId() == userId; });
if (it == users.end()) {
std::cout << "User not found.\n";
return;
}
std::cout << "Current fines: $" << (*it)->getTotalFines() << std::endl;
double amount;
std::cout << "Enter amount to waive (0 to cancel): $";
std::cin >> amount;
if (amount <= 0) return;
if (loanManager->payFine(it->get(), amount)) {
std::cout << "\nFines waived successfully!\n";
} else {
std::cout << "\nError waiving fines.\n";
}
}
void generateReports() {
displayHeader("Generate Reports");
std::cout << "\nLibrary Statistics:"
<< "\n-------------------"
<< "\nTotal books: " << books.size()
<< "\nTotal users: " << users.size()
<< "\nTotal loans: " << loanManager->getTotalLoans()
<< "\nActive loans: " << loanManager->getActiveLoans()
<< "\nOverdue books: " << loanManager->getOverdueCount()
<< "\nTotal fines: $" << loanManager->getTotalFines()
<< std::endl;
std::cout << "\nOverdue Books:\n";
loanManager->printOverdueBooks();
std::cout << "\nMost Popular Books:\n";
// TODO: Implement most popular books report
}
void systemSettings() {
displayHeader("System Settings");
std::cout << "\n1. Fine Rate Settings"
<< "\n2. Loan Period Settings"
<< "\n3. Reservation Settings"
<< "\n4. Backup Settings"
<< "\n5. Librarian Settings"
<< "\n6. Return to Main Menu"
<< "\n\nChoice: ";
int choice;
std::cin >> choice;
std::cin.ignore();
switch (choice) {
case 1: {
std::cout << "Current fine rate per day: $" << daily_fine_rate << std::endl;
std::cout << "Enter new fine rate per day: $";
double newRate;
std::cin >> newRate;
std::cin.ignore();
if (newRate > 0) {
daily_fine_rate = newRate;
ConfigManager::saveConfig();
std::cout << "Fine rate updated successfully.\n";
} else {
std::cout << "Invalid value. No changes made.\n";
}
break;
}
case 2: {
std::cout << "Current loan period (days): " << regular_user_loan_period << std::endl;
std::cout << "Enter new loan period (days): ";
int newPeriod;
std::cin >> newPeriod;
std::cin.ignore();
if (newPeriod > 0) {
regular_user_loan_period = newPeriod;
ConfigManager::saveConfig();
std::cout << "Loan period updated successfully.\n";
} else {
std::cout << "Invalid value. No changes made.\n";
}
break;
}
case 3: {
std::cout << "Current max reservations per user: " << regular_user_borrow_limit << std::endl;
std::cout << "Enter new max reservations per user: ";
int newMax;
std::cin >> newMax;
std::cin.ignore();
if (newMax > 0) {
regular_user_borrow_limit = newMax;
ConfigManager::saveConfig();
std::cout << "Reservation limit updated successfully.\n";
} else {
std::cout << "Invalid value. No changes made.\n";
}
break;
}
case 4:
// TODO: Implement backup settings
std::cout << "Feature not yet implemented.\n";
break;
case 5: {
std::cout << "Current librarian borrow limit: " << librarian_borrow_limit << std::endl;
std::cout << "Enter new librarian borrow limit: ";
int newLimit;
std::cin >> newLimit;
std::cin.ignore();
if (newLimit > 0) {
librarian_borrow_limit = newLimit;
ConfigManager::saveConfig();
std::cout << "Librarian borrow limit updated successfully.\n";
} else {
std::cout << "Invalid value. No changes made.\n";
}
std::cout << "Current librarian loan period (days): " << librarian_loan_period << std::endl;
std::cout << "Enter new librarian loan period (days): ";
int newPeriod;
std::cin >> newPeriod;
std::cin.ignore();
if (newPeriod > 0) {
librarian_loan_period = newPeriod;
ConfigManager::saveConfig();
std::cout << "Librarian loan period updated successfully.\n";
} else {
std::cout << "Invalid value. No changes made.\n";
}
break;
}
case 6:
return;
default:
std::cout << "Invalid choice.\n";
break;
}
}
public:
LibrarySystem() : loanManager(std::make_unique<LoanManager>()), currentUser(nullptr) {
// ساخت پوشه database اگر وجود نداشت
#ifdef _WIN32
_mkdir("database");
#else
mkdir("database", 0777);
#endif
// بررسی وجود فایل و خواندن کاربران
CSVStorageManager::checkOrCreateCSVFile(usersCSVFile);
users = CSVStorageManager::loadUsers(usersCSVFile);
if (users.empty()) {
users.push_back(std::make_unique<Librarian>(1, "admin", "admin123"));
}
// بررسی وجود فایل و خواندن کتابها
CSVStorageManager::checkOrCreateCSVFile(booksCSVFile);
books = CSVStorageManager::loadBooks(booksCSVFile);
// بررسی وجود فایل و خواندن تراکنشها
CSVStorageManager::checkOrCreateCSVFile(transactionsCSVFile);
auto loadedTransactions = CSVStorageManager::loadLoanTransactions(transactionsCSVFile);
for (auto& t : loadedTransactions) {
loanManager->getTransactions().push_back(std::move(t));
}
// بررسی وجود فایل و خواندن رزروها
CSVStorageManager::checkOrCreateCSVFile(reservationsCSVFile);
auto loadedReservations = CSVStorageManager::loadReservations(reservationsCSVFile);
// فرض بر این است که رزروها را باید به map مربوطه اضافه کنید (مثلاً بر اساس bookId)
for (const auto& r : loadedReservations) {
loanManager->getReservations()[r.bookId].push(r);
}
}
void run() {
loadGlobalConfigurationFromIni();
showMainMenu();
// ذخیره کاربران، کتابها، تراکنشها و رزروها در انتهای برنامه
CSVStorageManager::saveUsers(users, usersCSVFile);
CSVStorageManager::saveBooks(books, booksCSVFile);
CSVStorageManager::saveLoanTransactions(loanManager->getTransactions(), transactionsCSVFile);
// جمعآوری همه رزروها از map و ذخیره در فایل
std::vector<Reservation> allReservations;
for (const auto& pair : loanManager->getReservations()) {
std::queue<Reservation> q = pair.second;
while (!q.empty()) {
allReservations.push_back(q.front());
q.pop();
}
}
CSVStorageManager::saveReservations(allReservations, reservationsCSVFile);
}
};
int main() {
try {
LibrarySystem library;
library.run();
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return 0;
}