Newer
Older
CasicBioRecNew / AddPersonForm.cpp
#include "AddPersonForm.h"
#include "ui_AddPersonForm.h"

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

    // 加载css文件设置控件样式
    QFile file(QApplication::applicationDirPath() + "/qss/addPerson.css");
    if (file.open(QFile::ReadOnly))
    {
        QString qssStr = QLatin1String(file.readAll());
        this->setStyleSheet(qssStr);
        file.close();
    }

    SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr());
}

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

void AddPersonForm::setPersonId(QString personId)
{
    this->personId = personId;
}

void AddPersonForm::updateFormTitle(QString title)
{
    ui->labPersonTitle->setText(title);
}

void AddPersonForm::loadPersonInfo(QString personId)
{
    SysPersonDao personDao;
    QVariantMap person = personDao.findRecordById(personId);
    if (person.isEmpty() == false)
    {
        // 赋值姓名
        ui->inputName->setText(person.find("name")->toString());
        ui->inputName->setDisabled(true);
        // 赋值员工编号
        ui->inputCardNo->setText(person.find("person_code")->toString());
        ui->inputCardNo->setDisabled(true);
        // 赋值性别 如果不为空则不能修改
        QString gender = person.find("gender")->toString();
        if (gender == "1")
        {
            ui->radioMale->setChecked(true);
            ui->radioFemale->setDisabled(true);
        } else if (gender == "2")
        {
            ui->radioMale->setDisabled(true);
            ui->radioFemale->setChecked(true);
        } else
        {
            ui->radioMale->setChecked(false);
            ui->radioMale->setChecked(false);
        }
        // 赋值部门 部门可以重新选择
        QString deptId = person.find("deptid")->toString();
        SelectDeptUtil::getInstance().checkDeptSelected(ui->selectDept, CacheManager::getInstance().getDeptCachePtr(), deptId);

        // 查询并显示人脸照片
        FaceDataImgDao faceImgDao;
        QVariantMap faceImage = faceImgDao.findRecordByPersonId(personId);
        ui->labPhotoFace->setPixmap(QPixmap(":/images/photoFace.png"));
        if (faceImage.isEmpty() == false)
        {
            if (faceImage.find("face_image")->toString().isEmpty() == false)
            {
                QString imageData = faceImage.find("face_image")->toString();
                QImage image;
                QPixmap pixmap;
                image.loadFromData(QByteArray::fromBase64(imageData.toLatin1()));
                pixmap = QPixmap::fromImage(image);
                pixmap.scaledToHeight(ui->labPhotoFace->height(), Qt::SmoothTransformation);
                ui->labPhotoFace->setPixmap(pixmap);
            }
        }

        // 查询并显示虹膜照片
        IrisDataImgDao irisImgDao;
        QVariantMap irisImage = irisImgDao.findRecordByPersonId(personId);
        ui->labPhotoEyeLeft->setPixmap(QPixmap(":/images/photoEyeLeft.png"));
        ui->labPhotoEyeRight->setPixmap(QPixmap(":/images/photoEyeRight.png"));
        if (irisImage.isEmpty() == false)
        {
            if (irisImage.find("left_image1")->toString().isEmpty() == false)
            {
                QString imageDataLeft = irisImage.find("left_image1")->toString();
                QImage imageLeft;
                QPixmap pixmapLeft;
                imageLeft.loadFromData(QByteArray::fromBase64(imageDataLeft.toLatin1()));
                pixmapLeft = QPixmap::fromImage(imageLeft);
                pixmapLeft = pixmapLeft.scaled(200, 150);
                ui->labPhotoEyeLeft->setPixmap(pixmapLeft);
            }

            if (irisImage.find("right_image1")->toString().isEmpty() == false)
            {
                QString imageDataRight = irisImage.find("right_image1")->toString();
                QImage imageRight;
                QPixmap pixmapRight;
                imageRight.loadFromData(QByteArray::fromBase64(imageDataRight.toLatin1()));
                pixmapRight = QPixmap::fromImage(imageRight);
                pixmapRight = pixmapRight.scaled(200, 150);
                ui->labPhotoEyeRight->setPixmap(pixmapRight);
            }
        }

        // 查询并显示识别记录

    }
}

void AddPersonForm::clearPersonInfo()
{
    ui->inputName->setDisabled(false);
    ui->inputCardNo->setDisabled(false);
    ui->radioMale->setDisabled(false);
    ui->radioFemale->setDisabled(false);
    ui->radioMale->setAutoExclusive(false);
    ui->radioFemale->setAutoExclusive(false);

    ui->inputName->setText("");
    ui->inputCardNo->setText("");
    ui->radioMale->setChecked(false);
    ui->radioFemale->setChecked(false);
    ui->selectDept->setCurrentIndex(0);

    ui->radioMale->setAutoExclusive(true);
    ui->radioFemale->setAutoExclusive(true);

    ui->labPhotoFace->setScaledContents(false);
    ui->labPhotoFace->setPixmap(QPixmap(":/images/photoFace.png"));

    ui->labPhotoEyeLeft->setPixmap(QPixmap(":/images/photoEyeLeft.png"));
    ui->labPhotoEyeRight->setPixmap(QPixmap(":/images/photoEyeRight.png"));
}

void AddPersonForm::on_btnBack_clicked()
{
    emit switchToUserListForm();
}

void AddPersonForm::on_btnHome_clicked()
{
    emit backToHomePage();
}

void AddPersonForm::on_btnSave_clicked()
{
    SysPersonDao personDao;
    if (personId.isEmpty() == false)
    {
        // 人员信息编辑
        QVariantMap perToEdit;
        perToEdit.insert("deptid", ui->selectDept->currentData().toString());
        QString gender = "";
        if (ui->radioMale->isChecked())
        {
            gender = "1";
        } else if (ui->radioFemale->isChecked())
        {
            gender = "2";
        }
        perToEdit.insert("gender", gender);
        personDao.edit(perToEdit, personId);
    } else {
        // 人员注册
        QVariantMap perToRegist;

        perToRegist.insert("name", ui->inputName->text());
        perToRegist.insert("person_code", ui->inputCardNo->text());
        perToRegist.insert("deptid", ui->selectDept->currentData().toString());
        QString gender = "";
        if (ui->radioMale->isChecked())
        {
            gender = "1";
        } else if (ui->radioFemale->isChecked())
        {
            gender = "2";
        }
        perToRegist.insert("gender", gender);
        QString perIdReg = personDao.save(perToRegist);

        emit switchToUserListForm();
    }

}