java 数据库 课程设计 图书馆管理信息系统
java 数据库 重点是实现了预约 违章等功能 public static int checkIt(String name, String password,String purview)// 验证用户名 密码 { interFace s = new interFace(); String temp = "select * from user_info " + "where user_name='" + name + "'" + " and " + "user_psw='" + password + "& #039;" + " and " + "user_purview='" + purview + "'"; s.search(temp); int i = 0; try { while (s.C.next()) { i++; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return i; } public static void update_book_number(String s4){ String sql="update book_info set book_num_in=book_num_in+1 where book_info.book_id='"+s4+"'"; try{ interFace.edit(sql); }catch(Exception e){ e.printStackTrace(); } } public static int book_num_in(String s){ String sql="select book_num_in from book_info where book_name= '"+s+"'"; int count=0; try{ rs=B.executeQuery(sql); if(rs.next()){ count=Integer.parseInt(rs.getString(1)); } } catch(Exception e){ e.printStackTrace(); } return count; } public static void day_number(String s1,String s2,int s3){ float days=0;String s=null; int mum=0; try{ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); s = df.format(new Date()); String date=s1; Date d1 = df.parse(s); Date d2 = df.parse(date); long diff = d1.getTime() - d2.getTime(); days= diff / (1000 * 60 * 60 * 24); }catch(Exception e){ e.printStackTrace(); }System.out.println(days); days=days-30; if(s2.equals("是")){ days=days-30; } if(days>0){ days=days/10;} else{ days=0; } if(days>0){ write_dirty(s3,days);//写入不良信息 } try{//把borrow 中的borrow_returned 将return 改成"是" String ss="是"; String sql="update borrow_info set borrow_returned='"+ss+ "' , borrow_info.return_date= '"+s+"'where borrow_info.borrow_id='"+s3+"'"; interFace.edit(sql); }catch(Exception e ){ e.printStackTrace(); } } public static void write_dirty(int s,float days){ try{ int count=0; rs=B.executeQuery("select count(*) from dirty_info "); if(rs.next()) count=Integer.parseInt(rs.getString(1)); count++; String des="过期"+days*10+"天,罚款"+days+"元"; interFace.edit("insert into dirty_info values('"+ count+"','"+s+"','"+des+"') "); JOptionPane.showMessageDialog(null,des,"提示!",JOptionPane.PLAIN_MESSAGE); String descri=Adminfrm.jTextArea.getText(); if(descri.trim().equals(null)){ //do nothing } else{ count++; descri=descri+"罚款一元"; interFace.edit("insert into dirty_info values('"+ count+"','"+s+"','"+descri+"') "); JOptionPane.showMessageDialog(null,descri,"提示!",JOptionPane.PLAIN_MESSAGE); } } catch(Exception e ){ e.printStackTrace(); } } public int user_num(){ interFace s = new interFace(); String temp = "select * from user_info " ; s.search(temp); int i1 = 0; try { while (s.C.next()) { i1++; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return i1; } public static int sum_borrow(){ int count=0; try{ String sql1="select max(borrow_id) from borrow_info"; rs=null; rs=B.executeQuery(sql1); while(rs.next()){ count= Integer.parseInt(rs.getString(1)); } } catch (Exception e ){ e.printStackTrace(); } count++; return count; } public static void edit(String command) { interFace s=new interFace (); s.C=s.search(command); return; } public static void book_inquire(Object [] [] data,String string1,String sql){ try{ rs=null; rs=B.executeQuery(sql); int i=0; initialize(data,30,9); while(rs.next()){ s1=rs.getString("book_id"); data[i][0]=s1; s2=rs.getString("book_name");data[i][1]=s2; s3=rs.getString("book_price").trim(); data[i][2] =s3; s4=rs.getString("book_publishing").trim();data[i][3]=s4; s5=rs.getString("book_author").trim();data[i][4]=s5; s6=rs.getString("book_date").trim();data[i][5]=s6; s7=rs.getString("book_num").trim();data[i][6]=s7; s8=rs.getString("book_num_in").trim();data[i][7]=s8; s9=rs.getString("lib_name");data[i][8]=s9; i++; } } catch(Exception e ){ e.printStackTrace(); } } public static String[][] doSearch(String command, String[] colName) { interFace s = new interFace(); String temp = command; s.C = s.search(temp); int col = colName.length, i = 0; s.rec = new String[100][col]; try { while (s.C.next()) { for (int j = 1; j 0)||(count==0&¬request(s) )){ String date; sql="select borrow_reborrow,return_date from borrow_info where borrow_bid='"+b_id+"' and borrow_uid='"+u_id+"'"; rs=B.executeQuery(sql); if(rs.next()){ if (rs.getString(1).trim().equals("否")){ //System.out.println(rs.getString(1)); date=rs.getString("return_date"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date d=sdf.parse(date); System.out.println(d.toString()); /*String date=Integer.toString(cal.get(Calendar.YEAR))+"-"+ Integer.toString(cal.get(Calendar.MONTH))+"-"+ Integer.toString(cal.get(Calendar.DATE));*/ Calendar cal = new GregorianCalendar(); cal.setTime(d); String d1=Integer.toString(cal.get(Calendar.YEAR))+"-"+ Integer.toString(cal.get(Calendar.MONTH)+2)+"-"+ Integer.toString(cal.get(Calendar.DATE)); //System.out.println(d.getYear()+" "+d.getDay()); System.out.println(d1); sql="update borrow_info set borrow_reborrow= '是' , return_date='"+d1+"' where borrow_bid='"+b_id+"' and borrow_uid='"+u_id+"'"; System.out.println(sql); interFace.edit(sql); JOptionPane.showMessageDialog(null,"续借成功","提示!",JOptionPane.PLAIN_MESSAGE); } else JOptionPane.showMessageDialog(null,"已经续借,不得续借","提示!",JOptionPane.PLAIN_MESSAGE); } } else{ JOptionPane.showMessageDialog(null,"不得续借"+count + notrequest(s),"提示!",JOptionPane.PLAIN_MESSAGE); } }catch(Exception e){ e.printStackTrace(); } } @SuppressWarnings("static-access") public static void book_borrow(String b_id,int u_id){ interFace s=new interFace(); String sql="select count(*)from request_info where (request_finished='否' and request_uid'"+u_id+"' and " + " request_description in (select book_info.book_name " + "from book_info where book_id='"+b_id+"'))"; try{ rs=null;int count=0;int count1=0; rs=B.executeQuery(sql); if(rs.next()){ count=rs.getInt(1); rs=B.executeQuery("select book_num_in from book_info where book_id='"+b_id+"'"); if(rs.next()) count1=Integer.parseInt(rs.getString(1)); if(count>=count1||count1==0){System.out.println(count + " "+count1); JOptionPane.showMessageDialog(null,"全部书被预约或部借出","提示!",JOptionPane.PLAIN_MESSAGE); } else{ sql="update request_info set request_finished='是' where (request_uid='"+u_id+"' and " + "request_info.request_description=(select book_info.book_name " + "from book_info where book_id='"+b_id+"'))"; s.edit(sql); Calendar cal=Calendar.getInstance(); String date=Integer.toString(cal.get(Calendar.YEAR))+"-"+ Integer.toString(cal.get(Calendar.MONTH)+1)+"-"+ Integer.toString(cal.get(Calendar.DATE)); cal.add(Calendar.DATE, 30); String date1=Integer.toString(cal.get(Calendar.YEAR))+"-"+ Integer.toString(cal.get(Calendar.MONTH)+1)+"-"+ Integer.toString(cal.get(Calendar.DATE)); int num=s.sum_borrow(); sql="insert into borrow_info values('"+num+"','"+u_id+"','"+b_id+"','"+date+"','否','否','"+date1+"')"; s.edit(sql); sql="update book_info set book_info.book_num_in=book_info.book_num_in-1 " + "where book_id='"+b_id+"'"; s.edit(sql); JOptionPane.showMessageDialog(null,"成功借出","提示!",JOptionPane.PLAIN_MESSAGE); } } } catch (Exception e){ e.printStackTrace(); } } 课程设计 图书馆管理信息系统 #039;" + " and " + "user_purview='" + purview + "'"; s.search(temp); int i = 0; try { while (s.C.next()) { i++; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return i; } public static void update_book_number(String s4){ String sql="update book_info set book_num_in=book_num_in+1 where book_info.book_id='"+s4+"'"; try{ interFace.edit(sql); }catch(Exception e){ e.printStackTrace(); } } public static int book_num_in(String s){ String sql="select book_num_in from book_info where book_name= '"+s+"'"; int count=0; try{ rs=B.executeQuery(sql); if(rs.next()){ count=Integer.parseInt(rs.getString(1)); } } catch(Exception e){ e.printStackTrace(); } return count; } public static void day_number(String s1,String s2,int s3){ float days=0;String s=null; int mum=0; try{ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); s = df.format(new Date()); String date=s1; Date d1 = df.parse(s); Date d2 = df.parse(date); long diff = d1.getTime() - d2.getTime(); days= diff / (1000 * 60 * 60 * 24); }catch(Exception e){ e.printStackTrace(); }System.out.println(days); days=days-30; if(s2.equals("是")){ days=days-30; } if(days>0){ days=days/10;} else{ days=0; } if(days>0){ write_dirty(s3,days);//写入不良信息 } try{//把borrow 中的borrow_returned 将return 改成"是" String ss="是"; String sql="update borrow_info set borrow_returned='"+ss+ "' , borrow_info.return_date= '"+s+"'where borrow_info.borrow_id='"+s3+"'"; interFace.edit(sql); }catch(Exception e ){ e.printStackTrace(); } } public static void write_dirty(int s,float days){ try{ int count=0; rs=B.executeQuery("select count(*) from dirty_info "); if(rs.next()) count=Integer.parseInt(rs.getString(1)); count++; String des="过期"+days*10+"天,罚款"+days+"元"; interFace.edit("insert into dirty_info values('"+ count+"','"+s+"','"+des+"') "); JOptionPane.showMessageDialog(null,des,"提示!",JOptionPane.PLAIN_MESSAGE); String descri=Adminfrm.jTextArea.getText(); if(descri.trim().equals(null)){ //do nothing } else{ count++; descri=descri+"罚款一元"; interFace.edit("insert into dirty_info values('"+ count+"','"+s+"','"+descri+"') "); JOptionPane.showMessageDialog(null,descri,"提示!",JOptionPane.PLAIN_MESSAGE); } } catch(Exception e ){ e.printStackTrace(); } } public int user_num(){ interFace s = new interFace(); String temp = "select * from user_info " ; s.search(temp); int i1 = 0; try { while (s.C.next()) { i1++; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return i1; } public static int sum_borrow(){ int count=0; try{ String sql1="select max(borrow_id) from borrow_info"; rs=null; rs=B.executeQuery(sql1); while(rs.next()){ count= Integer.parseInt(rs.getString(1)); } } catch (Exception e ){ e.printStackTrace(); } count++; return count; } public static void edit(String command) { interFace s=new interFace (); s.C=s.search(command); return; } public static void book_inquire(Object [] [] data,String string1,String sql){ try{ rs=null; rs=B.executeQuery(sql); int i=0; initialize(data,30,9); while(rs.next()){ s1=rs.getString("book_id"); data[i][0]=s1; s2=rs.getString("book_name");data[i][1]=s2; s3=rs.getString("book_price").trim(); data[i][2] =s3; s4=rs.getString("book_publishing").trim();data[i][3]=s4; s5=rs.getString("book_author").trim();data[i][4]=s5; s6=rs.getString("book_date").trim();data[i][5]=s6; s7=rs.getString("book_num").trim();data[i][6]=s7; s8=rs.getString("book_num_in").trim();data[i][7]=s8; s9=rs.getString("lib_name");data[i][8]=s9; i++; } } catch(Exception e ){ e.printStackTrace(); } } public static String[][] doSearch(String command, String[] colName) { interFace s = new interFace(); String temp = command; s.C = s.search(temp); int col = colName.length, i = 0; s.rec = new String[100][col]; try { while (s.C.next()) { for (int j = 1; j 0)||(count==0&¬request(s) )){ String date; sql="select borrow_reborrow,return_date from borrow_info where borrow_bid='"+b_id+"' and borrow_uid='"+u_id+"'"; rs=B.executeQuery(sql); if(rs.next()){ if (rs.getString(1).trim().equals("否")){ //System.out.println(rs.getString(1)); date=rs.getString("return_date"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date d=sdf.parse(date); System.out.println(d.toString()); /*String date=Integer.toString(cal.get(Calendar.YEAR))+"-"+ Integer.toString(cal.get(Calendar.MONTH))+"-"+ Integer.toString(cal.get(Calendar.DATE));*/ Calendar cal = new GregorianCalendar(); cal.setTime(d); String d1=Integer.toString(cal.get(Calendar.YEAR))+"-"+ Integer.toString(cal.get(Calendar.MONTH)+2)+"-"+ Integer.toString(cal.get(Calendar.DATE)); //System.out.println(d.getYear()+" "+d.getDay()); System.out.println(d1); sql="update borrow_info set borrow_reborrow= '是' , return_date='"+d1+"' where borrow_bid='"+b_id+"' and borrow_uid='"+u_id+"'"; System.out.println(sql); interFace.edit(sql); JOptionPane.showMessageDialog(null,"续借成功","提示!",JOptionPane.PLAIN_MESSAGE); } else JOptionPane.showMessageDialog(null,"已经续借,不得续借","提示!",JOptionPane.PLAIN_MESSAGE); } } else{ JOptionPane.showMessageDialog(null,"不得续借"+count + notrequest(s),"提示!",JOptionPane.PLAIN_MESSAGE); } }catch(Exception e){ e.printStackTrace(); } } @SuppressWarnings("static-access") public static void book_borrow(String b_id,int u_id){ interFace s=new interFace(); String sql="select count(*)from request_info where (request_finished='否' and request_uid'"+u_id+"' and " + " request_description in (select book_info.book_name " + "from book_info where book_id='"+b_id+"'))"; try{ rs=null;int count=0;int count1=0; rs=B.executeQuery(sql); if(rs.next()){ count=rs.getInt(1); rs=B.executeQuery("select book_num_in from book_info where book_id='"+b_id+"'"); if(rs.next()) count1=Integer.parseInt(rs.getString(1)); if(count>=count1||count1==0){System.out.println(count + " "+count1); JOptionPane.showMessageDialog(null,"全部书被预约或部借出","提示!",JOptionPane.PLAIN_MESSAGE); } else{ sql="update request_info set request_finished='是' where (request_uid='"+u_id+"' and " + "request_info.request_description=(select book_info.book_name " + "from book_info where book_id='"+b_id+"'))"; s.edit(sql); Calendar cal=Calendar.getInstance(); String date=Integer.toString(cal.get(Calendar.YEAR))+"-"+ Integer.toString(cal.get(Calendar.MONTH)+1)+"-"+ Integer.toString(cal.get(Calendar.DATE)); cal.add(Calendar.DATE, 30); String date1=Integer.toString(cal.get(Calendar.YEAR))+"-"+ Integer.toString(cal.get(Calendar.MONTH)+1)+"-"+ Integer.toString(cal.get(Calendar.DATE)); int num=s.sum_borrow(); sql="insert into borrow_info values('"+num+"','"+u_id+"','"+b_id+"','"+date+"','否','否','"+date1+"')"; s.edit(sql); sql="update book_info set book_info.book_num_in=book_info.book_num_in-1 " + "where book_id='"+b_id+"'"; s.edit(sql); JOptionPane.showMessageDialog(null,"成功借出","提示!",JOptionPane.PLAIN_MESSAGE); } } } catch (Exception e){ e.printStackTrace(); } } 课程设计 图书馆管理信息系统
用户评论