-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateRoom.java
138 lines (119 loc) · 3.85 KB
/
updateRoom.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
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.sql.*;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class updateRoom extends JFrame {
Connection conn = null;
PreparedStatement pst = null;
private JPanel contentPane;
private JTextField txt_ID;
private JTextField txt_Ava;
private JTextField txt_Status;
private JTextField txt_Room;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
updateRoom frame = new updateRoom();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public void close(){
this.dispose();
}
/**
* Create the frame.
* @throws SQLException
*/
public updateRoom() throws SQLException {
conn = Javaconnect.getDBConnection();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 447, 406);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblUpdateRoomStatus = new JLabel("Update Room Status");
lblUpdateRoomStatus.setFont(new Font("Tahoma", Font.PLAIN, 20));
lblUpdateRoomStatus.setBounds(115, 11, 206, 34);
contentPane.add(lblUpdateRoomStatus);
JLabel lblNewLabel = new JLabel("Guest ID:");
lblNewLabel.setBounds(27, 87, 90, 14);
contentPane.add(lblNewLabel);
JLabel lblAvailability = new JLabel("Availability:");
lblAvailability.setBounds(27, 187, 90, 14);
contentPane.add(lblAvailability);
JLabel lblCleanStatus = new JLabel("Clean Status:");
lblCleanStatus.setBounds(27, 240, 90, 14);
contentPane.add(lblCleanStatus);
txt_ID = new JTextField();
txt_ID.setBounds(208, 84, 86, 20);
contentPane.add(txt_ID);
txt_ID.setColumns(10);
txt_Ava = new JTextField();
txt_Ava.setBounds(208, 184, 86, 20);
contentPane.add(txt_Ava);
txt_Ava.setColumns(10);
txt_Status = new JTextField();
txt_Status.setBounds(208, 237, 86, 20);
contentPane.add(txt_Status);
txt_Status.setColumns(10);
JButton btnUpdate = new JButton("Update");
btnUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) throws NumberFormatException {
String updateSQL = "Update Room set r_guestid = ?, r_checkstatus = ?, r_cleanstatus = ? where r_id = ?";
try{
pst = conn.prepareStatement(updateSQL);
pst.setInt(1, Integer.parseInt(txt_ID.getText()));
pst.setString(2, txt_Ava.getText());
pst.setString(3, txt_Status.getText());
pst.setInt(4, Integer.parseInt(txt_Room.getText()));
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "Update Sucessful");
close();
}catch (SQLException e1){
e1.printStackTrace();
}
catch(Exception s){
if(txt_Room.getText().equals(""))
{
JOptionPane.showMessageDialog(null, "Please Enter the Room ID");
}
else{
JOptionPane.showMessageDialog(null, "Please Enter a Valid Number");
}
}
}
});
btnUpdate.setBounds(216, 315, 89, 23);
contentPane.add(btnUpdate);
JButton btnExit = new JButton("Exit");
btnExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
close();
}
});
btnExit.setBounds(332, 315, 89, 23);
contentPane.add(btnExit);
JLabel lblRoomId = new JLabel("Room ID:");
lblRoomId.setBounds(27, 133, 79, 14);
contentPane.add(lblRoomId);
txt_Room = new JTextField();
txt_Room.setBounds(208, 130, 86, 20);
contentPane.add(txt_Room);
txt_Room.setColumns(10);
}
}