当前位置:网站首页>Pharmacy management system
Pharmacy management system
2022-06-30 12:24:00 【Desert –】
Pharmacy management system
Preface
Before we do the system , Remember to locate the file , The system uses to create a folder , take .c The file is placed in this folder , Text files are created directly in this folder ( That is, create a file from the current location ).
Concrete realization
frame
Specific functions are described in detail later
#include<stdio.h>
#include<windows.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
// Information about each drug
typedef struct medicine{
char id[20];
char name[50];
char function[100];
int num;
double price;
struct medicine *next;
}Medicine;
// User name and password of each user
typedef struct user{
char username[50];
char password[50];
struct user*next;
}User;
// Register login
int Usermenu(User*userHead);// User registration and login main interface
bool login(User*userHead);// User login interface
bool check(User *userHead);// Check the function of password
void user_print(User *userHead);// The function of the administrator to view the password
void user(User *userHead);// User registration interface
void user_change(User*userHead);// User password modification interface
void user_read(User*userHead);// The user name information in the file is read into the linked list
void user_write(User*userHead);// The user name information in the linked list is stored in the file
void gotoXY(int x,int y);// Calibrate the light at a certain position in the interface
// System interface
void menu();// The main menu
void read(Medicine*head);// Read the drug information in the document into the linked list
void write(Medicine*head);// The drug information in the linked list is stored in the file
void add(Medicine *head);// Add new drug information
void Delete(Medicine *head);// Delete drug information
void del1(Medicine *head);// Function to delete drug information ( Delete by number )
void del2(Medicine *head);// Function to delete drug information ( Delete... By name )
void Change(Medicine *head);// Modify drug information
Medicine *Find(Medicine *head);// Query drug information
Medicine *find1(Medicine *head);// Function for querying drug information ( Find by number )
Medicine *find2(Medicine *head);// Function for querying drug information ( Search by name )
void Insert(Medicine *head);// Insert the new drug information into the specified location
void insert1(Medicine *head);// Insert the new drug information in front of the specified drug
void insert1_1(Medicine *head);// Insert the new drug information into the function function in front of the specified drug ( Find the specified drug by number )
void insert1_2(Medicine *head);// Insert the new drug information into the function function in front of the specified drug ( Find the specified drug by name )
void insert2(Medicine *head); // Insert the new drug information after the designated drug
void Sort(Medicine *head);// Sort drug information
bool sort1(Medicine *p1,Medicine *p2);// Function for sorting drug information ( Sort in ascending order by quantity )
bool sort2(Medicine *p1,Medicine *p2);// Function for sorting drug information ( Sort by quantity descending )
bool sort3(Medicine *p1,Medicine *p2);// Function for sorting drug information ( Sort by price ascending )
bool sort4(Medicine *p1,Medicine *p2);// Function for sorting drug information ( Sort by price descending )
void Print(Medicine *head);// Print all drug information
void print(Medicine *L);// Function of printing drug information ( Print single drug information )
void Esc();// Exit the management system
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(" Has exited the system !!!\n");
return 0;
}
}
Functional analysis
Introduction to the registration and login interface functions
Login menu
Pages enter different pages through the entered number to achieve different functions
The return value is used to determine whether the system is successfully logged in
int Usermenu(User*userHead)
{
system("cls");
int flag=0;
int choice;
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" *******************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" *************** View the registered user name and password ( Available only to administrators )---6 ****************\n");
printf(" *************** Sign in ---1 ****************\n");
printf(" *************** sign out ---2 ****************\n");
printf(" *************** Registered account ---3 ****************\n");
printf(" *************** Change Password ---4 ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** Please select the interface to enter : ****************\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;
}
Administrator output function
The administrator is used to view the registered user name and password
void user_print(User *userHead)
{
system("cls");
char password[50]="mingrizhiwang";
char t[50];
printf(" Please enter the administrator password :");
scanf("%s",t);
if(strcmp(password,t)==0){
printf(" Verify success !\n");
} else{
printf(" Validation failed , About to return to the login screen ,");
system("pause");
return;
}
User *p=userHead->next;
printf(" Registered users :\n");
while(p){
printf("-------------------------------\n");
printf(" user name :%s\n",p->username);
printf(" password :%s\n\n",p->password);
p=p->next;
}
system("pause");
}
Login interface
bool login(User *userHead)
{
system("cls");
int count=5;
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" ************************* Login interface ***************************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" *************** user name : ****************\n");
printf(" *************** password : ****************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
while(count--){
if(check(userHead)){
gotoXY(34,10);
printf(" Input correct , About to enter the system ,");
system("pause");
break;
}else{
gotoXY(34,10);
printf(" Input error , Please re-enter , Do you have %d Second chance ",count);
gotoXY(34,12);
printf(" Tips : Directly overwrite the original user name and password ");
if(count==0){
gotoXY(34,10);
system("cls");
printf(" The opportunity has run out , About to exit the login page automatically ,");
system("pause");
return 0;
}
}
}
return 1;
}
User name password verification function
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;
}
User registration interface
void user(User*userHead)
{
system("cls");
User *p=userHead;
User *q;
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" ************************* The registration screen ***************************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" *************** user name : ****************\n");
printf(" *************** password : ****************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** Please enter the user name and password you want to register ****************\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(" Registered successfully ,");
system("pause");
}
User name change password interface
void user_change(User*userHead)
{
system("cls");
char name[50];
char password[50];
printf("-------------------------------\n");
printf(" Please enter your user name :");
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(" Please enter your old password :");
scanf("%s",password);
if(strcmp(p->password,password)==0){
printf(" Verify success \n");
printf(" Please enter your new password :");
scanf("%s",p->password);
printf(" Modification successful \n");
} else{
printf(" Your old password was entered incorrectly , Please confirm the old password and re-enter the page to change the password !!!\n");
}
}else{
printf(" There is no user name information !\n");
}
user_write(userHead);
system("pause");
}
Read file function
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);
}
Write file functions
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);
}
A function that calibrates light at a specified position
void gotoXY(int x,int y)
{
COORD coord={x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
Introduction to system interface functions
The main menu
void menu() // The main page
{
system("cls");
printf(" ****************************************************************\n");
printf(" *********** Pharmacy management system ***********\n");
printf(" *********** 1 ---- Add drug information ***********\n");
printf(" *********** 2 ---- Delete drug information ***********\n");
printf(" *********** 3 ---- Modify drug information ***********\n");
printf(" *********** 4 ---- Query drug information ***********\n");
printf(" *********** 5 ---- Output drug information ***********\n");
printf(" *********** 6 ---- Insert drug information ***********\n");
printf(" *********** 7 ---- Sort management system ***********\n");
printf(" *********** 8 ---- Exit the management system ***********\n");
printf(" ****************************************************************\n");
printf(" Please select the function you want to implement ( Numbers ):");
}
Read file function
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);
}
Write file functions
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);
}
Add drug information
void add(Medicine *head)
{
system("cls");
Medicine a;
printf(" Please enter the information about the drug to be added :\n");
printf(" Number :");
scanf("%s", a.id);
printf(" name :");
scanf("%s", a.name);
printf(" efficacy :");
scanf("%s", a.function);
printf(" Number :");
scanf("%d", &a.num);
printf(" Price :");
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;
}
Delete drug information
void Delete(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf(" Delete by number --- Input 1\n");
printf(" Delete by name --- Input 2\n");
printf(" Please select the deletion method :\n");
int choice;
scanf("%d",&choice);
switch(choice){
case 1:
del1(head);
break;
case 2:
del2(head);
break;
}
printf("-------------------------------\n");
printf(" The drug has been deleted :\n");
}
void del1(Medicine *head)
{
char s[50];
printf(" Please enter the drug number to delete :");
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(" The drug has been deleted :\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(" The drug does not exist :\n");
system("pause");
}
}
void del2(Medicine *head)
{
char s[50];
printf(" Please enter the name of the drug to be deleted :");
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(" The drug has been deleted :\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(" The drug does not exist :\n");
system("pause");
}
}
Modify drug information
void Change(Medicine *head)
{
Medicine *p=Find(head);
if(p==NULL){
return;
}
print(p);
while(1){
printf("-------------------------------\n");
printf(" Drug number ---1\n");
printf(" The name of the drug ---2\n");
printf(" Drug efficacy ---3\n");
printf(" Remaining quantity of drugs ---4\n");
printf(" Drug prices ---5\n");
printf(" Please select the information you want to modify :");
int choice;
scanf("%d",&choice);
char s[50];
int num;
double price;
printf(" Please input the modified information :");
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(" The drug information is modified to :\n");
print(p);
printf(" Continue to modify ? yes (1)/ no (0)");
int flag;
scanf("%d",&flag);
if(!flag){
break;
}else{
system("cls");
}
}
printf("-------------------------------\n");
printf(" The current information of the drug is :\n");
print(p);
system("pause");
write(head);
}
Query drug information
Medicine *Find(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf(" Find drugs by number ---1\n");
printf(" Find drugs by name ---2\n");
printf(" Please select the search method :");
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(" There is no information about the drug ! Please find again !!!\n");
system("pause");
}
return p;
}
Medicine *find1(Medicine *head)
{
char s[50];
printf(" Please enter the drug number you want to find :");
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(" Please enter the name of the drug you want to find :");
scanf("%s",s);
Medicine *p=head->next;
while(p){
if(strcmp(s,p->name)==0){
return p;
break;
}
p=p->next;
}
}
Insert drug information
void Insert(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf(" Insert in front of the specified drug --- Input 1\n");
printf(" Insert after the specified drug product --- Input 2\n");
printf(" Please select the insertion method :\n");
int choice;
scanf("%d",&choice);
switch(choice){
case 1:
insert1(head);
break;
case 2:
insert2(head);
break;
}
printf("-------------------------------\n");
printf(" Insert the success !\n");
system("pause");
}
void insert1(Medicine *head)
{
int choice;
printf(" Find the specified drug by number --- Input 1\n");
printf(" Find the specified drug by name --- Input 2\n");
printf(" Please select the search method :\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(" Please enter the number of the specified drug product :\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(" Please enter the information to insert the drug product :\n");
printf(" Number :");
scanf("%s", t->id);
printf(" name :");
scanf("%s", t->name);
printf(" efficacy :");
scanf("%s", t->function);
printf(" Number :");
scanf("%d", &t->num);
printf(" Price :");
scanf("%lf", &t->price);
t->next=q;
p->next=t;
break;
}
p=p->next;
q=q->next;
}
if(flag==0){
printf(" The specified drug information was not found !\n");
system("pause");
}
}
void insert1_2(Medicine *head)
{
char s[50];
printf(" Please enter the name of the specified drug :\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(" Please enter the information to insert the node :\n");
printf(" Number :");
scanf("%s", t->id);
printf(" name :");
scanf("%s", t->name);
printf(" efficacy :");
scanf("%s", t->function);
printf(" Number :");
scanf("%d", &t->num);
printf(" Price :");
scanf("%lf", &t->price);
t->next=q;
p->next=t;
break;
}
p=p->next;
q=q->next;
}
if(flag==0){
printf(" The specified drug information was not found !\n");
system("pause");
}
}
void insert2(Medicine *head)
{
Medicine *p=Find(head);
Medicine *t=(Medicine*)malloc(sizeof(Medicine));
t->next=NULL;
printf(" Please enter the information to insert the node :\n");
printf(" Number :");
scanf("%s", t->id);
printf(" name :");
scanf("%s", t->name);
printf(" efficacy :");
scanf("%s", t->function);
printf(" Number :");
scanf("%d", &t->num);
printf(" Price :");
scanf("%lf", &t->price);
t->next=p->next;
p->next=t;
}
Sort drug information
void Sort(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf(" Sort by quantity ( Ascending )---1\n");
printf(" Sort by quantity ( Descending )---2\n");
printf(" Sort by price ( Ascending )---3\n");
printf(" Sort by price ( Descending )---4\n");
printf(" Please select sort by :");
int choice=0;
scanf("%d",&choice);
Medicine *p=head->next;
Medicine *q=NULL;
int flag=0; // Determine whether to exchange data
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){
// Exchange the contents of the structure
Medicine t=*p;
*p=*q;
*q=t;
// Restore the pointer field
t.next=p->next;
p->next=q->next;
q->next=t.next;
}
}
}
int flag1;
printf(" Sort success !\n");
printf(" Whether to print the sorted drug information ? yes (1)/ no (0)");
scanf("%d",&flag1);
if(flag1==1){
Print(head);
}else{
printf(" About to exit the sorting interface !");
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;
}
Output drug information
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(" Number :%s\n",p->id);
printf(" name :%s\n",p->name);
printf(" efficacy :%s\n",p->function);
printf(" The remaining quantity :%d\n",p->num);
printf(" Price :%.2lf element \n",p->price);
}
Exit the system function
void Esc()// Exit the management system
{
system("cls");
printf(" Welcome to use the pharmacy management system next time !");
system("pause");
exit(0);// End procedure
}
Source code
#include<stdio.h>
#include<windows.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
// Information about each drug
typedef struct medicine{
char id[20];
char name[50];
char function[100];
int num;
double price;
struct medicine *next;
}Medicine;
// User name and password of each user
typedef struct user{
char username[50];
char password[50];
struct user*next;
}User;
// Register login
int Usermenu(User*userHead);// User registration and login main interface
bool login(User*userHead);// User login interface
bool check(User *userHead);// Check the function of password
void user_print(User *userHead);// The function of the administrator to view the password
void user(User *userHead);// User registration interface
void user_change(User*userHead);// User password modification interface
void user_read(User*userHead);// The user name information in the file is read into the linked list
void user_write(User*userHead);// The user name information in the linked list is stored in the file
void gotoXY(int x,int y);// Calibrate the light at a certain position in the interface
// System interface
void menu();// The main menu
void read(Medicine*head);// Read the drug information in the document into the linked list
void write(Medicine*head);// The drug information in the linked list is stored in the file
void add(Medicine *head);// Add new drug information
void Delete(Medicine *head);// Delete drug information
void del1(Medicine *head);// Function to delete drug information ( Delete by number )
void del2(Medicine *head);// Function to delete drug information ( Delete... By name )
void Change(Medicine *head);// Modify drug information
Medicine *Find(Medicine *head);// Query drug information
Medicine *find1(Medicine *head);// Function for querying drug information ( Find by number )
Medicine *find2(Medicine *head);// Function for querying drug information ( Search by name )
Medicine *find3(Medicine *head,char *s);// Function for querying drug information ( Search by name )
void Insert(Medicine *head);// Insert the new drug information into the specified location
void insert1(Medicine *head);// Insert the new drug information in front of the specified drug
void insert1_1(Medicine *head);// Insert the new drug information into the function function in front of the specified drug ( Find the specified drug by number )
void insert1_2(Medicine *head);// Insert the new drug information into the function function in front of the specified drug ( Find the specified drug by name )
void insert2(Medicine *head); // Insert the new drug information after the designated drug
void Sort(Medicine *head);// Sort drug information
bool sort1(Medicine *p1,Medicine *p2);// Function for sorting drug information ( Sort in ascending order by quantity )
bool sort2(Medicine *p1,Medicine *p2);// Function for sorting drug information ( Sort by quantity descending )
bool sort3(Medicine *p1,Medicine *p2);// Function for sorting drug information ( Sort by price ascending )
bool sort4(Medicine *p1,Medicine *p2);// Function for sorting drug information ( Sort by price descending )
void Print(Medicine *head);// Print all drug information
void print(Medicine *L);// Function of printing drug information ( Print single drug information )
void Esc();// Exit the management system
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(" Has exited the system !!!\n");
return 0;
}
}
int Usermenu(User*userHead)
{
system("cls");
int flag=0;
int choice;
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" *************** View the registered user name and password ( Available only to administrators )---6 ****************\n");
printf(" *************** Sign in ---1 ****************\n");
printf(" *************** sign out ---2 ****************\n");
printf(" *************** Registered account ---3 ****************\n");
printf(" *************** Change Password ---4 ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** Please select the interface to enter : ****************\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(" Please enter the administrator password :");
char c;
int cnt=0;
while((c=getch())!='\r'){
t[cnt++]=c;
printf("*");
}
if(strcmp(password,t)==0){
printf("\n Verify success !\n");
} else{
printf("\n Validation failed , About to return to the login screen ,");
system("pause");
return;
}
User *p=userHead->next;
printf(" Registered users :\n");
while(p){
printf("-------------------------------\n");
printf(" user name :%s\n",p->username);
printf(" password :%s\n\n",p->password);
p=p->next;
}
system("pause");
}
bool login(User *userHead)
{
system("cls");
int count=5;
printf(" ********************************************************************************\n");
printf(" ********************************************************************************\n");
printf(" ************************* Login screen ***************************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" *************** user name : ****************\n");
printf(" *************** password : ****************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
while(count--){
if(check(userHead)){
gotoXY(34,10);
printf(" Input correct , About to enter the system ,");
system("pause");
break;
}else{
gotoXY(34,10);
printf(" Input error , Please re-enter , Do you have %d Second chance ",count);
gotoXY(34,12);
printf(" Tips : Directly overwrite the original user name and password ");
if(count==0){
gotoXY(34,10);
system("cls");
printf(" The opportunity has run out , About to exit the login page automatically ,");
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(" ************************* The registration screen ***************************\n");
printf(" ********************************************************************************\n");
printf(" *************** ****************\n");
printf(" *************** user name : ****************\n");
printf(" *************** password : ****************\n");
printf(" *************** ****************\n");
printf(" ********************************************************************************\n");
printf(" *************** Please enter the user name and password you want to register ****************\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(" Registered successfully ,");
system("pause");
}
void user_change(User*userHead)
{
system("cls");
char name[50];
char password[50];
printf("-------------------------------\n");
printf(" Please enter your user name :");
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(" Please enter your old password :");
scanf("%s",password);
if(strcmp(p->password,password)==0){
printf(" Verify success \n");
printf(" Please enter your new password :");
scanf("%s",p->password);
printf(" Modification successful \n");
} else{
printf(" Your old password was entered incorrectly , Please confirm the old password and re-enter the page to change the password !!!\n");
}
}else{
printf(" There is no user name information !\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() // The main page
{
system("cls");
printf(" ****************************************************************\n");
printf(" *********** Pharmacy management system ***********\n");
printf(" *********** 1 ---- Add drug information ***********\n");
printf(" *********** 2 ---- Delete drug information ***********\n");
printf(" *********** 3 ---- Modify drug information ***********\n");
printf(" *********** 4 ---- Query drug information ***********\n");
printf(" *********** 5 ---- Output drug information ***********\n");
printf(" *********** 6 ---- Insert drug information ***********\n");
printf(" *********** 7 ---- Sort management system ***********\n");
printf(" *********** 8 ---- Exit the management system ***********\n");
printf(" ****************************************************************\n");
printf(" Please select the function you want to implement ( Numbers ):");
}
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(" Please enter the information about the drug to be added :\n");
printf(" Number :");
scanf("%s", a.id);
printf(" name :");
scanf("%s", a.name);
printf(" efficacy :");
scanf("%s", a.function);
printf(" Number :");
scanf("%d", &a.num);
printf(" Price :");
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(" The new drug has been successfully added to the warehouse !\n");
system("pause");
}else{
printf(" The drug already exists \n");
print(t);
printf(" Create new drug information ---1\n");
printf(" Include current drug information ---2\n");
printf(" Please select the adding method :");
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(" The new drug has been successfully added to the warehouse !\n");
system("pause");
break;
case 2:
t->num+=a.num;
t->price=a.price;
printf(" The drug has been incorporated into the current drug information !\n");
system("pause");
break;
}
}
}
void Delete(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf(" Delete by number --- Input 1\n");
printf(" Delete by name --- Input 2\n");
printf(" Press 0 Back to main menu \n");
printf(" Please select the deletion method :");
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(" Please enter the drug number to delete :");
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(" The drug has been deleted :\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(" The drug does not exist :\n");
system("pause");
}
}
void del2(Medicine *head)
{
char s[50];
printf(" Please enter the name of the drug to be deleted :");
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(" The drug has been deleted :\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(" The drug does not exist !\n");
system("pause");
}
}
void Change(Medicine *head)
{
Medicine *p=Find(head);
if(p==NULL){
return;
}
print(p);
while(1){
printf("-------------------------------\n");
printf(" Drug number ---1\n");
printf(" The name of the drug ---2\n");
printf(" Drug efficacy ---3\n");
printf(" Remaining quantity of drugs ---4\n");
printf(" Drug prices ---5\n");
printf(" Please select the information you want to modify :");
int choice;
scanf("%d",&choice);
char s[50];
int num;
double price;
printf(" Please input the modified information :");
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(" The drug information is modified to :\n");
print(p);
printf(" Continue to modify ? yes (1)/ no (0)");
int flag;
scanf("%d",&flag);
if(!flag){
break;
}else{
system("cls");
}
}
printf("-------------------------------\n");
printf(" The current information of the drug is :\n");
print(p);
system("pause");
}
Medicine *Find(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf(" Find the specified drug by number ---1\n");
printf(" Find the specified drug by name ---2\n");
printf(" Press 0 Back to main menu \n");
printf(" Please select the search method :");
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(" There is no information about the drug !\n");
system("pause");
}
return p;
}
Medicine *find1(Medicine *head)
{
char s[50];
printf(" Please enter the drug number you want to find :");
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(" Please enter the name of the drug you want to find :");
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(" Insert in front of the specified drug --- Input 1\n");
printf(" Insert after the specified drug product --- Input 2\n");
printf(" Press 0 Back to main menu \n");
printf(" Please select the insertion method :");
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(" Find the specified drug by number --- Input 1\n");
printf(" Find the specified drug by name --- Input 2\n");
printf(" Press 0 Back to main menu \n");
printf(" Please select the search method :");
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(" Please enter the number of the specified drug product :");
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(" Please enter the information to insert the drug product :\n");
printf(" Number :");
scanf("%s", t->id);
printf(" name :");
scanf("%s", t->name);
printf(" efficacy :");
scanf("%s", t->function);
printf(" Number :");
scanf("%d", &t->num);
printf(" Price :");
scanf("%lf", &t->price);
t->next=q;
p->next=t;
printf("-------------------------------\n");
printf(" Insert the success !\n");
system("pause");
break;
}
p=p->next;
q=q->next;
}
if(flag==0){
printf(" The specified drug information was not found !\n");
system("pause");
}
}
void insert1_2(Medicine *head)
{
char s[50];
printf(" Please enter the name of the specified drug :");
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(" Please enter the information to insert the node :\n");
printf(" Number :");
scanf("%s", t->id);
printf(" name :");
scanf("%s", t->name);
printf(" efficacy :");
scanf("%s", t->function);
printf(" Number :");
scanf("%d", &t->num);
printf(" Price :");
scanf("%lf", &t->price);
t->next=q;
p->next=t;
printf("-------------------------------\n");
printf(" Insert the success !\n");
system("pause");
break;
}
p=p->next;
q=q->next;
}
if(flag==0){
printf(" The specified drug information was not found !\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(" Please enter the information to insert the node :\n");
printf(" Number :");
scanf("%s", t->id);
printf(" name :");
scanf("%s", t->name);
printf(" efficacy :");
scanf("%s", t->function);
printf(" Number :");
scanf("%d", &t->num);
printf(" Price :");
scanf("%lf", &t->price);
t->next=p->next;
p->next=t;
printf("-------------------------------\n");
printf(" Insert the success !\n");
system("pause");
}
void Sort(Medicine *head)
{
system("cls");
printf("-------------------------------\n");
printf(" Sort by quantity ( Ascending )---1\n");
printf(" Sort by quantity ( Descending )---2\n");
printf(" Sort by price ( Ascending )---3\n");
printf(" Sort by price ( Descending )---4\n");
printf(" Press 0 Back to main menu \n");
printf(" Please select sort by :");
int choice=0;
scanf("%d",&choice);
Medicine *p=head->next;
Medicine *q=NULL;
int flag=0; // Determine whether to exchange data
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){
// Exchange the contents of the structure
Medicine t=*p;
*p=*q;
*q=t;
// Restore the pointer field
t.next=p->next;
p->next=q->next;
q->next=t.next;
}
}
}
int flag1;
printf(" Sort success !\n");
printf(" Whether to print the sorted drug information ? yes (1)/ no (0)");
scanf("%d",&flag1);
if(flag1==1){
Print(head);
}else{
printf(" About to exit the sorting interface !");
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(" Number :%s\n",p->id);
printf(" name :%s\n",p->name);
printf(" efficacy :%s\n",p->function);
printf(" The remaining quantity :%d\n",p->num);
printf(" Price :%.2lf element \n",p->price);
}
void Esc()// Exit the management system
{
system("cls");
printf(" Welcome to use the pharmacy management system next time !");
system("pause");
exit(0);// End procedure
}
边栏推荐
- Building of Hisilicon 3559 universal platform: obtaining the modified code of data frame
- [cf] 803 div2 A. XOR Mixup
- 海思3559萬能平臺搭建:獲取數據幀修改後編碼
- Getting started with the go language is simple: go handles XML files
- 1020. number of enclaves
- Flutter 从零开始 007 输入框
- How to use the plug-in mechanism to gracefully encapsulate your request hook
- Talk about how to do hardware compatibility testing and quickly migrate to openeuler?
- lvgl 小部件样式篇
- 1254. 统计封闭岛屿的数目
猜你喜欢
Lvgl widget styles
A new journey of the smart court, paperless office, escorting the green trial of the smart court
Hannaiping of Qilin software: the construction of Digital China needs its own open source root community
How difficult is data governance and data innovation?
移除无效的括号[用数组模拟栈]
SuperMap iClient3D for WebGL 加载TMS瓦片
What are the applications of 3D visual inspection in production flow
A Generic Deep-Learning-Based Approach for Automated Surface Inspection-论文阅读笔记
MySQL composite query
Browser plays RTSP video based on nodejs
随机推荐
海思3559开发常识储备:相关名词全解
用宝塔建第2个网站时网站总是报错:No input file specified.
STM32 移植 RT-Thread 标准版的 FinSH 组件
Yolov5 export the pit encountered by onnx
Construction de la plate - forme universelle haisi 3559: obtenir le codage après modification du cadre de données
Building of Hisilicon 3559 universal platform: obtaining the modified code of data frame
DMA控制器8237A
Sword finger offer 05 Replace spaces: replace each space in the string s with "%20"“
Hisilicon 3559 sample parsing: Venc
ES6新特性介绍
Splitting e-commerce systems into micro services
When building the second website with pagoda, the website always reports an error: no input file specified
695.最大岛屿面积
SuperMap 3D SDKs_Unity插件开发——连接数据服务进行SQL查询
Swagger2自动生成APi文档
R language ggplot2 visual Facet: gganimate package is based on Transition_ The time function creates a dynamic scatter graph animation (GIF) and uses the labs function to add a dynamic time title to t
After the node is installed in the NVM, the display is not internal or external when the NPM instruction is used
Subtrate 源码追新导读-5月上旬: XCM 正式启用
Lichuang EDA learning notes 10 common connector component identification and passive buzzer driving circuit
剑指 Offer 05. 替换空格: 把字符串 s 中的每个空格替换成“%20“