package xzt.rs.board;
import com.capitalnet.oa.db.*;
import com.content.util.*;
import com.content.model.*;
import java.util.*;
import java.sql.*;
import java.sql.Date;
/**
公告栏发布模型
*/
public class CallBoard {
/** DATABASE QUERIES 数据库查询 **/
private static final String LOAD_MAX =
"SELECT max(Universalid) FROM T_CALLBOARD";
private static final String LOAD_DATA_BY_ID =
"SELECT * FROM T_CALLBOARD WHERE Universalid=?";
private static final String INSERT_DATA =
"INSERT INTO T_CALLBOARD(Universalid,title,content,delStatus,auditingStatus,auditingUserId,addUserId,AttachFiles) VALUES(?,?,?,?,?,?,?,?)";
private static final String SAVE_DATA =
"UPDATE T_CALLBOARD set title=?, content=?, delStatus=?, auditingStatus=?, auditingUserId=?, addUserId=?,AttachFiles=? WHERE Universalid=?";
private static final String DELETE_PERMISSIONS =
"DELETE FROM T_CALLBOARD WHERE Universalid=?";
private int id;
private String title;
private String content;
private String delStatus;
private String auditingStatus;
private String auditingUserId;
private String addUserId;
private String addDatetime;
private String AttachFiles;
public CallBoard() {
}
public int getId() {
return this.id;
}
public void setId(int s1) {
this.id=s1;
}
public String getTitle(){
return this.title;
}
public void setTitle(String s1){
this.title=s1;
}
public String getContent(){
return this.content;
}
public void setContent(String s1){
this.content=s1;
}
public String getDelStatus(){
return this.delStatus;
}
public void setDelStatus(String s1){
this.delStatus=s1;
}
public String getAuditingStatus(){
return this.auditingStatus;
}
public void setAuditingStatus(String s1){
this.auditingStatus=s1;
}
public String getAuditingUserId(){
return this.auditingUserId;
}
public void setAuditingUserId(String s1){
this.auditingUserId=s1;
}
public String getAddUserId(){
return this.addUserId;
}
public void setAddUserId(String s1){
this.addUserId=s1;
}
public String getAddDatetime(){
return this.addDatetime;
}
public void setAddDatetime(String s1){
this.addDatetime=s1;
}
public String getAttachFiles() {
return this.AttachFiles;
}
public void setAttachFiles(String s1) {
this.AttachFiles=s1;
}
public Date stringToDate(String dateString){
StringTokenizer dateTok=new StringTokenizer(dateString ,"-");
int year=Integer.parseInt(dateTok.nextToken());
int month=Integer.parseInt(dateTok.nextToken())-1;
int day=Integer.parseInt(dateTok.nextToken());
return new java.sql.Date(new GregorianCalendar(year,month,day).getTime().getTime());
}
/**
* Load the data from the database.从数据库中提取数据
*/
public void loadFromDb() throws UserNotFoundException {
String query;
Connection con = null;
PreparedStatement pstmt = null;
try {
con = ConnectionPool.getConnection();
ConnectionProxy conProxy =new ConnectionProxy(con,true);
con = conProxy.getConnection();
query=LOAD_DATA_BY_ID;
pstmt = con.prepareStatement(query);
pstmt.setInt(1, id);
ResultSet rs = pstmt.executeQuery();
if (!rs.next()) {
throw new UserNotFoundException(
"Failed to read menu " + id + " from database."
);
}
this.id = rs.getInt("Universalid");
this.title=rs.getString("title");
this.content=rs.getString("content");
this.delStatus=rs.getString("delStatus");
this.auditingStatus=rs.getString("auditingStatus");
this.auditingUserId=rs.getString("auditingUserId");
this.addUserId=rs.getString("addUserId");
this.addDatetime=rs.getString("addDatetime");
this.AttachFiles=rs.getString("AttachFiles");
//this.attachFiles = rs.getString("AttachFiles");
}
catch( SQLException sqle ) {
throw new UserNotFoundException(
"Failed to read user " + id + " from database.", sqle
);
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
}
/**
* Inserts a new user record into the database.插入一个新的用户记录在数据库中
*/
public void insertIntoDb() {
Connection con = null;
PreparedStatement pstmt = null;
Statement smt=null;
ResultSet rs=null;
try {
con = ConnectionPool.getConnection();
ConnectionProxy conProxy =new ConnectionProxy(con,true);
con = conProxy.getConnection();
con.setAutoCommit(true);
smt=con.createStatement();
rs=smt.executeQuery(LOAD_MAX);
if(rs.next()){
this.id=rs.getInt(1)+1;
}
rs.close();
smt.close();
pstmt = con.prepareStatement(INSERT_DATA);
pstmt.setInt(1, id);
pstmt.setString(2,title);
pstmt.setString(3,content);
pstmt.setString(4,delStatus);
pstmt.setString(5,auditingStatus);
pstmt.setString(6,auditingUserId);
pstmt.setString(7,addUserId);
pstmt.setString(8,AttachFiles);
pstmt.executeUpdate();
}
catch( SQLException sqle ) {
System.err.println("Error in Menu:insertIntoDb()-" + sqle);
sqle.printStackTrace();
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
}
/**
* Save the user data to the database.保存用户数据到数据库
*/
public void saveToDb() {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = ConnectionPool.getConnection();
ConnectionProxy conProxy =new ConnectionProxy(con,true);
con = conProxy.getConnection();
con.setAutoCommit(true);
pstmt = con.prepareStatement(SAVE_DATA);
pstmt.setString(1,this.title);
pstmt.setString(2,this.content);
pstmt.setString(3,this.delStatus);
pstmt.setString(4,this.auditingStatus);
pstmt.setString(5,this.auditingUserId);
pstmt.setString(6,this.addUserId);
pstmt.setString(7,this.AttachFiles);
pstmt.setInt(8, id);
pstmt.executeUpdate();
}
catch( SQLException sqle ) {
System.err.println( "SQLException in Menu.java:saveToDb(): " + sqle +"你好");
sqle.printStackTrace();
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
}
}