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

📄 function.h

📁 一个典型的小区消息管理系统
💻 H
📖 第 1 页 / 共 2 页
字号:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int display(User_Group *head)//显示所有用户函数

{ 
	int k=1;
    User_Group *gp=head->glink;
    User_Item *up;
	printf("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
    while(gp)
    {
      printf("【%d】用户组%s:",k++,gp->group_name);
      up=gp->ulink;
       while(up)
	   {
          printf("用户%s\t",up->user_name);
          up=up->next;
	   }
	   if(!up)
		printf("\n");
	  gp=gp->glink;
    }
	printf("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
  return 1;
} 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int build_i_dir(char *dir_i, char *filename)//创建文件路径函数
{
	char dir[128];
	FILE *fp;

	strcpy(dir, "md ");
	strcat(dir, dir_i);
	system(dir);

	if (!(NULL == filename))
	{
		strcpy(dir, dir_i);
		strcat(dir, "\\");
		strcat(dir, filename);
		fp = fopen(dir, "wb");
		fclose(fp);
	}

	return 1;
} 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int message(char *head, char *body, char *deal)//屏幕信息函数
{
	char msg[MAX_MSG_LEN];
    strcpy(msg, "");
	strcat(msg, head);
	strcat(msg, body);
    printf("%s\n", msg);
        if (deal == NULL)
	{
		return 1;		// 如果没有操作直接返回
	}
	// 根据参数执行后续操作
	if (!strcmp(WC, deal))
	{
		WAIT;
		CLS;
	}
	else if (!strcmp(W, deal))
	{
		WAIT;
	}
	else if (!strcmp(C, deal))
	{
		CLS;
	}
	
	return 1;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
char text_menu(char item[][MAX_MENU_LEN], int start, int end)//屏幕显示函数
{
	int i, t;
	char choice;

	do {
		//CLS;
	
	    printf("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
		for (i = start; i <= end; i++)
		{
			t = i + 1;
			printf("【%d】%s	\n", t, item[i]);
		}
		printf("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");

		printf("【提示】请作出一个选择:");
		choice = getch();
		putchar('\n');
		choice -= '1';			// 转换为便于判断的整数类型
	} while ((choice < start) || (choice > end));

	return choice + '1';		// 仍然返回字符
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int  admin_login(admin *administor)//管理员登陆函数
{     
	  CLS;
	  char admn[MAX_MENU_LEN ],admc[MAX_MENU_LEN ];
      message(INFO,"请输入管理员帐号",NULL);
	  gets( admn);
	  message(INFO,"请输入管理员密码",NULL);
	  gets( admc);
	  if(strcmp(administor->admin_name,admn)==0&&strcmp(administor->admin_code,admc)==0)
		   return 1;
	  else return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int create_i_dir(char *finalpath, char *dir_i, char *filename)//生成文件函数
{
	strcpy(finalpath, "");
	strcat(finalpath, dir_i);
	strcat(finalpath, "\\");
	strcat(finalpath, filename);

	return 1;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int save_group_info(User_Group  *system_info_pt)//保存用户组资料函数
{
	FILE *fp;
	char filepath[MAX_MENU_LEN];
	
	// 取得文件路径
	create_i_dir(filepath, "usergroup","ghhg");
      fp = fopen(filepath, "ab+");		// 随机读写使用rb方式打开文件
	fwrite(system_info_pt, sizeof(User_Group), 1, fp);
	fclose(fp);

	return 1;
} 


///////////////////////////////////////////////////////////////////////////////////////////////////////////////
int save_system_info(admin *system_info_pt)//保存系统信息函数
{
	FILE *fp;
	char filepath[MAX_MENU_LEN];
	
	// 取得文件路径
	create_i_dir(filepath, "cd","cd");
      fp = fopen(filepath, "wb");		// 随机读写使用 rb+ 方式打开文件
	fwrite(system_info_pt, sizeof(admin), 1, fp);
	fclose(fp);

	return 1;
} 
////////////////////////////////////////////////////////////////////////////////////////////////////////
int admin_code_change(admin *system_info_pt)//管理员修改密码函数
{			
	char *str=system_info_pt->admin_code;
	char str1[MAX_MENU_LEN], str2[MAX_MENU_LEN];
    message(INFO,"请输入原密码",NULL); 
	gets(str1);
    if(strcmp(str1,str)==0)
	{
	message(INFO,"请输入新密码",NULL); 
	gets(str1);
	message(INFO,"请再次输入新密码",NULL); 
	gets(str2);
     if(strcmp(str1,str2)==0)
	   {
		   strcpy(str,str2);
		   save_system_info(system_info_pt);
		   message(INFO, "修改成功",WC);
		   return 1;
	   }
     else
       {
	        message(ERROR, "两次密码输入不同,修改失败",WC);
		    return 0;
       }
				   
	
	}
    else 
	{
		message(ERROR, "密码错误请重新输入",WC);
		return -1;
	}
} 
////////////////////////////////////////////////////////////////////////////////////////////////////////
int save_user_info_a(User_Item *userpt)//用户注册信息写入函
{    FILE *fp;
     char filepath[MAX_MENU_LEN];
    
     //取得文件路径
	 build_i_dir("user",userpt->user_name);
     create_i_dir(filepath, "user",userpt->user_name);
     fp=fopen(filepath, "wb+");    // 随机读写使用 wb+ 方式打开文件
     if(!fp) {printf("can not open file\n"); return 0;}
     fwrite(userpt,sizeof(User_Item),1,fp);
     fclose(fp);
     return 1;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
int save_delete_group_info(User_Group *system_info_pt,int a)//保存删除组信息函数
{   
	int i;
	FILE *fp;
	char filepath[MAX_MENU_LEN];// 取得文件路径
	create_i_dir(filepath, "usergroup","ghhg");
      fp = fopen(filepath, "wb+");		// 随机读写使用 rb+ 方式打开文件
	
	fwrite(system_info_pt, sizeof(User_Group), 1, fp);
	fclose(fp);
	for(i=2;i<=a;i++)
	{   
		system_info_pt=system_info_pt->glink;
		create_i_dir(filepath, "usergroup","ghhg");
        fp = fopen(filepath, "ab+");	
		fwrite(system_info_pt, sizeof(User_Group), 1, fp);
		fclose(fp);
	}
    return 1;
}
///////////////////////////////////////////////////////////////////
int save_user_info_b(User_Item *userpt)//用户注册信息写入函
{    FILE *fp;
     char filepath[MAX_MENU_LEN];
     //取得文件路径
	 create_i_dir(filepath, "user",userpt->user_name);
     fp=fopen(filepath, "wb+");    // 随机读写使用 wb+ 方式打开文件
     if(!fp) {printf("can not open file\n"); return 0;}
     fwrite(userpt,sizeof(User_Item),1,fp);
     fclose(fp);
     return 1;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
int create_user(User_Group *head,admin *adpt)   //注册用户函数
//head变为指向头结点的指针,adpt为指向管理员的指针
{
      CLS;  
      User_Item *userpt,*up; 
      User_Group *p,*pt,*gp; 
      char gname[MAX_USER_LEN]; 
      int i=1,j=adpt->num;    //将管理员信息中的用户个数值传给j
      char compare_code[MAX_USER_LEN];//验证密码
      userpt=(User_Item *)malloc(sizeof(User_Item));
      p=head->glink;
      pt=head->glink;
      gp=head->glink;
      message(INFO,"请输入新用户名称:",NULL);
      scanf("%s",userpt->user_name);
      while(gp)
       {
	     up=gp->ulink;
             while(up)
                {if(!strcmp(userpt->user_name,up->user_name))
                   break;
		 up=up->next;
                 }
	     if(up)
                {
		  if(!strcmp(userpt->user_name,up->user_name))
		  break;
		}
            gp=gp->glink;
       }
	   if(!gp) 
	   {
	   message(INFO,"恭喜你,该用户名未注册,请继续注册!",NULL); 
           message(INFO,"请输入密码:",NULL);
           scanf("%s",userpt->user_code);
	   message(INFO,"请再次输入密码:",NULL);
	   scanf("%s",compare_code);
	   if(strcmp(userpt->user_code,compare_code)!=0)
	   {
		  message(ERROR,"两次密码输入不同,注册失败",WC);
	   }
	   else
	   {
	   message(INFO,"正在读取用户组信息........",W);
	   message(INFO,"已经存在的用户组:",NULL);
       while(p)                  //输出存在的用户组序列
	       {
		    printf("【%d】:用户组%s\n",i++,p->group_name);
            
            p=p->glink;
	       }
       message(INFO,"请选择用户组(输入用户组名):",NULL);
       scanf("%s",gname);
       while(--i&&pt)
	   {
		  
	       if(!(strcmp(gname,pt->group_name)))
		   {
              printf("【信息】你选择的用户组为:用户组%s\n",gname);
			  userpt->next=pt->ulink;
              pt->ulink=userpt;
			  strcpy(userpt->gname,gname);
              pt->b++;
              //save_delete_group_info(head->glink,adpt->a);
			  userpt->count=0;
			 

              message(INFO,"创建新用户成功!",WC);
			  while(1)
                 {
				     if(save_user_info_a(userpt))            //将用户信息写入文件
                        {
						 printf("用户信息保存成功!\n"); 
                         strcpy(adpt->user[j],userpt->user_name);//将注册的用户名传给管理员
						 adpt->num++;
						 save_system_info(adpt);
                         break;
                        }  
                 }
		    printf("【提示】恭喜你,你是本系统的第%d个注册用户!\n",adpt->num);
		    message(INFO,"谢谢使用,正在返回登陆菜单.......",WC);
			return 1;
		   }
	        
	      else
		  pt=pt->glink;
	   }

	   if(i==0)
	   {
	     message(ERROR,"对不起,你选择的用户组不存在,注册失败",WC);
		 
	   }
	  }
	  }
	   else
	   {
		   message(ERROR,"对不起,该用户名已存在,请重新注册。",WC);
	   }
	  return 1; 
	  }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int user_login(User_Group *head,User_Item  *temp)   //用户登陆函数
{
   CLS; 
   User_Group *gp;
   User_Item *up;
   char uname[MAX_USER_LEN],ucode[MAX_USER_LEN];
   gp=head->glink;
   message(INFO,"请输入用户名:",NULL);
   scanf("%s",uname);
   while(gp)
       {
	     up=gp->ulink;
         while(up)
             {if(!strcmp(uname,up->user_name))
                break;
		        up=up->next;
             }
		    if(up)
			{
			 if(!strcmp(uname,up->user_name))
		     break;
			}
           gp=gp->glink;
       }
   if(!gp) 
   {
	   message(ERROR,"用户名不存在,登陆失败!",WC); 
       return 0;
   }  
   
  
     message(INFO,"请输入用户密码:",NULL);
     scanf("%s",ucode);
     message(INFO,"请等待确认....",NULL);
     if(!strcmp(ucode,up->user_code)) 
	   {
           *temp=*up;
		   message(INFO,"登陆成功!",WC);  
		   return 1;
	   }  
     else 
	   {
		   message(ERROR,"密码错误!",NULL); 
		   message(INFO,"请重新输入密码",NULL);
		   scanf("%s",ucode);
		   message(INFO,"请等待确认....",NULL);
           if(!strcmp(ucode,up->user_code)) 
		   {
		   *temp=*up;
		   message(INFO,"登陆成功!",WC); 
		   
		   return 1;
		   }  
           else 
		   {
		   message(ERROR,"密码再次错误,登陆失败!",WC); 
		   return 0; 
		   }
	   }

  
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 

int load_system_settings(admin *system_info_pt)//载入系统信息函数
{
	FILE *fp;
	char filepath[MAX_MENU_LEN];
	
	

	// 生成文件路径
	create_i_dir(filepath, "cd", "cd");
    fp = fopen(filepath, "rb"); 
	fread(system_info_pt, sizeof(admin), 1, fp);
	

	fclose(fp);
	return 1;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 


//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 

int user_code_change(User_Item  *temp)//用户修改密码函数
{  
	CLS;
	char str1[MAX_USER_LEN],str2[MAX_USER_LEN],str3[MAX_USER_LEN];
    message(INFO,"请输入原密码:",NULL);
    scanf("%s",str1);
    if(!strcmp(temp->user_code,str1))
	{
		while(1)
		{
			message(INFO,"请输入新密码:",NULL);
            scanf("%s",str2);
            message(INFO,"请确认新密码:",NULL);
            scanf("%s",str3);
            if(!strcmp(str2,str3)) 
			{
				strcpy(temp->user_code,str2);
                  save_user_info_b(temp);
                message(INFO,"恭喜你,密码修改成功!",WC); 
                return 1;
			}
            else 
            message(ERROR,"两次密码输入不同,请重新输入",NULL);
		}
	}
    else 
     {
		message(ERROR,"原密码错误,修改失败!",WC);
        return 1;
     }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 


//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
int delete_user(User_Group *head,admin *adpt)//删除用户函数
{
	CLS;
	int i,j;
	User_Group *gp=head->glink;
	User_Item *up,*p;
	char uname[MAX_USER_LEN];
	User_Item ;

⌨️ 快捷键说明

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