void menu() { system("cls"); gotoxy(20,1); printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2 MAIN MENU \xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"); // Sleep(2000); int choice; gotoxy(20,3); printf("\xDB\xDB\xDB\xDB\xB2 1. Search Book\n"); gotoxy(20,5);//Sleep(1000); printf("\xDB\xDB\xDB\xDB\xB2 2. Add Book\n"); gotoxy(20,7);//Sleep(1000); printf("\xDB\xDB\xDB\xDB\xB2 3. Delete Book\n"); gotoxy(20,9);//Sleep(1000); printf("\xDB\xDB\xDB\xDB\xB2 4. View Booklist\n"); gotoxy(20,11);//Sleep(1000); printf("\xDB\xDB\xDB\xDB\xB2 5. Edit Book Records\n"); gotoxy(20,13);//Sleep(1000); printf("\xDB\xDB\xDB\xDB\xB2 6. Change Password\n"); gotoxy(20,15);//Sleep(1000); printf("\xDB\xDB\xDB\xDB\xB2 7. Close Application\n"); gotoxy(20,17); printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"); gotoxy(20,18); tym(); gotoxy(20,21); fflush(stdin); printf("Select an option: "); scanf("%d", &choice); switch(choice) { case 1: searchbook(); break; case 2: addbook(); break; case 3: deletebook(); break; case 4: viewlistbook(); break; case 5: editbookrecords(); break; case 6: passwordChange(); break; case 7: { closeapplication(); } default: { gotoxy(10,23); printf("\aWrong Entry!!Please re-entered correct option"); if(getch()) menu(); } } exit(0); }
/*--This Function is main USER INTERACTING FUNCTION--*/ void mainloop(void) { for(;;) { fflush(stdin); ch=tolower(getch()); if (ch==32) //SPACE DETECTED { if(recno>=0 && recno<maxrec) { if(tabview==0) { recno++; read_data(); clsview(); oneatime_show(); if(recno == maxrec) status("Database - Right Boundary."); else status("<space> Next Record ->"); } else status("<space> Switch to One a time view."); } } else if (ch==13) //Refresh { setscreen(); which_view(); status("<CR> Data Refreshed."); } else if (ch=='t') { if(tabview==0) { recold=recno; tabview=1; } else { tabview=0; } setscreen(); which_view(); status("<t> Switch between tab/oneatime view."); } else if (ch=='a') { if (view==1 && tabview==0) { recold=recno; recno=maxrec+1; clsview(); status("<a> Please Enter the Book Info."); addbook(1); //setscreen(); clsview(); oneatime_show(); //which_view(); //status("Press <H> For Immediate Help."); } else if (tabview==1) status("<a> Switch to one-a-time view."); else status("<a> You ar not ADMIN!!!."); } else if (ch=='e') //edit info { if (view==1) { status("Please Enter Records To Modify."); truefalse=editbook(); if(truefalse==0) //if strcmp didn't found records then comes here status("Sorry, book number didn't match with stored one."); } else if (tabview==1) status("<a> Switch to one-a-time view."); else status("<a> You ar not ADMIN!!!."); } else if (ch=='f') //edit info { if (view==1) { truefalse=searchbook(); if(truefalse==0) //if strcmp didn't found records then comes here status("Sorry, record not match."); else status("<a> You ar not ADMIN!!!."); } } else if (ch=='d') //delete { /*strcpy(tempo,book.bookno); ft=fopen("temp.sjb","wb"); rewind(fp); while(fread(&tmp,rec_size,1,fp)==1) { if(strcmp(tmp.bookno,tempo)!=0) {fwrite(&tmp,rec_size,1,ft); } else truefalse=0; } fclose(fp); fclose(ft); remove("library.sjb"); rename("temp.sjb","library.sjb"); fp=fopen("library.sjb","rb+"); recno=0; maxrec=0; read_data(); // Reads data at the initialization time to find maxrec--; if(truefalse==0)*/ status("<d> Record can't be deleted."); } else if(ch=='x') {html(1);} else if (ch==27) break; else if(ch==0) {//i.e ch==0 if extended code, ch2 = getch(); // read second code if(ch2==59) status("Function key 1"); else if(ch2==60) status("Function key 2"); else if(ch2==75)//LEFT ARROW { if(recno>0 && recno<=maxrec) { if(tabview==0) { recno--; read_data(); clsview(); oneatime_show(); if(recno==0) status("Database - Left Boundary."); else status("<l-arrow> <- Previous Record"); } else status("<space> Switch to One a time view."); } } else if(ch2==77) //Right Arrow { if(recno>=0 && recno<maxrec) { if(tabview==0) { recno++; read_data(); clsview(); oneatime_show(); if(recno == maxrec) status("Database - Right Boundary."); else status("<r-arrow> Next Record ->"); } else status("<r-arrow> Switch to One a time view."); } } else if(ch2==80) //Down arrow <p> { if (tabview==1) { if(row <13+25 || recno <maxrec) {row++;recno++; //if (row>=26) row=13; bulet(6,row); status("<d-arrow> Select Down"); } } else if(tabview==0) status("<d-arrow> Switch to tabular view."); else printer(1); } else if(ch2==72) //up arrow <h> { if (tabview==1) {if(row>13 && recno >1) {row--;recno--;} else row=13+25; bulet(6,row); status("<u-arrow> Select Up"); } else status("Please do some Hit n Trial First."); } else status("Under construction."); }//EXTENDED CODE SCANNED }//MAIN LOOP OF THE PROGRAMME }
void searchbook() { system("cls"); int d; char z; printf("******************************** Search Books **********************************"); gotoxy(15,3); printf("\xDB\xDB\xDB\xB2 1. Search By ID"); gotoxy(17,5); printf("\xDB\xDB\xDB\xB2 2. Search By Name"); gotoxy(19,7); printf("\xDB\xDB\xDB\xB2 3. Search By Author"); gotoxy( 21,10); printf("Enter Your Choice:"); fp=fopen("quizdata.txt","rb+"); rewind(fp); int ch; scanf("%d",&ch); fflush(stdin); switch(ch) { case 1: { system("cls"); gotoxy(25,4); printf("****Search Books By Id****"); gotoxy(20,5); printf("Enter the book id:"); scanf("%d",&d); while(fread(&add,sizeof(add),1,fp)==1) { if(add.book_id==d) { Sleep(500); gotoxy(20,7); printf("The Book is available"); gotoxy(18,8); printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"); gotoxy(18,9); printf("\xB2 ID:%d",add.book_id);gotoxy(56,9);printf("\xB2"); gotoxy(18,10); printf("\xB2 Name:%s",add.bookname);gotoxy(56,10);printf("\xB2"); gotoxy(18,11); printf("\xB2 Author:%s ",add.author);gotoxy(56,11);printf("\xB2"); gotoxy(18,12); printf("\xB2 Qantity:%d ",add.quantity);gotoxy(56,12);printf("\xB2"); gotoxy(18,13); printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"); findbook='t'; } } if(findbook!='t') { gotoxy(20,8); printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"); gotoxy(20,9);printf("\xB2"); gotoxy(38,9);printf("\xB2"); gotoxy(20,10); printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"); gotoxy(22,9);printf("\aNo Record Found"); } gotoxy(20,17); printf("Try another search?(Y/N)"); if(getch()=='y') searchbook(); else menu(); break; } case 2: { char s[15]; system("cls"); gotoxy(25,4); printf("****Search Books By Name****"); gotoxy(20,5); printf("Enter Book Name:"); gets(s); int d=0; int index=7; while(fread(&add,sizeof(add),1,fp)==1) { if(findSubstring(add.bookname,s)!=0) { gotoxy(20,index++); if(d==0) printf("The Book is available"); gotoxy(20,index++); printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"); gotoxy(20,index++); printf("\xB2 ID:%d",add.book_id);gotoxy(47,9);printf("\xB2"); gotoxy(20,index++); printf("\xB2 Name:%s",add.bookname);gotoxy(47,10);printf("\xB2"); gotoxy(20,index++); printf("\xB2 Author:%s",add.author);gotoxy(47,11);printf("\xB2"); gotoxy(20,index++); printf("\xB2 Qantity:%d",add.quantity);gotoxy(47,12);printf("\xB2"); gotoxy(20,index++); printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"); d++; } } if(d==0) { gotoxy(20,8); printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"); gotoxy(20,9);printf("\xB2"); gotoxy(38,9);printf("\xB2"); gotoxy(20,10); printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"); gotoxy(22,9);printf("\aNo Record Found"); } gotoxy(20,index++); printf("Try another search?(Y/N)"); if(getch()=='y') searchbook(); else menu(); break; } case 3: { char s[15]; system("cls"); gotoxy(25,4); printf("****Search Books By Author****"); gotoxy(20,5); printf("Enter Author Name:"); gets(s); int d=0; int index=7; while(fread(&add,sizeof(add),1,fp)==1) { if(findSubstring(add.author,s)!=0) //checks whether a.name is equal to s or not { gotoxy(20,index++); if(d==0) printf("The Book is available"); gotoxy(20,index++); printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"); gotoxy(20,index++); printf("\xB2 ID:%d",add.book_id);gotoxy(47,9);printf("\xB2"); gotoxy(20,index++); printf("\xB2 Name:%s",add.bookname);gotoxy(47,10);printf("\xB2"); gotoxy(20,index++); printf("\xB2 Author:%s",add.author);gotoxy(47,11);printf("\xB2"); gotoxy(20,index++); printf("\xB2 Qantity:%d",add.quantity);gotoxy(47,12);printf("\xB2"); gotoxy(20,index++); printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"); d++; } } if(d==0) { gotoxy(20,8); printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"); gotoxy(20,9);printf("\xB2"); gotoxy(38,9);printf("\xB2"); gotoxy(20,10); printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"); gotoxy(22,9);printf("\aNo Record Found"); } gotoxy(20,index++); printf("Try another search?(Y/N)"); if(getch()=='y') searchbook(); else menu(); break; } default : getch(); searchbook(); } fclose(fp); }