-
Notifications
You must be signed in to change notification settings - Fork 0
/
batrec.java
405 lines (291 loc) · 10.5 KB
/
batrec.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
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
import javax.swing.table.*;
import java.sql.*;
import java.sql.ResultSet;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
class batrec extends JFrame implements ActionListener
{
JLabel lbcod,lstrdt,lnos,lcoid,ltnm,ltime,ladm,lbtime;
JTextField ttime,tbcod,ttnm,tstrdt,tnos,tbtime;
JComboBox co_id;
JButton bopen,bmod,bdel,bnew,badd,bcan;
Font fo=new Font("Verdana" ,Font.BOLD,20);
//JComboBox co_id;
String test;
Connection con;
ResultSet rs;
Statement stmt,st;
PreparedStatement pst;
Thread datimeThread;
Date date;
GregorianCalendar calendar;
String strDate;
//Table
DefaultTableModel model = new DefaultTableModel();
JTable tabGrid = new JTable(model);
JScrollPane scrlPane = new JScrollPane(tabGrid);
batrec()
{
setSize(480,530);
setLayout(null);
setTitle("BATCH RECORD");
setResizable(true);
setLocation(100,160);
ladm=new JLabel("STANDARD RECORD");
ladm.setFont(fo);
ladm.setForeground(Color.red);
ladm.setBounds(140,30,250,30);
lbcod=new JLabel("Batch Id :");
lbcod.setBounds(15,90,100,30);
tbcod=new JTextField(5);
tbcod.setBounds(100,90,90,25);
lcoid=new JLabel("Course:");
lcoid.setBounds(230,90,90,30);
co_id=new JComboBox();
co_id.setBounds(320,90,95,25);
lstrdt=new JLabel("Start Date:");
lstrdt.setBounds(15,150,100,30);
tstrdt=new JTextField(30);
tstrdt.setBounds(100,150,90,25);
lbtime=new JLabel("Batch Time:");
lbtime.setBounds(230,150,100,30);
tbtime=new JTextField(30);
tbtime.setBounds(320,150,95,25);
bopen=new JButton("Open");
bopen.addActionListener(this);
bopen.setBounds(50,210,90,25);
bmod=new JButton("Modify");
bmod.addActionListener(this);
bmod.setBounds(190,210,90,25);
bdel=new JButton("Delete");
bdel.addActionListener(this);
bdel.setBounds(330,210,90,25);
bnew=new JButton("New");
bnew.addActionListener(this);
bnew.setBounds(50,260,90,25);
badd=new JButton("Add");
badd.addActionListener(this);
badd.setBounds(190,260,90,25);
bcan=new JButton("ALL");
bcan.addActionListener(this);
bcan.setBounds(330,260,90,25);
add(ladm);
add(lbcod);
add(tbcod);
add(lstrdt);
add(tstrdt);
add(lcoid);
add(co_id);
// add(ltime);
// add(ttime);
add(lbtime);add(tbtime);
add(bopen);
add(bmod);
add(bdel);
add(bnew);
add(badd);
add(bcan);
tbcod.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))))
{
JOptionPane.showMessageDialog(null, "Please enter a numerical value");
e.consume();
}
}
});
// Table
scrlPane.setBounds(50,300,380,200);
add(scrlPane);
tabGrid.setFont(new Font ("Verdana",0,13));
model.addColumn("B_ID");
model.addColumn("C_NAME");
model.addColumn("S_DATE");
model.addColumn("B_TIME");
setVisible(true);
date=new Date();
calendar=new GregorianCalendar();
calendar.setTime(date);
strDate=calendar.get(Calendar.DATE)+"/"+(calendar.get(Calendar.MONTH)+1)+"/"+calendar.get(Calendar.YEAR);
//tstrdt.setText(strDate);
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/institute","root","root");
st=con.createStatement();
rs=st.executeQuery("select co_name from Course");
while(rs.next())
{
test=rs.getString(1);
co_id.addItem(test);
}
}
catch(Exception e)
{
System.out.println("error" +e);
}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==bnew)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/institute","root","root");
stmt=con.createStatement();
rs=stmt.executeQuery("select b_id from Batch");
int i=1;
while(rs.next())
{
i=Integer.parseInt(rs.getString("b_id"));
}
i++;
tbcod.setText(""+i);
tbtime.setText(" ");
tstrdt.setText(strDate);
/*//co_id.setEnabled(true);
tconm.setEnabled(true);
tcopd.setEnabled(true);
tcof.setEnabled(true);*/
rs.close();
}
catch(Exception e)
{
System.out.println("Error"+e);
}
}
if(ae.getSource()==bcan)
{
int r = 0;
while(model.getRowCount() > 0)
{
model.removeRow(0);
}
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection cnDriver = DriverManager.getConnection("jdbc:mysql://localhost:3306/institute","root","root");
Statement stmt = cnDriver.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT * from Batch");
while(rs.next())
{
model.insertRow(r++, new Object[]{rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4) });
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,"Error Occured : " + ex);
}
}
if(ae.getSource()==badd)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/institute","root","root");
PreparedStatement pst = con.prepareStatement("INSERT INTO Batch VALUES(?,?,?,?)");
int tbcod1 =Integer.parseInt(tbcod.getText());
String co_id1 =co_id.getSelectedItem().toString();
String tstrdt1=tstrdt.getText();
String ttime=tbtime.getText();
pst.setInt(1,tbcod1);
pst.setString(2,co_id1);
pst.setString(3,tstrdt1);
pst.setString(4,ttime);
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "Your Record is Submitted");
con.close();
tbcod.setText(" ");
tstrdt.setText(strDate);
tstrdt.setText(" ");
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,"Error Occured : " + ex);
}
}
if(ae.getSource()==bopen)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con= DriverManager.getConnection("jdbc:mysql://localhost:3306/institute","root","");
stmt= con.createStatement();
String id=tbcod.getText();
String qry= "Select * from Batch where b_id="+id+"";
rs = stmt.executeQuery(qry);
while(rs.next())
{
tstrdt.setText(rs.getString(3));
tbtime.setText(rs.getString(4));
}
con.close();
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,"Error Occured : " + ex);
}
}
if(ae.getSource()==bdel)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/institute","root","");
pst=con.prepareStatement("Delete from Batch where b_id=?");
String bcod1=tbcod.getText();
pst.setString(1,bcod1);
JOptionPane.showMessageDialog(null,"Record Is Deleted ");
pst.executeUpdate();
tbcod.setText("");
tbtime.setText("");
//co_id.setText("");
tstrdt.setText("");
con.close();
}
catch(Exception ex)
{
System.out.println("Error occured :"+ex);
}
}
if(ae.getSource()==bmod)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/institute","root","");
stmt=con.createStatement();
String tbcod1=tbcod.getText();
String co_id1=co_id.getSelectedItem().toString();
String tstrdt1=tstrdt.getText();
String ttime=tbtime.getText();
String str1="UPDATE Batch SET b_id ='"+tbcod1+"',co_name='"+co_id1+"',date1='"+tstrdt1+"',time='"+ttime+"' where b_id LIKE '" + tbcod1 +"' ";
stmt.executeUpdate(str1);
JOptionPane.showMessageDialog(null, "Record is Modified");
tbcod.setText("");
tbtime.setText("");
tstrdt.setText(strDate);
con.close();
}
catch(Exception ex)
{
System.out.println("Error Occured");
System.out.println("Error:"+ex);
}
}
}
public static void main (String args[])
{
new batrec();
}
}