You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

626 lines
14 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
int bgnumber = 023; //客户号
int goodsn = 0; //商品量的统计
int ordern = 0; //订单的统计
void secondmain(); //管理维护子菜单
void shuru(); //输入商品
void browse(); //浏览商品
void search(); //搜索商品
void order(); //订购商品
void seek(); //查询订单
void add(); //增加商品
void del(); //删除商品
void savesp(); //保存商品
void savedd(); //保存订单
void daoru(); //从文本导入商品
struct goods {
char name[30]; //商品名
int number; //货号
char vender[30]; //厂家
char filed[100]; //产地
int stock; //库存
double unvalent; //单价
};
struct goods a[100];
struct order {
int goodnumber; //货号
int ordernumber; //订购量
int ordertime; //日期时间
char customername[10]; //客户名
char customeraddress[100]; //客户地址
int customernumber; //客户编号
};
struct order b[100];
int main(void) {
printf(".. .. ......... .............. ........ .\n............ ... .. ....................@@\n.........@`..... .....................@@o \no.........@@.... ........@...... ..`@@@...\n.@@........@@..................O@O....@@ .......O@@@*... \n...@@O......@@@.....*O@@@@@@@@@@@..O@@@... ...@@@@o..... \n....@@@@`....@@@@@@@@@@@@@@@@@@@....@@......@@@@O....... \n.....@@@@/...@@@@............@*..O@@.....@@@@O......... \n........@@@@*..@@......oOOOO\\....@@@...*@@@@@.....o@.... \n.@@.......@@@@....@@@@@@@@@@@@@@@@@..O@@@@@....O@@@..... \n... @@@O....@@@@@@@@...........O@O.@@@@@@...@@@@O....... \n.. ...@@@@...O@@..... ... ......@@@@@@..@@@@@O......... \n ..O@@@...O*.....OOOO...@@@@@@..@@o..@@@. . . ... \n ......\\Oo...O@@@@@@@@@@@@@@..o.......@@O.. .... \n ...... ..O@@@@O.. ...O@@@*...........@@@.... \n . ... ..@@@@*.o@@/...@@@...@@@@....o@@.... \n............. .........O@@@@o..@@@..@@..@@...*@@*...... \n .... . ..... .......*..`@@*...@@@...@@@@....O@@.... . . \n............O......O@@@......@@@@...... ....@@@..... .. \n. ......O@@@..O@.o@@@@@@@@@@@@@*....... .. .@@O .. . \n......o..@@\\@@..@@@@o...oOOo................@@@. \n. ......@O@...@@@@.......... . ...o@......@@@.. \n . ....O^....@@@. ...... . .. .....*@@@O@@@@... \n............@@..... . ...... .. ......O@@@@O.... \n ../@ ... o@@@o... ....... \n .... .. ..\\@@@.. ....... \n ... .... .. .*@@@.... \n .... ... .. ....@@*.. \n");
Sleep(1000);
int i;
daoru();
do {
system("cls");
printf("\n\n\n\n\n\n");
printf("**************************欢迎使用商品订购系统**********************************\n");
printf(" 1.浏览商品信息 \n");
printf(" 2.订购商品 \n");
printf(" 3.订单查询 \n");
printf(" 4.搜索商品 \n");
printf(" 5.管理菜单 \n");
printf(" 0.退出系统 \n");
printf("********************************************************************************\n");
printf("\n\n 选择: ");
scanf("%d",&i);
switch(i) {
case 1:
system("cls");
browse();
break;
case 2:
system("cls");
order();
break;
case 3:
system("cls");
seek();
break;
case 4:
search();
break;
case 5:
secondmain();
break;
case 0: //退出系统的界面
system("cls");
printf("\n\n\n\n\n\n\n\n");
printf("\n\n 欢迎使用本系统\n\n\n\n\n 欢迎再次使用\n");
exit(0);
default:
printf("请从0-5中选择");
break;
}
} while(1);
return 0;
}
//浏览商品
void browse() {
int i;
system("cls");
printf(" 商品信息\n");
for (i = 0; i < goodsn; i++) {
printf("品名 : %s\n",a[i].name);
printf("货号 : %d\n",a[i].number);
printf("厂家 : %s\n",a[i].vender);
printf("产地 : %s\n",a[i].filed);
printf("库存 : %d\n",a[i].stock);
printf("单价 : %.2lf\n\n\n",a[i].unvalent);
}
printf("\n\n\n\n\n\n ");
printf("返回主菜单\n");
printf(" ");
system("pause");
return;
}
//商品的订购
void order() {
char ch;
int i, j, t, c = 1;
int n = 1;
int m = 0;
do {
switch(n) {
case 1:
system("cls");
printf(" 商品信息\n");
//显示商品的名称、货号信息,以便于订购
printf("名称 货号 库存\n");
for (i = 0; i < goodsn; i++) {
printf("%s %d %d\n\n\n",a[i].name,a[i].number,a[i].stock);
}
printf("\n\n\n");
printf(" 商品订单\n");
printf("\n 请输入你的第%d个订单信息:\n",m + 1);
printf("\n 货号:");
fflush(stdin);
scanf("%d",&b[ordern].goodnumber);
//检测是否含有此商品
j = 1;
for (i = 0; i < goodsn; i++) {
if(a[i].number == b[ordern].goodnumber) {
j = 0;
t = i;
}
}
//若有商品继续购买项目
if(j == 0) {
printf("\n 订购量:");
fflush(stdin);
scanf("%d",&b[ordern].ordernumber);
if (a[t].stock >= b[ordern].ordernumber) {
a[t].stock = a[t].stock - b[ordern].ordernumber; //顾客购买后商品的库存计算
printf("\n 日期时间:");
fflush(stdin);
scanf("%d",&b[ordern].ordertime);
printf("\n 客户名:");
fflush(stdin);
gets(b[ordern].customername);
printf("\n 客户地址:");
fflush(stdin);
gets(b[ordern].customeraddress);
printf("\n 客户编号:");
b[ordern].customernumber = bgnumber;
printf("%d\n",b[ordern].customernumber);
bgnumber++;
ordern++;
m++;
printf("\n\n\n ");
system("pause");
} else {
printf("\n\n 订购数目超出库存\n");
printf(" ");
system("pause");
}
}
//若没有商品的提示及操作
else {
printf("\n\n 查无此货\n");
printf(" ");
system("pause");
}
case 2:
printf("是否继续输入订购?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
if(ch == 'N' || ch == 'n') {
c = 0;
break;
} else if(ch == 'Y' || ch == 'y') {
c = 0;
n = 1;
break;
} else if(ch != 'n' || ch != 'N' || ch != 'Y' || ch != 'y') {
n = 0;
c = 1;
break;
}
case 0:
if(c == 1) {
n = 2;
}
}
} while(ch != 'n' && ch != 'N');
system("cls");
return ;
}
//订单的查询
void seek() {
int i;
system("cls");
printf(" 订单列表\n");
for (i = 0; i < ordern; i++) {
printf("货号 : %d\n",b[i].goodnumber);
printf("订购量 : %d\n",b[i].ordernumber);
printf("日期时间 : %d\n",b[i].ordertime);
printf("客户名 : %s\n",b[i].customername);
printf("客户地址 : %s\n",b[i].customeraddress);
printf("客户编号 : %d\n\n\n",b[i].customernumber);
}
printf("\n\n\n\n\n\n ");
printf("返回主菜单\n");
printf(" ");
system("pause");
return;
}
//增加商品
void add() {
char ch;
int i=1;
int n = 1;
do {
switch(n) {
case 1:
system("cls");
printf(" 商品信息的增加\n");
printf("\n 请输入你的第%d件商品的信息:\n",i);
printf("\n 名称:");
fflush(stdin);
scanf("%s",a[goodsn].name);
printf("\n 货号:");
fflush(stdin);
scanf("%d",&a[goodsn].number);
printf("\n 厂家:");
fflush(stdin);
scanf("%s",a[goodsn].vender);
printf("\n 产地:");
fflush(stdin);
scanf("%s",a[goodsn].filed);
printf("\n 库存:");
fflush(stdin);
scanf("%d",&a[goodsn].stock);
printf("\n 单价:");
fflush(stdin);
scanf("%lf",&a[goodsn].unvalent);
i++;
goodsn++;
case 2:
printf("是否继续输入记录?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
if(ch ==' Y'|| ch == 'y') {
n = 1;
}
if(ch == 'N' || ch ==' Y'|| ch == 'n'|| ch == 'y') {
break;
}
}
} while(ch != 'n' && ch != 'N');
return;
}
//删除商品
void del() {
int i;
int j;
char ch;
int n = 1;
do {
switch(n) {
case 1:
system("cls");
printf(" 商品列表\n");
//显示商品的名称、货号信息,以便于下部的删除
for (i = 0; i < goodsn; i++) {
printf("名称 : %s\n",a[i].name);
printf("ID : %d\n",i);
printf("库存 : %d\n\n\n",a[i].stock);
}
//商品的搜索
printf("\n\n\n 请输入你要删除商品的ID:");
scanf("%d",&j);
i = j;
while(i < goodsn - 1) {
strcpy(a[i].name, a[i + 1].name);
a[i].number = a[i + 1].number;
strcpy(a[i].filed, a[i + 1].filed);
a[i].stock = a[i + 1].stock;
a[i].unvalent = a[i + 1].unvalent;
strcpy(a[i].vender, a[i + 1].vender);
i++;
}
goodsn--;
case 2:
printf("是否继续删除商品?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
if(ch == 'N' || ch ==' Y'|| ch == 'n'|| ch == 'y') {
break;
}
if(ch ==' Y'|| ch == 'y') {
n = 1;
break;
}
case 0:
printf("是否继续输入记录?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
n = 2;
}
} while(ch != 'n' && ch != 'N');
printf("\n\n\n\n\n\n ");
printf("返回附加功能菜单\n");
printf(" ");
system("pause");
return;
}
//商品信息的保存
void savesp() {
FILE *fp;
int i;
fp = fopen("spxx.txt","w");
assert(fp != NULL);
fprintf(fp," 商品信息列表\n");
//商品信息的录入
for (i = 0; i < goodsn; i++) {
fprintf(fp,"名称: %s\n",a[i].name);
fprintf(fp,"货号: %d\n",a[i].number);
fprintf(fp,"厂家: %s\n",a[i].vender);
fprintf(fp,"产地: %s\n",a[i].filed);
fprintf(fp,"库存: %d\n",a[i].stock);
fprintf(fp,"单价: %.2lf\n\n\n",a[i].unvalent);
}
fclose(fp);
system("cls");
printf("\n\n\n\n\n\n 商品信息保存成功!!!\n");
printf(" ");
system("pause");
return;
}
//订单的保存信息
void savedd() {
FILE *fp;
int i;
fp = fopen("ddxx.txt","w");
assert(fp != NULL);
fprintf(fp," 订单列表\n");
//商品信息的录入
for (i = 0; i < ordern; i++) {
fprintf(fp,"货号 :%d\n",b[i].goodnumber);
fprintf(fp,"订购量 :%d\n",b[i].ordernumber);
fprintf(fp,"日期时间 :%d\n",b[i].ordertime);
fprintf(fp,"客户名 :%s\n",b[i].customername);
fprintf(fp,"客户地址 :%s\n",b[i].customeraddress);
fprintf(fp,"客户号 :%d\n\n\n",b[i].customernumber);
}
fclose(fp);
//保存后信息的反馈
system("cls");
printf("\n\n\n\n\n\n 信息保存成功!!!\n");
printf(" ");
system("pause");
return;
}
//管理维护子菜单
void secondmain() {
int i;
do {
system("cls");
printf("\n\n\n\n\n\n\n");
printf("********************************管理子菜单************************************\n\n");
printf(" 1.输入全部商品 \n");
printf(" 2.增加商品 \n");
printf(" 3.删除商品 \n");
printf(" 4.储存商品 \n");
printf(" 5.储存订单 \n");
printf(" 0.返回上一级 \n");
printf("**************************************************************************\n\n\n\n\n");
printf("\n\n 请输入你所要选择的功能(0~5): ");
scanf("%d",&i);
switch(i) {
case 1:
system("cls");
shuru ();
break;
case 2:
system("cls");
add();
break;
case 3:
system("cls");
del();
break;
case 4:
system("cls");
savesp();
break;
case 5:
system("cls");
savedd();
break;
case 0:
system("cls");
return ;
}
} while(1);
printf(" ");
system("pause");
system("cls");
return;
}
//从键盘输入商品
void shuru() {
char ch;
int n = 1;
goodsn = 0;
do {
switch(n) {
case 1:
//商品的录入
system("cls");
printf(" 请重新输入全部商品信息\n");
printf("\n 请输入第%d件商品的信息:\n",goodsn + 1);
printf("\n 名称:");
fflush(stdin);
gets(a[goodsn].name);
printf("\n 货号:");
fflush(stdin);
scanf("%d",&a[goodsn].number);
printf("\n 厂家:");
fflush(stdin);
gets(a[goodsn].vender);
printf("\n 产地:");
fflush(stdin);
gets(a[goodsn].filed);
printf("\n 库存:");
fflush(stdin);
scanf("%d",&a[goodsn].stock);
printf("\n 单价:");
fflush(stdin);
scanf("%lf",&a[goodsn].unvalent);
goodsn++;
fflush(stdin);
case 2:
printf("是否继续输入记录?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
if(ch == 'N' || ch ==' Y'|| ch == 'n'|| ch == 'y') {
break;
}
if(ch ==' Y'|| ch == 'y') {
n = 1;
break;
}
case 0:
printf("是否继续输入记录?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
n = 2;
}
} while(ch != 'n' && ch != 'N');
return;
}
//导入商品信息
void daoru() {
FILE *fp;
char ch[30];
double dou;
int in;
int i = 0;
goodsn = 0;
fp = fopen("spxx.txt","r");
assert(fp);
//从文件中导入商品信息
fscanf(fp,"%s",&ch);
while(fscanf(fp,"%s",&ch) != EOF) {
fscanf(fp, "%s", &ch);
strcpy(a[goodsn].name, ch);
fscanf(fp,"%s",&ch);
fscanf(fp,"%d",&in);
a[goodsn].number = in;
fscanf(fp,"%s",&ch);
fscanf(fp,"%s",&ch);
strcpy(a[goodsn].vender, ch);
fscanf(fp,"%s",&ch);
fscanf(fp,"%s",&ch);
strcpy(a[goodsn].filed, ch);
fscanf(fp,"%s",&ch);
fscanf(fp,"%d",&in);
a[goodsn].stock = in;
fscanf(fp,"%s",&ch);
fscanf(fp,"%lf",&dou);
a[goodsn].unvalent = dou;
goodsn++;
}
fclose (fp);
return;
}
//搜索商品
void search() {
int i;
int j;
char ch;
int n = 1;
do {
switch(n) {
case 1:
system("cls");
printf(" 商品列表\n");
//显示商品的名称、货号信息,以便于下部的删除
for (i = 0; i < goodsn; i++) {
printf("名称 : %s\n",a[i].name);
printf("ID : %d\n",i);
printf("库存 : %d\n\n\n",a[i].stock);
}
//商品的搜索
printf("\n\n\n 请输入你要搜索商品的ID:");
scanf("%d",&j);
if(0<=j&&j<=goodsn) {
printf("名称 : %s\n",a[j].name);
printf("货号 : %d\n",a[j].number);
printf("厂家 : %s\n",a[j].vender);
printf("产地 : %s\n",a[j].filed);
printf("库存 : %d\n",a[j].stock);
printf("单价 : %.2lf\n\n\n",a[j].unvalent);
}
case 2:
printf("是否继续搜索商品?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
if(ch == 'N'|| ch == 'n') {
break;
}
if(ch ==' Y'|| ch == 'y') {
n = 1;
break;
}
}
} while(ch != 'n' && ch != 'N');
printf("\n\n\n\n\n\n ");
printf("返回主菜单!\n");
printf(" ");
system("pause");
return;
}