www.pudn.com > liberSystem.rar > BookAction.java, change:2012-06-06,size:3489b


package com.ccl.action; 
 
import java.sql.Connection; 
import java.sql.Date; 
import java.util.List; 
 
import org.apache.struts2.ServletActionContext; 
 
import com.ccl.domin.Barcode; 
import com.ccl.domin.Book; 
import com.ccl.domin.Operator; 
import com.ccl.service.BookService; 
import com.ccl.util.ConnectionFactory; 
import com.ccl.util.ConnectionUtil; 
import com.ccl.util.JdbcUtil; 
import com.ccl.util.PublicUtil; 
import com.opensymphony.xwork2.ActionSupport; 
 
public class BookAction extends ActionSupport { 
	private static BookService bookService=new BookService(); 
	private int id; 
	private String bookName; 
	private String author; 
	private String publisher; 
	private float price; 
	private int type;	//外键,booktypeid 
	private int count; 
	private String key; 
	private int keytype; 
	public String bookQueryByKey(){ 
		Connection conn=ConnectionFactory.getConnection(); 
		StringBuilder sb=new StringBuilder("select * from book_t where"); 
		if(type!=0) 
			sb.append(" type =").append(type); 
		if(keytype==0) 
		{ 
			if(type!=0) 
				sb.append(" and"); 
		sb.append(" bookName like '%").append(key).append("%'");	 
		}else if(keytype==1) 
			sb.append(" author like '%").append(key).append("%'"); 
		List<Object> books=JdbcUtil.queryList(new Book(), sb.toString(), conn); 
		ServletActionContext.getRequest().setAttribute("books", books); 
		ConnectionUtil.close(conn); 
		return SUCCESS; 
	} 
	public String book_add(){ 
		Operator o= (Operator) ServletActionContext.getRequest().getSession().getAttribute("user"); 
		Book book=new Book(); 
		book.setAuthor(author); 
		book.setBookName(bookName); 
		book.setInTime(new Date(System.currentTimeMillis())); 
		book.setOperator(o.getId()); 
		book.setPublisher(publisher); 
		book.setType(type); 
		book.setPrice(price); 
		bookService.book_add(book); 
		int bookid=PublicUtil.getLastID("book_t"); 
		for(int i=0;i<count;i++) 
		{ 
			Barcode b=new Barcode(); 
			b.setBookid(bookid); 
			b.setBarcode(PublicUtil.createBarcode(type+"",bookid, i)); 
			bookService.insert(b); 
		} 
		return SUCCESS; 
	} 
	 
	public String book_del(){ 
		bookService.book_del(id); 
		return SUCCESS; 
	} 
	public String book_update(){ 
		Book b=new Book(); 
		b.setAuthor(author); 
		b.setBookName(bookName); 
		b.setId(id); 
		b.setPrice(price); 
		b.setPublisher(publisher); 
		b.setType(type); 
		bookService.book_update(b); 
		return SUCCESS; 
	} 
 
	public int getId() { 
		return id; 
	} 
 
	public void setId(int id) { 
		this.id = id; 
	} 
 
	public String getBookName() { 
		return bookName; 
	} 
 
	public void setBookName(String bookName) { 
		this.bookName = bookName; 
	} 
 
	public String getAuthor() { 
		return author; 
	} 
 
	public void setAuthor(String author) { 
		this.author = author; 
	} 
 
	public String getPublisher() { 
		return publisher; 
	} 
 
	public void setPublisher(String publisher) { 
		this.publisher = publisher; 
	} 
 
	public float getPrice() { 
		return price; 
	} 
 
	public void setPrice(float price) { 
		this.price = price; 
	} 
 
	public int getType() { 
		return type; 
	} 
 
	public void setType(int type) { 
		this.type = type; 
	} 
 
	public int getCount() { 
		return count; 
	} 
 
	public void setCount(int count) { 
		this.count = count; 
	} 
	public String getKey() { 
		return key; 
	} 
	public void setKey(String key) { 
		this.key = key; 
	} 
	public int getKeytype() { 
		return keytype; 
	} 
	public void setKeytype(int keytype) { 
		this.keytype = keytype; 
	} 
 
}