-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReturnBook.java
252 lines (214 loc) · 8.55 KB
/
ReturnBook.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
package library1;
import javax.swing.*;
import javax.swing.border.*;
import com.toedter.calendar.JDateChooser;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.time.chrono.JapaneseDate;
public class ReturnBook extends JFrame implements ActionListener{
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
private JTextField textField_5;
private JTextField textField_6;
private JButton b1,b2,b3;
private JDateChooser dateChooser;
public static void main(String[] args) {
new ReturnBook().setVisible(true);
}
public void delete() {
try {
conn con = new conn();
String sql = "delete from issueBook where book_id=?";
PreparedStatement st = con.c.prepareStatement(sql);
st.setString(1, textField.getText());
int i = st.executeUpdate();
if (i > 0)
JOptionPane.showConfirmDialog(null, "Book Returned");
else
JOptionPane.showMessageDialog(null, "error in Deleting");
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, e);
e.printStackTrace();
}
}
public ReturnBook() {
setBounds(450, 300, 617, 363);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setBackground(Color.WHITE);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("Book_id");
lblNewLabel.setForeground(new Color(0, 0, 0));
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel.setBounds(52, 52, 87, 24);
contentPane.add(lblNewLabel);
JLabel lblStudentid = new JLabel("Student_id");
lblStudentid.setForeground(Color.BLACK);
lblStudentid.setFont(new Font("Tahoma", Font.BOLD, 14));
lblStudentid.setBounds(243, 52, 87, 24);
contentPane.add(lblStudentid);
JLabel lblBook = new JLabel("Book");
lblBook.setForeground(Color.BLACK);
lblBook.setFont(new Font("Tahoma", Font.BOLD, 14));
lblBook.setBounds(52, 98, 71, 24);
contentPane.add(lblBook);
JLabel lblName = new JLabel("Name");
lblName.setForeground(Color.BLACK);
lblName.setFont(new Font("Tahoma", Font.BOLD, 14));
lblName.setBounds(300, 98, 71, 24);
contentPane.add(lblName);
JLabel lblCourse = new JLabel("Course");
lblCourse.setForeground(Color.BLACK);
lblCourse.setFont(new Font("Tahoma", Font.BOLD, 14));
lblCourse.setBounds(52, 143, 87, 24);
contentPane.add(lblCourse);
JLabel lblBranch = new JLabel("Branch");
lblBranch.setForeground(Color.BLACK);
lblBranch.setFont(new Font("Tahoma", Font.BOLD, 14));
lblBranch.setBounds(303, 144, 68, 24);
contentPane.add(lblBranch);
JLabel lblDateOfIssue = new JLabel("Date of Issue");
lblDateOfIssue.setForeground(Color.BLACK);
lblDateOfIssue.setFont(new Font("Tahoma", Font.BOLD, 14));
lblDateOfIssue.setBounds(52, 188, 105, 29);
contentPane.add(lblDateOfIssue);
JLabel lblDateOfReturn = new JLabel("Date of Return");
lblDateOfReturn.setForeground(Color.BLACK);
lblDateOfReturn.setFont(new Font("Tahoma", Font.BOLD, 14));
lblDateOfReturn.setBounds(52, 234, 118, 29);
contentPane.add(lblDateOfReturn);
textField = new JTextField();
textField.setForeground(new Color(105, 105, 105));
textField.setFont(new Font("Trebuchet MS", Font.BOLD, 14));
textField.setBounds(128, 56, 105, 20);
contentPane.add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setForeground(new Color(105, 105, 105));
textField_1.setFont(new Font("Trebuchet MS", Font.BOLD, 14));
textField_1.setBounds(340, 56, 93, 20);
contentPane.add(textField_1);
textField_1.setColumns(10);
b1 = new JButton("Search");
b1.addActionListener(this);
b1.setBounds(443, 52, 105, 29);
b1.setBackground(Color.BLACK);
b1.setForeground(Color.WHITE);
contentPane.add(b1);
textField_2 = new JTextField();
textField_2.setEditable(false);
textField_2.setForeground(new Color(0, 100, 0));
textField_2.setFont(new Font("Trebuchet MS", Font.BOLD, 13));
textField_2.setBounds(128, 102, 162, 20);
contentPane.add(textField_2);
textField_2.setColumns(10);
textField_3 = new JTextField();
textField_3.setEditable(false);
textField_3.setForeground(new Color(0, 100, 0));
textField_3.setFont(new Font("Trebuchet MS", Font.BOLD, 13));
textField_3.setColumns(10);
textField_3.setBounds(369, 102, 179, 20);
contentPane.add(textField_3);
textField_4 = new JTextField();
textField_4.setEditable(false);
textField_4.setForeground(new Color(0, 100, 0));
textField_4.setFont(new Font("Trebuchet MS", Font.BOLD, 13));
textField_4.setColumns(10);
textField_4.setBounds(128, 147, 162, 20);
contentPane.add(textField_4);
textField_5 = new JTextField();
textField_5.setForeground(new Color(0, 100, 0));
textField_5.setFont(new Font("Trebuchet MS", Font.BOLD, 13));
textField_5.setEditable(false);
textField_5.setColumns(10);
textField_5.setBounds(369, 147, 179, 20);
contentPane.add(textField_5);
textField_6 = new JTextField();
textField_6.setForeground(new Color(0, 100, 0));
textField_6.setFont(new Font("Trebuchet MS", Font.BOLD, 13));
textField_6.setEditable(false);
textField_6.setColumns(10);
textField_6.setBounds(167, 194, 162, 20);
contentPane.add(textField_6);
dateChooser = new JDateChooser();
dateChooser.setBorder(new LineBorder(new Color(0, 0, 0), 0, true));
dateChooser.setBounds(167, 234, 172, 29);
contentPane.add(dateChooser);
b2 = new JButton("Return");
b2.addActionListener(this);
b2.setFont(new Font("Trebuchet MS", Font.BOLD, 15));
b2.setBorder(new LineBorder(new Color(0, 0, 0), 0, true));
b2.setBounds(369, 179, 149, 30);
b2.setBackground(Color.BLACK);
b2.setForeground(Color.WHITE);
contentPane.add(b2);
b3 = new JButton("Back");
b3.addActionListener(this);
b3.setFont(new Font("Trebuchet MS", Font.BOLD, 15));
b3.setBorder(new LineBorder(new Color(0, 0, 0), 0, true));
b3.setBounds(369, 231, 149, 30);
b3.setBackground(Color.BLACK);
b3.setForeground(Color.WHITE);
contentPane.add(b3);
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(new LineBorder(new Color(255, 69, 0), 2, true), "Return-Panel",
TitledBorder.LEADING, TitledBorder.TOP, null, new Color(220, 20, 60)));
panel.setBounds(10, 24, 569, 269);
panel.setBackground(Color.WHITE);
contentPane.add(panel);
}
public void actionPerformed(ActionEvent ae){
try{
conn con = new conn();
if(ae.getSource() == b1){
String sql = "select * from issuebook where student_id = ? and book_id =?";
PreparedStatement st = con.c.prepareStatement(sql);
st.setString(1, textField_1.getText());
st.setString(2, textField.getText());
ResultSet rs = st.executeQuery();
while (rs.next()) {
textField_2.setText(rs.getString("bname"));
textField_3.setText(rs.getString("sname"));
textField_4.setText(rs.getString("course"));
textField_5.setText(rs.getString("branch"));
textField_6.setText(rs.getString("dateOfIssue"));
}
st.close();
rs.close();
}
if(ae.getSource() == b2){
String sql = "insert into returnbook(book_id, student_id, bname, sname,course, branch, dateOfIssue, dateOfReturn) values(?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement st = con.c.prepareStatement(sql);
st.setString(1, textField.getText());
st.setString(2, textField_1.getText());
st.setString(3, textField_2.getText());
st.setString(4, textField_3.getText());
st.setString(5, textField_4.getText());
st.setString(6, textField_5.getText());
st.setString(7, textField_6.getText());
st.setString(8, ((JTextField) dateChooser.getDateEditor().getUiComponent()).getText());
int i = st.executeUpdate();
if (i > 0) {
JOptionPane.showMessageDialog(null, "Processing..");
delete();
} else
JOptionPane.showMessageDialog(null, "error");
}
if(ae.getSource() == b3){
this.setVisible(false);
new home().setVisible(true);
}
}catch(Exception e){
}
}
}