#include "adminloginmange.h"
#include "ui_adminloginmange.h"
#include <QDebug>
#include <QSqlDatabase>
#include <QMessageBox>
#include <QSqlError>
#include<QSqlQuery>
#define StyleBtn "QLabel{ text-align:center; min-width:200px; min-height:100px;} QPushButton{ width:80px; height:50px;background-color:#0088C1; color:white; border-radius:7px; font-size:18px; font-family:'lucida grande'; font-weight:bold; } QPushButton::hover{background-color:#00FFFF; color:red;}"
AdminLoginMange::AdminLoginMange(QWidget *parent) :
QWidget(parent),
ui(new Ui::AdminLoginMange)
{
ui->setupUi(this);
//连接学生数据库
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("127.0.0.1");//数据库服务器ip
db.setUserName("root");//数据库用户名
db.setPassword("123");//数据库密码
db.setDatabaseName("mystumanger");//使用哪个数据库
if( !db.open() )
{
QMessageBox::warning(this,"错误",db.lastError().text() );//打开失败,显示错误信息
return;
}
}
AdminLoginMange::~AdminLoginMange()
{
delete ui;
}
void AdminLoginMange::exec_sql(QString sql, QString mess)
{
QSqlQuery query;
bool ok = query.exec(sql);
if( ok )
{
QMessageBox *box = new QMessageBox(QMessageBox::Information,"恭喜您",QString("%1成功^_^!").arg(mess) );
box->setStyleSheet(StyleBtn);
box->exec();
}
else
{
QMessageBox *box = new QMessageBox(QMessageBox::Warning,"真是遗憾呢",QString("%1失败O_O").arg(mess) );
box->setStyleSheet(StyleBtn);
box->exec();
}
}
void AdminLoginMange::on_Btninsert_clicked()//插入
{
int id = ui->Lineid->text().toInt();
int score = ui->Linescore->text().toInt();
int age = ui->Lineage->text().toInt();
QString name = ui->Linename->text();
QString sex = ui->Linesex->text();
QString qq = ui->Lineqq->text();
QString sql = QString("insert into studentlogin(id,name,age,sex,qq,score) values('%1','%2','%3','%4','%5','%6')").arg(id).arg(name).arg(age).arg(sex).arg(qq).arg(score);
exec_sql(sql,"插入");
}
void AdminLoginMange::on_pushButton_clicked()//查找
{
int id = ui->LineFindId->text().toInt();
QSqlQuery query;
QString in = QString("select id,name,sex,score,qq,age from studentlogin where id='%1'").arg(id);
query.exec(in);
if( query.next() )//找到了这个学号
{
ui->Lineid->setText(query.value("id").toString() );
ui->Linename->setText( query.value("name").toString() );
ui->Lineage->setText(query.value("age").toString() );
ui->Lineqq->setText(query.value("qq").toString() );
ui->Linescore->setText(query.value("score").toString() );
ui->Linesex->setText(query.value("sex").toString() );
}
else
{
QMessageBox *box = new QMessageBox(QMessageBox::Warning,"真是遗憾呢","并没有这个人O_O~");
box->setStyleSheet(StyleBtn);
box->exec();
}
}
void AdminLoginMange::on_Btnupdate_clicked()//更新
{
int id = ui->Lineid->text().toInt();
int score = ui->Linescore->text().toInt();
int age = ui->Lineage->text().toInt();
QString name = ui->Linename->text();
QString sex = ui->Linesex->text();
QString qq = ui->Lineqq->text();
QString sql = QString("update studentlogin set name='%1',age='%2',sex='%3',qq='%4',score='%5' where id='%6'").arg(name).arg(age).arg(sex).arg(qq).arg(score).arg(id);
exec_sql(sql,"更新");
}
void AdminLoginMange::on_Btndel_clicked()
{
int id = ui->Lineid->text().toInt();
QString sql = QString("delete from studentlogin where id='%1'").arg(id);
exec_sql(sql,"删除");
}
void AdminLoginMange::on_Btnback_clicked()
{
emit AdminLoginMange_close();
this->close();
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 1、该资源内项目代码都是经过测试运行成功,功能正常的情况下才上传的,请放心下载使用。 2、适用人群:主要针对计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、数学、电子信息等)的同学或企业员工下载使用,具有较高的学习借鉴价值。 3、不仅适合小白学习实战练习,也可作为大作业、课程设计、毕设项目、初期项目立项演示等,欢迎下载,互相学习,共同进步!
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 19 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
龙年行大运
- 粉丝: 1009
- 资源: 3847
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)