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

📄 attachment.java

📁 oa 源码
💻 JAVA
字号:
package com.redmoon.oa.flow;import java.io.*;import java.sql.*;import cn.js.fan.db.*;import cn.js.fan.web.*;import org.apache.log4j.*;public class Attachment implements java.io.Serializable {    int id;    int docId;    String name;    String fullPath;    String diskName;    String visualPath;    String connname;    String INSERT = "insert into flow_document_attach (doc_id, name, fullpath, diskname, visualpath, orders, page_num, field_name) values (?,?,?,?,?,?,?,?)";    String LOAD = "SELECT doc_id, name, fullpath, diskname, visualpath, orders, page_num, field_name FROM flow_document_attach WHERE id=?";    String SAVE = "update flow_document_attach set doc_id=?, name=?, fullpath=?, diskname=?, visualpath=?, orders=?, page_num=?, field_name=? WHERE id=?";    Logger logger = Logger.getLogger(Attachment.class.getName());    public Attachment() {        connname = Global.defaultDB;        if (connname.equals(""))            logger.info("Attachment:默认数据库名为空!");    }    public Attachment(int id) {        connname = Global.defaultDB;        if (connname.equals(""))            logger.info("Attachment:默认数据库名为空!");        this.id = id;        loadFromDb();    }    public Attachment(int orders, int docId, int pageNum) {        connname = Global.defaultDB;        if (connname.equals(""))            logger.info("Attachment:默认数据库名为空!");        this.orders = orders;        this.docId = docId;        this.pageNum = pageNum;        loadFromDbByOrders();    }    public boolean del() {        String sql = "delete from flow_document_attach where id=?";        Conn conn = new Conn(connname);        boolean re = false;        try {            PreparedStatement pstmt = conn.prepareStatement(sql);            pstmt.setInt(1, id);            re = conn.executePreUpdate()==1?true:false;            pstmt.close();                        sql = "update flow_document_attach set orders=orders-1 where doc_id=? and page_num=? and orders>?";            pstmt = conn.prepareStatement(sql);            pstmt.setInt(1, docId);            pstmt.setInt(2, pageNum);            pstmt.setInt(3, orders);            conn.executePreUpdate();        }        catch (SQLException e) {            logger.error("del:" + e.getMessage());            return false;        }        finally {            if (conn!=null) {                conn.close();                conn = null;            }        }                File fl = new File(this.fullPath);        fl.delete();        return re;    }    public boolean save() {        Conn conn = new Conn(connname);        boolean re = false;        try {            PreparedStatement pstmt = conn.prepareStatement(SAVE);            pstmt.setInt(1, docId);            pstmt.setString(2, name);            pstmt.setString(3, fullPath);            pstmt.setString(4, diskName);            pstmt.setString(5, visualPath);            pstmt.setInt(6, orders);            pstmt.setInt(7, pageNum);            pstmt.setString(8, fieldName);            pstmt.setInt(9, id);            re = conn.executePreUpdate()==1?true:false;        }        catch (SQLException e) {            logger.error(e.getMessage());        }        finally {            if (conn!=null) {                conn.close(); conn = null;            }        }        return re;    }    public int getId() {        return this.id;    }    public void setId(int id) {        this.id = id;    }    public int getDocId() {        return this.docId;    }    public void setDocId(int di) {        this.docId = di;    }    public String getName() {        return this.name;    }    public void setName(String name) {        this.name = name;    }    public String getDiskName() {        return this.diskName;    }    public void setDiskName(String dn) {        this.diskName = dn;    }    public String getFullPath() {        return this.fullPath;    }    public void setFullPath(String f) {        this.fullPath = f;    }    public String getVisualPath() {        return this.visualPath;    }    public int getOrders() {        return orders;    }    public int getPageNum() {        return pageNum;    }    public boolean isLoaded() {        return loaded;    }    public String getFieldName() {        return fieldName;    }    public void setVisualPath(String vp) {        this.visualPath = vp;    }    public void setOrders(int orders) {        this.orders = orders;    }    public void setPageNum(int pageNum) {        this.pageNum = pageNum;    }    public void setLoaded(boolean loaded) {        this.loaded = loaded;    }    public void setFieldName(String fieldName) {        this.fieldName = fieldName;    }    public boolean create() {                  boolean re = false;         PreparedStatement pstmt = null;         ResultSet rs = null;         Conn conn = new Conn(connname);         try {             pstmt = conn.prepareStatement(INSERT);             pstmt.setInt(1, docId);             pstmt.setString(2, name);             pstmt.setString(3, fullPath);             pstmt.setString(4, diskName);             pstmt.setString(5, visualPath);             pstmt.setInt(6, orders);             pstmt.setInt(7, pageNum);             pstmt.setString(8, fieldName);             re = conn.executePreUpdate()==1;         } catch (SQLException e) {             logger.error("create:" + e.getMessage());         } finally {             if (rs != null) {                 try {                     rs.close();                 } catch (Exception e) {}                 rs = null;             }             if (pstmt != null) {                 try {                     pstmt.close();                 } catch (Exception e) {}                 pstmt = null;             }             if (conn != null) {                 conn.close();                 conn = null;             }         }         return re;    }    public void loadFromDb() {        Conn conn = new Conn(connname);        PreparedStatement pstmt = null;        ResultSet rs = null;        try {            pstmt = conn.prepareStatement(LOAD);            pstmt.setInt(1, id);                        rs = conn.executePreQuery();            if (rs != null && rs.next()) {                docId = rs.getInt(1);                name = rs.getString(2);                                fullPath = rs.getString(3);                                diskName = rs.getString(4);                visualPath = rs.getString(5);                orders = rs.getInt(6);                pageNum = rs.getInt(7);                fieldName = rs.getString(8);                loaded = true;            }        } catch (SQLException e) {            logger.error(e.getMessage());        } finally {            if (rs != null) {                try {                    rs.close();                } catch (Exception e) {}                rs = null;            }            if (conn != null) {                conn.close();                conn = null;            }        }    }    public void loadFromDbByOrders() {        Conn conn = new Conn(connname);        PreparedStatement pstmt = null;        ResultSet rs = null;        try {            String LOADBYORDERS = "SELECT id, name, fullpath, diskname, visualpath, field_name FROM flow_document_attach WHERE orders=? and doc_id=? and page_num=?";            pstmt = conn.prepareStatement(LOADBYORDERS);            pstmt.setInt(1, orders);            pstmt.setInt(2, docId);            pstmt.setInt(3, pageNum);            rs = conn.executePreQuery();            if (rs != null && rs.next()) {                id = rs.getInt(1);                name = rs.getString(2);                fullPath = rs.getString(3);                diskName = rs.getString(4);                visualPath = rs.getString(5);                fieldName = rs.getString(6);                loaded = true;            }        } catch (SQLException e) {            logger.error(e.getMessage());        } finally {            if (rs != null) {                try {                    rs.close();                } catch (Exception e) {}                rs = null;            }            if (conn != null) {                conn.close();                conn = null;            }        }    }    private int orders = 0;    private int pageNum;    private boolean loaded = false;        private String fieldName;}

⌨️ 快捷键说明

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