Skip to content

Commit 3f9d7c0

Browse files
committed
도서 수정후 바로반영, 도서 추가 수정 예외처리
1 parent 546d4bc commit 3f9d7c0

4 files changed

Lines changed: 330 additions & 148 deletions

File tree

src/view/AddBook.java

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,31 +257,35 @@ public void changed() {
257257
// 책 관련링크 라벨
258258
JLabel bookLinkLabel = new JLabel("\uAD00\uB828\uB9C1\uD06C : ");
259259
bookLinkLabel.setFont(new Font("한컴산뜻돋움", Font.PLAIN, 16));
260-
bookLinkLabel.setBounds(12, 203, 83, 26);
260+
bookLinkLabel.setBounds(12, 216, 83, 26);
261261
panel_1.add(bookLinkLabel);
262262

263263
// 책 관련링크 텍스트필드
264264
bookLinkTextField = new JTextField();
265265
bookLinkTextField.setFont(new Font("한컴산뜻돋움", Font.PLAIN, 16));
266266
bookLinkTextField.setColumns(10);
267-
bookLinkTextField.setBounds(92, 203, 407, 26);
267+
bookLinkTextField.setBounds(92, 216, 407, 26);
268268
panel_1.add(bookLinkTextField);
269269

270270
// 책 가격 라벨
271271
JLabel bookPriceLabel = new JLabel("\uAC00\uACA9 : ");
272272
bookPriceLabel.setFont(new Font("한컴산뜻돋움", Font.PLAIN, 16));
273-
bookPriceLabel.setBounds(12, 107, 46, 26);
273+
bookPriceLabel.setBounds(12, 118, 46, 26);
274274
panel_1.add(bookPriceLabel);
275275

276-
276+
JLabel lblNewLabel_1 = new JLabel("");
277+
lblNewLabel_1.setForeground(Color.RED);
278+
lblNewLabel_1.setBounds(91, 145, 225, 15);
279+
panel_1.add(lblNewLabel_1);
277280
// 책 가격 텍스트필드
278281
bookPriceTextField = new JTextField();
279282
bookPriceTextField.setFont(new Font("한컴산뜻돋움", Font.PLAIN, 16));
280283
bookPriceTextField.setColumns(10);
281-
bookPriceTextField.setBounds(92, 107, 407, 26);
284+
bookPriceTextField.setBounds(92, 118, 407, 26);
282285
panel_1.add(bookPriceTextField);
283286
bookPriceTextField.getDocument().addDocumentListener(new DocumentListener() {
284287
public void changedUpdate(DocumentEvent e) {
288+
285289
changed();
286290
}
287291
public void removeUpdate(DocumentEvent e) {
@@ -290,31 +294,46 @@ public void removeUpdate(DocumentEvent e) {
290294
public void insertUpdate(DocumentEvent e) {
291295
changed();
292296
}
293-
297+
294298
public void changed() {
295299
if (bookISBNTextField.getText().equals("")){
296300
bookAddButton.setEnabled(false);
297301
}
298302
else {
299303
bookAddButton.setEnabled(true);
300304
}
305+
306+
if (bookPriceTextField.getText().length() > 10) {
307+
bookAddButton.setEnabled(false);
308+
lblNewLabel_1.setText("가격은 10자리 이하만 가능합니다.");
309+
}else {
310+
bookAddButton.setEnabled(true);
311+
lblNewLabel_1.setText("");
312+
}
301313

302314
}
303315
});
304316

305317
// 책 ISBN 라벨
306318
JLabel bookISBNLabel = new JLabel("ISBN : ");
307319
bookISBNLabel.setFont(new Font("한컴산뜻돋움", Font.PLAIN, 16));
308-
bookISBNLabel.setBounds(12, 154, 58, 26);
320+
bookISBNLabel.setBounds(12, 170, 58, 26);
309321
panel_1.add(bookISBNLabel);
310322

311323

312324
// 책 ISBN 텍스트필드
313325
bookISBNTextField = new JTextField();
314326
bookISBNTextField.setFont(new Font("한컴산뜻돋움", Font.PLAIN, 16));
315327
bookISBNTextField.setColumns(10);
316-
bookISBNTextField.setBounds(92, 154, 407, 26);
328+
bookISBNTextField.setBounds(92, 170, 407, 26);
317329
panel_1.add(bookISBNTextField);
330+
331+
JLabel lblNewLabel = new JLabel("");
332+
lblNewLabel.setForeground(Color.RED);
333+
lblNewLabel.setBounds(91, 202, 225, 15);
334+
panel_1.add(lblNewLabel);
335+
336+
318337
bookISBNTextField.getDocument().addDocumentListener(new DocumentListener() {
319338
public void changedUpdate(DocumentEvent e) {
320339
changed();
@@ -333,6 +352,14 @@ public void changed() {
333352
else {
334353
bookAddButton.setEnabled(true);
335354
}
355+
356+
if(bookISBNTextField.getText().length() > 13) {
357+
bookAddButton.setEnabled(false);
358+
lblNewLabel.setText("ISBN은 13자리 이하만 가능합니다.");
359+
}else {
360+
bookAddButton.setEnabled(true);
361+
lblNewLabel.setText("");
362+
}
336363

337364
}
338365
});

src/view/BookInfo.java

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class BookInfo extends JFrame {
5151
private JPanel contentPane;
5252
int bookReviewCnt = 0;
5353
int bookReviewGrade = 0;
54-
int bookBorrowCnt = 3;
54+
int bookBorrowCnt = 0;
5555
int userPoint = 0;
5656
boolean userSus = false;
5757
long diffDays = 0; // 연체일을 나타내는 변수
@@ -105,9 +105,8 @@ public void mouseClicked(MouseEvent e) {
105105
updateUserSuspension(0);
106106
}
107107

108-
if ((userPoint < 50 && bookBorrowCnt < 3 || userPoint >= 50 && bookBorrowCnt < 5) && !userSus) // 대출
109-
// 성공
110-
// 했을때
108+
if ((userPoint < 50 && bookBorrowCnt < 3 || userPoint >= 50 && bookBorrowCnt < 5) && !userSus) // 대출성공했을때
109+
111110
{
112111
if (BookRent() == 1) {
113112
Date now = new Date();
@@ -211,7 +210,7 @@ public void mouseClicked(MouseEvent e) {
211210
// 책 즐겨찾기 라벨
212211
JLabel bookFavoritesLabel = new JLabel("\u2606");
213212

214-
bookFavoritesLabel.setText(setStar(book_ISBN,user_phone));
213+
bookFavoritesLabel.setText(setStar(book_ISBN, user_phone));
215214

216215
bookFavoritesLabel.addMouseListener(new MouseAdapter() {
217216
@Override
@@ -258,7 +257,7 @@ public void mouseClicked(MouseEvent e) {
258257
panel_3.setBounds(12, 435, 805, 189);
259258
contentPane.add(panel_3);
260259
panel_3.setLayout(null);
261-
260+
262261
review = new ReviewPanel[3];
263262
review[0] = new ReviewPanel();
264263
review[0].setSize(805, 65);
@@ -287,7 +286,7 @@ public void mouseClicked(MouseEvent e) {
287286

288287
// 사용자의 대여 횟수 가져오기
289288
rs = dbConn.executeQuery(
290-
"SELECT COUNT(*) FROM RENT WHERE USER_PHONE = '" + user_phone + "' AND RENT_RETURN_YN = NULL;");
289+
"SELECT COUNT(*) FROM RENT WHERE USER_PHONE = '" + user_phone + "' AND RENT_RETURN_YN is NULL;");
291290
if (rs.next()) {
292291
bookBorrowCnt = rs.getInt(1);
293292
}
@@ -505,53 +504,46 @@ public void updateBookRentCnt() {
505504
System.out.println("bookRentCnt sql 오류");
506505
}
507506
}
508-
509-
//별 채색여부 설정 함수
510-
public String setStar(String ISBN,String phone) {
511507

512-
String sql = "SELECT * FROM FAVORITES WHERE BOOK_ISBN = '"+ISBN+"' AND USER_PHONE = '"+phone+"';";
508+
// 별 채색여부 설정 함수
509+
public String setStar(String ISBN, String phone) {
510+
511+
String sql = "SELECT * FROM FAVORITES WHERE BOOK_ISBN = '" + ISBN + "' AND USER_PHONE = '" + phone + "';";
513512

514-
ResultSet rs1=dbConn.executeQuery(sql);
513+
ResultSet rs1 = dbConn.executeQuery(sql);
515514
try {
516-
if(rs1.next()) { //결과가 null이 아닌경우(검색결과가 존재하는 경우)
515+
if (rs1.next()) { // 결과가 null이 아닌경우(검색결과가 존재하는 경우)
517516
return "★";
518-
}
519-
else {
517+
} else {
520518
return "☆";
521519
}
522-
520+
523521
} catch (SQLException e1) {
524522
e1.printStackTrace();
525523
return "☆";
526-
}
527-
528-
524+
}
525+
529526
}
530-
531-
//즐겨찾기 이벤트 함수
527+
528+
// 즐겨찾기 이벤트 함수
532529
public void favorite_event() {
533-
String sql = "insert into FAVORITES(\r\n"
534-
+"BOOK_ISBN,\r\n"
535-
+"USER_PHONE\r\n"
536-
+")values(\r\n"
537-
+"?, ?);";
530+
String sql = "insert into FAVORITES(\r\n" + "BOOK_ISBN,\r\n" + "USER_PHONE\r\n" + ")values(\r\n" + "?, ?);";
538531
try { // DB 접근
539532
PreparedStatement ps = dbConn.conn.prepareStatement(sql);
540-
541-
ps.setString(1, book_ISBN); //도서 ISBN
542-
ps.setString(2, user_phone); //유저 휴대전화
543-
533+
534+
ps.setString(1, book_ISBN); // 도서 ISBN
535+
ps.setString(2, user_phone); // 유저 휴대전화
536+
544537
ps.executeUpdate();
545538
} catch (SQLException e) {
546539
e.printStackTrace();
547540
System.out.println("즐겨찾기 추가 sql 오류");
548541
}
549542
}
550-
543+
551544
public void favorite_delete_event() {
552-
String sql = "delete from FAVORITES\r\n"
553-
+"where FAVORITES.USER_PHONE = '"+user_phone+"'\r\n"
554-
+"and FAVORITES.BOOK_ISBN = '"+book_ISBN+"';\r\n";
545+
String sql = "delete from FAVORITES\r\n" + "where FAVORITES.USER_PHONE = '" + user_phone + "'\r\n"
546+
+ "and FAVORITES.BOOK_ISBN = '" + book_ISBN + "';\r\n";
555547
try { // DB 접근
556548
PreparedStatement ps = dbConn.conn.prepareStatement(sql);
557549
ps.executeUpdate();
@@ -560,6 +552,7 @@ public void favorite_delete_event() {
560552
System.out.println("즐겨찾기 삭제 sql 오류");
561553
}
562554
}
555+
563556
// 도서 반납 함수
564557
public void updateBookReturn() {
565558
String sql = "update RENT\r\n" + "SET RENT_RETURN_YN = NOW()\r\n" + "WHERE RENT.USER_PHONE = '" + user_phone
@@ -577,21 +570,22 @@ public void updateBookReturn() {
577570
}
578571

579572
}
580-
573+
574+
// 리뷰 가져오는 함수
581575
public void getUserReview() {
582-
ResultSet rs = dbConn.executeQuery("SELECT USER_PHONE, REVIEW_TEXT, BOOK_GRADE FROM REVIEW WHERE BOOK_ISBN = '" + book_ISBN + "';");
576+
ResultSet rs = dbConn.executeQuery(
577+
"SELECT USER_PHONE, REVIEW_TEXT, BOOK_GRADE FROM REVIEW WHERE BOOK_ISBN = '" + book_ISBN + "';");
583578
int i = 0;
584579
try {
585-
while(rs.next() && i < 3) {
586-
580+
while (rs.next() && i < 3) {
581+
587582
String reviewUserPhone = rs.getString("USER_PHONE");
588583
String reviewUserName = "";
589584
System.out.println();
590585
ResultSet rs2 = dbConn.executeQuery(
591-
"SELECT USER_NAME FROM USER\r\n"
592-
+ "WHERE USER_PHONE = '" + reviewUserPhone + "';");
593-
594-
if(rs2.next()) {
586+
"SELECT USER_NAME FROM USER\r\n" + "WHERE USER_PHONE = '" + reviewUserPhone + "';");
587+
588+
if (rs2.next()) {
595589
reviewUserName = rs2.getString("USER_NAME");
596590
}
597591
review[i++].addProperty(reviewUserName, rs.getInt("BOOK_GRADE"), rs.getString("REVIEW_TEXT"));

0 commit comments

Comments
 (0)