www.pudn.com > YELIUJUN.rar > YELIUJUN.C


/*人事管理系统*/ 
/*系统密码:abc*/ 
 
#include 
#include 
#include 
#include/*字符串处理*/ 
#include /*字符处理*/ 
#include 
#define maxworker 200 
FILE *fp,*fd; /*文件指针*/ 
 
struct date    /*生日结构*/ 
         {       
          int year; 
          int month; 
          int day; 
         }; 
struct address   /*地址结构*/ 
         {   
          char province[10]; 
          char city[10]; 
          char street[20]; 
         }; 
struct WORKER  
         { 
          char name[20];/*姓名*/ 
          char num[10];/*工作证号*/ 
          char body_num[20];/*身分证号*/ 
          struct date birthday;/*生日*/ 
          struct address addr;/*家庭住址*/ 
          char tel[13];/*家庭电话号码*/ 
          char part[20];/*部门*/ 
          long salary;/*薪水*/ 
          int sex;/*性别0为女1为男*/ 
          int position;/*职务1为董事长2为总经理3为副总经理等4为经理5为副经理6为普通职工*/ 
          int rofs;/*0小学1中学2高校3大学4其他*/ 
         }; 
struct SECRET  
         { 
          char mima[20]; 
         }; 
d_load(struct SECRET *pa) 
  { 
   char c; 
    
   fd=fopen("wor.txt","r"); 
   if(!fd) 
     {fopen("wor.txt","w+");} 
   else 
     { 
        { 
         if(feof(fd)) return; 
           c=fgetc(fd); 
         if(c==EOF) return; 
           fflush(stdin); 
          
         fseek(fd,0*sizeof(struct SECRET),SEEK_SET); 
         fread(&pa[0],sizeof(struct SECRET),1,fd); 
        } 
     } 
   fclose(fd); 
  } 
 
void sav_passwod(struct SECRET *sap) 
  { 
   int si; 
   fd=fopen("wor.txt","w"); 
   /*错误处理*/ 
   if(!fd) 
     { 
      cprintf("\nfail to save!\r\n\nMaybe the database file named wor.txt cannot be opened!Please check this file,it cannot be reak only!\r\n"); 
      return; 
     } 
        fwrite(&sap[0],sizeof(struct SECRET),1,fd); 
     /*检测是否保存错误,如果错误的话提示再保存一遍*/ 
     if(ferror(fd)) 
       { 
        cprintf("\nsave error!you try again!\r\n");  
        clearerr(fd); 
        fclose(fd); 
        getch(); 
        return; 
       }  
     else 
       { 
                fclose(fp);  
         
       }  
  } 
 
 
 
/*数据初始化:把文件中的内容读出到内存中进行相应的操作*/ 
data_load(int *i,struct WORKER *p) 
  { 
   char c; 
   long int k; 
   fp=fopen("worker_file.txt","r"); 
   if(!fp) 
     {fopen("worker_file.txt","w+");*i=0;} 
   else 
     { 
      for((*i)=0;(*i)19) 
              {gotoxy(5,13); 
               cprintf("input error,name cannot over 8 character or less than 0 character!"); 
               gotoxy(5,14); 
               cprintf("Press any key to continue!"); 
               getch(); 
               clrscr(); 
               b=1; 
              } 
            else 
              b=0; 
            }while(b==1); 
         if((search(*i,profile,1,add_name))==-1)/*调用search函数,搜索到就返回其id,没有就返回-1*/ 
            { 
              a=0; 
            } 
         else 
            {cprintf("\nThis person had in the file!\r\n"); 
             cprintf("\ninput another person's name!\r\n"); 
             cprintf("\nPress any key to continue!\r\n"); 
             getch(); 
             clrscr(); 
             a=1; 
            } 
          }while(a==1); 
        clrscr(); 
        do 
          { 
           gotoxy(5,12); 
           cprintf("Enter the employee's I.D. card number of the worker:"); 
           scanf("%s",add_num); 
           if(strlen(add_num)==0||strlen(add_num)>10) 
             {gotoxy(5,13); 
              cprintf("input error!cannot over 4 character or less than 0 character!"); 
              gotoxy(5,14); 
              cprintf("Press any key to continue!"); 
              getch(); 
              clrscr(); 
              a=1; 
             } 
           else 
             a=0; 
         }while(a==1); 
       clrscr(); 
       do 
         { 
          gotoxy(5,12); 
          cprintf("Enter the identification card number of the worker:"); 
          scanf("%s",add_body_num); 
          if(strlen(add_body_num)==0||strlen(add_body_num)>19) 
            {gotoxy(5,13); 
             cprintf("input error!cannot over 8 character or less than 0 character!"); 
             gotoxy(5,14); 
             cprintf("Press any key to continue!"); 
             getch(); 
             clrscr(); 
             a=1; 
            } 
          else 
            a=0; 
         }while(a==1); 
       clrscr(); 
       do 
         { 
          gotoxy(5,12); 
          cprintf("Enter the birthday of worker::"); 
          cprintf("Year:"); 
          scanf("%4d",&add_birthday_year); 
          if(add_birthday_year<0||add_birthday_year>2008) 
            {gotoxy(5,13); 
             cprintf("input error!(0-9999)"); 
             gotoxy(5,14); 
             cprintf("Press any key to continue!"); 
             getch(); 
             clrscr(); 
             a=1; 
            } 
          else 
            a=0; 
 
         }while(a==1); 
       clrscr(); 
       do 
         { 
          gotoxy(5,12); 
          cprintf("Enter the birthday of worker::"); 
          cprintf("Month:"); 
          scanf("%2d",&add_birthday_month); 
          if(add_birthday_month<1||add_birthday_month>12) 
             {gotoxy(5,13); 
              cprintf("input error!(1-12)"); 
              gotoxy(5,14); 
              cprintf("Press any key to continue!"); 
              getch(); 
              clrscr(); 
              a=1; 
             } 
           else 
             a=0; 
 
          }while(a==1); 
        clrscr(); 
        do 
          { 
           gotoxy(5,12); 
           cprintf("Enter the birthday of worker::"); 
           cprintf("Day:"); 
           scanf("%2d",&add_birthday_day); 
           if(add_birthday_day<1||add_birthday_day>31) 
              {gotoxy(5,13); 
               cprintf("input error!(1-31)"); 
               gotoxy(5,14); 
               cprintf("Press any key to continue!"); 
               getch(); 
               clrscr(); 
               a=1; 
              } 
            else 
              a=0; 
 
           }while(a==1); 
         clrscr(); 
         do{ 
             gotoxy(5,12); 
             cprintf("Enter the address of worker::"); 
             cprintf("Province:"); 
             scanf("%s",add_province); 
             if(strlen(add_province)==0 || strlen(add_province)>10) 
               {gotoxy(5,13); 
                cprintf("input error!cannot over 8 character or less than 0 character!"); 
                gotoxy(5,14); 
                cprintf("Press any key to continue!"); 
                getch(); 
                clrscr(); 
                a=1; 
               } 
             else 
               a=0; 
 
            }while(a==1); 
          clrscr(); 
          do{ 
             gotoxy(5,12); 
             cprintf("Enter the address of worker::"); 
             cprintf("City:"); 
             scanf("%s",add_city); 
             if(strlen(add_city)==0 || strlen(add_city)>10) 
               {gotoxy(5,13); 
                cprintf("input error!cannot over 8 character or less than 0 character!"); 
                gotoxy(5,14); 
                cprintf("Press any key to continue!"); 
                getch(); 
                clrscr(); 
                a=1; 
               } 
             else 
               a=0; 
 
            }while(a==1); 
          clrscr(); 
          do{ 
             gotoxy(5,12); 
             cprintf("Enter the address of worker::"); 
             cprintf("Street:"); 
             scanf("%s",add_street); 
             if(strlen(add_street)==0 || strlen(add_street)>19) 
                {gotoxy(5,13); 
                 cprintf("input error!cannot over 8 character or less than 0 character!"); 
                 gotoxy(5,14); 
                 cprintf("Press any key to continue!"); 
                 getch(); 
                 clrscr(); 
                 a=1; 
                } 
              else 
                a=0; 
 
             }while(a==1); 
           clrscr(); 
           do{ 
              gotoxy(1,12); 
              cprintf("Enter the telephone number of worker:(area code/telephone code)"); 
              scanf("%s",add_tel); 
              if(strlen(add_tel)==0 || strlen(add_tel)>13) 
                 {gotoxy(5,13); 
                  cprintf("input error!cannot over 5 character or less than 0 character!"); 
                  gotoxy(5,14); 
                  cprintf("Press any key to continue!"); 
                  getch(); 
                  clrscr(); 
                  a=1; 
                 } 
               else 
                 a=0; 
 
              }while(a==1); 
            clrscr(); 
            do{ 
               gotoxy(5,12); 
               cprintf("Enter the department of worker:"); 
               scanf("%s",add_part); 
               if(strlen(add_part)==0 || strlen(add_part)>19) 
                 {gotoxy(5,13); 
                  cprintf("input error!cannot over 8 character or less than 0 character!"); 
                  gotoxy(5,14); 
                  cprintf("Press any key to continue!"); 
                  getch(); 
                  clrscr(); 
                  a=1; 
                 } 
               else 
                 a=0; 
 
              }while(a==1); 
            clrscr(); 
            do{ 
               gotoxy(5,12); 
               cprintf("Enter the salary of worker:"); 
               scanf("%ld",&add_salary); 
               if(add_salary<0 || add_salary>99999) 
                 {gotoxy(5,13); 
                 cprintf("input error!(0-99999)"); 
                 gotoxy(5,14); 
                 cprintf("Press any key to continue!"); 
                 getch(); 
                 clrscr(); 
                 a=1; 
                } 
              else 
                a=0; 
 
             }while(a==1); 
           clrscr(); 
           do{ 
              gotoxy(5,12); 
              cprintf("Enter the gender of worker(0=>female,1=>male):"); 
              scanf("%d",&add_sex); 
              if(add_sex<0 || add_sex>1) 
                {gotoxy(5,13); 
                 cprintf("input error!only 0 and 1"); 
                 gotoxy(5,14); 
                 cprintf("Press any key to continue!"); 
                 getch(); 
                 clrscr(); 
                 a=1; 
                } 
              else 
                a=0; 
 
             }while(a==1); 
             clrscr(); 
             do{ 
                gotoxy(5,12); 
 cprintf("Enter the position of worker(1 Dongshizhang,2 Zhongjingli,3 Fuzhongjingli,4 Jingli,5 Fujingli,6 Putongyuangong):"); 
    scanf("%d",&add_position); 
    if(add_position<1 || add_position>6) 
      {gotoxy(5,13); 
       cprintf("input error!(1-6)"); 
       gotoxy(5,14); 
       cprintf("Press any key to continue!"); 
       getch(); 
       clrscr(); 
       a=1; 
      } 
    else 
      a=0; 
 
   }while(a==1); 
   clrscr(); 
   do{ 
      gotoxy(5,12); 
      cprintf("Enter the rofs of worker(0 Element school,1 Middle school,2 High school,3 University,4 Other):"); 
      scanf("%d",&add_rofs); 
      if(add_rofs<0 || add_rofs>4) 
        {gotoxy(5,13); 
         cprintf("input error!(0-4)"); 
         gotoxy(5,14); 
         cprintf("Press any key to continue!"); 
         getch(); 
         clrscr(); 
         a=1; 
        } 
      else 
        a=0; 
 
     }while(a==1); 
 
  strcpy(profile[*i].name,add_name); 
  strcpy(profile[*i].num,add_num); 
  strcpy(profile[*i].body_num,add_body_num); 
  profile[*i].sex=add_sex; 
  profile[*i].birthday.year=add_birthday_year; 
  profile[*i].birthday.day=add_birthday_day; 
  profile[*i].birthday.month=add_birthday_month; 
  profile[*i].salary=add_salary; 
  profile[*i].rofs=add_rofs; 
  profile[*i].position=add_position; 
  strcpy(profile[*i].addr.province,add_province); 
  strcpy(profile[*i].addr.city,add_city); 
  strcpy(profile[*i].addr.street,add_street); 
  strcpy(profile[*i].tel,add_tel); 
  strcpy(profile[*i].part,add_part); 
    ++(*i); 
    clrscr(); 
    gotoxy(5,12); 
    cprintf("Do you want to add another worker (y/n)?"); 
    cs=getch(); 
   }while(cs=='y'||cs=='Y'); 
   
  } 
 
/*显示所有人资料*/ 
void list(int i,struct WORKER *prof) 
  { 
   int j; 
   char temp[20]; 
   if(i==0) 
     {gotoxy(25,12); 
      cprintf("There is no profile in the list!"); 
      gotoxy(25,13); 
      cprintf("Press any key to return!\r\n"); 
      getch(); 
      return; 
     } 
   cprintf("========There are %d workers' profiles========\r\n",i); 
   for(j=0;j\r\n",(j+1)); 
      cprintf("\nName: %s\r\n",prof[j].name); 
      cprintf("Employee's I.D. card number: %s\r\n",prof[j].num); 
      cprintf("Identification card number: %s\r\n",prof[j].body_num); 
      if(prof[j].sex) 
        strcpy(temp,"Male"); 
      else 
        strcpy(temp,"Female");  
      cprintf("Gender: %s\r\n",temp); 
      cprintf("Birthday:"); 
      cprintf("%4d %2d %2d\r\n",prof[j].birthday.year,prof[j].birthday.month,prof[j].birthday.day); 
      cprintf("Address: %s %s city %s province\r\n",prof[j].addr.street,prof[j].addr.city,prof[j].addr.province); 
      cprintf("Telephone number:%s\r\n",prof[j].tel); 
      cprintf("Department: %s\r\n",prof[j].part); 
      cprintf("Salary: %ld\r\n",prof[j].salary); 
      switch(prof[j].position) 
        { 
         case 1:strcpy(temp,"Dongshizhang");break;  
         case 2:strcpy(temp,"Zhongjingli");break; 
         case 3:strcpy(temp,"Fuzhongjingli");break; 
         case 4:strcpy(temp,"Jingli");break; 
         case 5: strcpy(temp,"Fujingli");break; 
         case 6: strcpy(temp,"Putongyuangong");break; 
         default:strcpy(temp,"Error"); 
        } 
      cprintf("Position:%s\r\n",temp); 
      switch(prof[j].rofs) 
        { 
         case 0:strcpy(temp,"Element school");break;  
         case 1:strcpy(temp,"Middle school");break; 
         case 2:strcpy(temp,"High school");break; 
         case 3:strcpy(temp,"University");break; 
         case 4: strcpy(temp,"Other");break; 
         default:strcpy(temp,"Error"); 
        } 
      cprintf("The record of formal schooling:%s\r\n",temp); 
      cprintf("\nPress any key to continue!\r\n"); 
      getch(); 
     } 
  } 
 
/*显示一个人资料*/ 
 display(int dk,struct WORKER *prof) 
  { 
   char temp[20]; 
   if(dk>maxworker) 
   return; 
   cprintf("\n===============The profile of %s=================\n\r\n",prof[dk].name); 
   cprintf("\nName: %s\r\n",prof[dk].name); 
   cprintf("Employee's I.D. card number: %s\r\n",prof[dk].num); 
   cprintf("Identification card number: %s\r\n",prof[dk].body_num); 
   if(prof[dk].sex) 
     strcpy(temp,"Male"); 
   else 
     strcpy(temp,"Female"); 
   cprintf("Gender:%s\r\n",temp); 
   cprintf("Birthday:%4d %2d %2d\r\n",prof[dk].birthday.year,prof[dk].birthday.month,prof[dk].birthday.day); 
   cprintf("Address:%s %s city %s province\r\n",prof[dk].addr.street,prof[dk].addr.city,prof[dk].addr.province); 
   cprintf("Telephone number:%s\r\n",prof[dk].tel); 
   cprintf("Department: %s\r\n",prof[dk].part); 
   cprintf("Salary: %ld\r\n",prof[dk].salary); 
   switch(prof[dk].position) 
        { 
         case 1:strcpy(temp,"Dongshizhuang");break; 
         case 2:strcpy(temp,"Zhongjingli");break; 
         case 3:strcpy(temp,"Fuzhongjingli");break; 
         case 4:strcpy(temp,"Jingli");break; 
         case 5: strcpy(temp,"Fujingli");break; 
         case 6: strcpy(temp,"Putongyuangong");break; 
         default:strcpy(temp,"Error"); 
        } 
      cprintf("Position:%s\r\n",temp); 
   switch(prof[dk].rofs) 
     { 
      case 0: strcpy(temp,"Element school");break; 
      case 1:strcpy(temp,"Middle school"); break; 
      case 2:strcpy(temp,"High school");break; 
      case 3: strcpy(temp,"University"); break; 
      case 4:strcpy(temp,"Other");break; 
      default:strcpy(temp,"Error"); 
     } 
   cprintf("The record of formal schooling:%s\r\n",temp); 
   cprintf("\nPress any key to continue!\r\n"); 
   getch(); 
  } 
 
 
 
/*修改员工数据*/ 
void modify(int i,struct WORKER *mp) 
  { 
   char mod_name[20]; 
   char temp[20]; 
   int mi,a,b; 
   char cc,xs; 
   do 
      {clrscr(); 
       do{ 
          cprintf("Enter the worker's name to modify:"); 
          scanf("%s",mod_name); 
          if(strlen(mod_name)==0 || strlen(mod_name)>19) 
              {gotoxy(5,13); 
               cprintf("input error,name cannot over 8 character or less than 0 character!"); 
               gotoxy(5,14); 
               cprintf("Press any key to continue!"); 
               getch(); 
               clrscr(); 
               b=1; 
              } 
            else 
              b=0; 
           }while(b==1); 
       if((mi=search(i,mp,1,mod_name))==-1)/*调用search函数,搜索到就返回其id,没有就返回-1*/ 
           return; 
       cprintf("\nNow modify %s's profile...\r\n",mod_name); 
       cprintf("Do you modify the name (y/n)?\r\n"); 
       cc=getch(); 
       if(cc=='y'||cc=='Y') 
        {clrscr(); 
         do 
           { 
            gotoxy(5,12); 
            cprintf("Enter the new name of the worker:"); 
            scanf("%s",mp[mi].name); 
            if(strlen(mp[mi].name)==0 || strlen(mp[mi].name)>19) 
              { 
               gotoxy(5,13); 
               cputs("input error,name cannot over 8 character or less than 0 character!"); 
               gotoxy(5,14); 
               cputs("Press any key to return!"); 
               getch(); 
               clrscr(); 
               a=1; 
              } 
            else  
              a=0; 
            }while(a==1); 
          } 
      clrscr(); 
      cprintf("Do you modify the employee's I.D. card number (y/n)?\r\n"); 
      cc=getch(); 
      if(cc=='y'||cc=='Y') 
  
       do 
         { 
          gotoxy(5,12); 
          cprintf("Enter the new employee's I.D. card number of the worker:"); 
          scanf("%s",mp[mi].num); 
	  if(strlen(mp[mi].num)<0||strlen(mp[mi].num)>10) 
            {gotoxy(5,13); 
             cprintf("input error!"); 
             gotoxy(5,14); 
             cputs("Press any key to return!"); 
             getch(); 
             clrscr(); 
             a=1; 
            } 
          else 
            a=0;  
         }while(a==1); 
       clrscr(); 
      cprintf("Do you modify the Identification card number (y/n)?\r\n"); 
      cc=getch(); 
      if(cc=='y'||cc=='Y') 
    do 
      { 
      gotoxy(5,12); 
      cprintf("Enter the new Identification card number of the worker:"); 
      scanf("%s",mp[mi].body_num); 
      if(strlen(mp[mi].body_num)<0||strlen(mp[mi].body_num)>19) 
        {gotoxy(5,13); 
        cprintf("input error!"); 
        gotoxy(5,14); 
        cputs("Press any key to return!"); 
        getch(); 
      clrscr(); 
      a=1; 
     } 
   else 
      
     a=0;  
     }while(a==1); 
   clrscr(); 
   cprintf("Do you modify the birthday Year of worker (y/n)?\r\n"); 
      cc=getch(); 
      if(cc=='y'||cc=='Y') 
   do 
    { 
   gotoxy(5,12); 
   cprintf("Enter the new birthday of worker:"); 
   cprintf("Year:"); 
   scanf("%4d",&mp[mi].birthday.year); 
   if(mp[mi].birthday.year<0||mp[mi].birthday.year>2008) 
     {gotoxy(5,13); 
      cprintf("input error!"); 
      gotoxy(5,14); 
      cputs("Press any key to return!"); 
      getch(); 
      clrscr(); 
      a=1; 
     } 
   else 
     a=0; 
       
     }while(a==1); 
   clrscr(); 
   cprintf("Do you modify the birthday Month of worker (y/n)?\r\n"); 
      cc=getch(); 
      if(cc=='y'||cc=='Y') 
   do 
    { 
   gotoxy(5,12); 
   cprintf("Enter the new birthday of worker:"); 
   cprintf("Month:"); 
   scanf("%2d",&mp[mi].birthday.month); 
   if(mp[mi].birthday.month<1||mp[mi].birthday.month>12) 
     {gotoxy(5,13); 
      cprintf("input error!"); 
      gotoxy(5,14); 
      cputs("Press any key to return!"); 
      getch(); 
      clrscr(); 
      a=1; 
     } 
   else 
     a=0; 
       
     }while(a==1); 
   clrscr(); 
   cprintf("Do you modify the birthday Day of worker (y/n)?\r\n"); 
      cc=getch(); 
      if(cc=='y'||cc=='Y') 
   do 
    { 
   gotoxy(5,12); 
   cprintf("Enter the new birthday of worker:"); 
   cprintf("Day:"); 
   scanf("%2d",&mp[mi].birthday.day); 
   if(mp[mi].birthday.day<1||mp[mi].birthday.day>31) 
     {gotoxy(5,13); 
      cprintf("input error!"); 
      gotoxy(5,14); 
      cputs("Press any key to return!"); 
      getch(); 
      clrscr(); 
      a=1; 
     } 
   else 
     a=0; 
       
     }while(a==1); 
   clrscr(); 
   cprintf("Do you modify the address(Province) of worker (y/n)?\r\n"); 
      cc=getch(); 
      if(cc=='y'||cc=='Y') 
   do{ 
   gotoxy(5,12); 
   
   cprintf("new Province:"); 
   scanf("%s",mp[mi].addr.province); 
   if(strlen(mp[mi].addr.province)==0 || strlen(mp[mi].addr.province)>10) 
     {gotoxy(5,13); 
      cprintf("input error!"); 
      gotoxy(5,14); 
      cputs("Press any key to return!"); 
      getch(); 
      clrscr(); 
      a=1; 
     } 
   else 
     a=0; 
       
     }while(a==1); 
   clrscr(); 
   cprintf("Do you modify the address(City) of worker (y/n)?\r\n"); 
      cc=getch(); 
      if(cc=='y'||cc=='Y') 
   do{ 
   gotoxy(5,12); 
   
   cprintf("new City:"); 
   scanf("%s",mp[mi].addr.city); 
   if(strlen(mp[mi].addr.city)==0 || strlen(mp[mi].addr.city)>10) 
     {gotoxy(5,13); 
      cprintf("input error!"); 
      gotoxy(5,14); 
      cputs("Press any key to return!"); 
      getch(); 
      clrscr(); 
      a=1; 
     } 
   else 
     a=0; 
       
     }while(a==1); 
   clrscr(); 
   cprintf("Do you modify the address(Street) of worker (y/n)?\r\n"); 
      cc=getch(); 
      if(cc=='y'||cc=='Y') 
   do{ 
   gotoxy(5,12); 
 
   cprintf("new Street:"); 
   scanf("%s",mp[mi].addr.street); 
   if(strlen(mp[mi].addr.street)==0 || strlen(mp[mi].addr.street)>19) 
     {gotoxy(5,13); 
      cprintf("input error!"); 
      gotoxy(5,14); 
      cputs("Press any key to return!"); 
      getch(); 
      clrscr(); 
      a=1; 
     } 
   else 
     a=0; 
       
     }while(a==1); 
   clrscr(); 
   cprintf("Do you modify the telephone number of worker (y/n)?\r\n"); 
      cc=getch(); 
      if(cc=='y'||cc=='Y') 
   do{ 
   gotoxy(1,12); 
   cprintf("Enter the new telephone number of worker:(area code/telephone code)"); 
   scanf("%s",mp[mi].tel); 
   if(strlen(mp[mi].tel)==0 || strlen(mp[mi].tel)>13) 
     {gotoxy(5,13); 
      cprintf("input error!"); 
      gotoxy(5,14); 
      cputs("Press any key to return!"); 
      getch(); 
      clrscr(); 
      a=1; 
     } 
   else 
     a=0; 
       
     }while(a==1); 
   clrscr(); 
   cprintf("Do you modify the department of worker (y/n)?\r\n"); 
      cc=getch(); 
      if(cc=='y'||cc=='Y') 
   do{ 
   gotoxy(5,12); 
   cprintf("Enter the new department of worker:"); 
   scanf("%s",mp[mi].part); 
   if(strlen(mp[mi].part)==0 || strlen(mp[mi].part)>19) 
     {gotoxy(5,13); 
      cprintf("input error!"); 
      gotoxy(5,14); 
      cputs("Press any key to return!"); 
      getch(); 
      clrscr(); 
      a=1; 
     } 
   else 
     a=0; 
       
     }while(a==1); 
   clrscr(); 
   cprintf("Do you modify the salary of worker (y/n)?\r\n"); 
      cc=getch(); 
      if(cc=='y'||cc=='Y') 
   do{ 
   gotoxy(5,12); 
   cprintf("Enter the new salary of worker:"); 
   scanf("%ld",&mp[mi].salary); 
   if(mp[mi].salary<0 || mp[mi].salary>99999) 
     {gotoxy(5,13); 
      cprintf("input error!"); 
      gotoxy(5,14); 
      cputs("Press any key to return!"); 
      getch(); 
      clrscr(); 
      a=1; 
     } 
   else 
     a=0; 
       
     }while(a==1); 
   clrscr(); 
   cprintf("Do you modify the gender of worker (y/n)?\r\n"); 
      cc=getch(); 
      if(cc=='y'||cc=='Y') 
   do{ 
   gotoxy(5,12); 
   cprintf("Enter the new gender of worker(0=>female,1=>male):"); 
   scanf("%d",&mp[mi].sex); 
   if(mp[mi].sex<0 || mp[mi].sex>1) 
     {gotoxy(5,13); 
      cprintf("input error!"); 
       gotoxy(5,14); 
      cputs("Press any key to return!"); 
      getch(); 
      clrscr(); 
      a=1; 
     } 
   else 
     a=0; 
       
     }while(a==1); 
   clrscr(); 
   cprintf("Do you modify the position of worker (y/n)?\r\n"); 
      cc=getch(); 
      if(cc=='y'||cc=='Y') 
   do{ 
   gotoxy(5,12); 
 cprintf("Enter the new position of worker(1 Dongshizhang,2 Zhongjingli,3 Fuzhongjingli,4 Jingli,5 Fujingli,6 Putongyuangong):"); 
   scanf("%d",&mp[mi].position); 
   if(mp[mi].position<1 || mp[mi].position>6) 
     {gotoxy(5,13); 
      cprintf("input error!"); 
      gotoxy(5,14); 
      cputs("Press any key to return!"); 
      getch(); 
      clrscr(); 
      a=1; 
     } 
   else 
     a=0; 
       
     }while(a==1); 
   clrscr(); 
   cprintf("Do you modify the rofs of worker (y/n)?\r\n"); 
      cc=getch(); 
      if(cc=='y'||cc=='Y') 
   do{ 
   gotoxy(5,12); 
   cprintf("Enter the new rofs 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>4) 
     {gotoxy(5,13); 
      cprintf("input error!"); 
      gotoxy(5,14); 
      cputs("Press any key to return!"); 
      getch(); 
      clrscr(); 
      a=1; 
     } 
    else 
     a=0; 
    }while(a==1); 
    clrscr(); 
    gotoxy(5,12); 
    cprintf("Do you want to modify another worker (y/n)?"); 
    xs=getch(); 
   }while(xs=='y'||xs=='Y'); 
  } 
 
 
/*删除一个人的资料*/ 
void del(int *i,struct WORKER *dp) 
  { 
   char del_name[20],choice; 
   int di,dj,mi; 
   cprintf("\nEnter the worker's name to delete:"); 
   scanf("%s",del_name); 
                                 
   /*调用search函数,搜索到就返回员工的id,没有就返回-1*/ 
   if((mi=search(*i,dp,1,del_name))==-1)return; 
   cprintf("\nAre you sure to delete this profile?(y/n)\r\n"); 
   choice=getch(); 
   if(choice=='n') 
     return; 
   for(di=dj=0;di<*i;di++) 
     if(di!=mi) 
       dp[dj++]=dp[di]; 
    
   --*i; 
   cputs("\ndelete successfully!\r\n"); 
   cputs("\nPress any key to return!\r\n"); 
   getch(); 
  } 
 
 
 /*将内存中的资料保存一遍*/ 
void save(int i,struct WORKER *sp) 
  { 
   int si; 
   fp=fopen("worker_file.txt","w"); 
   /*错误处理*/ 
   if(!fp) 
     { 
      cprintf("\nfail to save!\r\n\nMaybe the database file named worker_file.txt cannot be opened!Please check this file,it cannot be reak only!\r\n"); 
      return; 
     } 
   /*保存操作的循环*/ 
   for(si=0;si0) 
           { 
            sorttemp=sortp[sorti]; 
            sortp[sorti]=sortp[sortj]; 
            sortp[sortj]=sorttemp; 
           } 
        } 
     } 
   /*排序完成后提示是否再次查看列表*/ 
   cprintf("\nSort successfully!Do you want to list all  the profiles?(y/n)\r\n"); 
   schoice=getch(); 
   if(schoice=='y') 
     list(i,sortp); 
  } 
/*将数据库全部清空*/ 
void cleardb(int *i,struct WORKER *clrp) 
  { 
   char clrc; 
   cprintf("Are you sure to clear all the profiles?it will delete all the data(y/n)\r\n"); 
   clrc=getch(); 
   if(clrc=='n') return; 
   /*以只写模式打开文件,指针指向文件的头部,将文件内数据全部清空*/ 
   fp=fopen("worker_file.txt","w"); 
   fclose(fp); 
   data_load(i,clrp); 
   cprintf("\nClear successfully!\r\n"); 
   cprintf("\nPress any key to continue!\r\n"); 
   getch(); 
  } 
 
 
/*菜单*/ 
void menu(void) 
  { 
   cprintf("\n\n\n          <<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>\r\n"); 
       cprintf("\n        []============================MENU============================[]\r\n"); 
         cprintf("        []                                                            []\r\n"); 
         cprintf("        []        1.Add                                               []\r\n"); 
         cprintf("        []          2.Delete                                          []\r\n"); 
         cprintf("        []            3.Search                                        []\r\n"); 
         cprintf("        []              4.modify                                      []\r\n"); 
         cprintf("        []                5.Sort                                      []\r\n"); 
         cprintf("        []                  6.List all                                []\r\n"); 
         cprintf("        []                    7.Save data                             []\r\n"); 
         cprintf("        []                      8.Reload data                         []\r\n"); 
         cprintf("        []                        9.Delete all data                   []\r\n"); 
         cprintf("        []                          0.exit without save               []\r\n"); 
         cprintf("        []        10.modify  the  password                            []\r\n"); 
         cprintf("        []============================================================[]\r\n"); 
  } 
 
 
/*系统密码:abc*/ 
int password(struct SECRET *map) 
                { 
                 int j=0,count=0; 
                 char c,aa[20]; 
                 clrscr(); 
 
                 textcolor(2); /*字体颜色*/ 
            Loop: 
                 gotoxy(25,12); 
                 cprintf("Input your password:"); 
                 while((c=getch())!=13) /*不等与回车时,继续*/ 
                   { 
                    aa[j++]=c; 
                    gotoxy(45+j,12); 
                    cprintf("*"); 
                    if(j>20) 
                    break; 
                   } 
                 aa[j]=0; 
		 if(strcmp(aa,map[0].mima)==0) 
                   {clrscr(); 
                    gotoxy(25,11); 
                    cprintf("Your password input right!!!"); 
                    gotoxy(25,13); 
                    cprintf("Welcome to using this system!"); 
                    gotoxy(25,15); 
                    cprintf("Press any key into the system!"); 
                    getch(); 
                    } 
                  else 
                    { j=0; 
                      count++; 
                      gotoxy(25,13); 
                      cprintf("Your password input error!!!"); 
                       { 
                        gotoxy(25,14); 
                        if(count>3) 
                          { 
                           cprintf("You put the wrong number too many times"); 
                           gotoxy(25,15); 
                           cprintf("You can't into this system!!! Goodbye!"); 
                           delay(1000000); 
                           getch(); 
                           exit(0); 
                           } 
                         delay(10000000000); 
                         clrscr(); 
                         goto Loop; 
                        } 
                      } 
                     } 
 
int modify_password(struct SECRET *map) 
      { 
	int j,k; 
	char s; 
              do 
                  {j=0; 
                   clrscr(); 
                   gotoxy(25,12); 
                   cprintf("Input your New password:"); 
                   while((s=getch())!=13) /*不等与回车时,继续*/ 
                        { 
			 map[0].mima[j++]=s; 
                         gotoxy(48+j,12); 
                         cprintf("*"); 
                         if(j>20) 
                           {gotoxy(25,13); 
                            cprintf("Input error!cannot over 8 character or less than 0 character!"); 
                            gotoxy(25,14); 
			    cprintf("Input again!"); 
                            getch(); 
                            k=1; 
                           } 
                         } 
		  map[0].mima[j]=0; 
                  clrscr(); 
                 }while(k==1); 
      } 
 
/*主函数*/ 
void main(void) 
  { 
   struct WORKER profile[maxworker]; 
   struct SECRET pasd[1]; 
   
   int selection; 
   char c,s; 
   int i=0; 
   window(1, 1, 80,25); 
   textbackground(1); 
   textcolor(2); 
   d_load(pasd); 
   /*pasd[0].mima[20]="abc";*/ 
   /*cprintf("%s",pasd[0].mima);*/ 
      /*getch();*/ 
   /*if(strcmp(pasd[0].mima,"abc")==0)*/ 
      /*{*/ 
      /*modify_password(pasd);*/ 
      /*sav_passwod(pasd);*/ 
     /*}*/  
   /*else*/ 
       password(pasd); 
   clrscr(); 
   data_load(&i,profile); 
 
   do 
     { 
      menu(); 
      cprintf("\n         **********There is(are) %d person(s) in the profile!**********\r\n",i); 
      cprintf("\n                   Please input selection number:"); 
      scanf("%d",&selection); 
      clrscr(); 
      switch(selection) 
        { 
         case 1:add(&i,profile); 
                clrscr(); 
                break; 
         case 2:del(&i,profile); 
                clrscr(); 
                break; 
         case 3:search(i,profile,1,""); 
                clrscr(); 
                break; 
         case 4:modify(i,profile); 
                clrscr(); 
                break; 
         case 5:my_sort(i,profile); 
                clrscr(); 
                break; 
         case 6:list(i,profile); 
                clrscr(); 
                break; 
         case 7:save(i,profile); 
                 
                clrscr(); 
                break; 
         case 8:data_load(&i,profile); 
                gotoxy(3,12); 
                cputs("Reload data successful!Press any key to return!"); 
                getch(); 
                clrscr(); 
                break; 
         case 9:cleardb(&i,profile); 
                clrscr(); 
                break; 
	 case 10:modify_password(pasd); 
                 sav_passwod(pasd); 
                 clrscr(); 
                 break; 
         case 0:gotoxy(3,12); 
                cprintf("Are you sure to exit without save?New data that you enter will be lost!(y/n)"); 
		c=getch(); 
                if(c=='y') 
                exit(0); 
                break; 
         default:cprintf("please enter the correct selection!\r\n"); 
                 cprintf("\nPress any key to continue!\r\n"); 
                 getch(); 
                 clrscr(); 
        } 
      }while(1); 
  }