#include #include #include #include #include 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按任意键返回/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); 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; }
货品管理系统
最新推荐文章于 2019-06-30 01:31:05 发布