#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QLabel>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connectmysql();
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &MainWindow::updatetimeout);
timer->start(1000);
QPalette pe;
pe.setColor(QPalette::WindowText,Qt::white);
ui->label->setPalette(pe);
ui->label_3->setPalette(pe);
ui->label_4->setPalette(pe);
ui->label_5->setPalette(pe);
ui->groupBox->setPalette(pe);
ui->pushButton->setPalette(pe);
ui->pushButton_2->setPalette(pe);
ui->lineEdit_2->setEchoMode(QLineEdit::Password);
QPixmap pixmap = QPixmap(":/ground.jpg").scaled(this->size());
QPalette palette(this->palette());
palette.setBrush(QPalette::Background, QBrush(pixmap));
this->setPalette(palette);
connect(ui->pushButton_2, &QPushButton::clicked, this, &MainWindow::regist);
connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::login);
connect(®istwindow, ®istered::sendregist, this, &MainWindow::sqlregist);
connect(&user, &userwindow::sendquit, this, &MainWindow::quit);
connect(&user, &userwindow::sendprint, this, &MainWindow::sqlinq);
connect(&user, &userwindow::send_main_updateinfo, this, &MainWindow::sqlupdateinfo);
connect(&user, &userwindow::send_main_updatepass, this, &MainWindow::sqlupdatepass);
connect(&user, &userwindow::send_main_balance, this, &MainWindow::sqlupdatebalance);
connect(&user, &userwindow::send_main_yearmember, this, &MainWindow::sqlyearmember);
connect(&user, &userwindow::send_main_monthmember, this, &MainWindow::sqlmonthmember);
connect(&user, &userwindow::send_main_reservation, this, &MainWindow::sqlreservation);
connect(&user, &userwindow::send_main_payment, this, &MainWindow::sqlpayment);
connect(&user, &userwindow::send_main_consumption, this, &MainWindow::sqlconsumption);
}
void MainWindow::connectmysql()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("127.0.0.1");
db.setUserName("root");
db.setPassword("123456");
db.setDatabaseName("parking");
if (!db.open())
{
QMessageBox::warning(this, "错误", db.lastError().text());
return;
}
QMessageBox::information(nullptr, QStringLiteral("提示"), QStringLiteral("数据库成功连接!"), QMessageBox::Yes);
/*
QSqlQuery query_2;
query_2.exec("select * from stu");
while(query_2.next())
{
qDebug() << query_2.value(0).toString() << endl;
}
*/
return;
}
void MainWindow::regist(){
registwindow.show();
}
void MainWindow::login(){
QString account = this->ui->lineEdit->text();
QString password = this->ui->lineEdit_2->text();
if(account.isEmpty() || password.isEmpty())
{
QMessageBox::warning(nullptr, QStringLiteral("错误"), QStringLiteral("账号密码不能为空"), QMessageBox::Yes);
}
else{
if(!ui->radioButton->isChecked() && !ui->radioButton_2->isChecked())
{
QMessageBox::warning(nullptr, QStringLiteral("警告"), QStringLiteral("请选择你的身份"), QMessageBox::Yes);
}
else if(ui->radioButton_2->isChecked())
{
QSqlQuery query;
QString rightword;
QString str = QString("select password from userinfo where id = '%1'").arg(account);
query.exec(str);
while(query.next())
{
rightword = query.value(0).toString();
}
// qDebug() << rightword << endl;
if(password == rightword){
userid = account;
this->hide();
this->sqlinq();
this->sqlinfo();
user.show();
ui->lineEdit->clear();
ui->lineEdit_2->clear();
}
else{
QMessageBox::warning(nullptr, QStringLiteral("错误"), QStringLiteral("账号密码错误"), QMessageBox::Yes);
ui->lineEdit->clear();
ui->lineEdit_2->clear();
}
}
else {
QSqlQuery query;
QString rightword;
QString str = QString("select parkingpassword from parkinglot where parkingid = '%1'").arg(account);
query.exec(str);
while(query.next())
{
rightword = query.value(0).toString();
}
if(password == rightword){
parkerid = account;
this->sqlparkinglot();
this->sqlparkingspace();
parker.show();
this->hide();
ui->lineEdit->clear();
ui->lineEdit_2->clear();
}
else{
QMessageBox::warning(nullptr, QStringLiteral("错误"), QStringLiteral("账号密码错误"), QMessageBox::Yes);
ui->lineEdit->clear();
ui->lineEdit_2->clear();
}
}
}
}
void MainWindow::sqlregist(QString id, QString password, QString name, QString carid, QString cartype, QString tel){
QSqlQuery query;
QString str = QString("insert into userinfo(id,name,tel,type,balance,password) values('%1', '%2', '%3', '普通用户', 0, '%4')").arg(id).arg(name).arg(tel).arg(password);
QString str_2 = QString("insert into carinfo(id,carid,cartype) values('%1', '%2', '%3')").arg(id).arg(carid).arg(cartype);
if(query.exec(str) && query.exec(str_2)){
QMessageBox::information(nullptr, QStringLiteral("提示"), QStringLiteral("注册成功!"), QMessageBox::Yes);
}
else{
QMessageBox::warning(nullptr, QStringLiteral("错误"), QStringLiteral("该用户名已被注册"), QMessageBox::Yes);
}
}
void MainWindow::sqlinq(){
// qDebug() << "deal" << endl;
QSqlQuery query;
QString inquire = QString("select * from parkingspace where situation = '空闲'");
query.exec(inquire);
int i = 0;
while(query.next()){
data[i][0] = query.value(2).toString();
data[i][1] = query.value(3).toString();
data[i][2] = query.value(1).toString();
arr[i] = query.value(0).toInt();
// qDebug() << arr[i] << ' ' << data[i][0] << ' ' << data[i][1] << ' ' << data[i][2] << endl;
i++;
}
len = i;
// qDebug() << len << endl;
user.print(data, arr, len);
}
void MainWindow::sqlinfo(){
QString name, carid, tel, cartype, type;
int balance = 0;
QSqlQuery query;
QString inquire = QString("select * from userinfo where id = '%1'").arg(userid);
query.exec(inquire);
while(query.next()){
name = query.value(1).toString();
tel = query.value(2).toString();
type = query.value(3).toString();
balance = query.value(4).toInt();
}
QString inquire_2 = QString("select * from carinfo where id = '%1'").arg(userid);
query.exec(inquire_2);
while(query.next()){
carid = query.value(1).toString();
cartype = query.value(2).toString();
}
user.printinfo(userid, name, carid, tel, cartype, type, balance);
}
void MainWindow::sqlupdateinfo(QString name, QString tel, QString carid, QString cartype){
QSqlQuery query;
QString str = QString("update userinfo set name = '%1' where id = '%2'").arg(name).arg(userid);
query.exec(str);
QString str_2 = QString("update userinfo set tel = '%1' where id = '%2'").arg(tel).arg(userid);
query.exec(str_2);
QString str_3 = QString("update carinfo set carid = '%1' where id = '%2'").arg(carid).arg(userid);
query.exec(str_3);
QString str_4 = QString("update carinfo set cartype = '%1' where id = '%2'").arg(cartype).arg(userid);
query.exec(str_4);
QMessageBox::information(nullptr, QStringLiteral("提示"), QStringLiteral("修改成功"), QMessageBox::Yes);
this->sqlinfo();
}
void MainWi
没有合适的资源?快使用搜索试试~ 我知道了~
基于C++,Qt,Mysql实现,包括预约停车,会员办理,充值缴费等功【数据库课程设计】
共34个文件
cpp:9个
ui:8个
h:8个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 128 浏览量
2024-06-19
18:12:05
上传
评论
收藏 200KB ZIP 举报
温馨提示
【作品名称】:基于Qt,Mysql实现,包括预约停车,会员办理,充值缴费等功【数据库课程设计】 【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【项目介绍】:基于C++,Qt,Mysql实现,包括预约停车,会员办理,充值缴费等功【数据库课程设计】
资源推荐
资源详情
资源评论
收起资源包目录
ParkingManager-master.zip (34个子文件)
ParkingManager-master
topup.ui 2KB
edit_info.cpp 1KB
update_password.h 421B
record.h 703B
parkingwindow.cpp 2KB
edit_info.ui 5KB
mainwindow.h 1KB
userwindow.ui 26KB
topup.cpp 852B
update_password.cpp 1KB
ground.jpg 33KB
image.qrc 255B
mainwindow.cpp 21KB
registered.cpp 2KB
parking.sql 7KB
ground_2.jpg 70KB
Parkingmanager.pro 2KB
parkingwindow.h 806B
main.cpp 172B
edit_info.h 411B
registered.ui 6KB
userwindow.cpp 6KB
timg.jpg 16KB
ground_4.jpg 20KB
mainwindow.ui 5KB
update_password.ui 3KB
ground_3.jpg 8KB
record.cpp 3KB
topup.h 342B
question.jpg 18KB
record.ui 5KB
registered.h 416B
userwindow.h 2KB
parkingwindow.ui 5KB
共 34 条
- 1
资源评论
MarcoPage
- 粉丝: 4254
- 资源: 8839
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功