📄 store adminsystem.cpp
字号:
system("cls");
printf("\n在这输入你要修改的信息\n");
printf("\n输入修改后的货品编号:\n");
fflush(stdin);
scanf("%ld",&ptr1->num);
printf("\n输入修改后的货品名称:\n");
fflush(stdin);
gets(ptr1->name);
printf("\n输入修改后的货品数量:\n");
fflush(stdin);
scanf("%ld",&ptr1->count);
}
else
{
printf("你输入的货品编号不存在\n");
}
}// choise == 1
if(choise == 2)
{
printf("\n输入货品名称\n");
fflush(stdin);
gets(name);//
while(ptr1!=NULL && strcmpi(ptr1->name,name)!=0)
{
ptr1 = ptr1->next;
}
if(ptr1!=NULL)
{
printf("你将要修改的信息已经找到\n");
printf("货品编号: %ld\n货品名称: %s\n货品数量: %ld",ptr1->num,ptr1->name,ptr1->count);
Sleep(2000);
system("cls");
printf("\n在这输入你要修改的信息\n");
printf("\n输入修改后的货品编号:\n");
fflush(stdin);
scanf("%ld",&ptr1->num);
printf("\n输入修改后的货品名称:\n");
fflush(stdin);
gets(ptr1->name);
printf("\n输入修改后的货品数量:\n");
fflush(stdin);
scanf("%ld",&ptr1->count);
}
else
{
printf("你输入的货品名称不存在\n");
}
}//choise == 2
printf("是否继续修改(yes/no)\n");
fflush(stdin);
gets(key);
}while(strcmpi(key,"yes") == 0);
printf("\n注意保存\n");
printf("\n按任意键返回\n");
getch();
return head;
}
COM *pass()
{
char key[4];
int choise;
int select;
long temp;
head = openfile();
fflush(stdin);
if(head == NULL)
{
return NULL;
}
do{
system("cls");
ptr1 = head;
ptr2 = head->next;
printf("1:按货品编号排序\n2:按货品数量排序\n3:按任意键不做任何操作\n");
fflush(stdin);
scanf("%d",&choise);
if(choise!=1 && choise!=2)
{
break;
}
if(choise == 1)
{
system("cls");
printf("1.按从小到大排序\n2.按从大到小排序\n");
fflush(stdin);
scanf("%d",&select);
if(select == 1)
{
while(ptr1!=NULL)
{
while(ptr2!=NULL)
{
if(ptr1->num > ptr2->num)
{
temp = ptr1->num;
ptr1->num = ptr2->num;
ptr2->num = temp;
}
ptr2=ptr2->next;
}//while ptr2
ptr1 = ptr1->next;
if(ptr1->next == NULL)
{
break;
}
else
ptr2 = ptr1->next;
}//while ptr1
}//按从小到大排序
if(select == 2)
{
while(ptr1!=NULL)
{
while(ptr2!=NULL)
{
if(ptr1->num < ptr2->num)
{
temp = ptr1->num;
ptr1->num = ptr2->num;
ptr2->num = temp;
}
ptr2=ptr2->next;
}//while ptr2
ptr1 = ptr1->next;
if(ptr1->next == NULL)
{
break;
}
else
ptr2 = ptr1->next;
}// while prt1
}//按从大到小排序
printf("排序操作完成!\n");
}// choise ==1
if(choise == 2)
{
system("cls");
printf("1.按从小到大排序\n2.按从大到小排序\n");
fflush(stdin);
scanf("%d",&select);
if(select == 1)
{
while(ptr1!=NULL)
{
while(ptr2!=NULL)
{
if(ptr1->count > ptr2->count)
{
temp = ptr1->count;
ptr1->count = ptr2->count;
ptr2->count = temp;
}
ptr2=ptr2->next;
}//while ptr2
ptr1 = ptr1->next;
if(ptr1->next==NULL)
{
break;
}
else
ptr2 = ptr1->next;
}//while ptr1
}//按从小到大排序
if(select == 2)
{
while(ptr1!=NULL)
{
while(ptr2!=NULL)
{
if(ptr1->count < ptr2->count)
{
temp = ptr1->count;
ptr1->count = ptr2->count;
ptr2->count = temp;
}
ptr2=ptr2->next;
}//while ptr2
ptr1 = ptr1->next;
if(ptr1->next == NULL)
{
break;
}
else
ptr2 = ptr1->next;
}// while prt1
}//从大到小排序
printf("排序操作完成!\n");
}//choise == 2
printf("\n是否继续排序!(yes/no)\n");
fflush(stdin);
gets(key);
}while(!strcmpi(key,"yes"));
printf("\n注意保存\n");
printf("\n按任意键返回\n");
getch();
return head;
}
void save(COM *head)
{
system("cls");
fflush(stdin);
printf("\ninput filename1\n");
fflush(stdin);
gets(filename1);
if((fp=fopen(strcat(filename1,filename2),"wb")) == NULL)
{
printf("cannot file!\n");
return;
}
ptr1=head;
fflush(stdin);
rewind(fp);
while(ptr1!=NULL)
{
if(!fwrite(ptr1,LEN,1,fp))
{
printf("input to file false!\n");
return ;
}
ptr1=ptr1->next;
}
fclose(fp);
printf("save ok!\n");
printf("按任意键返回\n");
getch();
}
void printf_perf()
{
system("cls");
fflush(stdin);
head=openfile();
int i=1;
if(head == NULL)
{
return;
}
fflush(stdin);
ptr2 = head;
while(ptr2!=NULL)
{
printf("\nnum:%ld\tname: %s\tcount: %ld\n",ptr2->num,ptr2->name,ptr2->count);
ptr2=ptr2->next;
i++;
if(i/15 == 1)
{
printf("input any key to look next page\n");
getch();
system("cls");
i = 1;
}
}
printf("按任意键返回\n");
getch();
}
void search()
{
system("cls");
fflush(stdin);
int choise;
long num;
char name[20];
head = openfile();
ptr1 = head;
printf("input you can search goods's num or name!\n");
printf("1.input num\n2.input name\n3.press any key to return");
printf("\ninput you choise!\n");
fflush(stdin);
scanf("%d",&choise);
if(choise == 1)
{
printf("input num!\n");
fflush(stdin);
scanf("%ld",&num);
while(ptr1->num!=num && ptr1->next!=NULL)
{
// ptr2 = ptr1;
ptr1 = ptr1->next;
// n = n+1;
}
if(ptr1!=NULL)
{
printf("find data!\n");
Sleep(1000);
system("cls");
printf(PRINT);
}
else
{
printf("in database can not find you input data\n");
}
}
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)
{
printf("find data!\n");
Sleep(1000);
system("cls");
printf(PRINT);
}
else
{
printf("in database can not find you input name!\n");
}
}//
printf("按任意键返回\n");
getch();
}
COM *openfile()
{
system("cls");
int n = 1;
printf("input filename1:\n");
fflush(stdin);
gets(filename1);
if((fp=fopen(strcat(filename1,filename2),"rb")) == NULL)
{
printf("can not open file!\n");
getch();
return(NULL);
}
if(!(ptr2=ptr1=(COM *)malloc(LEN)))
{
printf("memory assign false!\n");
getch();
return(NULL);
}
if(!fread(ptr1,LEN,1,fp))
{
printf("can not read in file\n");
getch();
return(NULL);
}
if(ptr1->next == NULL)
{
head=ptr1;
}
else
{
do{
if(n==1)
{
head=ptr1;
}
else
{
ptr2->next=ptr1;
}
n = n+1;
ptr2=ptr1;
if(!(ptr1=(COM *)malloc(LEN)) )
{
printf("memory assign false!\n");
getch();
return(NULL);
}
if(!fread(ptr1,LEN,1,fp))
{
printf("can not read in file\n");
getch();
return(NULL);
}
}while(ptr1->next!=NULL);
ptr2->next=ptr1;
}
fclose(fp);
// printf("按任意键返回\n");
// getch();
return head;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -