|
|
|
@ -1,293 +1,625 @@
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<stdlib.h> /*其它说明*/
|
|
|
|
|
#include<string.h> /*字符串函数*/
|
|
|
|
|
#include<Windows.h>
|
|
|
|
|
#define max 100
|
|
|
|
|
#define LEN 15
|
|
|
|
|
#define N 50
|
|
|
|
|
int k = 1, n = 0, m = 0;
|
|
|
|
|
|
|
|
|
|
typedef struct Bank {
|
|
|
|
|
char no[13];//卡号
|
|
|
|
|
char name[10];//姓名
|
|
|
|
|
char sex[8];//性别
|
|
|
|
|
int balance;//余额
|
|
|
|
|
char passwd[20];
|
|
|
|
|
} bank, ban[max];
|
|
|
|
|
void fileWrite(int n, ban s);
|
|
|
|
|
void modify() {
|
|
|
|
|
int j = 0;
|
|
|
|
|
FILE * fp;
|
|
|
|
|
if ((fp = fopen("a.txt", "r")) == NULL) return;
|
|
|
|
|
ban s;
|
|
|
|
|
while (fscanf(fp, "%s %s %s %s %d ", &s[j].no, &s[j].name, &s[j].sex[j],&s[j].passwd, &s[j].balance) == 5) {
|
|
|
|
|
j++;
|
|
|
|
|
#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);
|
|
|
|
|
}
|
|
|
|
|
n = j;
|
|
|
|
|
int i, item, num;
|
|
|
|
|
int age;
|
|
|
|
|
char sex1[8], s1[LEN + 1], s2[LEN + 1],passwd1[20],age1[10];
|
|
|
|
|
float score1;
|
|
|
|
|
printf("请输入要修改的用户的卡号:\n");
|
|
|
|
|
scanf("%s", s1);
|
|
|
|
|
for (i = 0; i<n; i++) {
|
|
|
|
|
if (strcmp(s[i].no, s1) == 0) { /*比较字符串是否相等*/
|
|
|
|
|
num = i;
|
|
|
|
|
printf("------------------\n");
|
|
|
|
|
printf("1.修改姓名\n");
|
|
|
|
|
printf("2.修改性别\n");
|
|
|
|
|
printf("3.修改密码\n");
|
|
|
|
|
printf("4.退出本菜单\n");
|
|
|
|
|
printf("------------------\n");
|
|
|
|
|
while (1) {
|
|
|
|
|
printf("请选择子菜单编号:");
|
|
|
|
|
scanf("%d", &item);
|
|
|
|
|
switch (item) {
|
|
|
|
|
case 1:
|
|
|
|
|
printf("请输入新的姓名:\n");
|
|
|
|
|
scanf("%s", s2);
|
|
|
|
|
strcpy(s[num].name, s2);
|
|
|
|
|
fileWrite(n, s);
|
|
|
|
|
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;
|
|
|
|
|
case 2:
|
|
|
|
|
printf("请输入新的性别:\n");
|
|
|
|
|
scanf("%s", &sex1);
|
|
|
|
|
strcpy(s[num].sex, sex1);
|
|
|
|
|
fileWrite(n, s);
|
|
|
|
|
} else if(ch == 'Y' || ch == 'y') {
|
|
|
|
|
c = 0;
|
|
|
|
|
n = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
printf("请输入新的密码:\n");
|
|
|
|
|
scanf("%s", &passwd1);
|
|
|
|
|
strcpy(s[num].passwd, passwd1);
|
|
|
|
|
fileWrite(n, s);
|
|
|
|
|
} else if(ch != 'n' || ch != 'N' || ch != 'Y' || ch != 'y') {
|
|
|
|
|
n = 0;
|
|
|
|
|
c = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
return;
|
|
|
|
|
default:
|
|
|
|
|
printf("请在1-4之间选择\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("没有该卡号!!!\n");
|
|
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
if(c == 1) {
|
|
|
|
|
n = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
system("pause");
|
|
|
|
|
|
|
|
|
|
} while(ch != 'n' && ch != 'N');
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
void insert() {
|
|
|
|
|
int i, a, b;
|
|
|
|
|
printf("请输入待增加的用户数:\n");
|
|
|
|
|
scanf("%d", &n);
|
|
|
|
|
FILE * fp;
|
|
|
|
|
if ((fp = fopen("a.txt", "at")) == NULL) return;
|
|
|
|
|
ban s;
|
|
|
|
|
for (i = 0; i<n; i++) {
|
|
|
|
|
printf("\n请输入第%d个用户的卡号:", i + 1);
|
|
|
|
|
scanf("\n%s", &s[i].no);
|
|
|
|
|
printf("\n请输入第%d个用户的姓名:", i + 1);
|
|
|
|
|
scanf("%s", &s[i].name);
|
|
|
|
|
printf("\n请输入第%d 个用户的性别:", i + 1);
|
|
|
|
|
scanf("%s", &s[i].sex);
|
|
|
|
|
printf("\n请输入第%d 个用户的密码:", i + 1);
|
|
|
|
|
scanf("%s", &s[i].passwd);
|
|
|
|
|
//写入文件
|
|
|
|
|
fseek(fp, 0L, SEEK_END);
|
|
|
|
|
fprintf(fp, "%s %s %s %s %d \n", s[i].no, s[i].name, s[i].sex,s[i].passwd, s[i].balance = 0);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
|
|
//订单的查询
|
|
|
|
|
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");
|
|
|
|
|
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 j = 0;
|
|
|
|
|
FILE * fp, *fp1;
|
|
|
|
|
if ((fp = fopen("a.txt", "r")) == NULL) return;
|
|
|
|
|
ban s;
|
|
|
|
|
while (fscanf(fp, "%s %s %s %s %d ", &s[j].no, &s[j].name, &s[j].sex[j],&s[j].passwd, &s[j].balance) == 5) {
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
n = j;
|
|
|
|
|
|
|
|
|
|
int i, flag = 0;
|
|
|
|
|
char s1[LEN + 1];
|
|
|
|
|
printf("请输入要删除用户的卡号:\n");
|
|
|
|
|
scanf("%s", s1);
|
|
|
|
|
for (i = 0; i<n; i++) {
|
|
|
|
|
if (strcmp(s[i].no, s1) == 0) {
|
|
|
|
|
flag = 1;
|
|
|
|
|
for (j = i; j<n - 1; j++) {
|
|
|
|
|
strcpy(s[j].no, s[j + 1].no);
|
|
|
|
|
strcpy(s[j].name, s[j + 1].name);
|
|
|
|
|
s[j].balance = s[j + 1].balance;
|
|
|
|
|
strcpy(s[j].sex, s[j + 1].sex);
|
|
|
|
|
strcpy(s[j].passwd, s[j + 1].passwd);
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (flag == 0)
|
|
|
|
|
printf("该卡号不存在!\n");
|
|
|
|
|
if (flag == 1) {
|
|
|
|
|
n--;
|
|
|
|
|
fileWrite(n, s);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
printf("删除成功,显示结果请选择菜单\n");
|
|
|
|
|
} while(ch != 'n' && ch != 'N');
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
printf("\n\n\n\n\n\n ");
|
|
|
|
|
printf("返回附加功能菜单\n");
|
|
|
|
|
printf(" ");
|
|
|
|
|
system("pause");
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
void seek() {
|
|
|
|
|
int j = 0,flag=0;
|
|
|
|
|
FILE * fp;
|
|
|
|
|
if ((fp = fopen("a.txt", "r")) == NULL) return;
|
|
|
|
|
ban s;
|
|
|
|
|
while (fscanf(fp, "%s %s %s %s %d", &s[j].no, &s[j].name, &s[j].sex[j], &s[j].passwd, &s[j].balance) == 5) {
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
n = j;
|
|
|
|
|
int i = 0, item;
|
|
|
|
|
char s1[13], s2[20];
|
|
|
|
|
lable1:
|
|
|
|
|
printf("请输入卡号(输入0返回主菜单):\n");
|
|
|
|
|
scanf("%s", &s1);
|
|
|
|
|
if (strcmp(s1, "0") == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
|
if (strcmp(s[i].no, s1) == 0) {
|
|
|
|
|
printf("请输入密码:\n");
|
|
|
|
|
scanf("%s", &s2);
|
|
|
|
|
if (strcmp(s[i].passwd, s2) == 0) {
|
|
|
|
|
printf("您查询的账户信息如下\n");
|
|
|
|
|
printf("卡号:%s\n", s[i].no);
|
|
|
|
|
printf("姓名:%s\n", s[i].name);
|
|
|
|
|
printf("性别:%s\n", s[i].sex);
|
|
|
|
|
printf("余额:%d\n", s[i].balance);
|
|
|
|
|
flag = 2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("您输入的密码错误,请重新输入\n");
|
|
|
|
|
goto lable1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (flag != 2) {
|
|
|
|
|
printf("您输入的用户名不存在,请重新输入\n");
|
|
|
|
|
goto lable1;
|
|
|
|
|
|
|
|
|
|
//商品信息的保存
|
|
|
|
|
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 save()
|
|
|
|
|
{
|
|
|
|
|
int j = 0,flag=0;
|
|
|
|
|
FILE * fp;
|
|
|
|
|
if ((fp = fopen("a.txt", "r+")) == NULL) return;
|
|
|
|
|
ban s;
|
|
|
|
|
while (fscanf(fp, "%s %s %s %s %d", &s[j].no, &s[j].name, &s[j].sex[j], &s[j].passwd, &s[j].balance) == 5) {
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
n = j;
|
|
|
|
|
struct Bank *str = s;
|
|
|
|
|
int i = 0, item,save,aftersave;
|
|
|
|
|
char s1[13], s2[20];
|
|
|
|
|
lable1:
|
|
|
|
|
printf("请输入卡号(输入0返回主菜单):\n");
|
|
|
|
|
scanf("%s", &s1);
|
|
|
|
|
if (strcmp(s1, "0") == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
|
if (strcmp(s[i].no, s1) == 0) {
|
|
|
|
|
printf("请输入密码:\n");
|
|
|
|
|
scanf("%s", &s2);
|
|
|
|
|
if (strcmp(s[i].passwd, s2) == 0) {
|
|
|
|
|
printf("请输入您要存款的金额:");
|
|
|
|
|
scanf("%d",&save);
|
|
|
|
|
s[i].balance = save + s[i].balance;
|
|
|
|
|
fileWrite(n, s);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
printf("存款成功!\n");
|
|
|
|
|
printf("当前余额为%d元\n",s[i].balance);
|
|
|
|
|
flag = 2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("您输入的密码错误,请重新输入\n");
|
|
|
|
|
goto lable1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (flag != 2) {
|
|
|
|
|
printf("您输入的用户名不存在,请重新输入\n");
|
|
|
|
|
goto lable1;
|
|
|
|
|
|
|
|
|
|
//订单的保存信息
|
|
|
|
|
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 fileWrite(int n, ban s) {
|
|
|
|
|
FILE *fp1;
|
|
|
|
|
|
|
|
|
|
//管理维护子菜单
|
|
|
|
|
void secondmain() {
|
|
|
|
|
int i;
|
|
|
|
|
if ((fp1 = fopen("a.txt", "w")) == NULL) return;
|
|
|
|
|
for (i = 0; i<n; i++) {
|
|
|
|
|
fprintf(fp1, "%s %s %s %s %d ", s[i].no, s[i].name, s[i].sex,s[i].passwd, s[i].balance);
|
|
|
|
|
}
|
|
|
|
|
fclose(fp1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 menu() {
|
|
|
|
|
int num;
|
|
|
|
|
printf("------------------------------------------------------\n");
|
|
|
|
|
printf("------------------------------------------------------\n");
|
|
|
|
|
printf("-------------------银行管理系统-----------------------\n");
|
|
|
|
|
printf("------------------------------------------------------\n");
|
|
|
|
|
printf("------------------------------------------------------\n");
|
|
|
|
|
Sleep(3000);
|
|
|
|
|
system("CLS");
|
|
|
|
|
printf("------------------------------------------------------\n");
|
|
|
|
|
printf("----------------------请选择功能----------------------\n");
|
|
|
|
|
printf("-------------------1.查询 2.存款--------------------\n");
|
|
|
|
|
printf("-------------------3.取款 4.开户--------------------\n");
|
|
|
|
|
printf("-------------------5.销户 6.账户信息修改------------\n");
|
|
|
|
|
printf("-----------------------0.退出-------------------------\n");
|
|
|
|
|
printf("请选择菜单编号:");
|
|
|
|
|
scanf("%d", &num);
|
|
|
|
|
switch (num) {
|
|
|
|
|
case 0:
|
|
|
|
|
exit(0);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
seek();
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
save();
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
insert();
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
del();
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
modify();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("请在0-6之间选择\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//从键盘输入商品
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
while (k) {
|
|
|
|
|
system("cls");
|
|
|
|
|
menu();
|
|
|
|
|
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 0;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|