本文实例为大家分享了java实现酒店管理系统的具体代码,供大家参考,具体内容如下
编写环境:myeclipse2014+sql server2014
系统功能:
1.登录验证
2.房态统计显示
3.预定登记并入库
4.入住登记并入库
5.换房登记并入库
6.客人信息查询
7.退房并入库
运行界面如下:
=====登录界面======
=====主界面=====
=====为每个房间设置弹出菜单======
=====登记界面======
=====换房界面=====
=====退房界面=====
界面之间相关关系:
主界面主要由菜单条,按钮,标签等组成,一个jbutton是一个房间,其test从数据库中获取,颜色由房态决定。
登记-换房-查看信息-退房等界面皆继承一个父类而来,简单快捷。
主要代码目录:
1.数据库操作类
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
|
/**====================================================**
* 项目名 :酒店管理系统
* 模块名 :数据库连接
* 文件名 :databaseconnct.java
* 相关文件 :
* 实现功能 :jdbc连接数据库
* 函数说明 :
* [## public vector getid(){}]:
* 功能:获取数据库中系统登录id
*
* [## public void setid() {}]:
* 功能:设置数据库中系统登录id
*
* [## public vector getpassword(){}]:
* 功能:获取数据库中系统登录密码
*
* [## public void setpassword(){}]:
* 功能:设置数据库中系统登录密码
*
* [## public vector getroonnum(){}]:
* 功能:获取数据库中房间号
*
* [## public void setroonnum() {}]:
* 功能:设置数据库中房间号
*
* [## public vector getroomtype(){}]:
* 功能:获取数据库中房间类型
*
* [## public void seroomtype(){}]:
* 功能:设置数据库中房间类型
*
* [## public void sql(string sql){}]:
* 功能:执行sql语句进行查询
*
**===================================================**/
package com.common;
import java.sql.*;
import java.util.vector;
import javax.swing.joptionpane;
import javax.xml.crypto.dsig.keyinfo.retrievalmethod;
public class databaseconnect {
private string drivername= "com.microsoft.sqlserver.jdbc.sqlserverdriver" ;
private string dburl= "jdbc:sqlserver://localhost:1433;databasename=hotel_mangerment_system" ;
private string username= "sa" ;
private string userpwd= "1451171" ;
private connection ct= null ;
private resultset rs= null ;
private statement st;
private vector id = new vector();
private vector password = new vector();
/**====================================================**
* 获取数据库中系统登录id
**===================================================**/
public vector getid() {
return id;
}
/**====================================================**
* 设置数据库中系统登录id
**===================================================**/
public void setid(vector id) {
this .id = id;
}
/**====================================================**
* 获取数据库中系统登录密码
**===================================================**/
public vector getpassword() {
return password;
}
/**====================================================**
* 设置数据库中系统登录id
**===================================================**/
public void setpassword(vector password) {
this .password = password;
}
/**====================================================**
* [## public void sql(string sql) {}]
* 参数 :string sql
* 返回值 :无
* 修饰符 :public
* 功能 :创建sql查询,从数据库里查询登陆账号与密码
**===================================================**/
public void sql(string sql) throws exception
{
class .forname(drivername);
ct=drivermanager.getconnection(dburl,username,userpwd);
st=ct.createstatement();
rs=st.executequery(sql);
while (rs.next())
{
id.add(rs.getint( 1 ));
password.add(rs.getint( 2 ));
}
if (rs!= null )
rs.close();
if (st!= null )
st.close();
if (ct!= null )
ct.close();
}
/**====================================================**
* [## public vector roomoperation(int room_num) {}] 查询房间信息
* 参数 :int room_num
* 返回值 :无
* 修饰符 :public
* 功能 :创建sql查询房间号与类型,类外可使用
**===================================================**/
public vector roomoperation( int room_num) throws exception
{
vector<object> data= new vector<object>();
class .forname(drivername);
ct=drivermanager.getconnection(dburl,username,userpwd);
st=ct.createstatement();
rs=st.executequery( "select * from room_table where roomnum=" +room_num);
while (rs.next())
{
data.add(rs.getint( 1 ));
data.add(rs.getstring( 2 ));
data.add(rs.getint( 3 ));
data.add(rs.getint( 4 ));
}
if (rs!= null )
rs.close();
if (st!= null )
st.close();
if (ct!= null )
ct.close();
return data;
}
/**====================================================**
* [## public void roomoperation(string sql) {}] 查询房间使用状态
* 参数 :string sql
* 返回值 :房间个数
* 修饰符 :public
* 功能 :创建sql查询满足条件房间使用状态,类外可使用
**===================================================**/
public int getrow(string sql) throws exception
{
class .forname(drivername);
ct=drivermanager.getconnection(dburl,username,userpwd);
int rowcount= 0 ;
st=ct.createstatement();
rs=st.executequery(sql);
while (rs.next())
{
rowcount++;
}
if (rs!= null )
rs.close();
if (st!= null )
st.close();
if (ct!= null )
ct.close();
return rowcount;
}
/**====================================================**
* [## public void insertdata(){}] 插入记录
* 参数 :string table_name,string str
* 返回值 :无
* 修饰符 :public
* 功能 :向数据库中插入记录
**===================================================
* @throws exception **/
public void insertdata(string table_name,string str) throws exception
{
class .forname(drivername);
ct=drivermanager.getconnection(dburl,username,userpwd);
ct.setautocommit( false );
st=ct.createstatement();
string sql= "insert into" + " " +table_name+ " " + "values" + "(" +str+ ")" ;
st.executeupdate(sql);
ct.commit();
if (st!= null )
st.close();
if (ct!= null )
ct.close();
}
/**====================================================**
* [## public void updatedata(string str){}] 更新记录
* 参数 :string sql
* 返回值 :无
* 修饰符 :public
* 功能 :向数据库中更新记录
**===================================================*/
public void updatedata(string sql) throws exception
{
class .forname(drivername);
ct=drivermanager.getconnection(dburl,username,userpwd);
ct.setautocommit( false );
st=ct.createstatement();
st.executeupdate(sql);
ct.commit();
if (st!= null )
st.close();
if (ct!= null )
ct.close();
}
/**====================================================**
* [## public void getdatafromcostomer(){}] 从costomer_table中获取数据
* 参数 :int room_num
* 返回值 :vector<object> data
* 修饰符 :public
* 功能 :根据房间号从costomer_table中获取数据并返回
**===================================================*/
public vector getdatafromcostomer( int room_num) throws exception
{
vector<object> data= new vector<object>();
class .forname(drivername);
ct=drivermanager.getconnection(dburl,username,userpwd);
ct.setautocommit( false );
st=ct.createstatement();
rs=st.executequery( "select * from costomer_table where roomnum=" +room_num+ "and isliving=1" );
while (rs.next())
{
data.add(rs.getint( 1 ));
data.add(rs.getstring( 2 ));
data.add(rs.getstring( 3 ));
data.add(rs.getstring( 4 ));
data.add(rs.getstring( 5 ));
data.add(rs.getstring( 6 ));
data.add(rs.getint( 7 ));
data.add(rs.getint( 8 ));
data.add(rs.getint( 9 ));
}
if (rs!= null )
rs.close();
if (st!= null )
st.close();
if (ct!= null )
ct.close();
return data;
}
/**====================================================**
* [## public vector roomoperation(int room_num) {}] 查询房间信息
* 参数 :无
* 返回值 :return returedata;
* 修饰符 :public
* 功能 :创建sql查询房间号与类型,与入住状态并返回,类外可使用
**===================================================**/
public vector roomoperation() throws exception
{
vector<vector> returedata= new vector<vector>();
vector<object> roomnum= new vector<object>();
vector<object> roomtype= new vector<object>();
vector<integer> roomstate= new vector<integer>();
class .forname(drivername);
ct=drivermanager.getconnection(dburl,username,userpwd);
st=ct.createstatement();
rs=st.executequery( "select roomnum,roomtype,roomatate from room_table" );
while (rs.next())
{
roomnum.add(rs.getint( 1 ));
roomtype.add(rs.getstring( 2 ));
roomstate.add(rs.getint( 3 ));
}
if (rs!= null )
rs.close();
if (st!= null )
st.close();
if (ct!= null )
ct.close();
returedata.add(roomnum);
returedata.add(roomtype);
returedata.add(roomstate);
return returedata;
}
}
|
2.登录界面类
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
|
/**====================================================**
* 项目名 :酒店管理系统
* 模块名 :系统登录窗口
* 文件名 :hotellogingui.java
* 相关文件 :databaseconnct.java hotelmaingui.java
* 实现功能 :系统登录界面
* 函数说明 :
* [## public myjframe(){}]:
* 功能:构造函数 组建登录窗口
* [## public void enevtoperation(final myloginjframe mj){}]
* 功能:登录界面的事件监听处理
* [## private boolean logincheck() {}]:
* 功能:登录验证,仅类内使用
* [## private void quit() {}]:
* 功能:关闭系统函数,仅类内使用
**===================================================**/
package com.hotelgui;
import com.common.*; //引入包
import java.awt.*;
import java.awt.event.actionevent;
import java.awt.event.actionlistener;
import java.awt.event.itemevent;
import java.awt.event.itemlistener;
import javax.jws.soap.soapbinding.style;
import javax.swing.*;
import java.net.*;
import java.util.*;
public class hotellogingui {
public static void main(string[] args) {
// todo auto-generated method stub
myloginjframe logingui= new myloginjframe();
logingui.enevtoperation(logingui);
}
}
//登录界面myjframe
class myloginjframe extends jframe implements actionlistener
{
databaseconnect dc;
jpasswordfield passwordnum;
jtextfield accountnum;
jlabel password,account,login,backimg,backimg1;
jlabel tiplabel;
jcombobox<string> loginchoice;
jbutton loginbutton,resetbutton,exitbutton;
jpanel jp,jp0,jp1,jp2,jp3,jp4,jp5;
vector<string> dept= new vector<string>();
private string id_now,user_type;
/**=======================================================**
* 设置当前成功登录的id
**========================================================*/
public void setid_now(string id_now) {
this .id_now = id_now;
}
/**=======================================================**
* 获得当前成功登录的id
**========================================================*/
public string getid_now() {
return id_now;
}
/**====================================================**
* **[## public myjframe() {}] 组建登录窗口
* 参数 :无
* 返回值 :无
* 修饰符 :public
* 功能 :组建登录窗口
**===================================================**/
public myloginjframe()
{ dc= new databaseconnect(); //连接数据库实例
jp= new jpanel();
jp.setbounds( 0 , - 5 , 550 , 200 );
jp0= new jpanel();
jp0.setbounds( 0 , 180 , 250 , 250 );
jp1= new jpanel();
jp1.setbounds( 270 , 215 , 250 , 30 );
jp2= new jpanel();
jp2.setbounds( 270 , 250 , 250 , 30 );
jp3= new jpanel();
jp3.setbounds( 270 , 280 , 250 , 30 );
jp4= new jpanel();
jp4.setbounds( 270 , 335 , 250 , 40 );
jp5= new jpanel();
jp5.setbounds( 270 , 380 , 250 , 30 );
dept.add( "经理" );
dept.add( "部门主管" );
dept.add( "普通员工" );
account= new jlabel( "账 户" );
password= new jlabel( "密 码" );
login= new jlabel( "用 户 " );
backimg= new jlabel( new imageicon( "images\back.jpg" ));
backimg1= new jlabel( new imageicon( "images\back1.jpg" ));
tiplabel= new jlabel();
tiplabel.setfont( new font( "宋体" , font.plain, 12 ));
tiplabel.setforeground(color.red);
tiplabel.setvisible( false );
passwordnum= new jpasswordfield( 12 );
accountnum= new jtextfield( 12 );
loginbutton= new jbutton( "登 录" );
loginbutton.setopaque( false );
loginbutton.setcontentareafilled( false );
resetbutton= new jbutton( "重 置" );
resetbutton.setopaque( false );
resetbutton.setcontentareafilled( false );
exitbutton = new jbutton( "退 出" );
exitbutton.setopaque( false );
exitbutton.setcontentareafilled( false );
loginchoice = new jcombobox(dept);
jp.add(backimg);
jp0.add(backimg1);
jp1.add(account);
jp1.add(accountnum);
jp2.add(password);
jp2.add(passwordnum);
jp3.add(login);
jp3.add(loginchoice);
jp4.add(loginbutton);
jp4.add(resetbutton);
jp4.add(exitbutton);
jp5.add(tiplabel);
this .add(jp);
this .add(jp0);
this .add(jp1);
this .add(jp2);
this .add(jp3);
this .add(jp4);
this .add(jp5);
this .settitle( "系统登录" );
this .setlayout( null );
this .setdefaultcloseoperation(jframe.exit_on_close);
this .setresizable( false );
this .setbounds( 320 , 160 , 550 , 450 );
this .seticonimage( new imageicon( "images\icon.jpg" ).getimage());
this .setvisible( true );
}
/**====================================================**
* **[## private void enevtoperation() {}] 事件处理
* 参数 :无
* 返回值 :无
* 修饰符 :public
* 功能 :登录窗口的事件操作
**===================================================**/
public void enevtoperation( final myloginjframe mj)
{
/**=======================================================**
* 登录按钮监听事件
**========================================================*/
loginbutton.addactionlistener( new actionlistener() {
@override
public void actionperformed(actionevent e) {
// todo auto-generated method stub
if (logincheck())
{
tiplabel.settext( "正 在 登 录..." );
//记录当前的操作记录
id_now=accountnum.gettext();
user_type=loginchoice.getselecteditem().tostring();
myhotelmaingui mm= new myhotelmaingui(); //登录到主界面
mj.dispose();
//显示当前的操作人员信息
mm.setid_now(id_now);
mm.setuser_type(user_type);
mm.enevtopration();
mm.updateroomstate();
thread th= new thread(mm);
th.start();
}
else if (accountnum.gettext().isempty() && passwordnum.getpassword().length== 0 )
tiplabel.settext( "密码与账号不能为空!" );
else if (accountnum.gettext().isempty() && passwordnum.getpassword().length!= 0 )
tiplabel.settext( "请输入账号..." );
else if (accountnum.gettext().isempty()== false && passwordnum.getpassword().length== 0 )
tiplabel.settext( "请输入密码..." );
else
tiplabel.settext( "请检查后重新输入!" );
tiplabel.setvisible( true );
}
});
/**=======================================================**
* 重置按钮监听事件
**========================================================*/
resetbutton.addactionlistener( new actionlistener() {
@override
public void actionperformed(actionevent e) {
// todo auto-generated method stub
accountnum.settext( "" );
passwordnum.settext( "" );
loginchoice.setselectedindex( 0 );
}
});
/**=======================================================**
* 退出按钮监听事件
**========================================================*/
exitbutton.addactionlistener( new actionlistener() {
@override
public void actionperformed(actionevent e) {
// todo auto-generated method stub
quit();
}
});
}
/**====================================================**
* **[## private boolean logincheck() {}] 登陆验证
* 参数 :无
* 返回值 :flag
* 修饰符 :private
* 功能 :登录验证,仅类内使用
**===================================================**/
public boolean logincheck()
{
boolean flag= false ;
if (loginchoice.getselectedindex()== 0 )
{
try {
dc.sql( "select id,pass_word from mangerers_table" );
} catch (exception e) {
// todo auto-generated catch block
e.printstacktrace();
}
}
if (loginchoice.getselectedindex()== 1 )
{
try {
dc.sql( "select id,pass_word from dept_table" );
} catch (exception e) {
// todo auto-generated catch block
e.printstacktrace();
}
}
if (loginchoice.getselectedindex()== 2 )
{
try {
dc.sql( "select id,pass_word from common_table" );
} catch (exception e) {
// todo auto-generated catch block
e.printstacktrace();
}
}
for ( int i= 0 ;i<dc.getid().size();i++)
{
string password= new string(passwordnum.getpassword());
if (accountnum.gettext().equals(dc.getid().get(i).tostring()) && password.equals(dc.getpassword().get(i).tostring()))
{
flag= true ;
break ;
}
}
return flag;
}
/**====================================================**
* **[## private void quit() {}] 系统退出
* 参数 :无
* 返回值 :无
* 修饰符 :private
* 功能 :关闭系统函数,仅类内使用
**===================================================**/
private void quit()
{
int flag= 0 ;
string msg= "你 确 定 要 关 闭 系 统 吗?" ;
flag=joptionpane.showconfirmdialog( null , msg, "提示" ,joptionpane.yes_no_option);
if (flag==joptionpane.yes_option)
{
this .setvisible( false );
system.exit( 0 );
}
return ;
}
@override
public void actionperformed(actionevent e) {
// todo auto-generated method stub
}
}
|
3.主界面类
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
|
/**====================================================**
* 项目名 :酒店管理系统
* 模块名 :系统登录成功后的主窗口
* 文件名 :hotelmaingui.java
* 相关文件 :hotellogingui.java databaseconnect.java
* 实现功能 :系统登录成功后主界面
* 函数说明 :
* [## public myhotelmaingui(int i){}]:
* 功能:构造函数
* [## public myhotelmaingui(){}]:
* 功能:构造函数 组建登陆窗口
* [## private boolean logincheck() {}]:
* 功能:登录验证,仅类内使用
* [## private void quit() {}]:
* 功能:关闭系统函数,仅类内使用
* [## public void run(){}]
* 功能:线程执行刷新界面
* [## public void setlabeltext(jlabel jl,int row)]
* 功能:为jlabel设置text
**===================================================**/
package com.hotelgui;
import java.awt.*;
import com.common.databaseconnect;
import com.databasejdbc.*;
import javax.swing.*;
import java.text.simpledateformat;
import java.util.*;
import java.awt.event.*;
public class myhotelmaingui extends jframe implements actionlistener,runnable
{
public myhotelmaingui( int i)
{
}
private static final focuslistener focuslistener = null ;
string roomnum,roomtype;
jpopupmenu popupmenu;
jmenubar jmb;
jpanel jp1,jp2,room_jp1;
jlabel time_jl,order_jl,login_jl,change_jl,checkout_jl,relogin_jl,money_jl,exit_jl,emploer_jl;
jmenu jm1,jm2,jm3,jm4,jm5,jm6,jm7,jm8,bt_jm;
jbutton time_bt,order_bt,login_bt,change_bt,checkout_bt,relogin_bt,money_bt,exit_bt,emploer_bt,onef_bt,twof_bt,threef_bt,fourf_bt;
vector<jbutton> roomjb= new vector<jbutton>();
vector<jpopupmenu> popupvector= new vector<jpopupmenu>();
jlabel statelabel,state,staticsstate;
jbutton jj;
jlabel allroom_jl,empty_jl,ordered_jl,isliv_jl,else_jl,allroom_jl1,empty_jl1,ordered_jl1,isliv_jl1,else_jl1;
string id_now,user_type;
/**=======================================================**
* 获取当前成功登录的id
**========================================================*/
public string getid_now() {
return id_now;
}
/**=======================================================**
* 获取当前成功登录的用户类型
**========================================================*/
public string getuser_type() {
return user_type;
}
/**=======================================================**
* 设置当前成功登录的id
**========================================================*/
public void setid_now(string id_now) {
this .id_now = id_now;
}
/**=======================================================**
* 设置当前成功登录的用户类型
**========================================================*/
public void setuser_type(string user_type) {
this .user_type = user_type;
}
/**====================================================**
* **[## public myhotelmaingui() {}] 构造函数
* 参数 :无
* 返回值 :无
* 修饰符 :public
* 功能 :构造函数,初始化主界面
**===================================================**/
public myhotelmaingui()
{
//为每个房间设置点击事件
for ( int i= 0 ;i< 32 ;i++)
{
final string str;
if (i< 10 )
{
str= "40" +(i+ 1 );
}
else
{
str= "4" +(i+ 1 );
}
popupmenu = new jpopupmenu ();
popupvector.add(popupmenu);
jmenuitem ordermenuitem = new jmenuitem ( "新预定" ) ;
ordermenuitem.setfont( new font( "宋体" ,font.italic, 14 ));
popupvector.get(i).add ( ordermenuitem ) ;
//添加事件
ordermenuitem.addactionlistener( new actionlistener() {
@override
public void actionperformed(actionevent e) {
// todo auto-generated method stub
checkin ck= new checkin( "预订登记" , "images\checkin_bt.jpg" );
ck.room_num_jf.settext(str);
ck.cancelbutton();
//登記入住
ck.checkinbutton( 1 );
updateroomstate();
}
});
jmenuitem checkinmenuitem = new jmenuitem ( "入住登记" ) ;
checkinmenuitem.setfont( new font( "宋体" ,font.italic, 14 ));
popupvector.get(i).add ( checkinmenuitem ) ;
checkinmenuitem.addactionlistener( new actionlistener() {
@override
public void actionperformed(actionevent e) {
// todo auto-generated method stub
checkin ck= new checkin( "入住登记" , "images\checkin_bt.jpg" );
ck.room_num_jf.settext(str);
ck.cancelbutton();
//登記入住
ck.checkinbutton( 2 );
updateroomstate();
}
});
// separator
popupmenu.addseparator () ;
jmenuitem changemenuitem = new jmenuitem ( "客人换房" ) ;
changemenuitem.setfont( new font( "宋体" ,font.italic, 14 ));
popupvector.get(i).add ( changemenuitem ) ;
changemenuitem.addactionlistener( new actionlistener() {
@override
public void actionperformed(actionevent e) {
// todo auto-generated method stub
changeroom cr= new changeroom( "客人换房" , "images\change_bt.jpg" );
cr.check_bt.setvisible( false );
cr.jtf.settext(str);
try {
cr.check_bt( "房间未入住!" );
} catch (exception e1) {
// todo auto-generated catch block
e1.printstacktrace();
}
}
});
jmenuitem msgmenuitem = new jmenuitem ( "客人信息" ) ;
msgmenuitem.setfont( new font( "宋体" ,font.italic, 14 ));
popupvector.get(i).add ( msgmenuitem ) ;
msgmenuitem.addactionlistener( new actionlistener() {
@override
public void actionperformed(actionevent e) {
// todo auto-generated method stub
checkmsg cm= new checkmsg( "客人信息" , "images\" );
cm.check_bt.setvisible( false );
cm.jtf.settext(str);
try {
cm.check_bt( "房间未入住!" );
} catch (exception e1) {
// todo auto-generated catch block
e1.printstacktrace();
}
}
});
jmenuitem reckmenuitem = new jmenuitem ( "客人续住" ) ;
reckmenuitem.setfont( new font( "宋体" ,font.italic, 14 ));
popupvector.get(i).add ( reckmenuitem ) ;
popupmenu.addseparator () ;
jmenuitem checkoutmenuitem = new jmenuitem ( "客人退房" ) ;
checkoutmenuitem.setfont( new font( "宋体" ,font.italic, 14 ));
popupvector.get(i).add ( checkoutmenuitem ) ;
checkoutmenuitem.addactionlistener( new actionlistener() {
@override
public void actionperformed(actionevent e) {
// todo auto-generated method stub
checkout co= new checkout( "客人退房" , "images\checkout_bt.jpg" );
co.check_bt.setvisible( false );
co.jtf.settext(str);
try {
co.check_bt( "房间未入住!" );
} catch (exception e1) {
// todo auto-generated catch block
e1.printstacktrace();
}
}
});
}
onef_bt= new jbutton( new imageicon( "images\1f.jpg" ));
onef_bt.setbounds( 20 , 170 , 60 , 50 );
twof_bt= new jbutton( new imageicon( "images\2f.jpg" ));
twof_bt.setbounds( 20 , 250 , 60 , 50 );
threef_bt= new jbutton( new imageicon( "images\3f.jpg" ));
threef_bt.setbounds( 20 , 330 , 60 , 50 );
fourf_bt= new jbutton( new imageicon( "images\4f.jpg" ));
fourf_bt.setbounds( 20 , 410 , 60 , 50 );
for ( int i= 0 ;i< 32 ;i++)
{
jbutton jb= new jbutton();
roomjb.add(jb);
if (i< 8 )
roomjb.get(i).setbounds( 90 *i, 0 , 90 , 90 );
else if (i< 16 )
roomjb.get(i).setbounds( 90 *(i- 8 ), 90 , 90 , 90 );
else if (i< 24 )
roomjb.get(i).setbounds( 90 *(i- 16 ), 180 , 90 , 90 );
else
roomjb.get(i).setbounds( 90 *(i- 24 ), 270 , 90 , 90 );
roomjb.get(i).setcontentareafilled( false );
roomjb.get(i).setcomponentpopupmenu (popupvector.get(i));
}
//放置房间的jpanel
room_jp1= new jpanel();
room_jp1.setlayout( null );
room_jp1.setbounds( 120 , 150 , 730 , 367 );
allroom_jl= new jlabel( new imageicon( "images\all.jpg" ));
allroom_jl1= new jlabel();
allroom_jl.setbounds( 950 , 150 , 75 , 30 );
allroom_jl1.setbounds( 1110 , 150 , 75 , 30 );
empty_jl= new jlabel( new imageicon( "images\empty.jpg" ));
empty_jl1= new jlabel();
empty_jl.setbounds( 950 , 200 , 75 , 30 );
empty_jl1.setbounds( 1110 , 200 , 75 , 30 );
ordered_jl= new jlabel( new imageicon( "images\order.jpg" ));
ordered_jl1= new jlabel();
ordered_jl.setbounds( 950 , 250 , 75 , 30 );
ordered_jl1.setbounds( 1110 , 250 , 75 , 30 );
isliv_jl= new jlabel( new imageicon( "images\isliv.jpg" ));
isliv_jl1= new jlabel();
isliv_jl.setbounds( 950 , 300 , 75 , 30 );
isliv_jl1.setbounds( 1110 , 300 , 75 , 30 );
else_jl= new jlabel( new imageicon( "images\else.jpg" ));
else_jl1= new jlabel();
else_jl1.setbounds( 1110 , 350 , 75 , 30 );
else_jl.setbounds( 950 , 350 , 75 , 30 );
state= new jlabel( "实时房态统计" );
state.setfont( new font( "宋体" ,font.plain, 14 ));
state.setbounds( 1000 , 90 , 100 , 40 );
staticsstate= new jlabel();
staticsstate.setfont( new font( "宋体" ,font.plain, 25 ));
staticsstate.setbounds( 970 , 420 , 250 , 60 );
staticsstate.setforeground(color.red);
jp2= new jpanel();
jp2.setbounds( 10 , 570 , 950 , 50 ); //底部登录状态显示
statelabel= new jlabel();
statelabel.setfont( new font( "宋体" ,font.center_baseline, 12 ));
jp2.add(statelabel);
time_jl= new jlabel( "实时房态" );
time_jl.setfont( new font( "宋体" ,font.layout_no_limit_context, 10 ));
time_jl.setbounds( 10 , 53 , 40 , 10 );
time_bt= new jbutton( new imageicon( "images\实时房态.jpg" ));
time_bt.setbounds( 10 , 10 , 40 , 40 );
time_bt.setborderpainted( false );
order_bt= new jbutton( new imageicon( "images\预定登记.jpg" ));
order_bt.setbounds( 65 , 10 , 40 , 40 );
order_bt.setborderpainted( false );
order_jl= new jlabel( "预定登记" );
order_jl.setfont( new font( "宋体" ,font.layout_no_limit_context, 10 ));
order_jl.setbounds( 65 , 53 , 40 , 10 );
login_bt= new jbutton( new imageicon( "images\入住登记.jpg" ));
login_bt.setbounds( 120 , 10 , 40 , 40 );
login_bt.setborderpainted( false );
login_jl= new jlabel( "入住登记" );
login_jl.setfont( new font( "宋体" ,font.layout_no_limit_context, 10 ));
login_jl.setbounds( 120 , 53 , 40 , 10 );
change_bt= new jbutton( new imageicon( "images\客人换房.jpg" ));
change_bt.setbounds( 175 , 10 , 40 , 40 );
change_bt.setborderpainted( false );
change_jl= new jlabel( "客人换房" );
change_jl.setfont( new font( "宋体" ,font.layout_no_limit_context, 10 ));
change_jl.setbounds( 175 , 53 , 40 , 10 );
relogin_bt= new jbutton( new imageicon( "images\客房续住.jpg" ));
relogin_bt.setbounds( 230 , 10 , 40 , 40 );
relogin_bt.setborderpainted( false );
relogin_jl= new jlabel( "客人续住" );
relogin_jl.setfont( new font( "宋体" ,font.layout_no_limit_context, 10 ));
relogin_jl.setbounds( 230 , 53 , 40 , 10 );
checkout_jl= new jlabel( "客人退房" );
checkout_jl.setfont( new font( "宋体" ,font.layout_no_limit_context, 10 ));
checkout_jl.setbounds( 285 , 53 , 40 , 10 );
checkout_bt= new jbutton( new imageicon( "images\客人退房.jpg" ));
checkout_bt.setbounds( 285 , 10 , 40 , 40 );
checkout_bt.setborderpainted( false );
money_bt= new jbutton( new imageicon( "images\收银报表.jpg" ));
money_bt.setbounds( 340 , 10 , 40 , 40 );
money_bt.setborderpainted( false );
money_jl= new jlabel( "财务报表" );
money_jl.setfont( new font( "宋体" ,font.layout_no_limit_context, 10 ));
money_jl.setbounds( 340 , 53 , 40 , 10 );
exit_bt= new jbutton( new imageicon( "images\退出系统.png" ));
exit_bt.setbounds( 450 , 10 , 40 , 40 );
exit_bt.setborderpainted( false );
exit_jl= new jlabel( "退出系统" );
exit_jl.setfont( new font( "宋体" ,font.layout_no_limit_context, 10 ));
exit_jl.setbounds( 450 , 53 , 40 , 10 );
emploer_bt= new jbutton( new imageicon( "images\员工管理.jpg" ));
emploer_bt.setbounds( 395 , 10 , 40 , 40 );
emploer_bt.setborderpainted( false );
emploer_jl= new jlabel( "员工管理" );
emploer_jl.setfont( new font( "宋体" ,font.layout_no_limit_context, 10 ));
emploer_jl.setbounds( 395 , 53 , 40 , 10 );
jm1= new jmenu( "预订接待(a)" );
jm1.setfont( new font( "宋体" ,font.layout_no_limit_context, 12 ));
jm2= new jmenu( "前台营业(b)" );
jm2.setfont( new font( "宋体" ,font.layout_no_limit_context, 12 ));
jm3= new jmenu( "客户管理(c)" );
jm3.setfont( new font( "宋体" ,font.layout_no_limit_context, 12 ));
jm4= new jmenu( "员工管理(d)" );
jm4.setfont( new font( "宋体" ,font.layout_no_limit_context, 12 ));
jm5= new jmenu( "财务报表(e)" );
jm5.setfont( new font( "宋体" ,font.layout_no_limit_context, 12 ));
jm6= new jmenu( "综合查询(z)" );
jm6.setfont( new font( "宋体" ,font.layout_no_limit_context, 12 ));
jm7= new jmenu( "窗口(p)" );
jm7.setfont( new font( "宋体" ,font.layout_no_limit_context, 12 ));
jm8= new jmenu( "帮助(h)" );
jm8.setfont( new font( "宋体" ,font.layout_no_limit_context, 12 ));
jmb= new jmenubar();
jmb.add(jm1);
jmb.add(jm2);
jmb.add(jm3);
jmb.add(jm4);
jmb.add(jm5);
jmb.add(jm6);
jmb.add(jm7);
jmb.add(jm8);
for ( int i= 0 ;i< 32 ;i++)
{
room_jp1.add(roomjb.get(i));
}
this .add(onef_bt);
this .add(twof_bt);
this .add(threef_bt);
this .add(fourf_bt);
this .add(time_bt);
this .add(order_bt);
this .add(login_bt);
this .add(change_bt);
this .add(relogin_bt);
this .add(change_bt);
this .add(checkout_bt);
this .add(money_bt);
this .add(exit_bt);
this .add(emploer_bt);
this .add(time_jl);
this .add(order_jl);
this .add(login_jl);
this .add(change_jl);
this .add(relogin_jl);
this .add(change_jl);
this .add(checkout_jl);
this .add(money_jl);
this .add(exit_jl);
this .add(emploer_jl);
this .add(jp2);
this .add(state);
this .add(allroom_jl);
this .add(empty_jl);
this .add(isliv_jl);
this .add(ordered_jl);
this .add(else_jl);
this .add(allroom_jl1);
this .add(empty_jl1);
this .add(isliv_jl1);
this .add(ordered_jl1);
this .add(else_jl1);
this .add(staticsstate);
this .setresizable( false );
this .seticonimage( new imageicon( "images\icon.jpg" ).getimage());
this .settitle( "i酒店管理系统" + "——" + "[" + "实时房态" + "]" );
this .setfont( new font( "宋体" ,font.layout_no_limit_context, 12 ));
this .setjmenubar(jmb);
this .setlocation( 50 , 50 );
this .setlayout( null );
this .add(room_jp1);
this .setsize(toolkit.getdefaulttoolkit().getscreensize().width- 100 ,toolkit.getdefaulttoolkit().getscreensize().height- 100 );
this .setdefaultcloseoperation(jframe.exit_on_close);
this .setvisible( true );
}
@override
public void actionperformed(actionevent e) {
// todo auto-generated method stub
}
/**====================================================**
* **[## public void enevtopration {}] 主窗体上的事件监听
* 参数 :无
* 返回值 :无
* 修饰符 :public
* 功能 :监听用户在主窗体中的操作
**===================================================**/
public void enevtopration()
{
order_bt.addmouselistener( new mouselistener() {
@override
public void mouseclicked(mouseevent e) {
// todo auto-generated method stub
checkin ck= new checkin( "预订登记" , "images\checkin_bt.jpg" );
ck.cancelbutton();
//登記入住
ck.checkinbutton( 1 );
updateroomstate();
}
@override
public void mousepressed(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mousereleased(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mouseentered(mouseevent e) {
// todo auto-generated method stub
order_bt.setborderpainted( true );
}
@override
public void mouseexited(mouseevent e) {
// todo auto-generated method stub
order_bt.setborderpainted( false );
}
});
login_bt.addmouselistener( new mouselistener() {
@override
public void mouseclicked(mouseevent e) {
// todo auto-generated method stub
checkin ck= new checkin( "入住登记" , "images\checkin_bt.jpg" );
ck.cancelbutton();
//登記入住
ck.checkinbutton( 2 );
updateroomstate();
}
@override
public void mousepressed(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mousereleased(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mouseentered(mouseevent e) {
// todo auto-generated method stub
login_bt.setborderpainted( true );
}
@override
public void mouseexited(mouseevent e) {
// todo auto-generated method stub
login_bt.setborderpainted( false );
}
});
change_bt.addmouselistener( new mouselistener() {
@override
public void mouseclicked(mouseevent e) {
// todo auto-generated method stub
changeroom cr= new changeroom( "客人换房" , "images\change_bt.jpg" );
updateroomstate();
repaint();
}
@override
public void mousepressed(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mousereleased(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mouseentered(mouseevent e) {
// todo auto-generated method stub
change_bt.setborderpainted( true );
}
@override
public void mouseexited(mouseevent e) {
// todo auto-generated method stub
change_bt.setborderpainted( false );
}
});
relogin_bt.addmouselistener( new mouselistener() {
@override
public void mouseclicked(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mousepressed(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mousereleased(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mouseentered(mouseevent e) {
// todo auto-generated method stub
relogin_bt.setborderpainted( true );
}
@override
public void mouseexited(mouseevent e) {
// todo auto-generated method stub
relogin_bt.setborderpainted( false );
}
});
checkout_bt.addmouselistener( new mouselistener() {
@override
public void mouseclicked(mouseevent e) {
// todo auto-generated method stub
checkout co= new checkout( "客人退房" , "images\checkout_bt.jpg" );
}
@override
public void mousepressed(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mousereleased(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mouseentered(mouseevent e) {
// todo auto-generated method stub
checkout_bt.setborderpainted( true );
}
@override
public void mouseexited(mouseevent e) {
// todo auto-generated method stub
checkout_bt.setborderpainted( false );
}
});
money_bt.addmouselistener( new mouselistener() {
@override
public void mouseclicked(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mousepressed(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mousereleased(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mouseentered(mouseevent e) {
// todo auto-generated method stub
money_bt.setborderpainted( true );
}
@override
public void mouseexited(mouseevent e) {
// todo auto-generated method stub
money_bt.setborderpainted( false );
}
});
emploer_bt.addmouselistener( new mouselistener() {
@override
public void mouseclicked(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mousepressed(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mousereleased(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mouseentered(mouseevent e) {
// todo auto-generated method stub
emploer_bt.setborderpainted( true );
}
@override
public void mouseexited(mouseevent e) {
// todo auto-generated method stub
emploer_bt.setborderpainted( false );
}
});
exit_bt.addmouselistener( new mouselistener() {
@override
public void mouseclicked(mouseevent e) {
// todo auto-generated method stub
quit();
}
@override
public void mousepressed(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mousereleased(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mouseentered(mouseevent e) {
// todo auto-generated method stub
exit_bt.setborderpainted( true );
}
@override
public void mouseexited(mouseevent e) {
// todo auto-generated method stub
exit_bt.setborderpainted( false );
}
});
time_bt.addmouselistener( new mouselistener() {
@override
public void mouseclicked(mouseevent e) {
// todo auto-generated method stub
updateroomstate();
}
@override
public void mousepressed(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mousereleased(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mouseentered(mouseevent e) {
// todo auto-generated method stub
time_bt.setborderpainted( true );
}
@override
public void mouseexited(mouseevent e) {
// todo auto-generated method stub
time_bt.setborderpainted( false );
}
});
}
/**====================================================**
* **[## public void run() {}] 线程执行,随着系统改变当前时间
* 参数 :无
* 返回值 :无
* 修饰符 :public
* 功能 :使用线程使当前界面时间随着系统改变当
**===================================================**/
public void run() {
// todo auto-generated method stub
simpledateformat df = new simpledateformat( "yyyy-mm-dd hh:mm:ss" );
while ( true )
{
statelabel.settext( "当前时间为:" +df.format( new date())+ " " + "当前登录的用户为:" +id_now+ " " + "用户类型为:" +user_type);
statelabel.repaint();
this .repaint();
}
}
/**====================================================**
* **[## private void quit() {}] 系统退出
* 参数 :无
* 返回值 :无
* 修饰符 :private
* 功能 :关闭系统函数,仅类内使用
**===================================================**/
private void quit()
{
int flag= 0 ;
string msg= "你 确 定 要 关 闭 系 统 吗?" ;
flag=joptionpane.showconfirmdialog( null , msg, "提示" ,joptionpane.yes_no_option);
if (flag==joptionpane.yes_option)
{
this .setvisible( false );
system.exit( 0 );
}
return ;
}
/**====================================================**
* **[## public void setlabeltext(jlabel jl,int row) {}] 为jlabel设置text
* 返回值 :无
* 修饰符 :public
* 功能 :为jlabel设置text
**===================================================**/
public void setlabeltext(jlabel jl, int row)
{
try {
jl.settext(integer.tostring(row)+ " " + "间" );
} catch (exception e){}
}
/**====================================================**
* **[## public void updateroomstate{}] 更新入住状态
* 返回值 :无
* 修饰符 :public
* 功能 :更新入住统计情况
**===================================================
* @throws exception **/
public void updateroomstate()
{
databaseconnect ns= new databaseconnect();
vector<vector> returndata = null ;
try {
setlabeltext(allroom_jl1, ns.getrow( "select * from room_table" ));
} catch (exception e) {
// todo auto-generated catch block
e.printstacktrace();
}
int tol= 1 ;
try {
tol = ns.getrow( "select * from room_table" );
} catch (exception e) {
// todo auto-generated catch block
e.printstacktrace();
}
try {
setlabeltext(empty_jl1, ns.getrow( "select * from room_table where roomatate=0" ));
} catch (exception e) {
// todo auto-generated catch block
e.printstacktrace();
}
try {
setlabeltext(ordered_jl1, ns.getrow( "select * from room_table where roomatate=1" ));
} catch (exception e) {
// todo auto-generated catch block
e.printstacktrace();
}
try {
setlabeltext(isliv_jl1, ns.getrow( "select * from room_table where roomatate=2" ));
} catch (exception e) {
// todo auto-generated catch block
e.printstacktrace();
}
int isl= 1 ;
try {
isl = ns.getrow( "select * from room_table where roomatate=2" );
} catch (exception e) {
// todo auto-generated catch block
e.printstacktrace();
}
try {
setlabeltext(else_jl1, ns.getrow( "select * from room_table where roomatate=3" ));
} catch (exception e) {
// todo auto-generated catch block
e.printstacktrace();
}
try {
staticsstate.settext( "入 住 率 :" + " " +( int )(isl* 100 /tol)+ "%" );
returndata=ns.roomoperation();
} catch (exception e) {
// todo auto-generated catch block
e.printstacktrace();
}
for ( int i= 0 ;i<returndata.get( 0 ).size();i++)
{
try {
roomjb.get(i).settext( "<html>" +returndata.get( 0 ).get(i)+ "<br>" +returndata.get( 1 ).get(i)+ "</html>" );
} catch (exception e){}
try {
if (returndata.get( 2 ).get(i).equals( 0 ))
roomjb.get(i).setforeground(color.green);
else if (returndata.get( 2 ).get(i).equals( 1 ))
roomjb.get(i).setforeground(color.pink);
else
roomjb.get(i).setforeground(color.red);
} catch (exception e){}
repaint();
}
}
}
|
4.登记-换房-退房等父类
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
|
/**====================================================**
* 项目名 :酒店管理系统
* 模块名 :入住登记窗口与预定登记窗口
* 文件名 :checkin.java
* 相关文件 :databaseconnct.java
* 实现功能 :入住登记或预定登记并写入数据库
* 函数说明 :
* [## public checkin(){}]:
* 功能:构造函数 组建入住登记窗口
*
* [## public void cancelbutton(){}]
* 功能:取消按钮的事件监听处理
*
* [## returnbutton{}]:
* 功能:返回按钮的事件监听处理
*
* [## public void checkinbutton(final int flag){}]:
* 功能:确定登记按钮的事件监听处理
*
**===================================================**/
package com.databasejdbc;
import com.hotelgui.myhotelmaingui;
import com.common.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.actionevent;
import java.awt.event.actionlistener;
import java.awt.event.mouseevent;
import java.awt.event.mouselistener;
import javax.swing.*;
public class checkin extends jframe {
jlabel name_jl,gender_jl,id_jl,room_num_jl,room_type_jl,checkin_jl,checkout_jl,tital_jl,tip_jl,price_jl,charge_jl,despoit_jl,tip_jl1,tip_jl2;
jbutton checkin_bt,cancel_bt,return_bt;
jcombobox<string> gender_jb,room_type_jb;
jtextfield name_jf,id_jf;
public jtextfield room_num_jf;
jtextfield price_jf;
jtextfield despoit_jf;
jtextfield charge_jf;
jtextfield checkin_jf;
jtextfield checkout_jf;
public static void main(string[] args) {
// todo auto-generated method stub
checkin ck= new checkin( "入住登记" , "images\checkin_bt.jpg" );
ck.cancelbutton();
//ck.checkinbutton();
}
/**====================================================**
* **[## public checkin(){}] 构造函数
* 参数 :string str1,string path //界面tital、按钮ui地址
* 返回值 :无
* 修饰符 :public
* 功能 :构造函数,初始化入住登记界面
**===================================================**/
public checkin(string str1,string path)
{
tital_jl= new jlabel(str1);
tital_jl.setbounds( 300 , 20 , 100 , 60 );
tital_jl.setfont( new font( "宋体" ,font.bold, 23 ));
tip_jl= new jlabel( "(以下信息请完整填写)" );
tip_jl.setbounds( 270 , 70 , 200 , 30 );
tip_jl.setfont( new font( "宋体" ,font.hanging_baseline, 14 ));
name_jl= new jlabel( "姓 名" );
name_jl.setbounds( 150 , 170 , 60 , 30 );
name_jl.setfont( new font( "宋体" ,font.hanging_baseline, 14 ));
name_jf= new jtextfield( 10 );
name_jf.setbounds( 230 , 170 , 140 , 27 );
id_jl= new jlabel( "身份证号" );
id_jl.setbounds( 450 , 170 , 60 , 30 );
id_jl.setfont( new font( "宋体" ,font.hanging_baseline, 14 ));
id_jf= new jtextfield( 10 );
id_jf.setbounds( 530 , 170 , 140 , 27 );
gender_jl= new jlabel( "性 别" );
gender_jl.setbounds( 150 , 220 , 60 , 30 );
gender_jl.setfont( new font( "宋体" ,font.hanging_baseline, 14 ));
gender_jb= new jcombobox<string>();
gender_jb.setbounds( 230 , 220 , 140 , 27 );
gender_jb.additem( "男" );
gender_jb.additem( "女" );
room_num_jl= new jlabel( "房 间 号" );
room_num_jl.setbounds( 450 , 220 , 60 , 30 );
room_num_jl.setfont( new font( "宋体" ,font.hanging_baseline, 14 ));
room_num_jf= new jtextfield( 10 );
room_num_jf.setbounds( 530 , 220 , 140 , 27 );
room_type_jl= new jlabel( "房间标准" );
room_type_jl.setbounds( 150 , 270 , 60 , 30 );
room_type_jl.setfont( new font( "宋体" ,font.hanging_baseline, 14 ));
room_type_jb= new jcombobox<string>();
room_type_jb.setbounds( 230 , 270 , 140 , 27 );
room_type_jb.additem( "商务单间" );
room_type_jb.additem( "商务标间" );
room_type_jb.additem( "大床房" );
room_type_jb.additem( "杂物间" );
price_jl= new jlabel( "房间价格" );
price_jl.setbounds( 450 , 270 , 60 , 30 );
price_jl.setfont( new font( "宋体" ,font.hanging_baseline, 14 ));
price_jf= new jtextfield( 10 );
price_jf.setbounds( 530 , 270 , 140 , 27 );
charge_jl= new jlabel( "实际收费" );
charge_jl.setbounds( 150 , 320 , 60 , 30 );
charge_jl.setfont( new font( "宋体" ,font.hanging_baseline, 14 ));
charge_jf= new jtextfield( 10 );
charge_jf.setbounds( 230 , 320 , 140 , 27 );
despoit_jl= new jlabel( "预收押金" );
despoit_jl.setbounds( 450 , 320 , 60 , 30 );
despoit_jl.setfont( new font( "宋体" ,font.hanging_baseline, 14 ));
despoit_jf= new jtextfield( 10 );
despoit_jf.setbounds( 530 , 320 , 140 , 27 );
checkin_jl= new jlabel( "入住日期" );
tip_jl1= new jlabel( "(####-##-##)" );
tip_jl1.setbounds( 145 , 400 , 80 , 40 );
checkin_jl.setbounds( 150 , 370 , 60 , 40 );
checkin_jl.setfont( new font( "宋体" ,font.hanging_baseline, 14 ));
checkin_jf= new jtextfield( 10 );
checkin_jf.setbounds( 230 , 370 , 140 , 27 );
checkout_jl= new jlabel( "离店日期" );
tip_jl2= new jlabel( "(####-##-##)" );
tip_jl2.setbounds( 445 , 400 , 80 , 40 );
checkout_jl.setbounds( 450 , 370 , 60 , 30 );
checkout_jl.setfont( new font( "宋体" ,font.hanging_baseline, 14 ));
checkout_jf= new jtextfield( 10 );
checkout_jf.setbounds( 530 , 370 , 140 , 27 );
checkin_bt= new jbutton( new imageicon(path));
checkin_bt.setbounds( 160 , 500 , 85 , 30 );
checkin_bt.setopaque( false );
cancel_bt= new jbutton( new imageicon( "images\cancel_bt.jpg" ));
cancel_bt.setbounds( 345 , 500 , 85 , 30 );
cancel_bt.setopaque( false );
return_bt= new jbutton( new imageicon( "images\return_bt.jpg" ));
return_bt.setbounds( 530 , 500 , 85 , 30 );
return_bt.setopaque( false );
return_bt.setactioncommand( "1" );
/**========================================**
* 返回按钮注册监听
=========================================*/
return_bt.addactionlistener( new actionlistener() {
@override
public void actionperformed(actionevent e) {
// todo auto-generated method stub
if (e.getactioncommand().equals( "1" ))
returnbutton();
}
});
this .setlayout( null );
this .add(tital_jl);
this .add(tip_jl);
this .add(name_jl);
this .add(name_jf);
this .add(id_jl);
this .add(gender_jl);
this .add(room_num_jl);
this .add(room_type_jl);
this .add(price_jl);
this .add(charge_jl);
this .add(despoit_jl);
this .add(checkin_jl);
this .add(tip_jl1);
this .add(checkout_jl);
this .add(tip_jl2);
this .add(checkin_bt);
this .add(cancel_bt);
this .add(return_bt);
this .add(id_jf);
this .add(gender_jb);
this .add(room_num_jf);
this .add(room_type_jb);
this .add(price_jf);
this .add(charge_jf);
this .add(despoit_jf);
this .add(checkin_jf);
this .add(checkout_jf);
this .settitle(str1);
this .seticonimage( new imageicon( "images\入住登记.jpg" ).getimage());
this .setbounds( 250 , 80 , toolkit.getdefaulttoolkit().getscreensize().width- 600 ,toolkit.getdefaulttoolkit().getscreensize().height- 150 );
this .setresizable( false );
this .setvisible( true );
}
/**====================================================**
* **[## public void cancelbutton() {}] 取消按钮操作
* 参数 :无
* 返回值 :无
* 修饰符 :public
* 功能 :点击取消按钮清空操作
**===================================================**/
public void cancelbutton()
{
cancel_bt.addactionlistener( new actionlistener() {
@override
public void actionperformed(actionevent e) {
// todo auto-generated method stub
name_jf.settext( "" );
id_jf.settext( "" );
room_num_jf.settext( "" );
charge_jf.settext( "" );
price_jf.settext( "" );
despoit_jf.settext( "" );
checkin_jf.settext( "" );
checkout_jf.settext( "" );
gender_jb.setselectedindex( 0 );
room_type_jb.setselectedindex( 0 );
}
});
}
/**====================================================**
* **[## public void returnbutton() {}] 返回按钮操作
* 参数 :无
* 返回值 :无
* 修饰符 :public
* 功能 :点击返回按钮返回到主界面,入住登记界面释放
**===================================================**/
public void returnbutton()
{
this .dispose();
}
/**====================================================**
* **[## public void checkinbutton(int flag) {}] 确定按钮操作
* 参数 :int flag flag==1,则表示入住登记状态更改 ;flag==2,则表示预订登记状态更改
* 返回值 :无
* 修饰符 :public
* 功能 :点击确定按钮进行入住登记输入数据库操作操作
**===================================================**/
public void checkinbutton( final int flag)
{
checkin_bt.addactionlistener( new actionlistener() {
@override
public void actionperformed(actionevent e) {
// todo auto-generated method stub
databaseconnect dc= new databaseconnect();
string str= new string(integer.valueof(room_num_jf.gettext())+ ",'" +name_jf.gettext()+ "','" +gender_jb.getselecteditem().tostring()+ "','" +
id_jf.gettext()+ "','" +checkin_jf.gettext()+ "','" +checkout_jf.gettext()+ "'," +integer.valueof(charge_jf.gettext())+ "," +integer.valueof(despoit_jf.gettext())+ "," + 1 );
try {
dc.insertdata( "costomer_table" , str);
} catch (exception e1) {
// todo auto-generated catch block
e1.printstacktrace();
}
string sql= "update room_table set roomatate=" +flag+ " where roomnum=" +integer.valueof(room_num_jf.gettext());
try {
dc.updatedata(sql);
} catch (exception e1) {
// todo auto-generated catch block
e1.printstacktrace();
}
joptionpane.showconfirmdialog( null , "登记成功!" , "提示" ,joptionpane.closed_option);
int option= 0 ;
if (option==joptionpane.yes_option)
{
try {
myhotelmaingui hm= new myhotelmaingui( 1 );
hm.updateroomstate();
thread th= new thread(hm);
th.start();
}
catch (exception e1)
{}
}
}
});
}
}
|
源代码比较多,就不再上传了,欢迎交流,共同学习进步。项目全部资源需要可从此下载:java实现酒店管理系统
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/CCP5626/article/details/53590378