#include <stdio.h>
#include <stdlib.h>
typedef struct employee
{
int num;
char duty[10];
char name[10];
char sex[3];
unsigned char age;
char edu[10];
int salary;
char tel_office[13];
char tel_home[13];
char mobile[13];
char qq[11];
char address[31];
struct employee *next;
}EMP;
char password[9];
EMP *emp_first,*emp_end;
char gsave,gfirst;
void addemp(void);
void findemp(void);
void listemp(void);
void modifyemp(void);
void summaryemp(void);
void delemp(void);
void resetpwd(void);
void readdata(void);
void savedata(void);
int modi_age(int s);
int modi_salary(int s);
char *modi_field(char *field,char *s,int n);
EMP *findname(char *name);
EMP *findnum(int num);
EMP *findtelephone(char *name);
EMP *findqq(char *name);
void displayemp(EMP *emp,char *field,char *name);
void checkfirst(void);
void bound(char ch,int n);
void login();
void menu();
void addemp()
{
FILE *fp;
EMP *emp1;
int i=0;
char choice='y';
if((fp=fopen("employee.dat","ab"))==NULL)
{
printf("打开文件employee.dat出错!\n");
getch();
return;
}
do{
i++;
emp1=(EMP *)malloc(sizeof(EMP));
if(emp1==NULL)
{
printf("内存分配失败,按任意键退出!\n");
getch();
return;
}
printf("请输入第%d个员工的信息,\n",i);
bound('_',30);
printf("工号:");
scanf("%d",&emp1->num);
printf("职务:");
scanf("%s",&emp1->duty);
printf("姓名:");
scanf("%s",&emp1->name);
printf("性别:");
scanf("%s",&emp1->sex);
printf("年龄:");
scanf("%d",&emp1->age);
printf("文化程度:");
scanf("%s",&emp1->edu);
printf("工资:");
scanf("%d",&emp1->salary);
printf("办公电话:");
scanf("%s",&emp1->tel_office);
printf("家庭电话:");
scanf("%s",&emp1->tel_home);
printf("移动电话:");
scanf("%s",&emp1->mobile);
printf("QQ:");
scanf("%s",&emp1->qq);
printf("地址:");
scanf("%s",&emp1->address);
emp1->next=NULL;
if(emp_first==NULL)
{
emp_first=emp1;
emp_end=emp1;
}else {
emp_end->next=emp1;
emp_end=emp1;
}
fwrite(emp_end,sizeof(EMP),1,fp);
gfirst=0;
printf("\n");
bound('_',30);
printf("\n是否继续输入?(y/n)");
fflush(stdin);
choice=getch();
if(toupper(choice)!='Y')
{
fclose(fp);
printf("\n输入完毕,按任意键返回\n");
getch();
return;
}
system("cls");
}while(1);
}
void bound(char ch,int n)
{
while(n--)
putch(ch);
printf("\n");
return;
}
/*首次使用,进行用户信息初始化*/
void checkfirst()
{
FILE *fp,*fp1;
char pwd[9],pwd1[9],pwd2[9],pwd3[9],ch;
int i;
char strt='8';
if((fp=fopen("config.bat","rb"))==NULL)
{
printf("\n新系统,请进行相应的初始化操作!\n");
bound('_',50);
getch();
do{
printf("\n设置密码,请不要超过8位:");
for(i=0;i<8&&((pwd[i]=getch())!=13);i++)
putch('*');
printf("\n再确认一次密码:");
for(i=0;i<8&&((pwd1[i]=getch())!=13);i++)
putch('*');
pwd[i]='\0';
pwd1[i]='\0';
if(strcmp(pwd,pwd1)!=0)
printf("\n两次密码输入不一致,请重新输入!\n\n");
else break;
}while(1);
if((fp1=fopen("config.bat","wb"))==NULL)
{
printf("\n系统创建失败,请按任意键退出!");
getch();
exit(1);
}
i=0;
while(pwd[i])
{
pwd2[i]=(pwd[i]^ strt);
putw(pwd2[i],fp1);
i++;
}
fclose(fp1);
printf("\n\n系统初始化成功,按任意键退出后,再重新进入!\n");
getch();
exit(1);
}else{
i=0;
while(!feof(fp)&&i<8)
pwd[i++]=(getw(fp)^strt);
pwd[i]='\0';
if(i>=8) i--;
while(pwd[i]!=-1&&i>=0)
i--;
pwd[i]='\0';
strcpy(password,pwd);
}
}
void delemp()
{
int findok=0;
EMP *emp1,*emp2;
char name[10],choice;
system("cls");
printf("\n输入要删除的员工姓名:");
scanf("%s",name);
emp1=emp_first;
emp2=emp1;
while(emp1)
{
if(strcmp(emp1->name,name)==0)
{
findok=1;
system("cls");
printf("员工:%s的信息如下:",emp1->name);
bound('_',40);
printf("工号:%d\n",emp1->num);
printf("职务:%s\n",emp1->duty);
printf("姓名:%s\n",emp1->name);
printf("性别:%s\n",emp1->sex);
printf("年龄:%d\n",emp1->age);
printf("文化程度:%s\n",emp1->edu);
printf("工资:%d\n",emp1->salary);
printf("办公电话:%s\n",emp1->tel_office);
printf("家庭电话:%s\n",emp1->tel_home);
printf("移动电话:%s\n",emp1->mobile);
printf("QQ号码:%s\n",emp1->qq);
printf("住址:%\ns",emp1->address);
bound('_',40);
printf("您真的要删除该员工吗?(y/n)");
fflush(stdin);
choice=getchar();
if(choice!='y' && choice!='Y') return;
if(emp1==emp_first) emp_first=emp1->next;
else emp2->next=emp1->next;
free(emp1);
gsave=1;
savedata();
return;
} else{
emp2=emp1;
emp1=emp1->next;
}
}
if(!findok)
{
bound('_',40);
printf("\n没有找到姓名是:%s的信息!\n",name);
getch();
}
return;
}
void displayemp(EMP *emp,char *field,char *name)
{
if(emp)
{
printf("\n%s:%s信息如下:\n",field,name);
bound('_',30);
printf("工号:%d\n",emp->num);
printf("职务:%s\n",emp->duty);
printf("姓名:%s\n",emp->name);
printf("性别:%s\n",emp->sex);
printf("年龄:%d\n",emp->age);
printf("文化程度:%s\n",emp->edu);
printf("工资:%d\n",emp->salary);
printf("办公电话:%s\n",emp->tel_office);
printf("家庭电话:%s\n",emp->tel_home);
printf("移动电话:%s\n",emp->mobile);
printf("QQ号码:%s\n",emp->qq);
printf("住址:%s\n",emp->address);
bound('_',30);
}else {
bound('_',40);
printf("资料库中没有%s为:%s的员工!请重新确认!",field,name);
}
return;
}
EMP *findname(char *name)
{
EMP *emp1;
emp1=emp_first;
while(emp1)
{
if(strcmp(name,emp1->name)==0) return emp1;
emp1=emp1->next;
}
return NULL;
}
EMP *findnum(int num)
{
EM
评论12
最新资源