⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 person.c

📁 图书借阅管理程序v1.2
💻 C
📖 第 1 页 / 共 3 页
字号:
/****关于人员的管理窗口的操作函数*****/

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<dos.h>


/*全局变量*/
extern int allpersonnode=0;
extern int personwinx=1;
extern int personwiny=1;/*当前光标的绝对坐标,最大为allpersonnode*/
extern int personwintopx=1;
extern int personwintopy=1;
extern int personwinheight=20;




/**********函数原型*********************************/
/**本函数将根据顺序在程序中找到这个结点**/
struct personnode* FindBorrowerNodeOrder(int linenum,struct personnode* personhead);
/* 插入一个新结点(i为插入位置,x为插入的元素,personhead为欲插入的链表 */
int InsertPersonNode(int i,struct borrowerinfo x,struct personnode* personhead);
/***删除第I个结点**/
int DeletePersonNode(struct personnode* perosnhead,int i);
/*删除人员号码personnum所指向的节点*/
int DeletePerson(struct personnode* personhead,long personnum);
/*删除链表personhead中的personnode号节点*/
int DeletePersonFromNode(struct personnode* personhead,struct personnode* personnode);
/*清除人员链表***/
int ClearBorrowerList(struct personnode* personhead);
/* 求长度 */
int LengthofPersonList(struct personnode* personhead);
/* 判断表是否为空 */
int IsEmptyPersonList(struct personnode* personhead);
/**本函数将根据书号在程序中找到这个结点**/
struct personnode* FindBorrowerNode(long personnum,struct personnode* personhead);
/***本函数专用于输入借阅号****/
long InputBorrowerNum();
/**输入借书人的姓名***/
char* InputBorrowerName();
/*** 函数用于求出数据的插入位置*/
int InsertPlaceofBorrower(long num,struct personnode* personhead);
/**获取当前的日期**/
char* getnowdate(void);
/*得到当前日期:中文的年月日*/
char* getdates(void);
/***返回借书超过的日期**/
int beyondday(char *olddate,struct dnode* bookhead);
/***人员信息输入窗口**/
int InputPersonNode(struct personnode* personhead);
/*求出一个人的总借书数量*/
int  BorrowBookCount(long personnum,struct personnode* personhead,struct dnode* bookhead);
/***借书窗口***/
void BorrowBookWin(long personnum,struct personnode* personhead,struct dnode* bookhead);
/****还书窗口***/
void ReturnBookWin(struct personnode* personhead,struct dnode* bookhead);
/*输出指定成员的借书信息*/
void PrintBorrowerNode(long personnum,struct personnode* personhead,struct dnode* bookhead);
/*根据借书者的号码查找借书者在链表中的位置,如果找到返回一个大于0的数,否则返回0*/
int FindBorrower(long personnum,struct personnode* personhead);
/*根据书号找到借阅者的号码*/
struct personnode* FindBorrowerFromBookNum(int booknum,struct personnode* personhead);
/*启动借书功能后,开始执行此函数*/
int StartBorrowBook(struct personnode* personhead,struct dnode* bookhead);
/* 在屏幕上显示一条提示信息:依次为两个坐标和要显示的信息 */
int MessageBox(int col,int row,char *info);
/***对人员窗口上箭头光标进行控制**/
void keypersonup(struct personnode* personhead,struct dnode* bookhead);
/**对下箭头光标进行控制**/
void keypersondown(struct personnode* personhead,struct dnode* bookhead);
/****对光标的左右键进行控制*******/
void keypersonright(void);
void keypersonleft(void);
/***上下翻页键****/
void keypersonpgup(struct personnode* personhead,struct dnode* bookhead);
void keypersonpgdown(struct personnode* personhead,struct dnode* bookhead);
/****人员信息窗口(主窗口)*****/
void borrowerinfoWin(struct personnode* personhead,struct dnode* bookhead);
/***本函数用于在人员信息窗口中显示一行文本*****/
int ShowPersonWinaLine(int x,int y,int line,struct personnode* personhead,
                       struct dnode* bookhead,struct personnode* curnode);
/**用于显示一屏幕文字***/
int ShowPersonWinaScreen(struct personnode* personhead,struct dnode* bookhead,
                         int startline);
/****删除人员窗口****/
int DeletePersonWin(struct personnode* personhead,struct dnode* bookhead);
/***初始化人员信息节点*****/
struct personnode* InitPersonList(void);
/* 存储人员信息线性表 */
int SavePersonList(struct personnode* personhead,char* filename);
/* 加载人员信息线性表 */
struct personnode* LoadPersonList(char *filename);



/********************本函数将根据顺序在程序中找到这个结点**********************/
struct personnode* FindBorrowerNodeOrder(int linenum,struct personnode* head)
{
 int count=1;
 struct personnode* curp=head;
 while((curp->next!=NULL)&&(count<linenum))
     {count++;
      curp=curp->next;
     }
 if((count==linenum)&&(curp!=NULL)) return(curp->next);
 else return(NULL);
}

/* 插入一个新结点 */
int InsertPersonNode(int i,struct borrowerinfo x,struct personnode* head)

{
 struct personnode* curp=head;
 int count=1;
 struct personnode* newnode;
 if(i<1) return(0);
 while((curp!=NULL)&&(count<i))
       {curp=curp->next;
        count++;
       }
 if((curp!=NULL)&&(count==i))
        {newnode=(struct personnode*)malloc(sizeof(struct personnode));
         newnode->person=x;
         if(curp->next==NULL)      /* 如果现在指针指向最后一个结点 */
                {curp->next=newnode;
                 newnode->last=curp;
                 newnode->next=NULL;
                }
         else
                {curp->next->last=newnode;
                 newnode->next=curp->next;
                 curp->next=newnode;
                 newnode->last=curp;
                }
          allpersonnode++;   /*人员数量加1*/
          return(1);
         }
  else return(0);
}



/***************删除第I个结点****************/
int DeletePersonNode(struct personnode* head,int i)
{
 struct personnode* curp=head->next;
 int count=1;
 if(curp==NULL) return(0);
 while((curp!=NULL)&&(count<i))
      {curp=curp->next;
       count++;
      }
 if((curp!=NULL)&&(count==i))
      {if(curp->next==NULL)   /* 如果是最后一个结点 */
            {curp->last->next=NULL;}
       else
            {curp->last->next=curp->next;
             curp->next->last=curp->last;
            }
       free(curp);
       allpersonnode--;
       return(1);
      }
  else
       return(0);
}


/*删除personnum所指向的节点*/
int DeletePerson(struct personnode* personhead,long personnum)
{
 int deleteplace=FindBorrower(personnum,personhead);
 DeletePersonNode(personhead,deleteplace);
}

/*删除链表head中的node节点*/
int DeletePersonFromNode(struct personnode* head,struct personnode* node)
{
 struct personnode* curp=head;
 while(curp!=NULL&&curp!=node)
    curp=curp->next;
 if(curp!=NULL&&curp==node)
     {
      if(curp->next==NULL)
           curp->last->next=NULL;
      else
           {curp->last->next=curp->next;
            curp->next->last=curp->last;
           }
     free(curp);
     allpersonnode--;
     return(1);
      }
  else
      return(0);
}




/*清除人员链表***/
int ClearBorrowerList(struct personnode* head)
{
 struct personnode* curp=head->next;
 while(curp!=NULL)
     {free(curp->last);
      curp=curp->next;
     }
return 0;
}

/* 求长度 */
int LengthofPersonList(struct personnode* head)
{
 struct personnode* curp=head;
 int count=0;
 while(curp->next!=NULL)
       {curp=curp->next;
        count++;
       }
 return(count);
}

/* 判断表是否为空 */
int IsEmptyPersonList(struct personnode* head)
{
 if(head->next==NULL)
     return(1);
 else
     return(0);
}

/********************本函数将根据书号在程序中找到这个结点**********************/
struct personnode* FindBorrowerNode(long borrowernum,struct personnode* borrowerhead)
{
 /*int count=1;*/
 struct personnode* curp=borrowerhead->next;
 while((curp!=NULL)&&(curp->person.borrowernum!=borrowernum))
     {/*count++;*/
      curp=curp->next;
     }
 if((curp->person.borrowernum==borrowernum)&&(curp!=NULL)) return(curp);
 else return(NULL);
}


/*******************本函数专用于输入借阅号********************/
long InputBorrowerNum()
{
 int key,count=0;
 long num;
 char *string;
 string=(char*)malloc(9);
get: while((key=get_key())!=ENTER){
   switch(key){
             case '0':
             case '1':
             case '2':
             case '3':
             case '4':
             case '5':
             case '6':
             case '7':
             case '8':
             case '9':if(count>=8) continue;
                      putch(key);
                      string[count]=key;
                      count++;
                      break;

             case ESC:return CANCEL;  /*宏定义为取消*/

             case BACK:cprintf("\b");
                       putch('\0');
                       cprintf("\b");
                       count--;
                       if(count<=0) count=0;
                       break;

             case RIGHT:
             case LEFT:
             case DOWN:
             case UP:break;

             default:continue;
               }
         }
string[count]='\0';
if(string[0]=='\0') goto get;
sscanf(string,"%ld",&num);
free(string);
return (num);
}

/******输入借书人的姓名**********/
char* InputBorrowerName()
{

 int key,count=0;
 char *str;
 str=(char*)malloc(7);
get: while((key=get_key())!=ENTER)
      {
        switch(key){
        case BACK:
               if(count==0) continue; /*当删除完时*/
               cprintf("\b");
               putch('\0');
               cprintf("\b");
               count--;
               if(count<=0) count=0;

               break;
     case ESC: return NULL;
     /*case SPACE:continue;*/
        case '\0':
        case RIGHT:
        case LEFT:
        case DOWN:
        case UP:break;
     default:if(count>=6) continue;  /*当输入太多时*/
             putch(key);
             str[count]=key;
             count++;
              }
    }
str[count]='\0';
if(str[0]=='\0') goto get;
return(str);
}


/************************** 函数用于求出数据的插入位置*/
int InsertPlaceofBorrower(long num,struct personnode* head)
{
 int count=1;
 struct personnode* curp=head;
 while((curp->next!=NULL)&&(curp->next->person.borrowernum<num))
     {count++;
      curp=curp->next;
     }
 return(count);
}


/**************获取当前的日期*******************/
char* getnowdate(void)
{
   char* strtime=(char*)malloc(80);
   union REGS In, Out;       /* 定义结构变量                 */
   In.h.ah = 0x2a;           /* 设置DOS 21H类中断功能调用2AH */
   int86(0x21, &In, &Out);   /* 执行中断                     */
   sprintf(strtime,"%02d-%02d-%02d", Out.x.cx%1000, Out.h.dh, Out.h.dl);
   return (strtime);
}


/*得到中文的年月日*/
char* getdates(void)
{
   char* strtime=(char*)malloc(80);
   union REGS In, Out;       /* 定义结构变量                 */
   In.h.ah = 0x2a;           /* 设置DOS 21H类中断功能调用2AH */
   int86(0x21, &In, &Out);   /* 执行中断                     */
   sprintf(strtime,"%02d年%02d月%02d日", Out.x.cx%1000, Out.h.dh, Out.h.dl);
   return (strtime);
 }

/*************返回借书超过的日期*******************/
int beyondday(char *olddate,struct dnode* bookhead)
{

 int nowyear,nowmonth,nowday;
 int oldyear,oldmonth,oldday;
 char* nowdate;
 char  nownowdate[100];
 if(olddate[6]=='\0') return 0;  /*如果没借书的话到第7个字符为0*/
 nowdate=getnowdate();
 strcpy(nownowdate,nowdate);
 sscanf(olddate,"%02d-%02d-%02d",&oldyear,&oldmonth,&oldday);
 sscanf(nownowdate,"%02d-%02d-%02d",&nowyear,&nowmonth,&nowday);
 return(((nowyear-oldyear)*365+(nowmonth-oldmonth)*30+(nowday-oldday))-(bookhead->book.booknum));
}



/**************人员信息输入窗口**************/
int InputPersonNode(struct personnode* head)
{
 struct text_info ti;
 char block[4*40*5];
 int i,j;
 long insertplaceofborrower;
 long borrowernum;
 char borrowername[7],*BorrowerName;
 struct borrowerinfo newborrower={0,"未命名","没借书",0,"无",0};

 light_mouse(OFF);
 gettextinfo(&ti); /*保存屏幕参数*/
 gettext(20,10,60,15,&block);

 window(21,11,60,15); /*画影子*/
 textbackground(BLACK);
 clrscr();

 window(20,10,59,14);    /*画窗体和边框*/
 textbackground(CYAN);
 textcolor(LIGHTRED);
 clrscr();
 putch(201);
 for(i=1;i<39;i++) putch(205);
 putch(187);
 for(i=1;i<3;i++)
    for(j=1;j<41;j++)
        putch(186);
 putch(200);
 for(i=1;i<39;i++) putch(205);
 putch(188);
 textcolor(BLACK);
 gotoxy(15,1);
 cputs("添加新成员");

 window(21,11,58,12);
 clrscr();
 cputs(" 身份号码             姓名");

 window(21,12,58,12);   /*画输入框*/
 textbackground(BLACK);

 textcolor(YELLOW);
 clrscr();
 light_mouse(ON);

 newborrower.borrowernum=InputBorrowerNum();
 if(newborrower.borrowernum==CANCEL)
     goto back100; /*如果在输入的途中按ESC则返回*/

 gotoxy(20,1);
 BorrowerName=InputBorrowerName();
 if(BorrowerName==NULL) goto back100;   /*如果在输入的途中按ESC则返回*/

 strcpy(newborrower.borrower,BorrowerName);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -