?? 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 + -