#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#define PASS_WORD "123456"
typedef struct _Stuff
{
int no;//工号
char name[20];//姓名
struct tm * tm_strat;//上班时间
struct tm * tm_end;//下班时间
char state[20];//出勤状况
}Stuff,*PStuff;
void Save_Info(PStuff mon,int n)
{
int i;
FILE* pFile = fopen("Mon_Info.dat","w");
if(pFile==NULL)
{
return;
}
for(i=0;i<n;i++)
{
fwrite(&mon[i],1,sizeof(Stuff),pFile);
}
fclose(pFile);
}
int Read_Info(PStuff mon)
{
int i=0;
FILE* pFile = fopen("Mon_Info.dat","r");
if(pFile==NULL)
{
return 0;
}
while(fread(&mon[i++],1,sizeof(Stuff),pFile));
fclose(pFile);
if(i>=1)
{
return i-1;
}
return 0;
}
int menu()
{
int chioce;
system("cls");
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("请输入选择:");
scanf("%d",&chioce);
while(chioce<1||chioce>8)
{
printf("请重新选择:");
scanf("%d",&chioce);
}
return chioce;
}
void Print_Stuff(PStuff stu,int n)
{
int i;
system("cls");
printf("%10s%10s%10s\n","工号","姓名","出勤");
for(i=0;i<n;i++)
{
printf("%10d",stu[i].no);
printf("%10s",stu[i].name);
printf("%10s\n",stu[i].state);
}
system("pause");
}
void Modfiy_Menu(PStuff stu,int n)
{
int i,temp;
int chioce;
char str[20];
system("cls");
printf("请输入要修改信息的职工号:");
scanf("%d",&temp);
for(i=0;i<n;i++)
{
if(stu[i].no==temp)
{
break;
}
}
if(i==n)
{
printf("无该职工号信息!\n");
system("pause");
return;
}
else
{
Print_Stuff(&stu[i],1);
}
printf("1:修改职工号\n");
printf("2:修改职工姓名\n");
printf("3:修改出勤情况\n");
printf("0:返回\n");
printf("请输入选择:");
scanf("%d",&chioce);
while(chioce<0||chioce>3)
{
printf("请重新选择:");
scanf("%d",&chioce);
}
switch(chioce)
{
case 1:
printf("请输入新职工号:");
scanf("%d",&stu[i].no);
break;
case 2:
printf("请输入新职工名:");
scanf("%s",&stu[i].name);
break;
case 3:
printf("请输入新出勤情况:");
scanf("%s",str);
strcpy(stu[i].state,str);
break;
case 0:
return ;
break;
}
printf("修改成功!\n");
Print_Stuff(&stu[i],1);
}
struct tm * Set_Time()
{
time_t tmpcal_ptr;
struct tm *tmp_ptr = NULL;
time(&tmpcal_ptr);
tmp_ptr = gmtime(&tmpcal_ptr);
tmp_ptr = localtime(&tmpcal_ptr);
printf ("%d.%d.%d ", (1900+tmp_ptr->tm_year), (1+tmp_ptr->tm_mon), tmp_ptr->tm_mday);
printf("%d:%d:%d\n", tmp_ptr->tm_hour, tmp_ptr->tm_min, tmp_ptr->tm_sec);
return tmp_ptr;
}
int Start_Work(PStuff stu,int n)
{
system("cls");
printf("请输入员工工号:");
scanf("%d",&stu[n].no);
printf("请输入员工姓名:");
scanf("%s",stu[n].name);
stu[n].tm_strat = Set_Time();
stu[n].tm_end=NULL;
if(stu[n].tm_strat->tm_hour >= 9)
{
strcpy(stu[n].state,"迟到");
}
else
{
strcpy(stu[n].state,"全勤");
}
printf("上班打卡成功!\n");
system("pause");
return n+1;
}
void End_Work(PStuff stu,int n)
{
int temp,i;
system("cls");
printf("请输入员工工号:");
scanf("%d",&temp);
for(i=0;i<n;i++)
{
if(temp==stu[i].no)
break;
}
if(i==n)
{
printf("无该职工号!\n");
system("pause");
return ;
}
if(stu[i].tm_end!=NULL)
{
printf("下班打卡重复 本次无效!\n");
system("pause");
return;
}
stu[i].tm_end = Set_Time();
if(stu[i].tm_end->tm_hour <= 17)
{
strcat(stu[n].state,"早退");
}
printf("下班打卡成功!\n");
system("pause");
}
void Serach_Stuff(PStuff stu,int n)
{
int i,temp;
system("cls");
printf("请输入要查询的职工号:");
scanf("%d",&temp);
for(i=0;i<n;i++)
{
if(stu[i].no==temp)
{
break;
}
}
if(i==n)
{
printf("无该职工号信息!\n");
system("pause");
}
else
{
Print_Stuff(&stu[i],1);
}
}
void Serach_Stuff_Name(PStuff stu,int n)
{
int i;
char temp[20];
system("cls");
printf("请输入要查询的职工名:");
scanf("%s",temp);
for(i=0;i<n;i++)
{
if(!strcmp(stu[i].name,temp))
{
break;
}
}
if(i==n)
{
printf("无该职工名信息!\n");
system("pause");
}
else
{
Print_Stuff(&stu[i],1);
}
}
int Delete_Stuff(PStuff stu,int n)
{
int i,num,j;
char temp[20];
system("cls");
printf("请输入管理密码:");
scanf("%s",temp);
if(strcmp(temp,PASS_WORD))
{
printf("密码错误!\n");
system("pause");
return n;
}
printf("请输入要删除的工号:");
scanf("%d",&num);
for(i=0;i<n;i++)
{
if(stu[i].no==num)
{
break;
}
}
if(i==n)
{
printf("无该职工号信息!\n");
system("pause");
return n;
}
for(j=i;j<n;j++)
{
stu[j]=stu[j+1];
}
printf("删除成功!\n");
system("pause");
return n-1;
}
int main(int argc,char* argv[])
{
int chioce;//记录选择
Stuff stuff[100];//保存职工信息
int NUM=0;//记录职工数量
NUM=Read_Info(stuff);
do
{
chioce=menu();
switch(chioce)
{
case 1:
NUM = Start_Work(stuff,NUM);
break;
case 2:
End_Work(stuff,NUM);
break;
case 3:
Print_Stuff(stuff,NUM);
break;
case 4:
Serach_Stuff(stuff,NUM);
break;
case 5:
Serach_Stuff_Name(stuff,NUM);
break;
case 6:
NUM=Delete_Stuff(stuff,NUM);
break;
case 7:
Modfiy_Menu(stuff,NUM);
break;
case 8:
Save_Info(stuff,NUM);
exit(0);
break;
}
}while(chioce!=8);
return 0;
}
职工考勤管理系统
最新推荐文章于 2023-06-01 22:37:29 发布