addressdb.java

来自「一个用java编写的功能强大的OA系统」· Java 代码 · 共 646 行 · 第 1/2 页

JAVA
646
字号
package com.redmoon.oa.address;import java.sql.*;import java.util.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import com.redmoon.oa.db.*;public class AddressDb extends ObjectDb {    private int id;    public static final int TYPE_PUBLIC = 1;    public static final int TYPE_USER = 0;    public AddressDb() {        init();    }    public AddressDb(int id) {        this.id = id;        init();        load();    }    public int getId() {        return id;    }    public String getPerson() {        return person;    }    public String getJob() {        return job;    }    public String getTel() {        return tel;    }    public String getMobile() {        return mobile;    }    public String getEmail() {        return email;    }    public String getPostalcode() {        return postalcode;    }    public String getIntroduction() {        return introduction;    }    public void initDB() {        tableName = "address";        primaryKey = new PrimaryKey("id", PrimaryKey.TYPE_INT);        objectCache = new AddressCache(this);        isInitFromConfigDB = false;                                        QUERY_CREATE =                "insert into " + tableName + " (id,person,firstname, familyname, middleName,job,tel,nickname,fax,mobile,web,companyStreet,companyCity,companyPostcode,companyProvice,companyCountry,operationweb,operationPhone,operationFax,BeepPager,company,email,city,street,address,country,postalcode,province,introduction,userName,department,type,addDate,typeId,qq,msn) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW(),?,?,?)";        QUERY_SAVE = "update " + tableName + " set person=?,firstname=?,familyname=?, middleName=?,job=?,tel=?,nickname=?,fax=?,mobile=?,web=?,companyStreet=?,companyCity=?,companyPostcode=?,companyProvice=?,companyCountry=?,operationweb=?,operationPhone=?,operationFax=?,BeepPager=?,company=?,email=?,city=?,street=?,address=?,country=?,postalcode=?,province=?,introduction=?,userName=?,department=?,type=?,typeId=? ,qq=?,msn=? where id=?";        QUERY_LIST =                "select id from " + tableName + " order by mydate desc";        QUERY_DEL = "delete from " + tableName + " where id=?";        QUERY_LOAD = "select person,firstname, familyname, middleName,job,tel,nickname,fax,mobile,web,companyStreet,companyCity,companyPostcode,companyProvice,companyCountry,operationweb,operationPhone,operationFax,BeepPager,company,email,city,street,address,country,postalcode,province,introduction,userName,department,type,addDate,typeId,qq,msn from " +                     tableName + " where id=?";    }    public AddressDb getAddressDb(int id) {        return (AddressDb) getObjectDb(new Integer(id));    }    public boolean create() throws ErrMsgException {        id = (int) SequenceManager.nextID(SequenceManager.OA_ADDRESS);        Conn conn = new Conn(connname);        boolean re = false;        try {            PreparedStatement ps = conn.prepareStatement(QUERY_CREATE);                                    ps.setInt(1, id);            ps.setString(2, person);            ps.setString(3, firstname);            ps.setString(4, familyname);            ps.setString(5, middleName);            ps.setString(6, job);            ps.setString(7, tel);            ps.setString(8, nickname);            ps.setString(9, fax);            ps.setString(10, mobile);            ps.setString(11, web);            ps.setString(12, companyStreet);            ps.setString(13, companyCity);            ps.setString(14, companyPostcode);            ps.setString(15, companyProvice);            ps.setString(16, companyCountry);            ps.setString(17, operationweb);            ps.setString(18, operationPhone);            ps.setString(19, operationFax);            ps.setString(20, BeepPager);            ps.setString(21, company);            ps.setString(22, email);            ps.setString(23, city);            ps.setString(24, street);            ps.setString(25, address);            ps.setString(26, country);            ps.setString(27, postalcode);            ps.setString(28, province);            ps.setString(29, introduction);            ps.setString(30, userName);            ps.setString(31, department);            ps.setInt(32, type);            ps.setInt(33, typeId);            ps.setString(34, QQ);            ps.setString(35, MSN);            re = conn.executePreUpdate() == 1 ? true : false;            if (re) {                AddressCache rc = new AddressCache(this);                rc.refreshCreate();            }        } catch (SQLException e) {            logger.error("create:" + e.getMessage());            throw new ErrMsgException("数据库操作失败!");        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }        public boolean del() throws ErrMsgException {        Conn conn = new Conn(connname);        boolean re = false;        try {            PreparedStatement ps = conn.prepareStatement(QUERY_DEL);            ps.setInt(1, id);            re = conn.executePreUpdate() == 1 ? true : false;            if (re) {                AddressCache rc = new AddressCache(this);                primaryKey.setValue(new Integer(id));                rc.refreshDel(primaryKey);            }        } catch (SQLException e) {            logger.error("del: " + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }        public ObjectDb getObjectRaw(PrimaryKey pk) {        return new AddressDb(pk.getIntValue());    }        public void load() {        ResultSet rs = null;        Conn conn = new Conn(connname);        try {                                    PreparedStatement ps = conn.prepareStatement(QUERY_LOAD);            ps.setInt(1, id);            rs = conn.executePreQuery();            if (rs != null && rs.next()) {                person = StrUtil.getNullStr(rs.getString(1));                firstname = StrUtil.getNullStr(rs.getString(2));                familyname = StrUtil.getNullStr(rs.getString(3));                middleName = StrUtil.getNullStr(rs.getString(4));                job = StrUtil.getNullStr(rs.getString(5));                tel = StrUtil.getNullStr(rs.getString(6));                nickname = StrUtil.getNullStr(rs.getString(7));                fax = StrUtil.getNullStr(rs.getString(8));                mobile = StrUtil.getNullStr(rs.getString(9));                web = StrUtil.getNullStr(rs.getString(10));                companyStreet = StrUtil.getNullStr(rs.getString(11));                companyCity = StrUtil.getNullStr(rs.getString(12));                companyPostcode = StrUtil.getNullStr(rs.getString(13));                companyProvice = StrUtil.getNullStr(rs.getString(14));                companyCountry = StrUtil.getNullStr(rs.getString(15));                operationweb = StrUtil.getNullStr(rs.getString(16));                operationPhone = StrUtil.getNullStr(rs.getString(17));                operationFax = StrUtil.getNullStr(rs.getString(18));                BeepPager = StrUtil.getNullStr(rs.getString(19));                company = StrUtil.getNullStr(rs.getString(20));                email = StrUtil.getNullStr(rs.getString(21));                city = StrUtil.getNullStr(rs.getString(22));                street = StrUtil.getNullStr(rs.getString(23));                address = StrUtil.getNullStr(rs.getString(24));                country = StrUtil.getNullStr(rs.getString(25));                postalcode = StrUtil.getNullStr(rs.getString(26));                province = StrUtil.getNullStr(rs.getString(27));                introduction = StrUtil.getNullStr(rs.getString(28));                userName = StrUtil.getNullStr(rs.getString(29));                department = StrUtil.getNullStr(rs.getString(30));                type = rs.getInt(31);                addDate = rs.getTimestamp(32);                typeId = rs.getInt(33);                QQ = StrUtil.getNullStr(rs.getString(34));                MSN = StrUtil.getNullStr(rs.getString(35));                loaded = true;                primaryKey.setValue(new Integer(id));            }        } catch (SQLException e) {            logger.error("load: " + e.getMessage());        } finally {            if (rs != null) {                try {                    rs.close();                } catch (SQLException e) {}                rs = null;            }            if (conn != null) {                conn.close();                conn = null;            }        }    }        public boolean save() throws ErrMsgException {        Conn conn = new Conn(connname);        boolean re = false;        try {            PreparedStatement ps = conn.prepareStatement(QUERY_SAVE);            ps.setString(1, person);            ps.setString(2, firstname);            ps.setString(3, familyname);            ps.setString(4, middleName);            ps.setString(5, job);            ps.setString(6, tel);            ps.setString(7, nickname);            ps.setString(8, fax);            ps.setString(9, mobile);            ps.setString(10, web);            ps.setString(11, companyStreet);            ps.setString(12, companyCity);            ps.setString(13, companyPostcode);            ps.setString(14, companyProvice);            ps.setString(15, companyCountry);            ps.setString(16, operationweb);            ps.setString(17, operationPhone);            ps.setString(18, operationFax);            ps.setString(19, BeepPager);            ps.setString(20, company);            ps.setString(21, email);            ps.setString(22, city);            ps.setString(23, street);            ps.setString(24, address);            ps.setString(25, country);            ps.setString(26, postalcode);            ps.setString(27, province);            ps.setString(28, introduction);            ps.setString(29, userName);            ps.setString(30, department);            ps.setInt(31, type);            ps.setInt(32, typeId);            ps.setString(33, QQ);            ps.setString(34, MSN);            ps.setInt(35, id);            re = conn.executePreUpdate() == 1 ? true : false;            if (re) {                AddressCache rc = new AddressCache(this);                primaryKey.setValue(new Integer(id));                rc.refreshSave(primaryKey);            }        } catch (SQLException e) {            logger.error("save: " + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }    public void setUserName(String userName) {        this.userName = userName;    }    public String getUserName() {        return userName;    }    public int getType() {        return type;    }    public ListResult listResult(String listsql, int curPage, int pageSize) throws            ErrMsgException {        int total = 0;        ResultSet rs = null;        Vector result = new Vector();        ListResult lr = new ListResult();        lr.setTotal(total);        lr.setResult(result);        Conn conn = new Conn(connname);        try {                        String countsql = SQLFilter.getCountSql(listsql);            rs = conn.executeQuery(countsql);            if (rs != null && rs.next()) {

⌨️ 快捷键说明

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