#include "regist.h"
#include "ui_regist.h"
#include <QMessageBox>

Regist::Regist(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Regist)
{
    ui->setupUi(this);
    this->setAttribute(Qt::WA_DeleteOnClose,1);
}

Regist::~Regist()
{
    delete ui;
}

void Regist::getdata(QSqlDatabase db1,QString tablename1) {
    db = db1;
    tablename = tablename1;
}


void Regist::on_pushButton_clicked()
{
    QString username = ui->usrname->text();
    QString password = ui->psw->text();

    QString sql = QString("insert into user(username,password) values('%1','%2');").arg(username).arg(password);

    QSqlQuery sql_query(db);
    if(!sql_query.exec(sql)) {
        QMessageBox::about(this,"提示","注册失败");
        return;
    }
    QMessageBox::about(this,"提示","注册成功");
}

void Regist::on_goback_clicked()
{
    this->parentWidget()->show();
    this->hide();
}
