-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.cpp
97 lines (87 loc) · 2.37 KB
/
widget.cpp
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
#include "widget.h"
#include "work.h"
#include <QString>
#include <QSql>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QMessageBox>
#include <QStringList>
#include <QHeaderView>
#include <QDateTime>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QDebug>
Widget::Widget(QWidget *parent) :
QWidget(parent),
loginwindow(new Ui::Widget)
{
window = new QWidget;
lineEdit = new QLineEdit;
lineEdit_2 = new QLineEdit;
qDebug()<<lineEdit->text();
loginwindow->setupUi(this);
}
Widget::~Widget()
{
delete loginwindow;
}
void Widget::on_pushButton_clicked()
{
char name_find = 0;
QDateTime time = QDateTime::currentDateTime();//Get Operation System time
QString str = time.toString("yyyy-MM-dd hh:mm:ss ddd");
QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
QSqlQuery query(db);
QString username = loginwindow->lineEdit->text();
QString userpassword = loginwindow->lineEdit_2->text();
QString name;
QString password;
db.setHostName("localhost");
db.setDatabaseName("pos_data");
db.setUserName("root");
db.setPassword("");
if(!db.open()){
QMessageBox::information(0,"Error","Can not connect to service.",QMessageBox::Ok);
}else{
query.exec("select *from price");//check command
while(query.next())
{
name = query.value(0).toString();
password = query.value(3).toString();
qDebug()<<name<<password;
qDebug()<<username<<userpassword;
if((username == name)&&(userpassword == password))
{
name_find = 1;
this->close();
switch(QMessageBox::information(0,"Data","Now time is: "+str,QMessageBox::Ok,QMessageBox::Ok))
{
case QMessageBox::Ok:
show_work_window();
break;
default:
break;
}
break;
}
}
db.close();
if(!name_find)
{
QMessageBox::information(0,"Error","Wrong username or password",QMessageBox::Ok);
loginwindow->lineEdit->clear();
loginwindow->lineEdit_2->clear();
}
}
}
void Widget::show_work_window()
{
workwindow.show();
}
void Widget::on_pushButton_2_clicked()
{
close();
}
void Widget::on_lineEdit_2_editingFinished()
{
}