C Program to Build Prison Management System Full Project For Beginners

  • Post author:
  • Post category:c++
  • Post comments:0 Comments

 

 

main.c

 

 

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

void addrecord();

void viewrecord();

void editrecord();

void searchrecord();

void deleterecord();

void login();

struct record

{
	char id[10];
    
    char name[30];
    
    char age[6];
    
    char gender[10];
    
    char weight[20];
    
    char height[20];
    
    char haircolor[20];
    
    char eyecolor[20];
    
    char crime[40];
    
    char convictedf[20];
    
    char court[20];
	
	char lawyer[20]; 
    
    char punishment[50];
    
    char punishments[20];
    
    char punishmente[20];
    
    char emergencyc[20];
    
    char emergencyr[20];
    
    char emergencyn[20];

} a;

int main()
{
	login();

    int ch;
    printf("\n\n\t***********************************\n");
    printf("\t\t*PRISONER RECORD*\n");
    printf("\t***********************************");

    while(1)
    {

        printf("\n\n\t\tMAIN MENU:");
        printf("\n\n\t[1]\tADD RECORD\t");
        printf("\n\t[2]\tSEARCH RECORD\t");
        printf("\n\t[3]\tEDIT RECORD\t");
        printf("\n\t[4]\tVIEW RECORD\t");
		printf("\n\t[6]DELETE RECORD\t");
        printf("\n\t[5]\tEXIT\t\t");
        printf("\n\n\tENTER YOUR CHOICE:");
        scanf("%d",&ch);

        switch(ch)
        {

	        case 1:
	            addrecord();
	            break;
	
	        case 2:
	            searchrecord();
	            break;
	
	        case 3:
	            editrecord();
	            break;
	
	        case 4:
	            viewrecord();
	            break;
	            
	        case 6:
	            deleterecord();
	            break;
	
	        case 5:
	        	system("cls");
	            getch();
	            exit(0);
	
	        default:
	            printf("\nYOU ENTERED WRONG CHOICE.");
	            printf("\nPRESS ANY KEY TO TRY AGAIN");
	            getch();
	            break;
        }
        system("cls");
    }
    return 0;
}

//*********************************************************
/**************** ADDING FUNCTION************************/
//*********************************************************
void addrecord()
{
    system("cls");
    FILE *fp ;
    char another = 'Y' ,id[10];
    char filename[30];
    int choice;

    printf("\n\n\t\t***************************\n");
    printf("\t\t* WELCOME TO THE ADD MENU *");
    printf("\n\t\t***************************\n\n");
    printf("\n\n\tENTER FIRST NAME OF PRISONER:\t");
    fflush(stdin);
    gets(filename);

    fp = fopen ("prisonrecord", "ab+" ) ;

    if ( fp == NULL )
    {

        fp=fopen("prisonrecord","wb+");
        if(fp==NULL)
        {

            printf("\nSYSTEM ERROR...");
            printf("\nPRESS ANY KEY TO EXIT");
            getch();
            return ;

        }
    }

    while ( another == 'Y'|| another=='y' )

    {
        choice=0;
        fflush(stdin);
        
		printf ( "\n\tENTER PRISONER ID:\t");
        scanf("%s",id);
        
		rewind(fp);

        while(fread(&a,sizeof(a),1,fp)==1)
        {
            if(strcmp(a.id,id)==0)
            {

                printf("\n\tTHE RECORD ALREADY EXISTS.\n");
                choice=1;

            }

        }

        if(choice==0)
        {

            strcpy(a.id,id);

            printf("\tENTER PRISONER NAME: ");
            fflush(stdin);
            gets(a.name);
            
			printf("\tENTER GENDER: ");
            gets(a.gender);
            fflush(stdin);

            printf("\tENTER AGE: ");
            gets(a.age);
            fflush(stdin);

            printf("\tENTER WEIGHT: ");
            gets(a.weight);
            fflush(stdin);
            
            printf("\tENTER HEIGHT: ");
            gets(a.height);
 			fflush(stdin);
           
            printf("\tENTER HAIRCOLOR: ");
            gets(a.haircolor);
            fflush(stdin);
            
            printf("\tENTER EYECOLOR: ");
            gets(a.eyecolor);
            fflush(stdin);
            
            printf("\tENTER CRIME: ");
            gets(a.crime);
            fflush(stdin);
            
            printf("\tENTER THE PLACE WHERE THE PRISONER WAS CONVICTED: ");
            gets(a.convictedf);
            fflush(stdin);
            
            printf("\tENTER COURT: ");
            gets(a.court);
            fflush(stdin);
            
            printf("\tENTER LAWYER: ");
            gets(a.lawyer);
            fflush(stdin);
            
            printf("\tENTER CONVICTION: ");
            gets(a.punishment);
            fflush(stdin);
            
            printf("\tENTER THE DATE PUNISHMENT STARTED AT: ");
            gets(a.punishments);
            fflush(stdin);
            
            printf("\tENTER THE DATE PUNISHMENT ENDS AT: ");
            gets(a.punishmente);
            fflush(stdin);
            
            printf("\tENTER NAME OF EMERGENCY CONTACT: ");
            gets(a.emergencyc);
            fflush(stdin);
            
            printf("\tENTER RELATION OF EMERGENCY CONTACT WITH PRISONER: ");
            gets(a.emergencyr);
            fflush(stdin);
            
            printf("\tENTER PHONE NUMBER OF EMERGENCY CONTACT: ");
            gets(a.emergencyn);
            
            fwrite ( &a, sizeof ( a ), 1, fp ) ;
            printf("\nYOUR RECORD IS ADDED...\n");

        }

        printf ( "\n\tADD ANOTHER RECORD...(Y/N) \t" ) ;
        fflush ( stdin ) ;
        another = getch( ) ;

    }
    fclose ( fp ) ;
    printf("\n\n\tPRESS ANY KEY TO EXIT...");
    getch();

}


//***********************************************************
/**************** SEARCHING FUNCTION************************/
//***********************************************************
void searchrecord()
{
	system("cls");
    FILE *fp ;
	char id[16],choice,filename[14];
    int ch;

    printf("\n\n\t\t*******************************\n");
    printf("\t\t* HERE IS THE SEARCHING MENU *");
    printf("\n\t\t*******************************\n\n");

    do
	{
        
		printf("\n\tENTER THE PRISONER NAME TO BE SEARCHED:");
        fflush(stdin);
        gets(filename);

        fp = fopen ( "prisonrecord", "rb" ) ;


        //system("cls");
    	
    		printf("\n\tENTER PRISONER ID:");
            gets(id);
            system("cls");
            printf("\nTHE WHOLE RECORD IS:");
 
            while ( fread ( &a, sizeof ( a ), 1, fp ) == 1 )

          //{
          if(strcmpi(a.id,id)==0)
               { printf("\n");
                printf("\nPRISONER'S NAME IS: %s",a.name);
                printf("\nPRISONER'S GENDER IS: %s",a.gender);
                printf("\nPRISONER'S AGE IS: %s",a.age);
                printf("\nPRISONER'S WEIGHT IS: %s",a.weight);
                printf("\nPRISONER'S HEIGHT IS: %s",a.height);
                printf("\nPRISONER'S HAIRCOLOR IS: %s",a.haircolor);
				printf("\nPRISONER'S EYECOLOR IS: %s",a.eyecolor);
                printf("\nPRISONER'S CRIME IS: %s",a.crime);
                printf("\nTHE PLACE WHERE THE PRISONER WAS CONVICTED IS: %s",a.convictedf);
                printf("\nCOURT IS: %s",a.court);
                printf("\nPRISONER'S LAWYER IS: %s",a.lawyer);
                printf("\nPRISONER'S CONVICTION IS: %s",a.punishment);
                printf("\nTHE DATE PUNISHMENT STARTED AT IS: %s",a.punishments);
                printf("\nTHE DATE PUNISHMENT ENDS AT IS: %s",a.punishmente);
                printf("\nPRISONER'S EMERGENCY CONTACT IS: %s",a.emergencyc);
                printf("\nRELATION OF EMERGENCY CONTACT WITH PRISONER IS: %s",a.emergencyr);
                printf("\nEMERGENCY CONTACT'S PHONE NUMBER IS: %s",a.emergencyn);
                printf("\n");
            }

           // }
            

        printf("\n\nWOULD YOU LIKE TO CONTINUE VIEWING...(Y/N):");
        fflush(stdin);

        scanf("%c",&choice);

    }
    while(choice=='Y'||choice=='y');

    fclose ( fp) ;
	getch();
    return ;
getch();
}


//*********************************************************
/**************** EDITING FUNCTION************************/
//*********************************************************

void editrecord()
{
    system("cls");
    FILE *fp ;
    char id[10],choice,filename[14];
    int num,count=0;

    printf("\n\n\t\t*******************************\n");
    printf("\t\t* WELCOME TO THE EDITING MENU *");
    printf("\n\t\t*******************************\n\n");

    do
    {
        printf("\n\tENTER THE PRISONER NAME TO BE EDITED:");
        fflush(stdin);
        gets(filename);

        printf("\n\tENTER ID:");
    	gets(id);
        fp = fopen ( "prisonrecord", "rb+" ) ;

        /*if ( fp == NULL )
        {
            printf( "\nRECORD DOES NOT EXIST:" ) ;
            printf("\nPRESS ANY KEY TO GO BACK");
            getch();
            return;
        }*/

        while ( fread ( &a, sizeof ( a ), 1, fp ) == 1 )
        {

            if(strcmp(a.id,id)==0)
            {

                printf("\nYOUR OLD RECORD WAS AS:");
                printf("\nPRISONER'S NAME: %s",a.name);
                printf("\nPRISONER'S GENDER: %s",a.gender);
                printf("\nPRISONER'S AGE: %s",a.age);
                printf("\nPRISONER'S WEIGHT: %s",a.weight);
                printf("\nPRISONER'S HEIGHT: %s",a.height);
                printf("\nPRISONER'S HAIRCOLOR: %s",a.haircolor);
				printf("\nPRISONER'S EYECOLOR: %s",a.eyecolor);
                printf("\nPRISONER'S CRIME: %s",a.crime);
                printf("\nTHE PLACE WHERE THE PRISONER WAS CONVICTED: %s",a.convictedf);
                printf("\nCOURT: %s",a.court);
                printf("\nPRISONER'S LAWYER: %s",a.lawyer);
                printf("\nPRISONER'S CONVICTION: %s",a.punishment);
                printf("\nTHE DATE PUNISHMENT STARTED AT: %s",a.punishments);
                printf("\nTHE DATE PUNISHMENT ENDS AT: %s",a.punishmente);
                printf("\nPRISONER'S EMERGENCY CONTACT: %s",a.emergencyc);
                printf("\nRELATION OF EMERGENCY CONTACT WITH PRISONER: %s",a.emergencyr);
                printf("\nEMERGENCY CONTACT'S PHONE NUMBER: %s",a.emergencyn);
                
            
                
                printf("\n\n\t\tWHAT WOULD YOU LIKE TO EDIT..");
                
                
                
                printf("\n1.NAME.");
                printf("\n2.GENDER.");
                printf("\n3.AGE.");
                printf("\n4.WEIGHT.");
                printf("\n5.HEIGHT.");
                printf("\n6.HAIRCOLOR.");
                printf("\n7.EYECOLOR.");
                printf("\n8.CRIME.");
                printf("\n9.PLACE WHERE THE PRISONER WAS CONVICTED.");
                printf("\n10.COURT.");
                printf("\n11.LAWYER.");
                printf("\n12.CONVICTION.");
                printf("\n13.STARTING DATE OF PUNISHMENT.");
                printf("\n14.ENDING DATE OF PUNISHMENT.");
                printf("\n15.EMERGENCY CONTACT.");
                printf("\n16.RELATION OF EMERGENCY CONTACT.");
                printf("\n17.EMERGENCY CONTACT'S PHONE NUMBER.");
                printf("\n18.WHOLE RECORD.");
                printf("\n19.GO BACK TO MAIN MENU.");
                
                do
                {

                    printf("\n\tENTER YOUR CHOICE:");
                    fflush(stdin);
                    scanf("%d",&num);
                    fflush(stdin);
                    
                    switch(num)
                    {

                    case 1:
                        printf("\nENTER THE NEW DATA:");
                        printf("\nNAME:");
                        gets(a.name);
                        break;

                    case 2:
                        printf("\nENTER THE NEW DATA:");
                        printf("\nGENDER:");
                        gets(a.gender);
                        break;

                    case 3:
                        printf("\nENTER THE NEW DATA:");
                        printf("\nAGE:");
                        gets(a.age);
                        break;

                    case 4:
                        printf("\nENTER THE NEW DATA:");
                        printf("\nWEIGHT:");
                        gets(a.weight);
                        break;

                    case 5:
                        printf("ENTER THE NEW DATA:");
                        printf("\nHEIGHT:");
                        gets(a.height);
                        break;

                    case 6:
                        printf("ENTER THE NEW DATA:");
                        printf("\nHAIRCOLOR:");
                        gets(a.haircolor);
                        break;

                    case 7:
                        printf("ENTER THE NEW DATA:");
                        printf("\nEYECOLOR:");
                        gets(a.eyecolor);
                        break;

                    case 8:
                        printf("ENTER THE NEW DATA:");
                        printf("\nCRIME:");
                        gets(a.crime);
                        break;

                    case 9:
                        printf("ENTER THE NEW DATA:");
                        printf("\nPLACE:");
                        gets(a.convictedf);
                        break;

                    case 10:
                        printf("ENTER THE NEW DATA:");
                        printf("\nCOURT:");
                        gets(a.court);
                        break;

                    case 11:
                        printf("ENTER THE NEW DATA:");
                        printf("\nLAWYER:");
                        gets(a.lawyer);
                        break;

                    case 12:
                        printf("ENTER THE NEW DATA:");
                        printf("\nCONVICTION:");
                        gets(a.punishment);
                        break;

                    case 13:
                        printf("ENTER THE NEW DATA:");
                        printf("\nSTARTING DATE OF PUNISHMENT:");
                        gets(a.punishments);
                        break;

                    case 14:
                        printf("ENTER THE NEW DATA:");
                        printf("\nENDING DATE OF PUNISHMENT:");
                        gets(a.punishmente);
                        break;

                    case 15:
                        printf("ENTER THE NEW DATA:");
                        printf("\nEMERGENCY CONTACT:");
                        gets(a.emergencyc);
                        break;

                    case 16:
                        printf("ENTER THE NEW DATA:");
                        printf("\nRELATION OF EMERGENCY CONTACT:");
                        gets(a.emergencyr);
                        break;

                    case 17:
                        printf("ENTER THE NEW DATA:");
                        printf("\nPHONE NUMBER OF EMERGENCY CONTACT:");
                        gets(a.emergencyc);
                        break;

                    case 18:
                    	printf("ENTER THE NEW DATA:");
                        printf("\tPRISONER NAME:");
			            gets(a.name);		
						printf("\tGENDER:");
			            gets(a.gender);			
			            printf("\tAGE:");
			            gets(a.age);
			            printf("\tWEIGHT:");
			            gets(a.weight);
			            printf("\tHEIGHT:");
			            gets(a.height);
			            printf("\tHAIRCOLOR:");
			            gets(a.haircolor);
			            printf("\tEYECOLOR:");
			            gets(a.eyecolor);
			            printf("\tCRIME:");
			            gets(a.age);
			            printf("\tTHE PLACE WHERE THE PRISONER WAS CONVICTED:");
			            gets(a.convictedf);
			            printf("\tCOURT:");
			            gets(a.court);
			            printf("\tLAWYER:");
			            gets(a.lawyer);
			            printf("\tCONVICTION:");
			            gets(a.punishment);
			            printf("\tTHE DATE PUNISHMENT STARTED AT:");
			            gets(a.punishments);
			            printf("\tTHE DATE PUNISHMENT ENDS AT:");
			            gets(a.punishmente);
			            printf("\tNAME OF EMERGENCY CONTACT:");
			            gets(a.emergencyc);
			            printf("\tRELATION OF EMERGENCY CONTACT WITH PRISONER:");
			            gets(a.emergencyr);
			            printf("\tPHONE NUMBER OF EMERGENCY CONTACT:");
			            gets(a.emergencyn);
                        break;

                    case 19:
                        printf("\nPRESS ANY KEY TO GO BACK...\n");
                        getch();
                        return ;
                        break;

                    default:
                        printf("\nYOU TYPED SOMETHING ELSE...TRY AGAIN\n");
                        break;

                    }

                }
                while(num<1||num>20);

                fseek(fp,-sizeof(a),SEEK_CUR);

                fwrite(&a,sizeof(a),1,fp);

                fseek(fp,-sizeof(a),SEEK_CUR);

                fread(&a,sizeof(a),1,fp);

                choice=5;

                break;

            }
        }

        if(choice==5)

        {

            system("cls");

            printf("\n\t\tEDITING COMPLETED...\n");
            printf("--------------------\n");
            printf("THE NEW RECORD IS:\n");
            printf("--------------------\n");
            printf("\nPRISONER'S NAME IS: %s",a.name);
            printf("\nPRISONER'S GENDER IS: %s",a.gender);
            printf("\nPRISONER'S AGE IS: %s",a.age);
            printf("\nPRISONER'S WEIGHT IS: %s",a.weight);
            printf("\nPRISONER'S HEIGHT IS: %s",a.height);
            printf("\nPRISONER'S HAIRCOLOR IS: %s",a.haircolor);
			printf("\nPRISONER'S EYECOLOR IS: %s",a.eyecolor);
            printf("\nPRISONER'S CRIME IS: %s",a.crime);
            printf("\nTHE PLACE WHERE THE PRISONER WAS CONVICTED IS: %s",a.convictedf);
            printf("\nCOURT IS: %s",a.court);
            printf("\nPRISONER'S LAWYER IS: %s",a.lawyer);
    		printf("\nPRISONER'S CONVICTION IS: %s",a.punishment);
        	printf("\nTHE DATE PUNISHMENT STARTED AT IS: %s",a.punishments);
            printf("\nTHE DATE PUNISHMENT ENDS AT IS: %s",a.punishmente);
            printf("\nPRISONER'S EMERGENCY CONTACT IS: %s",a.emergencyc);
            printf("\nRELATION OF EMERGENCY CONTACT WITH PRISONER IS: %s",a.emergencyr);
            printf("\nEMERGENCY CONTACT'S PHONE NUMBER IS: %s",a.emergencyn);

            fclose(fp);

            printf("\n\n\tWOULD YOU LIKE TO EDIT ANOTHER RECORD.(Y/N)");
            scanf("%c",&choice);
            count++;

        }
        else
        {

            printf("\nTHE RECORD DOES NOT EXIST::\n");
            printf("\nWOULD YOU LIKE TO TRY AGAIN...(Y/N)");
        	scanf("%c",&choice);

        }
    }
    while(choice=='Y'||choice=='y');

    fclose ( fp ) ;
    printf("\tPRESS ENTER TO EXIT EDITING MENU.");
    getch();

}

//*********************************************************
/**************** VIEWING FUNCTION************************/
//*********************************************************

void viewrecord()
{
    system("cls");
    FILE *fp;
    //struct record a;
    char filename[30];
    
    printf("\n\n\t\t***************************\n");
    printf("\t\t   * LIST OF PRISONERS *");
    printf("\n\t\t***************************\n\n");
    
    fp=fopen("prisonrecord","rb");
    rewind(fp);
    while((fread(&a,sizeof(a),1,fp))==1)
    {
    	printf("||NOTE:-PRESS ENTER KEY TO LOAD OTHER RECORDS||\n");
    	printf("\nPRISONER'S ID IS: %s\n",a.id);
        printf("\nPRISONER'S NAME IS: %s",a.name);
        printf("\nPRISONER'S GENDER IS: %s",a.gender);
        printf("\nPRISONER'S AGE IS: %s",a.age);
        printf("\nPRISONER'S WEIGHT IS: %s",a.weight);
        printf("\nPRISONER'S HEIGHT IS: %s",a.height);
        printf("\nPRISONER'S HAIRCOLOR IS: %s",a.haircolor);
		printf("\nPRISONER'S EYECOLOR IS: %s",a.eyecolor);
        printf("\nPRISONER'S CRIME IS: %s",a.crime);
        printf("\nTHE PLACE WHERE THE PRISONER WAS CONVICTED IS: %s",a.convictedf);
        printf("\nCOURT IS: %s",a.court);
        printf("\nPRISONER'S LAWYER IS: %s",a.lawyer);
        printf("\nPRISONER'S CONVICTION IS: %s",a.punishment);
        printf("\nTHE DATE PUNISHMENT STARTED AT IS: %s",a.punishments);
        printf("\nTHE DATE PUNISHMENT ENDS AT IS: %s",a.punishmente);
        printf("\nPRISONER'S EMERGENCY CONTACT IS: %s",a.emergencyc);
        printf("\nRELATION OF EMERGENCY CONTACT WITH PRISONER IS: %s",a.emergencyr);
        printf("\nEMERGENCY CONTACT'S PHONE NUMBER IS: %s",a.emergencyn);
        getch();
     printf("\n\n");   
        
    }
    fclose(fp);
	getch();
	
}


/*********************************************************/
/**************** DELETING FUNCTION************************/
/*********************************************************/

void deleterecord()
{
    system("cls");
    FILE *fp,*ft ;
    struct record file ;
    char prisonername[15],another = 'Y' ,id[16];;
    int choice,check;
    int j=0;
    char pass[8];

    printf("\n\n\t\t*************************\n");
    printf("\t\t* WELCOME TO DELETE MENU*");
    printf("\n\t\t*************************\n\n");
    
//    printf("\nENTER PASSWORD\n");
//    int i;
//    for(  i=0;i<4;i++ )
//    {
//    	pass[i]=getch();
//    	printf("*");
//	}
//	if (strcmpi(pass,"pass")==0)
//	{
//	
//		printf("\n\t\t*ACCESS GRANTED*\n\n");
//	   while ( another == 'Y' || another == 'y' )
//	    {
	       
	    	system("cls");
			fflush(stdin);
			printf("\n");
			//printf("\n\tENTER THE NAME OF PRISONER TO BE DELETED:");
	        //gets(prisonername);
	        fp = fopen ("prisonrecord", "rb" ) ;
	        if ( fp == NULL )
            {
                printf("\nTHE FILE DOES NOT EXIST");
                printf("\nPRESS ANY KEY TO GO BACK.");
                getch();
                return ;
			}
			ft=fopen("temp","wb");
			
			if(ft==NULL)
            {
            	printf("\nSYSTEM ERROR");
                printf("\nPRESS ANY KEY TO GO BACK");
                getch();
                return ;
            }
            printf("\n\tENTER THE ID OF RECORD TO BE DELETED:");
            fflush(stdin);
            gets(id);

    		while(fread(&file,sizeof(file),1,fp)==1)

            {

                if(strcmp(file.id,id)!=0)
                    fwrite(&file,sizeof(file),1,ft);
            }
	        fclose(ft);
	        fclose(fp);
	        remove("prisonrecord");
	        rename("temp","prisonrecord");
	        printf("\nDELETED SUCCESFULLY...");
	        getch();
	
	        printf("\n\tDO YOU LIKE TO DELETE ANOTHER RECORD.(Y/N):");
	        fflush(stdin);
	        scanf("%c",&another);
	
//	    }
//	
//
//	    printf("\n\n\tPRESS ANY KEY TO EXIT...");
//	    getch();
//    
//	}
//	else
//	{
//		printf("\nSorry!Invalid password\n");
//		exit(0);
//	}

}

void login()
{
	int a=0,i=0;
    char uname[10],c=' '; 
    char pword[10],code[10];
    char user[10]="user";
    char pass[10]="pass";
    do
{
	
    printf("\n  **************************  LOGIN FORM  **************************  ");
    printf(" \n                       ENTER USERNAME:-");
	scanf("%s", &uname); 
	printf(" \n                       ENTER PASSWORD:-");
	while(i<10)
	{
	    pword[i]=getch();
	    c=pword[i];
	    if(c==13) break;
	    else printf("*");
	    i++;
	}
	pword[i]='\0';
	//char code=pword;
	i=0;
	//scanf("%s",&pword); 
		if(strcmp(uname,"user")==0 && strcmp(pword,"pass")==0)
	{
	printf("  \n\n\n       WELCOME TO PRISON MANAGEMENT SYSTEM !! YOUR LOGIN IS SUCCESSFUL");
	printf("\n\n\n\t\t\t\tPress any key to continue...");
	getch();//holds the screen
	break;
	}
	else
	{
		printf("\n        SORRY !!!!  LOGIN IS UNSUCESSFUL");
		a++;
		
		getch();//holds the screen
		
	}
}
	while(a<=2);
	if (a>2)
	{
		printf("\nSorry you have entered the wrong username and password for four times!!!");
		
		getch();
		
		}
		system("cls");	
}

 

 

splashscreen.c

 

 

#include<stdio.h>
#include<bios.h>
#include<conio.h>
#include<ctype.h>
#include<graphics.h>
#include<string.h>
#include<stdlib.h>
#include<dos.h>
enum TYPE {
    PASSWORD,
    INT,
    FLOAT,
    TEXT,
    ALL,
};
union REGS i,o;

int buttonm,xm,ym,gd=9,gm=1,close=1,set=1,midx,midy;

//declearation function
void getmousepos(int *buttonm,int *xm, int *ym);
void restrictmouse(int x1,int y1,int x2,int y2);
void showmouse();
int initmouse();
void setmousepos(int &xpos,int &ypos);
void hidemouse();
int menu(int);

void addrecord();
void viewrecord();
void editrecord();
void searchrecord();
void deleterecord();

void login();

int doctor();
void adddoc();
void deletedoc();
void searchdoc();
void welgr();
void userl();
void notice();
void setusrl();
void changeusrl();
void removeusrl();
int dropmenu(char menu[7][20],int x1,int y1,int x2,int y2,int opt);
void button(char name[15],int x1,int y1,int x2,int y2,int c);
void clrwin(int opt);
void drawwindow(char head[30],int x1, int y1, int x2, int y2, int c);
int program();
void managetype();
int about();
void input(int x,int y,char result[50],int limit ,int tc,int bkc,int type);
void inputbox(int x,int y,int limit,int bkc);
//end declearation
int main(){
    
    _setcursortype(0);
    initgraph(&gd,&gm,"..\\bgi");
    int menu1=-1;
    midx=getmaxx()/2;
    midy=getmaxy()/2;
    clrscr();
    //welgr();
    setfillstyle(1,BLUE);
    bar(0,0,getmaxx(),getmaxy());
    setcolor(3);
    settextstyle(2,0,5);
    settextjustify(CENTER_TEXT, TOP_TEXT);
    outtextxy(midx,0,"==== Prison Management System ====");
    settextjustify(LEFT_TEXT, TOP_TEXT);
    settextstyle(0,0,0);
    clrwin(2);
    restrictmouse(10,18,getmaxx()-10,getmaxy()-10);
    setmousepos(midx,midy);
    showmouse();
    getmousepos(&buttonm,&xm,&ym);
    menu(menu1);
    while(1){
        showmouse();
        getmousepos(&buttonm,&xm,&ym);
        if(buttonm==1){
            if(xm>=10&&xm<=34&&ym>=18&&ym<=32){
                menu1=0;
            }else if(xm>=35&&xm<=94&&ym>=18&&ym<=32){
                menu1=1;
            }else if(xm>=95&&xm<=169&&ym>=18&&ym<=32){
                menu1=2;
            }else if(xm>=170&&xm<=219&&ym>=18&&ym<=32){
                menu1=3;
            }else if(xm>=220&&xm<=269&&ym>=18&&ym<=32){
                menu1=4;
            }else menu1=-1;
            clrwin(1);
            menu(menu1);
            switch(menu1){
                case 0:program();break;
                case 1:doctor();break;
                case 2:about();break;
            }
        }
    }
    getch();
    closegraph();
    return(0);
}

int program(){
    int opt=-1,j;
    char menu[2][20]={"User Login >","Quit"};
    close=1;
    dropmenu(menu,10,33,131,76,opt);
    do{
        showmouse();
        getmousepos(&buttonm,&xm,&ym);
        if(xm>=10+10&&xm<=131-10&&ym>=33+8&&ym<=76-8&&buttonm==1){
            for(j=0;j<(76-33-8)/14;j++)
                if((ym-33-8)/14==j){
                    opt=j;
                    break;
                }
            dropmenu(menu,10,33,131,76,opt);
            switch(opt){
                case 0: userl();break;
                case 1: delay(100);cleardevice();closegraph();exit(0);
            }
        }else if(xm>=10&&xm<=34&&ym>=18&&ym<=32&&buttonm==1){
            dropmenu(menu,10,33,131,76,opt);
            continue;
        }else if(buttonm==1){
            break;
        }
    }while(close);
    return 0;
}

void userl(){
    int opt=-1,j;
    char menu[1][20]={"Set/Reset"};
    dropmenu(menu,132,41,229,98,opt);
    do{
        showmouse();
        getmousepos(&buttonm,&xm,&ym);
        if(xm>=132+10&&xm<=229-10&&ym>=41+8&&ym<=98-8&&buttonm==1){
            for(j=0;j<(98-41-8)/14;j++)
                if((ym-41-8)/14==j){
                    opt=j;
                    break;
                }
            dropmenu(menu,132,41,229,98,opt);
            delay(200);
            switch(opt){
                case 0: setusrl();break;
            }
        }else if(buttonm==1){
            break;
        }
    }while(close);
    clrwin(1);
}

void setusrl(){
    char head[30]="SET USER LOGIN";
    char usr[30]="",pwd[30]="",code[30]="";
    int a=midx/2+15+textwidth("Program Code : ");
    set=1;
    clrwin(2);
    drawwindow(head, midx/2, midy/2, (getmaxx()*3)/4, (getmaxy()*3)/4,1 );
    button("Set",midx+30,midy*3/2-22,midx+90,midy*3/2-8,7);
    button("Cancel",midx-90,midy*3/2-22,midx-30,midy*3/2-8,7);
    setcolor(15);moveto(midx/2+15,midy-26);
    outtext("Program Code :");inputbox(a,midy-26,15,15);
    setcolor(15);moveto(midx/2+15,midy-7);
    outtext("Username     :");inputbox(a,midy-7,15,15);
    setcolor(15);moveto(midx/2+15,midy+12);
    outtext("Password     :");inputbox(a,midy+12,15,15);
    do{
        getmousepos(&buttonm,&xm,&ym);
        if(buttonm==1){
            if(xm>=a-2&&xm<=a+15*8+1&&ym>=midy-26-2&&ym<=midy-26+8){
                set=1;
            }
            if(xm>=a-2&&xm<=a+15*8+1&&ym>=midy-7-2&&ym<=midy-7+8){
                set=2;
            }
            if(xm>=a-2&&xm<=a+15*8+1&&ym>=midy+12-2&&ym<=midy+12+8){
                set=3;
            }
            if(xm>=midx-90&&ym>=midy*3/2-22&&xm<=midx-30&&ym<=midy*3/2-8){
                button("Cancel",midx-90,midy*3/2-22,midx-30,midy*3/2-8,3);
                delay(100);close=0;set=0;
            }
            
            if(xm>=midx+30&&ym>=midy*3/2-22&&xm<=midx+90&&ym<=midy*3/2-8&&strlen(code)>0&&strlen(usr)>0&&strlen(pwd)>0){
                button("Set",midx+30,midy*3/2-22,midx+90,midy*3/2-8,3);
                delay(100);notice();close=0;set=0;
            }
        }
        if(set==4)set=1;
        if(set==1)
            input(a,midy-26,code,15 ,0,15,INT);
        if(set==2)
            input(a,midy-7,usr,15 ,0,15,TEXT);
        if(set==3)
            input(a,midy+12,pwd,15 ,0,15,PASSWORD);
    }while(close);
}




void input(int x,int y,char result[50],int limit ,int tc,int bkc,int type){
    char ch,text[2]="";
    int i=0,f=-1,key,j;
    close=1;
    hidemouse();
    setcolor(3);
    rectangle(x-3,y-3,x+limit*8+2,y+9);
    setfillstyle(1,bkc);
    bar(x-2,y-2,x+limit*8+1,y+8);
    showmouse();
    settextstyle(0,0,1);
    i=strlen(result);
    moveto(x,y);
    if(i>0){
        setcolor(tc);
        hidemouse();
        if(type!=0)
            outtext(result);
        else
            for(j=0;j<i;j++)
                outtext("*");
        showmouse();
    }
    if(i>0&&strstr(result,".")!=0){
        for(j=0;j<i;j++)
            if(result[j]=='.')
                break;
        f=j;
    }
    while(kbhit()){
        getch();
    }
    do{
        do{     hidemouse();
            setcolor(tc);
            line(x+i*8,y-1,x+i*8,y+7);
            showmouse();
            getmousepos(&buttonm,&xm,&ym);
            if(buttonm==1){
                if(xm<x-2||xm>x+limit*8+1||ym<y-2||ym>y+8){
                    close=0;
                    hidemouse();
                    setcolor(bkc);
                    line(x+i*8,y-1,x+i*8,y+7);
                    showmouse();
                    goto end;
                }
            }
            if(kbhit()){
                hidemouse();
                setcolor(bkc);
                line(x+i*8,y-1,x+i*8,y+7);
                showmouse();
                break;
            }else
                delay(100);
            hidemouse();
            setcolor(bkc);
            line(x+i*8,y-1,x+i*8,y+7);
            showmouse();
            getmousepos(&buttonm,&xm,&ym);
            if(buttonm==1){
                if(xm<x-2||xm>x+limit*8+1||ym<y-2||ym>y+8){
                    close=0;
                    hidemouse();
                    setcolor(bkc);
                    line(x+i*8,y-1,x+i*8,y+7);
                    showmouse();
                    goto end;
                }
            }
            if(!kbhit())
                delay(100);
        }while(bioskey(1)==0);
        key = bioskey(0);
        ch = key & 0xFF;
        hidemouse();
        if(type==3&&(isalpha(ch)||ch == ' ')&&i<limit){
            result[i++] = ch;
            text[0] = ch;
            text[1] = '\0';
            setcolor(tc);
            outtext(text);
        }
        if((type==1&&isdigit(ch)&&i<limit)||(((ch == '.'&&f==-1)||isdigit(ch))&&type==2&&i<limit)){
            if(ch=='.')
                f=i;
            result[i++] = ch;
            text[0] = ch;
            text[1] = '\0';
            setcolor(tc);
            outtext(text);
        }
        if((type==0||type==4)&&(isalpha(ch)||(ch>='!'&&ch<='@')||ch==95||ch == ' ')&&i<limit){//ch=95=_
            result[i++] = ch;
            text[0] = ch;
            text[1] = '\0';
            setcolor(tc);
            if(type==4)
                outtext(text);
            else
                outtext("*");
        }
        
        if(ch == 8 && i > 0){
            i--;
            if(i==f)
                f=-1;
            text[0] = result[i];
            text[1] = '\0';
            result[i] = '\0';
            setcolor(bkc);
            moveto(x+(i)*(textwidth(text)),y);
            if(type!=0)
                outtext(text);
            else
                outtext("*");
            moveto(x+textwidth(result),y);
        }
        if(type==0&&key==20992){//key=20992:insert key
            moveto(x,y);
            hidemouse();
            for(int j=0;j<i;j++){
                setcolor(bkc);
                outtext("*");//delete by outtext in same color to bkc;
            }
            result[i]='\0';
            moveto(x,y);
            setcolor(tc);
            outtext(result);
            showmouse();
            delay(70);
            if(!kbhit())
                delay(270);
            moveto(x,y);
            hidemouse();
            setcolor(bkc);
            outtext(result);
            moveto(x,y);
            setcolor(0);
            for(j=0;j<i;j++)
                outtext("*");
            showmouse();
        }
    end: showmouse();
    }while(close==1);
    result[i]='\0';
    close=1;
    hidemouse();
    setfillstyle(1,bkc);
    rectangle(x-3,y-3,x+limit*8+2,y+9);
    setcolor(0);
    line(x-3,y-3,x-3,y+9);
    line(x-3,y-3,x+limit*8+2,y-3);
    showmouse();
}





void managetype(){
    int opt=-1,j;
    char menu[3][20]={"Add new","Delete","All types"};
    dropmenu(menu,301,83,397,140,opt);
    do{
        getmousepos(&buttonm,&xm,&ym);
        if(xm>=301+10&&xm<=397-10&&ym>=83+8&&ym<=140-8&&buttonm==1){
            for(j=0;j<(140-83-8)/14;j++)
                if((ym-83-8)/14==j){
                    opt=j;
                    break;
                }
            dropmenu(menu,301,83,397,140,opt);
            delay(200);
            switch(opt){
                case 0: notice();break;
                case 1: notice();break;
                case 2: notice();break;
            }
        }else if(buttonm==1){
            break;
        }
    }while(close);
    clrwin(1);
}



int prisoner(){
    char menu[5][20]={"Add","Update","Delete    >","Search    >","View"};
    int opt=-1,j;
    close=1;
    dropmenu(menu,35,33,150,118,opt);
    do{
        showmouse();
        getmousepos(&buttonm,&xm,&ym);
        if(xm>=35+10&&xm<=150-10&&ym>=33+8&&ym<=118-8&&buttonm==1){
            for(j=0;j<(118-33-8)/14;j++)
                if((ym-33-8)/14==j){
                    opt=j;
                    break;
                }
            dropmenu(menu,35,33,150,118,opt);
            switch(opt){
                case 0:adddoc();break;
                case 1:notice();break;
                case 2:deletedoc();break;
                case 3:searchdoc();break;
                case 4:notice();break;
            }
        }else if(xm>=35&&xm<=94&&ym>=18&&ym<=32&&buttonm==1){
            dropmenu(menu,35,33,150,118,opt);
            continue;
        }else if(buttonm==1){
            break;
        }
    }while(close);
    clrwin(1);
    return 1;
}




void adddoc(){
    char head[30]="SET USER LOGIN";
    char usr[30]="",pwd[30]="",code[30]="";
    int a=midx/8+15+textwidth("Program Code : ");
    set=1;
    clrwin(2);
    drawwindow(head, midx/8, midy/4+16, (getmaxx()*15)/16, (getmaxy()*7)/8+16,1 );
    button("Set",midx+30,midy*3/2-22,midx+90,midy*3/2-8,7);
    button("Cancel",midx-90,midy*3/2-22,midx-30,midy*3/2-8,7);
    setcolor(15);moveto(a-textwidth("Program Code : "),midy-26);
    outtext("Program Code :");inputbox(a,midy-26,15,15);
    setcolor(15);moveto(a-textwidth("Program Code : "),midy-7);
    outtext("Username     :");inputbox(a,midy-7,15,15);
    setcolor(15);moveto(a-textwidth("Program Code : "),midy+12);
    outtext("Password     :");inputbox(a,midy+12,15,15);
    do{
        getmousepos(&buttonm,&xm,&ym);
        if(buttonm==1){
            if(xm>=a-2&&xm<=a+15*8+1&&ym>=midy-26-2&&ym<=midy-26+8){
                set=1;
            }
            if(xm>=a-2&&xm<=a+15*8+1&&ym>=midy-7-2&&ym<=midy-7+8){
                set=2;
            }
            if(xm>=a-2&&xm<=a+15*8+1&&ym>=midy+12-2&&ym<=midy+12+8){
                set=3;
            }
            if(xm>=midx-90&&ym>=midy*3/2-22&&xm<=midx-30&&ym<=midy*3/2-8){
                button("Cancel",midx-90,midy*3/2-22,midx-30,midy*3/2-8,3);
                delay(100);close=0;set=0;
            }
            
            if(xm>=midx+30&&ym>=midy*3/2-22&&xm<=midx+90&&ym<=midy*3/2-8&&strlen(code)>0&&strlen(usr)>0&&strlen(pwd)>0){
                button("Set",midx+30,midy*3/2-22,midx+90,midy*3/2-8,3);
                delay(100);close=0;set=0;
            }
        }
        if(set==4)set=1;
        if(set==1)
            //inputdat(a,midy-26,day,mon,year ,0,15);
            input(a,midy-26,code,15 ,0,15,INT);
        if(set==2)
            input(a,midy-7,usr,15 ,0,15,TEXT);
        if(set==3)
            input(a,midy+12,pwd,15 ,0,15,PASSWORD);
    }while(close);
}




void deletedoc(){
    int opt=-1,j;
    char menu[3][20]={"By ID","By Name"};
    dropmenu(menu,151,69,237,112,opt);
    do{
        getmousepos(&buttonm,&xm,&ym);
        if(xm>=151+10&&xm<=237-10&&ym>=69+8&&ym<=112-8&&buttonm==1){
            for(j=0;j<(112-69-8)/14;j++)
                if((ym-69-8)/14==j){
                    opt=j;
                    break;
                }
            dropmenu(menu,151,69,237,112,opt);
            delay(200);
            switch(opt){
                case 0: notice();break;
                case 1: notice();break;
            }
        }else if(buttonm==1){
            break;
        }
    }while(close);
    clrwin(1);
}



void searchdoc(){
    int opt=-1,j;
    char menu[4][20]={"By ID","By Last Name","By First Name","By Specialty"};
    dropmenu(menu,151,83,285,154,opt);
    do{
        getmousepos(&buttonm,&xm,&ym);
        if(xm>=151+10&&xm<=285-10&&ym>=83+8&&ym<=154-8&&buttonm==1){
            for(j=0;j<(154-83-8)/14;j++)
                if((ym-83-8)/14==j){
                    opt=j;
                    break;
                }
            dropmenu(menu,151,83,285,154,opt);
            delay(200);
            switch(opt){
                case 0: notice();break;
                case 1: notice();break;
                case 2: notice();break;
                case 3: notice();break;
            }
        }else if(buttonm==1){
            break;
        }
    }while(close);
    clrwin(1);
}















int menu(int select){
    char ch, menu[3][20]={"\360","Prisoner","About"};
    char date[11];
    struct date da;
    hidemouse();
    setfillstyle(1,3);
    setcolor(15);
    line(9,17,631,17);
    line(9,17,9,32);
    setcolor(0);
    line(631,18,631,32);
    bar(10,18,630,32);
    getdate(&da);
    setcolor(0);
    outtextxy(20,21,menu[0]);
    outtextxy(40,21,menu[1]);
    outtextxy(105,21,menu[2]);
    showmouse();
    switch(select){
        case 0: hidemouse();
            setfillstyle(9,9);
            setcolor(0);
            line(10,18,34,18);
            line(10,18,10,31);
            setcolor(15);
            line(35,18,35,32);
            line(10,32,35,32);
            bar(11,19,34,31);
            outtextxy(20,21,menu[0]);
            break;
        case 1: hidemouse();
            setfillstyle(9,9);
            setcolor(0);
            line(35,18,35,31);
            line(35,18,95,18);
            setcolor(15);
            line(95,18,95,32);
            line(35,32,95,32);
            bar(36,19,94,31);
            outtextxy(40,21,menu[1]);
            break;
        case 2: hidemouse();
            setfillstyle(9,9);
            setcolor(0);
            line(95,18,169,18);
            line(95,18,95,32);
            setcolor(15);
            line(170,18,170,31);
            line(95,32,170,32);
            bar(96,19,169,31);
            outtextxy(105,21,menu[2]);
            break;
            
            
    }
    sprintf(date,"%02d/%02d/%d",da.da_day,da.da_mon,da.da_year);
    setcolor(0);
    outtextxy(550,21,date);
    showmouse();
    return select;
}



void welgr()
{
    /* COLORS (text mode)
     flflflflflflflflflflflflflflflflflflflfl≥Back-≥Fore-
     Constant     ≥Value≥grnd?≥grnd?
     ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÿÕÕÕÕÕÿÕÕÕÕÕÿÕÕÕÕÕ
     BLACK        ≥  0  ≥ Yes ≥ Yes
     BLUE         ≥  1  ≥ Yes ≥ Yes
     GREEN        ≥  2  ≥ Yes ≥ Yes
     CYAN         ≥  3  ≥ Yes ≥ Yes
     RED          ≥  4  ≥ Yes ≥ Yes
     MAGENTA      ≥  5  ≥ Yes ≥ Yes
     BROWN        ≥  6  ≥ Yes ≥ Yes
     LIGHTGRAY    ≥  7  ≥ Yes ≥ Yes
     DARKGRAY     ≥  8  ≥ No  ≥ Yes
     LIGHTBLUE    ≥  9  ≥ No  ≥ Yes
     LIGHTGREEN   ≥ 10  ≥ No  ≥ Yes
     LIGHTCYAN    ≥ 11  ≥ No  ≥ Yes
     LIGHTRED     ≥ 12  ≥ No  ≥ Yes
     LIGHTMAGENTA ≥ 13  ≥ No  ≥ Yes
     YELLOW       ≥ 14  ≥ No  ≥ Yes
     WHITE        ≥ 15  ≥ No  ≥ Yes
     ƒƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒ≈ƒƒƒƒƒ≈ƒƒƒƒƒƒ
     BLINK        ≥128  ≥ No  ≥
     
     */
    clrscr();
    int i, a=(getmaxx()-textwidth("<<<               >>>"))/2;
    setfillstyle(1, BLUE);
    bar(0,0,getmaxx(),getmaxy());
    setcolor(11);
    //textcolor(11);
    //textbackground(BLUE);
    
    settextstyle(0, 0, 7);
    outtextxy((getmaxx()-textwidth("Prison"))/2,50,"Prison");
    outtextxy((getmaxx()-textwidth("Management"))/2,150,"Management");
    outtextxy((getmaxx()-textwidth("System"))/2,250,"System");
    setfillstyle(1,15);
    //left vertical bars
    bar(50,20,60,110);
    bar(30,20,40,110);
    bar(70,20,80,110);
    bar(90,20, 100,110);
    //left horizontal bars
    bar(20,50, 110, 40);
    bar(20,70, 110, 60);
    bar(20,90, 110, 80);
    
    bar(getmaxx()-90,20,getmaxx()-100,110);
    bar(getmaxx()-50,20,getmaxx()-60,110);
    bar(getmaxx()-30,20,getmaxx()-40,110);
    bar(getmaxx()-70,20,getmaxx()-80,110);
    
    bar(getmaxx()-20,40,getmaxx()-110,50);
    bar(getmaxx()-20,60,getmaxx()-110,70);
    bar(getmaxx()-20,80,getmaxx()-110,90);
    
    setcolor(9);
    do{
        settextstyle(0, 0, 1);
        setcolor(BLUE);
        outtextxy(a,getmaxy()-15,"<<<               >>>");
        setcolor(4);
        outtextxy(a,getmaxy()-15,"    PRESS ANY KEY    ");
        delay(250);if(kbhit()){getch();break;}
        setcolor(BLUE);
        outtextxy(a,getmaxy()-15,"<<<               >>>");
        setcolor(4);
        outtextxy(a,getmaxy()-15,"  < PRESS ANY KEY >  ");
        delay(250);if(kbhit()){getch();break;}
        setcolor(BLUE);
        outtextxy(a,getmaxy()-15,"<<<               >>>");
        setcolor(4);
        outtextxy(a,getmaxy()-15," << PRESS ANY KEY >> ");
        delay(250);if(kbhit()){getch();break;}
        setcolor(BLUE);
        outtextxy(a,getmaxy()-15,"<<<               >>>");
        setcolor(4);
        outtextxy(a,getmaxy()-15,"<<< PRESS ANY KEY >>>");
        delay(250);if(kbhit()){getch();break;}
    }while(1);
    setcolor(0);
    for(i=0;i<getmaxy()/4;i++){
        delay(20);
        //colliding splashscreen
        rectangle(midy-i,midy-i,getmaxx()+i-midy,midy+i);
        rectangle(i,i,getmaxx()-i,getmaxy()-i);
    }
}



void clrwin(int opt){
    if(opt==2)
        menu(-1);
    hidemouse();
    setcolor(0);
    line(9,33,631,33);
    line(9,34,9,340);
    setcolor(15);
    line(631,34,631,339);
    line(10,340,631,340);
    setfillstyle(1,11);
    bar(10,34,630,339);
    showmouse();
}



int about(){
    char str[3][35]={"Project : Prison Management System","Created by : Gunesh Shanbhag"};
    close=1;
    drawwindow("About me", midx/2, midy/2, (getmaxx()*3)/4, (getmaxy()*3)/4,1 );
    settextstyle(0,0,1);
    setcolor(15);
    for(int i=0;i<2;i++)
        outtextxy(midx/2+15,midy-50+(i*20),str[i]);
    outtextxy(midx/2+15,midy-10,"Detail : In this project I have ");
    outtextxy(midx/2+15,midy+10,"         coded in C and Graphics to");
    outtextxy(midx/2+15,midy+30,"         make the project look better.");
    button("OK",midx-30,midy*3/2-22,midx+30,midy*3/2-8,7);
    
    do{
        getmousepos(&buttonm,&xm,&ym);
        if(buttonm==1){
            if(xm>=midx-30&&ym>=midy*3/2-22&&xm<=midx+30&&ym<=midy*3/2-8){
                button("OK",midx-30,midy*3/2-22,midx+30,midy*3/2-8,3);
                delay(100);close=0;;
            }
        }
    }while(close);
    return 4;
}



void button(char name[15],int x1,int y1,int x2 ,int y2,int c){
    setfillstyle(1,c);
    setcolor(15);
    hidemouse();
    line(x1,y1,x2,y1);
    line(x1,y1,x1,y2);
    setcolor(0);
    line(x2,y1,x2,y2);
    line(x1,y2,x2,y2);
    bar(x1+1,y1+1,x2-1,y2-1);
    outtextxy((x2+x1-textwidth(name))/2,(y2+y1-textheight(name))/2,name);
    showmouse();
}



void drawwindow(char head[30],int x1, int y1, int x2, int y2, int c){
    hidemouse();
    setfillstyle(1,7);
    bar(x1,y1-14,x2,y1-2);
    setfillstyle(1,c);
    bar(x1,y1,x2,y2);
    setcolor(15);
    line(x1-1,y1-15,x2+1,y1-15);
    line(x1-1,y1-15,x1-1,y2+1);
    setcolor(0);
    line(x2+1,y1-14,x2+1,y2+1);
    line(x1-1,y2+1,x2+1,y2+1);
    line(x1,y1-1,x2,y1-1);
    setcolor(15);
    rectangle(x1+5,y1+5,x2-5,y2-5);
    setcolor(0);
    settextstyle(0,0,1);
    outtextxy((x2+x1-textwidth(head))/2,y1-12,head);
    showmouse();
    
}




int dropmenu(char menu[7][20],int x1,int y1,int x2,int y2,int opt){
    int i;
    char ch;
    setfillstyle(1,14);
    setcolor(15);
    hidemouse();
    line(x1,y1,x2,y1);
    line(x1,y1,x1,y2);
    setcolor(0);
    line(x2,y1,x2,y2);
    line(x1,y2,x2,y2);
    bar(x1+1,y1+1,x2-1,y2-1);
    rectangle(x1+5,y1+5,x2-5,y2-5);
    for(i=0;i<(y2-y1-15)/14;i++){
        if(i==opt){
            setcolor(15);
            setfillstyle(1,3);
            bar(x1+10,y1+8+(i*14),x2-10,y1+20+(i*14));
            outtextxy(x1+15,y1+10+(i*14),menu[i]);
        }else{
            setcolor(0);
            outtextxy(x1+15,y1+10+(i*14),menu[i]);
        }
    }
    showmouse();
    delay(100);
    return opt;
}


//mouse function
int initmouse(){
    i.x.ax=0;//for  initialising mouse.
    int86(0x33,&i,&o);
    return (o.x.ax);
}

void showmouse(){
    i.x.ax=1; // for displaying mouse pointer.
    int86(0x33,&i,&o);
}
void hidemouse(){
    i.x.ax=2;
    int86(0x33,&i,&o);
}

void setmousepos(int &xpos,int &ypos){
    i.x.ax=4;
    i.x.cx=xpos;
    i.x.dx=ypos;
    int86(0x33,&i,&o);
}

void restrictmouse(int x1,int y1,int x2,int y2){
    i.x.ax=7;     //to define the upper left boundry of mouse.
    i.x.cx=x1;
    i.x.dx=x2;
    int86(0x33,&i,&o);
    i.x.ax=8;   //to define the bottom right boundry of mouse.
    i.x.cx=y1;
    i.x.dx=y2;
    int86(0x33,&i,&o);
}
void getmousepos(int *buttonm,int *x, int *y){
    i.x.ax=3; //to move mouse.
    int86(0x33,&i,&o);
    *buttonm=o.x.bx;
    *x=o.x.cx;
    *y=o.x.dx;
}
//end mouse function



void inputbox(int x,int y,int limit,int bkc){
    hidemouse();
    setfillstyle(1,bkc);
    bar(x-2,y-2,x+limit*8+2,y+8);
    setcolor(0);
    line(x-3,y-3,x-3,y+9);
    line(x-3,y-3,x+limit*8+2,y-3);
    showmouse();
}

Leave a Reply