#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <windows.h>
//结构3:用户档案
struct user{
int p_id;//人员序号
char usr[20];//用户名
char psd[10];//密码
int level;//权限级别(1-全部权限2-只能新增和查询3-只能查询)
}us[10]={{1,"admin","admin",1},{2,"kinglin","kinglin",2}},Online_User={0,"","",3};
//Oneline为在线用户,可用于权限级别等限制!!!
//第三部分:人员管理
void user_menu(struct user *show_user);
void user_add(struct user *show_user);
void user_find(struct user *show_user);
void user_update(struct user up_user);
void user_del(struct user *show_user);
//第四部分:休闲小游戏及登录程序和界面设计
void main_menu();
void game_play();
void user_login();
//另外:文件操作
void data_user_read_file(struct user *show_user);
void data_user_write_file(struct user *show_user);
void main()
{
data_user_read_file(us);
user_login();
main_menu();
}
void main_menu()
{
int select;
system("cls");
system("color f1");
printf("\n\n\t\t\t+==============================+\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 1->歌曲基本数据管理 |\n");
printf("\t\t\t| 2->歌曲点取播放 |\n");
printf("\t\t\t| 3->人员权限管理 |\n");
printf("\t\t\t| 4->休闲小游戏 |\n");
printf("\t\t\t| 5->退出系统 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t+==============================+\n");
scanf("%d",&select);
switch(select)
{
// case 1: music_menu()break;
// case 2: play_menu()break;
case 3: user_menu(us);break;
//case 4: game_play();break;
case 5: data_user_write_file(us);exit(1);break; //退出前保存数据。
default:printf("选项输入错误!请选择(1-5):");
}
}
void user_login()
{
int i,count=0;
char u_name[10];
char u_psd[10];
do{
system("cls");
system("color f1");
printf("\n");
printf("\t\t ");
for(i=1;i<=60000000;i++)
{
if (i%3000000==0)
printf("☆");
}
printf("\n\n\t\t\t 欢迎进入KTV点歌系统! \n");
printf("\t\t\t \n");
printf("\t\t\t 风花雪月 \n");
printf("\t\t\t 研发小组 \n");
printf("\t\t\t 组长:王林 \n");
printf("\n\t\t\t 艾生芳 罗泽宇 邓丰波\n");
printf("\n\t\t\t 2007/08/15\n");
printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ");
for(i=1;i<=60000000;i++)
{
if (i%3000000==0)
printf("★\b\b");
}
printf("\n");
printf("\n\t\t\t用户名:");
fflush(stdin);
gets(u_name);
printf("\n\t\t\t密 码:");
for(i=0;i<10;i++)
{
fflush(stdin);
u_psd[i]=getch();
if (int (u_psd[i])==13)
{
u_psd[i]='\0';
break;
}
else if (int (u_psd[i])==8)
{
i=i-2;
printf("\b \b");
}
else
printf("*");
}
u_psd[i]='\0';
for(i=0;i<10;i++)
{
if(strcmp(u_name,us[i].usr)==0&&us[i].p_id>0)
break;
}
if (strcmp(u_psd,us[i].psd)==0)
{
printf("\n\t\t\t\t登陆成功!\n");
Sleep(1500);
for(i=0;i<sizeof(us)/sizeof(us[0]);i++)
{
if(stricmp(us[i].usr,u_name)==0)
{//登陆成功,记录用户信息
Online_User.p_id=us[i].p_id;
sprintf(Online_User.usr,"%s",us[i].usr);
sprintf(Online_User.psd,"%s",us[i].psd);
Online_User.level=us[i].level;
break;
}
}
break;
}
else
{
count++;
if(count>=3)
printf("三次密码不正确,请稍后再试!");
else
printf("\n\t\t\t用户名或密码不正确,请重新输入!\n");
}
}while(count<3);
}
void user_menu(struct user *show_user)
{
int sign=1,select;
while(sign)
{
system("cls");
system("color b1");
printf("\n\n\t\t\t+==============================+\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 1->增加用户信息 |\n");
printf("\t\t\t| 2->删除用户信息 |\n");
printf("\t\t\t| 3->查询用户权限 |\n");
printf("\t\t\t| 4->修改用户信息 |\n");
printf("\t\t\t| 5->退出管理 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t+==============================+\n");
printf("选择操作数:");
fflush(stdin);
scanf("%d",&select);
if((Online_User.level==2&&select==2)||(Online_User.level==3&&select!=3&&select!=4&&select!=5))
select=6;
switch(select)
{
case 1: user_add(show_user);break;
case 2: user_del(show_user);break;
case 3: user_find(show_user);break;
case 4: user_update(Online_User);break;
case 5: sign=0;break;
case 6: printf("\t\t\t警告:你的权限不足,3 秒后自动返回!");Sleep(3000);break;
default:printf("选项输入错误!请选择(1-5):");
}
}
}
void user_update(struct user up_user)
{
int sign=1,select,level=1,i;;
char usr[20]="",psd[10]="";//密码
char psd_1[10]=" ";//重复密码
while(sign==1)
{
system("cls");
printf("\t\t\t===================================\n");
printf("\t\t\t++ KTV点歌系统--更新用户信息 ++\n");
printf("\t\t\t++ 1.修改密码 ++\n");
printf("\t\t\t++ 2.设置权限 ++\n");
printf("\t\t\t++ 3.更新用户库 ++\n");
printf("\t\t\t++ 4.返回上一菜单 ++\n");
printf("\t\t\t===================================\n");
fflush(stdin);
scanf("%d",&select);
if((Online_User.level==2||Online_User.level==3)&&select!=1&&select!=4)
select=5;
switch(select)
{
case 1: printf("\t\t\t 新 密 码:");
fflush(stdin);
scanf("%s",psd);
printf("\t\t\t 重复密码:");
fflush(stdin);
scanf("%s",psd_1);
if(stricmp(psd,psd_1)!=0)
{ printf("\t\t两次输入密码不一致!3秒后返回自动!\n");Sleep(3000);break;}
sprintf(up_user.psd,"%s",psd);
for(i=0;i<sizeof(us)/sizeof(us[0]);i++)
if(stricmp(us[i].usr,up_user.usr)==0&&us[i].p_id>0)
{ sprintf(us[i].psd,"%s",psd); break;}
data_user_write_file(us);
break;
case 2: printf("\t\t\t 用 户 名:");
fflush(stdin);
scanf("%s",usr);
printf("\t\t\t 设置权限:");
fflush(stdin);
scanf("%d",&level);
for(i=0;i<sizeof(us)/sizeof(us[0]);i++)
if(stricmp(us[i].usr,usr)==0&&us[i].p_id>0)
{ us[i].level=level; break;}
data_user_write_file(us);
break;
case 3: data_user_write_file(us); break;
case 4: sign=0;break;
case 5: printf("\t\t\t警告:你的权限不足,3 秒后自动返回!");Sleep(3000);break;
default:printf("选项输入错误!请选择(1-3):");
}
}
}
void user_add(struct user *show_user)
{
int i,sign=1;
char usr_cp[20],usr[20]="";//用户名 ;
char psd[10]="";//密码
char psd_1[10]=" ";//重复密码
int level;
while(sign)
{
sign=0;
system("cls");
printf("\t\t\t===================================\n");
printf("\t\t\t++ KTV点歌系统--添加用户 ++\n");
printf("\t\t\t===================================\n");
printf(" 注意: 1.根据提示,输入用户名、密码、并设置用户权限!\n");
printf(" 2.权限级别(1-全部权限2-只能新增和查询3-只能查询.\n\n");
printf("\t\t\t 用 户 名:");
fflush(stdin);
scanf("%s",usr);
printf("\t\t\t 密 码:");
fflush(stdin);
scanf("%s",psd);
printf("\t\t\t 重复密码:");
fflush(stdin);
scanf("%s",psd_1);
printf("\t\t\t 设置权限:");
fflush(stdin);
scanf("%d",&level);
for(i=0;i<sizeof(show_user[0])/sizeof(show_user);i++)
{
sprintf(usr_cp,"%s",show_user[i].usr);
if(stricmp(usr_cp,usr)==0||stricmp(usr,"*")==0)
{ sign=1; printf("\t\t输入的用户名已经存在或者为空!1 秒后自动返回!\n");Sleep(1500);break;}
}
if(stricmp(psd,psd_1)!=0&&sign==0)
{ sign=1; printf("\t\t两次输入密码不一致!3 秒后自动返回!\n");Sleep(1500);break;}
for(i=0;i<sizeof(show_user[0])/sizeof(show_user) && sign==0;i++)
{
if(show_user[i].p_id==0)
{
show_user[i].p_id=i+1;
sprintf(show_user[i].usr,"%s",usr);
sprintf(show_user[i].psd,"%s",psd);
show_user[i].level=level;
data_user_write_file(show_user);
break;
}
if(i-1==sizeof(show_user[0])/sizeof(show_user)) {printf("已达到最大用户数!");}
}
}
}
void user_find(struct user *show_user)
{
int i,sign=1;
char usr_cp[20],usr[20],ctnu='Y';
while(ctnu=='Y'||ctnu=='y')
{
system("cls");
printf("\t\t\t===================================\n");
printf("\t\t\t++ KTV点歌系统--用户信息查询 ++\n");
printf("\t\t\t===================================\n");
printf("\t\t 提示:输入*号,可查询所有用户信息!\n");
printf("\t 用 户 名:");
fflush(stdin);
scanf("%s",usr);
printf("%d",stricmp(usr,"*"));
if(stricmp(usr,"*")==0)
{
printf("\t\t\t 编号 用户名 用户权限\n");
for(i=0;i<sizeof(show_user[0])/sizeof(show_user);i++)
if(show_user[i].p_id>0)
printf("\t\t\t\t %d %s %d\n",show_user[i].p_id,show_user[i].usr,show_user[i].level);
}
for(i=0;i<sizeof(show_user[0])/sizeof(show_user) && stricmp(usr,"*")!=0;i++)
{
sprintf(usr_cp,"%s",show_user[i].usr);
if(stricmp(usr_cp,usr)==0&&show_user[i].p_id>0)
{
printf("\t\t\t 编号 用户名 用户权限\n");
printf("\t\t\t\t %d %s %d\n",show_user[i].p_id,show_user[i].usr,show_user[i].level);
break;
}
}
if(i==sizeof(show_user[0])/sizeof(show_user)&&stricmp(usr,"*")!=0)
printf("\t\t 用户不存在。\n");
printf("\n\t\t\t 继续-查询操作?(Y||N):");
fflush(stdin);
scanf("%c",&ctnu);
}
}
void user_del(struct user *show_user)
{
int i;
char usr_cp[20],usr[20],ctnu='Y';
while(ctnu=='Y'||ctnu=='y')
{
system("cls");
printf("\t\t\t===================================\n");
printf("\t\t\t++ KTV点歌系统--删除用户 ++\n");
printf("\t\t\t===================================\n");
printf("\t\t\t 用 户 名:");
fflush(stdin);
scanf("%s",usr);
for(i=0;i<sizeof(show_user[0])/sizeof(show_user);i++)
{
sprintf(usr_cp,"%s",show_user[i].usr);
if(stricmp(usr_cp,usr)==0&&stricmp(usr_cp,"admin")!=0&&show_user[i].p_id>0)
{
printf("\t\t已删除: 编号 %d 用户名 %s 用户权限 %d 的用户。\n",show_user[i].p_id,show_user[i].usr,show_user[i].level);
show_user[i].p_id=0;
sprintf(show_user[i].usr,"%s","");
data_user_write_file(show_user);
break;
}
}
if(i==sizeof(show_user[0])/sizeof(show_user)) printf("\t\t\t 用户不存在,删除失败。\n");
printf("\n\t\t 继续下一个-删除操作?(Y||N):");
fflush(stdin);
scanf("%c",&ctnu);
}
}
void data_user_read_file(struct user *show_user)
{
FILE *fp;
int i;
if((fp=fopen("user_data.dat","rb"))==NULL)
{
fp=fopen("user_data.dat","wb+");
printf("Can not open the oid_data_file,It's a new_data_file!\n");
Sleep(3000);
}
for(i=0;i<sizeof(show_user[0])/sizeof(show_user);i++)
{
fseek(fp,i*sizeof(struct user),0);
fread(&show_user[i],sizeof(struct user),1,fp);
}
fclose(fp);
}
void data_user_write_file(struct user *show_user)
{
FILE *fp;
int i;
if((fp=fopen("user_data.dat","wb"))==NULL)
{
printf("Can not open the file\n");
exit(0);
}
for(i=0;i<sizeof(show_user[0])/sizeof(show_user);i++)
{
fseek(fp,i*sizeof(struct user),0);
if(fwrite(&show_user[i],sizeof(struct user),1,fp)!=1)
printf("File write error\n");
}
fclose(fp);
}
|