forked from kevinlq/HotelManage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customerwindget.cpp
411 lines (359 loc) · 12.1 KB
/
customerwindget.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
#include "customerwindget.h"
#include "ui_customerwindget.h"
#include "app/iconhelper.h"
#include "app/myhelper.h"
#include "app/myapp.h"
#include <QDebug>
#include <QSqlQuery>
#include <QSqlRecord>
#include <QDate>
CustomerWindget::CustomerWindget(QWidget *parent) :
QWidget(parent),
ui(new Ui::CustomerWindget)
{
ui->setupUi(this);
this->InitForm();
}
CustomerWindget::~CustomerWindget()
{
delete ui;
}
void CustomerWindget::InitForm()
{
//ui->letNo->setEnabled(false);//用户编号不允许修改
//设置窗体标题栏隐藏
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
this->setMinimumSize(1000,600);
location = this->geometry();
max = false;
mousePressed = false;
//安装事件监听器,让标题栏识别鼠标双击
ui->lab_Title->installEventFilter(this);
IconHelper::Instance()->SetIcon(ui->btnMenu_Close, QChar(0xf00d), 10);
IconHelper::Instance()->SetIcon(ui->btnMenu_Max, QChar(0xf096), 10);
IconHelper::Instance()->SetIcon(ui->btnMenu_Min, QChar(0xf068), 10);
IconHelper::Instance()->SetIcon(ui->btnMenu, QChar(0xf0c9), 10);
IconHelper::Instance()->SetIcon(ui->lab_Ico, QChar(0xf015), 12);
//初始化表格列名和列宽
ColumnNames[0] = tr("房间编号");
ColumnNames[1] = tr("房间类型");
ColumnNames[2] = tr("房间价格");
ColumnNames[3] = tr("房间状态");
ColumnWidths[0] = 80;
ColumnWidths[1] = 120;
ColumnWidths[2] = 120;
ColumnWidths[3] = 120;
//顾客信息显示字段初始化
CustomeColumnNames[0] = "编号";
CustomeColumnNames[1] = "姓名";
CustomeColumnNames[2] = "性别";
CustomeColumnNames[3] = "密码";
CustomeColumnNames[4] = "电话";
CustomeColumnNames[5] = "地址";
CustomeColumnNames[6] = "注册日期";
CustomeColumnNames[7] = "备注";
CustomeColumnWidths[0] = 50;
CustomeColumnWidths[1] = 90;
CustomeColumnWidths[2] = 100;
CustomeColumnWidths[3] = 80;
CustomeColumnWidths[4] = 150;
CustomeColumnWidths[5] = 200;
CustomeColumnWidths[6] = 200;
CustomeColumnWidths[7] = 200;
BindRoomInfo("Room",ui->tableViewRoomInfo,ColumnNames,ColumnWidths);
ui->dateRfrom->setDate(QDate::currentDate());
ui->dateRto->setDate(QDate::currentDate());
ui->dateCustomeIn->setDate(QDate::currentDate());
roompicture = new RoomPicDialog(); //酒店欣赏界面
ui->stackedWidget->addWidget(roompicture);
this->connect(ui->tableViewCustomeInfo,SIGNAL(clicked(QModelIndex)),SLOT(showCustomInfo()));
}
/*
*函数功能:将房间信息绑定到tableview上
*/
void CustomerWindget::BindRoomInfo(QString tableName, QTableView *tableView, QString columnNames[], int columnWidths[])
{
QueryModel = new QSqlQueryModel(this);
TableView = tableView;
QString sql = "SELECT RoomNo,Typename,TypePrice,RoomState FROM " + tableName+
",RoomType where room.RoomTypeId = roomtype.RoomTypeId and Roomstate ='空';";
QueryModel->setQuery(sql);
TableView->setModel(QueryModel);
//依次设置列标题、列宽等
for (int i = 0;i<TableView->model()->columnCount();i++)
{
QueryModel->setHeaderData(i,Qt::Horizontal,columnNames[i]); //设置列标题
TableView->setColumnWidth(i,columnWidths[i]); //设置列宽
}
TableView->horizontalHeader()->setHighlightSections(false); //点击表头时不对表头光亮
TableView->setSelectionMode(QAbstractItemView::ContiguousSelection);//选中模式为多行选中
TableView->setSelectionBehavior(QAbstractItemView::SelectRows); //选中整行
TableView->setStyleSheet( "QTableView::item:hover{background-color:rgb(92,188,227,200)}"
"QTableView::item:selected{background-color:#1B89A1}");
}
/*
*函数功能:将顾客信息绑定到tableview上
*/
void CustomerWindget::BindCustomeInfo(QString tableName, QTableView *tableView, QString columnNames[], int columnWidths[])
{
customModel = new QSqlQueryModel(this);
//QString customename = GetCutrrentUserName("Customelogblog");
QString customename = Myapp::CurrentUserName;
qDebug() <<"当前用户名:"<<customename;
QString sql = "SELECT * FROM " + tableName+
" where CustomerName ='"+customename+"';";
qDebug() <<sql;
QueryModel->setQuery(sql);
tableView->setModel(QueryModel);
//依次设置列标题、列宽等
for (int i = 0;i<tableView->model()->columnCount();i++)
{
QueryModel->setHeaderData(i,Qt::Horizontal,columnNames[i]); //设置列标题
tableView->setColumnWidth(i,columnWidths[i]); //设置列宽
}
tableView->horizontalHeader()->setHighlightSections(false); //点击表头时不对表头光亮
tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);//选中模式为多行选中
tableView->setSelectionBehavior(QAbstractItemView::SelectRows); //选中整行
tableView->setStyleSheet( "QTableView::item:hover{background-color:rgb(92,188,227,200)}"
"QTableView::item:selected{background-color:#1B89A1}");
}
/*
*函数功能:获取当前登录用户名
*/
QString CustomerWindget::GetCutrrentUserName(QString tablename)
{
QString sql ="select CustomeName from "+tablename+";";
QSqlQuery query;
query.exec(sql);
query.next();
return query.value(0).toString();
}
bool CustomerWindget::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseButtonDblClick) {
this->on_btnMenu_Max_clicked();
return true;
}
return QObject::eventFilter(obj, event);
}
void CustomerWindget::mouseMoveEvent(QMouseEvent *e)
{
if (mousePressed && (e->buttons() && Qt::LeftButton) && !max) {
this->move(e->globalPos() - mousePoint);
e->accept();
}
}
void CustomerWindget::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton) {
mousePressed = true;
mousePoint = e->globalPos() - this->pos();
e->accept();
}
}
void CustomerWindget::mouseReleaseEvent(QMouseEvent *)
{
mousePressed = false;
}
void CustomerWindget::on_btnMenu_Max_clicked()
{
if (max)
{
this->setGeometry(location);
IconHelper::Instance()->SetIcon(ui->btnMenu_Max, QChar(0xf096), 10);
ui->btnMenu_Max->setToolTip("最大化");
}
else
{
location = this->geometry();
this->setGeometry(qApp->desktop()->availableGeometry());
IconHelper::Instance()->SetIcon(ui->btnMenu_Max, QChar(0xf079), 10);
ui->btnMenu_Max->setToolTip("还原");
}
max = !max;
}
void CustomerWindget::on_btnMenu_Min_clicked()
{
this->showMinimized();
}
void CustomerWindget::on_btnMenu_Close_clicked()
{
this->close();
}
void CustomerWindget::on_punroom_clicked()
{
ui->stackedWidget->setCurrentIndex(0);
BindRoomInfo("Room",ui->tableViewRoomInfo,ColumnNames,ColumnWidths);
}
void CustomerWindget::on_pbnGuest_clicked()
{
BindCustomeInfo("Customer",ui->tableViewCustomeInfo,CustomeColumnNames,CustomeColumnWidths);
ui->stackedWidget->setCurrentIndex(1);
}
/*
*函数功能:确认预订房间
*/
void CustomerWindget::on_pbnROK_clicked()
{
QString roomId = ui->letNo->text();
QString roomType = ui->comboBoxRoomType->currentText();
QString roomPrice = ui->letprice->text();
//QString roomstate = ui->letstate->text();
QString dateto = ui->dateRto->text();
QString datefrom = ui->dateRfrom->text();
QString currentdatetime = QDateTime::currentDateTime().toString("yyyyMMddhhmmss");
//流水号
QString serialNumber = "2014"+currentdatetime;
if(ui->radioButtonNo->isChecked())
{
//到店支付
if(roomId.isEmpty()||roomPrice.isEmpty())
{
myHelper::ShowMessageBoxError(tr("必须填满带*的字段"));
}
else
{
QString roomTypeId = "";
if(roomType == "单人间")
{
roomTypeId ="1";
}
else if(roomType == "双人间")
{
roomTypeId == "2";
}
else if(roomType == "豪华套间")
{
roomTypeId == "3";
}
else
{
roomTypeId == "4";
}
qDebug() <<roomTypeId;
QString customerName = GetCutrrentUserName("customelogblog");
QSqlQuery query;
bool ok = query.prepare("INSERT INTO book(Id,roomno,bookName,roomtypeId,"
"booktimefrom,booktimeto,bookremark)"
"VALUES (:Id,:roomno,:bookName,:roomtypeId,:booktimefrom,:booktimeto,:bookremark)");
query.bindValue(":Id",serialNumber);
query.bindValue(":roomno",roomId);
query.bindValue(":bookName",customerName);
query.bindValue(":roomtypeId",roomTypeId);
query.bindValue(":booktimefrom",dateto);
query.bindValue(":booktimeto",datefrom);
query.bindValue(":bookremark"," ");
query.setForwardOnly(true);
query.exec();
if(ok)
{
myHelper::ShowMessageBoxInfo(QString("预订成功!订单号:"+serialNumber));
qDebug() <<"顾客预订成功!";
}
}
}
else if(ui->radioButtonOk->isChecked())
{
//在线支付
}
else
{
//其他
myHelper::ShowMessageBoxInfo(tr("请选择支付方式"));
}
}
void CustomerWindget::on_comboBoxRoomType_activated(const QString &arg1)
{
if(arg1 == "单人间")
{
ui->letprice->setText("120");
}
else if(arg1 == "双人间")
{
ui->letprice->setText("200");
}
else if(arg1 == "豪华套间")
{
ui->letprice->setText("500");
}
else if(arg1 == "总统套间")
{
ui->letprice->setText("1000");
}
}
void CustomerWindget::on_pbnroomPicture_clicked()
{
ui->stackedWidget->setCurrentIndex(2);
}
/*
*修改自己信息
*/
void CustomerWindget::on_pbnmodify_clicked()
{
ui->letusename->clear();
ui->letsex->clear();
ui->letpossword->clear();
ui->letphone->clear();
ui->letaddress->clear();
ui->letGnote->clear();
ui->pbnmodify->setEnabled(false);
}
/*
*函数功能:确认修改,进行写库
*/
void CustomerWindget::on_pbuModifyOk_clicked()
{
QString customeName = ui->letusename->text();
QString customeSex = ui->letsex->text();
QString customePwd = ui->letpossword->text();
QString customePhone = ui->letphone->text();
QString customedate = ui->dateCustomeIn->text();
QString customeAddress = ui->letaddress->text();
QString customeRemark = ui->letGnote->text();
if(customeName.isEmpty() ||customePhone.isEmpty()
||customePwd.isEmpty()||customeAddress.isEmpty())
{
myHelper::ShowMessageBoxError(tr("必须填满带*字段"));
}
else
{
QString currentUseName = Myapp::CurrentUserName; //获取当前登录名
QSqlQuery query;
QString sql ="update Customer set CustomerSex ='"+customeSex
+"', CustomerPassword='"+customePwd+"',CustomerPhone='"+customePhone
+"', CustomerData ='"+customedate+"', CustomerAddress='"+customeAddress
+"', CustomerRemark ='"+customeRemark+"' where Id = '"+currentUseName+"';";
qDebug() <<sql;
query.exec(sql);
myHelper::ShowMessageBoxInfo(tr("修改成功"));
myHelper::MyLoginBlog("logblog","修改信息","客户",currentUseName);
qDebug() <<"update customer info success!";
}
}
/*
*函数功能:取消操作
*/
void CustomerWindget::on_pbnCancle_clicked()
{
ui->pbnCancle->setEnabled(false);
ui->pbnmodify->setEnabled(true);
}
/*
*当鼠标点击显示客户信息到对应控件中
*/
void CustomerWindget::showCustomInfo()
{
QSqlQueryModel userMode(ui->tableViewCustomeInfo);
QString sql = "SELECT *FROM customer;";
qDebug() <<sql;
userMode.setQuery(QString(sql));
int Row = ui->tableViewCustomeInfo->currentIndex().row();
QSqlRecord record = userMode.record(Row);
ui->letusename->setText(record.value(1).toString());
ui->letsex->setText(record.value(2).toString());
ui->letpossword->setText(record.value(3).toString());
ui->letphone->setText(record.value(4).toString());
ui->letaddress->setText(record.value(5).toString());
//ui->dateCustomeIn->setDate(QDate::addDays(record.value(6).toInt()));
ui->letGnote->setText(record.value(7).toString());
}