-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddcustomer.java
206 lines (170 loc) · 6.93 KB
/
Addcustomer.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package javaproject;
import java.awt.*;
import java.awt.EventQueue;
import javax.swing.border.EmptyBorder;
import java.awt.Font;
import java.awt.Image;
import java.sql.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Addcustomer extends JFrame {
PreparedStatement pst = null;
private JPanel contentPane;
private JTextField t1, t2, t3, t4, t5, t6, t7, t8;
JComboBox comboBox;
JRadioButton r1, r2;
Choice c1;
public Addcustomer(String username) throws SQLException {
System.out.println(username);
setBounds(580, 220, 850, 550);
contentPane = new JPanel();
setContentPane(contentPane);
contentPane.setLayout(null);
ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("icons/newcustomer.jpg"));
Image i3 = i1.getImage().getScaledInstance(450, 500, Image.SCALE_DEFAULT);
ImageIcon i2 = new ImageIcon(i3);
JLabel l1 = new JLabel(i2);
l1.setBounds(450, 40, 450, 420);
add(l1);
JLabel lblName = new JLabel("NEW CUSTOMER FORM");
lblName.setFont(new Font("Yu Mincho", Font.PLAIN, 20));
lblName.setBounds(118, 11, 260, 53);
contentPane.add(lblName);
JLabel l3 = new JLabel("Username :");
l3.setBounds(35, 70, 200, 14);
contentPane.add(l3);
t7 = new JTextField();
t7.setBounds(271, 70, 150, 20);
contentPane.add(t7);
t7.setColumns(10);
JLabel lblId = new JLabel("ID :");
lblId.setBounds(35, 110, 200, 14);
contentPane.add(lblId);
comboBox = new JComboBox(new String[]{"Passport", "Aadhar Card", "Voter Id", "Driving license"});
comboBox.setBounds(271, 110, 150, 20);
contentPane.add(comboBox);
JLabel l2 = new JLabel("Number :");
l2.setBounds(35, 150, 200, 14);
contentPane.add(l2);
t1 = new JTextField();
t1.setBounds(271, 150, 150, 20);
contentPane.add(t1);
t1.setColumns(10);
JLabel lblName_1 = new JLabel("Name :");
lblName_1.setBounds(35, 190, 200, 14);
contentPane.add(lblName_1);
t2 = new JTextField();
t2.setBounds(271, 190, 150, 20);
contentPane.add(t2);
t2.setColumns(10);
JLabel lblGender = new JLabel("Gender :");
lblGender.setBounds(35, 230, 200, 14);
contentPane.add(lblGender);
r1 = new JRadioButton("Male");
r1.setFont(new Font("Raleway", Font.BOLD, 14));
r1.setBackground(Color.WHITE);
r1.setBounds(271, 230, 80, 12);
add(r1);
r2 = new JRadioButton("Female");
r2.setFont(new Font("Raleway", Font.BOLD, 14));
r2.setBackground(Color.WHITE);
r2.setBounds(350, 230, 100, 12);
add(r2);
JLabel lblCountry = new JLabel("Country :");
lblCountry.setBounds(35, 270, 200, 14);
contentPane.add(lblCountry);
t3 = new JTextField();
t3.setBounds(271, 270, 150, 20);
contentPane.add(t3);
t3.setColumns(10);
JLabel lblReserveRoomNumber = new JLabel("Permanent Address :");
lblReserveRoomNumber.setBounds(35, 310, 200, 14);
contentPane.add(lblReserveRoomNumber);
t5 = new JTextField();
t5.setBounds(271, 310, 150, 20);
contentPane.add(t5);
t5.setColumns(10);
JLabel lblCheckInStatus = new JLabel("Phone :");
lblCheckInStatus.setBounds(35, 350, 200, 14);
contentPane.add(lblCheckInStatus);
t6 = new JTextField();
t6.setBounds(271, 350, 150, 20);
contentPane.add(t6);
t6.setColumns(10);
JLabel lblDeposite = new JLabel("Email :");
lblDeposite.setBounds(35, 390, 200, 14);
contentPane.add(lblDeposite);
t8 = new JTextField();
t8.setBounds(271, 390, 150, 20);
contentPane.add(t8);
t8.setColumns(10);
try {
Conn c = new Conn();
ResultSet rs = c.s.executeQuery("select * from account where username = '" + username + "'");
while (rs.next()) {
t7.setText(rs.getString("username"));
t2.setText(rs.getString("name"));
}
} catch (Exception e) {
}
JButton btnNewButton = new JButton("Add");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Conn c = new Conn();
String radio = null;
if (r1.isSelected()) {
radio = "Male";
} else if (r2.isSelected()) {
radio = "Female";
}
try {
String s9 = t7.getText(); //username
String s1 = (String) comboBox.getSelectedItem();
String s2 = t1.getText();
String s3 = t2.getText();
String s4 = radio;
String s5 = t3.getText();
String s7 = t5.getText(); //address
String s8 = t6.getText();
String s10 = t8.getText(); //email
String q1 = "insert into customer values('" + s9 + "','" + s1 + "','" + s2 + "','" + s3 + "','" + s4 + "','" + s5 + "','" + s7 + "','" + s8 + "','" + s10 + "')";
c.s.executeUpdate(q1);
JOptionPane.showMessageDialog(null, "Customer Added Successfully");
setVisible(false);
} catch (SQLException e1) {
System.out.println(e1.getMessage());
} catch (NumberFormatException s) {
JOptionPane.showMessageDialog(null, "Please enter a valid Number");
}
}
});
btnNewButton.setBounds(100, 430, 120, 30);
btnNewButton.setBackground(Color.BLACK);
btnNewButton.setForeground(Color.WHITE);
contentPane.add(btnNewButton);
JButton btnExit = new JButton("Back");
btnExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
btnExit.setBounds(260, 430, 120, 30);
btnExit.setBackground(Color.BLACK);
btnExit.setForeground(Color.WHITE);
contentPane.add(btnExit);
getContentPane().setBackground(Color.WHITE);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Addcustomer frame = new Addcustomer("");
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}