123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- #include "ProfessionInfo.h"
- #include "ui_ProfessionInfo.h"
- #include "dbService/DBServiceSet.h"
- #include "dbService/UserService.h"
- #include <QAction>
- #include <QCryptographicHash>
- ProfessionalInfo::ProfessionalInfo(QWidget *parent)
- : QDialog(parent), ui(new Ui::ProfessionalInfo), m_completeIt(false), m_done(false)
- {
- ui->setupUi(this);
- setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
- this->setAttribute(Qt::WA_DeleteOnClose);
- QDateTime curDateTime = QDateTime::currentDateTime();
- ui->dateTimeEdit->setDateTime(curDateTime);
- ui->dateTimeEdit->setCalendarPopup(true);
- ui->roleCombx->addItems({ "超级管理员", "普通管理员", "专家" });
- ui->roleCombx->setCurrentIndex(2);
- ui->errorMsglabel->setText("");
- QAction *passAction = new QAction(ui->passwordEdit);
- passAction->setIcon(QIcon(":/res/pass_hide.png"));
- connect(passAction, &QAction::triggered, [=]() {
- if (ui->passwordEdit->echoMode() == QLineEdit::Password) {
- passAction->setIcon(QIcon(":/res/pass_show.png"));
- ui->passwordEdit->setEchoMode(QLineEdit::Normal);
- } else {
- passAction->setIcon(QIcon(":/res/pass_hide.png"));
- ui->passwordEdit->setEchoMode(QLineEdit::Password);
- }
- });
- ui->passwordEdit->addAction(passAction, QLineEdit::TrailingPosition);
- ui->passwordEdit->setText("123456");
- ui->passwordEdit->setEchoMode(QLineEdit::Password);
- connect(ui->noEdit, &QLineEdit::textChanged, this, &ProfessionalInfo::textChanged);
- connect(ui->passwordEdit, &QLineEdit::textChanged, this, &ProfessionalInfo::textChanged);
- connect(ui->nameEdit, &QLineEdit::textChanged, this, &ProfessionalInfo::textChanged);
- connect(ui->workPlaceEdit, &QLineEdit::textChanged, this, &ProfessionalInfo::textChanged);
- connect(ui->jobEdit, &QLineEdit::textChanged, this, &ProfessionalInfo::textChanged);
- connect(ui->majorEdit, &QLineEdit::textChanged, this, &ProfessionalInfo::textChanged);
- connect(ui->phoneEdit, &QLineEdit::textChanged, this, &ProfessionalInfo::textChanged);
- setCompleteIt(false);
- ui->sureButton->setVisible(false);
- ui->roleLabel->setVisible(false);
- ui->roleCombx->setVisible(false);
- }
- ProfessionalInfo::~ProfessionalInfo()
- {
- delete ui;
- }
- bool ProfessionalInfo::completeIt()
- {
- return m_completeIt;
- }
- void ProfessionalInfo::setCompleteIt(bool complete)
- {
- m_completeIt = complete;
- if (!m_completeIt) { // 管理员
- ui->noEdit->setEnabled(true);
- ui->passwordEdit->setEnabled(true);
- ui->nameEdit->setEnabled(true);
- ui->roleCombx->setEnabled(true);
- ui->dateTimeEdit->setEnabled(true);
- ui->workPlaceLabel->setEnabled(false);
- ui->workPlaceEdit->setEnabled(false);
- ui->workPlaceEdit->setPlaceholderText("管理员不填");
- ui->jobLabel->setEnabled(false);
- ui->jobEdit->setEnabled(false);
- ui->jobEdit->setPlaceholderText("管理员不填");
- ui->majorLabel->setEnabled(false);
- ui->majorEdit->setEnabled(false);
- ui->majorEdit->setPlaceholderText("管理员不填");
- ui->phoneLabel->setEnabled(false);
- ui->phoneEdit->setEnabled(false);
- ui->phoneEdit->setPlaceholderText("管理员不填");
- } else {
- ui->noEdit->setEnabled(false);
- ui->passwordEdit->setEnabled(false);
- ui->nameEdit->setEnabled(false);
- ui->roleCombx->setEnabled(false);
- ui->workPlaceLabel->setEnabled(true);
- ui->workPlaceEdit->setEnabled(true);
- ui->workPlaceEdit->setPlaceholderText("请输入单位名称");
- ui->jobLabel->setEnabled(true);
- ui->jobEdit->setEnabled(true);
- ui->jobEdit->setPlaceholderText("请输入职业名称");
- ui->majorLabel->setEnabled(true);
- ui->majorEdit->setEnabled(true);
- ui->majorEdit->setPlaceholderText("请输入专业");
- ui->phoneLabel->setEnabled(true);
- ui->phoneEdit->setEnabled(true);
- ui->phoneEdit->setPlaceholderText("请输入手机号");
- ui->dateTimeEdit->setEnabled(false);
- }
- }
- void ProfessionalInfo::setPerson(const QFUser &person)
- {
- m_userId = person.id;
- ui->noEdit->setText(person.userNo);
- ui->passwordEdit->setText(person.password);
- ui->roleCombx->setCurrentIndex(person.role);
- ui->nameEdit->setText(person.userName);
- ui->workPlaceEdit->setText(person.workPosition);
- ui->jobEdit->setText(person.post);
- ui->majorEdit->setText(person.major);
- ui->phoneEdit->setText(person.phone);
- ui->dateTimeEdit->setDateTime(QDateTime::fromString(person.writeTime));
- ui->remarkEdit->setText(person.remark);
- }
- void ProfessionalInfo::setSureButtonVisible()
- {
- ui->saveBtn->setVisible(false);
- ui->sureButton->setVisible(true);
- ui->passwordEdit->setVisible(false);
- ui->passwordLabel->setVisible(false);
- }
- void ProfessionalInfo::setDetailButtonVisible()
- {
- ui->saveBtn->setVisible(false);
- ui->sureButton->setVisible(false);
- ui->clearBtn->setVisible(false);
- ui->passwordLabel->setVisible(false);
- ui->passwordEdit->setVisible(false);
- this->setDisabled(true);
- }
- void ProfessionalInfo::on_saveBtn_clicked()
- {
- m_done = false;
- if (!ui->errorMsglabel->text().isEmpty()) {
- return;
- }
- QFUser user;
- user.userNo = ui->noEdit->text().trimmed();
- if (user.userNo.isEmpty()) {
- ui->errorMsglabel->setText("账号不能为空");
- return;
- }
- QString password = ui->passwordEdit->text().trimmed();
- if (password.isEmpty()) {
- ui->errorMsglabel->setText("密码不能为空");
- return;
- }
- QCryptographicHash ch(QCryptographicHash::Md5);
- QString md5str;
- QByteArray md5bytes = QCryptographicHash::hash(password.toLatin1(), QCryptographicHash::Md5);
- md5str.prepend(md5bytes.toHex());
- user.password = md5str;
- if (ui->roleCombx->currentIndex() < 0) {
- ui->errorMsglabel->setText("请选择用户权限");
- return;
- }
- user.role = static_cast<QFUser::Role>(ui->roleCombx->currentIndex());
- user.userName = ui->nameEdit->text().trimmed();
- if (user.userName.isEmpty()) {
- ui->errorMsglabel->setText("专家名不能为空");
- return;
- }
- if (m_completeIt) {
- user.workPosition = ui->workPlaceEdit->text().trimmed();
- if (user.workPosition.isEmpty()) {
- ui->errorMsglabel->setText("工作单位不能为空");
- return;
- }
- user.post = ui->jobEdit->text().trimmed();
- if (user.post.isEmpty()) {
- ui->errorMsglabel->setText("职务不能为空");
- return;
- }
- user.major = ui->majorEdit->text().trimmed();
- if (user.major.isEmpty()) {
- ui->errorMsglabel->setText("专业不能为空");
- return;
- }
- user.phone = ui->phoneEdit->text().trimmed();
- // if (user.phone.isEmpty()) {
- // ui->errorMsglabel->setText("手机号码不能为空");
- // return;
- // } else if (user.phone.count() != 11) {
- // ui->errorMsglabel->setText("手机号码必须11位");
- // return;
- // }
- } else {
- user.workPosition = "";
- user.post = "";
- user.major = "";
- user.educationDegree = "";
- user.phone = "";
- }
- user.writeTime = ui->dateTimeEdit->text();
- user.projectId = "";
- user.remark = ui->remarkEdit->toPlainText();
- ui->errorMsglabel->setText("");
- if (m_completeIt) {
- user.id = m_userId;
- if (!UserService().UpdateUserInfo(user)) {
- ui->errorMsglabel->setText("更新用户信息出错!");
- return;
- }
- } else {
- if (-1 == UserService().AddUserInfo(user)) {
- ui->errorMsglabel->setText("用户名已存在或者数据库存储异常!");
- return;
- }
- }
- m_done = true;
- emit saveNewUser();
- this->close();
- }
- void ProfessionalInfo::on_clearBtn_clicked()
- {
- m_done = false;
- QDateTime curDateTime = QDateTime::currentDateTime();
- // ui->nameEdit->clear();
- ui->dateTimeEdit->setDateTime(curDateTime);
- ui->workPlaceEdit->clear();
- ui->jobEdit->clear();
- ui->majorEdit->clear();
- ui->phoneEdit->clear();
- ui->remarkEdit->clear();
- }
- void ProfessionalInfo::textChanged(const QString &text)
- {
- QLineEdit *edit = static_cast<QLineEdit *>(sender());
- if (text.trimmed().isEmpty()) {
- ui->errorMsglabel->setText("输入不能为空!");
- edit->setText("");
- } else {
- ui->errorMsglabel->setText("");
- bool ok = true;
- if (edit == ui->noEdit || edit == ui->passwordEdit) {
- for (auto c : ui->noEdit->text()) {
- if (c.unicode() >= 127) {
- ok = false;
- break;
- }
- }
- if (!ok) {
- ui->errorMsglabel->setText("账号或密码不能出现非字母或者数字");
- }
- } else if (edit == ui->phoneEdit) {
- if (ui->phoneEdit->text().trimmed().count() > 11) {
- ui->errorMsglabel->setText("手机号不能大于11位");
- } else {
- ui->phoneEdit->text().trimmed().toLongLong(&ok);
- if (!ok) {
- ui->errorMsglabel->setText("手机号不能出现非数字");
- }
- }
- }
- }
- }
- void ProfessionalInfo::closeEvent(QCloseEvent *event)
- {
- if (m_done) {
- emit addNewPro(ui->nameEdit->text().trimmed());
- } else {
- emit addNewPro("");
- }
- }
- void ProfessionalInfo::on_sureButton_clicked()
- {
- m_done = false;
- if (!ui->errorMsglabel->text().isEmpty()) {
- return;
- }
- QFUser user;
- user.userNo = ui->noEdit->text().trimmed();
- if (user.userNo.isEmpty()) {
- ui->errorMsglabel->setText("账号不能为空");
- return;
- }
- QString password = ui->passwordEdit->text().trimmed();
- if (password.isEmpty()) {
- ui->errorMsglabel->setText("密码不能为空");
- return;
- }
- QCryptographicHash ch(QCryptographicHash::Md5);
- QString md5str;
- QByteArray md5bytes = QCryptographicHash::hash(password.toLatin1(), QCryptographicHash::Md5);
- md5str.prepend(md5bytes.toHex());
- user.password = md5str;
- if (ui->roleCombx->currentIndex() < 0) {
- ui->errorMsglabel->setText("请选择用户权限");
- return;
- }
- user.role = static_cast<QFUser::Role>(ui->roleCombx->currentIndex());
- user.userName = ui->nameEdit->text().trimmed();
- if (user.userName.isEmpty()) {
- ui->errorMsglabel->setText("专家名不能为空");
- return;
- }
- user.workPosition = ui->workPlaceEdit->text().trimmed();
- if (user.workPosition.isEmpty()) {
- ui->errorMsglabel->setText("工作单位不能为空");
- return;
- }
- user.post = ui->jobEdit->text().trimmed();
- if (user.post.isEmpty()) {
- ui->errorMsglabel->setText("职务不能为空");
- return;
- }
- user.major = ui->majorEdit->text().trimmed();
- if (user.major.isEmpty()) {
- ui->errorMsglabel->setText("专业不能为空");
- return;
- }
- user.phone = ui->phoneEdit->text().trimmed();
- user.writeTime = ui->dateTimeEdit->text();
- user.projectId = "";
- user.remark = ui->remarkEdit->toPlainText();
- ui->errorMsglabel->setText("");
- user.id = m_userId;
- QFUser info;
- if (UserService().QueryUserInfoById2(&info, user.id)) {
- if (!UserService().UpdateUserInfo2(user)) {
- ui->errorMsglabel->setText("更新用户信息出错!");
- return;
- }
- } else {
- if (-1 == UserService().AddUserInfo2(user)) {
- ui->errorMsglabel->setText("用户名已存在或者数据库存储异常!");
- return;
- }
- }
- m_done = true;
- emit saveNewUser();
- this->close();
- }
|