diff --git a/src/com/littleheap/Book.java b/src/com/littleheap/Book.java index d3703a1..aa22ac9 100644 --- a/src/com/littleheap/Book.java +++ b/src/com/littleheap/Book.java @@ -5,6 +5,7 @@ public class Book { public String classnumber; public String name; public String classname; + public String author; public String price; public String state; public String total; diff --git a/src/com/littleheap/DataBase/TableOperate.java b/src/com/littleheap/DataBase/TableOperate.java index 3568f1d..a80b7fb 100644 --- a/src/com/littleheap/DataBase/TableOperate.java +++ b/src/com/littleheap/DataBase/TableOperate.java @@ -8,23 +8,23 @@ public class TableOperate { - //Êý¾Ý¿â²éѯÁ¬½ÓÄ£°å + //���ݿ��ѯ����ģ�� public TableOperate() { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯£¡"); + System.out.println("�ɹ�����MySQL������"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â£¡"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ⣡"); - String sql = "select * from temp"; //ÒªÖ´ÐеÄSQL - ResultSet rs = stmt.executeQuery(sql);//´´½¨Êý¾Ý¶ÔÏó - System.out.println("±àºÅ"+"\t"+"ÐÕÃû"+"\t"+"ÄêÁä"); + String sql = "select * from temp"; //Ҫִ�е�SQL + ResultSet rs = stmt.executeQuery(sql);//�������ݶ��� + System.out.println("���"+"\t"+"����"+"\t"+"����"); while (rs.next()){ System.out.print(rs.getInt(1) + "\t"); System.out.print(rs.getString(2) + "\t"); @@ -40,23 +40,23 @@ public TableOperate() { } } - //ÊÇ·ñ´æÔÚ¸ÃÓû§ + //�Ƿ���ڸ��û� public static boolean isExist_Customer(String user,String password) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-isExist_Customer"); + System.out.println("�ɹ�����MySQL����-isExist_Customer"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-isExist_Customer"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-isExist_Customer"); - String sql = "select * from Customer"; //ÒªÖ´ÐеÄSQL - ResultSet rs = stmt.executeQuery(sql);//´´½¨Êý¾Ý¶ÔÏó - System.out.println("Óû§Ãû"+"\t"+"\t"+"\t"+"ÃÜÂë"); + String sql = "select * from Customer"; //Ҫִ�е�SQL + ResultSet rs = stmt.executeQuery(sql);//�������ݶ��� + System.out.println("�û���"+"\t"+"\t"+"\t"+"����"); while (rs.next()){ System.out.print(rs.getString(1) + "\t"); System.out.print(rs.getString(2) + "\t"); @@ -78,23 +78,23 @@ public static boolean isExist_Customer(String user,String password) { return false; } - //ÊÇ·ñ´æÔڸùÜÀíÔ± + //�Ƿ���ڸù���Ա public static boolean isExist_Manager(String user,String password) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-isExist_Manager"); + System.out.println("�ɹ�����MySQL����-isExist_Manager"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-isExist_Manager"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-isExist_Manager"); - String sql = "select * from Manager"; //ÒªÖ´ÐеÄSQL - ResultSet rs = stmt.executeQuery(sql);//´´½¨Êý¾Ý¶ÔÏó - System.out.println("Óû§Ãû"+"\t"+"\t"+"\t"+"ÃÜÂë"); + String sql = "select * from Manager"; //Ҫִ�е�SQL + ResultSet rs = stmt.executeQuery(sql);//�������ݶ��� + System.out.println("�û���"+"\t"+"\t"+"\t"+"����"); while (rs.next()){ System.out.print(rs.getString(1) + "\t"); System.out.print(rs.getString(2) + "\t"); @@ -116,21 +116,21 @@ public static boolean isExist_Manager(String user,String password) { return false; } - //×¢²áÐÂÓû§ + //ע�����û� public static void regist_Customer(String user,String password) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-regist_Customer"); + System.out.println("�ɹ�����MySQL����-regist_Customer"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-regist_Customer"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-regist_Customer"); - String sql = "insert into Customer values('"+user+"','"+password+"');"; //ÒªÖ´ÐеÄSQL + String sql = "insert into Customer values('"+user+"','"+password+"');"; //Ҫִ�е�SQL PreparedStatement stmts = conn.prepareStatement(sql); stmts.executeUpdate(); @@ -144,21 +144,21 @@ public static void regist_Customer(String user,String password) { } } - //×¢²áйÜÀíÔ± + //ע���¹���Ա public static void regist_Manager(String user,String password) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-regist_Manager"); + System.out.println("�ɹ�����MySQL����-regist_Manager"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-regist_Manager"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-regist_Manager"); - String sql = "insert into Manager values('"+user+"','"+password+"');"; //ÒªÖ´ÐеÄSQL + String sql = "insert into Manager values('"+user+"','"+password+"');"; //Ҫִ�е�SQL PreparedStatement stmts = conn.prepareStatement(sql); stmts.executeUpdate(); @@ -172,21 +172,21 @@ public static void regist_Manager(String user,String password) { } } - //¸Ä±äÓû§µÄÃÜÂë + //�ı��û������� public static void changePassword_Customer(String user,String password,String newPassword) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-changePassword"); + System.out.println("�ɹ�����MySQL����-changePassword"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-changePassword"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-changePassword"); - String sql = "update Customer set customer_password = '"+newPassword+"' where customer_user = '"+user+"';"; //ÒªÖ´ÐеÄSQL + String sql = "update Customer set customer_password = '"+newPassword+"' where customer_user = '"+user+"';"; //Ҫִ�е�SQL PreparedStatement stmts = conn.prepareStatement(sql); stmts.executeUpdate(); @@ -200,21 +200,21 @@ public static void changePassword_Customer(String user,String password,String ne } } - //¸Ä±ä¹ÜÀíÔ±µÄÃÜÂë + //�ı����Ա������ public static void changePassword_Manager(String user,String password,String newPassword) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-changePassword"); + System.out.println("�ɹ�����MySQL����-changePassword"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-changePassword"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-changePassword"); - String sql = "update Manager set manager_password = '"+newPassword+"' where manager_user = '"+user+"';"; //ÒªÖ´ÐеÄSQL + String sql = "update Manager set manager_password = '"+newPassword+"' where manager_user = '"+user+"';"; //Ҫִ�е�SQL PreparedStatement stmts = conn.prepareStatement(sql); stmts.executeUpdate(); @@ -228,23 +228,23 @@ public static void changePassword_Manager(String user,String password,String new } } - //ÊÇ·ñ´æÔÚ¸ÃÓû§Ãû + //�Ƿ���ڸ��û��� public static boolean isExist_Customer_user(String user,String password) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-isExist_Customer"); + System.out.println("�ɹ�����MySQL����-isExist_Customer"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-isExist_Customer"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-isExist_Customer"); - String sql = "select * from Customer"; //ÒªÖ´ÐеÄSQL - ResultSet rs = stmt.executeQuery(sql);//´´½¨Êý¾Ý¶ÔÏó - System.out.println("Óû§Ãû"+"\t"+"\t"+"\t"+"ÃÜÂë"); + String sql = "select * from Customer"; //Ҫִ�е�SQL + ResultSet rs = stmt.executeQuery(sql);//�������ݶ��� + System.out.println("�û���"+"\t"+"\t"+"\t"+"����"); while (rs.next()){ System.out.print(rs.getString(1) + "\t"); System.out.print(rs.getString(2) + "\t"); @@ -266,23 +266,23 @@ public static boolean isExist_Customer_user(String user,String password) { return false; } - //ÊÇ·ñ´æÔڸùÜÀíÔ±Ãû³Æ + //�Ƿ���ڸù���Ա���� public static boolean isExist_Manager_user(String user,String password) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-isExist_Manager"); + System.out.println("�ɹ�����MySQL����-isExist_Manager"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-isExist_Manager"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-isExist_Manager"); - String sql = "select * from Manager"; //ÒªÖ´ÐеÄSQL - ResultSet rs = stmt.executeQuery(sql);//´´½¨Êý¾Ý¶ÔÏó - System.out.println("Óû§Ãû"+"\t"+"\t"+"\t"+"ÃÜÂë"); + String sql = "select * from Manager"; //Ҫִ�е�SQL + ResultSet rs = stmt.executeQuery(sql);//�������ݶ��� + System.out.println("�û���"+"\t"+"\t"+"\t"+"����"); while (rs.next()){ System.out.print(rs.getString(1) + "\t"); System.out.print(rs.getString(2) + "\t"); @@ -304,21 +304,21 @@ public static boolean isExist_Manager_user(String user,String password) { return false; } - //²åÈëÐÂÊé - public static void insertBook(String number,String classnumber,String name,String classname,String price,String state,String total) { + //�������� + public static void insertBook(String number,String classnumber,String name,String classname,String author,String price,String state,String total) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-insertBook"); + System.out.println("�ɹ�����MySQL����-insertBook"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-insertBook"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-insertBook"); - String sql = "insert into "+classname+"Book"+" values('"+number+"','"+classnumber+"','"+name+"','"+classname+"','"+price+"','"+state+"','"+total+"','null','null','null');"; //ÒªÖ´ÐеÄSQL + String sql = "insert into "+classname+"Book"+" values('"+number+"','"+classnumber+"','"+name+"','"+classname+"','"+author+"','"+price+"','"+state+"','"+total+"','null','null','null');"; //Ҫִ�е�SQL PreparedStatement stmts = conn.prepareStatement(sql); stmts.executeUpdate(); @@ -332,21 +332,21 @@ public static void insertBook(String number,String classnumber,String name,Strin } } - //н¨Àà±ð + //�½���� public static void newClass(String classnumber, String classname) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-newClass"); + System.out.println("�ɹ�����MySQL����-newClass"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-newClass"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-newClass"); - String sql = "CREATE TABLE "+classname+"Book(number VARCHAR(255) primary key,classnumber VARCHAR(255),name VARCHAR(255),classname VARCHAR(255),price VARCHAR(255),state VARCHAR(255),total VARCHAR(255),current VARCHAR(255),dateon VARCHAR(255),dateoff VARCHAR(255));"; //ÒªÖ´ÐеÄSQL + String sql = "CREATE TABLE "+classname+"Book(number VARCHAR(255) primary key,classnumber VARCHAR(255),name VARCHAR(255),classname VARCHAR(255),author VARCHAR(255),price VARCHAR(255),state VARCHAR(255),total VARCHAR(255),current VARCHAR(255),dateon VARCHAR(255),dateoff VARCHAR(255));"; //Ҫִ�е�SQL PreparedStatement stmts = conn.prepareStatement(sql); stmts.executeUpdate(); @@ -360,21 +360,21 @@ public static void newClass(String classnumber, String classname) { } } - //ɾ³ýÊé¼®ÐÅÏ¢ + //ɾ���鼮��Ϣ public static void deleteBook(String number, String classname) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-deleteBook"); + System.out.println("�ɹ�����MySQL����-deleteBook"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-deleteBook"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-deleteBook"); - String sql = "delete from "+classname+"Book where number = '"+number+"';"; //ÒªÖ´ÐеÄSQL + String sql = "delete from "+classname+"Book where number = '"+number+"';"; //Ҫִ�е�SQL PreparedStatement stmts = conn.prepareStatement(sql); stmts.executeUpdate(); @@ -388,62 +388,79 @@ public static void deleteBook(String number, String classname) { } } - //²éѯijÀàͼÊéÐÅÏ¢ + //��ѯij��ͼ����Ϣ public static void search_classname(String classname) { Information.bookarray.clear(); try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-search_classname"); + System.out.println("�ɹ�����MySQL����-search_classname"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-search_classname"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-search_classname"); - String sql = "select * from "+classname+"Book;"; //ÒªÖ´ÐеÄSQL - ResultSet rs = stmt.executeQuery(sql);//´´½¨Êý¾Ý¶ÔÏó - while (rs.next()){ - Book book = new Book(); - book.number = rs.getString(1); - book.classnumber = rs.getString(2); - book.name = rs.getString(3); - book.classname = rs.getString(4); - book.price = rs.getString(5); - book.state = rs.getString(6); - book.total = rs.getString(7); - book.current = rs.getString(8); - book.dateon = rs.getString(9); - book.dateoff = rs.getString(10); - Information.bookarray.add(book); + String sql = "select * from "+classname+"Book;"; //Ҫִ�е�SQL + ResultSet rs = stmt.executeQuery(sql);//�������ݶ��� + ResultSetMetaData rsmd = rs.getMetaData(); + int columnCount = rsmd.getColumnCount(); + + //�����б����Ƿ���author�ֶ� + boolean hasAuthor = false; + for(int i=1; i<=columnCount; i++) { + if("author".equalsIgnoreCase(rsmd.getColumnName(i))) { + hasAuthor = true; + break; + } + } + + while (rs.next()){ + Book book = new Book(); + book.number = rs.getString("number"); + book.classnumber = rs.getString("classnumber"); + book.name = rs.getString("name"); + book.classname = rs.getString("classname"); + if(hasAuthor) { + book.author = rs.getString("author"); + } else { + book.author = "δ֪"; } - rs.close(); - stmt.close(); - conn.close(); - }catch(Exception e) - { - e.printStackTrace(); + book.price = rs.getString("price"); + book.state = rs.getString("state"); + book.total = rs.getString("total"); + book.current = rs.getString("current"); + book.dateon = rs.getString("dateon"); + book.dateoff = rs.getString("dateoff"); + Information.bookarray.add(book); } + rs.close(); + stmt.close(); + conn.close(); + }catch(Exception e) + { + e.printStackTrace(); + } } - //½èÊé¸ü¸ÄÐÅÏ¢ + //���������Ϣ public static void borrowBook_Update(String classname,String number,String user,String dateoff) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-borrowBook_Customer"); + System.out.println("�ɹ�����MySQL����-borrowBook_Customer"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-borrowBook_Customer"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-borrowBook_Customer"); - String sql = "update "+classname+"Book set state = 'out' where number = '"+number+"';\n"; //ÒªÖ´ÐеÄSQL + String sql = "update "+classname+"Book set state = 'out' where number = '"+number+"';\n"; //Ҫִ�е�SQL PreparedStatement stmts_state = conn.prepareStatement(sql); stmts_state.executeUpdate(); stmts_state.close(); @@ -466,21 +483,21 @@ public static void borrowBook_Update(String classname,String number,String user, } } - //´´½¨Óû§Êý¾Ý¿â + //�����û����ݿ� public static void newCustomer(String user) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-newCustomer"); + System.out.println("�ɹ�����MySQL����-newCustomer"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-newCustomer"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-newCustomer"); - String sql = "CREATE TABLE "+user+"Customer (number VARCHAR(255) primary key,classname VARCHAR(255),name VARCHAR(255),dateoff VARCHAR(255));"; //ÒªÖ´ÐеÄSQL + String sql = "CREATE TABLE "+user+"Customer (number VARCHAR(255) primary key,classname VARCHAR(255),name VARCHAR(255),dateoff VARCHAR(255));"; //Ҫִ�е�SQL PreparedStatement stmts = conn.prepareStatement(sql); stmts.executeUpdate(); @@ -494,21 +511,21 @@ public static void newCustomer(String user) { } } - //½èÊé×¢Éäµ½Óû§ÐÅÏ¢ + //����ע�䵽�û���Ϣ public static void borrowBook_Insert(String classname,String number,String user,String dateoff) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-borrowBook_Insert"); + System.out.println("�ɹ�����MySQL����-borrowBook_Insert"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-borrowBook_Insert"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-borrowBook_Insert"); - String sql = "insert into "+user+"Customer values('"+number+"','"+classname+"','"+search_bookname(classname, number)+"','"+dateoff+"');"; //ÒªÖ´ÐеÄSQL + String sql = "insert into "+user+"Customer values('"+number+"','"+classname+"','"+search_bookname(classname, number)+"','"+dateoff+"');"; //Ҫִ�е�SQL PreparedStatement stmts = conn.prepareStatement(sql); stmts.executeUpdate(); @@ -522,21 +539,21 @@ public static void borrowBook_Insert(String classname,String number,String user, } } - //»¹Êé¸üÐÂÊé¼®Êý¾Ý¿âÐÅÏ¢ + //��������鼮���ݿ���Ϣ public static void returnBook_Update(String classname,String number,String user,String dateoff) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-returnBook_Update"); + System.out.println("�ɹ�����MySQL����-returnBook_Update"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-returnBook_Update"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-returnBook_Update"); - String sql = "update "+classname+"Book set state = 'in' where number = '"+number+"';\n"; //ÒªÖ´ÐеÄSQL + String sql = "update "+classname+"Book set state = 'in' where number = '"+number+"';\n"; //Ҫִ�е�SQL PreparedStatement stmts_state = conn.prepareStatement(sql); stmts_state.executeUpdate(); stmts_state.close(); @@ -558,21 +575,21 @@ public static void returnBook_Update(String classname,String number,String user, e.printStackTrace(); } } - //»¹Êé¸üÐÂÓû§µÄÊý¾Ý¿âÐÅÏ¢ + //��������û������ݿ���Ϣ public static void returnBook_Delete(String number,String user) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-returnBook_Delete"); + System.out.println("�ɹ�����MySQL����-returnBook_Delete"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-returnBook_Delete"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-returnBook_Delete"); - String sql = "delete from "+user+"Customer where number = '"+number+"';"; //ÒªÖ´ÐеÄSQL + String sql = "delete from "+user+"Customer where number = '"+number+"';"; //Ҫִ�е�SQL PreparedStatement stmts = conn.prepareStatement(sql); stmts.executeUpdate(); @@ -585,21 +602,21 @@ public static void returnBook_Delete(String number,String user) { e.printStackTrace(); } } - //Ðø½è¸üÐÂÁ½ÕßÊý¾Ý¿âÐÅÏ¢ + //��������������ݿ���Ϣ public static void prolongBook_Update(String classname,String number,String dateoff,String user) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-prolongBook_Update"); + System.out.println("�ɹ�����MySQL����-prolongBook_Update"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-prolongBook_Update"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-prolongBook_Update"); - String sql = "update "+classname+"Book set dateoff = '"+dateoff+"' where number = '"+number+"';\n"; //ÒªÖ´ÐеÄSQL + String sql = "update "+classname+"Book set dateoff = '"+dateoff+"' where number = '"+number+"';\n"; //Ҫִ�е�SQL PreparedStatement stmts_state = conn.prepareStatement(sql); stmts_state.executeUpdate(); stmts_state.close(); @@ -617,24 +634,24 @@ public static void prolongBook_Update(String classname,String number,String date } } - //²éѯ¸öÈËͼÊéÐÅÏ¢ + //��ѯ����ͼ����Ϣ public static void search_personal(String user) { Information.bookarray.clear(); try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-search_personal"); + System.out.println("�ɹ�����MySQL����-search_personal"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-search_personal"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-search_personal"); - String sql = "select * from "+user+"Customer;"; //ÒªÖ´ÐеÄSQL - ResultSet rs = stmt.executeQuery(sql);//´´½¨Êý¾Ý¶ÔÏó + String sql = "select * from "+user+"Customer;"; //Ҫִ�е�SQL + ResultSet rs = stmt.executeQuery(sql);//�������ݶ��� while (rs.next()){ Book book = new Book(); book.number = rs.getString(1); @@ -651,22 +668,22 @@ public static void search_personal(String user) { e.printStackTrace(); } } - //ÊÇ·ñ´æÔÚ¸ÃTable±í + //�Ƿ���ڸ�Table�� public static boolean isExist_Table(String table) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-isExist_Table"); + System.out.println("�ɹ�����MySQL����-isExist_Table"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-isExist_Table"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-isExist_Table"); - String sql = "show tables"; //ÒªÖ´ÐеÄSQL - ResultSet rs = stmt.executeQuery(sql);//´´½¨Êý¾Ý¶ÔÏó + String sql = "show tables"; //Ҫִ�е�SQL + ResultSet rs = stmt.executeQuery(sql);//�������ݶ��� while (rs.next()){ if(table.equals(rs.getString(1))) { return true; @@ -681,22 +698,22 @@ public static boolean isExist_Table(String table) { } return false; } - //²éÕÒÊéÃû + //�������� public static String search_bookname(String classname,String number) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-search_bookname"); + System.out.println("�ɹ�����MySQL����-search_bookname"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-search_bookname"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-search_bookname"); - String sql = "select * from "+classname+"book where number='"+number+"';"; //ÒªÖ´ÐеÄSQL - ResultSet rs = stmt.executeQuery(sql);//´´½¨Êý¾Ý¶ÔÏó + String sql = "select * from "+classname+"book where number='"+number+"';"; //Ҫִ�е�SQL + ResultSet rs = stmt.executeQuery(sql);//�������ݶ��� while (rs.next()){ return rs.getString(3); } @@ -710,22 +727,22 @@ public static String search_bookname(String classname,String number) { return "null"; } - //²éÕÒÊ鼮״̬ + //�����鼮״̬ public static String search_bookstate(String classname,String number) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-search_bookstate"); + System.out.println("�ɹ�����MySQL����-search_bookstate"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-search_bookstate"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-search_bookstate"); - String sql = "select * from "+classname+"book where number='"+number+"';"; //ÒªÖ´ÐеÄSQL - ResultSet rs = stmt.executeQuery(sql);//´´½¨Êý¾Ý¶ÔÏó + String sql = "select * from "+classname+"book where number='"+number+"';"; //Ҫִ�е�SQL + ResultSet rs = stmt.executeQuery(sql);//�������ݶ��� while (rs.next()){ return rs.getString(6); } @@ -739,22 +756,22 @@ public static String search_bookstate(String classname,String number) { return "null"; } - //²éÕÒÊé¼®»¹ÊéÈÕÆÚ + //�����鼮�������� public static int search_bookdateoff(String classname,String number) { try{ - //µ÷ÓÃClass.forName()·½·¨¼ÓÔØÇý¶¯³ÌÐò + //����Class.forName()���������������� Class.forName("com.mysql.jdbc.Driver"); - System.out.println("³É¹¦¼ÓÔØMySQLÇý¶¯-search_bookdateoff"); + System.out.println("�ɹ�����MySQL����-search_bookdateoff"); - String url=Information.JDBC_URL; //JDBCµÄURL + String url=Information.JDBC_URL; //JDBC��URL Connection conn; conn = DriverManager.getConnection(url,Information.username,Information.password); - Statement stmt = conn.createStatement(); //´´½¨Statement¶ÔÏó - System.out.println("³É¹¦Á¬½Óµ½Êý¾Ý¿â-search_bookdateoff"); + Statement stmt = conn.createStatement(); //����Statement���� + System.out.println("�ɹ����ӵ����ݿ�-search_bookdateoff"); - String sql = "select * from "+classname+"book where number='"+number+"';"; //ÒªÖ´ÐеÄSQL - ResultSet rs = stmt.executeQuery(sql);//´´½¨Êý¾Ý¶ÔÏó + String sql = "select * from "+classname+"book where number='"+number+"';"; //Ҫִ�е�SQL + ResultSet rs = stmt.executeQuery(sql);//�������ݶ��� while (rs.next()){ return Integer.parseInt(rs.getString(10)); } @@ -767,4 +784,212 @@ public static int search_bookdateoff(String classname,String number) { } return 0; } + + //��ȡ�û��Ľ�鼮���� + public static ArrayList getUserBorrowedClasses(String user) { + ArrayList classes = new ArrayList(); + try{ + Class.forName("com.mysql.jdbc.Driver"); + System.out.println("�ɹ�����MySQL����-getUserBorrowedClasses"); + + String url=Information.JDBC_URL; + Connection conn; + + conn = DriverManager.getConnection(url,Information.username,Information.password); + Statement stmt = conn.createStatement(); + System.out.println("�ɹ����ӵ����ݿ�-getUserBorrowedClasses"); + + String sql = "select distinct classname from "+user+"Customer;"; + ResultSet rs = stmt.executeQuery(sql); + while (rs.next()){ + String className = rs.getString(1); + if(!classes.contains(className)) { + classes.add(className); + } + } + rs.close(); + stmt.close(); + conn.close(); + }catch(Exception e) + { + e.printStackTrace(); + } + return classes; + } + + //��ݶ�鼮����Ƽ�����ͼ�� + public static ArrayList getRecommendBooks(String user) { + ArrayList recommendBooks = new ArrayList(); + ArrayList borrowedClasses = getUserBorrowedClasses(user); + + //����û�н�鼮��¼�����Ƽ� + if(borrowedClasses.isEmpty()) { + return recommendBooks; + } + + //��ÿ�����e���в�ѯ�ɽ���ͼ�� + for(String className : borrowedClasses) { + try{ + Class.forName("com.mysql.jdbc.Driver"); + System.out.println("�ɹ�����MySQL����-getRecommendBooks"); + + String url=Information.JDBC_URL; + Connection conn; + + conn = DriverManager.getConnection(url,Information.username,Information.password); + Statement stmt = conn.createStatement(); + System.out.println("�ɹ����ӵ����ݿ�-getRecommendBooks"); + + //��ѯ���ø÷���еĿɽ���ͼ�� + String sql = "select * from "+className+"Book where state='in';"; + ResultSet rs = stmt.executeQuery(sql); + ResultSetMetaData rsmd = rs.getMetaData(); + int columnCount = rsmd.getColumnCount(); + + //�����б����Ƿ���author�ֶ� + boolean hasAuthor = false; + for(int i=1; i<=columnCount; i++) { + if("author".equalsIgnoreCase(rsmd.getColumnName(i))) { + hasAuthor = true; + break; + } + } + + while (rs.next()){ + Book book = new Book(); + book.number = rs.getString("number"); + book.classnumber = rs.getString("classnumber"); + book.name = rs.getString("name"); + book.classname = rs.getString("classname"); + if(hasAuthor) { + book.author = rs.getString("author"); + } else { + book.author = "δ֪"; + } + book.price = rs.getString("price"); + book.state = rs.getString("state"); + book.total = rs.getString("total"); + book.current = rs.getString("current"); + book.dateon = rs.getString("dateon"); + book.dateoff = rs.getString("dateoff"); + recommendBooks.add(book); + } + rs.close(); + stmt.close(); + conn.close(); + }catch(Exception e) + { + e.printStackTrace(); + } + } + + return recommendBooks; + } + + //��ȡ���н�鼮���� + public static ArrayList getAllBookClasses() { + ArrayList classes = new ArrayList(); + try{ + Class.forName("com.mysql.jdbc.Driver"); + System.out.println("�ɹ�����MySQL����-getAllBookClasses"); + + String url=Information.JDBC_URL; + Connection conn; + + conn = DriverManager.getConnection(url,Information.username,Information.password); + Statement stmt = conn.createStatement(); + System.out.println("�ɹ����ӵ����ݿ�-getAllBookClasses"); + + //��ѯ�������и�Book���� + String sql = "show tables;"; + ResultSet rs = stmt.executeQuery(sql); + while (rs.next()){ + String tableName = rs.getString(1); + //ֻȡ��Book��β�����ⲻ��Customer��� + if(tableName.endsWith("Book") && !tableName.contains("Customer")) { + //ȥ��Book׺ + String className = tableName.substring(0, tableName.length() - 4); + if(!classes.contains(className)) { + classes.add(className); + } + } + } + rs.close(); + stmt.close(); + conn.close(); + }catch(Exception e) + { + e.printStackTrace(); + } + return classes; + } + + //�����г���Ƽ��ͼ�� + public static ArrayList getRandomRecommendBooks() { + ArrayList recommendBooks = new ArrayList(); + ArrayList allClasses = getAllBookClasses(); + + //������� + if(allClasses.isEmpty()) { + return recommendBooks; + } + + //�Ӹ÷����в�ѯһЩ�ɽ���ͼ�� + for(String className : allClasses) { + try{ + Class.forName("com.mysql.jdbc.Driver"); + System.out.println("�ɹ�����MySQL����-getRandomRecommendBooks"); + + String url=Information.JDBC_URL; + Connection conn; + + conn = DriverManager.getConnection(url,Information.username,Information.password); + Statement stmt = conn.createStatement(); + System.out.println("�ɹ����ӵ����ݿ�-getRandomRecommendBooks"); + + //��ѯ���ø÷���еĿɽ���ͼ�� + String sql = "select * from "+className+"Book where state='in' limit 3;"; + ResultSet rs = stmt.executeQuery(sql); + ResultSetMetaData rsmd = rs.getMetaData(); + int columnCount = rsmd.getColumnCount(); + + //�����б����Ƿ���author�ֶ� + boolean hasAuthor = false; + for(int i=1; i<=columnCount; i++) { + if("author".equalsIgnoreCase(rsmd.getColumnName(i))) { + hasAuthor = true; + break; + } + } + + while (rs.next()){ + Book book = new Book(); + book.number = rs.getString("number"); + book.classnumber = rs.getString("classnumber"); + book.name = rs.getString("name"); + book.classname = rs.getString("classname"); + if(hasAuthor) { + book.author = rs.getString("author"); + } else { + book.author = "δ֪"; + } + book.price = rs.getString("price"); + book.state = rs.getString("state"); + book.total = rs.getString("total"); + book.current = rs.getString("current"); + book.dateon = rs.getString("dateon"); + book.dateoff = rs.getString("dateoff"); + recommendBooks.add(book); + } + rs.close(); + stmt.close(); + conn.close(); + }catch(Exception e) + { + e.printStackTrace(); + } + } + + return recommendBooks; + } } diff --git a/src/com/littleheap/Manager/InsertBook.java b/src/com/littleheap/Manager/InsertBook.java index 750d6f8..bb4a13f 100644 --- a/src/com/littleheap/Manager/InsertBook.java +++ b/src/com/littleheap/Manager/InsertBook.java @@ -1,175 +1,190 @@ -package com.littleheap.Manager; - -import javax.swing.JPanel; -import javax.swing.JLabel; -import javax.swing.JOptionPane; - -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.SwingConstants; - -import com.littleheap.MainInterface; -import com.littleheap.DataBase.TableOperate; - -import javax.swing.JTextField; -import javax.swing.JButton; -import java.awt.Color; - -public class InsertBook extends JPanel implements ActionListener{ - private JTextField tf_number; - private JLabel lb_number; - private JLabel lb_classnumber; - private JLabel lb_name; - private JLabel lb_classname; - private JLabel lb_price; - private JLabel lb_state; - private JLabel lb_total; - private JTextField tf_classnumber; - private JTextField tf_name; - private JTextField tf_classname; - private JTextField tf_price; - private JTextField tf_state; - private JTextField tf_total; - private JButton back; - private JButton btn_submit; - - /** - * Create the panel. - */ - public InsertBook() { - setBackground(Color.PINK); - setLayout(null); - - JLabel label = new JLabel("\u65B0\u4E66\u5F55\u5165"); - label.setHorizontalAlignment(SwingConstants.CENTER); - label.setFont(new Font("ËÎÌå", Font.BOLD, 40)); - label.setBounds(530, 0, 294, 105); - add(label); - - lb_number = new JLabel("\u7F16\u53F7\uFF1A"); - lb_number.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - lb_number.setBounds(293, 137, 194, 55); - add(lb_number); - - tf_number = new JTextField(); - tf_number.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - tf_number.setColumns(10); - tf_number.setBounds(486, 127, 526, 75); - add(tf_number); - - lb_classnumber = new JLabel("\u5206\u7C7B\u7F16\u53F7\uFF1A"); - lb_classnumber.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - lb_classnumber.setBounds(293, 233, 194, 55); - add(lb_classnumber); - - lb_name = new JLabel("\u4E66\u540D\uFF1A"); - lb_name.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - lb_name.setBounds(293, 329, 194, 55); - add(lb_name); - - lb_classname = new JLabel("\u5206\u7C7B\u540D\u79F0\uFF1A"); - lb_classname.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - lb_classname.setBounds(293, 435, 194, 55); - add(lb_classname); - - lb_price = new JLabel("\u4EF7\u683C\uFF1A"); - lb_price.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - lb_price.setBounds(293, 521, 194, 55); - add(lb_price); - - lb_state = new JLabel("\u5165\u85CF\u72B6\u6001\uFF1A"); - lb_state.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - lb_state.setBounds(293, 617, 194, 55); - add(lb_state); - - lb_total = new JLabel("\u6570\u91CF\uFF1A"); - lb_total.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - lb_total.setBounds(293, 713, 194, 55); - add(lb_total); - - tf_classnumber = new JTextField(); - tf_classnumber.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - tf_classnumber.setColumns(10); - tf_classnumber.setBounds(486, 223, 526, 75); - add(tf_classnumber); - - tf_name = new JTextField(); - tf_name.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - tf_name.setColumns(10); - tf_name.setBounds(486, 319, 526, 75); - add(tf_name); - - tf_classname = new JTextField(); - tf_classname.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - tf_classname.setColumns(10); - tf_classname.setBounds(486, 415, 526, 75); - add(tf_classname); - - tf_price = new JTextField(); - tf_price.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - tf_price.setColumns(10); - tf_price.setBounds(486, 511, 526, 75); - add(tf_price); - - tf_state = new JTextField(); - tf_state.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - tf_state.setColumns(10); - tf_state.setBounds(486, 607, 526, 75); - add(tf_state); - - tf_total = new JTextField(); - tf_total.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - tf_total.setColumns(10); - tf_total.setBounds(486, 703, 526, 75); - add(tf_total); - - btn_submit = new JButton("\u63D0\u4EA4"); - btn_submit.setFont(new Font("ËÎÌå", Font.BOLD, 35)); - btn_submit.setBounds(573, 833, 251, 80); - add(btn_submit); - btn_submit.addActionListener(this); - - back = new JButton("\u8FD4\u56DE"); - back.setFont(new Font("ËÎÌå", Font.PLAIN, 26)); - back.setBounds(0, 0, 115, 82); - add(back); - back.addActionListener(this); - - } - - @Override - public void actionPerformed(ActionEvent e) { - // TODO Auto-generated method stub - if(e.getSource() == back) { - //µã»÷·µ»Ø°´Å¥ - MainInterface.InserttoManager(); - }else if(e.getSource() == btn_submit) { - //µã»÷Ìá½»°´Å¥ - //Åж¨Â¼ÈëÐÅÏ¢ÊÇ·ñ³åÍ» - String number = tf_number.getText(); - String classnumber = tf_classnumber.getText(); - String name = tf_name.getText(); - String classname = tf_classname.getText(); - String price = tf_price.getText(); - String state = tf_state.getText(); - String total = tf_total.getText(); - - if(TableOperate.search_bookstate(classname, number).equals("null")) { - //²åÈëÊé¼®ÐÅÏ¢ - TableOperate.insertBook(number, classnumber, name, classname, price, state, total); - tf_number.setText(""); - tf_classnumber.setText(""); - tf_name.setText(""); - tf_classname.setText(""); - tf_price.setText(""); - tf_state.setText(""); - tf_total.setText(""); - JOptionPane.showMessageDialog(null, "¹§Ï²", "Ê鼮¼Èë³É¹¦", JOptionPane.OK_CANCEL_OPTION); - }else { - JOptionPane.showMessageDialog(null, "Êé¼®ÐÅÏ¢³åÍ»", "Ê鼮¼Èëʧ°Ü", JOptionPane.ERROR_MESSAGE); - } - } - } -} +package com.littleheap.Manager; + +import javax.swing.JPanel; +import javax.swing.JLabel; +import javax.swing.JOptionPane; + +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.SwingConstants; + +import com.littleheap.MainInterface; +import com.littleheap.DataBase.TableOperate; + +import javax.swing.JTextField; +import javax.swing.JButton; +import java.awt.Color; + +public class InsertBook extends JPanel implements ActionListener{ + private JTextField tf_number; + private JLabel lb_number; + private JLabel lb_classnumber; + private JLabel lb_name; + private JLabel lb_classname; + private JLabel lb_author; + private JLabel lb_price; + private JLabel lb_state; + private JLabel lb_total; + private JTextField tf_classnumber; + private JTextField tf_name; + private JTextField tf_classname; + private JTextField tf_author; + private JTextField tf_price; + private JTextField tf_state; + private JTextField tf_total; + private JButton back; + private JButton btn_submit; + + /** + * Create the panel. + */ + public InsertBook() { + setBackground(Color.PINK); + setLayout(null); + + JLabel label = new JLabel("\u65B0\u4E66\u5F55\u5165"); + label.setHorizontalAlignment(SwingConstants.CENTER); + label.setFont(new Font("����", Font.BOLD, 40)); + label.setBounds(530, 0, 294, 105); + add(label); + + lb_number = new JLabel("\u7F16\u53F7\uFF1A"); + lb_number.setFont(new Font("����", Font.BOLD, 35)); + lb_number.setBounds(293, 120, 194, 55); + add(lb_number); + + tf_number = new JTextField(); + tf_number.setFont(new Font("����", Font.BOLD, 35)); + tf_number.setColumns(10); + tf_number.setBounds(486, 110, 526, 75); + add(tf_number); + + lb_classnumber = new JLabel("\u5206\u7C7B\u7F16\u53F7\uFF1A"); + lb_classnumber.setFont(new Font("����", Font.BOLD, 35)); + lb_classnumber.setBounds(293, 200, 194, 55); + add(lb_classnumber); + + lb_name = new JLabel("\u4E66\u540D\uFF1A"); + lb_name.setFont(new Font("����", Font.BOLD, 35)); + lb_name.setBounds(293, 280, 194, 55); + add(lb_name); + + lb_classname = new JLabel("\u5206\u7C7B\u540D\u79F0\uFF1A"); + lb_classname.setFont(new Font("����", Font.BOLD, 35)); + lb_classname.setBounds(293, 360, 194, 55); + add(lb_classname); + + lb_author = new JLabel("\u4F5C\u8005\uFF1A"); + lb_author.setFont(new Font("����", Font.BOLD, 35)); + lb_author.setBounds(293, 440, 194, 55); + add(lb_author); + + lb_price = new JLabel("\u4EF7\u683C\uFF1A"); + lb_price.setFont(new Font("����", Font.BOLD, 35)); + lb_price.setBounds(293, 520, 194, 55); + add(lb_price); + + lb_state = new JLabel("\u5165\u85CF\u72B6\u6001\uFF1A"); + lb_state.setFont(new Font("����", Font.BOLD, 35)); + lb_state.setBounds(293, 600, 194, 55); + add(lb_state); + + lb_total = new JLabel("\u6570\u91CF\uFF1A"); + lb_total.setFont(new Font("����", Font.BOLD, 35)); + lb_total.setBounds(293, 680, 194, 55); + add(lb_total); + + tf_classnumber = new JTextField(); + tf_classnumber.setFont(new Font("����", Font.BOLD, 35)); + tf_classnumber.setColumns(10); + tf_classnumber.setBounds(486, 190, 526, 75); + add(tf_classnumber); + + tf_name = new JTextField(); + tf_name.setFont(new Font("����", Font.BOLD, 35)); + tf_name.setColumns(10); + tf_name.setBounds(486, 270, 526, 75); + add(tf_name); + + tf_classname = new JTextField(); + tf_classname.setFont(new Font("����", Font.BOLD, 35)); + tf_classname.setColumns(10); + tf_classname.setBounds(486, 350, 526, 75); + add(tf_classname); + + tf_author = new JTextField(); + tf_author.setFont(new Font("����", Font.BOLD, 35)); + tf_author.setColumns(10); + tf_author.setBounds(486, 430, 526, 75); + add(tf_author); + + tf_price = new JTextField(); + tf_price.setFont(new Font("����", Font.BOLD, 35)); + tf_price.setColumns(10); + tf_price.setBounds(486, 510, 526, 75); + add(tf_price); + + tf_state = new JTextField(); + tf_state.setFont(new Font("����", Font.BOLD, 35)); + tf_state.setColumns(10); + tf_state.setBounds(486, 590, 526, 75); + add(tf_state); + + tf_total = new JTextField(); + tf_total.setFont(new Font("����", Font.BOLD, 35)); + tf_total.setColumns(10); + tf_total.setBounds(486, 670, 526, 75); + add(tf_total); + + btn_submit = new JButton("\u63D0\u4EA4"); + btn_submit.setFont(new Font("����", Font.BOLD, 35)); + btn_submit.setBounds(573, 780, 251, 80); + add(btn_submit); + btn_submit.addActionListener(this); + + back = new JButton("\u8FD4\u56DE"); + back.setFont(new Font("����", Font.PLAIN, 26)); + back.setBounds(0, 0, 115, 82); + add(back); + back.addActionListener(this); + + } + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + if(e.getSource() == back) { + //������ذ�ť + MainInterface.InserttoManager(); + }else if(e.getSource() == btn_submit) { + //����Ï��ť + //�ж�¼����Ϣ�Ƿ��ͻ + String number = tf_number.getText(); + String classnumber = tf_classnumber.getText(); + String name = tf_name.getText(); + String classname = tf_classname.getText(); + String author = tf_author.getText(); + String price = tf_price.getText(); + String state = tf_state.getText(); + String total = tf_total.getText(); + + if(TableOperate.search_bookstate(classname, number).equals("null")) { + //�����鼮��Ϣ + TableOperate.insertBook(number, classnumber, name, classname, author, price, state, total); + tf_number.setText(""); + tf_classnumber.setText(""); + tf_name.setText(""); + tf_classname.setText(""); + tf_author.setText(""); + tf_price.setText(""); + tf_state.setText(""); + tf_total.setText(""); + JOptionPane.showMessageDialog(null, "��ϲ", "�鼮¼��ɹ�", JOptionPane.OK_CANCEL_OPTION); + }else { + JOptionPane.showMessageDialog(null, "�鼮��Ϣ��ͻ", "�鼮¼��ʧ��", JOptionPane.ERROR_MESSAGE); + } + } + } +} diff --git a/src/com/littleheap/User/BorrowBook_Information.java b/src/com/littleheap/User/BorrowBook_Information.java index a8ef8c7..fce8901 100644 --- a/src/com/littleheap/User/BorrowBook_Information.java +++ b/src/com/littleheap/User/BorrowBook_Information.java @@ -1,7 +1,9 @@ package com.littleheap.User; import javax.swing.JPanel; +import javax.swing.JScrollPane; +import com.littleheap.Book; import com.littleheap.MainInterface; import com.littleheap.DataBase.TableOperate; import com.littleheap.Static.Information; @@ -12,20 +14,27 @@ import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.ArrayList; + import javax.swing.JTextArea; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTextField; +import javax.swing.border.TitledBorder; public class BorrowBook_Information extends JPanel implements ActionListener { private JButton back; private static JTextArea textArea; + private static JTextArea recommendTextArea; private static String info; + private static String recommendInfo; private JTextField tf_number; private JLabel lb_number; private JButton btn_borrow; private JLabel lb_dateoff; private JTextField tf_dateoff; + private JLabel lb_recommend; + private JPanel recommendPanel; /** * Create the panel. @@ -35,52 +44,88 @@ public BorrowBook_Information() { setLayout(null); back = new JButton("\u8FD4\u56DE"); - back.setFont(new Font("ËÎÌå", Font.PLAIN, 26)); + back.setFont(new Font("����", Font.PLAIN, 26)); back.setBounds(0, 0, 115, 82); add(back); back.addActionListener(this); + //�����Լ���б��� textArea = new JTextArea(); - textArea.setFont(new Font("Monospaced", Font.PLAIN, 20)); - textArea.setBounds(152, 142, 1111, 782); - add(textArea); - + textArea.setFont(new Font("Monospaced", Font.PLAIN, 18)); + textArea.setBounds(152, 142, 800, 782); textArea.setEditable(false); + //�������ö� + JScrollPane scrollPane = new JScrollPane(textArea); + scrollPane.setBounds(152, 142, 800, 782); + scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + add(scrollPane); + lb_number = new JLabel("\u56FE\u4E66\u7F16\u53F7\uFF1A"); - lb_number.setFont(new Font("ËÎÌå", Font.BOLD, 35)); + lb_number.setFont(new Font("����", Font.BOLD, 35)); lb_number.setBounds(152, 39, 185, 55); add(lb_number); tf_number = new JTextField(); - tf_number.setFont(new Font("ËÎÌå", Font.BOLD, 35)); + tf_number.setFont(new Font("����", Font.BOLD, 35)); tf_number.setColumns(10); tf_number.setBounds(317, 29, 226, 75); add(tf_number); btn_borrow = new JButton("\u501F\u4E66"); - btn_borrow.setFont(new Font("ËÎÌå", Font.BOLD, 35)); + btn_borrow.setFont(new Font("����", Font.BOLD, 35)); btn_borrow.setBounds(926, 26, 251, 80); add(btn_borrow); btn_borrow.addActionListener(this); lb_dateoff = new JLabel("\u671F\u9650\uFF1A"); - lb_dateoff.setFont(new Font("ËÎÌå", Font.BOLD, 35)); + lb_dateoff.setFont(new Font("����", Font.BOLD, 35)); lb_dateoff.setBounds(575, 39, 185, 55); add(lb_dateoff); tf_dateoff = new JTextField(); - tf_dateoff.setFont(new Font("ËÎÌå", Font.BOLD, 35)); + tf_dateoff.setFont(new Font("����", Font.BOLD, 35)); tf_dateoff.setColumns(10); tf_dateoff.setBounds(679, 29, 226, 75); add(tf_dateoff); - info = "ͼÊé±àºÅ ·ÖÀà±àºÅ ͼÊéÃû³Æ ·ÖÀàÃû³Æ ¼Û¸ñ ״̬ »ñÈ¡ÈË ÖÕÖ¹ÈÕÆÚ\n"; + //�����Ƽ������� + lb_recommend = new JLabel("\u4E66\u7C4D\u63A8\u8350"); + lb_recommend.setFont(new Font("����", Font.BOLD, 28)); + lb_recommend.setForeground(new Color(139, 69, 19)); + lb_recommend.setBounds(970, 130, 180, 40); + add(lb_recommend); + + //�����Ƽ������ӱ߿� + recommendPanel = new JPanel(); + recommendPanel.setLayout(null); + recommendPanel.setBackground(new Color(255, 248, 220)); + recommendPanel.setBorder(new TitledBorder(null, "�����Ƽ�", TitledBorder.LEADING, TitledBorder.TOP, new Font("����", Font.BOLD, 20), new Color(139, 69, 19))); + recommendPanel.setBounds(970, 170, 300, 750); + add(recommendPanel); + + //�����Ƽ�������б��� + recommendTextArea = new JTextArea(); + recommendTextArea.setFont(new Font("Monospaced", Font.PLAIN, 16)); + recommendTextArea.setEditable(false); + recommendTextArea.setBackground(new Color(255, 248, 220)); + recommendTextArea.setLineWrap(true); + recommendTextArea.setWrapStyleWord(true); + + //�����Ƽ�������ö� + JScrollPane recommendScrollPane = new JScrollPane(recommendTextArea); + recommendScrollPane.setBounds(10, 25, 280, 715); + recommendScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + recommendScrollPane.setBorder(null); + recommendPanel.add(recommendScrollPane); + + info = "ͼ���� ������ ͼ������ �������� �۸� ״̬ ��ȡ�� ��ֹ����\n"; + recommendInfo = ""; } public static void setTextArea() { - info = "ͼÊé±àºÅ ·ÖÀà±àºÅ ͼÊéÃû³Æ ·ÖÀàÃû³Æ ¼Û¸ñ ״̬ »ñÈ¡ÈË ÖÕÖ¹ÈÕÆÚ\n"; + info = "ͼ���� ������ ͼ������ �������� �۸� ״̬ ��ȡ�� ��ֹ����\n"; for(int i=0;i recommendBooks = TableOperate.getRecommendBooks(Information.user); + + //����û�н�鼮��¼�����ṩ�����Ƽ� + if(recommendBooks.isEmpty()) { + recommendBooks = TableOperate.getRandomRecommendBooks(); + } + + recommendInfo = ""; + + if(recommendBooks.isEmpty()) { + recommendInfo = "��ʱû�����Ƽ�����\n\n�����������ֲ���ͼ�飡"; + } else { + recommendInfo = "���������Ľ�鼮��¼��\nΪ���������Ƽ����룺\n\n"; + recommendInfo += "================================\n\n"; + + for(int i=0;i= 9) { //ֻ��ʾǰ10����Ƽ� + recommendInfo += "... ���м�Ƽ� ...\n"; + break; + } + } + + recommendInfo += "\n================================\n"; + recommendInfo += "��ʾ���������Ƽ����ɽ���"; + } + + recommendTextArea.setText(recommendInfo); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getSource() == back) { - //µã»÷·µ»Ø°´Å¥ + //������ذ�ť MainInterface.BorrowInfotoBorrow(); }if(e.getSource() == btn_borrow) { - //µã»÷½èÊé°´Å¥ - //ÏÈÅж¨ÊÇ·ñÓдËÊé + //������鰴ť + //���ж��Ƿ��д��� if(TableOperate.search_bookname(Information.search_classname, tf_number.getText()).equals("null")) { - JOptionPane.showMessageDialog(null, "ÊäÈë½èÊéÐÅÏ¢ÓÐÎó", "½èÊéʧ°Ü", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(null, "���������Ϣ����", "����ʧ��", JOptionPane.ERROR_MESSAGE); tf_number.setText(""); tf_dateoff.setText(""); }else { - //Åж¨´ËÊéÊÇ·ñÒѱ»½è³ö + //�ж������Ƿ��ѱ���� if(TableOperate.search_bookstate(Information.search_classname, tf_number.getText()).equals("in")) { TableOperate.borrowBook_Update(Information.search_classname, tf_number.getText(), Information.user, tf_dateoff.getText().toString()); TableOperate.borrowBook_Insert(Information.search_classname, tf_number.getText(), Information.user, tf_dateoff.getText().toString()); tf_number.setText(""); tf_dateoff.setText(""); + //�������º����µ�Ƽ����� + setRecommendArea(); MainInterface.BorrowInfotoBorrow(); MainInterface.BorrowtoUser(); }else { - JOptionPane.showMessageDialog(null, "¸ÃÊéÒѽè³öÖÁ£º"+TableOperate.search_bookdateoff(Information.search_classname, tf_number.getText()), "½èÊéʧ°Ü", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(null, "�����ѽ������"+TableOperate.search_bookdateoff(Information.search_classname, tf_number.getText()), "����ʧ��", JOptionPane.ERROR_MESSAGE); tf_number.setText(""); tf_dateoff.setText(""); }