#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "login.h"
#include "messagebox/messagebox_user.h"
#include "messagebox/messagebox_history.h"
//风格:文字白色,图片选择样式切换
QString QCheckBoxstyle=
"QCheckBox{color: rgb(255, 255, 255);background-color: rgb(0, 0, 0);}"
"QCheckBox::indicator{background-color: rgba(255, 255, 255, 0);border: 0px solid #b1b1b1;width: 30px;height: 30px;}"
"QCheckBox::indicator:unchecked {image:url(:/PIC/未选择.png);}"
"QCheckBox::indicator:unchecked:hover {image:url(:/PIC/未选择.png);}"
"QCheckBox::indicator:unchecked:pressed {image:url(:/PIC/未选择.png);}"
"QCheckBox::indicator:checked {image:url(:/PIC/选择.png);}"
"QCheckBox::indicator:checked:hover {image:url(:/PIC/选择.png);}"
"QCheckBox::indicator:checked:pressed {image:url(:/PIC/选择.png);}";
QString btnwhite="color: rgb(255, 255, 255);";
QString btngreen="color: rgb(0, 255, 0);";
QString btnblue="color: rgb(20, 50, 255);";
QString btngray="color: rgb(160, 160, 160);";
QString btnstyle=
"background-color: rgba(255, 255, 255, 0);"
"border-right:0px solid #9eca56; "
"border-bottom:0px solid #9eca56;"
"border-left:0px solid #9eca56;"
"border-top:0px solid #9eca56; "
"font: 75 italic 12pt '宋体';"
"text-decoration: underline;";
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setWindowModality(Qt::ApplicationModal);//设置一直保持在顶端,不可切换其他界面,除非被新界面带此属性覆盖
this->setWindowFlags(Qt::Dialog);//取消窗口最大化最小化按钮
//用户管理初始化
QVector<int> table_line;
table_line.append({140,600,400,100,300});//配置表格宽度5列
QStringList table_title;
table_title.append({"序号","账号(操作人员)","密码","管理员","备注"});//配置表格表头名称5列
m_scrollBarV = ui->tableWidget_user->verticalScrollBar();//绑定表格滑动效//在表格第一次初始化前必须初始化一次,否则程序崩溃
tableWidget_user_init(ui->tableWidget_user,table_line,table_title,true);//初始化表格表头
tableWidget_user_refuse(ui->tableWidget_user);//更新全部用户信息
connect(ui->tableWidget_user,&QTableWidget::cellPressed,[=](){//点击表格某行生效,当需要滑动时必定点击到表格某行。
m_scrollBarV = ui->tableWidget_user->verticalScrollBar();//绑定表格滑动效
});
//历史数据初始化
QVector<int> historytable_line;
historytable_line.append({150,400,200,200,200,300});//配置表格宽度6列
QStringList historytable_title;
historytable_title.append({"序号","日期","操作员","设备号","健康状态","功能"});//配置表格表头名称6列
m_scrollBarV = ui->tableWidget_history->verticalScrollBar();//绑定表格滑动效//在表格第一次初始化前必须初始化一次,否则程序崩溃
tableWidget_datasearch_init(ui->tableWidget_history,historytable_line,historytable_title,true);//初始化表格表头
tableWidget_datasearch_refuse(ui->tableWidget_history);//更新历史信息
connect(ui->tableWidget_history,&QTableWidget::cellPressed,[=](){//点击表格某行生效,当需要滑动时必定点击到表格某行。
m_scrollBarV = ui->tableWidget_history->verticalScrollBar();//绑定表格滑动效
});
}
MainWindow::~MainWindow()
{
delete ui;
}
/*****************************人员管理处理函数**********************************/
//用户增加
void MainWindow::on_btn_user_add_clicked()
{
MessageBox_user * box = new MessageBox_user();
box->show();
box->setAttribute(Qt::WA_DeleteOnClose);//若是关闭界面,则彻底释放资源
connect(this,SIGNAL(sendtext(QString,QString,bool,QString,QStringList)),box,SLOT(receivetext(QString,QString,bool,QString,QStringList)));
emit sendtext("","",false,"",Data_user.usernamelist);
connect(box,&MessageBox_user::sendtext,[=](QString res1,QString res2,bool res3,QString res4){
qDebug()<<res1<<res2<<res3<<res4;
QSqlQuery qry(db);//数据库保存
qry.exec(QString("INSERT INTO Sys_user(name,password,root,note) VALUES ('%1','%2','%3','%4');").arg(res1).arg(res2).arg(res3).arg(res4));
tableWidget_user_refuse(ui->tableWidget_user);//更新全部用户信息
});
}
//用户修改
void MainWindow::on_btn_user_change_clicked()
{
int checkid=0;
QList<QCheckBox*> checkList = ui->tableWidget_user->findChildren<QCheckBox*>();
for(int i=0;i<checkList.size();i++){//遍历寻找是否有选中
if(checkList.at(i)->isChecked()){//如果找到选中,则跳出循环
checkid=checkList.at(i)->objectName().replace("QCheckBox_user_","").toInt();//替换控件名称转换为表格所在的行
break;//跳出寻找
}
}
if(checkid>0){//有选中的行
MessageBox_user * box = new MessageBox_user();
box->show();
box->setAttribute(Qt::WA_DeleteOnClose);//若是关闭界面,则彻底释放资源
connect(this,SIGNAL(sendtext(QString,QString,bool,QString,QStringList)),box,SLOT(receivetext(QString,QString,bool,QString,QStringList)));
QString change_username=Data_user.usernamelist.at(checkid-1);//赋值选中用户名称
QString change_userpassword=Data_user.userpswdlist.at(checkid-1);//赋值选中用户密码
bool change_userroot=Data_user.userroot.at(checkid-1);//赋值选中用户权限
QString change_usernote=Data_user.usernote.at(checkid-1);//赋值选中用户备注
emit sendtext(change_username,change_userpassword,change_userroot,change_usernote,Data_user.usernamelist);
connect(box,&MessageBox_user::sendtext,[=](QString res1,QString res2,bool res3,QString res4){
// qDebug()<<res1<<res2<<res3<<res4;
//判断修改的用户是否为当前用户
int err_flag=0;//错误编号
if(change_username==Data_user.now_username){
if(res3==0){
res3=1;
err_flag=1;//降低本身权限,可能导致没有账号能进入管理员系统
}
//赋值登录信息到当前用户信息缓存
Data_user.now_username=res1;//当前用户
Data_user.now_password=res2;//当前密码
Data_user.now_root=res3;//赋值权限
Data_user.now_noted=res4;//赋值备注
//存储当前登录界面配置信息到数据库
QSqlQuery qry(db);//数据库保存
qry.exec(QString("UPDATE Sys_userlast set username='%1',userpassword='%2' where id = 1;").arg(res1).arg(res2));
//刷新当前用户名称
// ui->label_name->setText(QString("当前用户:%1").arg(Data_user.now_username));
}
QSqlQuery qry(db);//数据库保存
qry.exec(QString("UPDATE Sys_user set name='%1',password='%2',root='%3' ,note='%4'where name = '%5';").arg(res1).arg(res2).arg(res3).arg(res4).arg(change_username));
tableWidget_user_refuse(ui->tableWidget_user);//更新全部用户信息
if(err_flag==1)
massage_dialog(1,"提示","用户信息修改成功!\r\n(不可修改自身权限,已自动恢复)",1);
else
massage_dialog(1,"提示","用户信息修改成功!",1);
});
}
else{
massage_dialog(1,"提示","请选择要修改的用户列表序号!",1);
}
}
//用户删除
void MainWindow::on_btn_user_delete_clicked()
{
int checkid=0;
QList<QCheckBox*> checkList = ui->tableWidget_user->findChildren<QCheckBox*>();
for(int i=0;i<checkList.size();i++){//遍历�
评论0
最新资源