first commit

master
parent b45dd32fdc
commit 17cbd5029d

@ -0,0 +1,433 @@
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
int i=1;
struct staffsinfor
{
char staffnums[100];
char name[100];
char sex[100];
char year[100];
char studyF[100];
char homedress[100];
char money[100];
char phonenum[100];
}staffs[50];
void reader()
{
FILE *fp;
int n = 0;
if( (fp = fopen("g:\\..txt","r")) == NULL )
{
return 0;
}
fscanf(fp,"%d\n",&i);
while(n < i)
{
fscanf(fp,"%s\n%s\n%s\n%s\n%s\n%s\n%s\n",staffs[n].staffnums,staffs[n].name,staffs[n].sex,staffs[n].studyF,staffs[n].homedress,staffs[n].money,staffs[n].phonenum);
n ++;
}
fclose(fp);
}
void writeer()
{
FILE *fp;
int n = 0;
if( (fp = fopen("g:\\..txt","wb")) == NULL )
{
return ;
}
fprintf(fp,"%d\n",i);
while(n < i)
{
fprintf(fp,"%s\n%s\n%s\n%s\n%s\n%s\n%s\n",staffs[n].staffnums,staffs[n].name,staffs[n].sex,staffs[n].studyF,staffs[n].homedress,staffs[n].money,staffs[n].phonenum);
n ++;
}
fclose(fp);
}
void input(struct staffsinfor staffs[]){
int n;
int a;
int c,d;
reader();
system("cls");
do
{
system("cls");
printf("\t\t\t\t您在进行的是信息录入!\t\t\t\n\n\n");
a = 0;
printf("\t\t请输入职工的工号: \n\t\t");
scanf("%s",staffs[i].staffnums);
for(n = 0 ; n < i ; n ++)
{
if(strcmp(staffs[n].staffnums,staffs[i].staffnums) == 0)
{
a = 1;
break;
}
}
if(a!=0)
{
MessageBox(NULL,"职工号已存在","系统提示",MB_OK);
d= MessageBox(NULL,"是否继续录入?","系统提示",MB_YESNO);
if(d==6)
continue;
break;
}
printf("\t\t请输入职工的姓名: \n\t\t");
scanf("%s",staffs[i].name);
printf("\t\t请输入职工的性别: \n\t\t");
scanf("%s",staffs[i].sex);
printf("\t\t请输入职工的年龄: \n\t\t");
scanf("%s",staffs[i].year);
printf("\t\t请输入职工的学历: \n\t\t");
scanf("%s",staffs[i].studyF);
printf("\t\t请输入职工的工资: \n\t\t");
scanf("%s",staffs[i].money);
printf("\t\t请输入职工的住址: \n\t\t");
scanf("%s",staffs[i].homedress);
printf("\t\t请输入职工的电话: \n\t\t");
scanf("%s",staffs[i].phonenum);
c=MessageBox(NULL,"是否继续录入","系统提示",MB_YESNO);
i ++;
}while( c ==6);
writeer();
MessageBox(NULL,"操作完成","系统提示",MB_OK);
}
void look(struct staffsinfor staffs[]){
int j;;char o;
reader();j=i-1;
three :
system("cls");
printf("\t\t\t\t您在进行的是浏览名单!\n\n\n");
printf("\t\t1,单个浏览\t\t\t2,总览\n");
char v;
scanf("%c",&v);
if(v>'2'||v<'1')
{
printf("输入错误,请重新输入!");
system("pause");
goto three;
}
else if(v=='2')
goto L999;
if(j==0)
{
MessageBox(NULL,"未找到名单信息!","系统提示",MB_OK);
return 0;
}
o1 :
system("cls");
printf("\t\t\t姓名:\n\t\t\t\t\t\t\t%s",staffs[j].name);
printf("\n\t\t\t职工号:\n\t\t\t\t\t\t\t%s",staffs[j].staffnums);
printf("\n\t\t\t性别:\n\t\t\t\t\t\t\t%s",staffs[j].sex);
printf("\n\t\t\t年龄:\n\t\t\t\t\t\t\t%s",staffs[j].year);
printf("\n\t\t\t学历:\n\t\t\t\t\t\t\t%s",staffs[j].studyF);
printf("\n\t\t\t工资:\n\t\t\t\t\t\t\t%s",staffs[j].money);
printf("\n\t\t\t家庭住址:\n\t\t\t\t\t\t\t%s",staffs[j].homedress);
printf("\n\t\t\t电话号码:\n\t\t\t\t\t\t\t%s",staffs[j].phonenum);
printf("\n\n\n\t\t\t\t\t\t按A和D切换名单\n\t\t\t\t\t\t按任意键退回菜单");
o=getch();
if(o=='A')
{
if(j==1)
{system("cls");
printf("这已经是第一个了");
system("pause");
goto o1;
}
j--;
goto o1;
}
if(o=='D')
{
if(j==i)
{system("cls");
printf("这是最后一个了");
system("pause");
goto o1;
}
j++;
goto o1;
}
else
return 0;
L999:
system("cls");
for(v=0;v<i;v++)
{
output_inf(v);
printf("---------------------------------------------------\n");
}
system("pause");
return 0;
}
void output_inf(int id)
{
printf("\t\t 姓名: %s\n",staffs[id].name);
printf("\t\t 工号: %s\n",staffs[id].staffnums);
printf("\t\t 性别: %s\n",staffs[id].sex);
printf("\t\t 年龄: %s\n",staffs[id].year);
printf("\t\t 学历: %s\n",staffs[id].studyF);
printf("\t\t 工资: %s\n",staffs[id].money);
printf("\t\t 住址: %s\n",staffs[id].homedress);
printf("\t\t 电话: %s\n",staffs[id].phonenum);
printf("\n\n\n");
}
void shanchu(){
int n,j;char delete_ID[20];
int flag;
char c;
reader();
while(1)
{
system("cls");
flag = 0;
printf("请输入需删除职工信息的工号:");
scanf("%s",delete_ID);
for(n=0;n<i;n++)
{
if( strcmp(staffs[n].staffnums,delete_ID) == 0)
{
i--;
flag = 1;
for(j=n ; j < i ; j ++)
{
staffs[j] =staffs[j + 1];
}
break;
}
}
if(!flag) printf("\n\n无此员工信息!\n\n");
else printf("\n\n删除成功!\n");
int k;
k=MessageBox(NULL,"是否继续删除?","系统提示",MB_YESNO);
if(k!=6) break;
}
writeer();
}
void que()//查询信息
{
char num;
int flag,n;
char q_id[20] ;//查询工号
char q_name[20] ;//查询姓名
char q_edu[20] ; //查询学历
int c;//
reader();//打开程序后,要查询以前的数据,要先读入
while(1)
{
system("cls");
printf("\t\t******************查询********************\n");
printf("\t\t* *\n");
printf("\t\t* 1.按工号查询 *\n");
printf("\t\t* *\n");
printf("\t\t* 2.按姓名查询 *\n");
printf("\t\t* *\n");
printf("\t\t* 按0退出本模块 *\n");
printf("\t\t******************************************\n");
printf("\t\t请输入指令(1-2):");
scanf("%d",&num);
if(num < 0 || num > 2)
{
printf("错误指令!\n\n");
system("pause");
continue;
}
system("cls");
flag = 0;//用来标记职工信息是否存在
if(num == 1)//按工号查询
{
printf("\t\t请输入您要查询职工的工号:");
scanf("%s",q_id);
for(n = 0 ; n < i ;n ++)
{
if( strcmp(staffs[n].staffnums,q_id) == 0)
{
output_inf(n);
flag = 1;//标记
break;
}
}
}
else if(num == 2)//按姓名查询
{
printf("\t\t请输入您要查询职工的姓名:");
scanf("%s",q_name);
for(n = 0 ; n < i ;n ++)
{
if( strcmp(staffs[n].name,q_name) == 0)
{
output_inf(n);
flag = 1;//标记
}
}
}
else if(num ==0)
return 0;
if(!flag)//判断是否有该职工信息
{
printf("\n\n无该职工信息!\n\n");
}
int k;
k= MessageBox(NULL,"是否继续?","系统提示",MB_YESNO);
if(k!=6) break;
}
}
void xiugai(){
char change_ID[20];//需修改的职工的工号
int number;//职工信息在数据中的位置
char num;//指令
char message[100];//修改的信息
char c;//指令Y?N
int flag;
int n;
reader();
while(1)
{
flag = 0;
system("cls");
printf("请输入需修改的职工的工号:");
scanf("%s",change_ID);
for(n = 0 ; n < i ; n ++)
{
if( strcmp(staffs[n].staffnums,change_ID) == 0 )
{
number = n;
flag = 1;
break;
}
}
if(!flag)
{
printf("\n\n无此员工信息!!\n\n");
c=MessageBox(NULL,"是否继续?","系统提示",MB_YESNO);
if(c==6) continue;
break;
}
printf("\n\n\t\t******************修改********************\n");
printf("\t\t* *\n");
printf("\t\t* 1.修改姓名 *\n");
printf("\t\t* *\n");
printf("\t\t* 2.修改学历 *\n");
printf("\t\t* *\n");
printf("\t\t* 3.修改工资 *\n");
printf("\t\t* *\n");
printf("\t\t* 4.修改住址 *\n");
printf("\t\t* *\n");
printf("\t\t* 5.修改电话 *\n");
printf("\t\t* *\n");
printf("\t\t* 6.修改性别 *\n");
printf("\t\t* *\n");
printf("\t\t* 按0退出 *\n");
printf("\t\t******************************************\n");
printf("\t\t请输入指令(1-6):");
scanf("%*c%c",&num);
if(num < '1' || num > '6')
{
printf("错误指令!\n\n");
system("pause");
continue;
}
system("cls");
printf("请输入修改后的信息:");
scanf("%s",message);
switch(num)
{
case '1' : strcpy(staffs[number].name,message); break;
case '2' : strcpy(staffs[number].studyF,message); break;
case '3' : strcpy(staffs[number].money,message); break;
case '4' : strcpy(staffs[number].homedress,message); break;
case '5' : strcpy(staffs[number].phonenum,message); break;
case '6' : strcpy(staffs[number].sex,message);break;
case '0' :exit(1);
}
system("cls");int k;
k=MessageBox(NULL,"是否继续?","系统提示",MB_YESNO);
if(k==6) break;
}
writeer();
}
int main()
{
char a;
/*职工信息管理系统设计最多2人
使
1
2()
3
4
5()*/
one :
system("cls");
printf("\t\t\t\t管理菜单\t\t\t\t\n");
printf("**********************************************************************\n\n\n");
printf("\t\t\t\tA.录入信息\t\t\t\t\n\n");
printf("\t\t\t\tB.浏览名单\t\t\t\t\n\n");
printf("\t\t\t\tC.查询信息\t\t\t\t\n\n");
printf("\t\t\t\tD.删除信息\t\t\t\t\n\n");
printf("\t\t\t\tE.修改信息\t\t\t\t\n\n");
printf("\t\t\t\t\t按BackSpace返回上一页\n\n\n");
printf("\t\t\t\t\tBy--罗丁,高论域\n\n");
printf("**********************************************************************\n");
a=getch();
if(a=='A')
{
input(staffs);
goto one;
}
else if(a=='B')
{
look(staffs);
goto one;
}
else if(a=='C')
{
que(staffs);
goto one;
}
else if(a=='D')
{
shanchu();
goto one;
}
else if(a=='E')
{
xiugai();
goto one;
}
else
{
printf("输入错误!");
system("pause");
goto one;
}
return 0;
}
Loading…
Cancel
Save