-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateCheck.java
186 lines (153 loc) · 6.21 KB
/
UpdateCheck.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Creating class for check update ( when customer checked - out the hotel room )....
// Import required libraries.......
import javax.naming.Name;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
public class UpdateCheck extends JFrame implements ActionListener{
// Declare Variables globally...
Choice ch;
JTextField RoomNo,Name, checkIn, price,pending;
JButton checkBtn, updateBtn, backBtn;
// Create Constuctor......
UpdateCheck(){
getContentPane().setBackground(Color.WHITE);
setLayout(null);
JLabel head = new JLabel("Update Customer's Status");
head.setFont(new Font("Tahoma",Font.PLAIN,24));
head.setBounds(370,15,280,35);
head.setForeground(Color.BLUE);
add(head);
JLabel csId = new JLabel("Customer Id");
csId.setBounds(80,75,100,30);
csId.setFont(new Font("Tahoma",Font.PLAIN,14));
add(csId);
ch = new Choice();
ch.setBounds(215,76,165,30);
add(ch);
try{
Connector cn = new Connector();
ResultSet rs = cn.stmt.executeQuery("select * from customer");
while(rs.next()){
ch.add(rs.getString("ID_No"));
}
}
catch(Exception er){
er.printStackTrace();
}
JLabel csRN = new JLabel("Room Number");
csRN.setBounds(80,120,100,30);
csRN.setFont(new Font("Tahoma",Font.PLAIN,14));
add(csRN);
RoomNo = new JTextField();
RoomNo.setBounds(215,120,165,25);
add(RoomNo);
JLabel csName = new JLabel("Customer Name");
csName.setBounds(80,165,120,30);
csName.setFont(new Font("Tahoma",Font.PLAIN,14));
add(csName);
Name = new JTextField();
Name.setBounds(215,165,165,25);
add(Name);
JLabel chkIn = new JLabel("Checkin Time");
chkIn.setBounds(80,205,120,30);
chkIn.setFont(new Font("Tahoma",Font.PLAIN,14));
add(chkIn);
checkIn = new JTextField();
checkIn.setBounds(215,205,165,25);
add(checkIn);
JLabel prc = new JLabel("Amount Paid");
prc.setBounds(80,250,120,30);
prc.setFont(new Font("Tahoma",Font.PLAIN,14));
add(prc);
price = new JTextField();
price.setBounds(215,250,165,25);
add(price);
JLabel pendingAmt = new JLabel("Pending Amount");
pendingAmt.setBounds(80,295,120,30);
pendingAmt.setFont(new Font("Tahoma",Font.PLAIN,14));
add(pendingAmt);
pending = new JTextField();
pending.setBounds(215,298,165,25);
add(pending);
checkBtn = new JButton("Check");
checkBtn.setBounds(100,368,110,35);
checkBtn.setFont(new Font("Tahoma",Font.PLAIN,17));
checkBtn.setForeground(Color.white);
checkBtn.setBackground(Color.black);
checkBtn.addActionListener(this);
add(checkBtn);
updateBtn = new JButton("Update");
updateBtn.setBounds(240,368,110,35);
updateBtn.setFont(new Font("Tahoma",Font.PLAIN,17));
updateBtn.setForeground(Color.white);
updateBtn.setBackground(Color.black);
updateBtn.addActionListener(this);
add(updateBtn);
backBtn = new JButton("Cancel");
backBtn.setBounds(175,445,110,35);
backBtn.setFont(new Font("Tahoma",Font.PLAIN,17));
backBtn.setForeground(Color.white);
backBtn.setBackground(Color.black);
backBtn.addActionListener(this);
add(backBtn);
ImageIcon i = new ImageIcon(ClassLoader.getSystemResource("images/customer1.jpeg"));
Image i1 = i.getImage().getScaledInstance(370,400,Image.SCALE_DEFAULT);
ImageIcon i2 = new ImageIcon(i1);
JLabel img = new JLabel(i2);
img.setBounds(515,82,370,400);
add(img);
setBounds(240,99,1000,600);
setVisible(true);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource() == checkBtn){
try{
String id = ch.getSelectedItem();
String qry = "select * from customer where ID_No = '"+id+"'";
Connector cn = new Connector();
ResultSet rs = cn.stmt.executeQuery(qry);
while(rs.next()){
RoomNo.setText(rs.getString("Room_No"));
Name.setText(rs.getString("Name"));
checkIn.setText(rs.getString("Check_in_Time"));
price.setText(rs.getString("Deposit_Amt"));
}
ResultSet rs1 = cn.stmt.executeQuery("select * from rooms where Room_No = '"+RoomNo.getText()+"'");
while(rs1.next()){
String price1 = rs1.getString("Price");
int amtPaid = Integer.parseInt(price1) - Integer.parseInt(price.getText());
pending.setText("" + amtPaid);
}
}catch (Exception er){
er.printStackTrace();
}
}
else if(ae.getSource() == updateBtn){
String numb = ch.getSelectedItem();
String room = RoomNo.getText();
String name = Name.getText();
String check_in = checkIn.getText();
String deposit = price.getText();
try{
Connector cn = new Connector();
cn.stmt.executeUpdate("update customer set Room_No = '"+room+"', Name = '"+name+"', Check_in_Time = '"+check_in+"', Deposit_Amt = '"+deposit+"' whwere ID_No = '"+numb+"'");
JOptionPane.showMessageDialog(null, "Data Updated Successfully.");
setVisible(false);
new Reception();
}
catch (Exception e){
e.printStackTrace();
}
}else if(ae.getSource() == backBtn){
setVisible(false);
new Reception();
}
}
// Create main method..
public static void main(String[] args) {
new UpdateCheck();
}
}