#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QMessageBox>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget) //构造函数
{
ui->setupUi(this);
mainform =new mainForm;
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_Log_resgister_clicked()
{
ui->stackedWidget->setCurrentIndex(1);
}
void Widget::on_reg_login_clicked()
{
ui->stackedWidget->setCurrentIndex(0);
}
void Widget::on_register_2_clicked()
{
QString str1;
//1.create connection
QSqlDatabase db= QSqlDatabase::addDatabase("QSQLITE");
//2.set db name
db.setDatabaseName("mydb");
//3.open.dbs
bool ok =db.open();
if(!ok)
{
qDebug("open error\n");
}
else
{
qDebug("open success\n");
}
//4.operator db
QSqlQuery query;
query.exec("create table std2(id integer primary key,name text,sco text)");
str1.sprintf("insert into std2 values(null,'%s','%s')",ui->reg_id->text().toStdString().data(),ui->reg_pwd->text().toStdString().data());
// str1=ui->reg_id->text().toStdString().data();
//str2=ui->reg_pwd->text().toStdString().data();
// query.prepare("INSERT INTO std2(id,name,sco)"
// "VALUES:id,:name,:sco");
// query.bindValue(":id",1001);
//query.bindValue(":name",str1);
//query.bindValue("sco",str2);
if(ui->reg_id->text().isEmpty()||ui->reg_pwd->text().isEmpty()) //判断输入的是否为空
{
QMessageBox msgBox;
msgBox.setText("Register failed !! Please input id or pwd!!");
msgBox.exec();
}
else
{
if(ui->reg_pwd->text()!=ui->reg_ensurepwd->text())
{
QMessageBox msgBox;
msgBox.setText("Register failed !! Please input pwd again!!");
msgBox.exec();
}
else
{
if(query.exec(str1))
{
QMessageBox msgBox;
msgBox.setText("Register success!!");
msgBox.exec();
ui->reg_id->clear();
ui->reg_pwd->clear();
ui->reg_ensurepwd->clear();
}
else
{
QMessageBox msgBox;
msgBox.setText("Register failed!!");
msgBox.exec();
}
}
}
//5.close.db
db.close();
}
void Widget::on_login_clicked()
{ /*
QSqlDatabase db= QSqlDatabase::addDatabase("QSQLITE");
//2.set db name
db.setDatabaseName("mydb");
//3.open.db
bool ok =db.open();
if(!ok)
{
qDebug("open error\n");
}
else
{
qDebug("open success\n");
}
QString sql;
sql.sprintf("SELECT name FROM std2 where name=%s",ui->Log_id->text().toStdString().data());
query.exec(sql);
QSqlQuery query(sql);
while (query.next()) { //显示查询结果,相当于回调函数
QString name= query.value(0).toString();
qDebug()<<"name:"<<name;
this->hide();
main->show();
}*/
QString str;
QSqlDatabase db= QSqlDatabase::addDatabase("QSQLITE");
//2.set db name
db.setDatabaseName("mydb");
//3.open.db
bool ok =db.open();
if(!ok)
{
qDebug("open error\n");
}
else
{
qDebug("open success\n");
}
QSqlQuery query;
str.sprintf("select * from std2 where name='%s' and sco='%s'",ui->Log_id_2->text().toStdString().data(),ui->Log_pwd->text().toStdString().data());
query.exec(str);
if(ui->Log_id_2->text().isEmpty()||ui->Log_pwd->text().isEmpty())
{
QMessageBox msgBox;
msgBox.setText("Please enter name or pwd!!");
msgBox.exec();
}
else
{
if(query.next()) { //显示查询结果,相当于回调函数
mainform->getid(ui->Log_id_2->text());
this->hide();
mainform->show();
}
else
{
QMessageBox msgBox;
msgBox.setText("There is a error either name or pwd!!");
msgBox.exec();
}
}
/* if(ui->Log_id->text().isEmpty()||ui->Log_pwd->text().isEmpty())
{
QMessageBox msgBox;
msgBox.setText("Login failed!!");
msgBox.exec();
}
else
{
if(query.exec(str))
{
mainform->show();
this->hide();
QMessageBox msgBox;
msgBox.setText("Login success!!");
msgBox.exec();
ui->Log_id->clear();
ui->Log_pwd->clear();
}
else
{
QMessageBox msgBox;
msgBox.setText("Login failed!!");
msgBox.exec();
}
}*/
}
void Widget::on_Log_cancel_clicked()
{
exit(0);
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
login1.zip (65个子文件)
login1
moc_mainform1.o 7KB
mainform1.ui 4KB
mainform1.h 722B
mainform.h 839B
gra_info_form.cpp 2KB
ui_mainform3.h 5KB
moc_gra_info_form.cpp 3KB
ui_mainform.h 5KB
moc_mainform2.o 7KB
stu_info_dataform.o 16KB
widget.o 24KB
ui_widget.h 8KB
main.o 2KB
moc_cou_info_dataform.o 7KB
mainform2.ui 4KB
moc_stu_info_dataform.o 7KB
moc_stu_info_dataform.cpp 3KB
ui_cou_info_dataform.h 3KB
mainform3.ui 4KB
moc_mainform.cpp 3KB
gra_info_form.ui 2KB
moc_gra_info_form.o 7KB
mainform.ui 4KB
widget.ui 7KB
stu_info_dataform.h 667B
mainform2.o 19KB
moc_mainform1.cpp 3KB
cou_info_dataform.ui 2KB
stu_info_dataform.ui 2KB
stu_info_dataform.cpp 3KB
login1.pro.user.1.3 0B
mainform3.o 19KB
gra_info_form.o 14KB
mainform2.cpp 2KB
ui_mainform1.h 6KB
main.cpp 170B
cou_info_dataform.h 490B
moc_widget.o 7KB
mainform.cpp 2KB
moc_mainform2.cpp 3KB
Makefile 14KB
login1 123KB
test.db 8KB
mainform1.o 25KB
mainform3.h 574B
gra_info_form.h 458B
login1.pro.user 16KB
moc_cou_info_dataform.cpp 3KB
ui_mainform2.h 5KB
mainform1.cpp 3KB
widget.cpp 5KB
cou_info_dataform.o 14KB
widget.h 488B
cou_info_dataform.cpp 2KB
login1.pro 805B
mydb 3KB
moc_mainform3.o 7KB
moc_mainform.o 7KB
mainform.o 14KB
mainform2.h 586B
ui_stu_info_dataform.h 3KB
mainform3.cpp 2KB
ui_gra_info_form.h 3KB
moc_mainform3.cpp 3KB
moc_widget.cpp 3KB
共 65 条
- 1
资源评论
baidu_33941176
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功