//为会议室添加设备 成功 int FacilityService::UpdateForRoom(string id,string mr_id) { string sql = "update facility set meetroom_id = '" + mr_id + "' where facility_id = " + Utils::AddSingleQuoteMark(id); DBConn db; if (db.Execute_mysql(sql) == 0) { db.Close_mysql(); return 330; } else db.Close_mysql(); return 331; }
int MeetroomService::DeleteSignle(string mr_id){ string sql=DELETE_SINGLE_MR_SQL+Utils::AddSingleQuoteMark(mr_id); DBConn db; if(db.Execute_mysql(sql)==0){ db.Close_mysql(); return 410; }else{ db.Close_mysql(); return 411; } }
/** * return 106;//管理删除成功 * return 107;//管理员删除失败 */ int AdminService::deleteAllAdmin(){ string sql="delete from admin"; DBConn db; if(db.Execute_mysql(sql)==0){ db.Close_mysql(); return 108; }else{ db.Close_mysql(); return 109; } }
int UserService::DeleteSignle(string u_id){ string sql="delete from user where u_id="+Utils::AddSingleQuoteMark(u_id); DBConn db; if(db.Execute_mysql(sql)==0){ db.Close_mysql(); return 400; }else{ db.Close_mysql(); return 401; } }
/** * return 106;//管理删除成功 * return 107;//管理员删除失败 */ int AdminService::deleteSingleAdmin(string a_id){ string sql="delete from admin where a_id="+Utils::AddSingleQuoteMark(a_id); DBConn db; if(db.Execute_mysql(sql)==0){ db.Close_mysql(); return 106; }else{ db.Close_mysql(); return 107; } }
//删除facility成功600 失败601 int FacilityService::DeleteSignle(string id) { string sql = "delete from facility where facility_id=" + Utils::AddSingleQuoteMark(id); DBConn db; if (db.Execute_mysql(sql) == 0) { db.Close_mysql(); return 310; } else { db.Close_mysql(); return 311; } }
//更新设备成功 320 失败321 int FacilityService::Update(Facility fac) { string sql = "update facility set facility_name='" + fac.getFacilityName() + "',available_state='" + fac.getAvailableState() + "',meetroom_id='" + fac.getMeetroomId() + "',facility_ip='" + fac.getFacilityIp() + "'where facility_id="+Utils::AddSingleQuoteMark(fac.getFacilityId()); DBConn db; if (db.Execute_mysql(sql) == 0) { db.Close_mysql(); return 320; } else db.Close_mysql(); return 321; }
int MeetroomService::Update(Meetroom mr){ string sql = "update meetroom set meetroom_name='"+ mr.getMeetroomName() + "',meetroom_addr='" + mr.getMeetroomAddr() + "',available_state='"+ mr.getAvailableState() + "',meetroom_size='"+mr.getMeetroomSize()+"' where meetroom_id='"+mr.getMeetroomId()+"'"; cout<<"update sql:"<<sql<<endl; DBConn db; if(db.Execute_mysql(sql)==0){ db.Close_mysql(); return 420; }else{ db.Close_mysql(); return 421; } }
int UserService::Update(User user){ string sql = "update user set u_name='"+ user.getName() + "',u_phone='" + user.getPhone() + "',u_department='"+ user.getDepartment() + "',u_gender='"+user.getGender()+"' where u_id='"+user.getId()+"'"; cout<<"update sql:"<<sql<<endl; DBConn db; if(db.Execute_mysql(sql)==0){ db.Close_mysql(); return 0; }else{ db.Close_mysql(); return -1; } }
/** * 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; } }
string UserService::SelectSignle(string u_id){ DBConn db; string sql=SELECT_SINGLE_USER_SQL+Utils::AddSingleQuoteMark(u_id); string res=db.Query_single_mysql(sql); db.Close_mysql(); return res; }
/* 查询所有管理员*/ string AdminService::selectAllAdmin(){ DBConn db; string res = db.Query_all_mysql(SELECT_ALL_ADMIN_SQL, "Admin"); cout<<"AdminService::selectAllAdmin(), res="<<res<<endl; db.Close_mysql(); return res; }
/** *查询同一个会议室的IP是否有重 */ int FacilityService::SelectFacilityExist(string id, string ip, string mr_id) { string sql = "select facility_id from facility where facility_id=" + Utils::AddSingleQuoteMark(id); string sql1 = "select meetroom_id from facility where facility_ip=" + Utils::AddSingleQuoteMark(ip); DBConn db; string facility_id = db.Query_mysql(sql); db.Close_mysql(); if (ip.empty() || mr_id.empty()) {//用户增加一个设备仅填写ID的情况 if (facility_id.empty()) { return 300; } else { return 301; //ID已存在 } } else { if (facility_id.empty()) { DBConn db; string meetroom_id = db.Query_mysql(sql1); db.Close_mysql(); if (meetroom_id == mr_id) { return 302; //IP重复 } else { return 300; } } else { return 301; //ID已存在 } } /* string sql="select facility_id from facility where facility_id="+Utils::AddSingleQuoteMark(id); cout<<"check sql:"<<sql<<endl; string sql1="select meetroom_id from facility where facility_ip="+Utils::AddSingleQuoteMark(ip); cout<<"check sql:"<<sql1<<endl; DBConn db; string facility_id=db.Query_mysql(sql); string res_id=db.Query_mysql(sql1); db.Close_mysql(); if(facility_id.empty()){ if(res_id!=mr_id){ return 500;//同一个会议室内无重复IP,可以插入 }else{ return 501;//IP 重复 } }else{ return 502;//ID被用 }*/ }
int MeetroomService::Add(Meetroom mr){ int tmp=this->SelectMeetroomExist(mr.getMeetroomId()); if(tmp==0){ string sql=ADD_MR_SQL+ mr.getMeetroomId() + "','" +mr.getMeetroomName()+ "','" +mr.getMeetroomAddr() + "','"+mr.getAvailableState() +"','"+mr.getMeetroomSize()+ "')"; DBConn db; if(db.Execute_mysql(sql)==0){ db.Close_mysql(); return 400; //添加成功 } db.Close_mysql(); return 402;//添加失败 }else{ return 401;//ID重复 } }
string UserService::SelectAll(){ DBConn db; string res=db.Query_all_mysql(SELECT_ALL_USER_SQL,"Users"); cout<<"i'm return back from Db.query_all_sql,result="<<res<<endl; db.Close_mysql(); cout<<"i'm in the UserService SelectAll:res="<<endl; return res; }
/** * 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重复 } }
/** * return 100;//登录成功 * return 101;//登录失败 :密码错误 * return 102;//登录失败:ID不存在 */ int AdminService::LoginSys(string a_id,string a_psd){ DBConn db; string sql="select a_psd from admin where a_id="+Utils::AddSingleQuoteMark(a_id); string sql1="update admin set a_loginState='1' where a_id='"+a_id+"'"; string res=db.Query_mysql(sql); db.Close_mysql(); if(res.empty()==true){ return 102; }else if(res==a_psd){ cout<<"AdminServcie::LoginSys-------- i'm before db.Execute_mysql"<<endl; DBConn db; db.Execute_mysql(sql1); //如果登录成功,就把loginState设为“1” cout<<"AdminServcie::LoginSys-------- i'm after db.Execute_mysql"<<endl; db.Close_mysql(); return 100; }else{ return 101; } }
/*按id查询单个管理员*/ string AdminService::selectSingleAdmin(string a_id){ cout<<"AdminService::slelectSingleAdmin ---------i'm here"<<endl; DBConn db; string sql = SELECT_SINGLE_ADMIN_SQL+Utils::AddSingleQuoteMark(a_id); cout<<"select single sql= "<<sql<<endl; string res = db.Query_single_mysql(sql); cout<<"AdminService::selectSingleAdmin(), res="<<res<<endl; db.Close_mysql(); return res; }
int UserService::Add(User user){ int tmp=this->SelectUserExist(user.getId()); if(tmp==0){ string sql="insert into user(u_id,u_name,u_department,u_phone,u_gender)values('"+ user.getId() + "','" +user.getName()+ "','" + user.getDepartment() + "','"+user.getPhone() +"','"+user.getGender()+ "')"; DBConn db; if(db.Execute_mysql(sql)==0){ db.Close_mysql(); return 200; //添加成功 } db.Close_mysql(); return 201;//添加失败 }else{ return 202;//添加失败:ID重复 } }
int FacilityService::Add(Facility fac) { string sql = "insert into facility(facility_id,facility_name,available_state,meetroom_id,facility_ip)values('" + fac.getFacilityId() + "','" + fac.getFacilityName() + "','" + fac.getAvailableState() + "','" + fac.getMeetroomId() + "','" + fac.getFacilityIp() + "')"; int check = this->SelectFacilityExist(fac.getFacilityId(),fac.getFacilityIp(), fac.getMeetroomId()); DBConn db; if (check == 300) { db.Execute_mysql(sql); db.Close_mysql(); return 300; } else if (check == 301) { db.Close_mysql(); return 301; } else { db.Close_mysql(); return 302; } }
int FacilityService::SelectFacilityExist(string id, string ip) { string sql = "select facility_name from facility where facility_id=" + Utils::AddSingleQuoteMark(id); string sql1 = "select facility_id from facility where facility_ip=" + Utils::AddSingleQuoteMark(ip); DBConn db; string res_name = db.Query_mysql(sql); string res_id = db.Query_mysql(sql1); db.Close_mysql(); if (res_id.empty()) { //查看该IP是否被占用 if (res_name.empty()) { //查看该ID是否存在 return 300; //可以添加 } else { return 302; //该ID已存在 } } else { return 301; //IP被占用 } }
/** * @params id table * @return eg: a user's all parameters of the Json format */ string MeetroomService::SelectSignle(string mr_id){ DBConn db; string res=db.Query_single_mr_sql(mr_id); db.Close_mysql(); return res; }
string MeetroomService::SelectAll(){ DBConn db; string res=db.Query_all_mysql(SELECT_ALL_MR_SQL,"Meetroom"); db.Close_mysql(); return res; }