⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 主执行文件.txt

📁 人事管理系统
💻 TXT
📖 第 1 页 / 共 2 页
字号:
 /*开始搜索*/
for(j=0;j<i;j++){
   if(!strcmp(sp[j].name,search_name))
    if(mode){
    display(j,sp);
    return j;
   }
    else return j;
 }
printf("not find this worker called %s\n",search_name);
 return -1;
}

/*修改一个工人的资料的函数*/

void modify(int i,struct WORKER *mp){
 char mod_name[20];
 char temp[20];
 int mi;
 enum {false,true}status;
 status=false;
 printf("Enter the worker's name to modify:");
 scanf("%s",mod_name);

 /*调用search函数(在上面已经声明了的),搜索到的话就返回工人的id,没有的话就返回-1*/
 if((mi=search(i,mp,1,mod_name))==-1)return;

 /*下面的处理跟添加一个工人的资料的处理一模一样,比较繁*/

 printf("\nNow modify %s's profile...\n",mod_name);
  while(status==false){
  printf("Enter the name of the worker:");
  scanf("%s",mp[mi].name);
     if(strlen(mp[mi].name)==0 || strlen(mp[mi].name)>20){
	 status=false;puts("input error,name cannot over 8 character or less than 0 character!");
	 continue;
     }
     else
	status=true;
  printf("Enter the gender of worker:(1=>female,0=>male)");
  scanf("%d",&mp[mi].sex);
     if(mp[mi].sex!=0 && mp[mi].sex!=1){
	 status=false;puts("only 0 or 1 can be accepted!");
	 continue;
     }
     else
	status=true;
  printf("Enter the birthday of worker:\n");
  printf("\tYear:");
  scanf("%4d",&mp[mi].birthday.year);
     if(mp[mi].birthday.year>9999 || mp[mi].birthday.year<0){
	 status=false;puts("input error,the year of birthday cannot more than 9999 or less than 0!");
	 continue;
      }
     else
	status=true;
printf("\tMonth:");
  scanf("%2d",&mp[mi].birthday.month);
     if(mp[mi].birthday.month>12 || mp[mi].birthday.month<1){
	 status=false;puts("input error,the month of birthday cannot be more than 12 or less than 1");
	 continue;
      }
     else
	status=true;
printf("\tDay:");
  scanf("%2d",&mp[mi].birthday.day);
     if(mp[mi].birthday.day>31 || mp[mi].birthday.day<1){
	 status=false;puts("input error,the year of birthday cannot be more than 31 or less than 1!");
	 continue;
      }
     else
	status=true;

  printf("Enter the workday of worker:\n");
    printf("\tYear:");
  scanf("%4d",&mp[mi].workday.year);
     if(mp[mi].workday.year>9999 || mp[mi].workday.year<0){
	 status=false;puts("input error,the year of workday cannot more than 9999 or less than 0!");
	 continue;
      }
     else
	status=true;
printf("\tMonth:");
  scanf("%2d",&mp[mi].workday.month);
     if(mp[mi].workday.month>12 || mp[mi].workday.month<1){
	 status=false;puts("input error,the month of workday cannot be more than 12 or less than 1");
	 continue;
      }
     else
	status=true;
printf("\tDay:");
  scanf("%2d",&mp[mi].workday.day);
     if(mp[mi].workday.day>31 || mp[mi].workday.day<1){
	 status=false;puts("input error,the year of workday cannot be more than 31 or less than 1!");
	 continue;
      }
     else
	status=true;
  printf("Enter the record of formal schooling of worker:(0=>element school,1=>middle school,2=>high school,3=>university,4=>other)");
  scanf("%d",&mp[mi].rofs);
     if(mp[mi].rofs!=0 && mp[mi].rofs!=1 &&mp[mi].rofs!=2 &&mp[mi].rofs!=3 &&mp[mi].rofs!=4){
	 status=false;puts("only digit can be accepted!you can only enter 0,1,2,3,4");
	 continue;
     }
     else
	status=true;
  printf("Enter the position of worker:");
  scanf("%s",mp[mi].position);
     if(strlen(mp[mi].position)==0 || strlen(mp[mi].position)>20){
	 status=false;puts("input error,position cannot over 20 character or less than 0 character!");
	 continue;
     }else
	status=true;
  printf("Enter the address of worker:\n");
  printf("\tProvince:");
  scanf("%s",mp[mi].addr.province);
     if(strlen(mp[mi].addr.province)==0 || strlen(mp[mi].addr.province)>20){
	 status=false;puts("input error,province cannot over 20 character or less than 0 character!");
	 continue;
     }
     else
       status=true;
printf("\tCity:");
scanf("%s",mp[mi].addr.city);
     if(strlen(mp[mi].addr.city)==0 || strlen(mp[mi].addr.city)>20){
	 status=false;puts("input error,city cannot over 20 character or less than 0 character!");
	 continue;
     }
     else
       status=true;
printf("\tStreet:");
scanf("%s",mp[mi].addr.street);
     if(strlen(mp[mi].addr.street)==0 || strlen(mp[mi].addr.street)>30){
	 status=false;puts("input error,street cannot over 30 character or less than 0 character!");
	 continue;
     }
     else
       status=true;
  printf("Enter the telephone number of worker:(area code/telephone code)");
  scanf("%s",mp[mi].tel);
     if(strlen(mp[mi].tel)==0 || strlen(mp[mi].tel)>13){
	status=false;puts("input error,telephone number cannot over 13 character or less than 0 character!");
	continue;
     }
    else
      status=true;
 }
}
/*从数据库中删除一个工人的资料*/

void del(int *i,struct WORKER *dp){
 char del_name[20],choice;
 int di,dj,mi;
 printf("Enter the worker's name to delete:");scanf("%s",del_name);

  /*调用search函数(在上面已经声明了的),搜索到的话就返回工人的id,没有的话就返回-1*/
 if((mi=search(*i,dp,1,del_name))==-1)return;
 printf("Are you sure to delete this profile?(y/n)");
 choice=getch();
 if(choice=='n')
   return;
 for(di=dj=0;di<*i;di++)
  if(di!=mi)
    dp[dj++]=dp[di];
--*i;
 }
/*将内存中的工人资料保存一遍,也就是将被你操作后的工人资料都保存到数据库中
 如果你不保存的话,所有的操作都将白费(我说的好象是废话哦)
*/
void save(int i,struct WORKER *sp){
 int si;
 fp=fopen("worker.txt","w");

  /*错误处理*/
 if(!fp){
     printf("fail to save!\nMaybe the database file named worker.txt cannot be opened!Please check this file,it cannot be reak only!");
     return;
    }

  /*保存操作的循环*/
for(si=0;si<i;si++)
   fwrite(&sp[si],sizeof(struct WORKER),1,fp);

  /*检测是否在保存的时候遇到错误,如果错误的话提示再保存一遍*/
if(ferror(fp)){
 printf("save error!you try again!");
 clearerr(fp);
 fclose(fp);
 return;
}else{
  puts("save successfully!");
  fclose(fp);
 }
}
  /*排序,用的是冒泡排序法*/
void my_sort(int i,struct WORKER *sortp)
{
 int sortj,sorti;
 char schoice;
 struct WORKER sorttemp;
 for(sorti=0;sorti<i;sorti++){
    for(sortj=sorti;sortj<i;sortj++){
       if(strcmp(sortp[sorti].name,sortp[sortj].name)>0){
	  sorttemp=sortp[sorti];
	  sortp[sorti]=sortp[sortj];
	  sortp[sortj]=sorttemp;
       }
   }
 }

 /*排序完成后提示是否再次查看列表*/
printf("Sort successfully!Do you want to list all the profiles?(y/n)");
 schoice=getch();
if(schoice=='y')list(i,sortp);

}

/*清楚所有数据的函数,就是将数据库全部清空*/
void cleardb(int *i,struct WORKER *clrp){
 char clrc;
 printf("Are you sure to clear all the profiles?it will delete all the data(y/n)");
 clrc=getch();
 if(clrc=='n') return;

 /*当以只写模式打开文件的时候,指针会指向文件的头部,并且将文件内数据全部清空*/
 fp=fopen("worker.txt","w");
 fclose(fp);
 data_load(i,clrp);
 printf("\n\n\tClear successfully!");
 getch();
}


/*下面就是主函数了*/
void main(void)
{
 struct WORKER profile[maxworker];
  int selection;
int GD=DETECT,GM;
  char c;
  int i=0,k=1;
  initgraph(&GD,&GM,"e:\\tc\\bgi");
  setbkcolor(LIGHTBLUE);
 if ((al=fopen("hzk16","rb"))==NULL)
     { printf("Can't open haz16,Please add it");
    getch(); closegraph(); exit(0);
     }
rectangle(20,20,620,460);
rectangle(10,10,630,470);
hz(200,80,40,2,10,"人事管理系统");/*数字依次为横坐标纵坐标字体间距字体大小字体颜色*/
hz(100,150,25,1,11,"长沙理工大学计算机系软件工程课程设计");
hz(100,200,25,1,11,"设计人员:安国兵姚金伶扬寒贺晓玲肖红吴涵");
hz(100,250,25,1,11,"按任意键进入");
getch();
closegraph();
	close(al);


  clrscr();
   initgraph(&GD,&GM,"e:\\tc\\bgi");
  setbkcolor(LIGHTBLUE);
 if ((al=fopen("hzk16","rb"))==NULL)
     { printf("Can't open haz16,Please add it");
    getch(); closegraph(); exit(0);
     }


  data_load(&i,profile);
  do
  { if(k!=1)
    {printf("\nPlease press any key to return to the main meun");
    getch();}
    k++;  

    clrscr();
    initgraph(&GD,&GM,"e:\\tc\\bgi");
    setbkcolor(LIGHTBLUE);
    hz(200,20,40,2,10,"人事管理系统");
    printf("\n\n\n\n\n");
    printf("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
    printf("\t\t\t*1.Add one worker to the file\n");
    printf("\t\t\t*2.Delete one worker from the file\n");
    printf("\t\t\t*3.Search one worker from the file\n");
    printf("\t\t\t*4.Modify one worker's information\n");
    printf("\t\t\t*5.List all the profiles\n");
    printf("\t\t\t*6.Save new data\n");
    printf("\t\t\t*7.Sort the profiles\n");
    printf("\t\t\t*8.Reload data from database file\n");
    printf("\t\t\t*9.Delete all data\n");
    printf("\t\t\t*0.exit without save\n\n\n");
    printf("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
    printf("\t\t\tPlease input your selection number:");

    scanf("%d",&selection);
    switch(selection)

	{
	  case 1:
	    add(&i,profile);
	    printf("\n\nin function main,i=%d",i);
	    break;
	  case 2:
	  del(&i,profile);
	  break;
	  case 3:
	  search(i,profile,1,"");
	  break;
	  case 4:
	  modify(i,profile);
	  break;
	  case 5:
	   list(i,profile);
	   break;
	 case 6:
	   save(i,profile);
	   break;
	 case 7:
	   my_sort(i,profile);
	   break;
	 case 8:
	   data_load(&i,profile);
	   break;
	 case 9:
	   cleardb(&i,profile);
	   break;
	  case 0:
	    printf("Are you sure to exit without save?New data that you enter will be lost!(y/n)");
	    c=getch();
	    if(c=='y'||'Y')exit(0);
	    break;
	  default:

	    printf("please enter the correct selection!");
	    return 0;
	 }
 }while(1);

}
 
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -