1 Star 0 Fork 2

Sugarscat/EmployeeManagement-for-Qt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
frmaddemployee.cpp 1.97 KB
一键复制 编辑 原始数据 按行查看 历史
Sugarscat 提交于 2022-07-18 16:18 . main
#include "frmaddemployee.h"
#include "ui_frmaddemployee.h"
#include "Used_head.h"
#include "employeecontainer.h"
FrmAddEmployee::FrmAddEmployee(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::FrmAddEmployee)
{
ui->setupUi(this);
}
FrmAddEmployee::~FrmAddEmployee()
{
delete ui;
}
bool FrmAddEmployee::judge(int id, string name, string phone, string depart){
if(id <=0 || name == "" || phone == "" || depart == ""){
QMessageBox::critical(this, "错误", "添加失败!可能原因:\n编号小于1\n姓名、电话或部门为空!");
return false;
}
for(int i = 0; i < EmployeeContainer::employeelist->size(); i++){
Employee *emp = EmployeeContainer::employeelist->at(i);
if(id == emp->id){
QMessageBox::critical(this, "错误", "添加失败!存在编号相同的员工!");
return false;
}
}
return true;
}
void FrmAddEmployee::on_btnAddandContinue_clicked()
{
//构建对象
int id = ui->letId->text().toInt();
string name = ui->letName->text().toStdString();
string phone = ui->letPhone->text().toStdString();
string depart = ui->letDepart->text().toStdString();
Employee *emp = new Employee(id, name, phone, depart);
//将员工添加到容器中
if(judge(id, name, phone, depart)){
EmployeeContainer::employeelist->push_back(emp);
ui->letId->clear();
ui->letName->clear();
ui->letPhone->clear();
ui->letDepart->clear();
}
}
void FrmAddEmployee::on_btnAddandClose_clicked()
{
//构建对象
int id = ui->letId->text().toInt();
string name = ui->letName->text().toStdString();
string phone = ui->letPhone->text().toStdString();
string depart = ui->letDepart->text().toStdString();
Employee *emp = new Employee(id, name, phone, depart);
//将员工添加到容器中
if(judge(id, name, phone, depart)){
EmployeeContainer::employeelist->push_back(emp);
this->close();
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Sugarscat/EmployeeManagement-for-Qt.git
[email protected]:Sugarscat/EmployeeManagement-for-Qt.git
Sugarscat
EmployeeManagement-for-Qt
EmployeeManagement-for-Qt
main

搜索帮助