Repository navigation
Expand file tree
/
Copy pathSupplier_update.java
More file actions
322 lines (247 loc) · 8.85 KB
/
Copy pathSupplier_update.java
File metadata and controls
322 lines (247 loc) · 8.85 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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import java.awt.Frame;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
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 org.eclipse.birt.report.designer.ui.dialogs.SelectParameterDefaultValueDialog;
import java.awt.Color;
import javax.swing.ImageIcon;
public class Supplier_update {
/**
*
*/
public JFrame frmAmElectronics;
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField t2;
private JTextField t4;
private JTextField t5;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Supplier_update frame = new Supplier_update();
frame.frmAmElectronics.setVisible(true);;
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Supplier_update() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 1378, 858);
contentPane = new JPanel();
contentPane.setBackground(new Color(51, 51, 153));
contentPane.setBorder(new BevelBorder(BevelBorder.LOWERED, Color.BLACK, null, null, null));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("New label");
lblNewLabel.setFont(new Font("Cambria", Font.PLAIN, 22));
lblNewLabel.setForeground(Color.BLACK);
lblNewLabel.setIcon(new ImageIcon("C:\\Users\\LENOVO\\Desktop\\project images\\background-3089930__340.jpg"));
lblNewLabel.setBounds(0, -11, 1380, 764);
contentPane.add(lblNewLabel);
JLabel lblSupplierNo = new JLabel("Supplier No");
lblSupplierNo.setForeground(Color.WHITE);
lblSupplierNo.setFont(new Font("Cambria", Font.PLAIN, 22));
lblSupplierNo.setBounds(544, 216, 129, 39);
contentPane.add(lblSupplierNo);
JLabel lblSupplierDetailsForm = new JLabel("Supplier Details Update Form");
lblSupplierDetailsForm.setForeground(Color.WHITE);
lblSupplierDetailsForm.setFont(new Font("Cambria", Font.BOLD, 25));
lblSupplierDetailsForm.setBounds(534, 149, 348, 47);
contentPane.add(lblSupplierDetailsForm);
JLabel lblSupplierAddress = new JLabel("Address");
lblSupplierAddress.setForeground(Color.WHITE);
lblSupplierAddress.setFont(new Font("Cambria", Font.PLAIN, 22));
lblSupplierAddress.setBounds(544, 308, 82, 31);
contentPane.add(lblSupplierAddress);
JLabel lblName = new JLabel("Name");
lblName.setForeground(Color.WHITE);
lblName.setFont(new Font("Cambria", Font.PLAIN, 22));
lblName.setBounds(544, 266, 91, 31);
contentPane.add(lblName);
JLabel lblEmail = new JLabel("E-mail");
lblEmail.setForeground(Color.WHITE);
lblEmail.setFont(new Font("Cambria", Font.PLAIN, 22));
lblEmail.setBounds(544, 430, 82, 31);
contentPane.add(lblEmail);
JLabel lblContactNo = new JLabel("Contact No");
lblContactNo.setForeground(Color.WHITE);
lblContactNo.setFont(new Font("Cambria", Font.PLAIN, 22));
lblContactNo.setBounds(544, 389, 107, 20);
contentPane.add(lblContactNo);
t2 = new JTextField();
t2.setBounds(674, 266, 138, 29);
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, new Color(0, 0, 0), null));
t3.setBounds(674, 306, 137, 63);
contentPane.add(t3);
t4 = new JTextField();
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(674, 389, 137, 24);
contentPane.add(t4);
t4.setColumns(10);
t5 = new JTextField();
t5.setBounds(674, 429, 138, 20);
contentPane.add(t5);
t5.setColumns(10);
JSeparator separator_1 = new JSeparator();
separator_1.setBounds(544, 494, 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)
{
frmAmElectronics.setVisible(false);
frmAmElectronics.dispose();
}
}
});
btnExit.setFont(new Font("Cambria", Font.BOLD, 22));
btnExit.setBounds(734, 514, 91, 34);
contentPane.add(btnExit);
JComboBox<String> comboBox = new JComboBox<String>();
comboBox.setBounds(674, 228, 91, 22);
contentPane.add(comboBox);
try {
Connection conObject=DriverManager.getConnection("jdbc:ucanaccess://d:/electronics1.accdb");
Statement stmt = conObject.createStatement();
String query = "Select sno from supplier";
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, 22));
btnView.setBounds(822, 216, 91, 39);
contentPane.add(btnView);
JButton btnUpdate = new JButton("Update");
btnUpdate.setFont(new Font("Cambria", Font.BOLD, 22));
btnUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
int resp = JOptionPane.showConfirmDialog(null, "Are you sure you want to update?");
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 = "update supplier set sname=?,saddr=?,scon=?,email=? where sno="+Integer.parseInt(supp);
PreparedStatement stmt = conObject.prepareStatement(query);
stmt.setString(1,t2.getText());
stmt.setString(2,t3.getText());
stmt.setInt(3,Integer.parseInt(t4.getText()));
stmt.setString(4,t5.getText());
int result = stmt.executeUpdate();
if(result == 1)
JOptionPane.showMessageDialog(null, "Record updated successfully!");
else
JOptionPane.showMessageDialog(null,"Insert Error!");
stmt.close();
conObject.close();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
}
}
});
btnUpdate.setBounds(560, 514, 113, 34);
contentPane.add(btnUpdate);
JSeparator separator = new JSeparator();
separator.setBounds(534, 207, 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 supplier where sno="+Integer.parseInt(supp);
PreparedStatement stmt = conObject.prepareStatement(query);
ResultSet rs = stmt.executeQuery();
if(rs.next())
{
t2.setText(rs.getString(2));
t3.setText(rs.getString(3));
t4.setText(String.valueOf(rs.getString(4)));
t5.setText(rs.getString(5));
}
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
}
});
}
private void setContentPane(JPanel contentPane2) {
// TODO Auto-generated method stub
}
private void setBounds(int i, int j, int k, int l) {
// TODO Auto-generated method stub
}
private void setDefaultCloseOperation(int exitOnClose) {
// TODO Auto-generated method stub
}
}