您现在的位置是:首页 >技术杂谈 >VS+Qt+C++医院排队叫号系统网站首页技术杂谈
VS+Qt+C++医院排队叫号系统
简介VS+Qt+C++医院排队叫号系统
程序示例精选
VS+Qt+C++医院排队叫号系统
如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!
前言
这篇博客针对<<VS+Qt+C++医院排队叫号系统>>编写代码,带用户登录,管理员登录,增删改查,代码整洁,规则,易读。 学习与应用推荐首选。
文章目录
一、所需工具软件
二、使用步骤
1. 引入库
2. 代码实现
3. 运行结果
三、在线协助
一、所需工具软件
1. VS, Qt
2. C++
二、使用步骤
1.引入库
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_AdminManager.h"
#include <QWidget>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlError>
#include <QtSql/QtSql>
2. 代码实现
代码如下:
namespace
{
using namespace std;
// 结构体
struct Person
{
int id;
QString name;
};
// 类
class AddressBooks
{
public:
std::vector<Person> datas;
public:
void InitAddrssBooks();
bool AddPerson(Person p);
bool DeletePerson(QString personid);
bool UpdatePerson(Person p);
Person* FindPerson(QString personid);
};
Person* AddressBooks::FindPerson(QString personid)
{
Person* p = NULL;
int index = -1;
for (size_t i = 0; i < datas.size(); i++)
{
auto person = datas.at(i);
if (QString::number(person.id) == personid)
{
index = i;
break;
}
}
if (index != -1)
{
p = &datas.at(index);
}
return p;
}
bool AddressBooks::AddPerson(Person p)
{
qDebug() << "iddd: " << QString::number(p.id);
if (FindPerson(QString::number(p.id)))
{
qDebug() << "iddddd: " << p.id;
return false;
}
datas.push_back(p);
qDebug() << "data size:" << datas.size();
return true;
}
bool AddressBooks::UpdatePerson(Person p)
{
auto person = FindPerson(QString::number(p.id));
if (!person) return false;
person->id = p.id;
person->name = p.name;
return true;
}
bool AddressBooks::DeletePerson(QString personid) {
if (!FindPerson(personid)) return false;
int index = -1;
for (size_t i = 0; i < datas.size(); i++)
{
auto person = datas.at(i);
if (person.id == personid.toInt())
{
index = i;
break;
}
}
datas.erase(datas.begin() + index);
return true;
}
AddressBooks AddrDatabase;
}
AdminManager::AdminManager(QWidget* parent)
: QMainWindow(parent)
{
ui.setupUi(this);
QObject::connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(on_addButton_clicked()));
QObject::connect(ui.pushButton_2, SIGNAL(clicked()), this, SLOT(on_delButton_clicked()));
QObject::connect(ui.pushButton_3, SIGNAL(clicked()), this, SLOT(on_updateButton_clicked()));
QObject::connect(ui.pushButton_4, SIGNAL(clicked()), this, SLOT(on_findButton_clicked()));
QObject::connect(ui.pushButton_5, SIGNAL(clicked()), this, SLOT(on_check_clicked()));
QObject::connect(ui.pushButton_6, SIGNAL(clicked()), this, SLOT(on_backLoginWindow()));
//背景色
ui.tableWidget->setStyleSheet("QTableView::Item{background-color:green}");
}
//显示所有
void AdminManager::on_findButton_clicked()
{
qDebug() << "显示所有********************************** ";
memset(&AddrDatabase, 0, sizeof(AddrDatabase)); //清空结构体
readCSV(); //读取csv
ui.tableWidget->clearContents();
ui.tableWidget->setRowCount(0);
for (int i = 0; i < AddrDatabase.datas.size(); i++)
{
auto person = AddrDatabase.datas.at(i);
//qDebug() << "aaa: " << person.id;
//qDebug() << "aaa: " << person.name;
//qDebug() << "aaa: " << person.gender;
//qDebug() << "aaa: " << person.age;
//qDebug() << "aaa: " << person.classL;
//std::cout << "test_add2 " << person.name<< std::endl;
int rowCount = ui.tableWidget->rowCount();
ui.tableWidget->insertRow(rowCount);
QTableWidgetItem* columnItem0 = new QTableWidgetItem(
QString::number(person.id));
QTableWidgetItem* columnItem1 = new QTableWidgetItem(
person.name);
//QTableWidgetItem* columnItem5 = new QTableWidgetItem(
// query.value(5).toString());
ui.tableWidget->setItem(rowCount, 0, columnItem0);
ui.tableWidget->setItem(rowCount, 1, columnItem1);
//ui.tableWidget->setItem(rowCount, 5, columnItem5);
}
}
//删除
void AdminManager::on_delButton_clicked()
{
Person p;
p.id = ui.idLineEdit->text().toInt();
qDebug() << p.id;
AddrDatabase.DeletePerson(QString::number(p.id));
qDebug() << "test2";
exportCSV(); //输出到csv
on_findButton_clicked();
}
//修改
void AdminManager::on_updateButton_clicked()
{
qDebug() << "修改********************************** ";
memset(&AddrDatabase, 0, sizeof(AddrDatabase)); //清空结构体
readCSV(); //读取csv
ui.tableWidget->clearContents();
ui.tableWidget->setRowCount(0);
for (int i = 0; i < AddrDatabase.datas.size(); i++)
{
auto person = AddrDatabase.datas.at(i);
qDebug() << "aaa: " << person.id;
qDebug() << "aaa: " << person.name;
if (person.id == ui.idLineEditUpdate->text().toInt())
{
qDebug() << "testIf -----------------------";
qDebug() << "person.id" << person.id;
person.name = ui.comboBox->currentText();
qDebug() << "person.name" << person.name;
AddrDatabase.UpdatePerson(person);
}
}
exportCSV(); //输出到csv
on_findButton_clicked(); //执行显示所有信息函数
}
//添加
void AdminManager::on_addButton_clicked()
{
on_findButton_clicked(); //执行显示所有信息函数
std::cout << "test_add " << std::endl;
Person p;
p.id = ui.idLineEdit_2->text().toInt();
qDebug() << p.id;
AddrDatabase.AddPerson(p); //执行添加函数
exportCSV(); //输出到csv
on_findButton_clicked(); //执行显示所有信息函数
}
//查找
void AdminManager::on_check_clicked()
{
qDebug() << "查找********************************** ";
memset(&AddrDatabase, 0, sizeof(AddrDatabase)); //清空结构体
readCSV(); //读取csv
ui.tableWidget->clearContents();
ui.tableWidget->setRowCount(0);
for (int i = 0; i < AddrDatabase.datas.size(); i++)
{
auto person = AddrDatabase.datas.at(i);
qDebug() << "aaa: " << person.id;
qDebug() << "aaa: " << person.name;
if (person.id == ui.lineEdit_2->text().toInt())
{
int rowCount = ui.tableWidget->rowCount();
ui.tableWidget->insertRow(rowCount);
QTableWidgetItem* columnItem0 = new QTableWidgetItem(
QString::number(person.id));
QTableWidgetItem* columnItem1 = new QTableWidgetItem(
person.name);
//QTableWidgetItem* columnItem5 = new QTableWidgetItem(
// query.value(5).toString());
ui.tableWidget->setItem(rowCount, 0, columnItem0);
ui.tableWidget->setItem(rowCount, 1, columnItem1);
//ui.tableWidget->setItem(rowCount, 5, columnItem5);
}
}
}
void AdminManager::readCSV()
{
qDebug() << "test readCSV ";
QFile file("data.csv");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "Can't open the file!" << endl;
}
//一行一行直接读取文件
while (!file.atEnd()) {
qDebug() << "test readCSV ";
QByteArray line = file.readLine();
qDebug() << "line: " << line;
QString str(line);
str.replace("
", "");
qDebug() << str;
auto list = str.split(",");
Person p;
p.id = list[0].toInt();
p.name = list[1];
AddrDatabase.AddPerson(p);
//AddrDatabase.datas.push_back(p);
for (int i = 0; i < AddrDatabase.datas.size(); i++)
{
auto person = AddrDatabase.datas.at(i);
//qDebug() << "aaa: " << person.id;
//qDebug() << "aaa: " << person.name;
//qDebug() << "aaa: " << person.gender;
//qDebug() << "aaa: " << person.age;
//qDebug() << "aaa: " << person.classL;
}
}
file.close();
}
void AdminManager::exportCSV()
{
QString fileNamePath = "data.csv";
QFile file(fileNamePath);
if (!file.open(QIODevice::WriteOnly)) {
qDebug() << "Can't open the file!" << endl;
return;
}
QTextStream filestream(&file);//QTextStream 与file关联
filestream.setCodec("utf-8");
QStringList lines;
for (size_t i = 0; i < AddrDatabase.datas.size(); i++)
{
Person p = AddrDatabase.datas.at(i);
QString strline = QString::number(p.id) + "," + p.name;
lines << strline;
}
QString str = lines.join("
");
qDebug() << str;
filestream << str;
file.flush();
file.close();
}
//返回登录窗口
void AdminManager::on_backLoginWindow()
{
std::cout << "test_ " << std::endl;
this->close();
LoginResiger* ad;
ad = new LoginResiger;
ad->show();
}
3. 运行结果
三、在线协助:
如需安装运行环境或远程调试,见文章底部个人 QQ 名片,由专业技术人员远程协助!
1)远程安装运行环境,代码调试
2)Qt, C++, Python入门指导
3)界面美化
4)软件制作
博主推荐文章:python人脸识别统计人数qt窗体-CSDN博客
博主推荐文章:Python Yolov5火焰烟雾识别源码分享-CSDN博客
Python OpenCV识别行人入口进出人数统计_python识别人数-CSDN博客
个人博客主页:alicema1111的博客_CSDN博客-Python,C++,网页领域博主
博主所有文章点这里:alicema1111的博客_CSDN博客-Python,C++,网页领域博主
风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。