-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecord.cpp
More file actions
179 lines (161 loc) · 5.58 KB
/
Copy pathrecord.cpp
File metadata and controls
179 lines (161 loc) · 5.58 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
#include <iostream>
#include<cstdio>
#include<windows.h>
#include<stdlib.h>
#include<stack>
#include<math.h>
#include"user.h"
#include"book.h"
#include"init.h"
#include"menu.h"
#include"record.h"
using namespace std;
void addrecord(char *userName, int bookid, int method)//增加记录
{
record *t = (record *)malloc(sizeof(record));
t->next = the_RecordLine_Head->next;
the_RecordLine_Head->next = t;
strcpy(t->userName, userName);
t->bookID = bookid;
t->method = method;
t->id = ++recordNum;
strcpy(t->time, getTime());
FILE *rfile = fopen(recordfile, "ab+");
fwrite(t, recordDataBlockSize, 1, rfile);
fclose(rfile);
}
void showRecordsingle(record *record, int cnt)//单条显示
{
char bookname[100];
book *book = findBookbyId(record->bookID);
strcpy(bookname, book ->name);
char tem = bookname[showlen];
bookname[showlen] = '\0';
printf("%-14d%-18s%-18s%-35s%-18d%-25s\n", cnt, record->userName, record->method ? " 还" : "借 ", bookname, book->id, record->time);
bookname[showlen] = tem;
}
void showRecordsList(record *thehead, int searchNum, bool isTheMianLine) //以链的方式显示列表
{
record* pre = thehead->next; //pre为驱动指针
int pageNow = 1; //当前页数
stack<record *> pagestack;//用于存放页数的栈,准确的说是每页的第一条的指针
pagestack.push(pre );
while(1)
{
int i = itemInPage, pagesNum = ceil(1.0 * searchNum / itemInPage); //item计数器
record* pagefirtItem = pagestack.top(); //当前页第一个条目
pre = pagefirtItem;
system("cls");
printf("==========================================================================================================================================================================\n");
printf(" 图书管理系统-借书记录(总览) \n");
printf("==========================================================================================================================================================================\n\n");
printf("共%d 条记录\n\n", searchNum);
printf("%-14s%-18s%-18s%-35s%-18s%-25s\n\n", "序号", "用户", "借/还", "书名", "书ID", "时间");
while(pre && --i >= 0)
{
showRecordsingle(pre, pre->id);
pre = pre->next;
}
//==============================翻页菜单
if(i > 0)
while(i-- ) // |
printf("\n");//控制菜单位置
printf("\n");
printf("[1]上一页 [2]下一页 [3]跳转 [4]书本详细信息 [0]退出 第 %d / %.0f 页\n", pageNow, ceil(1.0 * searchNum / itemInPage));
int cmd;
scanf("%d", &cmd);
if(cmd == 1)
{
if(pagestack.top() == thehead->next) //用该页的第一项是否是除首节点的第一个节点判断是否已经是第一页
continue;
pagestack.pop();//翻页
pageNow--;
continue;
}
if(cmd == 2)
{
if(pre == NULL ) //判断是否是最后一页
continue;
pagestack.push(pre);//翻页
pageNow++;
continue;
}
if(cmd == 3) //跳页
{
printf("跳转到(1-%d):\n", pagesNum);
int goalPage;
scanf("%d", &goalPage);
if(goalPage <= 0 || goalPage > pagesNum)
{
printf("输入错误,回车继续\n");
getchar();
getchar();
continue;
}
else
{
if(goalPage > pageNow)
{
pre = pagefirtItem;
for(int j = pageNow; j < goalPage; j++)
{
i = itemInPage;
while(--i >= 0)
{
pre = pre->next;
}
pagestack.push(pre);
pageNow++;
}
continue;
}
else if(goalPage < pageNow)
{
for(int j = pageNow; j > goalPage; j--)
{
pageNow--;
pagestack.pop();
pre = pagestack.top();
}
continue;
}
else
continue;
}
//================翻页菜单结束
}
if(cmd == 4)
{
int id;
printf("输入要查看的书本 ID :\n");
scanf("%d", &id);
book *t = findBookbyId(id);
if(t != NULL)
{
showBookdetail(t);
}
else
{
printf("查询失败,回车继续\n");
getchar();
}
}
if(cmd == 0)
{
//if(!isTheMianLine)
//freenode_Book(thehead);
adminMenu();
}
}
}
void rewriteAll_RecordData()//将链表中所有数据重写入文件
{
FILE *rfile = fopen(recordfile, "wb+");
record* pre = the_RecordLine_Head->next; //从尾节点开始,为了下次初始化时,最新添加的书在最上面
while(pre)
{
fwrite(pre, recordDataBlockSize, 1, rfile);
pre = pre->next;
}
fclose(rfile);
}