?? 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 + -