Qt框架对系统管理程序的再实现 – 一千零一网

我将该程序划分为几个页面(继承QMainWindow),根据功能的划分,分别有登录界面,登陆界面引申出密码找回界面,注册界面,病人管理界面,病人管理界面又引申出信息查找界面,信息添加界面,信息删除界面,模型预测界面(通过消息框弹出)。

代码如下:

登录界面(Computer.h)

#ifndef COMPUTER_H
#define COMPUTER_H
#include <QMainWindow>
#include<QPushButton>
#include<QMessageBox>
#include<QLineEdit>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include"reg.h"
#include"fond.h"
#include"fever.h"
QT_BEGIN_NAMESPACE
namespace Ui { class Computer; }
QT_END_NAMESPACE

class Computer : public QMainWindow
{
    Q_OBJECT
public:
    Computer(QWidget *parent = nullptr);
    ~Computer();
    QLabel *qaccount;
    QLabel *qpassword;
    QLineEdit *q_account;
    QLineEdit *q_password;
    QPushButton *qregister;
    QPushButton *qlogin;
    QWidget *qWidget;
    Reg *r;
    fond *f;
    fever *e;
private:
    Ui::Computer *ui;
public slots:
    void openAddAccount();
    void checkPassword();
};
#endif // COMPUTER_H

登录界面(Computer.cpp)

#include "Computer.h"
#include "ui_computer.h"
#include"system.h"
#include<QPushButton>
#include<QLabel>
#include<QIntValidator>
#include<QMessageBox>
#include<QLineEdit>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
Computer::Computer(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::Computer)
{
    setWindowTitle("登陆界面");
    qWidget=new QWidget();
    setCentralWidget(qWidget);
    setFixedSize(600,300);
    qaccount=new QLabel("账户");
    qpassword=new QLabel("密码");
    q_account=new QLineEdit();
    q_password=new QLineEdit();
    qregister=new QPushButton("注册");
    QPushButton *qlogin=new QPushButton("登陆");
    q_password->setEchoMode(QLineEdit::Password);
    q_account->setMaxLength(9);
    q_account->setValidator(new QIntValidator(0,1000000000,this));
    q_password->setMaxLength(12);
    qregister->setFixedSize(100,50);
    qlogin->setFixedSize(100,50);
    QGridLayout *gridlayout = new QGridLayout();
    gridlayout->addWidget(qaccount,0,0,1,1);
    gridlayout->addWidget(q_account,0,1,1,1);
    gridlayout->setSpacing(20);
    gridlayout->addWidget(qpassword,1,0,1,1);
    gridlayout->addWidget(q_password,1,1,1,1);
    gridlayout->setMargin(60);
    QHBoxLayout *hboxLayout = new QHBoxLayout();
    hboxLayout->setSpacing(60);
    hboxLayout->addWidget(qregister);
    hboxLayout->addWidget(qlogin);
    QVBoxLayout *vboxLayout = new QVBoxLayout();
    vboxLayout->addLayout(gridlayout);
    vboxLayout->addLayout(hboxLayout);
    centralWidget()->setLayout(vboxLayout);
    connect(qregister,&QPushButton::clicked,this,&Computer::openAddAccount);
    connect(qlogin,&QPushButton::clicked,this,&Computer::checkPassword);
};
void Computer::openAddAccount()
{
    r=new Reg();
    r->show();
}
void Computer::checkPassword()
{
    if(q_account->text().isEmpty()|q_password->text().isEmpty())
    {
        QMessageBox::warning(qWidget,"提示","请输入账号或密码");
    }
    else
    {
        long long x=q_account->text().toLongLong();
        string y=q_password->text().toStdString();
        bool d=LoginSystem::checkAccount(x,y);
        if(d)
        {
            e=new fever();
            e->show();
            this->close();
        }
        else
        {
            q_account->clear();
            q_password->clear();
            if(QMessageBox::question(qWidget,"提示","是否找回密码?",QMessageBox::Yes|QMessageBox::No)==QMessageBox::Yes)
            {
                f=new fond();
                f->show();
            }
        }
    }
}
Computer::~Computer()
{
    delete ui;
}

密码找回界面(fond.h)

#ifndef FIND_H
#define FIND_H
#include <QMainWindow>
#include<QPushButton>
#include<QLabel>
#include<QMessageBox>
#include<QLineEdit>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMainWindow>
class fond : public QMainWindow
{
    Q_OBJECT
public:
    explicit fond(QWidget *parent = nullptr);
    QPushButton *check;
    QLabel *account;
    QLabel *name;
    QLabel *number;
    QLineEdit *Account;
    QLineEdit *Name;
    QLineEdit *Number;
    QGridLayout *one;
    QHBoxLayout *two;
    QVBoxLayout *three;
    QWidget *QW;
signals:
public slots:
    void ract();
};

#endif // FIND_H

密码找回界面(fond.cpp)

#include "fond.h"
#include"system.h"
#include<QPushButton>
#include<QLabel>
#include<QIntValidator>
#include<QMessageBox>
#include<QLineEdit>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
fond::fond(QWidget *parent) : QMainWindow(parent)
{
    setWindowTitle("找回密码");
    QW=new QWidget(this);
    check=new QPushButton("确认");
    account=new QLabel("账户");
    name=new QLabel("姓名");
    number=new QLabel("编号");
    Account=new QLineEdit();
    Name=new QLineEdit();
    Number=new QLineEdit();
    one=new QGridLayout();
    two=new QHBoxLayout();
    three=new QVBoxLayout();
    setCentralWidget(QW);
    setFixedSize(700,500);
    check->setFixedSize(100,50);
    Account->setMaxLength(9);
    Account->setValidator(new QIntValidator(0,1000000000,this));
    Number->setValidator(new QIntValidator(0,1000000000,this));
    Number->setMaxLength(9);
    one->addWidget(account,0,0,1,1);
    one->addWidget(Account,0,1,1,1);
    one->addWidget(name,1,0,1,1);
    one->addWidget(Name,1,1,1,1);
    one->addWidget(number,2,0,1,1);
    one->addWidget(Number,2,1,1,1);
    one->setSpacing(20);
    one->setMargin(100);
    two->addWidget(check);
    two->setSpacing(60);
    three->addLayout(one);
    three->addLayout(two);
    centralWidget()->setLayout(three);
    connect(check,&QPushButton::clicked,this,&fond::ract);
}
void fond::ract()
{
    if(Name->text().isEmpty()|Account->text().isEmpty()|Number->text().isEmpty())
    {
        QMessageBox::warning(QW,"提示","请输入完整信息");
    }
    else
    {
        long long a=Account->text().toLongLong();
        string b=Name->text().toStdString();
        int c=Number->text().toInt();
        string Password=LoginSystem::findPassword(a,b,c);
        if(Password=="Wrong")
        {
            Account->clear();
            Name->clear();
            Number->clear();
            QMessageBox::about(QW,"提示信息","信息错误");
        }
        else
        {
            QString Pa=QString::fromStdString(Password);
            QMessageBox::about(QW,"密码",Pa);
            this->close();
        }
    }
}

注册界面(reg.h)

#ifndef REG_H
#define REG_H
#include<QPushButton>
#include<QLabel>
#include<QMessageBox>
#include<QLineEdit>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include<QWidget>
#include <QMainWindow>
class Reg : public QMainWindow
{
public:
    explicit Reg(QWidget *parent = nullptr);
    QPushButton *check;
    QLabel *user;
    QLabel *password;
    QLabel *name;
    QLabel *number;
    QLineEdit *User;
    QLineEdit *Password;
    QLineEdit *Name;
    QLineEdit *Number;
    QGridLayout *one;
    QHBoxLayout *two;
    QVBoxLayout *three;
    QWidget *qWidget;
public slots:
    void addaccount();
signals:

};

#endif // REG_H

注册界面(reg.cpp)

#include "reg.h"
#include"system.h"
#include"Computer.h"
#include<QPushButton>
#include<QLabel>
#include<QIntValidator>
#include<QMessageBox>
#include<QLineEdit>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include<QWidget>
Reg::Reg(QWidget *parent) : QMainWindow(parent)
{
    setWindowTitle("注册信息");
    qWidget=new QWidget(this);
    setCentralWidget(qWidget);
    setFixedSize(700,500);
    user=new QLabel("账户");
    password=new QLabel("密码");
    name=new QLabel("姓名");
    number=new QLabel("编码");
    User=new QLineEdit();
    Password=new QLineEdit();
    Name=new QLineEdit();
    Number=new QLineEdit();
    check=new QPushButton("确认");
    check->setFixedSize(100,50);
    User->setMaxLength(9);
    User->setValidator(new QIntValidator(0,1000000000,this));
    Password->setMaxLength(12);
    Number->setValidator(new QIntValidator(0,1000000000,this));
    Number->setMaxLength(9);
    one=new QGridLayout();
    one->addWidget(user,0,0,1,1);
    one->addWidget(User,0,1,1,1);
    one->addWidget(password,1,0,1,1);
    one->addWidget(Password,1,1,1,1);
    one->addWidget(name,2,0,1,1);
    one->addWidget(Name,2,1,1,1);
    one->addWidget(number,3,0,1,1);
    one->addWidget(Number,3,1,1,1);
    one->setSpacing(20);
    one->setMargin(100);
    two=new QHBoxLayout();
    two->addWidget(check);
    two->setSpacing(60);
    three=new QVBoxLayout();
    three->addLayout(one);
    three->addLayout(two);
    centralWidget()->setLayout(three);
    connect(check,&QPushButton::clicked,this,&Reg::addaccount);
}
void Reg::addaccount()
{
    if(User->text().isEmpty()|Password->text().isEmpty()|Number->text().isEmpty()|Name->text().isEmpty())
    {
        QMessageBox::warning(qWidget,"提示","请输入完整信息");
    }
    else
    {
        long long account=User->text().toLongLong();
        string name=Name->text().toStdString();
        string password=Password->text().toStdString();
        int number=Number->text().toInt();
        Doctor x=Doctor::findDoctor(name);
        Doctor y=Doctor::findDoctor(account);
        Doctor z=Doctor::findDoctor(number);
        if(x.showName()!="NoExist"|y.showName()!="NoExist"|z.showName()!="NoExist")
        {
            QMessageBox::warning(qWidget,"提示","姓名、编号或账户和已有信息重复,请重新输入");
            Name->clear();
            Number->clear();
            Password->clear();
            User->clear();
        }
        else
        {
            Doctor one(name,number,account);
            Doctor::addDoctor(one);
            LoginSystem::addAccount(account,password);
            QMessageBox::about(qWidget,"提示","注册成功");
            this->close();
        }
    }
}

病人管理界面(fever.h)

#ifndef FEVER_H
#define FEVER_H
#include <QMainWindow>
#include<QPushButton>
#include<QLabel>
#include<QMessageBox>
#include<QLineEdit>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMainWindow>
#include"feverpl.h"
#include"delet.h"
#include"fd.h"
class fever : public QMainWindow
{
    Q_OBJECT
public:
    explicit fever(QWidget *parent = nullptr);
    QPushButton *ad;
    QPushButton *del;
    QPushButton *cha;
    QPushButton *ffd;
    QWidget *Q1;
    QGridLayout *one;
    QHBoxLayout *two;
    QVBoxLayout *there;
    feverpl *u;
    delet *d;
    fd *f;
signals:

};

#endif // FEVER_H

病人管理界面(fever.cpp)

#include "fever.h"
#include"system.h"
fever::fever(QWidget *parent) : QMainWindow(parent)
{
    setWindowTitle("病人管理");
    ad=new QPushButton("添加信息");
    del=new QPushButton("删除信息");
    cha=new QPushButton("预测模型");
    ffd=new QPushButton("查找信息");
    one=new QGridLayout();
    two=new QHBoxLayout();
    there=new QVBoxLayout();
    Q1=new QWidget();
    u=new feverpl();
    d=new delet();
    f=new fd();
    setCentralWidget(Q1);
    setFixedSize(600,300);
    ffd->setFixedSize(100,50);
    ad->setFixedSize(100,50);
    cha->setFixedSize(100,50);
    del->setFixedSize(100,50);
    one->addWidget(ffd,0,0,1,1);
    one->addWidget(ad,0,1,1,1);
    one->addWidget(cha,1,0,1,1);
    one->addWidget(del,1,1,1,1);
    centralWidget()->setLayout(one);
    centralWidget()->setLayout(there);
    connect(ad,&QPushButton::clicked,this,[=](){
        u->show();
    });
    connect(cha,&QPushButton::clicked,this,[=](){
        pair<int,int>forc=Patient::show();
        stringstream ss;
        string x,y;
        ss<<forc.first;
        ss>>x;ss.clear();
        ss<<forc.second;
        ss>>y;ss.clear();
        QString inf=QString().fromStdString(x);
        inf="预测感染人数: "+inf;
        QString rec=QString().fromStdString(y);
        rec="预测康复人数: "+rec;
        QString k=inf+"<br>"+rec;
        QMessageBox::information(Q1,"预测结果",k,QMessageBox::Ok);
    });
    connect(del,&QPushButton::clicked,this,[=](){
       d->show();
    });
    connect(ffd,&QPushButton::clicked,this,[=](){
        f->show();
    });
}

信息查询界面(fd.h)

#ifndef FD_H
#define FD_H
#include <QMainWindow>
#include<QPushButton>
#include<QLabel>
#include<QValidator>
#include<QMessageBox>
#include<QLineEdit>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMainWindow>
#include <QMainWindow>
#include <QMainWindow>
#include <QObject>

class fd : public QMainWindow
{
    Q_OBJECT
public:
    explicit fd(QWidget *parent = nullptr);
    QLabel *name;
    QLabel *number;
    QLineEdit *Name;
    QLineEdit *Number;
    QGridLayout *one;
    QHBoxLayout *two;
    QVBoxLayout *three;
    QPushButton *fn;
    QWidget *Q3;
signals:
public slots:
    void fnd();
};

#endif // FD_H

信息查询界面(fd.cpp)

#include "fd.h"
#include"system.h"
fd::fd(QWidget *parent) : QMainWindow(parent)
{
    setWindowTitle("查找信息");
    name=new QLabel("姓名");
    number=new QLabel("编号");
    Name=new QLineEdit();
    Number=new QLineEdit();
    one=new QGridLayout();
    two=new QHBoxLayout();
    three=new QVBoxLayout();
    fn=new QPushButton("确定查找");
    Q3=new QWidget();
    setCentralWidget(Q3);
    setFixedSize(700,500);
    fn->setFixedSize(100,50);
    Number->setMaxLength(9);
    Number->setValidator(new QIntValidator(0,1000000000,this));
    one->addWidget(name,0,0,1,1);
    one->addWidget(Name,0,1,1,1);
    one->addWidget(number,1,0,1,1);
    one->addWidget(Number,1,1,1,1);
    one->setMargin(100);
    one->setSpacing(20);
    two->addWidget(fn);
    two->setSpacing(60);
    three->addLayout(one);
    three->addLayout(two);
    centralWidget()->setLayout(three);
    connect(fn,&QPushButton::clicked,this,&fd::fnd);
}
void fd::fnd()
{
    if(Name->text().isEmpty()&&Number->text().isEmpty())
    {
        QMessageBox::warning(Q3,"提示","请至少输入一项信息");
    }
    else
    {
        if(!Name->text().isEmpty())
        {
            string n=Name->text().toStdString();
            Patient p=Patient::findPatient(n);
            if(p.showName()=="NoExist")
            {
                QMessageBox::warning(Q3,"错误","该病人不存在");
            }
            else
            {
                QString a=QString().fromStdString(n);
                QString b,c;
                string x,y;
                stringstream ss;
                ss<<p.showNumber();
                ss>>x;ss.clear();
                ss<<p.showCondition();
                ss>>y;ss.clear();
                b=QString().fromStdString(x);
                c=QString().fromStdString(y);
                QString k="姓名:"+a+"<br>"+"编号:"+b+"<br>"+"病况:"+c;
                QMessageBox::about(Q3,"病人信息",k);
            }
        }
        else
        {
            long long n=Number->text().toLongLong();
            Patient p=Patient::findPatient(n);
            if(p.showName()=="NoExist")
            {
                QMessageBox::warning(Q3,"错误","该病人不存在");
            }
            else
            {
                QString a,b,c;
                string x,y;
                stringstream ss;
                a=QString().fromStdString(p.showName());
                ss<<p.showNumber();
                ss>>x;ss.clear();
                ss<<p.showCondition();
                ss>>y;ss.clear();
                b=QString().fromStdString(x);
                c=QString().fromStdString(y);
                QString k="姓名:"+a+"<br>"+"编号:"+b+"<br>"+"病况:"+c;
                QMessageBox::about(Q3,"病人信息",k);
            }
        }
        Name->clear();
        Number->clear();
    }
}

信息添加界面(feverpl.h)

#ifndef FEVERPL_H
#define FEVERPL_H
#include <QMainWindow>
#include<QPushButton>
#include<QLabel>
#include<QMessageBox>
#include<QLineEdit>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMainWindow>
#include <QMainWindow>

class feverpl : public QMainWindow
{
    Q_OBJECT
public:
    explicit feverpl(QWidget *parent = nullptr);
    QLabel *name;
    QLabel *number;
    QLabel *condition;
    QLineEdit *Name;
    QLineEdit *Number;
    QLineEdit *Condition;
    QPushButton *check;
    QWidget *Q2;
    QGridLayout *one;
    QHBoxLayout *two;
    QVBoxLayout *there;
signals:
public slots:
    void addfever();
};

#endif // FEVERPL_H

信息添加界面(feverpl.cpp)

#include "feverpl.h"
#include <QMainWindow>
#include<QPushButton>
#include<QLabel>
#include<QValidator>
#include<QMessageBox>
#include<QLineEdit>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMainWindow>
#include"system.h"
feverpl::feverpl(QWidget *parent) : QMainWindow(parent)
{
    setWindowTitle("添加病人");
    name=new QLabel("姓名");
    number=new QLabel("编号");
    condition=new QLabel("病情");
    Name=new QLineEdit();
    Number=new QLineEdit();
    Condition=new QLineEdit();
    check=new QPushButton("确认添加");
    Q2=new QWidget();
    setCentralWidget(Q2);
    setFixedSize(700,500);
    check->setFixedSize(100,50);
    Name->setMaxLength(5);
    Number->setMaxLength(9);
    Number->setValidator(new QIntValidator(0,1000000000,this));
    Condition->setPlaceholderText("请输入A,B或C");
    Condition->setMaxLength(1);
    one=new QGridLayout();
    two=new QHBoxLayout();
    there=new QVBoxLayout();
    one->addWidget(name,0,0,1,1);
    one->addWidget(Name,0,1,1,1);
    one->addWidget(number,1,0,1,1);
    one->addWidget(Number,1,1,1,1);
    one->addWidget(condition,2,0,1,1);
    one->addWidget(Condition,2,1,1,1);
    one->setMargin(100);
    one->setSpacing(20);
    two->addWidget(check);
    two->setSpacing(60);
    there->addLayout(one);
    there->addLayout(two);
    centralWidget()->setLayout(there);
    connect(check,&QPushButton::clicked,this,&feverpl::addfever);
}
void feverpl::addfever()
{
    if(Name->text().isEmpty()|Number->text().isEmpty()|Condition->text().isEmpty())
    {
        QMessageBox::warning(Q2,"提示","请输入完整信息");
    }
    else
    {
        string x=Name->text().toStdString();
        long long y=Number->text().toLongLong();
        string Z=Condition->text().toStdString();
        char z=Z[0];
        Patient one(x,z,y);
        Patient::addPatient(one);
        QMessageBox::about(Q2,"提示","添加成功");
        Name->clear();
        Number->clear();
        Condition->clear();
    }
}

信息删除界面(delet.h)

#ifndef DELET_H
#define DELET_H
#include <QMainWindow>
#include<QPushButton>
#include<QLabel>
#include<QIntValidator>
#include<QMessageBox>
#include<QLineEdit>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMainWindow>
#include <QMainWindow>

class delet : public QMainWindow
{
    Q_OBJECT
public:
    explicit delet(QWidget *parent = nullptr);
    QLabel *name;
    QLabel *number;
    QLineEdit *Name;
    QLineEdit *Number;
    QGridLayout *one;
    QHBoxLayout *two;
    QVBoxLayout *three;
    QPushButton *de;
    QWidget *Q3;
signals:
public slots:
    void delP();
};

#endif // DELET_H

信息删除界面(delet.cpp)

#include "delet.h"
#include"system.h"
delet::delet(QWidget *parent) : QMainWindow(parent)
{
    setWindowTitle("删除信息");
    name=new QLabel("姓名");
    number=new QLabel("编号");
    Name=new QLineEdit();
    Number=new QLineEdit();
    one=new QGridLayout();
    two=new QHBoxLayout();
    three=new QVBoxLayout();
    de=new QPushButton("确定删除");
    Q3=new QWidget();
    setCentralWidget(Q3);
    setFixedSize(700,500);
    de->setFixedSize(100,50);
    Number->setMaxLength(9);
    Number->setValidator(new QIntValidator(0,1000000000,this));
    one->addWidget(name,0,0,1,1);
    one->addWidget(Name,0,1,1,1);
    one->addWidget(number,1,0,1,1);
    one->addWidget(Number,1,1,1,1);
    one->setMargin(100);
    one->setSpacing(20);
    two->addWidget(de);
    two->setSpacing(60);
    three->addLayout(one);
    three->addLayout(two);
    centralWidget()->setLayout(three);
    connect(de,&QPushButton::clicked,this,&delet::delP);
}
void delet::delP()
{
    if(Name->text().isEmpty()&&Number->text().isEmpty())
    {
        QMessageBox::warning(Q3,"提示","请至少输入一项信息");
    }
    else
    {
        if(!Name->text().isEmpty())
        {
            string n=Name->text().toStdString();
            Patient p=Patient::findPatient(n);
            if(p.showName()=="NoExist")
            {
                QMessageBox::warning(Q3,"错误","该病人不存在");
            }
            else
            {
                Patient::deletePatient(n);
                QMessageBox::about(Q3,"提示","删除成功");
            }
        }
        else
        {
            long long n=Number->text().toLongLong();
            Patient p=Patient::findPatient(n);
            if(p.showName()=="NoExist")
            {
                QMessageBox::warning(Q3,"错误","该病人不存在");
            }
            else
            {
                Patient::deletePatient(n);
                QMessageBox::about(Q3,"提示","删除成功");
            }
        }
        Name->clear();
        Number->clear();
    }
}

代码中反复用到了大量关于QMessageBox、QLabel、QLineEdit,还有一些关于布局的和文本编辑的方法,虽然没有系统的总结,但是在代码中很直观。

发表评论

电子邮件地址不会被公开。 必填项已用*标注