⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbevent.java

📁 一套大型Office网络办公系统
💻 JAVA
字号:
/**
* Copyright (c) 2002 CODEFAD.com
* All right reserved.
*
* Description: ....
*
* Author: Chu Daping 2002-5-21 10:39
*
*/

package com.codefad.easyoffice.db;

import java.sql.*;
import java.util.*;
import java.io.*;

import com.codefad.easyoffice.*;

public class DbEvent implements Event {
	
    private static final String LOAD_EVENT_BY_ID =
    "SELECT * FROM jihua WHERE EVENTID=?";
    private static final String LOAD_EVENT_BY_OBJDATE =
        "SELECT * FROM jihua WHERE objdate=?";
    private static final String INSERT_EVENT =
        "INSERT INTO jihua(deptID, stationID, userID, subject, content ," +
        "createdate, objdate) VALUES(?,?,?,?,?,?,?)"; 
    private static final String SAVE_EVENT =
        "UPDATE jiahua SET userID=?, subject=?, content=?, objdate=?, createdate=? WHERE EVENTID=?";
    private static final String DELETE_EVENT =
        "DELETE FROM jihua WHERE EVENTID=?";
    
    
    private long EventID = -1;
    private java.util.Date createdate = null;
    private String subject = null;
    private String body = null;
    private String objdate = null;
    private long userID = -1;

    protected long deptID = -1;
    protected long stationID = -1;
    
    private boolean isReadyToSave = false;
    
    public DbEvent(long stationID, long deptID, long userID, String subject, String content, String objdate)
    {
    	this.stationID = stationID;
    	this.deptID = deptID;
    	this.userID = userID;
    	this.subject= subject;
    	this.body = content;
    	this.objdate= objdate;
    	InsertToDb();
    }
    
    public DbEvent(long id) 
    {
    	this.EventID = id;
        loadFromDbById();
        isReadyToSave = true;
    }
    
    public DbEvent(String objdate) 
    {
    	this.objdate = objdate;
        loadFromDbByObjdate();
        isReadyToSave = true;
    }
    
    private void loadFromDbById() 
    {
        try {
        	Connection con = new SqlCon().getConnection();
            PreparedStatement pstmt = con.prepareStatement(LOAD_EVENT_BY_ID);
            pstmt.setLong(1, EventID);
            ResultSet rs = pstmt.executeQuery();
            if (rs.next())
            {
	            deptID = rs.getLong("deptID");
	            stationID = rs.getLong("stationID");
	            userID = rs.getLong("userID");
	            subject = rs.getString("subject");
	            body = rs.getString("content");
	            createdate = rs.getDate("createdate");
	            objdate = rs.getString("objdate");
            }
            rs.close();
            pstmt.close();
            con.close();
         }
        catch( SQLException sqle ) {
        	System.out.print(sqle.toString());
        }
    }
    
    private void loadFromDbByObjdate() 
    {
        try {
            Connection con = new SqlCon().getConnection();
            PreparedStatement pstmt = con.prepareStatement(LOAD_EVENT_BY_OBJDATE);
            pstmt.setString(1, objdate);
            ResultSet rs = pstmt.executeQuery();
            if (rs.next())
            {
	            EventID = rs.getLong("EventID");
	            deptID = rs.getLong("deptID");
	            stationID = rs.getLong("stationID");
	            userID = rs.getLong("userID");
	            subject = rs.getString("subject");
	            body = rs.getString("content");
	            createdate = rs.getDate("createdate");
            }
            else {
                EventID = -1;
            }
            rs.close();
            pstmt.close();
            con.close();
         }
        catch( SQLException sqle ) {
        	System.out.print(sqle.toString());
        }
    }
    
    public long getID() {
        return EventID;
    }
    
    public String getObjDate() {
    	return objdate;
    }
    
    public void setObjDate(String objdate)
    {
        this.objdate = objdate;
        saveToDb();
    }
    
    public java.util.Date getCreateDate() {
        return createdate;
    }
    
    public void setCreateDate(java.util.Date createdate)
    {
        this.createdate = createdate;
        saveToDb();
    }
    
    public String getSubject() 
    {
        return subject;
    }
    
    public void setSubject(String subject)
    {
        this.subject = subject;
        saveToDb();
    }
    
    public String getBody() {
        return body;
    }
    
    public long getDeptID() {
    	return deptID;
    }
    
    public long getUserID() {
    	return userID;
    }
    
    public Department getDept() {
    	Department dept = new DbDepartment(deptID);
    	return dept;
    }
    
    public void setBody(String body)
    {
        this.body = body; 
        saveToDb();
    }
    
    public User getUser() {
        User user = new DbUser(userID);
        return user;
    }

    
    
	public void InsertToDb()
	{
		Connection con = new SqlCon().getConnection();
		PreparedStatement pstmt = null;
		try {
				pstmt = con.prepareStatement(INSERT_EVENT);
				pstmt.setLong(1, deptID);
				pstmt.setLong(2, stationID);
				pstmt.setLong(3, userID);
				pstmt.setString(4, subject);
				pstmt.setString(5, body);
				pstmt.setString(6, new Timestamp((new java.util.Date()).getTime()).toString());
				pstmt.setString(7, objdate);
				pstmt.executeUpdate();
		} catch (Exception e) {
		}
		finally {
		   try {  pstmt.close();   }
		   catch (Exception e) { e.printStackTrace(); }
		}
	}
    
    private synchronized void saveToDb(Connection con) throws SQLException
    {
    }
    
    private synchronized void saveToDb() {
        boolean abortTransaction = false;
         Connection con = new SqlCon().getConnection();
        try {
            saveToDb(con);
        }
        catch( Exception e ) {
            e.printStackTrace();
            abortTransaction = true;
        }
        finally {
            try {  con.close();   }
            catch (Exception e) {  }
        }
    }
    
    public void deleteEvent() {
    	deleteFromDb();
    }
    
    private synchronized void deleteFromDb() {
        try {
		Connection con = new SqlCon().getConnection();
            	PreparedStatement pstmt = con.prepareStatement(DELETE_EVENT);
				pstmt.setLong(1, EventID);
				pstmt.executeUpdate();
				pstmt.close();
				con.close();
		} catch (Exception e) {
		}
    }
}

    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -