3 Star 0 Fork 0

wdh1234/Server Port

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
usermodify.cpp 3.66 KB
一键复制 编辑 原始数据 按行查看 历史
www 提交于 2024-06-20 16:35 . 最终版
#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("密码:");
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wdh1234/server-port.git
git@gitee.com:wdh1234/server-port.git
wdh1234
server-port
Server Port
master

搜索帮助