基于MYSQL的球员信息管理
来源:互联网 发布:java中public的翻译 编辑:程序博客网 时间:2024/04/30 00:12
ER图
#include <iostream>#include <QSqlDatabase>#include <Qtsql>#include <string>#include <QSqlTableModel>#include <QVariant>#include <QString>#include <stdio.h>#include <QTextStream>using namespace std;class birthday{private: int year_; int month_; int day_;public: birthday(){} birthday(int x,int y,int z) { year_ = x; month_ = y; day_ = z; } int get_year() { return year_; } friend ostream &operator<<(ostream &os, const birthday &item) { os<< item.year_<<"-"<<item.month_<<"-"<<item.day_; return os; } friend istream &operator>>(istream &is, birthday &item) { is>> item.year_>> item.month_>>item.day_; return is; } QString toString()//转化为QString类型用来导入数据库 { QString s; s= year_+ '-' + month_+ '-' + day_; return s; } string toStdString() { string s; s= year_+'-'+month_+'-'+day_; cout<<s<<endl; return s; }};class League{private: QString leagueName_; QString leagueCountry;public:};class Club{private: QString clubName_; // birthday clubBith_; QString clubCountry_; //League clubOfLeague;public: Club(QString name,QString country) { clubName_ = name; clubCountry_ = country; //clubBith_ = bith; QSqlQuery q; q.exec(QObject::tr("insert into club values(0,'%1','%2')").arg(clubName_,clubCountry_)); } QString toQString() { QString s; s = clubName_ + '-' + clubCountry_ ; return s; }};class FootballPlayer{private: QString PlayerName_; QString PlayerSex_; QString PlayerBith_; QString PlayerCountry_; QString PlayerHeavyFoot_; QString PlayerHeight_; QString PlayerWeight_; QString PlayerLocation_; // Club PlayerOfClub_;public: FootballPlayer(){} FootballPlayer(QString name, QString sex,QString bith, QString country, QString foot, QString height, QString weight , QString location ) { PlayerName_ = name; PlayerSex_ = sex; PlayerBith_ = bith; PlayerCountry_ = country; PlayerHeavyFoot_ = foot; PlayerHeight_ = height; PlayerWeight_ = weight; PlayerLocation_ = location; QSqlQuery q; q.exec(QObject::tr("insert into footballplayer values(0,'%1','%2','%3','%4','%5','%6','%7','%8')").arg(name,sex,bith,country,foot,height,weight,location)); // cout<<q.exec()<<endl; // q.exec(QObject::tr("insert into footballplayer values(0,'%1','%2','%3','%4','%5','%6','%7','%8')").arg(name,sex,bith,country,foot,height,weight,location)); //cout<<PlayerName_.toStdString()<<","<<PlayerSex_.toStdString()<<","<<PlayerBith_.toStdString()<<","<<PlayerCountry_.toStdString()<<","<<PlayerHeavyFoot_.toStdString()<<","<<PlayerHeight_.toStdString()<<","<<PlayerWeight_.toStdString()<<","<<PlayerLocation_.toStdString()<<endl; // cout<<PlayerName_.toStdString()<<","<<PlayerSex_.toStdString()<<","<< // PlayerBith_.toString()<<","<<PlayerCountry_.toStdString()<<","<<PlayerHeavyFoot_.toStdString() // <<","<<PlayerHeight_.toStdString()<<","<<PlayerWeight_.toStdString()<<","<<PlayerLocation_.toStdString()<<endl; // cout<<q.exec()<<endl; } friend ostream &operator<<(ostream &os,const FootballPlayer &item ) { os<<item.PlayerName_.toStdString()<<endl<<item.PlayerSex_.toStdString() <<endl<<item.PlayerBith_.toStdString()<<endl<<item.PlayerCountry_.toStdString() <<item.PlayerHeavyFoot_.toStdString()<<endl<<item.PlayerHeight_.toStdString()<<endl <<item.PlayerWeight_.toStdString()<<endl<<item.PlayerLocation_.toStdString(); return os; }};class administrator{private: QString user_; QString password_;public: administrator(QString u,QString p) { QSqlQuery q; user_=u; password_=p; /* q.prepare("insert into administrator(user,password) values(:user,:password)"); QVariant user; QVariant password; user<<usr_; password<<password_; q.bindValue(":name",usr); q.bindValue(":password",password); // q.finish();*/ // q.prepare("insert into administrator(user,password) values(:user:password)"); // q.bindValue(":id","a1"); // q.bindValue(":password","123456"); q.exec(QObject::tr("insert into administrator values('%1','%2')").arg(user_,password_));//成功插入数据 // QSqlQuery a("insert into administrator(user,password) values('b','b')"); // cout<<"ok"<<endl; }};class PlayerOfClub{private: QString playerNo_; QString clubNo_; QString ptime_;public: PlayerOfClub(QString pno, QString cno,QString time) { playerNo_ = pno; clubNo_ = cno; ptime_=time; QSqlQuery q; // cout<<playerNo_.toStdString()<<" "<<clubNo_.toStdString()<<" "<<ptime_.toStdString()<<endl; q.exec(QObject::tr("insert into playerofclub values('%1','%2','%3')").arg(playerNo_,clubNo_,ptime_)); //q.exec(QObject::tr("insert into playerofclub values('%1','%2','%3')").arg(pno,cno,time)); }};bool connectDb(){ QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("localhost"); db.setDatabaseName("mosquito"); db.setUserName("root"); db.setPassword("sz11199634"); if(db.open()) { return true; } else return 0;}void selectPlayerAll(){ QSqlQuery q; // q.exec("insert into text values('t03','hello')"); // cout<<"get"<<endl; q.exec("select * from footballplayer"); while(q.next())//遍历表 { QString no,name,sex,bith,country,heavyfoot,height,weight,location; no = q.value(0).toString(); name = q.value(1).toString(); sex = q.value(2).toString(); bith = q.value(3).toString(); country = q.value(4).toString(); heavyfoot = q.value(5).toString(); height = q.value(6).toString(); weight = q.value(7).toString(); location = q.value(8).toString(); qDebug()<<no<<":"<<name<<":"<<sex<<":"<<bith<<":"<<country<<":"<<heavyfoot<<":"<<height<<":"<<weight<<":"<<location; }}bool selectOnOne(QString one,QString table)//按条件查询某张表{ QSqlQuery q; /* QSqlTableModel model; model.setTable(table); model.setFilter(one); model.select(); for(int i=0;i<model.rowCount();i++) { QSqlRecord record = model.record(i); QString user = record.value("user").toString(); QString password = record.value("password").toString(); std::cerr<<user<<":"<<password<<endl; }*/ q.exec(QObject::tr("select * from %1 where %2").arg(table,one)); while(q.next())//遍历表 { QString user; user = q.value(0).toString(); QString password; password = q.value(1).toString(); qDebug()<<qPrintable(user)<<":"<<password; } return true;}void selectOnPlayer(){ qDebug()<<"请输入条件"; QString s; string a; cin>>a;//输入不能带空格 s=QString::fromStdString(a); QSqlQuery q; q.exec(QObject::tr("select * from footballplayer where %1").arg(s)); while(q.next())//遍历表 { // cout<<"in"<<endl; QString no,name,sex,bith,country,heavyfoot,height,weight,location; no = q.value(0).toString(); name = q.value(1).toString(); sex = q.value(2).toString(); bith = q.value(3).toString(); country = q.value(4).toString(); heavyfoot = q.value(5).toString(); height = q.value(6).toString(); weight = q.value(7).toString(); location = q.value(8).toString(); qDebug()<<no<<":"<<name<<":"<<sex<<":"<<bith<<":"<<country<<":"<<heavyfoot<<":"<<height<<":"<<weight<<":"<<location; /* for(int i=0;i<8;i++) { QString a=q.value(i).toString(); qDebug() <<a; }*/ }}void selectOnClub(){ qDebug()<<"请输入条件"; QString s; string a; cin>>a;//输入不能带空格 s=QString::fromStdString(a); QSqlQuery q; q.exec(QObject::tr("select * from club where %1").arg(s)); while(q.next())//遍历表 { QString no,name,country; no = q.value(0).toString(); name=q.value(1).toString(); country=q.value(2).toString(); qDebug()<<no<<":"<<name<<":"<<country; }}void selectClubAll(){ QSqlQuery q; q.exec("select * from club"); while(q.next())//遍历表 { QString no,name,country; no = q.value(0).toString(); name=q.value(1).toString(); country=q.value(2).toString(); qDebug()<<no<<":"<<name<<":"<<country; }}void addPlayer(){ qDebug()<<"请输入球员姓名"; string a; cin>>a; QString name=QString::fromStdString(a); qDebug()<<"请输入球员性别"; cin>>a; QString sex=QString::fromStdString(a); qDebug()<<"请输入球员生日"; cin>>a; QString b=QString::fromStdString(a); qDebug()<<"请输入球员国家"; cin>>a; QString country=QString::fromStdString(a); qDebug()<<"请输入球员惯用脚"; cin>>a; QString foot=QString::fromStdString(a); qDebug()<<"请输入球员身高"; cin>>a; QString height=QString::fromStdString(a); qDebug()<<"请输入球员体重"; cin>>a; QString weight=QString::fromStdString(a); qDebug()<<"请输入球员位置"; cin>>a; QString location=QString::fromStdString(a); //QSqlQuery q; //q.exec(QObject::tr("insert into footballplayer values(0,'%1','%2','%3','%4','%5',%6,%7,'%8',1)").arg(name,sex,b.toString(),country,foot,height,weight,location)); //cout<<q.exec()<<endl; FootballPlayer player(name,sex,b,country,foot,height,weight,location);}void addClub(){ qDebug()<<"请输入俱乐部姓名"; string a; cin>>a; QString name=QString::fromStdString(a); qDebug()<<"请输入俱乐部国家"; cin>>a; QString country=QString::fromStdString(a); Club add(name,country);}void addPlayerOfClub(){ qDebug()<<"请输入球员ID"; string a; cin>>a; QString pid=QString::fromStdString(a); qDebug()<<"请输入俱乐部ID"; cin>>a; QString cid=QString::fromStdString(a); qDebug()<<"输入入会time"; cin>>a; QString time = QString::fromStdString(a); PlayerOfClub add(pid,cid,time);}void delPlayer(){ qDebug()<<"输入删除球员ID"; string id; cin>>id; QString qid; qid = QString::fromStdString(id); QSqlQuery q; q.exec(QObject::tr("delete from footballplayer where playerno = '%1' ").arg(qid));}void delClub(){ qDebug()<<"输入删除俱乐部ID"; string id; cin>>id; QString cid; cid = QString::fromStdString(id); QSqlQuery q; q.exec(QObject::tr("delete from club where clubno = '%1' ").arg(cid));}void mainwindows(){ qDebug()<<"1.查看所有球员"<<endl; qDebug()<<"2.查看所有俱乐部"<<endl; qDebug()<<"3.按条件查询球员"<<endl; qDebug()<<"4.按条件查询俱乐部"<<endl; qDebug()<<"5.增加球员"<<endl; qDebug()<<"6.增加俱乐部"<<endl; qDebug()<<"7.删除球员"<<endl; qDebug()<<"8.删除俱乐部"<<endl; qDebug()<<"9.增加球员所属俱乐部"<<endl; qDebug()<<"15.退出"<<endl;}void choose(){ int x; scanf("%d",&x); switch(x) { case(1):selectPlayerAll();break; case(2):selectClubAll();break; case(3):selectOnPlayer();break; case(4):selectOnClub();break; case(5):addPlayer();break; case(6):addClub();break; case(7):delPlayer();break; case(8):delClub();break; case(9):addPlayerOfClub();break; case(15):exit(1); }}int main(){ connectDb(); QSqlQuery q; // administrator a("a1","123456"); // q.exec("insert into footballplayer values(0,'guoxiaoqi','man','1900-11-11','china','left','170','120','b',1)"); // cout<<q.exec()<<endl; // FootballPlayer b("Ronaldo","man","1985-2-5","Portugal","right", "180","150","ST"); // q.exec("insert into footballplayer values(0,'Ronaldo','man','1985-2-5','Portugal','right', 185,150,'ST')"); // cout<<q.exec()<<endl; // selectOnOne("password = '123456'","administrator"); // Club c("text1","Espa?a"); // PlayerOfClub p("3","3"); //FootballPlayer m ("guoxiao","man",birthday(1909,11,11),"china","left" ,"170","120","cb"); mainwindows(); choose(); return 0;}
0 0
- 基于MYSQL的球员信息管理
- 基于JavaSwing+MySql的学生信息管理系统
- 基于链表的学生信息管理系统和基于MySQL的学生信息管理系统 -C语言
- JAVAEE案例: 基于javaweb、mysql的 学生信息管理系统
- 基于STL的学生信息管理
- 球员数量可变的
- 球员信息的操作
- 基于 appfuse 的学生信息管理系统
- 基于linux下的学生信息管理系统
- 基于链表的学生信息管理
- 基于文件的学生信息管理系统
- 基于二叉排序树的员工信息管理系统
- 基于C++的学生信息管理系统
- 基于SSH的个人信息管理系统
- 基于QT的学生信息管理系统开发
- 基于javaweb的客户信息管理系统搭建
- 基于struts2开发的学生信息管理系统
- 球员
- 203.[LeetCode]Remove Linked List Elements
- 杭电1081 最大子矩阵和
- 编辑距离 - 科普 & 记录
- 海量数据处理问题
- 数据结构实验之排序二:交换排序
- 基于MYSQL的球员信息管理
- poj 1442 Black Box
- HDU 5816 状压dp
- 获取input上传文件文件名及扩展名
- Ubuntu下wps无法输入中文 使用的是搜狗输入法
- [Coursera_Machine_learning]--Model and Cost Funtion
- Python 函数
- C++vector基础容器2.0
- 异常基础