📄 person.c
字号:
/***********************下翻页键**********************************/
void keypersonpgdown(struct personnode* personhead,struct dnode* bookhead)
{
if(personwintopy>=allpersonnode-19) return;/*如果这是最后一页,就不用翻页了*/
personwintopy+=19;
if(personwintopy>=allpersonnode-19)
{personwintopy=allpersonnode-19;
personwiny=allpersonnode;
}
else personwiny+=19;
ShowPersonWinaScreen(personhead,bookhead,personwintopy);
}
/****人员信息窗口(主窗口)*****/
void borrowerinfoWin(struct personnode* head,struct dnode* bookhead)
{
int key,i,j;
struct text_info ti;
char block[4*25*80];/*保存整个屏幕(把主窗口给保存起来)*/
struct commonstr* helpinformation;
/* personwiny=1; personwintopx=1; personwintopy=1; personwinx=1;*/
light_mouse(OFF);
gettextinfo(&ti);
gettext(1,1,80,25,&block);
window(1,1,80,25);
textbackground(LIGHTGRAY);
textcolor(BLACK);
clrscr();
gotoxy(1,1);
cprintf(" 图书借阅管理程序 ");
gotoxy(67,1);
textbackground(MAGENTA);
textcolor(LIGHTGREEN);
cprintf("上翻页");
gotoxy(74,1);
cprintf("下翻页");
window(1,2,80,25);
textbackground(BLUE);
textcolor(YELLOW);
clrscr();
textcolor(BLACK);
clrscr();
putch(218);
for(i=1;i<79;i++) putch(196);
for(i=1;i<22;i++)
{gotoxy(1,i+1);
putch(179);
}
gotoxy(1,23);
putch(192);
textcolor(LIGHTBLUE);
gotoxy(80,1);
putch(191);
for(i=1;i<22;i++)
{gotoxy(80,i+1);
putch(179);
}
gotoxy(2,23);
for(i=1;i<79;i++) putch(196);
putch(217);
textcolor(LIGHTGREEN);
gotoxy(30,1);
cprintf(" 人员信息管理器 \r\n");
window(1,25,80,25);
highvideo();
textcolor(BLACK); /*提示栏信息*/
textbackground(LIGHTGRAY);
clrscr();
cprintf(" F1-帮助 F2-密码 F4-查询 F5-切换屏幕 F8-借书 F9-还书 Ins-插入 ");
textcolor(LIGHTRED);
textbackground(BLACK);
cprintf("%c %c %c",175,175,175);
window(2,3,79,23);
textbackground(BLUE);
textcolor(WHITE);
clrscr();
cprintf("借阅号码 姓名 借书日期 超期 %c 书名",179);
window(2,4,79,23);
textcolor(YELLOW);
clrscr();
light_mouse(ON);
allpersonnode=LengthofPersonList(head);
ShowPersonWinaScreen(head,bookhead,personwintopy);
gotoxy(personwinx-personwintopx+1,personwiny-personwintopy+1);
do{
key=get_key();
if(bookhead->book.data!=0) /*如果以管理员的身份登陆则执行下面的着一部分*/
{
switch(key){
case ESC:
case F5:
case C_X: goto back10; /*退出*/
case INSERT: InputPersonNode(head);
ShowPersonWinaScreen(head,bookhead,personwintopy);
break;
case DELETE: DeletePersonWin(head,bookhead);
ShowPersonWinaScreen(head,bookhead,personwintopy);
break;
case C_S:
case END: ShowPersonWinaScreen(head,bookhead,1);
personwiny=1; personwintopx=1; personwintopy=1; personwinx=1;
break;/*刷新*/
case HOME:MessageBox(15,10,curpath);break; /*显示当前工作目录**/
case PGUP: keypersonpgup(head,bookhead);break;
case PGDOWN: keypersonpgdown(head,bookhead);break;
case LEFT: keypersonleft();break;
case RIGHT: keypersonright();break;
case UP: keypersonup(head,bookhead);break;
case DOWN: keypersondown(head,bookhead);break;
case F7: ChangeBorrowCount(bookhead,head);break;
case F6: ChangeDays(bookhead);break;/*修改最多借书期限(此期限存在bookhead指针的booknum中*/
case F8: StartBorrowBook(head,bookhead);
ShowPersonWinaScreen(head,bookhead,personwintopy);
break;/*借书*/
case F9: ReturnBookWin(head,bookhead);
ShowPersonWinaScreen(head,bookhead,personwintopy);
break;/*还书*/
case F2: ChangePassWin(bookhead); break; /*修改密码*/
case F4 :
case C_F: FindWindow(bookhead,head);break; /*查找*/
case F1: helpinformation=HelpInfo();CommonWin(helpinformation);
ClearCommonList(helpinformation);
break;
case LEFT_BUTTON:/*sprintf(errormess,"鼠标坐标%d,%d",mx/8,my/8);
MessageBox(20,10,errormess);
*/
if((mx/8>=0&&mx/8<=8)&&(my/8==24)||(mx/8<=60)&&(my/8==0)) /*帮助*/
{
helpinformation=HelpInfo();
CommonWin(helpinformation);
ClearCommonList(helpinformation);
}
else if((mx/8>=10&&mx/8<=17)&&(my/8==24)) /*密码*/
ChangePassWin(bookhead);
else if((mx/8>=19&&mx/8<=26)&&(my/8==24))/*查找*/
FindWindow(bookhead,head);
else if((mx/8>=28&&mx/8<=39)&&(my/8==24))/*屏幕切换*/
goto back10;
else if((mx/8>=41&&mx/8<=47)&&(my/8==24))/*借书*/
{StartBorrowBook(head,bookhead);
ShowPersonWinaScreen(head,bookhead,personwintopy);
}
else if((mx/8>=49&&mx/8<=56)&&(my/8==24))/*还书*/
{ReturnBookWin(head,bookhead);
ShowPersonWinaScreen(head,bookhead,personwintopy);
}
else if((mx/8>=58&&mx/8<=68)&&(my/8==24))/*插入*/
{InputPersonNode(head);
ShowPersonWinaScreen(head,bookhead,personwintopy);
}
else if((mx/8>=66&&mx/8<=71)&&my/8==0) /*上翻页*/
keypersonpgup(head,bookhead);
else if((mx/8>=73&&mx/8<=78)&&my/8==0) /*下翻页*/
keypersonpgdown(head,bookhead);
else if((mx/8>=73&&mx/8<=78)&&my/8==24)/*多功能*/
{/*window(68,19,80,24);
textcolor(BLACK);
textbackground(BROWN);
clrscr();
cprintf("\r\n Ins-插入\r\n Del-删除 \r\n F10-期限\r\n F11-数量");
*/
MessageBox(20,10,"提示:此功能暂未实现");
}
break;
default:break;
}
}
else /*如果以guest的身份登陆则执行下面的着一部分*/
{
switch(key){
case INSERT:
case DELETE:
case F12:
case F11:
case F8:
case F9:MessageBox(20,10,"警告:你没有使用此功能的权限!");break;
case PGUP: keypersonpgup(head,bookhead);break;
case PGDOWN: keypersonpgdown(head,bookhead);break;
case LEFT: keypersonleft();break;
case RIGHT: keypersonright();break;
case UP: keypersonup(head,bookhead);break;
case DOWN: keypersondown(head,bookhead);break;
case END: ShowPersonWinaScreen(head,bookhead,1);
personwiny=1; personwintopx=1; personwintopy=1; personwinx=1;
break;/*刷新*/
case HOME:MessageBox(15,10,curpath);break; /*显示当前工作目录**/
case ESC:
case F5:
case C_X:goto back10;
case C_F:
case F4: FindWindow(bookhead,head);break;
case F1: helpinformation=HelpInfo();CommonWin(helpinformation);
ClearCommonList(helpinformation);
break;
case LEFT_BUTTON:
if((mx/8>=0&&mx/8<=8)&&(my/8==24)||(mx/8<=60)&&(my/8==0)) /*帮助*/
{
helpinformation=HelpInfo();
CommonWin(helpinformation);
ClearCommonList(helpinformation);
}
else if((mx/8>=10&&mx/8<=17)&&(my/8==24)) /*密码*/
MessageBox(20,10,"警告:你没有使用此功能的权限!");
else if((mx/8>=19&&mx/8<=26)&&(my/8==24))/*查找*/
FindWindow(bookhead,head);
else if((mx/8>=28&&mx/8<=39)&&(my/8==24))/*屏幕切换*/
goto back10;
else if((mx/8>=41&&mx/8<=47)&&(my/8==24))/*借书*/
MessageBox(20,10,"警告:你没有使用此功能的权限!");
else if((mx/8>=49&&mx/8<=56)&&(my/8==24))/*还书*/
MessageBox(20,10,"警告:你没有使用此功能的权限!");
else if((mx/8>=58&&mx/8<=68)&&(my/8==24))/*插入*/
MessageBox(20,10,"警告:你没有使用此功能的权限!");
else if((mx/8>=66&&mx/8<=71)&&my/8==0) /*上翻页*/
keypersonpgup(head,bookhead);
else if((mx/8>=73&&mx/8<=78)&&my/8==0) /*下翻页*/
keypersonpgdown(head,bookhead);
else if((mx/8>=73&&mx/8<=78)&&my/8==24)
{
MessageBox(20,10,"提示:此功能暂未实现");
}
break;
default:break;
}
}
gotoxy(personwinx-personwintopx+1,personwiny-personwintopy+1);
}while(1);
back10: window(ti.winleft,ti.wintop,ti.winright,ti.winbottom);
myputtext(1,1,80,25,block);
textattr(ti.attribute);
gotoxy(ti.curx,ti.cury);
return;
}
/*****************本函数用于在人员信息窗口中显示一行文本*********************/
int ShowPersonWinaLine(int x,int y,int line,struct personnode* personhead,
struct dnode* bookhead,struct personnode* curline)
{
int beyonddaycount;
if((line<1)||(line>allpersonnode)) return;
gotoxy(x,y);
if(curline->person.booknum!=0)
beyonddaycount=beyondday(curline->person.borrowdate,bookhead);
else beyonddaycount=0;
if(beyonddaycount>0) textcolor(LIGHTGREEN); /*绿色表示借书巳超期*/
else textcolor(YELLOW);
cprintf("%08ld",curline->person.borrowernum);
cprintf(" %-6s",curline->person.borrower);
cprintf("%9s ",curline->person.borrowdate);
if(curline->person.booknum==0) cprintf("%3d",0);/*如果没有借书,显示0*/
else cprintf("%3d",beyonddaycount);/*如果借书了就显示超过时间*/
cprintf(" %s",curline->person.bookname);
}
/*******************用于显示一屏幕文字*************************************/
int ShowPersonWinaScreen(struct personnode* personhead,struct dnode* bookhead,int startline/*,int personwinheight*/)
{
int oldx=wherex(),oldy=wherey();
int height;
int line=1,curline=1;
struct personnode* curnode;
textcolor(YELLOW);
if(allpersonnode>personwinheight)
height=personwinheight;
light_mouse(OFF);
clrscr();
curnode=FindBorrowerNodeOrder(startline,personhead);
/* do{
ShowPersonWinaLine(1,curline++,startline++,personhead,bookhead,curnode);
curnode=curnode->next;
}while((line++)<=height);
*/
for(line=1;line<=height;line++)
{
ShowPersonWinaLine(1,curline++,startline++,personhead,bookhead,curnode);
curnode=curnode->next;
}
gotoxy(oldx,oldy);
light_mouse(ON);
}
/****删除人员窗口****/
int DeletePersonWin(struct personnode* personhead,struct dnode* bookhead)
{
struct text_info ti;
char errormessage[80];
char block[4*70*14];
int key;
long borrowernum;
struct personnode* deleteborrower;
light_mouse(OFF);
gettextinfo(&ti);
gettext(5,6,75,20,&block);
window(15,10,45,13);
textbackground(BLACK);
clrscr();
window(14,9,44,12);
textbackground(CYAN);
textcolor(LIGHTGREEN);
clrscr();
cprintf(" 请输入要删除的人的号码:");
window(15,10,43,10);
textbackground(BLACK);
textcolor(YELLOW);
clrscr();
light_mouse(ON);
borrowernum=InputBorrowerNum();
if(borrowernum==CANCEL) goto back1;
deleteborrower=FindBorrowerNode(borrowernum,personhead);/*按代号查找结点*/
if(deleteborrower==NULL)
{sprintf(errormessage,"错误:%08ld不存在。",borrowernum);
MessageBox(20,11,errormessage);
goto back1;
}
light_mouse(OFF);
window(5,6,75,20);
textbackground(CYAN);
textcolor(BLACK);
clrscr();
cprintf(" 此人的借书情况:\r\n");
window(6,7,74,19);
textbackground(BLACK);
clrscr();
light_mouse(ON);
PrintBorrowerNode(borrowernum,personhead,bookhead);
if(BorrowBookCount(borrowernum,personhead,bookhead)>0)
{sprintf(errormessage,"注意:%08ld还有书没还,不能删除!",borrowernum);
MessageBox(20,13,errormessage);
goto back1;
}
key=MessageBox(10,2,"真的要删除此人吗?(Y/N)");/*借用错误信息窗口*/
if(key=='y'||key=='Y')
{DeletePerson(personhead,borrowernum);
SavePersonList(personhead,"data\\person.lvj");
chdir(curpath);
SaveList(bookhead,"data\\list.lvj");
chdir(curpath);
}
back1:myputtext(5,6,75,20,block);
window(ti.winleft,ti.wintop,ti.winright,ti.winbottom);
textattr(ti.attribute);
gotoxy(ti.curx,ti.cury);
}
/*******初始化人员信息节点*********/
struct personnode* InitPersonList(void)
{
struct personnode* head;
struct borrowerinfo person={0,"未命名","没借书",0,"无",0};
head=(struct personnode*)malloc(sizeof(struct personnode));
head->last=NULL;
head->next=NULL;
head->person=person;
return(head);
}
/* 存储人员信息线性表 */
int SavePersonList(struct personnode* head,char* filename)
{
struct personnode* curp=head;
char errormessage[80];
FILE* fp;
int borrowerinfolen=(int)sizeof(struct borrowerinfo);
fp=fopen(filename,"wb+");
if(fp==NULL)
{sprintf(errormessage,"打开文件%s错误。",filename);
MessageBox(20,9,errormessage);
return;
}
do
{
fwrite(&curp->person,borrowerinfolen,1,fp);
curp=curp->next;
}while(curp!=NULL);
fclose(fp);
}
/* 加载人员信息线性表 */
struct personnode* LoadPersonList(char *filename)
{
int count=1;
char errormessage[80];
struct personnode* head;
struct borrowerinfo person;
int borrowerinfolen=(int)sizeof(struct borrowerinfo);
FILE* fp;
head=InitPersonList();
fp=fopen(filename,"rb");
if(fp==NULL)
{ sprintf(errormessage,"打开文件%s错误。",filename);
MessageBox(20,9,errormessage);
return NULL;
}
fread(&head->person,borrowerinfolen,1,fp);/* 读入链头内容 */
do
{
fread(&person,borrowerinfolen,1,fp);
InsertPersonNode(count++,person,head);
} while((feof(fp))==0);
fclose(fp);
DeletePersonNode(head,--count);
/*之所以要删除是因为文件读取方面的一个小问题.每次都多有一行*/
return (head);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -