-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckOut.java
172 lines (137 loc) · 5.48 KB
/
CheckOut.java
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hotel.management.system;
import java.awt.BorderLayout;
import java.awt.*;
import java.awt.EventQueue;
import java.sql.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.Font;
import java.awt.event.*;
import java.awt.event.ActionEvent;
public class CheckOut extends JFrame{
Connection conn = null;
PreparedStatement pst = null;
private JPanel contentPane;
private JTextField t1;
Choice c1;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
CheckOut frame = new CheckOut();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public void close(){
this.dispose();
}
/**
* Create the frame.
* @throws SQLException
*/
public CheckOut() throws SQLException {
//conn = Javaconnect.getDBConnection();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(530, 200, 800, 294);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("hotel/management/system/icons/sixth.jpg"));
Image i3 = i1.getImage().getScaledInstance(400, 225,Image.SCALE_DEFAULT);
ImageIcon i2 = new ImageIcon(i3);
JLabel l1 = new JLabel(i2);
l1.setBounds(300,0,500,225);
add(l1);
JLabel lblCheckOut = new JLabel("Check Out ");
lblCheckOut.setFont(new Font("Tahoma", Font.PLAIN, 20));
lblCheckOut.setBounds(70, 11, 140, 35);
contentPane.add(lblCheckOut);
JLabel lblName = new JLabel("Number :");
lblName.setBounds(20, 85, 80, 14);
contentPane.add(lblName);
c1 = new Choice();
try{
conn c = new conn();
ResultSet rs = c.s.executeQuery("select * from customer");
while(rs.next()){
c1.add(rs.getString("number"));
}
}catch(Exception e){ }
c1.setBounds(130, 82, 150, 20);
contentPane.add(c1);
ImageIcon i4 = new ImageIcon(ClassLoader.getSystemResource("hotel/management/system/icons/tick.png"));
Image i5 = i4.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT);
ImageIcon i6 = new ImageIcon(i5);
JButton l2 = new JButton(i6);
l2.setBounds(290,82,20,20);
add(l2);
l2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
System.out.println("Hi");
try{
conn c = new conn();
String number = c1.getSelectedItem();
ResultSet rs = c.s.executeQuery("select * from customer where number = "+number);
if(rs.next()){
System.out.println("clicked");
t1.setText(rs.getString("room_number"));
}
}catch(Exception e){ }
}
});
JLabel lblRoomNumber = new JLabel("Room Number:");
lblRoomNumber.setBounds(20, 132, 86, 20);
contentPane.add(lblRoomNumber);
t1 = new JTextField();
t1.setBounds(130, 132, 150, 20);
contentPane.add(t1);
JButton btnCheckOut = new JButton("Check Out");
btnCheckOut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String id = c1.getSelectedItem();
String s1 = t1.getText();
String deleteSQL = "Delete from customer where number = "+id;
String q2 = "update room set availability = 'Available' where room_number = "+s1;
conn c = new conn();
try{
c.s.executeUpdate(deleteSQL);
c.s.executeUpdate(q2);
JOptionPane.showMessageDialog(null, "Check Out Successful");
new Reception().setVisible(true);
setVisible(false);
}catch(SQLException e1){
System.out.println(e1.getMessage());
}
}
});
btnCheckOut.setBounds(50, 200, 100, 25);
btnCheckOut.setBackground(Color.BLACK);
btnCheckOut.setForeground(Color.WHITE);
contentPane.add(btnCheckOut);
JButton btnExit = new JButton("Back");
btnExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Reception().setVisible(true);
setVisible(false);
}
});
btnExit.setBounds(160, 200, 100, 25);
btnExit.setBackground(Color.BLACK);
btnExit.setForeground(Color.WHITE);
contentPane.add(btnExit);
getContentPane().setBackground(Color.WHITE);
}
}