-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer_delete.java
More file actions
302 lines (237 loc) · 8.17 KB
/
Customer_delete.java
File metadata and controls
302 lines (237 loc) · 8.17 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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.JSeparator;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.awt.event.ActionEvent;
import javax.swing.JComboBox;
import javax.swing.border.BevelBorder;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JFormattedTextField;
public class Customer_delete extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField t2;
private JTextField t5;
private JTextField t4;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Customer_delete frame = new Customer_delete();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Customer_delete() {
setTitle("AM ELECTRONICS");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 824, 661);
contentPane = new JPanel();
contentPane.setBackground(new Color(51, 51, 153));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblSupplierNo = new JLabel("Customer No");
lblSupplierNo.setForeground(new Color(255, 255, 255));
lblSupplierNo.setFont(new Font("Cambria", Font.BOLD, 15));
lblSupplierNo.setBounds(63, 55, 82, 21);
contentPane.add(lblSupplierNo);
JLabel lblSupplierDetailsForm = new JLabel("Customer Delete Form");
lblSupplierDetailsForm.setForeground(new Color(255, 255, 255));
lblSupplierDetailsForm.setFont(new Font("Cambria", Font.BOLD, 17));
lblSupplierDetailsForm.setBounds(189, 11, 238, 21);
contentPane.add(lblSupplierDetailsForm);
JLabel lblSupplierAddress = new JLabel("Address");
lblSupplierAddress.setForeground(new Color(255, 255, 255));
lblSupplierAddress.setFont(new Font("Cambria", Font.BOLD, 15));
lblSupplierAddress.setBounds(63, 124, 82, 14);
contentPane.add(lblSupplierAddress);
JLabel lblName = new JLabel("Name");
lblName.setForeground(new Color(255, 255, 255));
lblName.setFont(new Font("Cambria", Font.BOLD, 15));
lblName.setBounds(63, 87, 46, 14);
contentPane.add(lblName);
JLabel lblEmail = new JLabel("E-mail");
lblEmail.setForeground(new Color(255, 255, 255));
lblEmail.setFont(new Font("Cambria", Font.BOLD, 15));
lblEmail.setBounds(63, 227, 46, 14);
contentPane.add(lblEmail);
JLabel lblContactNo = new JLabel("Contact No");
lblContactNo.setForeground(new Color(255, 255, 255));
lblContactNo.setFont(new Font("Cambria", Font.BOLD, 15));
lblContactNo.setBounds(63, 196, 82, 14);
contentPane.add(lblContactNo);
t2 = new JTextField();
t2.setBounds(154, 84, 138, 20);
contentPane.add(t2);
t2.setColumns(10);
JTextArea textArea = new JTextArea();
textArea.setBounds(251, 112, -94, 39);
contentPane.add(textArea);
JTextArea t3 = new JTextArea();
t3.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, Color.BLACK, null));
t3.setBounds(155, 120, 137, 63);
contentPane.add(t3);
t4 = new JTextField();
//t4.addKeyListener(keyListener);
t4.addKeyListener(new KeyAdapter()
{
private static final long serialVersionUID = 1L;
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (!((c >= '0') && (c <= '9') ||
(c == KeyEvent.VK_BACK_SPACE) ||
(c == KeyEvent.VK_DELETE))) {
getToolkit().beep();
t4.setToolTipText("Please enter numbers ONLY");
e.consume();
}
}
});
t4.setBounds(155, 195, 137, 20);
contentPane.add(t4);
t4.setColumns(10);
t5 = new JTextField();
t5.setBounds(154, 224, 138, 20);
contentPane.add(t5);
t5.setColumns(10);
JSeparator separator_1 = new JSeparator();
separator_1.setBounds(63, 255, 314, 2);
contentPane.add(separator_1);
JButton btnExit = new JButton("Exit");
btnExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int resp = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit?");
if(resp == 0)
{
System.exit(1);
MDI1 frame1 = new MDI1();
frame1.frmAmEletronics.setVisible(true);
}
}
});
btnExit.setFont(new Font("Cambria", Font.BOLD, 15));
btnExit.setBounds(336, 278, 91, 23);
contentPane.add(btnExit);
JComboBox<String> comboBox = new JComboBox<String>();
comboBox.setBounds(155, 54, 91, 22);
contentPane.add(comboBox);
try {
Connection conObject=DriverManager.getConnection("jdbc:ucanaccess://d:/electronics1.accdb");
Statement stmt = conObject.createStatement();
String query = "Select cno from Customer_add";
ResultSet rs = stmt.executeQuery(query);
while(rs.next())
{
comboBox.addItem(rs.getString(1));
}
stmt.close();
conObject.close();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
JButton btnView = new JButton("Show");
btnView.setFont(new Font("Cambria", Font.BOLD, 15));
btnView.setBounds(272, 54, 91, 23);
contentPane.add(btnView);
JButton btnUpdate = new JButton("Delete");
btnUpdate.setIcon(null);
btnUpdate.setFont(new Font("Cambria", Font.BOLD, 15));
btnUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
int resp = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete?");
if(resp == 0)
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conObject=DriverManager.getConnection("jdbc:ucanaccess://d:/electronics1.accdb");
String supp=String.valueOf(comboBox.getSelectedItem());
String query = "delete * from Customer_add where cno="+Integer.parseInt(supp);
PreparedStatement stmt = conObject.prepareStatement(query);
int result = stmt.executeUpdate();
if(result == 1)
{
JOptionPane.showMessageDialog(null, "Record deleted successfully!");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
comboBox.removeItem(supp);
}
else
JOptionPane.showMessageDialog(null,"Insert Error!");
stmt.close();
conObject.close();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
}
}
});
btnUpdate.setBounds(97, 278, 109, 46);
contentPane.add(btnUpdate);
JSeparator separator = new JSeparator();
separator.setBounds(63, 43, 314, 2);
contentPane.add(separator);
btnView.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conObject=DriverManager.getConnection("jdbc:ucanaccess://d:/electronics1.accdb");
String supp=String.valueOf(comboBox.getSelectedItem());
String query = "select * from Customer_add where cno="+Integer.parseInt(supp);
PreparedStatement stmt = conObject.prepareStatement(query);
ResultSet rs = stmt.executeQuery();
while(rs.next())
{
t2.setText(rs.getString(2));
t3.setText(rs.getString(3));
t4.setText(String.valueOf(rs.getString(4)));
t5.setText(rs.getString(5));
}
stmt.close();
conObject.close();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
}
});
}
}