-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary Management System.java
More file actions
385 lines (380 loc) · 14.1 KB
/
Copy pathLibrary Management System.java
File metadata and controls
385 lines (380 loc) · 14.1 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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;
public class p2 {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
JFrame frame = new JFrame("BOOK STALL");
frame.setSize(640,480);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);
JButton insertButton = new JButton("Insert books");
insertButton.setBounds(210, 60, 200, 75);
JButton searchButton = new JButton("Search books");
searchButton.setBounds(210, 150, 200, 75);
JButton updateButton = new JButton("Buy books");
updateButton.setBounds(210, 240, 200, 75);
JButton newButton = new JButton("New books");
newButton.setBounds(210, 330, 200, 75);
insertButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae)
{
JFrame insertFrame = new JFrame("Insert Window");
JTextField atext=new JTextField(20);
JTextField btext=new JTextField(20);
JTextField ctext=new JTextField(20);
JTextField dtext=new JTextField(20);
JTextField etext=new JTextField(20);
JTextField out=new JTextField(20);
JButton ins=new JButton("INSERT");
JLabel a=new JLabel("Publisher name");
JLabel b=new JLabel("PBookID");
JLabel c=new JLabel("Author");
JLabel d=new JLabel("Book name");
JLabel e=new JLabel("Copies");
insertFrame.add(atext);
insertFrame.add(btext);
insertFrame.add(ctext);
insertFrame.add(dtext);
insertFrame.add(etext);
insertFrame.add(ins);
insertFrame.add(a);
insertFrame.add(out);
insertFrame.add(b);
insertFrame.add(c);
insertFrame.add(d);
insertFrame.add(e);
insertFrame.setLayout(null);
ins.setBounds(260,100,110,25);
out.setBounds(260,140,110,25);
a.setBounds(10,40,110,25);
b.setBounds(10,90,110,25);
c.setBounds(10,140,110,25);
d.setBounds(10,190,110,25);
e.setBounds(10,240,110,25);
atext.setBounds(140,40,110,25);
btext.setBounds(140,90,110,25);
ctext.setBounds(140,140,110,25);
dtext.setBounds(140,190,110,25);
etext.setBounds(140,240,110,25);
insertFrame.setSize(500, 400);
insertFrame.setVisible(true);
ins.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent x)
{
try
{
Scanner scan=new Scanner(System.in);
String bid,bname,author,publisher;
int copy;
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bookstall","root","2402");
Statement stm=con.createStatement();
publisher=atext.getText();
bid=btext.getText();
author=ctext.getText();
bname=dtext.getText();
copy=Integer.parseInt(etext.getText());
int rs=stm.executeUpdate("insert into publisher (bookid,name,author,publisher,copy) values('"+bid+"','"+bname+"','"+author+"','"+publisher+"',"+copy+")");
if(rs==1)
{
out.setText("Destination Updated");
}
else
{
out.setText("Destination not Updated");
}
stm.close();
con.close();
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
catch(SQLException e)
{
System.out.println(e);
}
}
});
}
});
searchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae)
{
JFrame searchFrame = new JFrame("Search Window");
JLabel id=new JLabel("bookid");
JButton s=new JButton("SEARCH");
JTextField idtext=new JTextField(20);
JTextField atext=new JTextField(20);
JTextField btext=new JTextField(20);
JTextField ctext=new JTextField(20);
JTextField dtext=new JTextField(20);
JTextField etext=new JTextField(20);
JTextField out=new JTextField(20);
JLabel a=new JLabel("Publisher name");
JLabel b=new JLabel("PBookID");
JLabel c=new JLabel("Author");
JLabel d=new JLabel("Book name");
JLabel e=new JLabel("Copies");
searchFrame.add(id);
searchFrame.add(s);
searchFrame.add(idtext);
searchFrame.add(atext);
searchFrame.add(btext);
searchFrame.add(ctext);
searchFrame.add(dtext);
searchFrame.add(etext);
searchFrame.add(out);
searchFrame.add(a);
searchFrame.add(b);
searchFrame.add(c);
searchFrame.add(d);
searchFrame.add(e);
searchFrame.add(out);
searchFrame.setLayout(null);
s.setBounds(260,100,110,25);
id.setBounds(260,30,90,25);
idtext.setBounds(320,30,110,25);
out.setBounds(260,100,110,25);
a.setBounds(10,40,110,25);
b.setBounds(10,90,110,25);
c.setBounds(10,140,110,25);
d.setBounds(10,190,110,25);
e.setBounds(10,240,110,25);
atext.setBounds(140,40,110,25);
btext.setBounds(140,90,110,25);
ctext.setBounds(140,140,110,25);
dtext.setBounds(140,190,110,25);
etext.setBounds(140,240,110,25);
searchFrame.setSize(500, 400);
searchFrame.setVisible(true);
s.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent x)
{
try
{
Scanner scan=new Scanner(System.in);
String bid,bname,author,publisher,val;
int copy,numrows;
numrows=0;
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bookstall","root","2402");
Statement stm=con.createStatement();
val=idtext.getText();
String qry = "select * from publisher";
ResultSet rs = stm.executeQuery(qry);
while(rs.next())
{
bid=rs.getString(1);
if(bid.equals(val))
{
atext.setText(rs.getString(4));
btext.setText(rs.getString(1));
ctext.setText(rs.getString(3));
dtext.setText(rs.getString(2));
etext.setText(Integer.toString(rs.getInt(5)));
out.setText("Found");
numrows++;
}
}
if(numrows<1)
{
atext.setText("NULL");
btext.setText("NULL");
ctext.setText("NULL");
dtext.setText("NULL");
etext.setText("NULL");
out.setText("Not found");
}
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
catch(SQLException e)
{
System.out.println(e);
}
}
});
}
});
updateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae)
{
JFrame updateFrame = new JFrame("Buy Window");
JTextField cid=new JTextField(20);
JTextField cname=new JTextField(20);
JTextField phno=new JTextField(20);
JTextField bname=new JTextField(20);
JTextField qty=new JTextField(20);
JTextField price=new JTextField(20);
JTextField dop=new JTextField(20);
JTextField out=new JTextField(20);
JButton sub=new JButton("Submit");
JLabel a=new JLabel("CUSTOMER ID: ");
JLabel b=new JLabel("CUSTOMER NAME: ");
JLabel c=new JLabel("PHONE NUMBER: ");
JLabel d=new JLabel("BOOK NAME: ");
JLabel e=new JLabel("QUANTITY: ");
JLabel f=new JLabel("PRICE: ");
JLabel g=new JLabel("DATE OF PURCHASE: ");
JLabel h=new JLabel("STATUS:");
updateFrame.add(cid);
updateFrame.add(cname);
updateFrame.add(phno);
updateFrame.add(bname);
updateFrame.add(qty);
updateFrame.add(price);
updateFrame.add(dop);
updateFrame.add(sub);
updateFrame.add(out);
updateFrame.add(a);
updateFrame.add(b);
updateFrame.add(c);
updateFrame.add(d);
updateFrame.add(e);
updateFrame.add(f);
updateFrame.add(g);
updateFrame.add(h);
updateFrame.setLayout(null);
cid.setBounds(140,40,150,25);
cname.setBounds(140,70,150,25);
phno.setBounds(140,100,150,25);
bname.setBounds(140,130,150,25);
qty.setBounds(140,160,150,25);
price.setBounds(140,190,150,25);
dop.setBounds(140,220,150,25);
sub.setBounds(100,280,200,80);
out.setBounds(100,380,150,25);
a.setBounds(10,40,150,25);
b.setBounds(10,70,150,25);
c.setBounds(10,100,150,25);
d.setBounds(10,130,150,25);
e.setBounds(10,160,150,25);
f.setBounds(10,190,150,25);
g.setBounds(10,220,150,25);
h.setBounds(10,380,150,25);
updateFrame.setSize(800,800);
updateFrame.setVisible(true);
sub.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent x)
{
try{
int cid1,qty1;
String cname1,bname1,dop1,phno1;
Double price1;
Scanner scan=new Scanner(System.in);
Object souce =ae.getSource();
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bookstall","root","2402");
Statement stm=con.createStatement();
cid1=Integer.parseInt(cid.getText());
cname1=cname.getText();
phno1=phno.getText();
bname1=bname.getText();
qty1=Integer.parseInt(qty.getText());
price1=Double.parseDouble(price.getText());
dop1=dop.getText();
String qry = "INSERT INTO customer VALUES (" + cid1 + ", '" + cname1 + "', '" + phno1 + "', '" + bname1 + "', " + qty1 + ", " + price1 + ", '" + dop1 + "')";
int count=stm.executeUpdate(qry);
if(count!=0)
{
out.setText("Entered");
String q1="update publisher set copy=copy-"+qty1+" where name='"+bname1+"'";
count=stm.executeUpdate(q1);
}
else
{
out.setText("Denied");
}
stm.close();
con.close();
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
catch(SQLException e)
{
System.out.println(e);
}
}
});
}
});
newButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JFrame newFrame = new JFrame("New books Window");
JTextField atext=new JTextField(20);
JTextField btext=new JTextField(20);
JTextField out=new JTextField(20);
JButton add=new JButton("ADD");
JLabel a=new JLabel("BookID");
JLabel b=new JLabel("Quantity");
newFrame.add(atext);
newFrame.add(btext);
newFrame.add(out);
newFrame.add(a);
newFrame.add(b);
newFrame.add(add);
newFrame.setLayout(null);
add.setBounds(260,100,110,25);
out.setBounds(260,140,110,25);
a.setBounds(10,40,110,25);
b.setBounds(10,90,110,25);
atext.setBounds(140,40,110,25);
btext.setBounds(140,90,110,25);
newFrame.setSize(500, 400);
newFrame.setVisible(true);
add.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent x)
{
try
{
String id;
int qty,count;
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bookstall","root","2402");
Statement stm=con.createStatement();
id=atext.getText();
qty=Integer.parseInt(btext.getText());
String q1="update publisher set copy=copy+"+qty+" where bookid='"+id+"'";
count=stm.executeUpdate(q1);
if(count>=1)
{
out.setText("Success");
}
else
{
out.setText("Error");
}
stm.close();
con.close();
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
catch(SQLException e)
{
System.out.println(e);
}
}
});
}
});
frame.add(searchButton);
frame.add(insertButton);
frame.add(newButton);
frame.add(updateButton);
frame.setVisible(true);
}
}