-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
130 lines (118 loc) · 3.37 KB
/
mainwindow.cpp
File metadata and controls
130 lines (118 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "cd.h"
#include "newdoc.h"
#include <QtSql>
extern QSqlDatabase db;
extern QSqlQueryModel *model;
extern QSqlQuery query;
QString LandingRole;//登陆的角色,方便权限管理
QString CabinetCommunicationIp;//主机柜IP
QString CabinetCommunicationId;//主机柜当前通信线程ID
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//打开数据库
db=QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("ManagementSystemSatabase.db");
bool ok=db.open();
if(ok)
{
QMessageBox::information(this,"提示","数据库已准备可以进行相关操作");
}
else
{
QMessageBox::information(this,"提示","数据库打开失败");
}
ui->lineEdit->setEchoMode(QLineEdit::Password);
//获取主机柜IP
QString Qfind="SELECT * FROM socket WHERE type='cabinet'";
query = QSqlQuery(db);
if(!query.exec(Qfind))
{
qDebug()<<query.lastError();
}
else
{
QString ip="";
QString type="";
QString other="";
while(query.next())
{
ip = query.value(0).toString();
type = query.value(1).toString();
other = query.value(2).toString();
//qDebug()<<QString("用户名:%1,密码:%2,角色:%3").arg(u).arg(p).arg(s);
}
if(ip.isEmpty()||type.isEmpty()||other.isEmpty())
{
QMessageBox::warning(this,"提示","没有设置主机柜IP,使用前先去设置");
return;
}else {
CabinetCommunicationIp=ip;
}
}
// query = QSqlQuery(db);
// // QString yonghu,mima,juese,shengfengzheng,zhiwen,renlianshibie;
// bool query_OK= query.exec("create table use(yonghu vchar primary key,mima vchar ,juese vchar ,shengfengzheng vchar ,zhiwen vchar ,renlianshibie vchar )");
// if(query_OK)
// {
// qDebug()<< "create table success!";
// }
// else
// {
// qDebug()<< "create table fail!" << db.lastError();
// }
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_Button_DL_clicked()
{
/*LandingRole="";
if(ui->lineEdit->text().isEmpty() || ui->lineEdit_2->text().isEmpty()){
QMessageBox::information(this,"警告","请填写人完整!");
return;
}
QString Qfind="SELECT * FROM use WHERE yonghu='"+ui->lineEdit_2->text()+"'";
query = QSqlQuery(db);
if(!query.exec(Qfind))
{
qDebug()<<query.lastError();
}
else
{
QString u="";
QString p="";
QString s="";
while(query.next())
{
u = query.value(0).toString();
p = query.value(1).toString();
s = query.value(2).toString();
qDebug()<<QString("用户名:%1,密码:%2,角色:%3").arg(u).arg(p).arg(s);
}
if(u.isEmpty()||p.isEmpty()||s.isEmpty())
{
qDebug()<<"登录失败";
return;
}else if(u==ui->lineEdit_2->text()&&p==ui->lineEdit->text()){
LandingRole=s;
cd d;
this->hide();//隐藏主窗口
d.exec();
qDebug()<<"可以登录";
}
}*/
cd d;
this->hide();//隐藏主窗口
d.exec();
LandingRole="管理员";
}
void MainWindow::on_Button_TC_clicked()
{
qApp->quit();
}