QT5实现职工工资信息管理系统(文件读写)

这篇具有很好参考价值的文章主要介绍了QT5实现职工工资信息管理系统(文件读写)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

暑期学校QT实践项目

题目要求

该系统需创建和管理如下信息:1、职工信息:工号、姓名、年龄、入职日期、电话、住址、月工资数据集。2、月工资信息:月份、基本工资、岗位工资、工龄工资、津贴、岗贴、补贴、房贴、交通补贴。
系统功能要求如下:
1.创建和管理职工信息的对象;
2.创建和管理月工资信息的对象;
3.增加和删除职工;
4.针对特定职工增加和删除月工资信息;
5.基本查询功能;
6.数据文件读写:文件中包含所有职工信息、每个职工的月工资信息等数据;
7.基本信息显示:1)所有职工的信息显示;2)特定职工的月工资信息;
8.可选功能提升:在显示中增加个人所得税(个人所得税计算方法设为:工资少于800元为0;800~1000元的部分为5%;1000~5000元的部分为10%;5000元以上的部分为20%)、实发数等显示。

成品展示

主界面
qt 员工管理系统,QT项目,qt,开发语言,ui
选择读取文件
qt 员工管理系统,QT项目,qt,开发语言,ui
添加职工
qt 员工管理系统,QT项目,qt,开发语言,ui
查看特定职工薪资
qt 员工管理系统,QT项目,qt,开发语言,ui
添加特定职工薪资信息
qt 员工管理系统,QT项目,qt,开发语言,ui
删除职工
qt 员工管理系统,QT项目,qt,开发语言,ui
删除特定薪资信息
qt 员工管理系统,QT项目,qt,开发语言,ui
帮助界面
qt 员工管理系统,QT项目,qt,开发语言,ui
查询职工信息
qt 员工管理系统,QT项目,qt,开发语言,ui
查询薪资信息
qt 员工管理系统,QT项目,qt,开发语言,ui
查看特定薪资税后收入
qt 员工管理系统,QT项目,qt,开发语言,ui
修改信息(在工具栏编辑中选择修改后方可修改)
qt 员工管理系统,QT项目,qt,开发语言,ui
薪资情况简单统计
qt 员工管理系统,QT项目,qt,开发语言,ui

一些说明

还存在一些bug , 包括
1.添加职工信息和薪资信息时不能判断是否出现编号重复的错误。
2.薪资统计功能必须所有职工的工资信息存在且不为0,否则会出现"nan"……
3.薪资统计功能有待完善
……
(希望各位dalao批评指正)

使用流程介绍
qt 员工管理系统,QT项目,qt,开发语言,ui

源码展示

首先是4个类,薪资类,薪资表类,职工类,职工表类来存储基本信息。

salary.h 薪资类

#ifndef SALARY_H
#define SALARY_H
#include<QTextStream>
#include<qstring.h>
#include<qdatetime.h>
#include<qlist.h>
#include<QFile>
#include <QMessageBox>
#include<QFileDialog>
#include<QTextCodec>
#include <QAbstractItemDelegate>
#include<QAbstractItemView>

class salary
{
public:
    salary();
    salary& operator= (const salary& salary);
    virtual ~salary();

    void Savesalary(QTextStream &aStream);
    void Readsalary(QTextStream &aStream);

    QString e_id;
    int month;
    double base_salary;
    double post_salary;
    double seniority_salary;
    double allowance;
    double post_allowance;
    double subsidy;
    double housing_allowance;
    double trans_allowance;


};

#endif // SALARY_H

salary.cpp

#include "salary.h"

salary::salary()
{
    e_id="";
    month = 1;
    base_salary = 0;
    post_salary = 0;
    seniority_salary=0;
    allowance = 0;
    post_allowance = 0;
    subsidy = 0;
    housing_allowance = 0;
    trans_allowance = 0;
}

salary &salary::operator=(const salary &salary)
{
    e_id=salary.e_id;
    month=salary.month;
    base_salary=salary.base_salary;
    post_salary=salary.post_salary;
    seniority_salary=salary.seniority_salary;
    allowance=salary.allowance;
    post_allowance=salary.post_allowance;
    subsidy=salary.subsidy;
    housing_allowance=salary.housing_allowance;
    trans_allowance=salary.trans_allowance;

    return *this;
}

salary::~salary()
{

}

void salary::Savesalary(QTextStream &aStream)
{
    aStream<<e_id<<"\t"<<month<<"\t"<<base_salary<<"\t"<<post_salary<<"\t"
          <<seniority_salary<<"\t"<<allowance<<"\t"<<post_allowance<<"\t"
         <<subsidy<<"\t"<<housing_allowance<<"\t"<<trans_allowance<<"\n";
}

void salary::Readsalary(QTextStream &aStream)
{
    aStream>>e_id;
    aStream>>month;
    aStream>>base_salary;
    aStream>>post_salary;
    aStream>>seniority_salary;
    aStream>>allowance;
    aStream>>post_allowance;
    aStream>>subsidy;
    aStream>>housing_allowance;
    aStream>>trans_allowance;

}

salaryinfotable.h 薪资表类

#ifndef SALARYINFOTABLE_H
#define SALARYINFOTABLE_H

#include"salary.h"

class salaryinfotable
{
public:
    salaryinfotable();
    salaryinfotable& operator = (const salaryinfotable & salary);

    void Savesalaryinfotable(QTextStream &aStream);
    void Readsalaryinfotable(QTextStream &aStream);

    void addSalary(salary& salary);
    void delSalary(int index);
    salary& Getsalary(int index);
    int salaryNum();

    QList<salary> m_salary;
    int m_num; //薪资信息条数
};

#endif // SALARYINFOTABLE_H

emoloyee.h 职工类

#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include"salaryinfotable.h"

class employee
{
public:
    employee();
    virtual ~employee();
    employee& operator=(const employee & employee);

    void Saveemployee(QTextStream &aStream);
    void Reademployee(QTextStream &aStream);

    bool is_salary(); //是否有薪资信息

    QString id;
    QString name;
    int age;
    QDate hiredate;
    QString tele;
    QString address;
    salaryinfotable m_salary;

};

#endif // EMPLOYEE_H

employee.cpp

#include "employee.h"

employee::employee()
{
    id=" ";
    name=" ";
    age=0;
    hiredate=QDate();
    tele =" ";
    address =" ";
    m_salary=salaryinfotable();
}

employee::~employee()
{

}

employee& employee::operator=(const employee &employee)
{
    id=employee.id;
    name=employee.name;
    age=employee.age;
    hiredate=employee.hiredate;
    tele=employee.tele;
    address=employee.address;
    m_salary = employee.m_salary;
    return *this;
}

void employee::Saveemployee(QTextStream &aStream)
{
    aStream<<id<<"\t"<<name<<"\t"<<age<<"\n";
    aStream<<hiredate.year()<<"\t"<<hiredate.month()<<"\t"<<hiredate.day()<<"\n";
    aStream<<tele<<"\n";
    aStream<<address<<"\n";
    m_salary.salaryinfotable::Savesalaryinfotable(aStream);
}

void employee::Reademployee(QTextStream &aStream)
{
    int year,month,day;
    aStream>>id;
    aStream>>name;
    aStream>>age;
    aStream>>year;
    aStream>>month;
    aStream>>day;
    hiredate.setDate(year,month,day);
    aStream>>tele;
    aStream>>address;
    m_salary.Readsalaryinfotable(aStream);
}

bool employee::is_salary()
{
    return m_salary.salaryNum()==0;
}

employeeinfotable 职工表类

#ifndef EMPLOYEEINFOTABLE_H
#define EMPLOYEEINFOTABLE_H

#include"employee.h"

class employeeinfotable
{
public:
    employeeinfotable();
    employeeinfotable& operator= (const employeeinfotable & employee);

    void Saveemployeeinfotable(QTextStream &aStream);
    void ReadSalaryinfotable(QTextStream &aStream);

    void Addemployee(employee & employee);
    void Delemployee(int index);
    employee & Getemployee(int index);
    int employeeNum();

    QList<employee> m_employee;
    int e_num;  //职工列表中的职工人数
};

#endif // EMPLOYEEINFOTABLE_H

employeeinfotable.cpp

#include "employeeinfotable.h"

employeeinfotable::employeeinfotable()
{
    m_employee=QList<employee>();
    e_num=0;
}


employeeinfotable& employeeinfotable::operator=(const employeeinfotable &employee)
{
    m_employee=employee.m_employee;
    e_num=employee.e_num;
    return *this;
}

int employeeinfotable::employeeNum()
{
    e_num=m_employee.size();
    return this->e_num;
}

void employeeinfotable::Saveemployeeinfotable(QTextStream &aStream)
{
    int num=employeeNum();
    aStream<<num<<"\n";
    for(int i=0;i<num;i++)
    {
       m_employee[i].Saveemployee(aStream);
       aStream<<"\n";
    }
}


void employeeinfotable::ReadSalaryinfotable(QTextStream &aStream)
{
    aStream>>e_num;
    for(int i=0;i<e_num;i++)
    {
        employee temp;
        temp.Reademployee(aStream);
        m_employee.append(temp);
    }
}


void employeeinfotable::Addemployee(employee &employee)
{
    m_employee.append(employee);
    e_num +=1;
}

void employeeinfotable::Delemployee(int index)
{
    m_employee.removeAt(index);
    e_num-=1;
}

employee& employeeinfotable::Getemployee(int index)
{
    return m_employee[index];
}

inputdialog 插入职工信息

新建QT设计师类界面
qt 员工管理系统,QT项目,qt,开发语言,ui
inputdialog.h

#ifndef INPUTDIALOG_H
#define INPUTDIALOG_H

#include <QDialog>
#include<QTextEdit>

namespace Ui {
class inputdialog;
}

class inputdialog : public QDialog
{
    Q_OBJECT

public:
    explicit inputdialog(QWidget *parent = nullptr);
    ~inputdialog();

    QString is_Error();
    void Show_error(const QString & tempstr); //显示错误信息

    QString get_ID();
    QString get_name();
    QString get_age();
    QDate get_hid();
    QString get_tele();
    QString get_address();

    void label_Show();

private slots:
// ui界面中点击转到槽
    void on_lineEdit_id_editingFinished();

    void on_lineEdit_name_editingFinished();

    void on_lineEdit_age_editingFinished();

    void on_dateEdit_editingFinished();

    void on_lineEdit_tele_editingFinished();

    void on_lineEdit_address_editingFinished();


    void on_lineEdit_age_selectionChanged();

    void on_lineEdit_id_selectionChanged();

    void on_lineEdit_name_selectionChanged();

    void on_lineEdit_tele_selectionChanged();

    void on_lineEdit_address_selectionChanged();

private:
    Ui::inputdialog *ui;
};

#endif // INPUTDIALOG_H
#include "inputdialog.h"
#include "ui_inputdialog.h"

inputdialog::inputdialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::inputdialog)
{
    ui->setupUi(this);
//设置样式表
    ui->buttonBox->setStyleSheet("QPushButton{font: 25 14pt '微软雅黑 Light';color: rgb(255,255,255);background-color: rgb(20,196,188);"
                                 "border: 2px groove gray;border-radius:15px;padding:2px 4px;border-style: outset;}"
                                 "QPushButton:hover{background-color: rgb(22,218,208);}"//hover
                                 "QPushButton:pressed{background-color: rgb(17,171,164);}"//pressed
                                   "border:2px solid rgb(20,196,188);");
    ui->dateEdit->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                "color: rgb(31,31,31);"		//字体颜色
                                "padding-left:20px;"       //内边距-字体缩进
                                "background-color: rgb(255, 255, 255);" //背景颜色
                                "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit_address->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                        "color: rgb(31,31,31);"		//字体颜色
                                        "padding-left:20px;"       //内边距-字体缩进
                                        "background-color: rgb(255, 255, 255);" //背景颜色
                                        "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit_age->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                    "color: rgb(31,31,31);"		//字体颜色
                                    "padding-left:20px;"       //内边距-字体缩进
                                    "background-color: rgb(255, 255, 255);" //背景颜色
                                    "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit_id->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                   "color: rgb(31,31,31);"		//字体颜色
                                   "padding-left:20px;"       //内边距-字体缩进
                                   "background-color: rgb(255, 255, 255);" //背景颜色
                                   "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit_name->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                     "color: rgb(31,31,31);"		//字体颜色
                                     "padding-left:20px;"       //内边距-字体缩进
                                     "background-color: rgb(255, 255, 255);" //背景颜色
                                     "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit_tele->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                     "color: rgb(31,31,31);"		//字体颜色
                                     "padding-left:20px;"       //内边距-字体缩进
                                     "background-color: rgb(255, 255, 255);" //背景颜色
                                     "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->label->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                             "color: rgb(31,31,31);"		//字体颜色
                             "padding-left:20px;"       //内边距-字体缩进
                             "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_address->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                     "color: rgb(31,31,31);"		//字体颜色
                                     "padding-left:20px;"       //内边距-字体缩进
                                     "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_age->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                 "color: rgb(31,31,31);"		//字体颜色
                                 "padding-left:20px;"       //内边距-字体缩进
                                 "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_hiredate->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                      "color: rgb(31,31,31);"		//字体颜色
                                      "padding-left:20px;"       //内边距-字体缩进
                                      "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_id->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                "color: rgb(31,31,31);"		//字体颜色
                                "padding-left:20px;"       //内边距-字体缩进
                                "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_name->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                  "color: rgb(31,31,31);"		//字体颜色
                                  "padding-left:20px;"       //内边距-字体缩进
                                  "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_tele->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                  "color: rgb(31,31,31);"		//字体颜色
                                  "padding-left:20px;"       //内边距-字体缩进
                                  "background-color: rgb(198,222,212);border-radius:15px;");
    this->setStyleSheet("background-color: rgb(244,252,250)");  //背景颜色

}

inputdialog::~inputdialog()
{
    delete ui;
}

QString inputdialog::is_Error()
{
    QString error;
    if(get_ID().isEmpty())
    {
        error="工号";
        return error;
    }
    else if(get_name().isEmpty())
    {
        error="姓名";
        return error;
    }
    else if(get_age().isEmpty())
    {
        error="年龄";
        return error;
    }
    else if(get_tele().isEmpty())
    {
        error="电话";
        return error;
    }
    else if(get_address().isEmpty())
    {
        error="住址";
        return error;
    }
    else
    {
        error="OK";
        return error;
    }
}

void inputdialog::Show_error(const QString &tempstr)
{
    ui->label->setText(tempstr);
    ui->label->setAlignment(Qt::Alignment());
}
void inputdialog::label_Show()
{
    QString error=is_Error();
    if(error=="OK") Show_error("点击OK即可添加!");
    else Show_error(QString("%1为空,请输入!!").arg(error));
}



QString inputdialog::get_ID()
{
    return ui->lineEdit_id->text();
}

QString inputdialog::get_name()
{
    return ui->lineEdit_name->text();
}

QString inputdialog::get_age()
{
    return ui->lineEdit_age->text();
}

QDate inputdialog::get_hid()
{
    return ui->dateEdit->date();
}

QString inputdialog::get_tele()
{
    return ui->lineEdit_tele->text();
}

QString inputdialog::get_address()
{
    return ui->lineEdit_address->text();
}



void inputdialog::on_lineEdit_id_editingFinished()
{
    label_Show();
}

void inputdialog::on_lineEdit_name_editingFinished()
{
    label_Show();
}

void inputdialog::on_lineEdit_age_editingFinished()
{
    label_Show();
}

void inputdialog::on_dateEdit_editingFinished()
{
    label_Show();
}


void inputdialog::on_lineEdit_tele_editingFinished()
{
    label_Show();
}

void inputdialog::on_lineEdit_address_editingFinished()
{
    label_Show();
}


void inputdialog::on_lineEdit_age_selectionChanged()
{
    label_Show();
}

void inputdialog::on_lineEdit_id_selectionChanged()
{
    label_Show();
}

void inputdialog::on_lineEdit_name_selectionChanged()
{
    label_Show();
}

void inputdialog::on_lineEdit_tele_selectionChanged()
{
    label_Show();
}

void inputdialog::on_lineEdit_address_selectionChanged()
{
    label_Show();
}

inputsalary 插入特定职工薪资信息

新建QT设计师类界面
qt 员工管理系统,QT项目,qt,开发语言,ui
inputsalary.h

#ifndef INPUTSALARY_H
#define INPUTSALARY_H

#include <QDialog>

namespace Ui {
class inputsalary;
}

class inputsalary : public QDialog
{
    Q_OBJECT

public:
    explicit inputsalary(QWidget *parent = nullptr);
    ~inputsalary();

    QString is_Error();
    void Show_error(const QString&tempstr);

    void show_Label();
    QString get_e_id();
    int get_month();
    double getBase_salary();
    double getPost_salary();
    double getseniority_salary();
    double getAllowance();
    double getPostAllowance();
    double getSubsidy();
    double getHousingSalary();
    double getTransSalary();


private slots:
// ui界面中点击转到槽
    void on_lineEdit_base_salary_selectionChanged();

    void on_lineEdit_post_salary_selectionChanged();

    void on_lineEdit_seniority_salary_selectionChanged();

    void on_lineEdit_allowance_selectionChanged();

    void on_lineEdit_post_allowance_selectionChanged();

    void on_lineEdit_subsidy_selectionChanged();

    void on_lineEdit_housing_salary_selectionChanged();

    void on_lineEdit_trans_salary_selectionChanged();

    void on_lineEdit_id_editingFinished();

private:
    Ui::inputsalary *ui;
};

#endif // INPUTSALARY_H

inputsalary.cpp

#include "inputsalary.h"
#include "ui_inputsalary.h"

inputsalary::inputsalary(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::inputsalary)
{
    ui->setupUi(this);
//设置样式表
    ui->buttonBox->setStyleSheet("QPushButton{font: 25 14pt '微软雅黑 Light';color: rgb(255,255,255);background-color: rgb(20,196,188);"
                                 "border: 2px groove gray; border-radius:15px ;padding:2px 4px;border-style: outset;}"
                                 "QPushButton:hover{background-color: rgb(22,218,208);}"//hover
                                 "QPushButton:pressed{background-color: rgb(17,171,164);}"//pressed
                                   "border:2px solid rgb(20,196,188);");
    ui->label_error->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                             "color: rgb(31,31,31);"		//字体颜色
                             "padding-left:20px;"       //内边距-字体缩进
                             "background-color: rgb(198,222,212);border-radius:15px;");
    ui->lineEdit_allowance->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                          "color: rgb(31,31,31);"		//字体颜色
                                          "padding-left:20px;"       //内边距-字体缩进
                                          "background-color: rgb(255, 255, 255);" //背景颜色
                                          "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit_base_salary->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                            "color: rgb(31,31,31);"		//字体颜色
                                            "padding-left:20px;"       //内边距-字体缩进
                                            "background-color: rgb(255, 255, 255);" //背景颜色
                                            "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit_housing_salary->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                               "color: rgb(31,31,31);"		//字体颜色
                                               "padding-left:20px;"       //内边距-字体缩进
                                               "background-color: rgb(255, 255, 255);" //背景颜色
                                               "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit_id->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                   "color: rgb(31,31,31);"		//字体颜色
                                   "padding-left:20px;"       //内边距-字体缩进
                                   "background-color: rgb(255, 255, 255);" //背景颜色
                                   "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit_post_allowance->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                               "color: rgb(31,31,31);"		//字体颜色
                                               "padding-left:20px;"       //内边距-字体缩进
                                               "background-color: rgb(255, 255, 255);" //背景颜色
                                               "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit_post_salary->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                            "color: rgb(31,31,31);"		//字体颜色
                                            "padding-left:20px;"       //内边距-字体缩进
                                            "background-color: rgb(255, 255, 255);" //背景颜色
                                            "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit_seniority_salary->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                                 "color: rgb(31,31,31);"		//字体颜色
                                                 "padding-left:20px;"       //内边距-字体缩进
                                                 "background-color: rgb(255, 255, 255);" //背景颜色
                                                 "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit_subsidy->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                        "color: rgb(31,31,31);"		//字体颜色
                                        "padding-left:20px;"       //内边距-字体缩进
                                        "background-color: rgb(255, 255, 255);" //背景颜色
                                        "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit_trans_salary->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                             "color: rgb(31,31,31);"		//字体颜色
                                             "padding-left:20px;"       //内边距-字体缩进
                                             "background-color: rgb(255, 255, 255);" //背景颜色
                                             "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->cBox_month->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                  "color: rgb(31,31,31);"		//字体颜色
                                  "padding-left:20px;"       //内边距-字体缩进
                                  "background-color: rgb(255, 255, 255);" //背景颜色
                                  "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->label_allowance->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                     "color: rgb(31,31,31);"		//字体颜色
                                     "padding-left:20px;"       //内边距-字体缩进
                                     "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_base_salary->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                         "color: rgb(31,31,31);"		//字体颜色
                                         "padding-left:20px;"       //内边距-字体缩进
                                         "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_housing_salary->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                            "color: rgb(31,31,31);"		//字体颜色
                                            "padding-left:20px;"       //内边距-字体缩进
                                            "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_id->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                "color: rgb(31,31,31);"		//字体颜色
                                "padding-left:20px;"       //内边距-字体缩进
                                "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_month->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                   "color: rgb(31,31,31);"		//字体颜色
                                   "padding-left:20px;"       //内边距-字体缩进
                                   "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_post_allowance->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                            "color: rgb(31,31,31);"		//字体颜色
                                            "padding-left:20px;"       //内边距-字体缩进
                                            "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_post_salary->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                         "color: rgb(31,31,31);"		//字体颜色
                                         "padding-left:20px;"       //内边距-字体缩进
                                         "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_seniority->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                       "color: rgb(31,31,31);"		//字体颜色
                                       "padding-left:20px;"       //内边距-字体缩进
                                       "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_subsidy->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                     "color: rgb(31,31,31);"		//字体颜色
                                     "padding-left:20px;"       //内边距-字体缩进
                                     "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_trans_salary->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                          "color: rgb(31,31,31);"		//字体颜色
                                          "padding-left:20px;"       //内边距-字体缩进
                                          "background-color: rgb(198,222,212);border-radius:15px;");
     this->setStyleSheet("background-color: rgb(244,252,250)");
}

inputsalary::~inputsalary()
{
    delete ui;
}

QString inputsalary::is_Error()
{
    QString error;
    if(get_e_id().isEmpty())
    {
        error="编号";
        return error;
    }
    else if(ui->lineEdit_base_salary->text().isEmpty())
    {
        error="基本工资";
        return error;
    }
    else if(ui->lineEdit_post_salary->text().isEmpty())
    {
        error="岗位工资";
        return error;
    }
    else if(ui->lineEdit_seniority_salary->text().isEmpty())
    {
        error="工龄工资";
        return error;
    }
    else if(ui->lineEdit_allowance->text().isEmpty())
    {
        error="津贴";
        return error;
    }
    else if(ui->lineEdit_post_allowance->text().isEmpty())
    {
        error="岗贴";
        return error;
    }
    else if(ui->lineEdit_subsidy->text().isEmpty())
    {
        error="补贴";
        return error;
    }
    else if(ui->lineEdit_housing_salary->text().isEmpty())
    {
        error="房贴";
        return error;
    }
    else if(ui->lineEdit_trans_salary->text().isEmpty())
    {
        error="交通补贴";
        return error;
    }
    else
    {
        error="OK";
        return error;
    }
}

void inputsalary::Show_error(const QString &tempstr)
{
    ui->label_error->setText(tempstr);
    ui->label_error->setAlignment(Qt::Alignment());
}

void inputsalary::show_Label()
{
    QString error=is_Error();
    if(error=="OK") Show_error("点击OK即可添加!");
    else Show_error(QString("%1为空!请输入!!").arg(error));
}


QString inputsalary::get_e_id()
{
    return ui->lineEdit_id->text();
}

int inputsalary::get_month()
{
    return ui->cBox_month->currentIndex()+1;
}

double inputsalary::getBase_salary()
{
    return ui->lineEdit_base_salary->text().toDouble();
}

double inputsalary::getPost_salary()
{
    return ui->lineEdit_post_salary->text().toDouble();
}

double inputsalary::getseniority_salary()
{
    return ui->lineEdit_seniority_salary->text().toDouble();
}

double inputsalary::getAllowance()
{
    return ui->lineEdit_allowance->text().toDouble();
}

double inputsalary::getPostAllowance()
{
    return ui->lineEdit_post_allowance->text().toDouble();
}

double inputsalary::getSubsidy()
{
    return ui->lineEdit_subsidy->text().toDouble();
}

double inputsalary::getHousingSalary()
{
    return ui->lineEdit_housing_salary->text().toDouble();
}

double inputsalary::getTransSalary()
{
    return ui->lineEdit_trans_salary->text().toDouble();
}

void inputsalary::on_lineEdit_base_salary_selectionChanged()
{
    show_Label();
}

void inputsalary::on_lineEdit_post_salary_selectionChanged()
{
    show_Label();
}

void inputsalary::on_lineEdit_seniority_salary_selectionChanged()
{
    show_Label();
}

void inputsalary::on_lineEdit_allowance_selectionChanged()
{
    show_Label();
}

void inputsalary::on_lineEdit_post_allowance_selectionChanged()
{
    show_Label();
}

void inputsalary::on_lineEdit_subsidy_selectionChanged()
{
    show_Label();
}

void inputsalary::on_lineEdit_housing_salary_selectionChanged()
{
    show_Label();
}

void inputsalary::on_lineEdit_trans_salary_selectionChanged()
{
    show_Label();
}


void inputsalary::on_lineEdit_id_editingFinished()
{
    show_Label();
}

selectdialog 查询特定职工(姓名,工号两种查询方式)

新建QT设计师类窗口
qt 员工管理系统,QT项目,qt,开发语言,ui
inputdialog.h

#ifndef SELECTDIALOG_H
#define SELECTDIALOG_H

#include <QDialog>

namespace Ui {
class selectdialog;
}

class selectdialog : public QDialog
{
    Q_OBJECT

public:
    explicit selectdialog(QWidget *parent = nullptr);
    ~selectdialog();

    QString get_Value();
    int get_Comboboxindex();
    QString get_Comboboxtext();

private slots:  //转到槽
    void on_comboBox_currentIndexChanged(const QString &arg1);

private:
    Ui::selectdialog *ui;
    int m_index;  //索引 0为工号查询,1为姓名查询
};

#endif // SELECTDIALOG_H

selectdialog.cpp

#include "selectdialog.h"
#include "ui_selectdialog.h"

selectdialog::selectdialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::selectdialog)
{
    ui->setupUi(this);

    m_index = 0; //初始化为0 

    ui->buttonBox->setStyleSheet("QPushButton{font: 25 14pt '微软雅黑 Light';color: rgb(255,255,255);background-color: rgb(20,196,188);"
                                 "border: 2px groove gray;border-radius:15px;padding:2px 4px;border-style: outset;}"
                                 "QPushButton:hover{background-color: rgb(22,218,208);}"//hover
                                 "QPushButton:pressed{background-color: rgb(17,171,164);}"//pressed
                                   "border:2px solid rgb(20,196,188);");
    ui->comboBox->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                "color: rgb(31,31,31);"		//字体颜色
                                "padding-left:20px;"       //内边距-字体缩进
                                "background-color: rgb(255, 255, 255);" //背景颜色
                                "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                "color: rgb(31,31,31);"		//字体颜色
                                "padding-left:20px;"       //内边距-字体缩进
                                "background-color: rgb(255, 255, 255);" //背景颜色
                                "border:2px solid rgb(20,196,188);border-radius:15px;");
    this->setStyleSheet("background-color: rgb(244,252,250)");
}

selectdialog::~selectdialog()
{
    delete ui;
}

QString selectdialog::get_Value()
{
    return ui->lineEdit->text();
}

int selectdialog::get_Comboboxindex()
{
    return m_index;
}

QString selectdialog::get_Comboboxtext()
{
    if(m_index==0) return QString("工号");
    else return QString("姓名");
}

void selectdialog::on_comboBox_currentIndexChanged(const QString &arg1)
{
    if(arg1=="工号")
        m_index=0;
    else m_index=1;
}

selectdialog1 查询特定职工的薪资信息(月份/编号)

新建设计师类界面
qt 员工管理系统,QT项目,qt,开发语言,ui
selectdialog1.h

#ifndef SELECTDIALOG1_H
#define SELECTDIALOG1_H

#include <QDialog>

namespace Ui {
class selectdialog1;
}

class selectdialog1 : public QDialog
{
    Q_OBJECT

public:
    explicit selectdialog1(QWidget *parent = nullptr);
    ~selectdialog1();

    QString get_Value();
    int get_Comboboxindex();
    QString get_Comboboxtext();
private slots:
    void on_comboBox_currentIndexChanged(const QString &arg1);

private:
    Ui::selectdialog1 *ui;
    int m_index;
};

#endif // SELECTDIALOG1_H

selectdialog1.cpp

#include "selectdialog1.h"
#include "ui_selectdialog1.h"

selectdialog1::selectdialog1(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::selectdialog1)
{
    ui->setupUi(this);
    m_index=0;

    ui->buttonBox->setStyleSheet("QPushButton{font: 25 14pt '微软雅黑 Light';color: rgb(255,255,255);background-color: rgb(20,196,188);"
                                 "border: 2px groove gray;border-radius:15px;padding:2px 4px;border-style: outset;}"
                                 "QPushButton:hover{background-color: rgb(22,218,208);}"//hover
                                 "QPushButton:pressed{background-color: rgb(17,171,164);}"//pressed
                                   "border:2px solid rgb(20,196,188);");
    ui->comboBox->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                "color: rgb(31,31,31);"		//字体颜色
                                "padding-left:20px;"       //内边距-字体缩进
                                "background-color: rgb(255, 255, 255);" //背景颜色
                                "border:2px solid rgb(20,196,188);border-radius:15px;");
    ui->lineEdit->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                "color: rgb(31,31,31);"		//字体颜色
                                "padding-left:20px;"       //内边距-字体缩进
                                "background-color: rgb(255, 255, 255);" //背景颜色
                                "border:2px solid rgb(20,196,188);border-radius:15px;");
    this->setStyleSheet("background-color: rgb(244,252,250)");
}

selectdialog1::~selectdialog1()
{
    delete ui;
}

QString selectdialog1::get_Value()
{
    return ui->lineEdit->text();
}

int selectdialog1::get_Comboboxindex()
{
    return m_index;
}

QString selectdialog1::get_Comboboxtext()
{
    if(m_index==0) return QString("月份");
    else return QString("编号");
}

void selectdialog1::on_comboBox_currentIndexChanged(const QString &arg1)
{
    if(arg1=="月份")
        m_index=0;
    else m_index=1;
}

mainwindow 主界面设计

ui界面
qt 员工管理系统,QT项目,qt,开发语言,ui
mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include"employeeinfotable.h"
#include<QMainWindow>
#include<QStandardItemModel>
#include<QAbstractItemDelegate>
#include<QModelIndex>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
// 职工信息视图
    void show_EmployeeTable();  //不可修改
    void show_Table_e_changed(); //可以修改
// 薪资信息视图
    void show_SalaryTable();  //不可修改
    void show_Table_s_changed(); //可以修改
// 查询页面视图
    void show_SelectTable(); //不可修改
    void show_Table_sc_changed(); //可以修改

private slots:
    void on_actionOpen_triggered();  //打开文件

    void on_actionSave_triggered();  //保存数据

    void on_actionReadData_triggered();  //读取数据

    void on_actionSaveAs_triggered();  //另存为

    void on_actionAddemployee_triggered(); //添加职工

    void on_actionemployeeinfo_triggered(); //职工信息视图

    void on_tableView_clicked(const QModelIndex &index);  //获取鼠标选中表格的索引

    void on_actionDelemployee_triggered(); //删除特定职工

    void on_actionAddsalary_triggered();  //为特定职工添加薪资信息

    void on_actionsalaryShow_triggered();  //薪资信息展示

    void on_actionDelsalary_triggered();  //删除某个薪资信息

    void on_actionSelect_triggered(); //查询

    void ShowInfotableViewchanged();  //修改数据

    void on_actionchange_triggered();  //修改

    void on_actionChangeSave_triggered();  //保存修改(退出修改)

    void on_tableView_doubleClicked(const QModelIndex &index);

    void on_actiontips_triggered();

    void on_actionaftertax_triggered();

    void on_actionstatistics_triggered();

    double aveaftertax(employee temp);

    double caltotalsalary(salary totals);


private:
    Ui::MainWindow *ui;
    QStandardItemModel *employeeTableView;
    employeeinfotable m_employees;

    int m_View_kind;  //0职工信息视图 1薪资信息视图 2从0中查询 3从1中查询 4特定薪资的职工信息

    int m_row; //0表中选中的行数
    QList<int> indexlist;  //记录0中查询结果索引,在查询视图可以进行删除、修改操作

    int m_row1;   //1表中选中的行数
    QList<int> indexlist1;  //记录1中查询结果索引,在查询视图可以进行删除、修改操作

    bool can_change; //是否进行修改
};
#endif // MAINWINDOW_H

mainwindow.cpp (代码超过1000 行,这里只截取部分)

1.构造函数

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include"selectdialog.h"
#include"selectdialog1.h"
#include"inputdialog.h"
#include"inputsalary.h"
#include"readonlydelegate.h"
#include"tipsdialog.h"
#include"tax.h"
#include"statistic.h"
#include<QFile>
#include<QApplication>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //建立view模型
    ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
    ui->tableView->setSelectionBehavior(QAbstractItemView::SelectItems);

    employeeTableView=new QStandardItemModel();
    //关联
    ui->tableView->setModel(employeeTableView);
    //信号与槽进行连接(后续可在tableView中直接修改)
    connect(ui->tableView->itemDelegate(),&QAbstractItemDelegate::closeEditor,
            this,&MainWindow::ShowInfotableViewchanged);
    //成员默认构造
    m_View_kind=0;
    m_row=-1;
    indexlist=QList<int>();
    m_row1=-1;
    indexlist1=QList<int>();
    can_change=false;
    //修改样式表
    ui->label_num->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                 "color: rgb(31,31,31);"		//字体颜色
                                 "padding-left:20px;"       //内边距-字体缩进
                                 "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_tips->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                  "color: rgb(31,31,31);"		//字体颜色
                                  "padding-left:20px;"       //内边距-字体缩进
                                  "background-color: rgb(198,222,212);border-radius:15px;");
    ui->label_title->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                   "color: rgb(31,31,31);"		//字体颜色
                                   "padding-left:20px;"       //内边距-字体缩进
                                   "background-color: rgb(198,222,212);border-radius:15px;");
    ui->tableView->setStyleSheet("font: 25 14pt '微软雅黑 Light';" //字体
                                 "color: rgb(31,31,31);"		//字体颜色
                                 "padding-left:20px;"       //内边距-字体缩进
                                 "background-color: rgb(255, 255, 255);" //背景颜色
                                 "border:2px groove gray;border-radius:10px;padding:2px 4px;");
    ui->menubar->setStyleSheet("font: 25 12pt '微软雅黑 Light';" //字体
                               "color: rgb(31,31,31);"		//字体颜色
                               "padding-left:20px;"       //内边距-字体缩进
                               "background-color: rgb(230,241,235);border-radius:15px;");
    this->setStyleSheet("background-color: rgb(244,252,250)");
}

2.修改数据

void MainWindow::ShowInfotableViewchanged()
{
    QModelIndex index = ui->tableView->currentIndex();
    int col = index.column();

    employee & temp_e = m_employees.Getemployee(m_row);
    QVariant data;  //数据

    switch(m_View_kind)
    {
    case 0: //职工信息视图
    {
        data = employeeTableView->data(index);
        switch(col)
        {
        case 0: //工号
            temp_e.id=data.toString();
            break;
        case 1: //姓名
            temp_e.name=data.toString();
            break;
        case 2: //年龄
            temp_e.age=data.toInt();
            break;
        case 3: //入职日期
            temp_e.hiredate=data.toDate();
            break;
        case 4: //电话
            temp_e.tele=data.toString();
            break;
        case 5: //住址
            temp_e.address=data.toString();
            break;
        default:
            break;
        }
        show_Table_e_changed();
        ui->label_tips->setText("修改已保存!");
        break;
    }
    case 1: //薪资信息视图
    {
        salary & temp_s=temp_e.m_salary.Getsalary(m_row1);
        data=employeeTableView->data(index);
        switch(col)
        {
        case 0: //薪资编号
            temp_s.e_id=data.toString();
            break;
        case 1: //月份
            temp_s.month=data.toInt();
            break;
        case 2: //基本工资
            temp_s.base_salary=data.toDouble();
            break;
        case 3: //岗位工资
            temp_s.post_salary=data.toDouble();
            break;
        case 4: //工龄工资
            temp_s.seniority_salary=data.toDouble();
            break;
        case 5: //津贴
            temp_s.allowance=data.toDouble();
            break;
        case 6: //岗贴
            temp_s.post_allowance=data.toDouble();
            break;
        case 7: //补贴
            temp_s.subsidy=data.toDouble();
            break;
        case 8: //房贴
            temp_s.housing_allowance=data.toDouble();
            break;
        case 9: //交通补贴
            temp_s.trans_allowance=data.toDouble();
            break;
        default:
            break;
        }
        show_Table_s_changed();
        ui->label_tips->setText("修改已保存!");
        break;
    }
    case 2: //职工信息查询视图
    {
        data = employeeTableView->data(index);
        switch(col)
        {
        case 0:
            temp_e.id=data.toString();
            break;
        case 1:
            temp_e.name=data.toString();
            break;
        case 2:
            temp_e.age=data.toInt();
            break;
        case 3:
            temp_e.hiredate=data.toDate();
            break;
        case 4:
            temp_e.tele=data.toString();
            break;
        case 5:
            temp_e.address=data.toString();
            break;
        default:
            break;
        }
        show_Table_sc_changed();
        ui->label_tips->setText("修改已保存!");
        break;
    }
    case 3: //薪资信息查询视图
    {
        salary & temp_s=temp_e.m_salary.Getsalary(m_row1);
        data = employeeTableView->data(index);
        switch(col)
        {
        case 0:
            temp_s.e_id=data.toString();
            break;
        case 1:
            temp_s.month=data.toInt();
            break;
        case 2:
            temp_s.base_salary=data.toDouble();
            break;
        case 3:
            temp_s.post_salary=data.toDouble();
            break;
        case 4:
            temp_s.seniority_salary=data.toDouble();
            break;
        case 5:
            temp_s.allowance=data.toDouble();
            break;
        case 6:
            temp_s.post_allowance=data.toDouble();
            break;
        case 7:
            temp_s.subsidy=data.toDouble();
            break;
        case 8:
            temp_s.housing_allowance=data.toDouble();
            break;
        case 9:
            temp_s.trans_allowance=data.toDouble();
            break;
        default:
            break;
        }
        show_Table_sc_changed();
        ui->label_tips->setText("修改已保存!");
        break;
    }
    }
}

  1. 显示职工信息(薪资信息同理)
void MainWindow::show_EmployeeTable()
{
    //不能修改
    ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    can_change=false;

    //显示职工信息
    m_View_kind=0;
//    重置选择行
    m_row=-1;
    m_row1=-1;
    ui->label_title->setText("职工信息视图");

    employeeTableView->clear();
    employeeTableView->setColumnCount(7);  //7列

//  表头
//  工号、姓名、年龄、入职日期、电话、住址、是否有工资信息
    QStringList templist;
    templist<<"工号"<<"姓名"<<"年龄"<<"入职日期"<<"电话"<<"住址"<<"是否有工资信息";
    employeeTableView->setHorizontalHeaderLabels(templist);

    int RowCnt = m_employees.employeeNum(); //行数(不含标题)
    employeeTableView->setRowCount(RowCnt);

    //遍历插入数据
    QStandardItem *aTempItem;  //临时的item
    QString tempstr;
    for(int i=0;i<RowCnt;++i)
    {
        employee temp_e=m_employees.Getemployee(i);

        tempstr=temp_e.id;
        aTempItem = new QStandardItem(tempstr);
        employeeTableView->setItem(i,0,aTempItem);

        tempstr=temp_e.name;
        aTempItem = new QStandardItem(tempstr);
        employeeTableView->setItem(i,1,aTempItem);

        tempstr=QString::number(temp_e.age);
        aTempItem = new QStandardItem(tempstr);
        employeeTableView->setItem(i,2,aTempItem);

        tempstr=temp_e.hiredate.toString("yyyy/MM/dd");
        aTempItem = new QStandardItem(tempstr);
        employeeTableView->setItem(i,3,aTempItem);

        tempstr=temp_e.tele;
        aTempItem = new QStandardItem(tempstr);
        employeeTableView->setItem(i,4,aTempItem);

        tempstr=temp_e.address;
        aTempItem = new QStandardItem(tempstr);
        employeeTableView->setItem(i,5,aTempItem);

        if(temp_e.is_salary()) tempstr="否";
        else tempstr="是";
        aTempItem = new QStandardItem(tempstr);
        employeeTableView->setItem(i,6,aTempItem);
    }
    ui->label_num->setText(QString("职工人数:%1人").arg(m_employees.employeeNum()));
//  设置内容为只读
    readonlydelegate* readOnlyDelegate = new readonlydelegate(this);
    ui->tableView->setItemDelegateForColumn(6,readOnlyDelegate);
}
void MainWindow::show_Table_e_changed()  //可以修改
{
    ui->tableView->setEditTriggers((QAbstractItemView::DoubleClicked));

    m_View_kind=0;
    m_row=-1;
    m_row1=-1;

    employeeTableView->clear();
    employeeTableView->setColumnCount(7);

    QStringList templist;
    templist<<"工号"<<"姓名"<<"年龄"<<"入职日期"<<"电话"<<"住址"<<"是否有工资信息";
    employeeTableView->setHorizontalHeaderLabels(templist);

    int RowCnt = m_employees.employeeNum();
    employeeTableView->setRowCount(RowCnt);

    QStandardItem *aTempItem;
    QString tempstr;
    for(int i=0;i<RowCnt;++i)
    {
        employee temp_e=m_employees.Getemployee(i);

        tempstr=temp_e.id;
        aTempItem = new QStandardItem(tempstr);
        employeeTableView->setItem(i,0,aTempItem);

        tempstr=temp_e.name;
        aTempItem = new QStandardItem(tempstr);
        employeeTableView->setItem(i,1,aTempItem);

        tempstr=QString::number(temp_e.age);
        aTempItem = new QStandardItem(tempstr);
        employeeTableView->setItem(i,2,aTempItem);

        tempstr=temp_e.hiredate.toString("yyyy/MM/dd");
        aTempItem = new QStandardItem(tempstr);
        employeeTableView->setItem(i,3,aTempItem);

        tempstr=temp_e.tele;
        aTempItem = new QStandardItem(tempstr);
        employeeTableView->setItem(i,4,aTempItem);

        tempstr=temp_e.address;
        aTempItem = new QStandardItem(tempstr);
        employeeTableView->setItem(i,5,aTempItem);

        if(temp_e.is_salary()) tempstr="否";
        else tempstr="是";
        aTempItem = new QStandardItem(tempstr);
        employeeTableView->setItem(i,6,aTempItem);
    }
    ui->label_num->setText(QString("职工人数:%1人").arg(m_employees.employeeNum()));

    readonlydelegate* readOnlyDelegate = new readonlydelegate(this);
    ui->tableView->setItemDelegateForColumn(6,readOnlyDelegate);
}

4.查询视图显示(在职工信息视图下查询职工,薪资信息视图下查询薪资)

void MainWindow::show_SelectTable()
{
    ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    can_change=false;

    //2-0  3-1
    if(m_View_kind==0||m_View_kind==2)
    {
        m_View_kind=2;
        m_row=-1;
        m_row1=-1;
        ui->label_title->setText("职工信息视图");

        employeeTableView->clear();
        employeeTableView->setColumnCount(7);

        QStringList templist;
        templist<<"工号"<<"姓名"<<"年龄"<<"入职日期"<<"电话"<<"住址"<<"是否有工资信息";
        employeeTableView->setHorizontalHeaderLabels(templist);

        int RowCnt = indexlist.size();
        employeeTableView->setRowCount(RowCnt);

        QStandardItem *aTempItem;
        QString tempstr;
        for(int i=0;i<RowCnt;i++)
        {
            employee temp_e=m_employees.Getemployee(indexlist[i]);

            tempstr=temp_e.id;
            aTempItem = new QStandardItem(tempstr);
            employeeTableView->setItem(i,0,aTempItem);

            tempstr=temp_e.name;
            aTempItem = new QStandardItem(tempstr);
            employeeTableView->setItem(i,1,aTempItem);

            tempstr=QString::number(temp_e.age);
            aTempItem = new QStandardItem(tempstr);
            employeeTableView->setItem(i,2,aTempItem);

            tempstr=temp_e.hiredate.toString("yyyy/MM/dd");
            aTempItem = new QStandardItem(tempstr);
            employeeTableView->setItem(i,3,aTempItem);

            tempstr=temp_e.tele;
            aTempItem = new QStandardItem(tempstr);
            employeeTableView->setItem(i,4,aTempItem);

            tempstr=temp_e.address;
            aTempItem = new QStandardItem(tempstr);
            employeeTableView->setItem(i,5,aTempItem);

            if(temp_e.is_salary()) tempstr="否";
            else tempstr="是";
            aTempItem = new QStandardItem(tempstr);
            employeeTableView->setItem(i,6,aTempItem);
        }
        ui->label_num->setText(QString("职工人数:%1人").arg(indexlist.size()));

        readonlydelegate* readOnlyDelegate = new readonlydelegate(this);
        ui->tableView->setItemDelegateForColumn(6,readOnlyDelegate);
    }
    else if(m_View_kind==1||m_View_kind==3)
    {
        m_View_kind=3;
        m_row1=-1;

        ui->label_title->setText(QString("工号:%1  姓名:%2  薪资信息: ").arg(m_employees.Getemployee(m_row).id).arg(m_employees.Getemployee(m_row).name));

        employeeTableView->clear();
        employeeTableView->setColumnCount(10);

        QStringList templist;
        templist<<"编号"<<"月份"<<"基本工资"<<"岗位工资"<<"工龄工资"<<"津贴"<<"岗贴"
               <<"补贴"<<"房贴"<<"交通补贴";
         employeeTableView->setHorizontalHeaderLabels(templist);

         int RowCnt=indexlist1.size();
         employeeTableView->setRowCount(RowCnt);

         QStandardItem *aTempItem;
         QString tempstr;
         for(int i=0;i<RowCnt;++i)
         {
             salary temp_e=m_employees.Getemployee(m_row).m_salary.Getsalary(indexlist1[i]);

             tempstr=temp_e.e_id;
             aTempItem = new QStandardItem(tempstr);
             employeeTableView->setItem(i,0,aTempItem);

             tempstr=QString::number(temp_e.month);
             aTempItem = new QStandardItem(tempstr);
             employeeTableView->setItem(i,1,aTempItem);

             tempstr=QString::number(temp_e.base_salary);
             aTempItem = new QStandardItem(tempstr);
             employeeTableView->setItem(i,2,aTempItem);

             tempstr=QString::number(temp_e.post_salary);
             aTempItem = new QStandardItem(tempstr);
             employeeTableView->setItem(i,3,aTempItem);

             tempstr=QString::number(temp_e.seniority_salary);
             aTempItem = new QStandardItem(tempstr);
             employeeTableView->setItem(i,4,aTempItem);

             tempstr=QString::number(temp_e.allowance);
             aTempItem = new QStandardItem(tempstr);
             employeeTableView->setItem(i,5,aTempItem);

             tempstr=QString::number(temp_e.post_allowance);
             aTempItem = new QStandardItem(tempstr);
             employeeTableView->setItem(i,6,aTempItem);

             tempstr=QString::number(temp_e.subsidy);
             aTempItem = new QStandardItem(tempstr);
             employeeTableView->setItem(i,7,aTempItem);

             tempstr=QString::number(temp_e.housing_allowance);
             aTempItem = new QStandardItem(tempstr);
             employeeTableView->setItem(i,8,aTempItem);

             tempstr=QString::number(temp_e.trans_allowance);
             aTempItem = new QStandardItem(tempstr);
             employeeTableView->setItem(i,9,aTempItem);
         }
         ui->label_num->setText(QString("薪资信息数:%1条").arg(RowCnt));
    }
}

5.打开文件

void MainWindow::on_actionOpen_triggered()  //打开文件
{   //打开一个文件
    QString curPath=QDir::currentPath();
    QString dlgTitle ="选择一个文件";
    QString filter="文本文件(*.txt);;所有文件(*.*)";
    QString aFileName=QFileDialog::getOpenFileName(this,dlgTitle,curPath,filter);

    if(aFileName.isEmpty())
    {
        ui->label_tips->setText("打开文件失败!");
        return ;
    }
    ui->label_tips->setText("正在打开文件。。。");
    //创建成功,打开文件
    QFile aFile(aFileName);

    if(!aFile.exists())  //文件不存在
    {
        ui->label_tips->setText("打开文件失败!");
        return;
    }
    if(!aFile.open(QIODevice::ReadOnly|QIODevice::Text)) //以文本方式打开
    {
        ui->label_tips->setText("打开文件失败!");
        return ;
    }

    m_employees=employeeinfotable(); //清空

    QTextStream aStream(&aFile);  //用文本流读取文件
    aStream.setCodec(QTextCodec::codecForName("system")); //显示汉字

    m_employees.ReadSalaryinfotable(aStream);
    aFile.close();  //关闭文件
    ui->label_tips->setText("文件读取成功!");

    show_EmployeeTable();
}

6.保存文件

void MainWindow::on_actionSave_triggered()
{   //保存一个文件
    QFile aFile("D:\\QTCode\\employeeMS\\data.txt");
    if(!aFile.open(QIODevice::WriteOnly|QIODevice::Text))  //保存为文本
    {
        ui->label_tips->setText("保存文件失败!");
        return;
    }
    QTextStream aStream(&aFile);//用文本流保存文件
    aStream.setCodec(QTextCodec::codecForName("system"));  //显示汉字

    m_employees.Saveemployeeinfotable(aStream);
    aFile.close();//关闭文件
    ui->label_tips->setText("文件已保存!");
}

7.文件另存为

void MainWindow::on_actionSaveAs_triggered()
{
    QString curPath=QDir::currentPath();
    QString dlgTitle = "另存一个文件";
    QString filter = "文本文件(*.txt);;所有文件(*.*)";
    QString aFileName=QFileDialog::getSaveFileName(this,dlgTitle,curPath,filter);
    if(aFileName.isEmpty())
    {
        ui->label_tips->setText("保存文件失败!");
        return ;
    }
    QFile aFile(aFileName);
    if(!aFile.open(QIODevice::WriteOnly|QIODevice::Text))
    {
        ui->label_tips->setText("保存文件失败!");
        return ;
    }

    QTextStream aStream(&aFile);
    aStream.setCodec(QTextCodec::codecForName("system"));

    m_employees.Saveemployeeinfotable(aStream);
    aFile.close();
    ui->label_tips->setText("文件保存成功!");
}

8.读取数据(默认路径)文章来源地址https://www.toymoban.com/news/detail-707788.html

void MainWindow::on_actionReadData_triggered()
{
    ui->label_tips->setText("正在读取数据。。。");
    QFile aFile("D:\\QTCode\\employeeMS\\data.txt");
    if(!aFile.exists())
    {
        ui->label_tips->setText("读取数据失败!");
        return ;
    }
    if(!aFile.open(QIODevice::ReadOnly | QIODevice::Text)) //以文本方式打开
    {

         ui->label_tips->setText("读取数据失败!");
        return;
    }

    QTextStream aStream(&aFile); //用文本流读取文件
    aStream.setCodec(QTextCodec::codecForName("system"));
    m_employees=employeeinfotable(); //清空

    m_employees.ReadSalaryinfotable(aStream);
    aFile.close();
    ui->label_tips->setText("数据读取成功!");
    show_EmployeeTable();
}
  1. 获得选择信息索引
//为tableView控件的槽函数,函数参数为鼠标选中的表格索引
void MainWindow::on_tableView_clicked(const QModelIndex &index)
{
    if(m_View_kind==0)
    {
        m_row=index.row();
        ui->label_tips->setText(QString("已选中工号为%1 姓名为%2的职工")
                                .arg(m_employees.Getemployee(m_row).id)
                                .arg(m_employees.Getemployee(m_row).name));
    }
    else if(m_View_kind==1)
    {
        m_row1=index.row();
        ui->label_tips->setText(QString("已选中编号为%1 月份为%2的薪资信息")
                                .arg(m_employees.Getemployee(m_row).m_salary.Getsalary(m_row1).e_id)
                                .arg(m_employees.Getemployee(m_row).m_salary.Getsalary(m_row1).month));
    }
    else if(m_View_kind==2)
    {
        if(indexlist.isEmpty()) m_row=-1;
        else
        {
            m_row = indexlist[index.row()];
            ui->label_tips->setText(QString("已选中工号为%1 姓名为%2的职工")
                                    .arg(m_employees.Getemployee(m_row).id
                                    .arg(m_employees.Getemployee(m_row).name)));
        }
    }
    else if(m_View_kind==3)
    {
        if(indexlist1.isEmpty()) m_row=-1;
        else
        {
            m_row1=indexlist1[index.row()];
            ui->label_tips->setText(QString("已选中编号为%1 月份为%2的薪资信息")
                                    .arg(m_employees.Getemployee(m_row).m_salary.Getsalary(m_row1).e_id)
                                    .arg(m_employees.Getemployee(m_row).m_salary.Getsalary(m_row1).month));
        }
    }
}
  1. 查询功能
void MainWindow::on_actionSelect_triggered()
{
    ui->label_tips->setText("正在查询。。。");
//  查询前清空索引列表
    indexlist.clear();
    indexlist1.clear();
//  在职工信息视图下
    if(m_View_kind==0||m_View_kind==2)
    {
        selectdialog sg1;
        sg1.setWindowTitle("职工信息查询");
        int ret=sg1.exec();

        if(ret==QDialog::Accepted)
        {
            int index =sg1.get_Comboboxindex(); //查询特征索引0为工号,1为姓名
            QString tempstr=sg1.get_Value();
//          遍历数据
            for(int i=0;i<m_employees.employeeNum();i++)
            {
                if(index==0)
                {
                    if(m_employees.Getemployee(i).id==tempstr)
                        indexlist.append(i);  //记录列表中
                }
                if(index==1)
                {
                    if(m_employees.Getemployee(i).name==tempstr)
                        indexlist.append(i);  //记录列表中
                }
            }
//          判断列表是否为空
            if(indexlist.isEmpty())
                ui->label_tips->setText(QString("未找到%1为%2的职工信息")
                                        .arg(sg1.get_Comboboxtext()).arg(tempstr));
            else
                ui->label_tips->setText(QString("成功找到%1为%2的职工信息")
                                        .arg(sg1.get_Comboboxtext()).arg(tempstr));

            show_SelectTable();
        }
        else ui->label_tips->setText("查询操作已取消!");
    }
//  在薪资信息视图下
    else if(m_View_kind==1||m_View_kind==3)
    {
        selectdialog1 sg1;
        sg1.setWindowTitle("薪资信息查询");
        int ret =sg1.exec();

        if(ret==QDialog::Accepted)
        {
            int index=sg1.get_Comboboxindex();//查询特征索引0为月份,1为编号
            QString tempstr=sg1.get_Value(); //查询特征值
//          遍历数据
            for(int i=0;i<m_employees.Getemployee(m_row).m_salary.salaryNum();i++)
            {
                salary temp = m_employees.Getemployee(m_row).m_salary.Getsalary(i);
                if(index==0)
                {
                    if(QString::number(temp.month)==tempstr)
                    indexlist1.append(i); //记录列表中
                }
                if(index==1)
                {
                    if(temp.e_id==tempstr)
                        indexlist1.append(i); //记录列表中
                }
            }
//          判断列表是否为空
            if(indexlist1.isEmpty())
                ui->label_tips->setText(QString("未找到%1为%2的薪资信息")
                                        .arg(sg1.get_Comboboxtext()).arg(sg1.get_Value()));
            else ui->label_tips->setText(QString("成功找到%1为%2的薪资信息!")
                                         .arg(sg1.get_Comboboxtext()).arg(sg1.get_Value()));

            show_SelectTable();
        }
        else ui->label_tips->setText("查询操作已取消!");
    }
    else
    {
        tipsdialog tig;
        tig.tips_show("请在职工信息视图或薪资信息视图下进行次操作!!!");
        tig.exec();
        ui->label_tips->setText("查询失败!");
    }
}

到了这里,关于QT5实现职工工资信息管理系统(文件读写)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 用c++实现职工管理系统

    首先带大家看看文件的结构以及树状图 以下是具体的思路: 职工管理系统可以用来管理公司内所有员工信息 本教程主要利用c++来实现一个基于多态的职工管理系统 公司中职工分为三类:普通员工、经理、老板、显示信息时,需要显示职工编号、职工姓名、职工岗位、以及职

    2024年02月08日
    浏览(25)
  • qt实现信息管理系统(学生信息管理系统)功能更完善

    信息系统代码地址:https://gitee.com/dxl96/StdMsgSystem 本学生信息管理系统同升级改造的幅度较大,涉及到的东西对于初学者来说,可能稍显复杂,可以先移步到 https://blog.csdn.net/IT_CREATE/article/details/82027462 查看简易的系统。 本系统引入日志管理,数据库选择支持sqllite、mysql,自

    2024年02月13日
    浏览(35)
  • 37基于java的职工管理系统设计与实现

    本章节给大家带来一个基于java的职工管理系统设计与实现,可适用于员工管理系统,企业员工管理系统,公司员工管理系统,企业人事管理系统,基于java职工管理系统,前后端分离,员工考勤管理系统,职工奖惩管理系统,职员合同管理,HR管理系统,人事HR管理系统等;

    2024年02月05日
    浏览(88)
  • mysql实现(工资管理系统)课程设计

    目录 1 需求分析 1 2 概念结构设计 2 3 逻辑结构设计 3 4 数据库物理设计与实施 5 5 访问系统库 10 6 总结 11 1 需求分析 本系统的主要目的是,明确查询公司职工某年某月的工资情况,通过职工工资管理系统,能明确的察看到从入职以来,每位职工的每月工资情况。同时也能查询

    2024年02月08日
    浏览(25)
  • C++实现简单的工资管理系统

    编译环境:VS2019    语言:C++ 项目描述: 实现一个简单的工资管理系统,可以进行添加员工、查询员工、显示员工信息、删除员工信息、修改员工信息以及退出系统。添加员工时可以输入员工工号、姓名、性别、年龄、工资和工时。查询、删除、修改都是按照工号进行操作

    2024年02月15日
    浏览(27)
  • Java GUI 实现工资管理系统

    主要的要求如下: 建立职工工资管理系统,要求实现职工基本信息管理(编号、姓名、性别、初始年月、工资等级等)、工资等级情况管理(工资等级、基本工资、岗位工资、交通补贴等)、每月职工变动工资管理(职工编号、月份、奖励工资、扣款等),并根据职工的工资

    2024年02月04日
    浏览(30)
  • vb+access工资管理系统的设计与实现

    本系统为工资发放系统,是为了能够对工资发放进行有效的管理而做,采用的开发工具是 Microsoft Visual Basic 6.0。 使用的技术有:数据库的访问;菜单控制。 本系统能够提供对工资发放各明细项目的数据编辑,自动计算出工资发放各项合计数据及代扣项目数据;可自主设定条

    2024年02月10日
    浏览(33)
  • 通用工资管理系统--SQL server课程设计(Java实现+SQL server)

    本科参与项目文档合集: 点击跳转~ General payroll management system 设计题目:通用工资管理系统 专 业:计算机科学与技术 班 级: 19级1班 设 计 人: 安** 指导老师: 刘** 日 期:2021年06月30日 1.1开发环境 数据库系统:Microsoft SQL Server 2019 开发语言:JAVA 数据库连接方式:JDBC连接方

    2024年02月03日
    浏览(39)
  • 职工管理系统(C++)

     职工管理系统有以下8个功能: - 增加职工信息:实现批量添加职工功能,将信息录入到文件中,职工信息为:职工编号、姓名、部门编号 - 显示职工信息:显示公司内部所有职工的信息 - 删除离职职工:按照编号删除指定的职工 - 修改职工信息:按照编号修改职工个人信息

    2024年02月01日
    浏览(32)
  • 程序设计职工管理系统

    本系统要求用 C 语言建立 一个职工信息管理系统 ,本职工信息管理系统可以实现对众多员工信息 的管理 。 包含 对 职工信息 进行 添加 、 查询 、 删除 、修改 。 1.2 系统的界面要求  按任意键便可以进入主菜单,在主菜单上显示出 该系统 的功能,通过输入数字 0 到 6  来

    2024年02月08日
    浏览(32)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包