代码拉取完成,页面将自动刷新
#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();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。