📄 dbdepartment.java
字号:
/**
* Copyright (c) 2002 CODEFAD.com
* All right reserved.
*
* Description: ....
*
* Author: Chu Daping 2002-5-12 16:49
*
*/
package com.codefad.easyoffice.db;
import java.sql.*;
import java.util.*;
import java.util.Date;
import java.util.ArrayList;
import com.codefad.easyoffice.*;
import com.codefad.easyoffice.db.*;
public class DbDepartment implements Department {
private static final String DELETE_CALLBOARD =
"DELETE FROM notice WHERE noticeID=?";
private static final String LOAD_DEPT =
"SELECT * FROM dept WHERE deptID=?";
private static final String ALL_USERS =
"SELECT * FROM userinf WHERE deptID=?";
private long id = -1;
protected long stationID = -1;
protected String deptname = null;
protected String deptmemo = null;
private boolean isReadyToSave = false;
private java.util.Date createdate = null;
public DbDepartment(long id)
{
this.id = id;
loadFromDb();
isReadyToSave = true;
}
public long getDeptID() {
return id;
}
public long getStationID() {
return stationID;
}
public void setDeptName(String deptname) {
this.deptname = deptname;
isReadyToSave = true;
try { saveToDb();}
catch (SQLException e) {}
}
public String getDeptName() {
return deptname;
}
public java.util.Date getCreateDate() {
return createdate;
}
public void setCreateDate(java.util.Date createdate)
{
this.createdate = createdate;
isReadyToSave=true ;
try { saveToDb();}
catch (SQLException e) {}
}
public String getDeptMemo() {
return deptmemo;
}
public void setDeptMemo(String memo) {
this.deptmemo = memo;
isReadyToSave = true;
try { saveToDb();}
catch (SQLException e) {}
}
public Scheme getScheme(long schemeID) {
Scheme scheme = new DbScheme(schemeID);
return scheme;
}
public Scheme getScheme(String objdate) {
Scheme scheme = new DbScheme(objdate);
return scheme;
}
public ArrayList schemes() {
Connection con = new SqlCon().getConnection();
PreparedStatement stmt = null;
ArrayList schemes = new ArrayList();
String sql = "select * from jihua where deptID=? order by schemeID DESC";
try {
stmt = con.prepareStatement(sql);
stmt.setLong(1,id);
ResultSet rs = stmt.executeQuery();
long schemeID = -1;
while (rs.next())
{
schemeID = rs.getLong("schemeID");
schemes.add(getScheme(schemeID));
}
rs.close();
stmt.close();
con.close();
}
catch (SQLException sqle) {
sqle.printStackTrace();
}
return schemes;
}
public Callboard getCallboard(long boardID) {
Callboard callboard = new DbCallboard(boardID);
return callboard;
}
public ArrayList callboards() {
Connection con = new SqlCon().getConnection();
PreparedStatement stmt = null;
ArrayList callboards = new ArrayList();
String sql = "select * from notice where deptID=? order by noticeID DESC";
try {
stmt = con.prepareStatement(sql);
stmt.setLong(1,id);
ResultSet rs = stmt.executeQuery();
long boardID = -1;
while (rs.next())
{
boardID = rs.getLong("noticeID");
callboards.add(getCallboard(boardID));
}
rs.close();
stmt.close();
con.close();
}
catch (SQLException sqle) {
sqle.printStackTrace();
}
return callboards;
}
public User getUser(long userID) {
User user = new DbUser(userID);
return user;
}
public ArrayList users() {
ArrayList users = new ArrayList();
Connection con = new SqlCon().getConnection();
PreparedStatement pstmt = null;
try {
pstmt = con.prepareStatement(ALL_USERS);
pstmt.setLong(1, this.id);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
users.add(rs.getString(1));
}
}
catch( SQLException sqle ) {
sqle.printStackTrace();
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
return users;
}
public InfoStation getInfoStation() {
InfoStation station = new DbInfoStation(this.stationID);
return station;
}
protected void reset() {
try {
loadFromDb();
} catch (Exception e) { }
}
private void loadFromDb() {
Connection con = new SqlCon().getConnection();
PreparedStatement pstmt = null;
ResultSet rs =null;
try {
pstmt = con.prepareStatement(LOAD_DEPT);
pstmt.setLong(1, id);
rs = pstmt.executeQuery();
if (rs.next())
{
stationID = rs.getLong("stationID");
deptname = rs.getString("deptname");
createdate = rs.getDate("createDate");
}
}
catch( SQLException sqle ) {
sqle.printStackTrace();
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
}
private void saveToDb(Connection con) throws SQLException
{
//
}
private synchronized void saveToDb() throws SQLException
{
Connection con = new SqlCon().getConnection();
try {
saveToDb(con);
}
catch (SQLException e) {
}
finally {
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -