Ejemplo n.º 1
0
/**
 * return 108;//管理员更新成功
 * return 109;//管理员更新失败
 */
int AdminService::updateAdmin(Admin admin){

	string sql = "update admin set a_name='"+ admin.getName() + "',a_psd='" + admin.getPsd() + "',a_priority='"+ admin.getPriority() +"' where u_id='"+admin.getId()+"'";
cout<<"AdminService::updateAdmin ---- update sql="<<sql<<endl;
	DBConn db;
	if(db.Execute_mysql(sql)==0){
		db.Close_mysql();
		return 108;
	}else{

		db.Close_mysql();
		return 109;
	}
}
Ejemplo n.º 2
0
/**
 * return 103;//管理员添加成功
 * return 104;//管理员添加失败
 * return 105;//管理员添加失败:ID重复
 */
int AdminService::addAdmin(Admin admin){
	string sql="insert into admin(a_id,a_name,a_psd,a_priority)values('"+admin.getId()+"','"
			+admin.getName()+"','"+admin.getPsd()+"','"+admin.getPriority()+"')";
	string sql1="update admin set a_loginState='0' where a_id='"+admin.getId()+"'";
cout<<"insert admin sql:"<<sql<<endl;
	int tmp = this->SelectAdminExist(admin.getId());
	if(tmp==0){
		DBConn db;
		if(db.Execute_mysql(sql)==0){
			db.Execute_mysql(sql1);           //添加成功一个admin,默认登录状况为未登录把loginState设置为“0”
			db.Close_mysql();
			return 103;      //添加成功
		}
		db.Close_mysql();
		return 104;         //添加失败
	}else{
		return 105;         //添加失败:ID重复
	}
}
Ejemplo n.º 3
0
void* Job::WorkThread(void* connect_fd){
	int conn_fd = *(int*) connect_fd;
	char buff[4096],utf8buff[4096];
	int n = recv(conn_fd, buff, 4096, 0);
	buff[n] = '\0';
	Utils util;
	util.gb2312toutf8(buff, n, utf8buff, 4096);
	printf("recv msg from client: %s\n", utf8buff);
	string receive(utf8buff);
	Json::Reader reader;
	Json::Value value;
	int object;
	if (reader.parse(receive, value)) {
		object = value["m_object"].asInt();
	}
	switch(object)
	{
	case 0:{
		Facility fac;
		FacilityService fs;
		fac=fs.GetParasFRomJson(receive);
		if(fac.getOp()==SELECT_ALL_FACILITY){
			string res=fs.SelectAll();
			send(conn_fd, res.c_str(), (unsigned int) strlen(res.c_str()), 0);
		}else if(fac.getOp()==SELECT_SINGLE_FACILITY){
			string res=fs.SelectSignle(fac.getFacilityId());
			send(conn_fd, res.c_str(), (unsigned int) strlen(res.c_str()), 0);
		}else if(fac.getOp()==ADD_FACILITY){
			int res=fs.Add(fac);
			char buff[20];memset(buff,0,20);
			sprintf(buff,"%d",res);
			send(conn_fd, buff, 26, 0);
		}else if(fac.getOp()==DELETE_FACILITY){
			int res=fs.DeleteSignle(fac.getFacilityId());
			char buff[20];memset(buff,0,20);
			sprintf(buff,"%d",res);
			send(conn_fd, buff, 26, 0);
		}else if(fac.getOp()==UPDATE_FACILITY){
			int res=fs.Update(fac);
			char buff[20];memset(buff,0,20);
			sprintf(buff,"%d",res);
			send(conn_fd, buff, 26, 0);
		}else if(fac.getOp()==UPDATE_FACILITY_FOR_ROOM){
			int res=fs.UpdateForRoom(fac.getFacilityId(),fac.getMeetroomId());
			char buff[20];memset(buff,0,20);
			sprintf(buff,"%d",res);
			send(conn_fd, buff, 26, 0);
		}
	}
	break;
	case 1:
	{
		User user;
		UserService us;
		user=us.GetParasFRomJson(receive);
		if(user.getOp()==SELECT_ALL_USER){
			string res=us.SelectAll();
			send(conn_fd, res.c_str(), (unsigned int) strlen(res.c_str()), 0);
		}else if(user.getOp()==SELECT_SINGLE_USER){
			string res=us.SelectSignle(user.getId());
			send(conn_fd, res.c_str(), (unsigned int) strlen(res.c_str()), 0);
		}else if(user.getOp()==UPDATE_USER){
			int res=us.Update(user);
			char buff[20];memset(buff,0,20);
			sprintf(buff,"%d",res);
			send(conn_fd,buff, 26, 0);
		}else if(user.getOp()==DELETE_USER){
			int res=us.DeleteSignle(user.getId());
			char buff[20];memset(buff,0,20);
			sprintf(buff,"%d",res);
			send(conn_fd, buff, 26, 0);
		}else if(user.getOp()==ADD_USER){
			int res=us.Add(user);
			char buff[20];memset(buff,0,20);
			sprintf(buff,"%d",res);
			send(conn_fd, buff, 26, 0);
		}
	}
		break;

	case 2:
	{
		AdminService as;
		Admin admin;
		admin=as.GetParasFRomJson(receive);
		if(admin.getOp()==LOGIN){
			char buff[20];memset(buff,0,20);
			int res=as.LoginSys(admin.getId(),admin.getPsd());
			sprintf(buff,"%d",res);
			send(conn_fd, buff, 26, 0);//重复
		}
	}
		break;

	case 3:{
		MeetroomService mrs;
		Meetroom mr;
		mr=mrs.GetParasFRomJson(receive);
		if(mr.getOp()==SELECT_ALL_MEETROOM){
			string res=mrs.SelectAll();
			send(conn_fd, res.c_str(), (unsigned int) strlen(res.c_str()), 0);
		}else if(mr.getOp()==ADD_MEETROOM){
			char buff[20];memset(buff,0,20);
			int res=mrs.Add(mr);sprintf(buff,"%d",res);
			send(conn_fd, buff, 26, 0);
		}else if(mr.getOp()==UPDATE_MEETROOM){
			char buff[20];memset(buff,0,20);
			int res=mrs.Update(mr);sprintf(buff,"%d",res);
			send(conn_fd, buff, 26, 0);
		}else if(mr.getOp()==DELETE_MEETROOM){
			char buff[20];memset(buff,0,20);
			int res=mrs.DeleteSignle(mr.getMeetroomId());sprintf(buff,"%d",res);
			send(conn_fd, buff, 26, 0);
		}else if(mr.getOp()==SELECT_SINGLE_MEETROOM){
			string res=mrs.SelectSignle(mr.getMeetroomId());
			send(conn_fd, res.c_str(), (unsigned int) strlen(res.c_str()), 0);
		}
	}
	break;
}
}
Ejemplo n.º 4
0
int AdminService::AddAdmin(Admin admin){
	string sql="insert into admin(a_id,a_name,a_psd,a_priority)values('"+admin.getId()+"','"+admin.getName()+"','"+admin.getPsd()+"','"+admin.getPriority()+"')";
}
Ejemplo n.º 5
0
void* Job::WorkThread(void* connect_fd){
	cout << "connect..." << endl;
	int conn_fd = *(int*) connect_fd;
	char buff[4096],utf8buff[4096];
	int n = recv(conn_fd, buff, 4096, 0);
	buff[n] = '\0';
	printf("recv msg from client: %s\n", buff);
	Utils util;
	util.gb2312toutf8(buff, n, utf8buff, 4096);
	printf("recv msg from client: %s\n", utf8buff);
	string receive(utf8buff);
	Json::Reader reader;
	Json::Value value;

	int object;
	if (reader.parse(receive, value)) {
		object = value["m_object"].asInt();
		cout<<"object="<<object<<endl;
	}

	switch(object)
	{
		case 0:{
			Facility fac;
			FacilityService fs;
			fac=fs.GetParasFRomJson(receive);
			if(fac.getOp()=="selectFacility"){
				string res=fs.SelectAll();
				send(conn_fd, res.c_str(), (unsigned int) strlen(res.c_str()), 0);
				cout<<"the selectFacility res is :"<<res<<endl;
			}else if(fac.getOp()=="selectSFacility"){
				string res=fs.SelectSignle(fac.getFacilityId());
				send(conn_fd, res.c_str(), (unsigned int) strlen(res.c_str()), 0);
					cout<<"the  selectSFacility res is :"<<res<<endl;
			}else if(fac.getOp()=="addFacility"){
				int res=fs.Add(fac);
				char buff[20];
				memset(buff,0,20);
				sprintf(buff,"%d",res);
				send(conn_fd, buff, 26, 0);
				cout<<"the  addFacility res is :"<<res<<endl;
			}else if(fac.getOp()=="deleteFacility"){
				int res=fs.DeleteSignle(fac.getFacilityId());
			}
		}
		break;
		case 1:
		{
			User user;
			UserService us;
			user=us.GetParasFRomJson(receive);
			if(user.getOp()==SELECT_ALL_USER){
				string res=us.SelectAll();
	cout<<"i'm in the Job res="<<res<<endl;
				send(conn_fd, res.c_str(), (unsigned int) strlen(res.c_str()), 0);
			}else if(user.getOp()==SELECT_SINGLE_USER){
				string res=us.SelectSignle(user.getId());
				send(conn_fd, res.c_str(), (unsigned int) strlen(res.c_str()), 0);
			}else if(user.getOp()==UPDATE_USER){
				if(us.Update(user)==0){
					send(conn_fd, "300", 26, 0);
				}else{
					send(conn_fd, "301", 26, 0);
				}
			}else if(user.getOp()==DELETE_USER){
				int res=us.DeleteSignle(user.getId());
				char buff[20];
				memset(buff,0,20);
				sprintf(buff,"%d",res);
				send(conn_fd, buff, 26, 0);
			}else if(user.getOp()==ADD_USER){
				int res=us.Add(user);
				char buff[20];
				memset(buff,0,20);
				sprintf(buff,"%d",res);
				send(conn_fd, buff, 26, 0);
			}
		}
			break;
        /*
         * 超级管理员:权限为1
         *
         */
		case 2:
		{
			AdminService as;
			Admin admin;
			string loginId;
			admin=as.GetParasFRomJson(receive);
			loginId =admin.getLoginId();  //拿到目前登录状态的管理员的id
			string info= "对不起,您不是超级管理员,没有权限!";

			if(admin.getOp()==LOGIN){
cout<<"i'm in the login, admin_id = "<<admin.getOp()<<endl;
				   char buff[20];
				   memset(buff,0,20);
				   int res = as.LoginSys(admin.getId(),admin.getPsd());
				   sprintf(buff,"%d",res);
				   send(conn_fd, buff,strlen(buff), 0);//重复
			}else if(admin.getOp()==ADD_ADMIN){
				if(loginId=="0001"){            //检查是否是超级管理员
					char buff[20];
					memset(buff,0,20);
					int res = as.addAdmin(admin);
					sprintf(buff,"%d",res);
					send(conn_fd,buff,strlen(buff), 0);
				}else{
					send(conn_fd,info.c_str(),strlen(info.c_str()),0);
				}

			}else if(admin.getOp()==DELETE_SINGLE_ADMIN){
				if(loginId=="0001"){            //检查是否是超级管理员
					char buff[20];
					memset(buff,0,20);
					int res = as.deleteSingleAdmin(admin.getId());
					sprintf(buff,"%d",res);
					send(conn_fd,buff,strlen(buff), 0);
				}else{
					send(conn_fd,info.c_str(),strlen(info.c_str()),0);
				}

			}else if(admin.getOp()==DELETE_ALL_ADMIN){
				if(loginId=="0001"){            //检查是否是超级管理员
					char buff[20];
					memset(buff,0,20);
					int res = as.deleteAllAdmin();
					sprintf(buff,"%d",res);
					send(conn_fd,buff,strlen(buff), 0);
				}else{
					send(conn_fd,info.c_str(),strlen(info.c_str()),0);
				}
			}else if(admin.getOp()==UPDATE_ADMIN){
				if(loginId=="0001"){            //检查是否是超级管理员
				char buff[20];
				memset(buff,0,20);
				int res = as.updateAdmin(admin);
				sprintf(buff,"%d",res);
				send(conn_fd,buff,strlen(buff), 0);
				}else{
					send(conn_fd,info.c_str(),strlen(info.c_str()),0);
				}

			}else if(admin.getOp()==SELECT_ALL_ADMIN){
				if(loginId=="0001"){            //检查是否是超级管理员
					string res = as.selectAllAdmin();
	cout<<"i'm in the Job admin ,res="<<res<<endl;
					send(conn_fd,res.c_str(),(unsigned int)strlen(res.c_str()),0);
				}else{
					send(conn_fd,info.c_str(),strlen(info.c_str()),0);
				}
			}else if(admin.getOp()==SELECT_SINGLE_ADMIN){
				if(loginId=="0001"){            //检查是否是超级管理员
					string res = as.selectSingleAdmin(admin.getId());
					send(conn_fd,res.c_str(),(unsigned int)strlen(res.c_str()),0);
				}else{
					send(conn_fd,info.c_str(),strlen(info.c_str()),0);
				}
			}
		}
		break;
	}
}