📄 store adminsystem.cpp
字号:
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<windows.h>
typedef struct com{
//char num[10];
long num;
char name[10];
long count;
//char amount[10];
//char from[20];
//char stockdate[10];
struct com *next;
}COM;
#define LEN sizeof(COM)
#define PRINT "%-15ld%-15s%-15ld\n",ptr1->num,ptr1->name,ptr1->count
COM *head=NULL;
COM *ptr1=NULL,*ptr2=NULL;
FILE *fp;
void start(); //开始函数 over
COM *openfile(); //载入模块 over
COM *input(); //输入 over
COM *insert_perf(); //插入 over
COM *del_perf(); //删除 over
COM *revise_perf(); //修改 over
COM *pass(); //排序 over
void save(COM *head);//保存 over
void printf_perf(); //输出 over
void search(); //查找 over
char filename1[20];
char filename2[] = ".dat";
int main(void)
{
start();
system("cls");
fflush(stdin);
//printf("按任意键进入主菜单\n");
//getch();
int select;
char menu[] = {
" 1.输入货品信息\n"
" 2.输出全部货品信息\n"
" 3.插入货品信息\n"
" 4.删除货品信息\n"
" 5.修改货品信息\n"
" 6.综合排序\n"
" 7.综合查找\n"
" 8.存盘\n"
" 0.退出\n"
};
do{
system("cls");
printf("\n\n*******************************************************************************\n");
printf(" chlaws 制作");
printf("\n*******************************************************************************\n");
puts(menu);
printf("*******************************************************************************\n");
printf(" chlaws 制作");
printf("\n*******************************************************************************");
printf(" 请在0-8中选择:");
scanf("%d",&select);
switch(select)
{
case 1: head=input(); //输入模块
break;
case 2: printf_perf(); //输出模块
break;
case 3: head=insert_perf(); //插入模块
break;
case 4: head=del_perf(); //删除模块
break;
case 5: head=revise_perf(); //修改模块
break;
case 6: head=pass(); //排序模块
break;
case 7: search(); //查找模块
break;
case 8: save(head); //保存模块
break;
case 0: break;
}
}while(select);
getch();
return 0;
}
void start()
{
system("cls");
fflush(stdin);
char message[]={
"超市货品库存管理系统使用说明 \n"
"本系统是一个超市货品库存信息管理系统 \n"
"系统中输入多类货品信息,系统将以您输入的货品类名 \n"
"作为文件名保存 \n"
"本系统对已保存的货品信息可以调出后进行插入,删除,修改 \n"
"等操作,然后重新保存 \n"
"同时系统还有具备分别按货品号,货品名 \n"
"进行排序与查找功能 \n"
"欢迎您使用货品信息库存管理系统 \n"
};
puts(message);
printf("按任意键返回\n");
getch();
}
COM *input()
{
system("cls");
fflush(stdin);
COM *ptr3;
int n = 0;
char cell[5];
char y[]="yes";
ptr1=(COM *)malloc(LEN);
printf("input num:\n");
fflush(stdin);
scanf("%ld",&ptr1->num);
fflush(stdin);
printf("input name:\n");
fflush(stdin);
gets(ptr1->name);
printf("input count:\n");
fflush(stdin);
scanf("%ld",&ptr1->count);
head=ptr1;
ptr2=ptr1;
do
{
printf("are you continue input?(yes/no)\n");
fflush(stdin);
gets(cell);
if(strcmpi(cell,"no")==0)
{
break;
}
ptr1=(COM *)malloc(LEN);
printf("input num:\n");
fflush(stdin);
scanf("%ld",&ptr1->num);
printf("input name:\n");
fflush(stdin);
gets(ptr1->name);
printf("input count:\n");
fflush(stdin);
scanf("%d",&ptr1->count);
ptr2->next = ptr1;
ptr2=ptr1;
printf("input ok!\n");
}while(strcmpi(cell,y) == 0);
printf("\n\n\n\n\n***********************************************");
ptr2->next= NULL;
ptr3=head;
while(ptr3!=NULL)
{
printf("\nnum:%ld\tname: %s\tcount: %ld\n",ptr3->num,ptr3->name,ptr3->count);
ptr3=ptr3->next;
}
printf("\n注意保存\n");
printf("\n按任意键返回\n");
getch();
return head;
}
COM *insert_perf()
{
system("cls");
fflush(stdin);
COM *ptr3=(COM *)malloc(LEN);
char key[4];
head=openfile();
ptr1=head;
while(ptr1->next != NULL)
{
ptr1 = ptr1->next;
}
printf("input insert goods's num:\n");
fflush(stdin);
scanf("%ld",&ptr3->num);
printf("input insert goods's name:\n");
fflush(stdin);
gets(ptr3->name);
printf("input insert goods's count:\n");
fflush(stdin);
scanf("%ld",&ptr3->count);
// ptr1 = ptr3;
ptr3->next = ptr1->next;
ptr1->next=ptr3;
ptr1 = ptr3;
printf("insert ok!\n");
do{
printf("are you continue insert data?(yes/no)\n");
fflush(stdin);
gets(key);
if(!strcmpi(key,"no"))
{
printf("ok! you already insert!\n");
break;
}
if(!strcmpi(key,"yes"))
{
ptr3 = (COM *)malloc(LEN);
printf("input insert goods's num:\n");
fflush(stdin);
scanf("%ld",&ptr3->num);
printf("input insert goods's name:\n");
fflush(stdin);
gets(ptr3->name);
printf("input insert goods's count:\n");
fflush(stdin);
scanf("%ld",&ptr3->count);
ptr3->next = ptr1->next;
ptr1->next = ptr3;
ptr1=ptr3;
}
}while(!strcmpi(key,"yes"));
///////////////保存到文件/////////////////////
/////////////////////////////////////////
printf("\n注意保存\n");
printf("\n按任意键返回\n");
getch();
return head;
}
COM *del_perf()
{
system("cls");
fflush(stdin);
int choise;
int n;
long num;
char name[20];
char key[4];
COM *ptr3;
head = openfile();
if(head == NULL)
{
return NULL;
}
do{
system("cls");
printf("input you can delete goods's num or name!\n");
printf("1.input num to delete\n2.input name to delete\n3.press any key to return");
printf("\ninput you choise!\n");
printf("choise:");
fflush(stdin);
scanf("%d",&choise);
ptr1 = head;
n = 1;
if(choise !=1 && choise !=2)
{
break;
}
if(choise == 1)
{
printf("input num!\n");
fflush(stdin);
scanf("%ld",&num);
// printf("ptr1->num = %ld",ptr1->num);
while(ptr1!=NULL && ptr1->num!=num)
{
ptr2 = ptr1;
ptr1 = ptr1->next;
n = n+1;
//printf("ptr1->num = %ld,ptr2->num = %ld,n = %d",ptr1->num,ptr2->num,n);
}
if(ptr1!=NULL)
{
if(n == 1)
{
head = ptr1->next;
}
if(n!=1)
{
ptr2->next = ptr1->next;
}
free(ptr1);
printf("delete ok!\n");
printf("last data:\n");
ptr3 = head;
while(ptr3 != NULL)
{
printf("\n%-15ld%-15s%-15ld\n",ptr3->num,ptr3->name,ptr3->count);
ptr3 = ptr3->next;
}
}
else
{
printf("in database can not find you input data\n");
}
}//if choise == 1
if(choise == 2)
{
printf("input name\n");
fflush(stdin);
gets(name);
while(strcmpi(ptr1->name,name)!=0 && ptr1->next!=NULL)
{
ptr2 = ptr1;
ptr1 = ptr1->next;
n = n+1;
}
if(ptr1!=NULL)
{
if(n == 1)
{
head = ptr1->next;
}
else
{
ptr2->next = ptr1->next;
}
free(ptr1);
printf("delete ok!\n");
printf("last data:\n");
ptr3 = head;
while(ptr3 != NULL)
{
printf("\n%-15ld%-15s%-15ld\n",ptr3->num,ptr3->name,ptr3->count);
ptr3 = ptr3->next;
}
}
else
{
printf("in database can not find you input name!\n");
}
}//if choise == 2;
printf("\nare you continue to delete?(yes/no)\n");
fflush(stdin);
gets(key);
}while(strcmpi(key,"yes") == 0);
printf("\n注意保存\n");
printf("\按任意键返回\n");
getch();
return head;
}
COM *revise_perf()
{
long num;
int choise;
char name[20];
char key[4];
head = openfile();
fflush(stdin);
if(head == NULL)
{
return NULL;
}
do{
ptr1 = head;
system("cls");
printf("1:通过货品编号修改信息\n2:通过货品名称修改信息\n3:不修改按任意键\n");
fflush(stdin);
scanf("%d",&choise);
printf("choise = %d",choise);
if(choise!=1 && choise!=2)
{
break;
}
if(choise == 1)
{
printf("\n输入货品编号\n");
fflush(stdin);
scanf("%ld",&num);
while(ptr1!=NULL && ptr1->num!=num)
{
ptr1 = ptr1->next;
}
if(ptr1!=NULL)
{
printf("你将要修改的信息已经找到\n");
printf("货品编号: %ld\n货品名称: %s\n货品数量: %ld",ptr1->num,ptr1->name,ptr1->count);
Sleep(2000);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -