0% found this document useful (0 votes)
21 views22 pages

Product Management System Code

The document includes header files for input/output operations and graphics in C programming. It defines a structure to store product details and functions for a product management system including adding, deleting, searching, editing products.

Uploaded by

lprasanna9573
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views22 pages

Product Management System Code

The document includes header files for input/output operations and graphics in C programming. It defines a structure to store product details and functions for a product management system including adding, deleting, searching, editing products.

Uploaded by

lprasanna9573
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include<stdio.

h>

#include<conio.h>

#include<string.h>

#include<ctype.h>

#include<stdlib.h>

#include<windows.h>

#include<time.h>

#define ENTER 13

#define BKSP 8

#define SPACE 32

#define TAB 9

void setcolor(int ForgC)

{ WORD wColor;

HANDLE hStdOut=GetStdHandle(STD_OUTPUT_HANDLE);

CONSOLE_SCREEN_BUFFER_INFO csbi;

if(GetConsoleScreenBufferInfo(hStdOut,&csbi))

wColor=([Link] & 0xF0)+(ForgC & 0x0F);

// SetConsoleTextAttributes(hStdOut,wColor);

SetConsoleTextAttribute(hStdOut,wColor);

struct item

char productname[40],productcomp[40],c;
int productid;

int price;

int Qnt;

}st;

void wel_come(void);

void title(void);

void login();

void menu(void);

void title(void);

void deleteproduct(void);

void gotoxy(short x, short y)

COORD pos ={x,y};

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);

void add_item();

void read_item();

void search_item();

void edit_item();

void main(void)

wel_come(); //call for welcome screen function

login(); //call for login function

void wel_come(void)
{

time_t t;

time(&t);

printf(" \n");

printf("---------------------------------------------------------------------------------------------------------\n");

printf("\t\t\t\t\t%s",ctime(&t));

printf("---------------------------------------------------------------------------------------------------------\n");

printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");

printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");

printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");

printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");

printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");

printf("|\t\t\t\t==================================\t\t\t\t\t\t|\n");

printf("|\t\t\t\t|\t WELCOME TO \t |\t\t\t\t\t\t|\n");

printf("|\t\t\t\t|\tPRODUCT MGMT SYSTEM\t |\t\t\t\t\t\t|\n");

printf("|\t\t\t\t==================================\t\t\t\t\t\t|\n");

printf("|\t\t\t\t Address \t\t\t\t\t\t\t|\n");

printf("|\t\t\t\t\t Number\t\t\t\t\t\t\t\t|\n");

printf("|\t\t\t\t \"WE BELIEVE IN QUALITY\"\t\t\t\t\t\t\t|\n");

printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");

printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");

printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");

printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");

printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");

printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");

printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");

printf("|Press any key to continue.........\t\t\t\t\t\t\t\t\t\t|\n");

printf("---------------------------------------------------------------------------------------------------------\n");
getch();

system("cls");

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 ======================== ");

printf(" \n USERNAME:-");

scanf("%s", &uname);

printf(" \n 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 PRODUCT MANAGEMENT SYSTEM !!!! 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");

menu();

}
void menu(void)

int choice;

system("cls");

main:

printf("\n======================== Product Management System


========================");

printf(" ");

printf(" ");

printf("\n\t\tPress <1> Add Products");

printf("\n\t\tPress <2> Delete Products");

printf("\n\t\tPress <3> Search Products");

printf("\n\t\tPress <4> Read Items");

printf("\n\t\tPress <5> Edit Items");

printf("\n\t\tPress <6> Exit!");

printf("\n\n\t\tEnter your choice[1-6]");

scanf("%i", &choice);

system("cls");

switch(choice)

case 1:

add_item();

break;

case 2:

deleteproduct();

break;

case 3:

search_item();
break;

case 4:

read_item();

break;

case 5:

edit_item();

break;

case 6:

printf("System Exit");

exit(0);

break;

default:

printf("Invalid Choice! System Exit\n");

getch();

void add_item()

int index, valid;

char c;

int a=0;

FILE *fp;

do

{
system("cls");

printf("============ Enter Product Detail ============");

int ID;//for comparing staff ID if file isnot NULL

//declaration of file variable named as sfile

fp = fopen("[Link]","a+");//opening file and creating a [Link] file to append or


write

if((fp = fopen("[Link]","a+"))!=NULL)//if condition to check file is NULL or not

I:

printf("\nProduct Code\t :");

scanf("%i",&ID);

while(fscanf(fp,"%s %s %i %i %i", [Link], [Link],


&[Link], &[Link],&[Link])!=EOF)

/*

fscanf reads every data stored in the file

if entered staffID already exist then jumps to

position I declared inside if(sfile!=NULL) at top

*/

if(ID == [Link])

printf("\n\tTHE PRODUCT CODE ALREADY EXIST.\n");

goto I;

[Link] = ID;

else//runs if sfile is empty

printf("\nProduct Code\t :");

scanf("%i",&[Link]);
}

//add product name

do

//printf("<<<<<<<<<<<<<<Enter Product Detail>>>>>>>>>>>>>");

fflush(stdin);

printf("\nProduct Name\t :");

gets([Link]); // get input string

[Link][0]=toupper([Link][0]);

//iterate for every character in string

for (index=0; index<strlen([Link]); ++index)

{ //check if character is valid or not

if(isalpha([Link][index]))

valid = 1;

else

valid = 0;

break;

if (!valid)

printf("\n Name contain invalid character. Please 'Enter' again");

getch();

}while(!valid); //while end here


//Product Company

do

char productcomp[40];

fflush(stdin);

printf("\nProduct Company\t :");

gets([Link]); // get input string

[Link][0]=toupper([Link][0]);

//iterate for every character in string

for (index=0; index<strlen([Link]); ++index)

{ //check if character is valid or not

if(isalpha([Link][index]))

valid = 1;

else

valid = 0;

break;

if (!valid)

printf("\n Name contain invalid character. Please 'Enter' again");

getch();

}while(!valid);

//productid

do
{

printf("\nPrice [10-5000]Rupees:");

scanf("%i",&[Link]);

if([Link]<10 || [Link]>5000)

printf("\n\tYou Cannot Enter the price limit [10-5000].Re-


Enter.");

}while([Link]<10 || [Link]>5000);

do

printf("\nQuantity [1-500]\t:");

scanf("%i",&[Link]);

if([Link]<1 || [Link]>500)

printf("\n\tEnter Quantity[1-500] [Link]-Enter.");

}while([Link]<1 || [Link]>500);

// printf("\nProduct Price\t :");

// scanf("%i", &[Link]);

//printf("\nProduct ID\t :");

//scanf("%i", &[Link]);

// printf("\nProduct Quantity :");

// scanf("%i",&[Link]);

fp=fopen("[Link]","a");

fprintf(fp,"\n%s %s %i %i %i", [Link], [Link],[Link],


[Link],[Link]);

fclose(fp);

printf("\nPress 'Enter' to add more item and any other key to go to main menu");
}

while((c = getch()) =='\r');

menu();

void search_item()

char target[40];

int found=0;

FILE *sfile;

sfile=fopen("[Link]","r");

printf("\nEnter name to search:");

fflush(stdin);

gets(target);

target[0]=toupper(target[0]);

while (!feof(sfile) && found==0)

fscanf(sfile,"%s %s %i %i %i", [Link], [Link], &[Link],


&[Link],&[Link]);

if(strcmp(target, [Link])==0)

found=1;

if(found)

printf("\n Record found");


printf("\nProduct Name\t\t:%s \nProduct Company\t\t:%s \nProduct Price\t\t:%i \
nProduct ID\t\t:%i \nProduct Quantity\t:%i", [Link], [Link], [Link], [Link],
[Link]);

else

printf("Noo Record found");

fclose(sfile);

printf("\nPress any key to go to Main Menu!");

while((st.c = getch()) =='\r');

menu();

void deleteproduct(void)

char target[40];

int found=0;

FILE *sfile, *tfile;

sfile=fopen("[Link]","r");

tfile=fopen("[Link]","w+");

printf("\n Enter name to Delete: ");

fflush(stdin);

scanf("%s",target);

target[0]=toupper(target[0]);

while (fscanf(sfile,"%s %s %i %i %i\n",[Link],[Link],


&[Link],&[Link],&[Link])!=EOF)

if(strcmp(target,[Link])==0)

found=1;

}
else

fprintf(tfile,"%s %s %i %i %i\n", [Link],[Link],


[Link],[Link],[Link]);

if(!found)

printf("\n Record not Found");

getch();

menu();

else

printf("\n Record deleted");

fclose(sfile);

fclose(tfile);

remove("[Link]");

rename("[Link]","[Link]");

printf("\nPress any key to go to Main Menu!");

while((st.c = getch()) =='\r');

menu();

void read_item()

FILE *f;

int i, q;

if((f=fopen("[Link]","r"))==NULL)
{

gotoxy(10,3);

printf("NO RECORDS");

printf("\n\t\tPress any key to go back to Menu.");

getch();

menu();

else

gotoxy(0,5);

for(i=0;i<100;i++)

printf("-");

gotoxy(5,6);

printf("Product Name");

gotoxy(25,6);

printf("Product Price");

gotoxy(40,6);

printf("Product Company");

gotoxy(60,6);

printf("Product CODE");

gotoxy(80,6);

printf("Product Quantity\n");

for(i=0;i<100;i++)

{
printf("-");

q=8;

while(fscanf(f,"%s %s %i %i %i\n", [Link],[Link], &[Link],


&[Link],&[Link])!=EOF)

gotoxy(5,q);

printf("%s",[Link]);

gotoxy(25,q);

printf("%i",[Link]);

gotoxy(40,q);

printf("%s",[Link]);

gotoxy(60,q);

printf("%i",[Link]);

gotoxy(80,q);

printf("%i",[Link]);

q++;

printf("\n");

for(i=0;i<100;i++)

printf("-");

fclose(f);

printf("\nPress any key to go to Main Menu!");

//while((st.c = getch()) =='\r');

getch();

menu();

}
void edit_item()

int index, valid;

char target[40];

FILE *fp, *rp;

int a=0;

int id;

char edit;

long int size=sizeof(st);

if((fp=fopen("[Link]","r+"))==NULL)

printf("NO RECORD ADDED.");

menu();

else

rp = fopen("[Link]","a");

system("cls");

printf("Enter Product Code for edit:");

scanf("%i",&id);

fflush(stdin);

while(fscanf(fp,"%s %s %i %i %i\n", [Link],[Link], &[Link],


&[Link],&[Link])!=EOF)

if(id==[Link])

a=1;

printf("\n\t***** Record Found *****");

printf("\nProduct Name\t\t: %s",[Link]);

printf("\nProduct Company\t\t: %s",[Link]);


printf("\nPrice\t\t\t: %i",[Link]);

printf("\nProduct Code\t\t: %i",[Link]);

printf("\nProduct Quantity\t:%i",[Link]);

printf("\n\n\t*** New Record ***");

do

fflush(stdin);

printf("\nNew Product Name\t\t: ");

gets([Link]); // get input string

[Link][0]=toupper([Link][0]);

//iterate for every character in string

for (index=0; index<strlen([Link]); ++index)

{ //check if character is valid or not

if(isalpha([Link][index]))

valid = 1;

else

valid = 0;

break;

if (!valid)

printf("\n Name contain invalid character. Please


'Enter' again");

getch();

}
}while(!valid); //while end here

//Product Company

do

char productcomp[40];

fflush(stdin);

printf("\nNew Product Company\t\t:");

gets([Link]); // get input string

[Link][0]=toupper([Link][0]);

//iterate for every character in string

for (index=0; index<strlen([Link]); ++index)

{ //check if character is valid or not

if(isalpha([Link][index]))

valid = 1;

else

valid = 0;

break;

if (!valid)

printf("\n Name contain invalid character. Please


'Enter' again");

getch();

}while(!valid);
do

printf("\nNew Price [10-5000]Rupees:");

scanf("%i",&[Link]);

if([Link]<10 || [Link]>5000)

printf("\n\tYou Cannot Enter the price limit [10-5000].Re-


Enter.");

}while([Link]<10 || [Link]>5000);

printf("\nEnter New Product Code\t\t:");

scanf("%i",&[Link]);

do

printf("\nNew Quantity [1-500]\t:");

scanf("%i",&[Link]);

if([Link]<1 || [Link]>500)

printf("\n\tEnter New Quantity[1-500] [Link]-Enter.");

}while([Link]<1 || [Link]>500);

printf("Press 'y' to edit the existing record or any key to cancel...");

edit=getche();

if(edit=='y' || edit=='Y')

fprintf(rp,"%s %s %i %i %i\n", [Link],


[Link], [Link], [Link],[Link]);
fflush(stdin);

printf("\n\n\t\tYOUR RECORD IS SUCCESSFULLY EDITED!!!");

else

fprintf(rp,"%s %s %i %i %i\n", [Link], [Link],


[Link], [Link],[Link]);

fflush(stdin);

if(!a)

printf("\n\nTHIS PRODUCT DOESN'T EXIST!!!!");

fclose(rp);

fclose(fp);

remove("[Link]");

rename("[Link]","[Link]");

getch();

menu();

Output:

You might also like