-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHome_Page.java
More file actions
246 lines (216 loc) · 8.93 KB
/
Home_Page.java
File metadata and controls
246 lines (216 loc) · 8.93 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
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Home_Page {
static Connection con;
static int columncount;
static DefaultTableModel tableModel;
public static void main(String[] args) throws SQLException {
new Home_Page(2,"Rathore");
}
Home_Page(int uid,String n) throws SQLException {
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/inventory","root","abhi1210@");
}
catch(Exception ex) { System.out.println(ex); }
Font bold = new Font("Times New Roman",1,35);
Font itelic = new Font("Serif",2,30);
Font plan = new Font("Serif",0,25);
JFrame hf = new JFrame("Dashboard");
hf.setExtendedState(JFrame.MAXIMIZED_BOTH);
hf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
hf.setLocationRelativeTo(null);
Container c = hf.getContentPane();
c.setLayout(null);
hf.setBackground(new Color(0,153,153));
JLabel header = new JLabel("INVENTORY MANAGEMENT SYSTEM",JLabel.CENTER);
header.setFont(bold);
// hf.add(header);
c.add(header);
header.setBounds(310,10,1080,50);
JPanel p1 = new JPanel();
p1.setLayout(null);
p1.setBackground(new Color(33,41,52));
c.add(p1);
p1.setBounds(0,0,270,1080);
// JLabel hv = new JLabel("Welcome "+n,JLabel.CENTER); hv.setForeground(Color.WHITE);
JLabel hv = new JLabel("Welcome "+n,JLabel.CENTER); hv.setForeground(Color.WHITE);
// JLabel sv = new JLabel("Stock Value: 0.00Rs"); sv.setForeground(Color.WHITE);
JLabel sv = new JLabel("Created By :"); sv.setForeground(Color.WHITE);
JLabel lv = new JLabel("Registration No"); lv.setForeground(Color.WHITE);
JLabel tv = new JLabel("All Rights Reserved."); tv.setForeground(Color.WHITE);
hv.setFont(itelic);
sv.setFont(plan);
lv.setFont(plan);
tv.setFont(plan);
p1.add(sv);p1.add(lv);p1.add(hv);p1.add(tv);
hv.setBounds(0,30,300,60);
sv.setBounds(10,200,300,60);
JLabel sv1 = new JLabel("Abhishek Rathore");sv1.setForeground(Color.white);
sv1.setFont(plan);
p1.add(sv1);
sv1.setBounds(10,240,300,60);
lv.setBounds(10,300,300,60);
JLabel lv1 = new JLabel("12101413");lv1.setForeground(Color.white);
lv1.setFont(plan);
p1.add(lv1);
lv1.setBounds(10,340,300,60);
sv1.setBounds(10,240,300,60);
tv.setBounds(10,450,300,60);
//
JButton add = new JButton("ADD ITEM");add.setFont(plan);add.setForeground(new Color(247,183,93));
add.setBackground(new Color(33,41,52));
c.add(add);
add.setBounds(320,140,200,50);
//
JButton del = new JButton("DELETE ITEM");del.setFont(plan);del.setForeground(new Color(247,183,93));
del.setBackground(new Color(33,41,52));
c.add(del);
del.setBounds(590,140,200,50);
//
JButton ser = new JButton("SEARCH ITEM");ser.setFont(plan);ser.setForeground(new Color(247,183,93));
ser.setBackground(new Color(33,41,52));
c.add(ser);
ser.setBounds(860,140,200,50);
//
JButton up = new JButton("UPDATE ITEM");up.setFont(plan);up.setForeground(new Color(247,183,93));
up.setBackground(new Color(33,41,52));
c.add(up);
up.setBounds(1130,140,200,50);
//
JButton rf = new JButton("REFRESH");rf.setFont(plan);rf.setForeground(new Color(247,183,93));
rf.setBackground(new Color(33,41,52));
p1.add(rf);
rf.setBounds(0,580,250,50);
JPanel tp = new JPanel();
tp.setLayout(new BorderLayout());
JTable table;
//
//
String tablename = "UIT"+uid;
try
{
String query = "SELECT * FROM "+tablename;
Statement smt = con.createStatement();
ResultSet rs = smt.executeQuery(query);
tableModel = new DefaultTableModel();
ResultSetMetaData metaData = rs.getMetaData();
columncount = metaData.getColumnCount();
for(int i=1;i<=columncount;i++)
{
tableModel.addColumn(metaData.getColumnName(i));
}
while (rs.next())
{
Object[] row = new Object[columncount];
for (int i = 1; i <= columncount; i++) {
row[i - 1] = rs.getObject(i);
}
tableModel.addRow(row);
}
table = new JTable(tableModel);
table.setFont(new Font("Serif",Font.BOLD,18));
DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
centerRenderer.setHorizontalAlignment(SwingConstants.CENTER);
centerRenderer.setFont(new Font("Arial", Font.PLAIN, 16));
table.setDefaultRenderer(Object.class, centerRenderer);
DefaultTableCellRenderer headerRenderer = new DefaultTableCellRenderer();
headerRenderer.setHorizontalAlignment(SwingConstants.CENTER);
headerRenderer.setFont(new Font("Arial", Font.BOLD, 18));
TableColumnModel columnModel = table.getColumnModel();
for (int i = 0; i < columnModel.getColumnCount(); i++) {
columnModel.getColumn(i).setHeaderRenderer(headerRenderer);
}
JScrollPane scrollPane = new JScrollPane(table);
tp.add(scrollPane);
rs.close();
smt.close();
}
catch (Exception e)
{
System.out.println(e);
}
c.add(tp);
tp.setBounds(300,250,1050,400);
class MyListener implements ActionListener {
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==add)
{
new Add(uid);
}
if(ae.getSource()==del)
{
new Delete(uid);
}
if(ae.getSource()==up)
{
new Update(uid);
}
if(ae.getSource()==ser)
{
new Search(uid);
}
if(ae.getSource()==rf)
{
try{
String query = "SELECT * FROM "+tablename;
Statement smt = con.createStatement();
ResultSet rs = smt.executeQuery(query);
tableModel.setRowCount(0);
while (rs.next())
{
Object[] row = new Object[columncount];
for (int i = 1; i <= columncount; i++) {
row[i - 1] = rs.getObject(i);
}
tableModel.addRow(row);
}
}
catch (Exception e)
{
System.out.println(e);
}
try
{
PreparedStatement ps1 = con.prepareStatement("select PURCHASE_PRICE from "+tablename);
ResultSet rs1 = ps1.executeQuery();
int stock = 0;
while(rs1.next())
{
stock += Integer.parseInt(rs1.getString(1));
}
// sv.setText("Stock Value: "+stock+"Rs");
PreparedStatement ps2 = con.prepareStatement("Select STOCK, MIN_STOCK from "+tablename);
ResultSet rs2 = ps2.executeQuery();
int minstock = 0;
int totals =0;
while(rs2.next())
{
if(rs2.getInt(1)<rs2.getInt(2))
minstock++;
totals += rs2.getInt(1);
}
// lv.setText("Low Stocks: "+minstock);
// tv.setText("Total Stock: "+totals);
}
catch (Exception e)
{
System.out.println(e);
}
}
}
}
MyListener ml = new MyListener();
rf.addActionListener(ml);
add.addActionListener(ml);
del.addActionListener(ml);
ser.addActionListener(ml);
up.addActionListener(ml);
hf.setVisible(true);
}
}