Browse Source

Add user;
Show remark;

chengxr 1 year ago
parent
commit
a3c6db2b06

+ 2 - 0
QFD/QFD.pro

@@ -60,6 +60,7 @@ INCLUDEPATH += $$PWD/widgets
 INCLUDEPATH += $$PWD/common
 
 SOURCES += \
+    common/ExpertManager.cpp \
     common/QFDAlert.cpp \
     common/QFDConfig.cpp \
     common/QFDIcon.cpp \
@@ -90,6 +91,7 @@ SOURCES += \
     widgets/SchemeWidget.cpp
 
 HEADERS += \
+    common/ExpertManager.h \
     common/QFDAlert.h \
     common/QFDConfig.h \
     common/QFDIcon.h \

+ 26 - 1
QFD/common/QFDAlert.cpp

@@ -11,6 +11,7 @@ void QFDAlert::showAlertWithCode(int code, QWidget *w)
     }
 
     QString msg;
+    QFDAlertType type = Alert;
 
     if (code == QF_CODE_EMPTY_ACCOUNT) {
         msg = "账号不能为空";
@@ -28,7 +29,31 @@ void QFDAlert::showAlertWithCode(int code, QWidget *w)
         msg = "数据异常";
     }
 
+    if (code == QF_CODE_EMPTY_USERNAME) {
+        msg = "专家名不能为空";
+    } else if (code == QF_CODE_ACCOUNT_OCCUPIED) {
+        msg = "用户名已存在或者数据库存储异常!";
+    } else if (code == QF_CODE_ADD_USER_SUCCEEDED) {
+        msg  = "已添加";
+        type = Success;
+    }
+
     if (!msg.isEmpty()) {
-        InfoBar::warning("提示", msg, Qt::Horizontal, false, 2000, InfoBarPosition::TOP_RIGHT, w);
+        switch (type) {
+        case None:
+            break;
+        case Info:
+            InfoBar::info("提示", msg, Qt::Horizontal, false, 2000, InfoBarPosition::TOP_RIGHT, w);
+            break;
+        case Success:
+            InfoBar::success("提示", msg, Qt::Horizontal, false, 2000, InfoBarPosition::TOP_RIGHT, w);
+            break;
+        case Alert:
+            InfoBar::warning("提示", msg, Qt::Horizontal, false, 2000, InfoBarPosition::TOP_RIGHT, w);
+            break;
+        case Error:
+            InfoBar::error("提示", msg, Qt::Horizontal, false, 2000, InfoBarPosition::TOP_RIGHT, w);
+            break;
+        }
     }
 }

+ 9 - 0
QFD/common/QFDAlert.h

@@ -8,6 +8,15 @@ class QFDAlert : public QObject
     Q_OBJECT
 
 public:
+    typedef enum
+    {
+        None,
+        Info,
+        Success,
+        Alert,
+        Error,
+    } QFDAlertType;
+
     static void showAlertWithCode(int code, QWidget *w);
 };
 

+ 10 - 5
QFD/dbService/ClassSet.cpp

@@ -133,7 +133,12 @@ QString QFUser::nameOfRole(QFUser::Role role)
 
 QFUser::QFUser() { }
 
-QFUser::QFUser(const QString userId, const QString password) : userNo(userId), rawPassword(password) { }
+QFUser::QFUser(const QString userId, const QString password) : userNo(userId), m_rawPassword(password) { }
+
+const QString QFUser::rawPassword() const
+{
+    return m_rawPassword;
+}
 
 QFUser *QFUser::currentUser()
 {
@@ -165,7 +170,7 @@ int QFUser::resetAdmin(QString account, QString password, QString repeatPassword
         return QF_CODE_EMPTY_PASSWORD;
     } else if (password != repeatPassword) {
         return QF_CODE_PASSWORD_NOT_SAME;
-    } else if (password == rawPassword) {
+    } else if (password == m_rawPassword) {
         return QF_CODE_PASSWORD_UNCHANGED;
     }
 
@@ -191,7 +196,7 @@ int QFUser::login()
         return QF_CODE_EMPTY_ACCOUNT;
     }
 
-    if (rawPassword.isEmpty()) {
+    if (m_rawPassword.isEmpty()) {
         return QF_CODE_EMPTY_PASSWORD;
     }
 
@@ -201,10 +206,10 @@ int QFUser::login()
 
     QCryptographicHash ch(QCryptographicHash::Md5);
     QString md5str;
-    QByteArray md5bytes = QCryptographicHash::hash(rawPassword.toLatin1(), QCryptographicHash::Md5);
+    QByteArray md5bytes = QCryptographicHash::hash(m_rawPassword.toLatin1(), QCryptographicHash::Md5);
     md5str.prepend(md5bytes.toHex());
 
-    m_currentUser = new QFUser(userNo, rawPassword);
+    m_currentUser = new QFUser(userNo, m_rawPassword);
     if (!DBServiceSet().QueryUserByNoAndPassword(m_currentUser, userNo, md5str)) {
         delete m_currentUser;
         m_currentUser = nullptr;

+ 8 - 3
QFD/dbService/ClassSet.h

@@ -5,8 +5,9 @@
 
 #include <QDate>
 
-const int QF_CODE_SUCCEEDED     = 1000;
-const int QF_CODE_ALREADY_LOGIN = 1001;
+const int QF_CODE_SUCCEEDED          = 1000;
+const int QF_CODE_ALREADY_LOGIN      = 1001;
+const int QF_CODE_ADD_USER_SUCCEEDED = 1002;
 
 const int QF_CODE_FAILED             = 2000;
 const int QF_CODE_EMPTY_ACCOUNT      = 2001;
@@ -17,6 +18,8 @@ const int QF_CODE_NOT_LOGIN          = 2005;
 const int QF_CODE_PASSWORD_NOT_SAME  = 2006;
 const int QF_CODE_PASSWORD_UNCHANGED = 2007;
 const int QF_CODE_DATA_ERROR         = 2008;
+const int QF_CODE_EMPTY_USERNAME     = 2009;
+const int QF_CODE_ACCOUNT_OCCUPIED   = 2010;
 
 /**
  * @projectName   QFD
@@ -104,6 +107,8 @@ public:
 
     QFUser(const QString userId, const QString password);
 
+    const QString rawPassword() const;
+
     static QFUser *currentUser();
 
     QString roleName() const;
@@ -115,7 +120,7 @@ public:
     int resetAdmin(QString account, QString password, QString repeatPassword);  // 修改管理员账号
 
 private:
-    QString rawPassword;
+    QString m_rawPassword;
 };
 
 /**

+ 6 - 6
QFD/dbService/DBServiceSet.cpp

@@ -1720,11 +1720,11 @@ int DBServiceSet::AddUserInfo(const QFUser &userInfo)
         returnId = getNextId("t_user_info");
         Transaction t(SqlDBHelper::getDatabase());
         InsertQuery query = t.insertInto("t_user_info (user_name, user_no, password, role, post, "
-                                         "major,work_position,education_degree,phone,project_id,write_time)");
+                                         "major,work_position,education_degree,phone,project_id,write_time,remark)");
         NonQueryResult result =
                 query.values(userInfo.userName, userInfo.userNo, userInfo.password, userInfo.role, userInfo.post,
                              userInfo.major, userInfo.workPosition, userInfo.educationDegree, userInfo.phone,
-                             userInfo.projectId, userInfo.writeTime)
+                             userInfo.projectId, userInfo.writeTime, userInfo.remark)
                         .exec();
         t.commit();
         returnId = result.lastInsertId().toInt();
@@ -1892,7 +1892,7 @@ bool DBServiceSet::QueryUserListByEngineerId(QList<QFUser *> *userInfoList, int
     if (query.exec(selectSql)) {
         while (query.next()) {
             if (query.isNull(0) == false) {
-                QFUser *userInfo        = new QFUser();
+                QFUser *userInfo          = new QFUser();
                 userInfo->id              = query.value(0).toInt();
                 userInfo->userName        = query.value(1).toString();
                 userInfo->userNo          = query.value(2).toString();
@@ -1933,7 +1933,7 @@ bool DBServiceSet::QueryUserListByColumnAndColumnValue(QList<QFUser *> *userInfo
     if (query.exec(selectSql)) {
         while (query.next()) {
             if (query.isNull(0) == false) {
-                QFUser *userInfo        = new QFUser();
+                QFUser *userInfo          = new QFUser();
                 userInfo->id              = query.value(0).toInt();
                 userInfo->userName        = query.value(1).toString();
                 userInfo->userNo          = query.value(2).toString();
@@ -1967,7 +1967,7 @@ bool DBServiceSet::QueryUserList(QList<QFUser *> *userInfoList)
     if (query.exec(selectSql)) {
         while (query.next()) {
             if (query.isNull(0) == false) {
-                QFUser *userInfo        = new QFUser();
+                QFUser *userInfo          = new QFUser();
                 userInfo->id              = query.value(0).toInt();
                 userInfo->userName        = query.value(1).toString();
                 userInfo->userNo          = query.value(2).toString();
@@ -2003,7 +2003,7 @@ bool DBServiceSet::QueryUserListNotAdmin(QList<QFUser *> *userInfoList)
         if (query.exec(selectSql)) {
             while (query.next()) {
                 if (query.isNull(0) == false) {
-                    QFUser *userInfo        = new QFUser();
+                    QFUser *userInfo          = new QFUser();
                     userInfo->id              = query.value(0).toInt();
                     userInfo->userName        = query.value(1).toString();
                     userInfo->userNo          = query.value(2).toString();

+ 17 - 1
QFD/view/ExpertManageView.cpp

@@ -6,6 +6,9 @@
 #include "ExpertInfoWidget.h"
 #include "ExpertListWidget.h"
 
+#include "ExpertManager.h"
+#include "QFDAlert.h"
+
 #include <dbService/DBServiceSet.h>
 
 #include <Widgets/Button.h>
@@ -131,6 +134,7 @@ void ExpertManageView::showExpertInfo(QFUser *user)
 
 void ExpertManageView::refreshList()
 {
+    m_userList.clear();
     if (!DBServiceSet().QueryUserListNotAdmin(&m_userList)) {
         QFDAlert::showAlertWithCode(QF_CODE_DATA_ERROR, this);
         return;
@@ -152,6 +156,9 @@ void ExpertManageView::slotDetailClicked()
         return;
     }
     QFUser *user = m_userList[row];
+
+    qDebug() << __FUNCTION__ << __LINE__ << user->id << user->userNo << user->userName << user->role << user->remark;
+
     showExpertInfo(user);
 }
 
@@ -179,5 +186,14 @@ void ExpertManageView::slotListItemDoubleClicked(int row)
 void ExpertManageView::slotConfirmAddExpert()
 {
     QFUser *user = m_expertInfoWidget->user();
-    qDebug() << __FUNCTION__ << __LINE__ << user->id << user->userName;
+
+    int code = ExpertManager::addUser(*user);
+    QFDAlert::showAlertWithCode(code, this);
+
+    qDebug() << __FUNCTION__ << __LINE__ << code << user->id << user->userNo << user->userName;
+
+    if (code == QF_CODE_ADD_USER_SUCCEEDED) {
+        hideExpertInfoWidget();
+        refreshList();
+    }
 }

+ 8 - 3
QFD/widgets/ExpertInfoWidget.cpp

@@ -76,9 +76,12 @@ void ExpertInfoWidget::setUser(QFUser *user)
 QFUser *ExpertInfoWidget::user() const
 {
     if (m_mode == Create) {
-        QFUser *user   = new QFUser();
-        user->id       = m_idLineEdit->text().toInt();
-        user->userName = m_nameLineEdit->text();
+        QFUser *user    = new QFUser(m_idLineEdit->text(), m_passwordLineEdit->text());
+        user->password  = m_passwordLineEdit->text();
+        user->userName  = m_nameLineEdit->text();
+        user->writeTime = m_timeLineEdit->text();
+        user->role      = QFUser::Expert;
+        user->remark    = m_noteTextEdit->toPlainText();
         return user;
     } else {
         return m_user;
@@ -259,6 +262,8 @@ void ExpertInfoWidget::setEditable(bool editable)
     m_idLineEdit->setReadOnly(!editable);
     m_contactInfoLineEdit->setReadOnly(!editable);
     m_timeLineEdit->setReadOnly(!editable);
+    m_timeLineEdit->upButton->setEnabled(editable);
+    m_timeLineEdit->downButton->setEnabled(editable);
     m_noteTextEdit->setReadOnly(!editable);
 }
 

BIN
bin/data/qfd.db