代码拉取完成,页面将自动刷新
#include "usermodify.h"
#include "ui_usermodify.h"
#include <QDebug>
#include <QMessageBox>
#include <QFile>
UserModify::UserModify(QWidget *parent) :
QWidget(parent),
ui(new Ui::UserModify)
{
ui->setupUi(this);
ui->conBtn->setDisabled(true);
this->query.exec("use serial server");
this->model=new QSqlTableModel(this);
this->model->setTable("userinfo");
this->model->select();
ui->accountEdit->setDisabled(true);
ui->pwdEdit->setDisabled(true);
}
UserModify::~UserModify()
{
delete ui;
}
void UserModify::on_regBtn_clicked()
{
ui->conBtn->setDisabled(false);
ui->regBtn->setDisabled(true);
ui->repBtn->setDisabled(true);
ui->delBtn->setDisabled(true);
ui->accountEdit->setDisabled(false);
ui->pwdEdit->setDisabled(false);
ui->accountLab->setText("请注册新账号:");
ui->pwdLab->setText("请注册新密码:");
this->choice=1;
}
void UserModify::on_repBtn_clicked()
{
ui->conBtn->setDisabled(false);
ui->regBtn->setDisabled(true);
ui->repBtn->setDisabled(true);
ui->delBtn->setDisabled(true);
ui->accountEdit->setDisabled(false);
ui->pwdEdit->setDisabled(false);
ui->accountLab->setText("请输入修改账号:");
ui->pwdLab->setText("请输入修改密码:");
this->choice=2;
}
void UserModify::on_delBtn_clicked()
{
ui->conBtn->setDisabled(false);
ui->regBtn->setDisabled(true);
ui->repBtn->setDisabled(true);
ui->delBtn->setDisabled(true);
ui->accountEdit->setDisabled(false);
ui->pwdEdit->setDisabled(false);
ui->accountLab->setText("请输入要删除账号:");
ui->pwdLab->setText("请输入要删除密码:");
this->choice=3;
}
void UserModify::on_conBtn_clicked()
{
if (this->choice == 1)
{
QString sql = QString("insert into userinfo values(null, %1, %2)").arg(ui->accountEdit->text()).arg(ui->pwdEdit->text());
this->query.exec(sql);
if(!this->query.next()){}
else {
QMessageBox result;
result.about(this, "successed", "用户注册成功");
this->close();
}
}
if (this->choice == 2)
{
QString sql=QString("select * from userinfo where username='%1'").arg(ui->accountEdit->text());
this->query.exec(sql);
if(!this->query.next())
{
QMessageBox result;
result.critical(this, "error", "账号或密码输入错误");
}
else
{
QString sql=QString("update userinfo set password='%2' where username='%1'").arg(ui->accountEdit->text()).arg(ui->pwdEdit->text());
this->query.exec(sql);
QMessageBox result;
result.about(this, "successed", "修改成功");
this->close();
}
}
if (this->choice == 3)
{
QString sql=QString("select * from userinfo where username='%1' and password='%2'").arg(ui->accountEdit->text()).arg(ui->pwdEdit->text());
this->query.exec(sql);
if(!this->query.next())
{
QMessageBox result;
result.critical(this, "error", "没有该账号");
}
else
{
QString sql=QString("delete userinfo where username='%1'").arg(ui->accountEdit->text());
this->query.exec(sql);
QMessageBox result;
result.about(this, "successed", "删除成功");
this->close();
}
}
ui->conBtn->setDisabled(false);
ui->regBtn->setDisabled(false);
ui->repBtn->setDisabled(false);
ui->delBtn->setDisabled(false);
ui->accountEdit->setText("");
ui->pwdEdit->setText("");
ui->accountLab->setText("账号:");
ui->pwdLab->setText("密码:");
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。