Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrarysystem.cpp
More file actions
4557 lines (4329 loc) · 171 KB
/
Copy pathlibrarysystem.cpp
File metadata and controls
4557 lines (4329 loc) · 171 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
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "librarysystem.h"
#include "ui_librarysystem.h"
#include<QMessageBox>
#include <QTextStream>
#include <QTableWidgetItem>
#include <sstream>
#include <QTableView>
#include <QScrollBar>
using namespace std;
int allbook;
int allcard;
int alladmin;
int dmend;
static int nCurScroller=0; //翻页时的当时滑动条位置
static int pageValue = 7; // 一页显示条数
int tcflag=1; //用于表示找回密码的时候是用户还是管理员
QRegExp hanzi("[\u4e00-\u9fa5]{1,3}");
QRegExp passwordstype("[A-Za-z0-9]{6,16}");
QRegExp sfztype("^([0-9]{17}[x0-9]{1})$");
QRegExp phonetype("[0-9]{11}");
QRegExp shuming("[A-Za-z0-9\u4e00-\u9fa5]{1,30}");
QRegExp zuozhe("[A-Za-z0-9\u4e00-\u9fa5]{1,15}");
QRegExp isbntype("[A-Za-z0-9]{1,16}");
QRegExp shudekucun("[1-9]|1[0-9]|20");
QRegExp bookid("^[1-9]{1}[0-9]{8}$");
LibrarySystem::LibrarySystem(QWidget *parent) :
QWidget(parent),
ui(new Ui::LibrarySystem)
{
//setFixedSize(1200, 700);
update_Order();
dmend=0;
FILE *fp1;
if ((fp1 = fopen("ALLNUM", "rb")) == NULL)
{
fprintf(stderr, "Can not open file allnum");
exit(1);
}
fread(&allcard, sizeof(int), 1, fp1);
fread(&allbook, sizeof(int), 1, fp1);
fread(&alladmin, sizeof(int), 1, fp1);
fclose(fp1);
ui->setupUi(this);
//ui->mainwidget->setCurrentIndex(0);
this->UIDesign();
//对于预约信息表只能选中一行的限定
ui->orderInfotable->setSelectionBehavior ( QAbstractItemView::SelectRows); //设置选择行为,以行为单位
ui->orderInfotable->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式,选择单行
ui->orderInfotable->setEditTriggers(QAbstractItemView::NoEditTriggers); //设置每行不可编辑
//对于借阅信息表只能选中一行的限定
ui->lendInfotable->setSelectionBehavior ( QAbstractItemView::SelectRows); //设置选择行为,以行为单位
ui->lendInfotable->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式,选择单行
ui->lendInfotable->setEditTriggers(QAbstractItemView::NoEditTriggers); //设置每行不可编辑
//对于日志信息表的限定
ui->logtable->setSelectionBehavior ( QAbstractItemView::SelectRows); //设置选择行为,以行为单位
ui->logtable->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式,选择单行
ui->logtable->setEditTriggers(QAbstractItemView::NoEditTriggers); //设置每行不可编辑
//对于查询结果表只能选中一行的限定
ui->searchresult->setSelectionBehavior ( QAbstractItemView::SelectRows); //设置选择行为,以行为单位
ui->searchresult->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式,选择单行
ui->searchresult->setEditTriggers(QAbstractItemView::NoEditTriggers); //设置每行不可编辑
//ui->searchresult->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch);
//ui->searchresult->horizontalHeader()->setSectionResizeMode(3,QHeaderView::Stretch);
ui->mainwidget->setCurrentIndex(0);
ui->userpassword->setEchoMode(QLineEdit::Password);
//QRegExp regExp("0|[1-9]\\d{0,4}");
//ui->useraccount->setValidator(new QRegExpValidator(regExp, this));
//QRegExp hanzi("[\u4e00-\u9fa5]{1,3}");
//ui->usernameget->setValidator(new QRegExpValidator(hanzi, this));
//ui->searchresult->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); //x先自适应宽度
ui->searchresult->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->searchresult->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents); //然后设置要根据内容使用宽度的列
ui->searchresult->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents); //然后设置要根据内容使用宽度的列
ui->searchresult->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents); //然后设置要根据内容使用宽度的列
ui->searchresult->horizontalHeader()->setSectionResizeMode(4, QHeaderView::Stretch);
ui->searchresult->horizontalHeader()->setSectionResizeMode(5, QHeaderView::Stretch);
ui->searchresult->setShowGrid(false);//设置不显示格子线
ui->searchresult->setFrameShape(QFrame::NoFrame);//设置无边框
ui->searchresult->setFocusPolicy(Qt::NoFocus);//设置无选择虚线
ui->searchresult->verticalHeader()->setVisible(false);//设置垂直头不可见
ui->searchresult->horizontalHeader()->setVisible(false);//设置水平表头不可见
ui->searchresult->horizontalHeader();
//QTableWidgetItem *SHearder = ui->searchresult->horizontalHeaderItem(1);
//SHearder->setBackgroundColor(QColor(221, 231, 242));
ui->orderInfotable->setFrameShape(QFrame::NoFrame);//设置无边框
ui->orderInfotable->setFocusPolicy(Qt::NoFocus);//设置无选择虚线
ui->lendInfotable->setShowGrid(false);//设置不显示格子线
ui->lendInfotable->setFrameShape(QFrame::NoFrame);//设置无边框
ui->lendInfotable->setFocusPolicy(Qt::NoFocus);//设置无选择虚线
ui->logtable->setShowGrid(false);//设置不显示格子线
ui->logtable->setFrameShape(QFrame::NoFrame);//设置无边框
ui->logtable->setFocusPolicy(Qt::NoFocus);//设置无选择虚线
}
LibrarySystem::~LibrarySystem()
{
delete ui;
}
bool comp_1(const so_1 &x, const so_1 &y)
{
return x.a < y.a;
}
bool comp_2(const so_2 &x, const so_2 &y)
{
return x.a > y.a;
}
int isLeapYear(int year) //判断是否是闰年,返回1为闰年,返回0不是闰年
{
if (year % 4 == 0 && year % 100 != 0)return 1;
if (year % 400 == 0)return 1;
return 0;
}
int getDayInYear(int year, int month, int day) //得到该日期是一年的第几天
{
int months[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (isLeapYear(year))months[1] = 29;
for (int i = 0; i<month - 1; i++)
{
day = day + months[i];
}
return day;
}
int compareDate(int year1, int month1, int day1, int year2, int month2, int day2) //日期比较,日期1year1month1day1-日期2year2month2day2,
{
int days = 0;
//不需要判断日期数字是否合理,系统日期不会出现32天的情况
if (year1 == year2) //年份相等
{
if (month1 == month2)days = day1 - day2;//月份相等
else days = getDayInYear(year1, month1, day1) - getDayInYear(year2, month2, day2);//月份不等
}
else //年份不同,则日期差值为日期1的在year1的第几天+日期2在year2还剩下的天数+year1和year2两年之间的天数差值
{
//确保year1年份比year2晚
if (year1 > year2)
{
if (isLeapYear(year2))
days = 366 - getDayInYear(year2, month2, day2); //取得日期2在该年还剩下多少天
else
days = 365 - getDayInYear(year2, month2, day2);
days += getDayInYear(year1, month1, day1); //取得日期1在当年中的第几天
for (int year = year2 + 1; year < year1; year++)//取得year1和year2之间的天数差值
{
if (isLeapYear(year))
days += 366;
else
days += 365;
}
}
else days = -compareDate(year2, month2, day2, year1, month1, day1); //date1小于date2的情况
}
// if(days<0)exit(0);//出错则退出程序
return days;
}
Book::Book(char BookID[10], char BookName[100], char Author[50], char Publisher[50],char BOOKISBN[20], short Storage)//构造函数
{
for (int i = 0; i<10; i++)
{
bookID[i] = BookID[i];
}
for (int i = 0; i<100; i++)
{
bookName[i] = BookName[i];
}
for (int i = 0; i<50; i++)
{
author[i] = Author[i];
}
for (int i = 0; i<50; i++)
{
publisher[i] = Publisher[i];
}
for (int i = 0; i < 20 ; i++ )
{
bookisbn[i] = BOOKISBN[i];
}
memset(books, '3', sizeof(books));//把books全部初始化为3
books[20] = '\0';
if(Storage < 21)
{
storage = Storage;//初始库存为10本
for(int i = 0; i < Storage; i++)
{
books[i] = '1'; //把前storage本书置为1 表示可借
}
}
bookMan = 0;//初始预约人数为0
tStorage = 0;//初始预约该书的人数为0
flag = '1'; //所有标记 0表示不存在 1表示存在//此处,1表示书可借
//books[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
//books = (int*)malloc(storage*sizeof(int)); //分配给该类书对应库存量的空间大小 在管理员修改库存的时候应该重新分配内存
}
Book::Book()
{
for (int i = 0; i<10; i++)
{
bookID[i] = ' ';
}
for (int i = 0; i<100; i++)
{
bookName[i] = ' ';
}
for (int i = 0; i<50; i++)
{
author[i] = ' ';
}
for (int i = 0; i<50; i++)
{
publisher[i] = ' ';
}
for (int i = 0; i < 20 ; i++ )
{
bookisbn[i] = ' ';
}
memset(books, '3', sizeof(books));//把books全部初始化为3
books[20] = '\0';
storage = 0;//初始库存为10本
bookMan = 0;//初始预约人数为0
tStorage = 0;//初始预约该书的人数为0
flag = '1'; //所有标记 0表示不存在 1表示存在//此处,1表示书可借
}
Book::Book(Book &book) //复制构造函数
{
for (int i = 0; i<10; i++)
{
bookID[i] = book.bookID[i];
}
for (int i = 0; i<100; i++)
{
bookName[i] = book.bookName[i];
}
for (int i = 0; i<50; i++)
{
author[i] = book.author[i];
}
for (int i = 0; i<50; i++)
{
publisher[i] = book.publisher[i];
}
for (int i = 0; i < 20 ; i++ )
{
bookisbn[i] = book.bookisbn[i];
}
storage = book.storage;
bookMan = book.bookMan;
tStorage = book.tStorage;
flag = book.flag;
for (int i = 0; i < 21; i++)
{
books[i] = book.books[i];
}
}
char* Book::getbookID()
{
return bookID;
}
void Book::setbookID(char newbookID[10])
{
for (int i = 0; i<10; i++)
{
bookID[i] = newbookID[i];
}
}
char* Book::getbookName()
{
return bookName;
}
void Book::setbookName(char newbookName[100])
{
for (int i = 0; i<50; i++)
{
bookName[i] = newbookName[i];
}
}
char* Book::getauthor()
{
return author;
}
void Book::setauthor(char newauthor[50])
{
for (int i = 0; i<50; i++)
{
author[i] = newauthor[i];
}
}
char* Book::getpublisher()
{
return publisher;
}
void Book::setpublisher(char newpublisher[50])
{
for (int i = 0; i<50; i++)
{
publisher[i] = newpublisher[i];
}
}
char* Book::getbookisbn()
{
return bookisbn;
}
void Book::setbookisbn(char BOOKISBN[20])
{
for(int i=0;i < 20; i++)
{
bookisbn[i]=BOOKISBN[i];
}
}
short Book::getstorage()
{
return storage;
}
void Book::setstorage(short newstorage)
{
storage = newstorage;
}
int Book::addstorage(short newstorage)
{
int i=0;
while(books[i] != '3') i++; //i为目前的库存
if(i + newstorage < 20) //如果增加库存后超过20 提示越界 拒绝修改
{
storage += newstorage; //新库存
while(newstorage != 0)
{
books[i + newstorage - 1] = '1';
newstorage--;
}
return 1;
}
else return 0;
}
short Book::getbookMan()
{
return bookMan;
}
void Book::setbookMan(short newbookMan)
{
bookMan = newbookMan;
}
short Book::gettStorage()
{
return tStorage;
}
void Book::settStorage(short newStorage)
{
tStorage = newStorage;
}
char Book::getflag()
{
return flag;
}
void Book::setflag(char newflag)
{
flag = newflag;
}
char* Book::getBooks()
{
return books;
}
//11.10 新增修改Books[i]的函数
void Book::setBooksI(int i, char newbooksi) //i表示第i本书,newbooksi表示新的Books[i]的值
{
books[i] = newbooksi;
}
Card::Card(char CardID[10], char CPassword[20], char CardHolder[10], double Balance, char CID[19], char CPhone[12]) //构造函数
{
for (int i = 0; i<10; i++)
{
cardID[i] = CardID[i];
}
for (int i = 0; i<20; i++)
{
cPassword[i] = CPassword[i];
}
for (int i = 0; i<10; i++)
{
cardHolder[i] = CardHolder[i];
}
lendedCount = 0;//初始已借本数为0
lendingCount = 10;//初始可借本数为10
cardState = '1';//1表示未冻结
balance = Balance;
oweMoney = 0;
bookedCount = 0;//初始预约本数为0
for (int i = 0; i<19; i++)
{
cID[i] = CID[i];
}
for (int i = 0; i<12; i++)
{
cPhone[i] = CPhone[i];
}
}
Card::Card(Card &card) //复制构造函数
{
for (int i = 0; i<10; i++)
{
cardID[i] = card.cardID[i];
}
for (int i = 0; i<20; i++)
{
cPassword[i] = card.cPassword[i];
}
lendedCount = card.lendedCount;
lendingCount = card.lendingCount;
for (int i = 0; i<10; i++)
{
cardHolder[i] = card.cardHolder[i];
}
cardState = card.cardState;
balance = card.balance;
oweMoney = card.oweMoney;
bookedCount = card.bookedCount;
for (int i = 0; i<19; i++)
{
cID[i] = card.cID[i];
}
for (int i = 0; i<12; i++)
{
cPhone[i] = card.cPhone[i];
}
}
Card::Card()
{
int i = 0;
for (i = 0; i<10; i++)
{
cardID[i] = ' ';
}
for (i = 0; i<20; i++)
{
cPassword[i] = ' ';
}
for (i = 0; i<10; i++)
{
cardHolder[i] = ' ';
}
balance = 0;
for (i = 0; i<19; i++)
{
cID[i] = ' ';
}
for (i = 0; i<12; i++)
{
cPhone[i] = ' ';
}
lendedCount = 0;//初始已借本数为0
lendingCount = 10;//初始可借本数为10
cardState = '1';//1表示未冻结
oweMoney = 0;
bookedCount = 0;//初始预约本数为0
}
char* Card::getcardID()
{
return cardID;
}
void Card::setcardID(char newcardID[10])
{
for (int i = 0; i<10; i++)
{
cardID[i] = newcardID[i];
}
}
char* Card::getcPassword()
{
return cPassword;
}
void Card::setcPassword(char newcPassword[20])
{
for (int i = 0; i<20; i++)
{
cPassword[i] = newcPassword[i];
}
}
short Card::getlendedCount()
{
return lendedCount;
}
void Card::setlendedCount(short newlendedCount)
{
lendedCount = newlendedCount;
}
short Card::getlendingCount()
{
return lendingCount;
}
void Card::setlendingCount(short newlendingCount)
{
lendingCount = newlendingCount;
}
char* Card::getcardHolder()
{
return cardHolder;
}
void Card::setcardHolder(char newcardHolder[10])
{
for (int i = 0; i<10; i++)
{
cardHolder[i] = newcardHolder[i];
}
}
char Card::getcardState()
{
return cardState;
}
void Card::setcardState(char newcardState)
{
cardState = newcardState;
}
double Card::getbalance()
{
return balance;
}
void Card::setbalance(double newbalance)
{
balance = newbalance;
}
double Card::getoweMoney()
{
return oweMoney;
}
void Card::setoweMoney(double newoweMoney)
{
oweMoney = newoweMoney;
}
short Card::getbookedCount()
{
return bookedCount;
}
void Card::setbookedCount(short newbookedCount)
{
bookedCount = newbookedCount;
}
char* Card::getcID()
{
return cID;
}
void Card::setcID(char newcID[19])
{
for (int i = 0; i<19; i++)
{
cID[i] = newcID[i];
}
}
char* Card::getcPhone()
{
return cPhone;
}
void Card::setcPhone(char newcPhone[12])
{
for (int i = 0; i<12; i++)
{
cPhone[i] = newcPhone[i];
}
}
Administrator::Administrator(char Account[5], char APassword[20], char AccountHolder[10], char AID[19], char APhone[12])//构造函数
{
for (int i = 0; i<5; i++)
{
account[i] = Account[i];
}
for (int i = 0; i<20; i++)
{
aPassword[i] = APassword[i];
}
for (int i = 0; i<10; i++)
{
accountHolder[i] = AccountHolder[i];
}
for (int i = 0; i<19; i++)
{
aID[i] = AID[i];
}
for (int i = 0; i < 12; i++)
{
aPhone[i] = APhone[i];
}
aID[18]='\0';
aPhone[11]='\0';
}
Administrator::Administrator()
{
for (int i = 0; i<5; i++)
{
account[i] = ' ';
}
for (int i = 0; i<20; i++)
{
aPassword[i] = ' ';
}
for (int i = 0; i<10; i++)
{
accountHolder[i] = ' ';
}
for (int i = 0; i<19; i++)
{
aID[i] = ' ';
}
for (int i = 0; i<12; i++)
{
aPhone[i] = ' ';
}
aID[18]='\0';
aPhone[11]='\0';
}
//复制构造函数
Administrator::Administrator(Administrator &administrator)
{
for (int i = 0; i<5; i++)
{
account[i] = administrator.account[i];
}
for (int i = 0; i<20; i++)
{
aPassword[i] = administrator.aPassword[i];
}
for (int i = 0; i<10; i++)
{
accountHolder[i] = administrator.accountHolder[i];
}
for (int i = 0; i<19; i++)
{
aID[i] = administrator.aID[i];
}
for (int i = 0; i<12; i++)
{
aPhone[i] = administrator.aPhone[i];
}
}
void Administrator::setaccount(char newaccount[5])
{
for (int i = 0; i<5; i++)
{
account[i] = newaccount[i];
}
}
void Administrator::setaPassword(char newaPassword[20])
{
for (int i = 0; i<20; i++)
{
aPassword[i] = newaPassword[i];
}
}
void Administrator::setaccountHolder(char newaccountHolder[10])
{
for (int i = 0; i<10; i++)
{
accountHolder[i] = newaccountHolder[i];
}
}
void Administrator::setaID(char newaID[19])
{
for (int i = 0; i<19; i++)
{
aID[i] = newaID[i];
}
}
void Administrator::setaPhone(char newaaPhone[12])
{
for (int i = 0; i<12; i++)
{
aPhone[i] = newaaPhone[i];
}
}
char* Administrator::getaccount()
{
return account;
}
char* Administrator::getaPassword()
{
return aPassword;
}
char* Administrator::getaccountHolder()
{
return accountHolder;
}
char* Administrator::getaID()
{
return aID;
}
char* Administrator::getaPhone()
{
return aPhone;
}
int Administrator::addadmin(char*aPassword, char*accountHolder, char*aID, char*aPhone)
{
std::string account_str = std::to_string(2000 + alladmin + 1);
char account[5];
strcpy(account,account_str.c_str());
int i = 0;
Administrator newadministrator(account, aPassword, accountHolder, aID, aPhone);
Administrator temp;
FILE*fp_admin;
if (NULL == (fp_admin = fopen("ADMININFORMATION", "rb+")))
{
fprintf(stderr, "Can not open file");
exit(1);
}
while(i < alladmin)
{
fseek(fp_admin, i*sizeof(Administrator), SEEK_SET);
fread(&temp, sizeof(Administrator), 1, fp_admin);
if(strcmp(newadministrator.getaID(),temp.getaID()) == 0)return 0;
i++;
}
fseek(fp_admin, 0, SEEK_END);
if (fwrite(&newadministrator, sizeof(Administrator), 1, fp_admin) != 1)
printf("file write error\n");
time_t timer;
time(&timer);
tm* t_tm = localtime(&timer); //获取了当前时间,并且转换为int类型的year,month,day
int year = t_tm->tm_year + 1900;
int month = t_tm->tm_mon + 1;
int day = t_tm->tm_mday;
Record record(newadministrator.getaccount(), year, month, day, 'l');
record.signUpRecord();
fclose(fp_admin);
alladmin++;
FILE *fp_num;
if (NULL == (fp_num = fopen("ALLNUM", "rb+")))
{
fprintf(stderr, "Can not open file");
exit(1);
}
if (fwrite(&allcard, sizeof(int), 1, fp_num) != 1) //覆盖写入?
printf("file write error\n");
if (fwrite(&allbook, sizeof(int), 1, fp_num) != 1)
printf("file write error\n");
if (fwrite(&alladmin, sizeof(int), 1, fp_num) != 1)
printf("file write error\n");
fclose(fp_num);
return 1;
}
//管理员查看大日志
void Administrator::searchLog()
{
FILE *fp_log;
if (NULL == (fp_log = fopen("LOG", "rb+")))
{
fprintf(stderr, "Can not open file");
exit(1);
}
}
//11.2管理员新加书函数
int Administrator::addBook(Book book)
{
FILE *fp_add_book;
FILE *fp_book;
Book temp;
int i = 0;
if (NULL == (fp_add_book = fopen("ADMININ_ADD_BOOK", "rb+")))
{
fprintf(stderr, "Can not open admin_add_book");
exit(1);
}
if (NULL == (fp_book = fopen("BOOKINFORMATION", "rb+")))
{
fprintf(stderr, "Can not open bookinformation");
exit(1);
}
while(i < allbook)
{
fseek(fp_book, i*sizeof(Book), SEEK_SET);
fread(&temp, sizeof(Book), 1, fp_book);
if(strcmp(temp.getbookisbn(), book.getbookisbn()) == 0)return 0;
i++;
}
fseek(fp_add_book, 0, SEEK_END);
fseek(fp_book, 0, SEEK_END);
fwrite(&book, sizeof(Book), 1, fp_book);
allbook++;
time_t timer;
time(&timer);
tm* t_tm = localtime(&timer); //获取了当前时间,并且转换为int类型的year,month,day
int year = t_tm->tm_year + 1900;
int month = t_tm->tm_mon + 1;
int day = t_tm->tm_mday;
Record record(book.getbookID(), this->getaccount(), year, month, day, 'j', '0'); //这个this是可以用的,因为调用的时候指向的也是一个具体的Administrator对象
record.admininaddbook();
fclose(fp_add_book);
fclose(fp_book);
FILE *fp_num;
if (NULL == (fp_num = fopen("ALLNUM", "rb+")))
{
fprintf(stderr, "Can not open file");
exit(1);
}
if (fwrite(&allcard, sizeof(int), 1, fp_num) != 1) //覆盖写入?
printf("file write error\n");
if (fwrite(&allbook, sizeof(int), 1, fp_num) != 1)
printf("file write error\n");
if (fwrite(&alladmin, sizeof(int), 1, fp_num) != 1)
printf("file write error\n");
fclose(fp_num);
return 1;
}
int Administrator::newStorage(char* bookid,short addstor) //addstor是要增加的库存数目
{
//修改库存时输入的值应该改成增加的量或者减少的量,不能直接输入最终的库存量
time_t timer;
time(&timer);
tm* t_tm = localtime(&timer); //获取了当前时间,并且转换为int类型的year,month,day
int year = t_tm->tm_year + 1900;
int month = t_tm->tm_mon + 1;
int day = t_tm->tm_mday;
Book book;
FILE *fp_book;
if (NULL == (fp_book = fopen("BOOKINFORMATION", "rb+")))
{
fprintf(stderr, "Can not open file");
exit(1);
}
int position = atoi(bookid) - 100000000 - 1;//书籍位置
if(position > (allbook - 1) || position < 0)return 2;
fseek(fp_book, position * sizeof(Book), SEEK_SET);//定位到这本书
fread(&book, sizeof(Book), 1, fp_book);///取出这本书
if(book.addstorage(addstor) == 0) {fclose(fp_book);return 0;}//增加这本书的库存 addstor是要增加的数目
Record record(book.getbookID(), this->getaccount(), year, month, day, 'k', '0');//写入记录 //这个this也是可以用的,理由同上
record.admininchangestorage();
fseek(fp_book, position * sizeof(Book), SEEK_SET);//重新定位
if (fwrite(&book, sizeof(Book), 1, fp_book) != 1)//把修改完的book写回文件
printf("file write error\n");
fclose(fp_book);
return 1;
}
Record::Record(char*bookid1, char*cardid1, int Year, int Month, int Day, char flag11, char flag22)
{
for (int i = 0; i < 10; i++)
{
bookid[i] = bookid1[i];
}
for (int i = 0; i < 10; i++)
{
cardid[i] = cardid1[i];
}
year = Year;
month = Month;
day = Day;
flag1 = flag11;
flag2 = flag22;
order=0;
//获取当前系统日期 自行查询方法 读入当前year month day
}
Record::Record(char*cardid1, int Year, int Month, int Day, int flag11)
{
for (int i = 0; i < 10; i++)
{
bookid[i] = ' ';
}
for (int i = 0; i < 10; i++)
{
cardid[i] = cardid1[i];
}
year = Year;
month = Month;
day = Day;
flag1 = flag11;
order=0;
}
//刘峰同学需要的构造函数啦啦~~
Record::Record(char*bookid1, char*cardid1, int Year, int Month, int Day, char flag11, char flag22, int Order)
{
for (int i = 0; i < 10; i++)
{
bookid[i] = bookid1[i];
}
for (int i = 0; i < 10; i++)
{
cardid[i] = cardid1[i];
}
year = Year;
month = Month;
day = Day;
flag1 = flag11;
flag2 = flag22;
order = Order;
}
//默认构造函数
Record::Record()
{
for (int i = 0; i < 10; i++)
{
bookid[i] = ' ';
}
for (int i = 0; i < 10; i++)
{
cardid[i] = ' ';
}
year = 0;
month = 0;
day = 0;
flag2 = 1;//用于缓冲区 1对预约记录表示此预约失效并且已经写入记录文件 1对续借记录表示该书已续借
order = 1;
flag1 = 'a'; //所有标记 0表示不存在 1表示存在//此处,1表示书可借
}
//复制构造函数
Record::Record(Record &R)
{
for (int i = 0; i<10; i++)
{
bookid[i] = R.bookid[i];
}
for (int i = 0; i<10; i++)
{
cardid[i] = R.cardid[i];
}
year = R.year;
month = R.month;
day = R.day;
flag2 = R.flag2;//用于缓冲区 1对预约记录表示此预约失效并且已经写入记录文件 1对续借记录表示该书已续借
order = R.order;
flag1 = R.flag1;
}
char Record::getflag1()
{
return flag1;
}
void Record::setflag1(char newflag1)
{
flag1 = newflag1;
}
int Record::getyear()
{
return year;
}
void Record::setyear(int newyear)
{
year = newyear;
}
int Record::getmonth()
{
return month;
}
void Record::setmonth(int newmonth)
{
month = newmonth;
}
int Record::getday()
{
return day;
}
void Record::setday(int newday)
{
You can’t perform that action at this time.
