文档库 最新最全的文档下载
当前位置:文档库 › 仓库管理系统源代码

仓库管理系统源代码

/*******************************************************************************************************************/

/********************************************仓库管理系统***********************************************************/

/*******************************************************************************************************************/

#include
#include
#include
void input(); /*输入*/
void display(); /*显示*/
void search(); /*查找*/
void amend(); /*修改*/
void delete_slf(); /*删除*/
void list(); /*菜单*/

struct stud /*定义商品属性数组*/
{
long num; /*商品编号*/
char name[20]; /*商品名字*/
float price; /*商品的价格*/
int godsnum; /*商品的数量*/
}infom;



void input() /*输入信息函数*/
{

FILE *fp; /*定义文件指针*/
char numstr[20],ch;
if((fp=fopen("c:\\123.dat","wb"))==NULL)
{
exit(0);
}
do
{

getchar();
printf("\n\t\tenter num:");
gets(numstr); /*接受字符并存入数组中*/
infom.num=atol(numstr); /*把字符型转换成整型*/
printf("\n\t\tenter name:");
gets(https://www.wendangku.net/doc/da1857593.html,);
printf("\n\t\tenter price:");
gets(numstr);
infom.price=atof(numstr);/*把字符型转换成float型*/
printf("\n\t\tenter godsnum:");
gets(numstr);
infom.godsnum=atoi(numstr);/*把字符型转换成整型*/
fwrite(&infom,sizeof(infom),1,fp);
printf("\n\t\tinput continue(y/n)?");
ch=getchar();getchar();
}while(ch=='Y'||ch=='y');
fclose(fp);
}



void display() /*显示信息函数*/
{

FILE *fp;
char ch;
int x;
float f;

if((fp=fopen("c:\\123.dat","rb"))==NULL)
{
printf("\nCannt open file!\n");
getch();
exit(1);
}
while(fread(&infom,sizeof(struct stud),1,fp)==1)

{

printf("\n\tnum:%ld",infom.num);
printf("\n\tname:%s",https://www.wendangku.net/doc/da1857593.html,);
printf("\n\t\price:%.3f",infom.price);
printf("\n\t\godsnum:%d",infom.godsnum);

}
fclose(fp);
}





void search() /*查询信息函数*/
{

FILE *fp;
int x;
long y;
char ch;
if((fp=fopen("c:\\123.dat","rb"))==NULL)
{

printf("\nCannot open file!\n");
getch();
exit(1);

}
do
{

printf("\nplease input recond num:");
scanf("%d",&x);
y=(x-1)*sizeof(infom);
rewind(fp); /*把指针移回文件开始*/
if(fseek(fp,y,0)!=0)/*把指针指向Y*/
{

printf("can not move there!\n");
exit(1);

}
fread(&infom,sizeof(infom),1,fp);
printf("num:%ld\n",infom.num);
printf("name:%s\n",https://www.wendangku.net/doc/da1857593.html,);
printf("price:%f\n",infom.price);
printf("godsnum:%d",infom.godsnum);
ch=getchar();getchar();
}while(ch=='Y'||ch=='y');
fclose(fp);
}




void amend() /*修改信息函数*/
{

FILE *fp1 ,*fp2;
int flag;
long ch;
char f;
char temp[10];
do
{
if((fp1=fopen("c:\\123.dat ","rb")) ==NULL)
{

prin

tf("\tCan not open the inform file!");
getch();
exit(1);
}

if((fp2=fopen("c:\\456.dat","wb")) == NULL)
{

printf("\tCan not open the temp file!");
getch();
exit(1);
}

printf("please input the num you want to amend:");
getchar();
scanf("%ld",&ch);
flag=0;
while(fread(&infom,sizeof(infom),1,fp1)==1)
{
if(ch==infom.num)
{

printf("\n\nPlease input the new information:\n");
printf("\tnum:");getchar();gets(temp);
infom.num=atol(temp);
printf("\tname:");
gets(https://www.wendangku.net/doc/da1857593.html,);
printf("\tprice:");
gets(temp);
infom.price=atof(temp);
printf("\tgodsnum:");
gets(temp);
infom.godsnum=atoi(temp);
getchar();
flag=1;
}
fwrite(&infom,sizeof(infom),1,fp2);
}
fclose(fp1);
fclose(fp2);

if(flag == 1)
{
printf("amend success!\n");
remove("c:\\123.dat");
rename("c:\\456.dat","c:\\123.dat");
}
else
printf("Can not find this record!\n");

printf("amend any more ?(Y/N): [ ]\b\b");
f=getchar();
getchar();
}while (f=='Y'||f=='y');
}





void delete_slf() /*删除信息函数*/
{

FILE * fp1,* fp2;
int flag=0; /*定义一个标记*/
long ch;
char f;
char temp[10];
do
{
if((fp1=fopen("c:\\123.dat","rb"))==NULL)
{

printf("\tCan not open the inform file!");
getch();
exit(1);
}
if((fp2=fopen("c:\\456.dat","wb"))==NULL)
{
printf("\tCan not creat the temp file!");
getch();
exit(1);
}
printf("Please input the num you want to delete:");
getchar();
scanf("%ld",&ch);
while(fread(&infom,sizeof(infom),1,fp1)==1)
{
if(ch==infom.num)
{
flag=1;
}
else
fwrite(&infom,sizeof(infom),1,fp2); /*分配一段内存空间&infom是首地址*/
}
fclose(fp1);
fclose(fp2);
if(flag==1)
{
printf("Delete success!\n");
remove("c:\\123.dat"); /*删除文件123*/
rename("c:\\456.dat","c:\\123.dat"); /*对文件456重命名*/
}
else
printf("Can not find this record!\n");
printf("Delete any more?(Y/N):[ ]\b\b");
f=getchar();
getchar();
}while(f=='Y'||f=='y');
}




void list() /*选择功能函数*/
{
int x;
while(1)
{
system("cls");
printf("\t\t****************仓库管理系统***********************\n");/*软件界面*/
printf("\t\t****************欢 迎 使 用***********************\n");
printf("\t\t\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n");
printf("\t\t\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n");
printf("\t\t\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n\n");
printf("\t\t请选择功能: *******\n");
printf("\t\t******* *******\n");
printf("\t\t*******1.输 入 信 息*******\n");
printf("\t\t******* **

*****\n");
printf("\t\t***************************************\n");
printf("\t\t******* *******\n");
printf("\t\t*******2.显 示 信 息*******\n");
printf("\t\t******* *******\n");
printf("\t\t***************************************\n");
printf("\t\t******* *******\n");
printf("\t\t*******3.查 找 信 息*******\n");
printf("\t\t******* *******\n");
printf("\t\t***************************************\n");
printf("\t\t******* *******\n");
printf("\t\t*******4.修 改 信 息*******\n");
printf("\t\t******* *******\n");
printf("\t\t***************************************\n");
printf("\t\t******* *******\n");
printf("\t\t*******5.删 除 信 息*******\n");
printf("\t\t******* *******\n");
printf("\t\t***************************************\n");
printf("\t\t******* *******\n");
printf("\t\t*******0.退 出 程 序*******\n");
printf("\t\t******* *******\n");
printf("\t\t\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n");
printf("\t\t\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n");
printf("请 选 择 功 能:");
scanf("%d",&x);
if(x>=0&&x<=5) /*功能选择函数*/
{
switch(x)
{
case 1:input();
break;
case 2:display();
break;
case 3:search();
break;
case 4:amend();
break;
case 5:delete_slf();
break;
case 0:exit(0);

}
printf("\n\nsuccess. \nPress any key to continue......\n");getch();
}
else
printf("\n\nfail.choose again\n\n");
}
}




void main() /*主函数*/
{
printf("\n\n\n\n\n\n\n\n\n\n");
list();
}

相关文档
相关文档 最新文档