当前位置:网站首页>药店管理系统
药店管理系统
2022-06-30 12:00:00 【漠–】
药店管理系统
前言
做系统之前,记得将文件存储位置确定,该系统采用的是创建一个文件夹,将.c文件放在该文件夹中,文本文件直接创建在该文件夹中(即从当前位置出发创建文件)。
具体实现
框架
具体函数内部在后面进行详细说明
#include<stdio.h>
#include<windows.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
//每一个药品的信息
typedef struct medicine{
char id[20];
char name[50];
char function[100];
int num;
double price;
struct medicine *next;
}Medicine;
//每一个用户的用户名和密码
typedef struct user{
char username[50];
char password[50];
struct user*next;
}User;
//注册登录
int Usermenu(User*userHead);//用户注册登录主界面
bool login(User*userHead);//用户登陆界面
bool check(User *userHead);//检查密码的功能函数
void user_print(User *userHead);//管理员查看密码的功能函数
void user(User *userHead);//用户注册界面
void user_change(User*userHead);//用户修改密码界面
void user_read(User*userHead);//文件中用户名信息读入链表
void user_write(User*userHead);//链表中用户名信息存入文件
void gotoXY(int x,int y);//将光标定在界面中某个位置
//系统界面
void menu();//主菜单
void read(Medicine*head);//文件中药品信息读入链表
void write(Medicine*head);//链表中药品信息存入文件
void add(Medicine *head);//添加新的药品信息
void Delete(Medicine *head);//删除药品信息
void del1(Medicine *head);//删除药品信息的功能函数(按编号删除)
void del2(Medicine *head);//删除药品信息的功能函数(按名称删除)
void Change(Medicine *head);//修改药品信息
Medicine *Find(Medicine *head);//查询药品信息
Medicine *find1(Medicine *head);//查询药品信息的功能函数(按编号查找)
Medicine *find2(Medicine *head);//查询药品信息的功能函数(按名称查找)
void Insert(Medicine *head);//将新的药品信息插入指定位置
void insert1(Medicine *head);//将新的药品信息插入指定药品前面
void insert1_1(Medicine *head);//将新的药品信息插入指定药品前面的功能函数(按编号查找指定药品)
void insert1_2(Medicine *head);//将新的药品信息插入指定药品前面的功能函数(按名称查找指定药品)
void insert2(Medicine *head); //将新的药品信息插入指定药品后面
void Sort(Medicine *head);//排序药品信息
bool sort1(Medicine *p1,Medicine *p2);//排序药品信息的功能函数(通过数量升序排序)
bool sort2(Medicine *p1,Medicine *p2);//排序药品信息的功能函数(通过数量降序排序)
bool sort3(Medicine *p1,Medicine *p2);//排序药品信息的功能函数(通过价格升序排序)
bool sort4(Medicine *p1,Medicine *p2);//排序药品信息的功能函数(通过价格降序排序)
void Print(Medicine *head);//打印全部药品信息
void print(Medicine *L);//打印药品信息的功能函数(打印单个药品信息)
void Esc();// 退出管理系统
int main()
{
Medicine *head=(Medicine*)malloc(sizeof(Medicine));
head->next=NULL;
User *userHead=(User*)malloc(sizeof(User));
userHead->next=NULL;
read(head);
user_read(userHead);
Medicine *p;
int flag=0;
while(1){
flag=Usermenu(userHead);
if(flag==-1||flag==1){
break;
}
}
if(flag==1){
while(1){
menu();
int choice;
scanf("%d",&choice);
switch(choice){
case 1:
add(head);
write(head);
break;
case 2:
Delete(head);
write(head);
break;
case 3:
Change(head);
break;
case 4:
p=Find(head);
if(p){
print(p);
system("pause");
}
break;
case 5:
Print(head);
break;
case 6:
Insert(head);
break;
case 7:
Sort(head);
break;
case 8:
Esc();
break;
}
}
}else{
gotoXY(0,15);
printf("已退出系统!!!\n");
return 0;
}
}
函数功能分析
注册登录界面函数介绍
登陆菜单
页面通过输入的编号进入不同的页面来实现不同的功能
返回值用来决定是否成功登陆系统
int Usermenu(User*userHead)
{
system("cls");
int flag=0;
int choice;
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" *******************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" ***************查看已注册的用户名和密码(仅管理员可用)---6 ****************\n");
printf(" ***************登录---1 ****************\n");
printf(" ***************退出---2 ****************\n");
printf(" ***************注册账号---3 ****************\n");
printf(" ***************修改密码---4 ****************\n");
printf(" ********************************************************************************\n");
printf(" ***************请选择要进入的界面: ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
gotoXY(54,10);
scanf("%d",&choice);
switch(choice){
case 1:
flag=login(userHead);
break;
case 2:
flag=-1;
break;
case 3:
user(userHead);
flag=0;
break;
case 4:
user_change(userHead);
break;
case 6:
user_print(userHead);
break;
}
return flag;
}
管理员输出函数
管理员用来查看已注册的用户名和密码
void user_print(User *userHead)
{
system("cls");
char password[50]="mingrizhiwang";
char t[50];
printf("请输入管理员密码:");
scanf("%s",t);
if(strcmp(password,t)==0){
printf("验证成功!\n");
} else{
printf("验证失败,即将返回登陆界面,");
system("pause");
return;
}
User *p=userHead->next;
printf("已注册用户:\n");
while(p){
printf("-------------------------------\n");
printf("用户名:%s\n",p->username);
printf("密码:%s\n\n",p->password);
p=p->next;
}
system("pause");
}
登陆界面
bool login(User *userHead)
{
system("cls");
int count=5;
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" ************************* 登陆界面 ***************************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" ***************用户名: ****************\n");
printf(" ***************密码: ****************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
while(count--){
if(check(userHead)){
gotoXY(34,10);
printf("输入正确,即将进入系统,");
system("pause");
break;
}else{
gotoXY(34,10);
printf("输入错误,请重新输入,你还有%d次机会",count);
gotoXY(34,12);
printf("提示:直接覆盖原来的用户名密码输入即可");
if(count==0){
gotoXY(34,10);
system("cls");
printf("机会已用完,即将自动退出登陆页面,");
system("pause");
return 0;
}
}
}
return 1;
}
用户名密码验证函数
bool check(User *userHead)
{
char name[50];
char password[50];
char t;
int cnt=0;
gotoXY(41,5);
scanf("%s",name);
gotoXY(39,6);
while((t=getch())!='\r'){
password[cnt++]=t;
printf("*");
}
gotoXY(0,15);
User *p=userHead->next;
int flag=0;
while(p){
if(strcmp(p->username,name)==0&&strcmp(p->password,password)==0){
flag=1;
}
p=p->next;
}
return flag;
}
用户注册界面
void user(User*userHead)
{
system("cls");
User *p=userHead;
User *q;
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" ************************* 注册界面 ***************************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" ***************用户名: ****************\n");
printf(" ***************密码: ****************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
printf(" ***************请输入您要注册的用户名和密码 ****************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
q=(User*)malloc(sizeof(User));
q->next=NULL;
gotoXY(41,5);
scanf("%s",q->username);
gotoXY(39,6);
scanf("%s",q->password);
q->next=p->next;
p->next=q;
user_write(userHead);
gotoXY(34,12);
printf("注册成功,");
system("pause");
}
用户名修改密码界面
void user_change(User*userHead)
{
system("cls");
char name[50];
char password[50];
printf("-------------------------------\n");
printf("请输入您的用户名:");
scanf("%s",name);
int flag=0;
User *p=userHead->next;
while(p){
if(strcmp(name,p->username)==0){
flag=1;
break;
}
p=p->next;
}
if(flag){
printf("请输入您的旧密码:");
scanf("%s",password);
if(strcmp(p->password,password)==0){
printf("验证成功\n");
printf("请输入您的新密码:");
scanf("%s",p->password);
printf("修改成功\n");
} else{
printf("您的旧密码输入错误,请确定好旧密码再重新进入该页面修改密码!!!\n");
}
}else{
printf("没有该用户名信息!\n");
}
user_write(userHead);
system("pause");
}
读文件函数
void user_read(User*userHead)
{
FILE *l=fopen("UsernameAndPassword.txt","r");
if(l==NULL){
return;
}
User *p=userHead,*q;
User a;
while(fscanf(l,"%s %s",a.username,a.password)!=EOF)
{
q=(User*)malloc(sizeof(User));
*q=a;
q->next=NULL;
p->next=q;
p=q;
}
fclose(l);
}
写文件函数
void user_write(User*userHead)
{
FILE *l=fopen("UsernameAndPassword.txt","w");
if(l==NULL){
return;
}
User *p=userHead->next;
while(p){
fprintf(l,"%s %s\n",p->username,p->password);
p=p->next;
}
fclose(l);
}
将光标定在指定位置的函数
void gotoXY(int x,int y)
{
COORD coord={x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
系统界面函数介绍
主菜单
void menu() //主页面
{
system("cls");
printf(" ****************************************************************\n");
printf(" *********** 药店管理系统 ***********\n");
printf(" *********** 1 ---- 添加药品信息 ***********\n");
printf(" *********** 2 ---- 删除药品信息 ***********\n");
printf(" *********** 3 ---- 修改药品信息 ***********\n");
printf(" *********** 4 ---- 查询药品信息 ***********\n");
printf(" *********** 5 ---- 输出药品信息 ***********\n");
printf(" *********** 6 ---- 插入药品信息 ***********\n");
printf(" *********** 7 ---- 排序管理系统 ***********\n");
printf(" *********** 8 ---- 退出管理系统 ***********\n");
printf(" ****************************************************************\n");
printf(" 请选择想要实现的功能(数字):");
}
读文件函数
void read(Medicine*head)
{
FILE *l=fopen("mingrijiangzhi.txt","r");
if(l==NULL){
return;
}
Medicine t;
Medicine *p=head;
Medicine *q;
while(fscanf(l,"%s %s %s %d %lf",t.id,t.name,t.function,&t.num,&t.price)!=EOF){
q=(Medicine*)malloc(sizeof(Medicine));
*q=t;
q->next=NULL;
p->next=q;
p=q;
}
fclose(l);
}
写文件函数
void write(Medicine*head)
{
FILE *l=fopen("mingrijiangzhi.txt","w");
if(l==NULL){
return;
}
Medicine*p=head->next;
while(p){
fprintf(l,"%s %s %s %d %.2lf\n",p->id,p->name,p->function,p->num,p->price);
p=p->next;
}
fclose(l);
}
添加药品信息
void add(Medicine *head)
{
system("cls");
Medicine a;
printf("请输入要添加药品的相关信息:\n");
printf("编号:");
scanf("%s", a.id);
printf("名称:");
scanf("%s", a.name);
printf("功效:");
scanf("%s", a.function);
printf("数量:");
scanf("%d", &a.num);
printf("价格:");
scanf("%lf", &a.price);
Medicine *p=(Medicine*)malloc(sizeof(Medicine));
*p=a;
p->next=NULL;
Medicine *q=head;
p->next=q->next;
q->next=p;
}
删除药品信息
void Delete(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf("通过编号删除---输入1\n");
printf("通过名称删除---输入2\n");
printf("请选择删除方式:\n");
int choice;
scanf("%d",&choice);
switch(choice){
case 1:
del1(head);
break;
case 2:
del2(head);
break;
}
printf("-------------------------------\n");
printf("该药品已删除:\n");
}
void del1(Medicine *head)
{
char s[50];
printf("请输入要删除的药品编号:");
scanf("%s",s);
Medicine *p=head->next;
Medicine *q=head;
int flag=0;
while(p){
if(strcmp(s,p->id)==0){
flag=1;
printf("-------------------------------\n");
printf("该药品已删除:\n");
print(p);
system("pause");
q->next=p->next;
p->next=NULL;
free(p);
break;
}
p=p->next;
q=q->next;
}
if(flag==0){
printf("-------------------------------\n");
printf("该药品不存在:\n");
system("pause");
}
}
void del2(Medicine *head)
{
char s[50];
printf("请输入要删除的药品名称:");
scanf("%s",s);
Medicine *p=head->next;
Medicine *q=head;
int flag=0;
while(p){
if(strcmp(s,p->name)==0){
flag=1;
printf("-------------------------------\n");
printf("该药品已删除:\n");
print(p);
system("pause");
q->next=p->next;
p->next=NULL;
free(p);
break;
}
p=p->next;
q=q->next;
}
if(flag==0){
printf("-------------------------------\n");
printf("该药品不存在:\n");
system("pause");
}
}
修改药品信息
void Change(Medicine *head)
{
Medicine *p=Find(head);
if(p==NULL){
return;
}
print(p);
while(1){
printf("-------------------------------\n");
printf("药品编号---1\n");
printf("药品名称---2\n");
printf("药品功效---3\n");
printf("药品剩余数量---4\n");
printf("药品价格---5\n");
printf("请选择要修改的信息:");
int choice;
scanf("%d",&choice);
char s[50];
int num;
double price;
printf("请输入修改后的信息:");
switch(choice){
case 1:
scanf("%s",s);
strcpy(p->id,s);
break;
case 2:
scanf("%s",s);
strcpy(p->name,s);
break;
case 3:
scanf("%s",s);
strcpy(p->function,s);
break;
case 4:
scanf("%d",&num);
p->num=num;
break;
case 5:
scanf("%lf",&price);
p->price=price;
break;
}
printf("-------------------------------\n");
printf("该药品信息被修改为:\n");
print(p);
printf("是否继续修改? 是(1)/否(0)");
int flag;
scanf("%d",&flag);
if(!flag){
break;
}else{
system("cls");
}
}
printf("-------------------------------\n");
printf("该药品当前信息为:\n");
print(p);
system("pause");
write(head);
}
查询药品信息
Medicine *Find(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf("通过编号查找药品---1\n");
printf("通过名称查找药品---2\n");
printf("请选择查找方式:");
int choice;
scanf("%d",&choice);
Medicine *p=NULL;
switch(choice){
case 1:
p=find1(head);
break;
case 2:
p=find2(head);
break;
}
if(p==NULL){
printf("没有该药品信息!请重新查找!!!\n");
system("pause");
}
return p;
}
Medicine *find1(Medicine *head)
{
char s[50];
printf("请输入要查找的药品编号:");
scanf("%s",s);
Medicine *p=head->next;
while(p){
if(strcmp(s,p->id)==0){
return p;
}
p=p->next;
}
}
Medicine *find2(Medicine *head)
{
char s[50];
printf("请输入要查找的药品名称:");
scanf("%s",s);
Medicine *p=head->next;
while(p){
if(strcmp(s,p->name)==0){
return p;
break;
}
p=p->next;
}
}
插入药品信息
void Insert(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf("插入到指定药品前面---输入1\n");
printf("插入到指定药品后面---输入2\n");
printf("请选择插入方式:\n");
int choice;
scanf("%d",&choice);
switch(choice){
case 1:
insert1(head);
break;
case 2:
insert2(head);
break;
}
printf("-------------------------------\n");
printf("插入成功!\n");
system("pause");
}
void insert1(Medicine *head)
{
int choice;
printf("通过编号查找指定药品---输入1\n");
printf("通过名称查找指定药品---输入2\n");
printf("请选择查找方式:\n");
scanf("%d",&choice);
switch(choice){
case 1:
insert1_1(head);
break;
case 2:
insert1_2(head);
break;
}
}
void insert1_1(Medicine *head)
{
char s[50];
printf("请输入指定药品的编号:\n");
scanf("%s",s);
Medicine *p=head,*q=head->next;
int flag=0;
while(q){
if(strcmp(q->id,s)==0){
flag=1;
Medicine *t=(Medicine*)malloc(sizeof(Medicine));
t->next=NULL;
printf("请输入要插入药品的信息:\n");
printf("编号:");
scanf("%s", t->id);
printf("名称:");
scanf("%s", t->name);
printf("功效:");
scanf("%s", t->function);
printf("数量:");
scanf("%d", &t->num);
printf("价格:");
scanf("%lf", &t->price);
t->next=q;
p->next=t;
break;
}
p=p->next;
q=q->next;
}
if(flag==0){
printf("未找到指定药品信息!\n");
system("pause");
}
}
void insert1_2(Medicine *head)
{
char s[50];
printf("请输入指定药品的名称:\n");
scanf("%s",s);
Medicine *p=head,*q=head->next;
int flag=0;
while(q){
if(strcmp(q->name,s)==0){
flag=1;
Medicine *t=(Medicine*)malloc(sizeof(Medicine));
t->next=NULL;
printf("请输入要插入节点的信息:\n");
printf("编号:");
scanf("%s", t->id);
printf("名称:");
scanf("%s", t->name);
printf("功效:");
scanf("%s", t->function);
printf("数量:");
scanf("%d", &t->num);
printf("价格:");
scanf("%lf", &t->price);
t->next=q;
p->next=t;
break;
}
p=p->next;
q=q->next;
}
if(flag==0){
printf("未找到指定药品信息!\n");
system("pause");
}
}
void insert2(Medicine *head)
{
Medicine *p=Find(head);
Medicine *t=(Medicine*)malloc(sizeof(Medicine));
t->next=NULL;
printf("请输入要插入节点的信息:\n");
printf("编号:");
scanf("%s", t->id);
printf("名称:");
scanf("%s", t->name);
printf("功效:");
scanf("%s", t->function);
printf("数量:");
scanf("%d", &t->num);
printf("价格:");
scanf("%lf", &t->price);
t->next=p->next;
p->next=t;
}
排序药品信息
void Sort(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf("通过数量排序(升序)---1\n");
printf("通过数量排序(降序)---2\n");
printf("通过价格排序(升序)---3\n");
printf("通过价格排序(降序)---4\n");
printf("请选择排序方式:");
int choice=0;
scanf("%d",&choice);
Medicine *p=head->next;
Medicine *q=NULL;
int flag=0; //判断是否交换数据
for(p=head->next;p->next;p=p->next){
for(q=p->next;q;q=q->next){
switch(choice){
case 1:
flag=sort1(p,q);
break;
case 2:
flag=sort2(p,q);
break;
case 3:
flag=sort3(p,q);
break;
case 4:
flag=sort4(p,q);
break;
}
if(flag==1){
//交换结构体的内容
Medicine t=*p;
*p=*q;
*q=t;
//将指针域还原
t.next=p->next;
p->next=q->next;
q->next=t.next;
}
}
}
int flag1;
printf("排序成功!\n");
printf("是否打印排序后的药品信息? 是(1)/否(0)");
scanf("%d",&flag1);
if(flag1==1){
Print(head);
}else{
printf("即将退出排序界面!");
system("pause");
}
write(head);
}
bool sort1(Medicine *p1,Medicine *p2)
{
return p1->num>p2->num;
}
bool sort2(Medicine *p1,Medicine *p2)
{
return p1->num<p2->num;
}
bool sort3(Medicine *p1,Medicine *p2)
{
return p1->price>p2->price;
}
bool sort4(Medicine *p1,Medicine *p2)
{
return p1->price<p2->price;
}
输出药品信息
void Print(Medicine *head)
{
system("cls");
Medicine*p=head->next;
while(p){
print(p);
p=p->next;
}
system("pause");
}
void print(Medicine *L)
{
Medicine*p=L;
printf("-------------------------------\n");
printf("编号:%s\n",p->id);
printf("名称:%s\n",p->name);
printf("功效:%s\n",p->function);
printf("剩余数量:%d\n",p->num);
printf("价格:%.2lf元\n",p->price);
}
退出系统函数
void Esc()// 退出管理系统
{
system("cls");
printf("欢迎下次使用药店管理系统!");
system("pause");
exit(0);// 结束程序
}
源代码
#include<stdio.h>
#include<windows.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
//每一个药品的信息
typedef struct medicine{
char id[20];
char name[50];
char function[100];
int num;
double price;
struct medicine *next;
}Medicine;
//每一个用户的用户名和密码
typedef struct user{
char username[50];
char password[50];
struct user*next;
}User;
//注册登录
int Usermenu(User*userHead);//用户注册登录主界面
bool login(User*userHead);//用户登录界面
bool check(User *userHead);//检查密码的功能函数
void user_print(User *userHead);//管理员查看密码的功能函数
void user(User *userHead);//用户注册界面
void user_change(User*userHead);//用户修改密码界面
void user_read(User*userHead);//文件中用户名信息读入链表
void user_write(User*userHead);//链表中用户名信息存入文件
void gotoXY(int x,int y);//将光标定在界面中某个位置
//系统界面
void menu();//主菜单
void read(Medicine*head);//文件中药品信息读入链表
void write(Medicine*head);//链表中药品信息存入文件
void add(Medicine *head);//添加新的药品信息
void Delete(Medicine *head);//删除药品信息
void del1(Medicine *head);//删除药品信息的功能函数(按编号删除)
void del2(Medicine *head);//删除药品信息的功能函数(按名称删除)
void Change(Medicine *head);//修改药品信息
Medicine *Find(Medicine *head);//查询药品信息
Medicine *find1(Medicine *head);//查询药品信息的功能函数(按编号查找)
Medicine *find2(Medicine *head);//查询药品信息的功能函数(按名称查找)
Medicine *find3(Medicine *head,char *s);//查询药品信息的功能函数(按名称查找)
void Insert(Medicine *head);//将新的药品信息插入指定位置
void insert1(Medicine *head);//将新的药品信息插入指定药品前面
void insert1_1(Medicine *head);//将新的药品信息插入指定药品前面的功能函数(按编号查找指定药品)
void insert1_2(Medicine *head);//将新的药品信息插入指定药品前面的功能函数(按名称查找指定药品)
void insert2(Medicine *head); //将新的药品信息插入指定药品后面
void Sort(Medicine *head);//排序药品信息
bool sort1(Medicine *p1,Medicine *p2);//排序药品信息的功能函数(通过数量升序排序)
bool sort2(Medicine *p1,Medicine *p2);//排序药品信息的功能函数(通过数量降序排序)
bool sort3(Medicine *p1,Medicine *p2);//排序药品信息的功能函数(通过价格升序排序)
bool sort4(Medicine *p1,Medicine *p2);//排序药品信息的功能函数(通过价格降序排序)
void Print(Medicine *head);//打印全部药品信息
void print(Medicine *L);//打印药品信息的功能函数(打印单个药品信息)
void Esc();// 退出管理系统
int main()
{
Medicine *head=(Medicine*)malloc(sizeof(Medicine));
head->next=NULL;
User *userHead=(User*)malloc(sizeof(User));
userHead->next=NULL;
read(head);
user_read(userHead);
Medicine *p;
int flag=0;
while(1){
flag=Usermenu(userHead);
if(flag==-1||flag==1){
break;
}
}
if(flag==1){
while(1){
menu();
int choice;
scanf("%d",&choice);
switch(choice){
case 1:
add(head);
write(head);
break;
case 2:
Delete(head);
write(head);
break;
case 3:
Change(head);
write(head);
break;
case 4:
p=Find(head);
if(p){
print(p);
system("pause");
}
break;
case 5:
Print(head);
break;
case 6:
Insert(head);
write(head);
break;
case 7:
Sort(head);
write(head);
break;
case 8:
Esc();
break;
}
}
}else{
gotoXY(0,15);
printf("已退出系统!!!\n");
return 0;
}
}
int Usermenu(User*userHead)
{
system("cls");
int flag=0;
int choice;
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" ***************查看已注册的用户名和密码(仅管理员可用)---6 ****************\n");
printf(" ***************登录---1 ****************\n");
printf(" ***************退出---2 ****************\n");
printf(" ***************注册账号---3 ****************\n");
printf(" ***************修改密码---4 ****************\n");
printf(" ********************************************************************************\n");
printf(" ***************请选择要进入的界面: ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
gotoXY(54,10);
scanf("%d",&choice);
switch(choice){
case 1:
flag=login(userHead);
break;
case 2:
flag=-1;
break;
case 3:
user(userHead);
flag=0;
break;
case 4:
user_change(userHead);
break;
case 6:
user_print(userHead);
break;
}
return flag;
}
void user_print(User *userHead)
{
system("cls");
char password[50]="mingrizhiwang";
char t[50];
printf("请输入管理员密码:");
char c;
int cnt=0;
while((c=getch())!='\r'){
t[cnt++]=c;
printf("*");
}
if(strcmp(password,t)==0){
printf("\n验证成功!\n");
} else{
printf("\n验证失败,即将返回登录界面,");
system("pause");
return;
}
User *p=userHead->next;
printf("已注册用户:\n");
while(p){
printf("-------------------------------\n");
printf("用户名:%s\n",p->username);
printf("密码:%s\n\n",p->password);
p=p->next;
}
system("pause");
}
bool login(User *userHead)
{
system("cls");
int count=5;
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" ************************* 登录界面 ***************************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" ***************用户名: ****************\n");
printf(" ***************密码: ****************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
while(count--){
if(check(userHead)){
gotoXY(34,10);
printf("输入正确,即将进入系统,");
system("pause");
break;
}else{
gotoXY(34,10);
printf("输入错误,请重新输入,你还有%d次机会",count);
gotoXY(34,12);
printf("提示:直接覆盖原来的用户名密码输入即可");
if(count==0){
gotoXY(34,10);
system("cls");
printf("机会已用完,即将自动退出登陆页面,");
system("pause");
return 0;
}
}
}
return 1;
}
bool check(User *userHead)
{
char name[50];
char password[50];
char t;
int cnt=0;
gotoXY(41,5);
scanf("%s",name);
gotoXY(39,6);
while((t=getch())!='\r'){
password[cnt++]=t;
printf("*");
}
gotoXY(0,15);
User *p=userHead->next;
int flag=0;
while(p){
if(strcmp(p->username,name)==0&&strcmp(p->password,password)==0){
flag=1;
}
p=p->next;
}
return flag;
}
void user(User*userHead)
{
system("cls");
User *p=userHead;
User *q;
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" ************************* 注册界面 ***************************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" ***************用户名: ****************\n");
printf(" ***************密码: ****************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
printf(" ***************请输入您要注册的用户名和密码 ****************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
q=(User*)malloc(sizeof(User));
q->next=NULL;
gotoXY(41,5);
scanf("%s",q->username);
gotoXY(39,6);
scanf("%s",q->password);
q->next=p->next;
p->next=q;
user_write(userHead);
gotoXY(34,12);
printf("注册成功,");
system("pause");
}
void user_change(User*userHead)
{
system("cls");
char name[50];
char password[50];
printf("-------------------------------\n");
printf("请输入您的用户名:");
scanf("%s",name);
int flag=0;
User *p=userHead->next;
while(p){
if(strcmp(name,p->username)==0){
flag=1;
break;
}
p=p->next;
}
if(flag){
printf("请输入您的旧密码:");
scanf("%s",password);
if(strcmp(p->password,password)==0){
printf("验证成功\n");
printf("请输入您的新密码:");
scanf("%s",p->password);
printf("修改成功\n");
} else{
printf("您的旧密码输入错误,请确定好旧密码再重新进入该页面修改密码!!!\n");
}
}else{
printf("没有该用户名信息!\n");
}
user_write(userHead);
system("pause");
}
void user_read(User*userHead)
{
FILE *l=fopen("UsernameAndPassword.txt","r");
if(l==NULL){
return;
}
User *p=userHead,*q;
User a;
while(fscanf(l,"%s %s",a.username,a.password)!=EOF)
{
q=(User*)malloc(sizeof(User));
*q=a;
q->next=NULL;
p->next=q;
p=q;
}
fclose(l);
}
void user_write(User*userHead)
{
FILE *l=fopen("UsernameAndPassword.txt","w");
if(l==NULL){
return;
}
User *p=userHead->next;
while(p){
fprintf(l,"%s %s\n",p->username,p->password);
p=p->next;
}
fclose(l);
}
void gotoXY(int x,int y)
{
COORD coord={x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
void menu() //主页面
{
system("cls");
printf(" ****************************************************************\n");
printf(" *********** 药店管理系统 ***********\n");
printf(" *********** 1 ---- 添加药品信息 ***********\n");
printf(" *********** 2 ---- 删除药品信息 ***********\n");
printf(" *********** 3 ---- 修改药品信息 ***********\n");
printf(" *********** 4 ---- 查询药品信息 ***********\n");
printf(" *********** 5 ---- 输出药品信息 ***********\n");
printf(" *********** 6 ---- 插入药品信息 ***********\n");
printf(" *********** 7 ---- 排序管理系统 ***********\n");
printf(" *********** 8 ---- 退出管理系统 ***********\n");
printf(" ****************************************************************\n");
printf(" 请选择想要实现的功能(数字):");
}
void read(Medicine*head)
{
FILE *l=fopen("Medicine_imformaition.txt","r");
if(l==NULL){
return;
}
Medicine t;
Medicine *p=head;
Medicine *q;
while(fscanf(l,"%s %s %s %d %lf",t.id,t.name,t.function,&t.num,&t.price)!=EOF){
q=(Medicine*)malloc(sizeof(Medicine));
*q=t;
q->next=NULL;
p->next=q;
p=q;
}
fclose(l);
}
void write(Medicine*head)
{
FILE *l=fopen("Medicine_imformaition.txt","w");
if(l==NULL){
return;
}
Medicine*p=head->next;
while(p){
fprintf(l,"%s %s %s %d %.2lf\n",p->id,p->name,p->function,p->num,p->price);
p=p->next;
}
fclose(l);
}
void add(Medicine *head)
{
system("cls");
Medicine a;
printf("请输入要添加药品的相关信息:\n");
printf("编号:");
scanf("%s", a.id);
printf("名称:");
scanf("%s", a.name);
printf("功效:");
scanf("%s", a.function);
printf("数量:");
scanf("%d", &a.num);
printf("价格:");
scanf("%lf", &a.price);
Medicine *t=find3(head,a.name);
Medicine *p,*q;
if(t==NULL){
p=(Medicine*)malloc(sizeof(Medicine));
*p=a;
p->next=NULL;
q=head;
p->next=q->next;
q->next=p;
printf("新药品已成功添加到仓库!\n");
system("pause");
}else{
printf("该药品已存在\n");
print(t);
printf("创建新的药品信息---1\n");
printf("纳入当前药品信息---2\n");
printf("请选择添加方式:");
int choice;
scanf("%d",&choice);
switch(choice){
case 1:
p=(Medicine*)malloc(sizeof(Medicine));
*p=a;
p->next=NULL;
q=head;
p->next=q->next;
q->next=p;
printf("新药品已成功添加到仓库!\n");
system("pause");
break;
case 2:
t->num+=a.num;
t->price=a.price;
printf("该药品已纳入到当前药品信息!\n");
system("pause");
break;
}
}
}
void Delete(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf("通过编号删除---输入1\n");
printf("通过名称删除---输入2\n");
printf("按0返回主菜单\n");
printf("请选择删除方式:");
int choice;
scanf("%d",&choice);
switch(choice){
case 1:
del1(head);
break;
case 2:
del2(head);
break;
case 0:
return;
}
}
void del1(Medicine *head)
{
char s[50];
printf("请输入要删除的药品编号:");
scanf("%s",s);
Medicine *p=head->next;
Medicine *q=head;
int flag=0;
while(p){
if(strcmp(s,p->id)==0){
flag=1;
printf("-------------------------------\n");
printf("该药品已删除:\n");
print(p);
system("pause");
q->next=p->next;
p->next=NULL;
free(p);
break;
}
p=p->next;
q=q->next;
}
if(flag==0){
printf("-------------------------------\n");
printf("该药品不存在:\n");
system("pause");
}
}
void del2(Medicine *head)
{
char s[50];
printf("请输入要删除的药品名称:");
scanf("%s",s);
Medicine *p=head->next;
Medicine *q=head;
int flag=0;
while(p){
if(strcmp(s,p->name)==0){
flag=1;
printf("-------------------------------\n");
printf("该药品已删除:\n");
print(p);
system("pause");
q->next=p->next;
p->next=NULL;
free(p);
break;
}
p=p->next;
q=q->next;
}
if(flag==0){
printf("-------------------------------\n");
printf("该药品不存在!\n");
system("pause");
}
}
void Change(Medicine *head)
{
Medicine *p=Find(head);
if(p==NULL){
return;
}
print(p);
while(1){
printf("-------------------------------\n");
printf("药品编号---1\n");
printf("药品名称---2\n");
printf("药品功效---3\n");
printf("药品剩余数量---4\n");
printf("药品价格---5\n");
printf("请选择要修改的信息:");
int choice;
scanf("%d",&choice);
char s[50];
int num;
double price;
printf("请输入修改后的信息:");
switch(choice){
case 1:
scanf("%s",s);
strcpy(p->id,s);
break;
case 2:
scanf("%s",s);
strcpy(p->name,s);
break;
case 3:
scanf("%s",s);
strcpy(p->function,s);
break;
case 4:
scanf("%d",&num);
p->num=num;
break;
case 5:
scanf("%lf",&price);
p->price=price;
break;
}
printf("-------------------------------\n");
printf("该药品信息被修改为:\n");
print(p);
printf("是否继续修改? 是(1)/否(0)");
int flag;
scanf("%d",&flag);
if(!flag){
break;
}else{
system("cls");
}
}
printf("-------------------------------\n");
printf("该药品当前信息为:\n");
print(p);
system("pause");
}
Medicine *Find(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf("通过编号查找指定药品---1\n");
printf("通过名称查找指定药品---2\n");
printf("按0返回主菜单\n");
printf("请选择查找方式:");
int choice;
scanf("%d",&choice);
Medicine *p=NULL;
switch(choice){
case 1:
p=find1(head);
break;
case 2:
p=find2(head);
break;
case 0:
return 0;
}
if(p==NULL){
printf("没有该药品信息!\n");
system("pause");
}
return p;
}
Medicine *find1(Medicine *head)
{
char s[50];
printf("请输入要查找的药品编号:");
scanf("%s",s);
Medicine *p=head->next;
while(p){
if(strcmp(s,p->id)==0){
return p;
}
p=p->next;
}
}
Medicine *find2(Medicine *head)
{
char s[50];
printf("请输入要查找的药品名称:");
scanf("%s",s);
Medicine *p=head->next;
while(p){
if(strcmp(s,p->name)==0){
return p;
break;
}
p=p->next;
}
}
Medicine *find3(Medicine *head,char *s)
{
Medicine *p=head->next;
while(p){
if(strcmp(s,p->name)==0){
return p;
}
p=p->next;
}
}
void Insert(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf("插入到指定药品前面---输入1\n");
printf("插入到指定药品后面---输入2\n");
printf("按0返回主菜单\n");
printf("请选择插入方式:");
int choice;
scanf("%d",&choice);
switch(choice){
case 1:
insert1(head);
break;
case 2:
insert2(head);
break;
case 0:
return;
}
}
void insert1(Medicine *head)
{
system("cls");
int choice;
printf("通过编号查找指定药品---输入1\n");
printf("通过名称查找指定药品---输入2\n");
printf("按0返回主菜单\n");
printf("请选择查找方式:");
scanf("%d",&choice);
switch(choice){
case 1:
insert1_1(head);
break;
case 2:
insert1_2(head);
break;
case 0:
return;
}
}
void insert1_1(Medicine *head)
{
char s[50];
printf("请输入指定药品的编号:");
scanf("%s",s);
Medicine *p=head,*q=head->next;
int flag=0;
while(q){
if(strcmp(q->id,s)==0){
flag=1;
Medicine *t=(Medicine*)malloc(sizeof(Medicine));
t->next=NULL;
printf("请输入要插入药品的信息:\n");
printf("编号:");
scanf("%s", t->id);
printf("名称:");
scanf("%s", t->name);
printf("功效:");
scanf("%s", t->function);
printf("数量:");
scanf("%d", &t->num);
printf("价格:");
scanf("%lf", &t->price);
t->next=q;
p->next=t;
printf("-------------------------------\n");
printf("插入成功!\n");
system("pause");
break;
}
p=p->next;
q=q->next;
}
if(flag==0){
printf("未找到指定药品信息!\n");
system("pause");
}
}
void insert1_2(Medicine *head)
{
char s[50];
printf("请输入指定药品的名称:");
scanf("%s",s);
Medicine *p=head,*q=head->next;
int flag=0;
while(q){
if(strcmp(q->name,s)==0){
flag=1;
Medicine *t=(Medicine*)malloc(sizeof(Medicine));
t->next=NULL;
printf("请输入要插入节点的信息:\n");
printf("编号:");
scanf("%s", t->id);
printf("名称:");
scanf("%s", t->name);
printf("功效:");
scanf("%s", t->function);
printf("数量:");
scanf("%d", &t->num);
printf("价格:");
scanf("%lf", &t->price);
t->next=q;
p->next=t;
printf("-------------------------------\n");
printf("插入成功!\n");
system("pause");
break;
}
p=p->next;
q=q->next;
}
if(flag==0){
printf("未找到指定药品信息!\n");
system("pause");
}
}
void insert2(Medicine *head)
{
Medicine *p=Find(head);
if(p==NULL){
return;
}
Medicine *t=(Medicine*)malloc(sizeof(Medicine));
t->next=NULL;
printf("请输入要插入节点的信息:\n");
printf("编号:");
scanf("%s", t->id);
printf("名称:");
scanf("%s", t->name);
printf("功效:");
scanf("%s", t->function);
printf("数量:");
scanf("%d", &t->num);
printf("价格:");
scanf("%lf", &t->price);
t->next=p->next;
p->next=t;
printf("-------------------------------\n");
printf("插入成功!\n");
system("pause");
}
void Sort(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf("通过数量排序(升序)---1\n");
printf("通过数量排序(降序)---2\n");
printf("通过价格排序(升序)---3\n");
printf("通过价格排序(降序)---4\n");
printf("按0返回主菜单\n");
printf("请选择排序方式:");
int choice=0;
scanf("%d",&choice);
Medicine *p=head->next;
Medicine *q=NULL;
int flag=0; //判断是否交换数据
for(p=head->next;p->next;p=p->next){
for(q=p->next;q;q=q->next){
switch(choice){
case 1:
flag=sort1(p,q);
break;
case 2:
flag=sort2(p,q);
break;
case 3:
flag=sort3(p,q);
break;
case 4:
flag=sort4(p,q);
break;
case 0:
return;
}
if(flag==1){
//交换结构体的内容
Medicine t=*p;
*p=*q;
*q=t;
//将指针域还原
t.next=p->next;
p->next=q->next;
q->next=t.next;
}
}
}
int flag1;
printf("排序成功!\n");
printf("是否打印排序后的药品信息? 是(1)/否(0)");
scanf("%d",&flag1);
if(flag1==1){
Print(head);
}else{
printf("即将退出排序界面!");
system("pause");
}
}
bool sort1(Medicine *p1,Medicine *p2)
{
return p1->num>p2->num;
}
bool sort2(Medicine *p1,Medicine *p2)
{
return p1->num<p2->num;
}
bool sort3(Medicine *p1,Medicine *p2)
{
return p1->price>p2->price;
}
bool sort4(Medicine *p1,Medicine *p2)
{
return p1->price<p2->price;
}
void Print(Medicine *head)
{
system("cls");
Medicine*p=head->next;
while(p){
print(p);
p=p->next;
}
system("pause");
}
void print(Medicine *L)
{
Medicine*p=L;
printf("-------------------------------\n");
printf("编号:%s\n",p->id);
printf("名称:%s\n",p->name);
printf("功效:%s\n",p->function);
printf("剩余数量:%d\n",p->num);
printf("价格:%.2lf元\n",p->price);
}
void Esc()// 退出管理系统
{
system("cls");
printf("欢迎下次使用药店管理系统!");
system("pause");
exit(0);// 结束程序
}
边栏推荐
- Introduction to the pursuit of new subtrate source code - early May: xcm officially launched
- Hisilicon 3559 sample parsing: Venc
- 200. number of islands
- Installing onnx is very slow. Use Tsinghua image
- Go 语言入门很简单:Go 处理 XML 文件
- The sci-fi ideas in these movies have been realized by AI
- Subtrate 源码追新导读-5月上旬: XCM 正式启用
- 3D线光谱共焦传感器在半导体如何检测
- 聊聊怎么做硬件兼容性检测,快速迁移到openEuler?
- 会议预告 | 华为 2012 实验室全球软件技术峰会-欧洲分会场
猜你喜欢

MySQL 内置函数

What is the principle of spectral confocal displacement sensor? Which fields can be applied?

光谱共焦位移传感器的原理是什么?能应用那些领域?

智慧法院新征程,无纸化办公,护航智慧法院绿色庭审

A new journey of the smart court, paperless office, escorting the green trial of the smart court

How to detect 3D line spectral confocal sensors in semiconductors

SuperMap iClient3D 11i for Cesium三维场景中图例使用说明

Hisilicon 3559 sample parsing: Venc

90.(cesium篇)cesium高度监听事件
![[leetcode] 15. Sum of three numbers](/img/0c/4363d7737d90c170eb4519828990b9.png)
[leetcode] 15. Sum of three numbers
随机推荐
[cf] 803 div2 A. XOR Mixup
海思3559 sample解析:venc
21、wpf之绑定使用小记
用宝塔建第2个网站时网站总是报错:No input file specified.
How can c write an SQL parser
SuperMap iClient3D for WebGL 加载TMS瓦片
R language ggplot2 visualization: use ggplot2 visualization scatter diagram and the size parameter in AES function to specify the size of data points (point size)
[cf] 803 div2 A. XOR Mixup
edusoho企培版纯内网部署教程(解决播放器,上传,后台卡顿问题)
SuperMap iServer11i新功能----图例的发布和使用
Swagger2自动生成APi文档
Map集合
A review of quantum neural networks 2022 for generating learning tasks
光谱共焦位移传感器的原理是什么?能应用那些领域?
STM32 porting the fish component of RT thread Standard Edition
695. maximum island area
How to detect 3D line spectral confocal sensors in semiconductors
The website with id 0 that was requested wasn‘t found. Verify the website and try again
Use of redis in projects
使用Power Designer工具构建数据库模型