本系统大多数情况使用单一数字或数字空格加数字操控,另外,大多数情况 0 或 0 0 代表返回,0 1 代表撤回操作,读者可以自行摸索。本代码可以在Code Blocks中正常运行,用VS的朋友可以自行调试。
后续各函数解析及功能介绍使用说明会在下一篇博客里详细讲解,有需要的小伙伴可以点点关注呀!
源代码:
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <Windows.h>
#include <time.h>
#include <stdbool.h>
#include <conio.h>
void gotoxy();
void fun();
struct card* ININ();
struct card* ININ2();
void WRITE0();
void WRITE ();
void WRITE1 ();
void READ0();
void READ ();
void READ1 ();
void PASS0();
void PASS();
void CHOICE();
int get();
void CHANGE ();
void CUTOUT();
void SETPASS();
void BACK();
void MENU();
void SELL();
void BUY();
void SETUP();
void PRINT();
void PRINT0();
void PRINT ();
void PRINT1();
struct card
{
int num;
char name[10];
double a ,b ,t ,c;
struct card* next;
struct card* other;
};
struct sell
{
char name[10];
int n,y,r,s,f,dis;
double a,b,c;
struct sell*next;
};
struct buy
{
char name[10];
int n,y,r,s,f;
double a,b,c,d;
struct buy*next;
};
double y=0;
int discount = 10;
char password[20] ;
int kill=1,bk0=0,bk=0,pd=0;
typedef struct card* point;
typedef struct buy* pointb;
typedef struct sell* points;
point A=NULL , A0=NULL ;
point back0=NULL,back=NULL;
pointb B=NULL , B0=NULL ;
points C=NULL , C0=NULL ;
void gotoxy(int x, int y)//移动光标到指定位置
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void fun(int time)//进度条函数
{
int i = 0 ;
char bar[102] = { 0 };
gotoxy( 33 , 9 );
printf ( "数据载入中,请稍后\n" );
while (i <= 50)
{
gotoxy(33 , 10);
printf("[%-50s][%3d%%]\r", bar, i * 2);
Sleep ( time );
bar[i++] = '*';
bar[i] = '\0';
}
system("cls");
}
struct card* ININ (int a)
{
point p;
pointb r , r0;
double b , c , d ;
if(B==NULL)
{
r=(pointb)malloc(sizeof(struct buy));
B = r;
r->next = NULL;
}
else
{
r=B;
while(r!=NULL){
r0 = r;
r = r->next;
}
r=(pointb)malloc(sizeof(struct buy));
r0->next = r;
r->next=NULL;
}
p=(point)malloc(sizeof(struct card));
p->next = NULL;
p->other = NULL;
p->num = a;
printf ("\t\t\t\t请输入名称:");
scanf ("%s",&(p->name));
printf("\t\t\t\t货品单价[500g]:");
scanf ( "%lf" , &b );
if(b==0)
{
printf("\t\t\t\t货品单价[个]:");
scanf ( "%lf" , &c );
}
else
{
c=0;
}
printf("\t\t\t\t请输入进货量:");
scanf ( "%lf" , &d );
struct tm t; //tm结构指针
time_t now; //声明time_t类型变量
time (&now); //获取系统日期和时间
localtime_s(&t, &now);//获取当地日期和时间
if(b==0)
{
p->a =b;
p->b = c * 1.3;
p->t = c * 1.3;
p->c =d;
r->d =p->b*p->c;
}
else
{
p->a =b * 1.3;
p->t =b * 1.3;
p->b =c;
p->c =d;
r->d =b * p->c;
}
strcpy(r->name,p->name);
r->a=b;
r->b=c;
r->c=d;
r->n=t.tm_year+1900;
r->y= t.tm_mon + 1;
r->r= t.tm_mday;
r->s= t.tm_hour;
r->f= t.tm_min;
return p;
}
struct card* ININ2 (point p)
{
double b ,c , d ;
pointb r , r0 ;
r=B;
while(r!=NULL){
r0=r;
r=r->next;
}
r=(pointb)malloc(sizeof(struct buy));
r0->next = r;
r->next =NULL;
printf("\t\t\t\t名称:%s\n",p->name);
if(p->a>0||p->b==0){
printf("\t\t\t\t现有量:%.2lf 斤\n",p->c);
printf ( "\t\t\t\t进货单价[500g]:" );
scanf ( "%lf" , &b );
c=0;
}
else{
printf("\t\t\t\t现有量:%.2lf 个\n",p->c);
printf ( "进货单价[个]:" );
scanf ( "%lf" , &c );
b=0;
}
printf("\t\t\t\t进货量");
scanf("%lf",&d);
struct tm t; //tm结构指针
time_t now; //声明time_t类型变量
time(&now); //获取系统日期和时间
localtime_s(&t, &now);//获取当地日期和时间
p->c=d+p->c;
r->a=b;
r->b=c;
r->c=d;
strcpy(r->name,p->name);
r->d=(c+b)*p->c;
r->n=t.tm_year+1900;
r->y= t.tm_mon + 1;
r->r= t.tm_mday;
r->s= t.tm_hour;
r->f= t.tm_min;
return p;
}
int get ()
{
switch(getch()){
case 'Q':
case 'q':
return 1;
case 'W':
case 'w':
return 2;
case 'E':
case 'e':
return 3;
default:
get();
}
}
void SELL ()
{
system("cls");
double y0=0;
int i=0 , a=0 , n=0;
point p=A , p0;
points p1;
printf("\n\n\n\n\t\t\t\t╔═══════════════════════════════════════════════════════╗\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║");
while(p!=NULL)
{
printf("%5d%7s",p->num,p->name);
n++;
p=p->other;
if(n%4==0){
printf("\t║\n\t\t\t\t║");
}
}
printf (" ");
n++;
while(n%4!=0){
printf(" ");
n++;
}
printf("\t║\n");
printf("\t\t\t\t║ ║\n");
//printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t╚═══════════════════════════════════════════════════════╝\n");
scanf("%d",&a);
getchar();
if(a==0){
system("cls");
return ;
}
p=A;
for(i=1;i<a;i++)
{
p0 = p;
p=p->other;
if(p==NULL)
return;
}
int m = 0;
p0 = p;
p=p->next;
system("cls");
printf("\n\n\n\n\t\t\t\t╔═══════════════════════════════════════════════════════╗\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║");
while(p!=NULL)
{
printf("%5d%7s",p->num,p->name);
m++;
p=p->next;
if(m%4==0){
printf ("\t║\n\t\t\t\t║");
}
}
printf (" ");
m++;
while(m%4!=0)
{
printf(" ");
m++;
}
printf("\t║\n");
printf("\t\t\t\t║ ║\n");
//printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t╚═══════════════════════════════════════════════════════╝\n");
a=0;
scanf("%d",&a);
getchar();
if(a==0){
system("cls");
return ;
}
p=p0->next;
for(i=1;i<a;i++)
{
p0 = p ;
p = p->next;
if(p==NULL)
return;
}
system("cls");
a=10;
gotoxy(60,9);
printf("%.2lf",y);
gotoxy(0,0);
printf("\n\n\n\n\t\t\t\t名称: %10s \n\t\t\t\t库存: %10.2lf\n",p->name,p->c);
if(discount==10)
printf("\t\t\t\t当前折扣: 无\n");
else
printf("\t\t\t\t当前折扣: %d\n",discount);
printf("\t\t\t单价Q:%3.2lf 单价W:%3.2lf 折扣E\n",(p->a+p->b)*discount/10,(p->t)*discount/10);
i=get();
if(i==3)
{
printf("\t\t\t\t请输入折扣: ");
scanf("%d",&a);
system("cls");
gotoxy(60,9);
printf("%.2lf",y);
gotoxy(0,0);
printf("\n\n\n\n\t\t\t\t名称: %10s \n\t\t\t\t库存: %10.2lf\n",p->name,p->c);
printf("\t\t\t\t当前折扣: %d\n",a);
printf("\t\t\t单价Q:%3.2lf 单价W:%3.2lf 折扣E\n",(p->a+p->b)*a/10,(p->t)*a/10);
i=get();
}
if(p->b==0)
printf("\t\t\t\t请输入质量: ");
else
printf("\t\t\t\t请输入个数: ");
scanf("%d",&m);
p1=(points)malloc(sizeof(struct sell));
if(i==1)
{
p1->a=p->a+p->b;
if(a==10)
{
y0 = (p->a)*discount*m/10;
printf("\t\t\t%.2lf",y0);
p1->dis=discount;
}
else
{
y0 = (p->a)*a*m/10;
printf("\t\t\t%.2lf",y0);
p1->dis=a;
}
}
else if(i==2)
{
p1->a=p->t;
if(a==10)
{
y0 = (p->t)*discount*m/10;
printf("\t\t\t%.2lf",y0);
p1->dis=discount;
}
else
{
y0 = (p->t)*a*m/10;
printf("\t\t\t%.2lf",y0);
p1->dis=a;
}
}
struct tm t; //tm结构指针
time_t now; //声明time_t类型变量
time (&now); //获取系统日期和时间
localtime_s(&t, &now);//获取当地日期和时间
strcpy(p1->name,p->name);
p1->n=t.tm_year+1900;
p1->y=t.tm_mon+1;
p1->r=t.tm_mday;
p1->s=t.tm_hour;
p1->f=t.tm_min;
p1->b=(p1->a)*(p1->dis)/10;
p1->c=m;
p->c=p->c-m;
p1->next=C;
C=p1;
switch(getch()){
case'+':
y=y+y0;
break;
default:
y=y+y0;
printf("\n\t\t\t%.2lf\n\n\n",y);
system("pause");
y=0;
break;
}
SELL();
}
void BUY()
{
system("cls");
int i=0 , a=0 , n=0;
point p=A , p0;
printf("\n\n\n\n\t\t\t\t╔═══════════════════════════════════════════════════════╗\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║");
while(p!=NULL)
{
printf("%5d%7s",p->num,p->name);
n++;
p=p->other;
if(n%4==0){
printf("\t║\n\t\t\t\t║");
}
}
printf ("%5d",n+1);
printf (" 添加");
n++;
while(n%4!=0)
{
printf(" ");
n++;
}
printf("\t║\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t╚═══════════════════════════════════════════════════════╝\n");
scanf("%d",&a);
getchar();
if(a==0){
system("cls");
return ;
}
p=A;
for(i=1;i<a;i++)
{
p0 = p;
p=p->other;
if(p==NULL&&i!=a-1)
return;
}
if(p==NULL)
{
p=(point)malloc(sizeof(struct card));
if(a==1)
A=p;
else
p0->other= p;
p->num = a;
p->other=NULL;
p->next =NULL;
printf("\t\t\t\t请输入添加的名称:");
scanf ("%s",&(p->name));
p->next = ININ(1) ;
}
else
{
int m = 0;
p0 = p;
p=p->next;
system("cls");
printf("\n\n\n\n\t\t\t\t╔═══════════════════════════════════════════════════════╗\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║");
while(p!=NULL)
{
printf("%5d%7s",p->num,p->name);
m++;
p=p->next;
if(m%4==0){
printf ("\t║\n\t\t\t\t║");
}
}
printf("%5d",m+1);
printf (" 添加");
m++;
while(m%4!=0)
{
printf(" ");
m++;
}
printf("\t║\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t╚═══════════════════════════════════════════════════════╝\n");
a=0;
scanf("%d",&a);
getchar();
if(a==0){
system("cls");
return ;
}
p=p0->next;
for(i=1;i<a;i++)
{
p0 = p ;
p = p->next;
if(p==NULL&&i!=a-1)
return;
}
if (p==NULL)
p0->next=ININ(a);
else
p = ININ2(p);
}
system("cls");
BUY();
}
void READ0()
{
FILE*fp;
if( (fp=fopen("d:\\password.txt","r") )== NULL)
{
printf("打开写入文件buy.txt失败\n");
return;
}
fscanf(fp,"%s",&password);
fclose(fp);
return;
}
void READ ()
{
FILE*fp;
if( (fp=fopen("d:\\stock.txt","r") )== NULL)
{
printf("打开写入文件stock.txt失败\n");
return;
}
char a[10];
point p , p0 , p1 , r , r0 , r1;
p= (point)malloc(sizeof(struct card));
while(1)
{
if(A==NULL){
A = p;
r = p;
r0 = p;
p0 = p;
}
else{
p = r;
p0 = r;
}
while(1)
{
p->next = NULL;
p->other = NULL;
fscanf(fp,"%d %s %lf %lf %lf %lf\n",&p->num,&p->name,&p->a,&p->b,&p->t,&p->c);
if(p->num!=0)
{
p=(point)malloc(sizeof(struct card));
p0->next = p;
p1 = p0;
p0 = p;
}
else
{
strcpy(a,p->name);
free ( p ) ;
p1->next = NULL;
p1->other = NULL;
break;
}
}
if(strcmp(a,"OVER")!=0)
{
r=(point)malloc(sizeof(struct card));
r0->other= r;
r1 = r0;
r0 = r;
}
else
{
r1->other=NULL;
break;
}
}
fclose (fp);
}
void READ1 ()
{
FILE*fp;
if( (fp=fopen("d:\\buy.txt","r") )== NULL)
{
printf("打开写入文件buy.txt失败\n");
return;
}
pointb r , r0;
r=(pointb)malloc(sizeof(struct buy));
B=r;
struct tm t; //tm结构指针
time_t now; //声明time_t类型变量
time(&now); //获取系统日期和时间
localtime_s(&t, &now);//获取当地日期和时间
while(1)
{
fscanf(fp,"%d %d %d %d %d %s %lf %lf %lf %lf\n",&r->n,&r->y,&r->r,&r->s,&r->f,&r->name,&r->a,&r->b,&r->c,&r->d);
if(r->n!=0||r->n==t.tm_year+1900||r->y==t.tm_mon+1)
{
r0 = r;
r=(pointb)malloc(sizeof(struct buy));
r0->next=r;
}
else
{
r0->next=NULL;
free (r) ;
break ;
}
}
fclose(fp);
}
void READ2 ()
{
points p=NULL , p0=NULL;
FILE*fp;
if( (fp=fopen("d:\\sell.txt","r") )== NULL)
{
printf("0");
printf("打开写入文件sell.txt失败\n");
return;
}
p=(points)malloc(sizeof(struct sell));
C=p;
struct tm t; //tm结构指针
time_t now; //声明time_t类型变量
time(&now); //获取系统日期和时间
localtime_s(&t, &now);//获取当地日期和时间
while(1)
{
fscanf(fp,"%d %d %d %d %d %d %s %lf %lf %lf\n",&p->n,&p->y,&p->r,&p->s,&p->f,&p->dis,&p->name,&p->a,&p->b,&p->c);
if(p->n!=0||p->n==t.tm_year+1900||p->y==t.tm_mon+1)
{
p0=p;
p=(points)malloc(sizeof(struct sell));
p0->next=p;
}
else
{
p0->next=NULL;
free(p);
break;
}
}
fclose(fp);
}
void WRITE0()
{
FILE*fp;
if( (fp=fopen("d:\\password.txt","w") )== NULL)
{
printf("打开写入文件password.txt失败\n");
return;
}
fprintf(fp,"%s",password);
fclose(fp);
return;
}
void WRITE ()
{
point p=A , p0=A;
FILE*fp;
if( (fp=fopen("d:\\stock.txt","w") )== NULL)
{
printf("打开写入文件stock.txt失败\n");
return;
}
while (p0!=NULL)
{
while(p!=NULL)
{
fprintf(fp,"%d %s %lf %lf %lf %lf\n",p->num,p->name,p->a,p->b,p->t,p->c);
p = p->next;
}
fprintf(fp,"%d %s %lf %lf %lf %lf\n",0,"结束",0,0,0,0);
p0 = p0->other;
p = p0;
}
fprintf(fp,"%d %s %lf %lf %lf %lf\n",0,"OVER",0,0,0,0);
fclose(fp);
}
void WRITE1 ()
{
pointb r=B;
FILE*fp;
if( (fp=fopen("d:\\buy.txt","w") )== NULL)
{
printf("打开写入文件buy.txt失败\n");
return;
}
while(r!=NULL)
{
fprintf(fp,"%d %d %d % d %d %s %lf %lf %lf %lf\n",r->n,r->y,r->r,r->s,r->f,r->name,r->a,r->b,r->c,r->d);
r = r->next;
}
fprintf(fp,"%d %d %d % d %d %s %lf %lf %lf %lf\n",0,0,0,0,0,"over",0,0,0,0);
fclose(fp);
}
void WRITE2()
{
points p=C;
FILE*fp;
if( (fp=fopen("d:\\sell.txt","w") )== NULL)
{
printf("打开写入文件sell.txt失败\n");
return;
}
while(p!=NULL)
{
fprintf(fp,"%d %d %d %d %d %d %s %lf %lf %lf\n",p->n,p->y,p->r,p->s,p->f,p->dis,p->name,p->a,p->b,p->c);
p=p->next;
}
fprintf(fp,"%d %d %d %d %d %d %s %lf %lf %lf\n",0,0,0,0,0,0,"OVER",0,0,0);
fclose(fp);
}
void CHANGE ()
{
system("cls");
int a,b,c=0,i;
point p , p0;
p0=A;
printf("\t\t种类 名称 单价[500g] 单价[个] 单价(降价) 库存\n\n");
while(p0!=NULL)
{
printf("\t\t%d %s\n",p0->num,p0->name);
p=p0->next;
while(p!=NULL)
{
printf("\t\t\t\t%d %10s %10.2lf %10.2lf %10.2lf %10.2lf\n",p->num,p->name,p->a,p->b,p->t,p->c);
p=p->next;
}
p0=p0->other;
}
free(p0);
p = A;
scanf("%d %d",&a,&b);
getchar();
if (a==0 || b==0 )
return;
for(i=1;i<a;i++)
{
p= p->other;
if (p==NULL)
{
c = 1;
break ;
}
}
if(c==0)
{
for (i=0; i<b ;i++)
{
p =p->next;
if(p==NULL)
{
c = 1;
break ;
}
}
}
if(c==0)
{
system("cls");
printf("\n\n\n\t\t\t%10s\n",p->name);
if(p->b==0)
{
printf("\n\t\t\t\t现有单价[500g]:%.2lf\n",p->a);
printf("\t\t\t\t改后单价[500g]:");
scanf ("%lf",&p->a);
printf("\t\t\t\t现有单价[降价后]:%.2lf\n",p->a);
printf("\t\t\t\t改后单价[降价后]:");
scanf ("%lf",&p->t);
printf("\t\t\t\t现有库存: %.2lf\n",p->c);
printf("\t\t\t\t改后库存: ");
scanf ("%lf",&p->c);
}
else
{
printf("\n\t\t\t\t现有单价[个]:%.2lf\n",p->b);
printf("\t\t\t\t改后单价[个]:");
scanf ("%lf",&p->b);
printf("\t\t\t\t现有单价[降价后]:%.2lf\n",p->b);
printf("\t\t\t\t改后单价[降价后]:");
scanf ("%lf",&p->t);
printf("\t\t\t\t现有库存: %.2lf\n",p->c);
printf("\t\t\t\t改后库存: ");
scanf ("%lf",&p->c);
}
printf("\n\t\t\t\t 名称 单价[500g] 单价[个] 单价(降价) 库存\n\n");
printf("\t\t\t\t%d %10s %10.2lf %10.2lf %10.2lf %10.2lf\n",p->num,p->name,p->a,p->b,p->t,p->c);
system("pause");
return;
}
else
{
printf("error");
system("pause");
CHANGE();
}
}
void BACK()
{
point p=A , p0=A , p1=A;
int i;
if(pd==0)
return;
else
{
if(pd==1)
{
for(i=1;i<bk0;i++)
{
p1 = p0 ;
p0=p0->other;
}
p=p0;
for(i=0;i<bk;i++)
{
p0=p;
p=p->next;
}
p0->next=back;
back->next=p;
while(p!=NULL)
{
p->num=p->num+1;
p=p->next;
}
}
else if(pd==-1)
{
if(bk0==1&&bk==1)
{
if(A==NULL)
{
back0->next=back;
A=back0;
}
else
{
back0->next=back;
back0->other=A;
A=back0;
while(back0->other!=NULL)
{
back0=back0->other;
back0->num=back0->num+1;
}
}
}
else
{
for(i=1;i<bk0;i++)
{
p1 = p0 ;
p0=p0->other;
}
back0->next=back;
back0->other=p0;
p1->other=back0;
while(p0!=NULL)
{
p0->num=p0->num+1;
p0=p0->other;
}
}
}
}
back0=NULL;
back=NULL;
bk=0;
bk0=0;
pd=0;
return;
}
void CUTOUT()
{
system("cls");
int a,b,c=0,i;
point p , p0 , p1 , p2;
p0=A;
printf("\t\t种类 名称 单价[500g] 单价[个] 单价(降价) 库存\n\n");
while(p0!=NULL)
{
printf("\t\t%d %s\n",p0->num,p0->name);
p = p0->next;
while(p!=NULL)
{
printf("\t\t\t\t%d %10s %10.2lf %10.2lf %10.2lf %10.2lf\n",p->num,p->name,p->a,p->b,p->t,p->c);
p=p->next;
}
p0 =p0->other;
}
free(p0);
p=A;
p1=A;
p0=A;
scanf("%d %d",&a,&b);
if((a==0&&b==0)||(kill==0))
{
kill=0;
return;
}
else if((a==0&&b!=0)||(a!=0&&b==0))
{
BACK();
CUTOUT();
if(kill==0)
return;
}
for(i=1;i<a;i++)
{
p1 = p0 ;
p0=p0->other;
if(p0==NULL)
{
c = 1;
break;
}
}
if(c==0)
{
p=p0;
for(i=0;i<b;i++)
{
p0 = p;
p = p->next;
if(p==NULL)
{
c = 1;
break;
}
}
}
if(c!=0)
{
printf("error");
system("pause");
}
else
{
if (p->next==NULL && p->num==1 )
{
pd=-1;
p1->other = p0->other ;
if(p1->num==1&&p1->other!=NULL)
p1=p1->other;
else if(p1->num==1&&p1->other==NULL)
{
A = NULL;
back0=p0;
back0->next=NULL;
back=p;
return ;
}
free(back0);
free(back);
back0=p0;
back0->next=NULL;
back0->other=NULL;
back=p;
if(p1->num!=3&&p1->num!=2)
p1=p1->other;
else if (p1->num==2)
A=p1;
while(p1!=NULL)
{
p1->num=p1->num-1;
p1 = p1->other;
}
}
else
{
pd=1;
p0->next = p->next;
free(back);
back=p;
back->next=NULL;
while (p0->next!=NULL)
{
p0 = p0->next;
p0->num= p0->num-1;
}
}
bk0=a;
bk=b;
}
CUTOUT();
}
void PASS0()
{
if(password==0)
return;
else
{
char a[20]="0";
while(strcmp(password,a)!=0)
{
system("cls");
printf("\n\n\n\t\t\t\t请输入原密码:");
gets(a);
if(strcmp(password,a)!=0){
if(strcmp("0",a)==0)
return;
printf("\n\n\n\t\t\t\terror");
system("pause");}
}
strcpy(password,"\0");
WRITE0();
return;
}
}
void PASS ()
{
char a[20]="0",b[20]="0";
if(strcmp(password,"\0")!=0)
{
while(strcmp(password,a)!=0)
{
system("cls");
printf("\n\n\n\t\t\t\t请输入原密码:");
gets(a);
if(strcmp(password,a)!=0){
if(strcmp("0",a)==0)
return;
printf("\n\n\n\t\t\t\terror");
system("pause");
}
}
printf("\n\t\t\t\t请输入新密码(小于二十位字符):");
gets(a);
if(strcmp("0",a)==0)
return;
while(strcmp(b,a)!=0)
{
system("cls");
printf("\n\n\n\t\t\t\t请再次确认密码:");
gets(b);
if(strcmp(b,a)!=0){
if(strcmp(b,"0")==0)
return;
printf("error");
system("pause");
}
}
strcpy(password,a);
WRITE0();
printf("\n\n\n\t\t\t\t修改成功\n");
system("pause");
return;
}
else
{
printf("\n\n\n\t\t\t\t请输入新密码(小于二十位字符):");
gets(a);
if(strcmp("0",a)==0)
return;
while(strcmp(b,a)!=0)
{
system("cls");
printf("\n\n\n\t\t\t\t请再次确认密码:");
gets(b);
if(strcmp(b,a)!=0){
if(strcmp("0",b)==0)
return;
printf("\n\n\n\t\t\t\terror");
system("pause");}
}
strcpy(password,a);
WRITE0();
printf("\n\n\n\t\t\t\t修改成功\n");
system("pause");
return;
}
}
void DISCOUNT ()
{
int a=10;
if(discount==10)
printf("\n\n\n\n\n\t\t\t\t当前折扣: 无\n");
else
printf("\n\n\n\n\n\t\t\t\t当前折扣: %d\n",discount);
getchar();
printf("\n\t\t\t\t设置整体折扣: ");
scanf("%d",&a);
if(a<=0||a>10){
printf("error");
system("cls");
DISCOUNT();
return;
}
else{
discount=a;
fun(2);
return;
}
}
void SETPASS()
{
getchar();
system("cls");
printf("\n\n\n\n\t\t\t\t╔═════════════════════════════════════════════════════════════════╗\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║ ┏━━━━━━━━━━━┓ ┏━━━━━━━━━━━┓ ┏━━━━━━━━━━━┓ ║\n");
printf("\t\t\t\t║ ┃ 密码设置:1┃ ┃ 取消密码:2┃ ┃ 返回: 3 ┃ ║\n");
printf("\t\t\t\t║ ┗━━━━━━━━━━━┛ ┗━━━━━━━━━━━┛ ┗━━━━━━━━━━━┛ ║\n");
printf("\t\t\t\t╚═════════════════════════════════════════════════════════════════╝\n");
switch(getch()){
case '1':
system("cls");
fun(1);
PASS();
return;
case '2':
system("cls");
PASS0();
fun(1);
return;
case '3':
system("cls");
fun(1);
return;
default:
system("cls");
printf("error");
SETPASS();
}
}
void SETUP()
{
system("cls");
printf("\n\n\n\n\t\t╔═════════════════════════════════════════════════════════════════════════════════╗\n");
printf("\t\t║ ║\n");
printf("\t\t║ ║\n");
printf("\t\t║ ║\n");
printf("\t\t║ ┏━━┓ ┏━━┓ ┏━━┓ ┏━━┓ ┏━━┓ ║\n");
printf("\t\t║ 信息更改:┃ 1┃ 删除品种:┃ 2┃ 安全设置:┃ 3┃ 整体折扣:┃ 4┃ 返回:┃ 5┃ ║\n");
printf("\t\t║ ┗━━┛ ┗━━┛ ┗━━┛ ┗━━┛ ┗━━┛ ║\n");
printf("\t\t╚═════════════════════════════════════════════════════════════════════════════════╝\n");
switch(getch()){
case '1':
system("cls");
fun(2);
CHANGE();
SETUP();
break;
case '2':
system("cls");
fun(2);
CUTOUT();
kill=1;
SETUP();
break;
case '3':
system("cls");
fun(1);
SETPASS();
SETUP();
break;
case '4':
system("cls");
fun(2);
DISCOUNT ();
break;
case '5':
system("cls");
fun(1);
return;
default:
system("cls");
printf("error");
SETUP();
return;
}
}
void CHOICE ()
{
system("cls");
printf("\n\n\n\n\t\t\t\t╔═════════════════════════════════════════════════════════════════╗\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t║ ┏━━━━┓ ┏━━━━┓ ┏━━━━┓ ║\n");
printf("\t\t\t\t║ 销售记录:┃ 1 ┃ 进货记录:┃ 2 ┃ 返回:┃其他┃ ║\n");
printf("\t\t\t\t║ ┗━━━━┛ ┗━━━━┛ ┗━━━━┛ ║\n");
printf("\t\t\t\t╚═════════════════════════════════════════════════════════════════╝\n");
switch(getch()){
case '1':
system("cls");
PRINT1();
CHOICE();
return;
case '2':
system("cls");
PRINT0();
CHOICE();
return;
//default:
//CHOICE();
}
}
void MENU ()//打印菜单界面
{
system("cls");
printf("\n\n\n\n\n\n\t\t\t╔═══════════════════════════════════════════════════════════════════════════╗\n");
printf("\t\t\t║ ║\n");
printf("\t\t\t║ 果蔬管理系统 ║\n");
printf("\t\t\t║ ║\n");
printf("\t\t\t║ ║\n");
printf("\t\t\t║ ║\n");
printf("\t\t\t║ ║\n");
printf("\t\t\t║ ║\n");
printf("\t\t\t║ ║\n");
printf("\t\t\t║ ┏━━━━━━━━━┓ ┏━━━━━━━━━┓ ┏━━━━━━━━━┓ ┏━━━━━━━━━┓ ┏━━━━━━━━━┓ ┏━━━━━━━━━┓ ║\n");
printf("\t\t\t║ ┃售货系统1┃ ┃进货系统2┃ ┃ 设置 3 ┃ ┃ 库存 4 ┃ ┃交易记录5┃ ┃ 退出 6 ┃ ║\n");
printf("\t\t\t║ ┗━━━━━━━━━┛ ┗━━━━━━━━━┛ ┗━━━━━━━━━┛ ┗━━━━━━━━━┛ ┗━━━━━━━━━┛ ┗━━━━━━━━━┛ ║\n");
printf("\t\t\t║ ║\n");
printf("\t\t\t║ ║\n");
printf("\t\t\t╚═══════════════════════════════════════════════════════════════════════════╝\n");
switch(getch()){
case '1':
system("cls");
fun(3);
SELL();
MENU();
break;
case '2':
system("cls");
fun(3);
BUY();
MENU();
break;
case '3':
system("cls");
fun(3);
SETUP ();
MENU();
break;
case '4':
system("cls");
fun(3);
PRINT();
MENU();
break;
case '5':
system("cls");
fun(3);
CHOICE();
MENU();
break;
case '6':
if(A!=NULL)
WRITE();
if(B!=NULL)
WRITE1();
if(C!=NULL)
WRITE2();
exit(0);
break;
default:
system("cls");
printf("error");
MENU();
}
}
void PRINT0 ()
{
pointb r;
r=B;
printf("\t\t\t时间 名称 进价\500g 进价\个 进货量 金额\n");
//printf("%d%d%d%d%d %s %.2lf %.2lf %.2lf %.2lf\n",B->n,B->y,B->r,B->s,B->f,B->name,B->a,B->b,B->c,B->d);
while(r!=NULL)
{
printf("\t\t%d.%d.%d %2d:%2d %10s %10.2lf %10.2lf %10.2lf %10.2lf\n",r->n,r->y,r->r,r->s,r->f,r->name,r->a,r->b,r->c,r->d);
r=r->next;
}
system("pause");
system("cls");
return;
}
void PRINT ()
{
point p , p0;
p0=A;
printf("\t\t种类 名称 单价[500g] 单价[个] 单价(降价) 库存\n\n");
while(p0!=NULL)
{
printf("\t\t%d %s\n",p0->num,p0->name);
p=p0->next;
while(p!=NULL)
{
printf("\t\t\t\t%d %10s %10.2lf %10.2lf %10.2lf %10.2lf",p->num,p->name,p->a,p->b,p->t,p->c);
if(p->c<=5.0)
printf(" 紧缺\n");
else
printf("\n");
p=p->next;
}
p0=p0->other;
}
system("pause");
system("cls");
return;
}
void PRINT1()
{
points r;
r=C;
printf("\t\t时间 名称 原价 折扣 折后价 货量 金额\n");
while(r!=NULL)
{
printf("\t\t%d.%d.%d %2d:%2d %10s %10.2lf %2d %10.2lf %10.2lf %10.2lf\n",r->n,r->y,r->r,r->s,r->f,r->name,r->a,r->dis,r->b,r->c,r->b*r->c);
r=r->next;
}
system("pause");
system("cls");
return;
}
int main (){
READ0();
READ ();
READ1();
READ2();
if(strcmp(password,"\0")!=0)
{
char password1[20];
while(strcmp(password,password1)!=0)
{
system("cls");
printf("\n\n\n\n\n\n\t\t\t请输入密码:");
gets(password1);
}
}
MENU();
}
后续各函数解析及功能介绍使用说明会在下一篇博客里详细讲解,有需要的小伙伴可以点点关注呀!