📄 bookms.c
字号:
}
printf("\nThere are %d matching records!\n", match_total);
if(match_total)
{
printf("Press P to continur, Press else key to return!\n");
ch = getch();
if(ch=='p'||ch=='P')
Search_By_BookID();
else
return;
}
else
{
printf("Press any key to continue!\n");
getch();
}
return;
}
/*******************************************************/
void Search_By_Press()
{
int i, loop, match_total=0;
char ch, instr[PRESSSZ], press_str[PRESSSZ], temp_str[PRESSSZ];
printf("Please Input Book'press's fullname(1~15 chars):\n");
gets(instr);
while(strlen(instr) > PRESSSZ-1)
{
printf("Wrong input, it is too long!\n");
printf("Please Input Book'press's fullname(1~15 chars):\n");
gets(instr);
}
sprintf(press_str, "%-15s", instr);
for(i=0; i<book_record_Total; i++)
{
loop = Load_Book_Record(i);
if(loop != 1)
continue;
strcpy(temp_str, cur_book_ptr->Press);
loop = strcmp(strlwr(temp_str), strlwr(press_str));
if(!loop)
{
match_total++;
if(match_total % PAGESIZE==1)
{
clrscr();
printf(" Number| Name | Writer | Press | Pub-Time |In-Lib\n");
printf("-------------------------------------------------------------------------------\n");
}
Display_Record(cur_book_ptr);
free(cur_book_ptr);
cur_book_ptr = NULL;
if(match_total % PAGESIZE==0)
{
printf("Press any key to the next page!\n");
getch();
}
}
}
printf("\nThere are %d matching records!\n", match_total);
if(match_total)
{
printf("Press P to continur, Press else key to return!\n");
ch = getch();
if(ch=='p'||ch=='P')
Search_By_BookID();
else
return;
}
else
{
printf("Press any key to continue!\n");
getch();
}
return;
}
/************************************************************/
/* Select a book and process this book */
void Select_And_Display(int num)
{
int loop;
if(num >= book_record_Total)
{
printf("The book is not exist!\n");
printf("Press any key to return:\n");
getch();
return;
}
else
{
loop = Load_Book_Record(num);
if(loop==-1)
{
printf("The book has been deleted! \n");
getch();
}
if(loop > 0)
{
Display_curBook_Detail();
printf("Press any key to continue!\n");
getch();
free(cur_book_ptr); /*释放指针 */
cur_book_ptr = NULL;
}
return;
}
}
/****************************************************/
void Display_curBook_Detail()
{
char num;
clrscr();
num = atoi(cur_book_ptr->rdID);
Load_Reader_Record(num);
printf("\n");
printf("\t\t The Book's Detailed Information \n");
printf("\t\t------------------------------------------\n");
printf("\t\t| Book ID : %s |\n", cur_book_ptr->bkID);
printf("\t\t| Book Name : %s |\n", cur_book_ptr->bkName);
printf("\t\t| Writer : %s |\n", cur_book_ptr->writer);
printf("\t\t| Press : %s |\n", cur_book_ptr->Press);
printf("\t\t| Publish Time : %s |\n", cur_book_ptr->pubTime);
if(cur_book_ptr->curStatus=='1')
{
printf("\t\t| Current Status : OUT |\n");
printf("\t\t------------------------------------------\n");
printf("\t\t Reader Information\n ");
printf("\t\t------------------------------------------\n");
printf("\t\t| Reader ID: %s |\n", cur_reader_ptr->rdID);
printf("\t\t| Reader Name: %s |\n", cur_reader_ptr->Name);
printf("\t\t| Reader Grade: %s |\n", cur_reader_ptr->Grade);
printf("\t\t| Reader Major: %s |\n", cur_reader_ptr->Major);
printf("\t\t------------------------------------------\n");
}
else
{
printf("\t\t| Current Status : IN |\n");
printf("\t\t------------------------------------------\n");
}
printf("\n");
free(cur_reader_ptr);
cur_reader_ptr = NULL;
return;
}
/*************************************************/
/* Display the list of all book */
void Display_Book_List()
{
int i, dsp_total=0;
int loop;
clrscr();
if(book_record_Total==0)
{
printf("There is no book!\n");
return;
}
for(i=0; i<book_record_Total; i++)
{
loop = Load_Book_Record(i);
if(loop != 1) continue;
dsp_total++;
if(dsp_total % PAGESIZE==1)
{
clrscr();
printf(" Number| Name | Writer | Press | Pub-Time |In-Lib\n");
printf("-------------------------------------------------------------------------------\n");
}
Display_Record(cur_book_ptr);
/*************释放指针(释放内存空间是很重要的)*************** */
/* ### my_debug printf("Release Memory:\n"); */
free(cur_book_ptr);
cur_book_ptr = NULL;
if(dsp_total % PAGESIZE==0)
{
printf("\nPress any key to the next page!\n");
getch();
}
}
loop = book_record_Total-book_delete_total;
printf("\nThere are %d books total.\n", loop);
return;
}
/************************************************************/
/* display one node pointed out by the parameter(new_node) */
void Display_Record(struct BookNode* new_node)
{
printf(" %s |", new_node->bkID);
printf("%s|", new_node->bkName);
printf("%s|", new_node->writer);
printf("%s|", new_node->Press);
printf(" %s |", new_node->pubTime);
if(new_node->curStatus=='1')
printf(" Out");
else
printf(" In");
printf("\n");
return;
}
/***********************************************/
void Lend_Book()
{
int num1, num2, loop;
const int max = ONCEMAX;
char stime_str[TIMESZ], etime_str[TIMESZ];
/* 读入读者证号 */
num1 = Get_Reader_ID();
if(num1==-1) /* 操作取消 */
return;
/* 看该读者是否存在 */
loop = Load_Reader_Record(num1);
if(loop != 1)
{
printf("The Reader is not exsit!\n");
printf("Press any key to return!\n");
getch();
return;
}
/* 载入借阅记录 */
Load_Lend_Record(num1);
/* 达到最大借书数目时,不能再借,返回 */
if(cur_lend_ptr->bkCount-48==max)
{
printf("Sorry! You have borrowed %d books!\n", max);
printf("You could not borrow anymore!\n");
printf("Press any key to return!\n");
getch();
return;
}
/* 读入书号 */
num2 = Get_Book_ID();
if(num2==-1) /* 操作取消 */
return;
/* 载入书目记录 */
loop = Load_Book_Record(num2);
if(loop==-1)
{
printf("Press any key to return!\n");
getch();
return;
}
/* 该书已经借出,不能再借,返回*/
if(cur_book_ptr->curStatus=='1')
{
printf("Error! The book is lended out!\n");
printf("Press any key to return!\n");
getch();
return;
}
/* 修改书目记录 */
cur_book_ptr->curStatus = '1';
strcpy(cur_book_ptr->rdID, cur_reader_ptr->rdID);
/* 修改借阅记录 */
cur_lend_ptr->bkCount++; /*借书书目加1*/
loop = cur_lend_ptr->bkCount-48;
strcpy(cur_lend_ptr->bkID[loop-1], cur_book_ptr->bkID);
/* 计算借书时间和还书时间 */
Calculate_Time(stime_str, etime_str);
strcpy(cur_lend_ptr->StartTime[loop-1], stime_str);
strcpy(cur_lend_ptr->EndTime[loop-1], etime_str);
/* 保存记录,将修改写入文件 */
Save_cur_Book_Node();
Save_cur_Lend_Node();
/* 释放指针 */
free(cur_book_ptr);
cur_book_ptr = NULL;
free(cur_lend_ptr);
cur_lend_ptr = NULL;
printf("Lend out successfully!\n");
getch();
return;
}
/*************************************************/
void Calculate_Time(char *startTime, char *endTime)
{
int loop;
char instr[TIMESZ], mon_str[TIMESZ], day_str[TIMESZ];
struct date *cur_date;
cur_date = (struct date *)malloc(sizeof(struct date));
/*自动获得当前日期作为借出时间 */
getdate(cur_date);
sprintf(instr, "%d", cur_date->da_year);
sprintf(mon_str, "%d", cur_date->da_mon);
sprintf(day_str, "%d", cur_date->da_day);
if(cur_date->da_mon < 10)
strcat(instr, "0");
strcat(instr, mon_str);
if(cur_date->da_day < 10)
strcat(instr, "0");
strcat(instr, day_str);
instr[TIMESZ-1] = '\0';
strcpy(startTime, instr);
/*由借出时间得出应还时间 */
loop = Days_Per_Month(cur_date->da_year, cur_date->da_mon); /* 计算当前月最大天数 */
cur_date->da_mon += (cur_date->da_day + MaxTime) / loop;
cur_date->da_day = (cur_date->da_day + MaxTime) % loop;
cur_date->da_year += cur_date->da_mon / 12;
cur_date->da_mon = cur_date->da_mon % 12;
sprintf(instr, "%d", cur_date->da_year);
sprintf(mon_str, "%d", cur_date->da_mon);
sprintf(day_str, "%d", cur_date->da_day);
if(cur_date->da_mon < 10)
strcat(instr, "0");
strcat(instr, mon_str);
if(cur_date->da_day < 10)
strcat(instr, "0");
strcat(instr, day_str);
strcpy(endTime, instr);
free(cur_date);
cur_date = NULL;
return;
}
/********************************************/
void Return_Book()
{
int temp, loop, i;
int num1, num2;
/* 读入要还的书号 */
num1 = Get_Book_ID();
if(num1==-1) /* 操作取消 */
return;
/* 载入书目记录 */
loop = Load_Book_Record(num1);
if(loop==-1)
{
printf("Press any key to return!\n");
getch();
return;
}
/* 该书已经在馆,返回错误 */
if(cur_book_ptr->curStatus=='0')
{
printf("Error! The book is in the library!\n");
printf("Press any key to return!\n");
getch();
return;
}
/* 获得该书当前的借阅者读者号 */
num2 = atoi(cur_book_ptr->rdID);
/* 载入借阅记录 */
Load_Lend_Record(num2);
if(loop==-1)
{
printf("Press any key to return!\n");
getch();
return;
}
/* 修改书目记录 */
cur_book_ptr->curStatus = '0';
strcpy(cur_book_ptr->rdID, "*****");
temp = cur_lend_ptr->bkCount-48; /* 借的书的数目 */
cur_lend_ptr->bkCount--; /*借书数目减1*/
/* 修改存放的所借的书目 */
if(temp==1)
{
strcpy(cur_lend_ptr->bkID[0], "*****");
strcpy(cur_lend_ptr->StartTime[0], "********");
strcpy(cur_lend_ptr->EndTime[0], "********");
}
if(temp > 1) /* 当借书数目大于1时,应在数组中找到该书 */
{
for(i=0; i<temp; i++)
{
loop = strcmp(cur_lend_ptr->bkID[i], cur_book_ptr->bkID);
if(loop==0)
{
if(i==temp-1) /* 该书为所借书中最后一本 */
{
strcpy(cur_lend_ptr->bkID[i], "*****");
strcpy(cur_lend_ptr->StartTime[i], "********");
strcpy(cur_lend_ptr->EndTime[i], "********");
}
else
{ /* 记录前移 */
for(; i<temp-1; i++)
{
strcpy(cur_lend_ptr->bkID[i], cur_lend_ptr->bkID[i+1]);
strcpy(cur_lend_ptr->StartTime[i], cur_lend_ptr->StartTime[i+1]);
strcpy(cur_lend_ptr->EndTime[i], cur_lend_ptr->EndTime[i+1]);
}
strcpy(cur_lend_ptr->bkID[temp-1], "*****");
strcpy(cur_lend_ptr->StartTime[temp-1], "********");
strcpy(cur_lend_ptr->EndTime[temp-1], "********");
}
break;
}
}
}
/* 保存记录,将修改写入文件 */
Save_cur_Book_Node();
Save_cur_Lend_Node();
/* 释放指针 */
free(cur_book_ptr);
cur_book_ptr = NULL;
free(cur_lend_ptr);
cur_lend_ptr = NULL;
printf("Return successfully!\n");
getch();
return;
}
/*****************************************************/
/* delete the book pointed out by pointer(cur_book_ptr) */
void Delete_Book()
{
int num, loop, step, result;
FILE *wfp;
num = Get_Book_ID();
if(num==-1) /* 操作取消 */
return;
loop = Load_Book_Record(num);
if(loop==-1)
{
printf("The book is not exsit!\n");
printf("Press any key to return!\n");
getch();
return;
}
/* 该书已经借出,不能删除,返回*/
if(cur_book_ptr->curStatus=='1')
{
printf("Sorry! The book is lended out, You can not delete it!\n");
printf("Press any key to return!\n");
getch();
return;
}
result = Delet_Verify();
if(result != 1)
{
printf("Delete Cancled!\n");
printf("Press any key to return!\n");
getch();
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -