#include "permissonwindow.h"
|
#include "qcomboxdelegate.h"
|
#include "ui_permissonwindow.h"
|
|
#include <QDialog>
|
#include <QMouseEvent>
|
#include <QPushButton>
|
|
PermissonWindow::PermissonWindow(QWidget *parent) :
|
QMainWindow(parent),
|
ui(new Ui::PermissonWindow)
|
{
|
ui->setupUi(this);
|
clientSocket = new PmsClientSocket(this);
|
|
dia = new PermissonDialog(this,clientSocket);
|
|
|
|
connect(this,SIGNAL(sendUserNo(PmsQueryResult)),dia,SLOT(recvUserNo(PmsQueryResult)));
|
connect(clientSocket,SIGNAL(notifyDateChange(vector<PmsQueryResult>)),this,SLOT(renderItemData(vector<PmsQueryResult>)));
|
|
roleMap["普通采矿员工"] = 1;
|
roleMap["技术维护人员"] = 2;
|
roleMap["系统管理员"] = 3;
|
roleMap["安全管理人员"] = 4;
|
|
this->setWindowTitle("权限管理");
|
vector<QString> lableList;
|
lableList.push_back("员工编号");
|
lableList.push_back("姓名");
|
lableList.push_back("当天工作时间");
|
lableList.push_back("当天结束时间");
|
lableList.push_back("职位");
|
|
|
|
m_model = new QStandardItemModel(globalPms.size(),lableList.size(),this);
|
|
ui->tableView->setModel(m_model);
|
|
for(int i=0;i<m_model->rowCount();i++){
|
PmsQueryResult curRes = globalPms[i];
|
m_model->setItem(i,0,new QStandardItem(QString::fromStdString(curRes.getUserNo())));
|
m_model->setItem(i,1,new QStandardItem(QString::fromLocal8Bit(curRes.getName().c_str())));
|
m_model->setItem(i,2,new QStandardItem(QString::fromStdString(curRes.getStartDateTime())));
|
m_model->setItem(i,3,new QStandardItem(QString::fromStdString(curRes.getEndDateTime())));
|
m_model->setItem(i,4,new QStandardItem(QString::fromLocal8Bit(curRes.getPermissonType().c_str())));
|
|
}
|
|
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
ui->tableView->verticalHeader()->hide();
|
|
|
QStringList lable;
|
for(int i=0;i<m_model->columnCount();i++){
|
lable << lableList.at(i);
|
}
|
|
m_model->setHorizontalHeaderLabels(lable);
|
|
QComBoxDelegate * qc = new QComBoxDelegate(this);
|
|
|
|
ui->tableView->setItemDelegateForColumn(4,qc);
|
|
|
m = new QMenu(this);
|
QAction * ac1 = new QAction("编辑当前员工权限");
|
|
|
m->addAction(ac1);
|
|
|
ui->tableView->viewport()->installEventFilter(this);
|
|
|
|
connect(ac1,&QAction::triggered,[=]{
|
int row = ui->tableView->currentIndex().row();
|
qDebug() << globalPms[row].getDevManage();
|
// 发送员工编号信息
|
emit sendUserNo(globalPms[row]);
|
|
dia->setModal(true);
|
dia->show();
|
});
|
|
|
connect(m_model,SIGNAL(itemChanged(QStandardItem*)),this,SLOT(listenItemChange(QStandardItem*)));
|
|
|
}
|
|
bool PermissonWindow::eventFilter(QObject *watch, QEvent *event)
|
{
|
if(watch == ui->tableView->viewport() || watch == ui->tableView->verticalHeader()->viewport()
|
|
|| watch == ui->tableView->horizontalHeader()->viewport()){
|
if(event->type()==QEvent::MouseButtonPress && ((QMouseEvent *)event)->button()==Qt::RightButton){
|
m->exec(QCursor::pos());
|
}
|
|
}
|
return QMainWindow::eventFilter(watch,event);
|
}
|
|
|
PermissonWindow::~PermissonWindow()
|
{
|
delete dbInfo;
|
delete dia;
|
delete m_model;
|
delete m;
|
delete ui;
|
}
|
|
void PermissonWindow::on_pushButton_clicked()
|
{
|
qDebug() << "发送查询请求";
|
PmsParam pm;
|
pm.setName(ui->lineEdit->text().toStdString());
|
pm.setPermissonType(ui->lineEdit_2->text().toStdString());
|
pm.setUserNo(ui->lineEdit_3->text().toStdString());
|
|
clientSocket->queryPmsByParam(pm);
|
qDebug() << "查询中";
|
|
}
|
|
void PermissonWindow::listenItemChange(QStandardItem *item)
|
{
|
qDebug() << "数据开始更新";
|
QString localText = item->text();
|
PmsPlusParma pm;
|
pm.setPermissonType(localText.toStdString());
|
pm.setRoleId(roleMap[localText.toStdString()]);
|
clientSocket->updatePmsByParam(pm);
|
}
|
|
void PermissonWindow::renderItemData(vector<PmsQueryResult> res)
|
{
|
globalPms = res;
|
m_model->setRowCount(globalPms.size());
|
|
for(int i=0;i<m_model->rowCount();i++){
|
PmsQueryResult curRes = globalPms[i];
|
m_model->setItem(i,0,new QStandardItem(QString::fromStdString(curRes.getUserNo())));
|
m_model->setItem(i,1,new QStandardItem(QString::fromLocal8Bit(curRes.getName().c_str())));
|
m_model->setItem(i,2,new QStandardItem(QString::fromStdString(curRes.getStartDateTime())));
|
m_model->setItem(i,3,new QStandardItem(QString::fromStdString(curRes.getEndDateTime())));
|
m_model->setItem(i,4,new QStandardItem(QString::fromLocal8Bit(curRes.getPermissonType().c_str())));
|
|
}
|
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
qDebug() << "查询到的数量 " << globalPms.size();
|
}
|