📄 reader.java
字号:
package booksys;
import java.sql.*;
import java.util.*;
import java.util.Date;
import java.io.*;
import java.text.*;
public class reader extends users{
String userid;
int id;
int bookid;
String bookstatus;
Date bookdate;
public final int limitcount=2;
static Vector v = new Vector();
static reader read1;
public reader(){
id = 0;
this.userid = "";
this.bookid = 0;
this.bookstatus ="";
this.bookdate =new Date();
}
public reader(int id,String userid,int bookid,String bookstatus,Date bookdate){
this.id = id;
this.userid = userid;
this.bookid = bookid;
this.bookdate = bookdate;
this.bookstatus = bookstatus;
}
public static int getid() throws Exception{
int count = 0;
dbconn.conn();
String sql = "select * from readers";
ResultSet rs=dbconn.dbquery(sql);
while(rs.next()){
count=rs.getInt(1);
}
return count+1;
}
public int getbookid(){
return bookid;
}
public static reader getreader(int bookid,String userid) throws Exception{
reader r1 = new reader();
dbconn.conn();
String sql = "select * from readers where bookid="+bookid+" and userid='"+userid+"'";
ResultSet rs=dbconn.dbquery(sql);
while(rs.next()){
r1 = new reader(rs.getInt(1),rs.getString(2),rs.getInt(3),rs.getString(4),rs.getDate(5));
}
return r1;
}
public int getreadid(){
return this.id;
}
public Date getbookdate(){
return bookdate;
}
public String getbookstatus(){
return bookstatus;
}
public void welcome() throws Exception{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
reader reader1=new reader();
reader1.remenu();
String reselect = in.readLine();
if(reselect.equals("1")){
System.out.println(reader1);
System.out.print("请输入书名:");
String booknm = in.readLine();
}
if(reselect.equals("4")){
System.exit(0);
}
}
public String toString(){
String s="ddd";
if(this.getbookid()==0){
s="\n所借书籍: 无";
}
else{
try{
s="";
for(int i=0;i<v.size();i++){
reader r = (reader)v.elementAt(i);
s+="\n所借书籍1:"+books.searchbook(r.getbookid()).trim()+"\n状态:"+r.getbookstatus().trim()+"\n借书时间:"+DateFormat.getDateInstance(DateFormat.SHORT).format(r.getbookdate());
}
}catch(Exception e){
}
}
return s;
}
public boolean change(){
return true;
}
public void check(){
}
public void browsebook() throws Exception{
books b1 = new books();
b1.browse("");
}
private void remenu(){
System.out.println("1、查书 2、预订 3、取消预订 4、退出");
System.out.println("");
}
/**按用户名查询读者,返回读者对象,使用了用户对象,读者对象*/
public static reader selectreader(String userid) throws Exception{
//users user1 = users.selectuser(userid);
//System.out.println(user1);
read1=new reader();
v.clear();
dbconn.conn();
String sql = "select * from readers where userid='"+userid+"'";
ResultSet rs = dbconn.dbquery(sql);
while(rs.next()){
read1=new reader(rs.getInt(1),rs.getString(2),rs.getInt(3),rs.getString(4),rs.getDate(5));
v.addElement(read1);
}
dbconn.dbclose();
return read1;
}
public static Vector searchreader(String userid) throws Exception{
read1=new reader();
v.clear();
dbconn.conn();
String sql = "select * from readers where userid='"+userid+"'";
ResultSet rs = dbconn.dbquery(sql);
while(rs.next()){
read1=new reader(rs.getInt(1),rs.getString(2),rs.getInt(3),rs.getString(4),rs.getDate(5));
v.addElement(read1);
}
dbconn.dbclose();
return v;
}
public boolean insert() throws Exception{
boolean b = false;
dbconn.conn();
String sql = "insert into readers values("+id+",'"+userid+"',"+bookid+",'"+bookstatus+"','"+bookdate.toLocaleString()+"')";
int count = dbconn.dbinsert(sql);
dbconn.dbclose();
if(count>0) b=true;
return b;
}
public boolean delete(int id) throws Exception{
boolean b = false;
dbconn.conn();
String sql = "delete from readers where id="+id;
int count = dbconn.dbupdate(sql);
dbconn.dbclose();
if(count>0) b=true;
return b;
}
public static boolean checkborrow(String userid,int bookid) throws Exception{
boolean b = false;
dbconn.conn();
String sql = "select * from readers where userid='"+userid+"' and bookid="+bookid;
ResultSet rs = dbconn.dbquery(sql);
b=rs.next();
dbconn.dbclose();
return b;
}
public int checkborrow(String userid) throws Exception{
int count = 0;
dbconn.conn();
String sql = "select count(*) from readers where userid='"+userid+"'";
ResultSet rs = dbconn.dbquery(sql);
if(rs.next()){
count = rs.getInt(1);
}
dbconn.dbclose();
return count;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -