Repository navigation
Expand file tree
/
Copy pathSearchRoom.java
More file actions
146 lines (125 loc) · 4.9 KB
/
Copy pathSearchRoom.java
File metadata and controls
146 lines (125 loc) · 4.9 KB
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
package Hotel.Management.System;
import net.proteanit.sql.DbUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class SearchRoom extends JFrame implements ActionListener {
JCheckBox checkBox;
Choice choice;
JTable table;
JButton add, back;
SearchRoom(){
JPanel panel = new JPanel();
panel.setBackground(new Color(3,45,48));
panel.setBounds(5,5,690,490);
panel.setLayout(null);
add(panel);
JLabel searchForRoom = new JLabel("Search For Room");
searchForRoom.setBounds(250,11,186,31);
searchForRoom.setForeground(Color.WHITE);
searchForRoom.setFont(new Font("Tahoma", Font.BOLD,20));
panel.add(searchForRoom);
JLabel rbt = new JLabel("Room Bed Type:");
rbt.setBounds(50,73,120,20);
rbt.setForeground(Color.WHITE);
rbt.setFont(new Font("Tahoma", Font.BOLD,14));
panel.add(rbt);
JLabel rn = new JLabel("Room Number");
rn.setBounds(23,162,150,20);
rn.setForeground(Color.WHITE);
rn.setFont(new Font("Tahoma", Font.BOLD,14));
panel.add(rn);
JLabel available = new JLabel("Availability");
available.setBounds(175,162,150,20);
available.setForeground(Color.WHITE);
available.setFont(new Font("Tahoma", Font.BOLD,14));
panel.add(available);
JLabel price = new JLabel("Price");
price.setBounds(458,162,150,20);
price.setForeground(Color.WHITE);
price.setFont(new Font("Tahoma", Font.BOLD,14));
panel.add(price);
JLabel BT = new JLabel("Bed Type");
BT.setBounds(580,162,150,20);
BT.setForeground(Color.WHITE);
BT.setFont(new Font("Tahoma", Font.BOLD,14));
panel.add(BT);
JLabel SS = new JLabel("Clean Status");
SS.setBounds(306,162,150,20);
SS.setForeground(Color.WHITE);
SS.setFont(new Font("Tahoma", Font.BOLD,14));
panel.add(SS);
checkBox = new JCheckBox("Only Display Available");
checkBox.setBounds(400,69,205,23);
checkBox.setForeground(Color.WHITE);
checkBox.setBackground(new Color(3,45,48));
panel.add(checkBox);
choice = new Choice();
choice.add("Single Bed");
choice.add("Double Bed");
choice.setBounds(170,70,120,20);
panel.add(choice);
table = new JTable();
table.setBounds(0,187,700,150);
table.setBackground(new Color(3,45,48));
table.setForeground(Color.WHITE);
panel.add(table);
try{
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/HotelMS","chirayu","chirayu");
Statement stmt = con.createStatement();
String q = "select * from Room";
ResultSet resultSet = stmt.executeQuery(q);
table.setModel(DbUtils.resultSetToTableModel(resultSet));
}catch (Exception e){
e.printStackTrace();
}
add = new JButton("Search");
add.setBounds(200,400,120,30);
add.setBackground(Color.BLACK);
add.setForeground(Color.WHITE);
add.addActionListener(this);
panel.add(add);
back = new JButton("Back");
back.setBounds(380,400,120,30);
back.setBackground(Color.BLACK);
back.setForeground(Color.WHITE);
back.addActionListener(this);
panel.add(back);
setUndecorated(true);
setLayout(null);
setLocation(500,200);
setSize(700,500);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource()==add){
String Q = "select * from Room where BedType = '"+choice.getSelectedItem()+"'";
String Q1 = "select * from Room where Ava = 'Available' AND BedType = '"+choice.getSelectedItem()+"'";
try {
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/HotelMS","chirayu","chirayu");
Statement stmt = con.createStatement();
ResultSet resultSet = stmt.executeQuery(Q);
table.setModel(DbUtils.resultSetToTableModel(resultSet));
if (checkBox.isSelected()){
ResultSet resultSet1 = stmt.executeQuery(Q1);
table.setModel(DbUtils.resultSetToTableModel(resultSet1));
}
}catch (Exception E){
E.printStackTrace();
}
}else {
setVisible(false);
}
}
public static void main(String[] args) {
new SearchRoom();
}
}