-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnum_tic.cpp
180 lines (164 loc) · 6.95 KB
/
num_tic.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include "num_tic.h"
#include <QTimer>
Num_Tic::Num_Tic(QWidget *parent) : QWidget(parent)
{
// label.setParent(this);//设置标签的父窗口
// label.setText("车票数:");//设置标签的文本
// QFont ft;//定义字体对象
// ft.setPointSize(16);//设置字体大小为20号
// label.setFont(ft);//设置标签的字体为ft
// label.move(80,80);//设置标签的位置
// label.resize(480,60);
label.setParent(this);//设置标签的父窗口
label.setText("车票数:");//设置标签的文本
QFont ft;//定义字体对象
ft.setPointSize(16);//设置字体大小为20号
label.setFont(ft);//设置标签的字体为ft
label.move(80,80);//设置标签的位置
label.resize(380,60);
num.setParent(this);
num.move(180,80);
num.resize(70,60);
num.setFont(ft);
button_ok.setParent(this);//设置确定按钮父窗口
button_ok.setText("确定");//设置确定按钮文本
button_ok.move(80,200);//设置确定按钮位置
button_can.setParent(this);
button_can.setText("取消");
button_can.move(240,200);
connect(&button_can,&QPushButton::clicked,this,&Num_Tic::button_can_clicked);
connect(&button_ok,&QPushButton::clicked,this,&Num_Tic::button_ok_clicked);
}
void Num_Tic::button_can_clicked(){
KaiGuan::cf=0;
KaiGuan::dd=0;
KaiGuan::chioce = 0;
this->close();
}
void Num_Tic::button_ok_clicked(){
QString s = num.text();
int n = s.toInt();
int i = 0;
for(i = 0;i < n;i++){
int id1=0;
QString start_name1=KaiGuan::name[KaiGuan::start];
QString end_name1=KaiGuan::name[KaiGuan::end];
int moeny1 = 2;
int chepiaozhuangtai1 = 0;
KaiGuan::new_id= ChePiaoXinXiJiHe::add_list(id1,start_name1,end_name1,moeny1,chepiaozhuangtai1);
ChePiaoXinXi cp = ChePiaoXinXiJiHe::list_set.last();
QString str = QString("车票id:%1 出发站:%2 -> 到达站:%3").arg(cp.id).arg(cp.start_name).arg(cp.end_name);
tic_info.imformation.setText(str);
tic_info.setFixedSize(960,300);
tic_info.show();
QDate date=QDate::currentDate();
QString str2=date.toString("yyyy-MM-dd");
QTime time=QTime::currentTime();
QString str1=time.toString("hh:mm:ss");
qDebug()<<QSqlDatabase::drivers();
QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("127.0.0.1");//数据库主机ip
db.setUserName("root");//数据库用户名
db.setPassword("duanyuhang518.");//数据库密码
db.setDatabaseName("ditie");//数据库名字
if(db.open()==false){
QMessageBox::warning(this,"waring",db.lastError().text());
}
QSqlQuery query;
query.prepare("insert into chepiao (id,date,time,start_name,end_name,money,zhuangtai) values (:id,:date,:time,:start_name,:end_name,:money,:zhuangtai)");
QVariantList idList;
idList << ChePiaoXinXiJiHe::list_set.last().id;
query.bindValue(":id",idList);
//日期
QVariantList dateList;
dateList << str2;
query.bindValue(":date",dateList);
//时间
QVariantList timeList;
timeList << str1;
query.bindValue(":time",timeList);
//出发地
QVariantList start_name;
start_name << ChePiaoXinXiJiHe::list_set.last().start_name;
query.bindValue(":start_name",start_name);
//到达地
QVariantList end_name;
end_name << ChePiaoXinXiJiHe::list_set.last().end_name;
query.bindValue(":end_name",end_name);
//票价
QVariantList money;
money << ChePiaoXinXiJiHe::list_set.last().money;
query.bindValue(":money",money);
//状态
QVariantList zhuangtai;
zhuangtai << ChePiaoXinXiJiHe::list_set.last().chepiaozhuangtai;
query.bindValue(":zhuangtai",zhuangtai);
query.execBatch();
this->close();
// int id1 = 0;
// KaiGuan::new_id= ChePiaoXinXiJiHe::add_list(id1,start_name1,end_name1,moeny1,chepiaozhuangtai1);
// ChePiaoXinXi cp = ChePiaoXinXiJiHe::list_set.last();
// QString str = QString("车票id:%1 出发站:%2 -> 到达站:%3").arg(cp.id).arg(cp.start_name).arg(cp.end_name);
// tic_info.imformation.setText(str);
// tic_info.setFixedSize(700,200);
// QTimer* timer = new QTimer(this);
// timer->start(15000);//时间1.5秒
// timer->setSingleShot(true);
// tic_info.setFixedSize(700,200);
// tic_info.show();
}
// int id1=0;
// QString start_name1=KaiGuan::name[KaiGuan::start];
// QString end_name1=KaiGuan::name[KaiGuan::end];
// int moeny1 = 2;
// int chepiaozhuangtai1 = 0;
// KaiGuan::new_id= ChePiaoXinXiJiHe::add_list(id1,start_name1,end_name1,moeny1,chepiaozhuangtai1);
// ChePiaoXinXi cp = ChePiaoXinXiJiHe::list_set.last();
// QString str = QString("车票id:%1 出发站:%2 -> 到达站:%3").arg(cp.id).arg(cp.start_name).arg(cp.end_name);
// tic_info.imformation.setText(str);
// tic_info.setFixedSize(700,200);
// tic_info.show();
// QDate date=QDate::currentDate();
// QString str2=date.toString("yyyy-MM-dd");
// QTime time=QTime::currentTime();
// QString str1=time.toString("hh:mm:ss");
// qDebug()<<QSqlDatabase::drivers();
// QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
// db.setHostName("127.0.0.1");//数据库主机ip
// db.setUserName("root");//数据库用户名
// db.setPassword("duanyuhang518.");//数据库密码
// db.setDatabaseName("ditie");//数据库名字
// if(db.open()==false){
// QMessageBox::warning(this,"waring",db.lastError().text());
// }
// QSqlQuery query;
// query.prepare("insert into chepiao (id,date,time,start_name,end_name,money,zhuangtai) values (:id,:date,:time,:start_name,:end_name,:money,:zhuangtai)");
// QVariantList idList;
// idList << ChePiaoXinXiJiHe::list_set.last().id;
// query.bindValue(":id",idList);
// //日期
// QVariantList dateList;
// dateList << str2;
// query.bindValue(":date",dateList);
// //时间
// QVariantList timeList;
// timeList << str1;
// query.bindValue(":time",timeList);
// //出发地
// QVariantList start_name;
// start_name << ChePiaoXinXiJiHe::list_set.last().start_name;
// query.bindValue(":start_name",start_name);
// //到达地
// QVariantList end_name;
// end_name << ChePiaoXinXiJiHe::list_set.last().end_name;
// query.bindValue(":end_name",end_name);
// //票价
// QVariantList money;
// money << ChePiaoXinXiJiHe::list_set.last().money;
// query.bindValue(":money",money);
// //状态
// QVariantList zhuangtai;
// zhuangtai << ChePiaoXinXiJiHe::list_set.last().chepiaozhuangtai;
// query.bindValue(":zhuangtai",zhuangtai);
// query.execBatch();
}