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

📄 common.c

📁 图书借阅管理程序v1.2
💻 C
📖 第 1 页 / 共 2 页
字号:
/***
****本文件中主要包含一些通用窗口中显示
****内容的操作函数.通用窗口是用来干什么的?
****本程序的很多内容都是显示在这个窗口中,
****比如帮助信息,执行各种搜索功能后的结果,
****都是在这个窗口中显示.
***/

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


/* 将gettext()函数取得的内容重新显示到屏幕上*/
void myputtext(int left,int top,int right,int button,char* block);
/* 插入一个新结点 */
int InsertCommonNode(int i,char* x,struct commonstr* head);
/* 定义数据结构为双向非循环链表 */
struct commonstr* InitCommonList(void);
/*清除整个链表*/
int ClearCommonList(struct commonstr* head);
/* 求长度 */
int LengthCommonList(struct commonstr* head);
/***查找节点并返回此节点***/
struct commonstr* FindCommonNode(int linenum,struct commonstr* head);
/*显示一行*/
void ShowCommonWinaLine(int x,int y,int linenum,struct commonstr* head);
/*显示一屏*/
void ShowCommonWinaScreen(struct commonstr* head,int startline,int textline);
/**上下左右键**/
int keycommonwinup(int* winy,int* wintopy,int* winheight,struct commonstr* head);
int keycommonwindown(int* winy,int* wintopy,int* winheight,struct commonstr* head);
int keycommonwinleft(int* winx,int* wintopx,int* winwidth);
int keycommonwinright(int* winx,int* wintopx,int* winwidth);
struct commonstr* FindPersonInfo(long personnum,struct personnode* personhead,
                                 struct dnode* bookhead);
/*用于显示head链表中的内容,窗口标题放在head的头结点中*/
void CommonWin(struct commonstr* head);
/***根据书是否被借出来查找书<当YN为Y时,查看借出去的书,为N时查看没有被借出去的书***/
struct commonstr* SearchBookYN(struct dnode* bookhead,char YN);
/**根据是否超期查找借书的人**/
struct commonstr* SearchPersonBeyond(struct personnode* personhead,
                                     struct dnode* bookhead);
/***查找书链表中的书名中有string关键字的书的节点***/
struct commonstr* SearchBookName(struct dnode* bookhead,char* string);
/*****本程序专门用于输入查找的关键书名****/
char* InputSearchName();
/**选择查找命令后第一个出现的窗口**/
int    FindWindow(struct dnode* bookhead,struct personnode* personhead);
/**帮助信息**/
struct commonstr* HelpInfo();

/* 将gettext()函数的内容重新显示到屏幕上*/
void myputtext(int left,int top,int right,int button,char* block)
{
 light_mouse(OFF);
 puttext(left,top,right,button,block);
 light_mouse(ON);
}

/* 插入一个新结点 */
int InsertCommonNode(int i,char* x,struct commonstr* head)

{
 struct commonstr* curp=head;
 int count=1;
static struct commonstr* newnode;
 if(i<1) return(0);
 while((curp!=NULL)&&(count<i))
       {curp=curp->next;
        count++;
       }
 if((curp!=NULL)&&(count==i))
        {newnode=(struct commonstr*)malloc(sizeof(struct commonstr));
         strncpy(newnode->string,x,69);
         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;
                }
          return(1);
         }
  else return(0);
}





/* 定义数据结构为双向非循环链表 */
struct commonstr* InitCommonList(void)
{
 struct commonstr* head;
 char   errormessage[80];
 head=(struct commonstr*)malloc(sizeof(struct commonstr));
   if(head==NULL)
        {sprintf(errormessage,"系统内存严重不足。");
         MessageBox(20,10,errormessage);
         return(NULL);
        }
  head->last=NULL;
  head->next=NULL;
  strcpy(head->string,"None");
  return (head);

}


/*清除整个链表*/
int ClearCommonList(struct commonstr* head)
{
 struct commonstr* curp=head->next;
 while(curp!=NULL)
      {free(curp->last);
       curp=curp->next;
      }
 return 0;
}



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


int IsEmptyCommonList(struct commonstr* head)
{
 if(head->next==NULL)
     return(1);
 else
     return(0);
}



struct commonstr* FindCommonNode(int linenum,struct commonstr* head)
{
 struct commonstr* curp=head->next;
 int  count=1;
 while((curp!=NULL)&&(count<linenum))
     {count++;
      curp=curp->next;
     }
 return curp;
}



/*显示一行*/
void ShowCommonWinaLine(int x,int y,int linenum,struct commonstr* curnode)
{
 /*struct commonstr* curp=FindCommonNode(linenum,head);*/
 /*linenum为现在显示的行的行号(现在未用)*/
 gotoxy(x,y);
 if(curnode==NULL) return;
 cprintf("%s",curnode->string);
}


/*显示一屏*/
void ShowCommonWinaScreen(struct commonstr* head,int startline,int textheight)
{/*textheight为一屏文本的行数*/
 int curline;
 int oldx=wherex(),oldy=wherey();
 struct commonstr* curnode;
 textcolor(BLACK);

 light_mouse(OFF);
 clrscr();
 curnode=FindCommonNode(startline,head);
 for(curline=1;curline<=textheight;curline++)
     {ShowCommonWinaLine(1,curline,startline++,curnode);
      curnode=curnode->next;
     }
 gotoxy(oldx,oldy);
 light_mouse(ON);
}

int keycommonwinup(int* winy,int* wintopy,int* winheight,struct commonstr* head)
{
 /*int allcommonnode=LengthCommonList(head);*/
 struct commonstr* curnode;

 if(--(*winy)>=(*wintopy)) return 0;
 else
    if(--(*wintopy)<1)
       {(*wintopy)=(*winy)=1;
        return 0;
       }
 curnode=FindCommonNode(*wintopy,head);
 scroll(6,5,74,21,1,LIGHTGRAY);
 ShowCommonWinaLine(1,1,*wintopy,curnode);
}


int keycommonwindown(int* winy,int* wintopy,int* winheight,struct commonstr* head)
{
 int allcommonnode=LengthCommonList(head);
 struct commonstr* curnode;
 if(++(*winy)>allcommonnode)
     {(*winy)=allcommonnode;
      return 0;
     }
 if((*winy)<=(*wintopy)+(*winheight)-1) return 0;
 else
     (*wintopy)++;
 curnode=FindCommonNode(*wintopy+*winheight-1,head);
 scroll(6,5,74,21,0,LIGHTGRAY);
 ShowCommonWinaLine(1,*winheight,*wintopy,curnode);
}


int keycommonwinleft(int* winx,int* wintopx,int* winwidth)
{
 (*winx)--;
 if((*winx)<1) (*winx)=1;
}

int keycommonwinright(int* winx,int* wintopx,int* winwidth)
{
 (*winx)++;
 if((*winx)>(*winwidth)) (*winx)=(*winwidth);
}




/**上翻页键**/
int keycommonpgup(int* winy,int* wintopy,int* winheight,struct commonstr* head)
{
 /*int allcommonnode=LengthCommonList(head);*/
 if(*wintopy==1) return 0;
 if((*wintopy-=(*winheight-1))>=1)
    *winy-=(*winheight-1);
 else
    {*wintopy=*winy=1;
     /*return 0;*/
    }
 ShowCommonWinaScreen(head,*wintopy,*winheight);
}

/**下翻页键**/
int keycommonpgdown(int* winy,int* wintopy,int*winheight,struct commonstr* head)
{
 int allcommonnode=LengthCommonList(head);
  /*如果已经是屏幕的最低行则返回*/
 if(allcommonnode<=*winheight) return;
 if(*wintopy+(*winheight-1)>=allcommonnode) return;
 *wintopy+=(*winheight-1);
 if(*wintopy+(*winheight-1)>=allcommonnode)
    {*wintopy=allcommonnode-(*winheight-1);
     *winy=allcommonnode;
    }
 else *winy+=(*winheight-1);
 ShowCommonWinaScreen(head,*wintopy,*winheight);
}



struct commonstr* FindPersonInfo(long personnum,struct personnode* personhead,struct dnode* bookhead)
{
 struct commonstr* commonhead=InitCommonList();
 struct personnode* curp=FindBorrowerNode(personnum,personhead);
 int   beyonddays;
 int   count=1;
 char  exchange[80];
 strcpy(commonhead->string,"    人员信息\r\n 借阅号码  姓名   超期        所借的书的名称");

 while(curp!=NULL)
    {
     if(curp->person.booknum==0) beyonddays=0;
     else beyonddays=beyondday(curp->person.borrowdate,bookhead);
     if(curp->person.borrowernum==personnum)
          {
           sprintf(exchange,"%08ld %-6s %3d %s",curp->person.borrowernum,curp->person.borrower,beyonddays,curp->person.bookname);
           InsertCommonNode(count++,exchange,commonhead);
           curp=curp->next;
          }
      else curp=curp->next;
     }
return(commonhead);
}



/*用于显示head链表中的内容,窗口标题放在head的头结点中*/
void CommonWin(struct commonstr* head)
{
 struct text_info ti;
 char block[4*71*20];
 int nodecount=LengthCommonList(head); /*链表的长度*/
 int key;
 int commonwinx=1,commonwiny=1,commonwintopx=1,commonwintopy=1;
 int commonwinheight=17,commonwinwidth=69;
 int firstshow=commonwinheight;

 light_mouse(OFF);
 gettextinfo(&ti);
 gettext(5,3,76,23,&block);
 window(6,4,76,23);
 textbackground(BLACK);
 clrscr();
 window(5,3,75,22);
 textbackground(CYAN);
 clrscr();
 textcolor(BLACK);
 gotoxy(20,1);
 cprintf("%s",head->string);   /*显示标题*/
 gotoxy(30,20);
 cprintf("ESC-退出  方向键移动   共有%3d条信息",nodecount);
 textcolor(LIGHTGREEN);
 textbackground(BROWN);
 gotoxy(57,1);
 cprintf("上翻页");
 gotoxy(64,1);
 cprintf("下翻页");

 window(6,5,74,21);
 textcolor(BLACK);
 textbackground(LIGHTGRAY);
 clrscr();
 light_mouse(ON);

 if(nodecount<commonwinheight) firstshow=nodecount;
 ShowCommonWinaScreen(head,commonwintopy,firstshow);

 while((key=get_key())!=ESC)
     {switch(key){
         case LEFT_BUTTON:
            if((mx/8>=35&&mx/8<=41)&&(my/8==21))
              goto overs;
            else if((mx/8>=58&&mx/8<=64)&&(my/8==2))
              goto choosepgup;
            else if((mx/8>=66&&mx/8<=72)&&my/8==2)
              goto choosepgdown;
            else break;
         case UP:
                    keycommonwinup(&commonwiny,&commonwintopy,&commonwinheight,head);break;
         case DOWN:keycommonwindown(&commonwiny,&commonwintopy,&commonwinheight,head);break;
         case RIGHT:keycommonwinright(&commonwinx,&commonwintopx,&commonwinwidth);break;
         case LEFT: keycommonwinleft(&commonwinx,&commonwintopx,&commonwinwidth);break;
         case PGUP:
       choosepgup:
                    keycommonpgup(&commonwiny,&commonwintopy,&commonwinheight,head);break;
         case PGDOWN:
       choosepgdown:
                    keycommonpgdown(&commonwiny,&commonwintopy,&commonwinheight,head);break;
        default:break;
      }
 gotoxy(commonwinx-commonwintopx+1,commonwiny-commonwintopy+1);
      }

overs:
 myputtext(5,3,76,23,block);
 window(ti.winleft,ti.wintop,ti.winright,ti.winbottom);
 textattr(ti.attribute);
 gotoxy(ti.curx,ti.cury);

}




/***根据书是否被借出来查找书<当YN为Y时,查看借出去的书,为N时查看没有被借出去的书***/
struct commonstr* SearchBookYN(struct dnode* bookhead,char YN)
{
 struct dnode* curp=bookhead->next;
 struct commonstr* searchhead=InitCommonList();
 int    count=1;

 char exchange[80];

 while(curp!=NULL)
    {
     if(curp->book.borrow_out[0]!=YN) curp=curp->next;
     else
         {
           sprintf(exchange,"%-3d  %2s   %s",curp->book.booknum,curp->book.borrow_out,curp->book.bookname);
           InsertCommonNode(count++,exchange,searchhead);
           curp=curp->next;
          }
     }
strcpy(searchhead->string,"图书借阅情况查询结果\r\n 书号 借出?       书名");
return(searchhead);
}



/**根据是否超期查找借书的人**/
struct commonstr* SearchPersonBeyond(struct personnode* personhead,struct dnode* head)
{
 struct personnode* curp=personhead->next;
 struct commonstr* searchhead=InitCommonList();
 int count=1;
 int beyonddays;/*超借时间*/
 char exchange[80];

 while(curp!=NULL)
    {
     if(curp->person.booknum==0) curp=curp->next;
     else
       {
         beyonddays=beyondday(curp->person.borrowdate,head);
         if((beyonddays<=0)||(beyonddays>400)) curp=curp->next;

⌨️ 快捷键说明

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