📄 person.c
字号:
insertplaceofborrower=InsertPlaceofBorrower(newborrower.borrowernum,head);
InsertPersonNode(insertplaceofborrower,newborrower,head);
SavePersonList(head,"data\\person.lvj"); /***每输入一个就重新存储一次***/
chdir(curpath);
back100: myputtext(20,10,60,15,block);
window(ti.winleft,ti.wintop,ti.winright,ti.winbottom);
textattr(ti.attribute);
gotoxy(ti.curx,ti.cury);
return 1;
}
/*求出一个人的总借书数量*/
int BorrowBookCount(long borrowernum,struct personnode* personhead,
struct dnode* bookhead)
{
struct personnode* curp=personhead->next;
int bookcount=0;
while(curp!=NULL)
{if(curp->person.borrowernum==borrowernum)
bookcount++;
curp=curp->next;
}
if(bookcount<=0) return 0;
else return (bookcount-1);
}
/*************借书窗口******************************/
void BorrowBookWin(long borrowernum,struct personnode* borrowerhead,
struct dnode* bookhead)
{
struct text_info ti;
struct dnode* curp;
struct borrowerinfo newborrower;
struct personnode* thisborrower;
char block[4*77*15];
char errormessage[80];
int booknum; /*书的代号*/
int borrowcount=BorrowBookCount(borrowernum,borrowerhead,bookhead);
int insertplaceofborrower;/*人员的插入位置*/
light_mouse(OFF);
gettextinfo(&ti);
gettext(2,5,79,20,&block);
window(3,6,79,20);
textbackground(BLACK);
clrscr();
window(2,5,78,19);
textbackground(BROWN); /*紫色*/
textcolor(LIGHTGREEN);
clrscr();
cputs(" 请输入要借的书的书号:");
gotoxy(1,4);
cputs(" 姓名 超期 所借的书名");
gotoxy(15,15);
cprintf("共借书%d本",borrowcount);
window(3,9,77,18); /*输出窗口*/
textbackground(BLACK);
textcolor(YELLOW);
clrscr();
light_mouse(ON);
PrintBorrowerNode(borrowernum,borrowerhead,bookhead);
/*输出借书情况,结果输出在一个小窗口中*/
if(borrowcount>=((int)bookhead->book.bookprice))
{sprintf(errormessage,"借书已超过%d本,不能再借!",(int)bookhead->book.bookprice);
MessageBox(30,3,errormessage);
goto back;
}
window(3,6,77,6); /*输入条*/
textbackground(BLACK);
clrscr();
booknum=InputBookNum(); /*提示输入书号*/
if(booknum==CANCEL) goto back;
if((curp=FindBookNodeFromNum(booknum,bookhead))==NULL)
{sprintf(errormessage,"图书%d不存在!",booknum);
MessageBox(20,10,errormessage);
goto back; /*没有找到书就返回*/
}
else
{
if((curp->book.borrow_out[0]=='Y')||(curp->book.borrow_out[0])=='y')
/*如果书已经被借出去了就提示错误*/
{sprintf(errormessage,"图书%d已经被借出去了。",booknum);
MessageBox(20,10,errormessage);
goto back;
}
curp->book.borrow_out[0]='Y';curp->book.borrow_out[1]='\0';
/*如果书存在就把书的是否借出置"Y"*/
SaveList(bookhead,"data\\list.lvj");
chdir(curpath);
thisborrower=FindBorrowerNode(borrowernum,borrowerhead);
newborrower.borrowernum=borrowernum; /*插入借书者号码*/
newborrower.booknum=booknum; /*插入书号*/
strcpy(newborrower.borrower,thisborrower->person.borrower);
/*在新节点中装入借书者姓名*/
strncpy(newborrower.bookname,curp->book.bookname,48);
/*在新节点中装入书名(最多46个字符)*/
strcpy(newborrower.borrowdate,getnowdate());
/*在新节点中装入借书时间*/
insertplaceofborrower=InsertPlaceofBorrower(borrowernum,borrowerhead);
/*求插入位置*/
InsertPersonNode(insertplaceofborrower,newborrower,borrowerhead);
/*开始插入*/
SavePersonList(borrowerhead,"data\\person.lvj");
/*保存*/
chdir(curpath);
}
clrscr();
textattr(128+WHITE+(BLACK<<4)); /*黑底白字加闪为烁*/
/* textcolor(WHITE); */
gotoxy(20,1);
cprintf("完成(注意:看一下书名对不对....)");
light_mouse(OFF);
window(3,9,77,18); /*再把信息窗口输出一次*/
textbackground(BLACK);
textcolor(YELLOW);
clrscr();
light_mouse(ON);
PrintBorrowerNode(borrowernum,borrowerhead,bookhead);
/*输出借书情况,结果输出在一个小窗口中*/
get_key();
back: myputtext(2,5,79,20,block);
window(ti.winleft,ti.wintop,ti.winright,ti.winbottom);
textattr(ti.attribute);
gotoxy(ti.curx,ti.cury);
}
/****还书窗口***/
void ReturnBookWin(struct personnode* personhead,struct dnode* bookhead)
{
struct text_info ti;
struct personnode* curp; /*指向当前正在处理的节点*/
char errormessage[80];
char block[4*71*15];
long borrowernum; /*还书人号码*/
int booknum; /*所还的书的书号*/
int key;
struct dnode* returnbook;
light_mouse(OFF);
gettextinfo(&ti);
gettext(5,6,76,21,&block);
window(15,10,45,13);
textbackground(BLACK);
clrscr();
window(14,9,44,12);
textbackground(CYAN);
textcolor(WHITE);
clrscr();
cprintf(" 请输入要还的书的书号:");
window(15,10,43,10);
textbackground(BLACK);
textcolor(YELLOW);
clrscr();
light_mouse(ON);
booknum=InputBookNum();
if(booknum==CANCEL) goto back2;
returnbook=FindBookNodeFromNum(booknum,bookhead);
/*根据输入的书号查找书节点,如果找不到返回NULL*/
if(returnbook==NULL)
{sprintf(errormessage,"错误:图书%d不存在。",booknum);
MessageBox(20,15,errormessage);
goto back2;
}
curp=FindBorrowerFromBookNum(booknum,personhead);
if(curp==NULL)
{MessageBox(20,15,"这本书没有借出。");
goto back2;
}
borrowernum=curp->person.borrowernum;
light_mouse(OFF);
window(6,7,76,21);
textbackground(BLACK);
clrscr();
window(5,6,75,20);
textbackground(BROWN);
textcolor(WHITE);
clrscr();
cprintf(" 借书情况如下:\r\n");
window(6,7,74,19);
textbackground(BLACK);
clrscr();
light_mouse(ON);
PrintBorrowerNode(borrowernum,personhead,bookhead);
sprintf(errormessage,"请确认书名:%s (Y/N)",returnbook->book.bookname);
key=MessageBox(5,2,errormessage);
if(key=='Y'||key=='y')
{}
else goto back2; /*如果选择非y则退出*/
returnbook->book.borrow_out[0]='N'; /*使图书变为未借出*/
returnbook->book.borrow_out[1]='\0';
SaveList(bookhead,"data\\list.lvj");
chdir(curpath);
DeletePersonFromNode(personhead,curp);
SavePersonList(personhead,"data\\person.lvj");
chdir(curpath);
light_mouse(OFF);
window(6,7,76,21);
textbackground(BLACK);
clrscr();
window(5,6,75,20);
textbackground(BROWN);
textcolor(WHITE);
clrscr();
cprintf(" 借书情况如下:\r\n");
window(6,7,74,19);
textbackground(BLACK);
clrscr();
light_mouse(ON);
PrintBorrowerNode(borrowernum,personhead,bookhead);
MessageBox(20,2,"完成,按任意键继续...");/*借用错误信息窗口*/
back2:myputtext(5,6,76,21,block);
window(ti.winleft,ti.wintop,ti.winright,ti.winbottom);
textattr(ti.attribute);
gotoxy(ti.curx,ti.cury);
}
/*输出指定成员的信息*/
void PrintBorrowerNode(long borrowernum,struct personnode* head,struct dnode* bookhead)
{
struct personnode* curp=head->next;
int beyonddaycount;
while(curp!=NULL)
{if(curp->person.borrowernum==borrowernum)
{
here:if(curp->person.booknum!=0) beyonddaycount=beyondday(curp->person.borrowdate,bookhead);
else beyonddaycount=0;
if(beyonddaycount>0) textcolor(LIGHTRED); /*红色表示借书巳超期*/
else textcolor(YELLOW);
cprintf("%-6s ",curp->person.borrower);
if(curp->person.booknum==0) cprintf(" %3d",0);/*如果没有借书,显示0*/
else cprintf(" %3d",beyonddaycount);/*如果借书了就显示超过日期*/
cprintf(" %s\r\n",curp->person.bookname);
curp=curp->next;
if((curp->person.borrowernum)==(curp->last->person.borrowernum)) goto here;
return;
}
else
curp=curp->next;
}
}
/*根据借书者的号码查找借书者在链表中的位置,如果找到返回一个大于0的数,否则返回0*/
int FindBorrower(long borrowernum,struct personnode* head)
{
struct personnode* curp=head->next;
int count=1;
while(curp!=NULL)
{if((curp->person.borrowernum)==borrowernum) return count;
else {count++;curp=curp->next; }
}
return 0;
}
/*根据书号找到借阅者的借阅号*/
struct personnode* FindBorrowerFromBookNum(int booknum,struct personnode* head)
{
struct personnode* curp=head->next;
while((curp!=NULL)&&(curp->person.booknum!=booknum))
curp=curp->next;
if((curp!=NULL)&&(curp->person.booknum==booknum))
return (curp);
else return NULL;
}
/*启动借书功能后,开始执行此函数*/
int StartBorrowBook(struct personnode* borrowerhead,struct dnode* bookhead)
{
struct text_info ti;
char block[4*41*6];
long borrowernum; /*待输入的借书者的号码 */
char errormessage[80];
light_mouse(OFF);
gettextinfo(&ti);
gettext(19,10,60,14,&block);
window(20,11,60,14); /*阴影*/
textbackground(BLACK);
clrscr();
window(19,10,59,13);
textbackground(MAGENTA);
textcolor(LIGHTGREEN);
clrscr();
cprintf(" 请输入借书者的号码:");
window(20,11,58,11);
textbackground(BLACK);
textcolor(YELLOW);
clrscr();
light_mouse(ON);
/*输入窗口终于画完了*/
borrowernum=InputBorrowerNum(); /*输入借书者代号*/
if(borrowernum==CANCEL) goto goback;
if((FindBorrower(borrowernum,borrowerhead))==0) /***如果没有找到借书者*/
{sprintf(errormessage,"无%08ld,此人不存在。",borrowernum);
MessageBox(22,12,errormessage);
goto goback;/*返回*/
}
else /*找到了借书者*/
{BorrowBookWin(borrowernum,borrowerhead,bookhead);/*借书窗口*/
}
goback: window(ti.winleft,ti.wintop,ti.winright,ti.winbottom); /*还原窗口*/
myputtext(19,10,60,14,block); /*还原内容*/
textattr(ti.attribute); /*还原属性*/
gotoxy(ti.curx,ti.cury); /*还原光标*/
}
/* 在屏幕上显示一条提示信息 */
int MessageBox(int col,int row,char *info)
{
struct text_info ri;/* 保存当前屏幕窗口信息的变量 */
char block[4*3*80]; /* 保存屏幕区域(4行*4l列)的区域的数组 */
int key; /* 接收用户的按键值变量 */
/* 保存原来屏幕参数和提示窗口的背景 */
int infolen=strlen(info);
light_mouse(OFF);
gettextinfo(&ri);
gettext(col,row,80,row+4,&block);
/* 画出提示窗口 */
textcolor(YELLOW);
textbackground(BLACK);
window(col+1,row+1,col+infolen+3,row+3);
clrscr(); /* 画黑色阴影 */
textbackground(YELLOW);
window(col,row,col+infolen+2,row+2);
clrscr();
light_mouse(ON);
gotoxy(2,2);
textcolor(WHITE);
cputs(info);
key=get_key();
/* 恢复屏幕参数和屏幕的内容 */
window(ri.winleft,ri.wintop,ri.winright,ri.winbottom);
myputtext(col,row,80,row+4,block);
textattr(ri.attribute);
gotoxy(ri.curx,ri.cury);
return key;
}
/*******************对人员窗口上箭头光标进行控制**********************************/
void keypersonup(struct personnode* personhead,struct dnode* bookhead)
{
struct personnode* curnode;
if(--personwiny>=personwintopy) return;
else
{
if(--personwintopy<1)
{personwintopy=personwiny=1;
return;
}
}
/* ShowPersonWinaScreen(personhead,bookhead,personwintopy,personwinheight);*/
curnode=FindBorrowerNodeOrder(personwintopy,personhead); /*找到这一行所对应的结点*/
scroll(2,4,79,23,1,BLUE);/*下滚屏*/
ShowPersonWinaLine(1,1,1,personhead,bookhead,curnode);
}
/*******************对下箭头光标进行控制*********************************/
void keypersondown(struct personnode* personhead,struct dnode* bookhead)
{
struct personnode* curnode;
if(++personwiny>allpersonnode)
{personwiny=allpersonnode;
return;
}
if(personwiny<=personwintopy+personwinheight-1) return;
else
personwintopy++;
/*ShowPersonWinaScreen(personhead,bookhead,personwintopy,personwinheight);*/
curnode=FindBorrowerNodeOrder(personwintopy+personwinheight-1,personhead);
scroll(2,4,79,23,0,BLUE);
ShowPersonWinaLine(1,personwinheight,1,personhead,bookhead,curnode);
}
/****对光标的左右键进行控制*******/
void keypersonright(void)
{
personwinx++;
if(personwinx>78) personwinx=78;
gotoxy(personwinx-personwintopx+1,personwiny-personwintopy+1);
}
void keypersonleft(void)
{
personwinx--;
if(personwinx<1) personwinx=1;
gotoxy(personwinx-personwintopx+1,personwiny-personwintopy+1);
}
void keypersonpgup(struct personnode* personhead,struct dnode* bookhead)
{
/**********************上翻页键************************************/
if(personwintopy==1) return; /*如果这已经是每一页,主不用翻页了*/
personwintopy-=19;
if(personwintopy<=1) personwintopy=personwiny=1;
else personwiny-=19;
ShowPersonWinaScreen(personhead,bookhead,personwintopy);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -