-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainSupplier.java
360 lines (303 loc) · 11.7 KB
/
MainSupplier.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
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
//package forms;
import java.sql.*;
import javax.swing.*;
import java.awt.EventQueue;
import javax.swing.border.EmptyBorder;
import net.proteanit.sql.DbUtils;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.table.DefaultTableModel;
import javax.swing.border.MatteBorder;
import java.awt.Font;
public class MainSupplier extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainSupplier frame = new MainSupplier();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
Connection connection = null;
PreparedStatement pst ;
ResultSet rs;
private JTable table;
public void close() {
this.setVisible(false);
this.dispose();
}
private void updateTable() {
String sql = "Select * from supplierregister";
try {
pst = connection.prepareStatement(sql);
rs = pst.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the frame.
*/
public MainSupplier() {
setResizable(false);
setTitle("Supplier Form");
connection = MyConnection.getConnection();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 1459, 602);
contentPane = new JPanel();
contentPane.setBackground(new Color(0, 128, 128));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBackground(new Color(47, 79, 79));
panel.setForeground(new Color(255, 255, 240));
panel.setBounds(0, 0, 148, 373);
contentPane.add(panel);
panel.setLayout(null);
JLabel lblMenu = new JLabel("Menu");
lblMenu.setForeground(new Color(95, 158, 160));
lblMenu.setFont(new Font("Gill Sans Ultra Bold", Font.BOLD, 19));
lblMenu.setBackground(new Color(47, 79, 79));
lblMenu.setBounds(35, 5, 74, 26);
panel.add(lblMenu);
JButton btnHome = new JButton("Home");
btnHome.setForeground(new Color(0, 0, 0));
btnHome.setToolTipText("");
btnHome.setBackground(new Color(192, 192, 192));
btnHome.setFont(new Font("Tahoma", Font.BOLD, 12));
btnHome.setHorizontalAlignment(SwingConstants.LEFT);
btnHome.setIcon(new ImageIcon(EmployeeDetails.class.getResource("/images/Apps-Home-icon.png")));
btnHome.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
menu mu= new menu();
mu.show();
close();
}
});
btnHome.setBounds(10, 42, 128, 36);
panel.add(btnHome);
JButton btnProduct = new JButton("Product");
btnProduct.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ProductCategories ps = new ProductCategories();
ps.show();
close();
}
});
btnProduct.setIcon(new ImageIcon(EmployeeDetails.class.getResource("/images/product.png")));
btnProduct.setToolTipText("");
btnProduct.setHorizontalAlignment(SwingConstants.LEFT);
btnProduct.setForeground(Color.BLACK);
btnProduct.setFont(new Font("Tahoma", Font.BOLD, 12));
btnProduct.setBackground(new Color(192, 192, 192));
btnProduct.setBounds(10, 89, 128, 36);
panel.add(btnProduct);
JButton btnSupplier = new JButton("Supplier");
btnSupplier.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnSupplier.setIcon(new ImageIcon(EmployeeDetails.class.getResource("/images/supplier.png")));
btnSupplier.setToolTipText("");
btnSupplier.setHorizontalAlignment(SwingConstants.LEFT);
btnSupplier.setForeground(Color.BLACK);
btnSupplier.setFont(new Font("Tahoma", Font.BOLD, 12));
btnSupplier.setBackground(new Color(192, 192, 192));
btnSupplier.setBounds(10, 134, 128, 36);
panel.add(btnSupplier);
JButton btnCustomer = new JButton("Customer");
btnCustomer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnCustomer.setIcon(new ImageIcon(EmployeeDetails.class.getResource("/images/customer.png")));
btnCustomer.setToolTipText("");
btnCustomer.setHorizontalAlignment(SwingConstants.LEFT);
btnCustomer.setForeground(Color.BLACK);
btnCustomer.setFont(new Font("Tahoma", Font.BOLD, 11));
btnCustomer.setBackground(new Color(192, 192, 192));
btnCustomer.setBounds(10, 181, 128, 36);
panel.add(btnCustomer);
JButton btnOrder = new JButton("Order");
btnOrder.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnOrder.setIcon(new ImageIcon(EmployeeDetails.class.getResource("/images/sale.png")));
btnOrder.setToolTipText("");
btnOrder.setHorizontalAlignment(SwingConstants.LEFT);
btnOrder.setForeground(Color.BLACK);
btnOrder.setFont(new Font("Tahoma", Font.BOLD, 12));
btnOrder.setBackground(new Color(192, 192, 192));
btnOrder.setBounds(10, 227, 128, 36);
panel.add(btnOrder);
JButton btnInventory = new JButton("Inventory");
btnInventory.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Inventory in = new Inventory();
in.show();
close();
}
});
btnInventory.setIcon(new ImageIcon(EmployeeDetails.class.getResource("/images/material.png")));
btnInventory.setToolTipText("");
btnInventory.setHorizontalAlignment(SwingConstants.LEFT);
btnInventory.setForeground(Color.BLACK);
btnInventory.setFont(new Font("Tahoma", Font.BOLD, 11));
btnInventory.setBackground(new Color(192, 192, 192));
btnInventory.setBounds(10, 274, 128, 36);
panel.add(btnInventory);
JButton btnEmployee = new JButton("Employee");
btnEmployee.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EmployeeDetails emp = new EmployeeDetails();
emp.show();
close();
}
});
btnEmployee.setIcon(new ImageIcon(EmployeeDetails.class.getResource("/images/employee.png")));
btnEmployee.setToolTipText("");
btnEmployee.setHorizontalAlignment(SwingConstants.LEFT);
btnEmployee.setForeground(Color.BLACK);
btnEmployee.setFont(new Font("Tahoma", Font.BOLD, 12));
btnEmployee.setBackground(new Color(192, 192, 192));
btnEmployee.setBounds(10, 321, 128, 36);
panel.add(btnEmployee);
JPanel panel1 = new JPanel();
panel1.setBounds(5, 5, 266, 560);
contentPane.add(panel1);
JButton btnRegister = new JButton("Register New Supplier");
btnRegister.setFont(new Font("Courier New", Font.BOLD, 20));
btnRegister.setBackground(new Color(102, 205, 170));
btnRegister.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//create an object of second frame
Register rframe = new Register();
rframe.setVisible(true);
}
});
btnRegister.setBounds(528, 492, 294, 52);
contentPane.add(btnRegister);
try {
String query = "Select * from supplierregister";
pst = connection.prepareStatement(query);
rs = pst.executeQuery();
JScrollPane scrollPane = new JScrollPane();
scrollPane.setFont(new Font("Poor Richard", Font.BOLD, 18));
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setBounds(286, 111, 1155, 358);
contentPane.add(scrollPane);
table = new JTable();
scrollPane.setViewportView(table);
table.setRowHeight(30);
table.setFont(new Font("Poor Richard", Font.BOLD, 20));
table.setEnabled(true);
table.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
table.setBackground(new Color(230, 230, 250));
table.setModel(new DefaultTableModel(
new Object[][] {
{new Integer(2), "Jenita Joli Fille", "Royal Road La Flora", new Integer(57035021), "[email protected]", "Diamond"},
{new Integer(3), "A&A Company Ltd", "Plaisance, Rose Hill", new Integer(58469356), "[email protected]", "Stones"},
{new Integer(4), "abc ltd", "fatima road, Plaine Magnien", new Integer(6179627), "[email protected]", "Water"},
{new Integer(5), "kr ltd", "royal road petit raffray", new Integer(52894613), "[email protected]", "Stones White"},
{new Integer(6), "kede ltd", "royal road ebene", new Integer(57896412), "[email protected]", "White Pearl"},
{new Integer(12), "XYZ Ltd", "Royal Road, Camp Thorel", new Integer(57841391), "[email protected]", "Shiny White Stones"},
{new Integer(13), "Figaro Ltd", "Petit lil street, Montagne Long", new Integer(6152342), "[email protected]", "Gems Blue"},
{new Integer(14), "Tylon Ltd", "Royal road Petit Cabane", new Integer(54023146), "[email protected]", "Gem White"},
},
new String[] {
"Id", "Name", "Address", "Contact Number", "Email", "Items"
}
));
table.getColumnModel().getColumn(1).setPreferredWidth(283);
table.getColumnModel().getColumn(2).setPreferredWidth(400);
table.getColumnModel().getColumn(3).setPreferredWidth(162);
table.getColumnModel().getColumn(4).setPreferredWidth(232);
table.getColumnModel().getColumn(5).setPreferredWidth(216);
table.setModel(DbUtils.resultSetToTableModel(rs));
}
catch(Exception e) {
e.printStackTrace();
}
finally {
try {
pst.close();
rs.close();
}
catch (Exception e) {
}
}
JButton btnDelete = new JButton("Delete");
btnDelete.setFont(new Font("Courier New", Font.BOLD, 20));
btnDelete.setBackground(new Color(102, 205, 170));
btnDelete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int row = table.getSelectedRow();
String cell = table.getModel().getValueAt(row,0).toString();
String sql = "Delete from supplierregister where id = " + cell;
try {
pst = connection.prepareStatement(sql);
pst.execute();
updateTable();
JOptionPane.showMessageDialog(null, "Deleted Successfully");
}
catch(Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "Deletion Error");
}
finally {
try {
pst.close();
rs.close();
}
catch (Exception ex) {
}
}
}
});
btnDelete.setBounds(1005, 492, 128, 52);
contentPane.add(btnDelete);
JLabel labelSupplier = new JLabel("SUPPLIER");
labelSupplier.setVerticalAlignment(SwingConstants.TOP);
labelSupplier.setFont(new Font("Courier New", Font.BOLD, 45));
labelSupplier.setBounds(689, 43, 247, 45);
contentPane.add(labelSupplier);
JButton btnView = new JButton("View History");
btnView.setFont(new Font("Courier New", Font.BOLD, 21));
btnView.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Histo rframe = new Histo();
rframe.setVisible(true);
}
});
btnView.setBackground(new Color(102, 205, 170));
btnView.setBounds(286, 492, 216, 52);
contentPane.add(btnView);
JButton btnUpdate = new JButton("Update");
btnUpdate.setFont(new Font("Courier New", Font.BOLD, 20));
btnUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
updateTable();
}
});
btnUpdate.setBackground(new Color(102, 205, 170));
btnUpdate.setBounds(850, 492, 128, 52);
contentPane.add(btnUpdate);
JLabel lblNewLabel = new JLabel("");
lblNewLabel.setIcon(new ImageIcon(MainSupplier.class.getResource("/images/supp.jpg")));
lblNewLabel.setBounds(580, 16, 99, 79);
contentPane.add(lblNewLabel);
}
}