-
Notifications
You must be signed in to change notification settings - Fork 0
/
administratorUser.cpp
110 lines (105 loc) · 3.15 KB
/
administratorUser.cpp
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
#include"administratorUser.h"
#include<fstream>
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
void AdministratorUser::addBook(Inventory& inventory)
{
std::string title, author, ISBN, press, type;
std::cout << "请输入书名:";
std::cin >> title;
std::cout << "请输入作者:";
std::cin >> author;
std::cout << "请输入ISBN:";
std::cin >> ISBN;
std::cout << "请输入出版社:";
std::cin >> press;
std::cout << "请输入类型:";
std::cin >> type;
Book book(title, author, ISBN, press, type);
inventory.addBook(book);
std::ofstream file("inventory.csv", std::ios::app);
// 检查文件是否成功打开
if (!file.is_open())
{
std::cout << "图书目录出错,请紧急修复!" << std::endl;
return;
}
// 写入图书信息到CSV文件
file << title << ","
<< author << ","
<< ISBN << ','
<< press << ','
<< type << ','
<< "未借出" << ','
<< "NULL" << ','
<< "NULL" << '\n';
// 关闭文件
file.close();
std::cout << "添加成功!" << std::endl;
}
void AdministratorUser::deleteBook(Inventory& inventory)
{
std::string ISBN;
std::cout << "请输入删除书目的ISBN:";
std::cin >> ISBN;
Book bookToDelete = inventory.findBook(ISBN,"ISBN");
if(inventory.getBooks().size() == 0)
{
std::cout << "图书目录为空!" << std::endl;
return;
}
else if(!inventory.isExist(bookToDelete))
{
std::cout << "图书不存在!" << std::endl;
return;
}
else
{
inventory.deleteBook(bookToDelete);
std::ofstream outFile("inventory.csv");
for (Book &book : inventory.getBooks())
{
outFile << book.getTitle() << ','
<< book.getAuthor() << ','
<< book.getISBN() << ','
<< book.getPress() << ','
<< book.getType() << ','
<< book.getStatus()[0] << ','
<< book.getStatus()[1] << ','
<< book.getStatus()[2] << '\n';
}
std::cout << "删除成功!" << std::endl;
}
}
/*void AdministratorUser::modifyBook(Inventory &inventory, Book &book)
{
if(inventory.getBooks().size() == 0)
{
std::cout << "图书目录为空!" << std::endl;
return;
}
else if(!inventory.isExist(book))
{
std::cout << "图书不存在!" << std::endl;
return;
}
else
{
inventory.modifyBook(book);
std::ofstream outFile("inventory.csv");
for (Book &book : inventory.getBooks())
{
outFile << book.getTitle() << ','
<< book.getAuthor() << ','
<< book.getISBN() << ','
<< book.getPress() << ','
<< book.getType() << ','
<< book.getStatus()[0] << ','
<< book.getStatus()[1] << ','
<< book.getStatus()[2] << '\n';
}
std::cout << "修改成功!" << std::endl;
}
}*/