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

📄 auctionshopdb.java~2~

📁 云网论坛CWBBS 源码,内容丰富,学习,参考,教学的好资料,具体见内说明,
💻 JAVA~2~
字号:
package com.redmoon.forum.plugin.auction;

import java.io.File;
import java.sql.*;
import java.util.Iterator;
import java.util.Vector;

import cn.js.fan.base.ObjectDb;
import cn.js.fan.db.*;
import cn.js.fan.util.*;
import cn.js.fan.web.Global;
import cn.js.fan.web.SkinUtil;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class AuctionShopDb extends ObjectDb {
    private String userName;
    public static final int LOGO_NO_WIDTH = 0;

    public AuctionShopDb() {
        super();
    }

    public AuctionShopDb(String userName) {
        this.userName = userName;
        load();
        init();
    }

    public boolean create() throws ResKeyException {
        int rowcount = 0;
         Conn conn = null;
         id = (int)SequenceMgr.nextID(SequenceMgr.ShopId);
         try {
             conn = new Conn(connname);
             PreparedStatement ps = conn.prepareStatement(this.QUERY_CREATE);
             ps.setString(1, userName);
             ps.setString(2, shopName);
             ps.setString(3, address);
             ps.setString(4, tel);
             ps.setString(5, desc);
             ps.setInt(6, valid?0:1);
             ps.setString(7, reason);
             ps.setInt(8, id);
             ps.setString(9, "" + System.currentTimeMillis());
             ps.setInt(10, recommanded?1:0);
             rowcount = conn.executePreUpdate();
             if (rowcount>0) {
                 AuctionShopCache uc = new AuctionShopCache(this);
                 uc.refreshCreate();
             }
         } catch (SQLException e) {
             logger.error("create:" + e.getMessage());
             throw new ResKeyException(new SkinUtil(), SkinUtil.ERR_DB);
         } finally {
             if (conn != null) {
                 conn.close();
                 conn = null;
             }
         }
        return rowcount>0? true:false;
    }

    /**
     * del
     *
     * @return boolean
     * @throws ErrMsgException
     * @todo Implement this cn.js.fan.base.ObjectDb method
     */
    public boolean del() throws ResKeyException, ErrMsgException {
        int rowcount = 0;
        Conn conn = null;
        try {
            conn = new Conn(connname);
            PreparedStatement ps = conn.prepareStatement(this.QUERY_DEL);
            ps.setString(1, userName);
            rowcount = conn.executePreUpdate();

            AuctionShopCache uc = new AuctionShopCache(this);
            primaryKey.setValue(userName);
            uc.refreshDel(primaryKey);
            // 删除logo图片
            File file = new File(Global.getRealPath() + logo);
            file.delete();
            // 删除所有用户自己的商品目录及目录下的所有商品
            AuctionShopDirDb asdd = new AuctionShopDirDb();
            Vector v = asdd.list(userName);
            Iterator ir = v.iterator();
            while (ir.hasNext()) {
                asdd = (AuctionShopDirDb)ir.next();
                asdd.delWithAuction();
            }

        } catch (SQLException e) {
            logger.error("del:" + e.getMessage());
        } finally {
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        if (rowcount > 0) {
            AuctionShopCache cc = new AuctionShopCache(this);
            primaryKey.setValue(userName);
            cc.refreshDel(primaryKey);
        }
        return rowcount>0? true:false;
    }

    /**
     *
     * @param pk Object
     * @return Object
     * @todo Implement this cn.js.fan.base.ObjectDb method
     */
    public ObjectDb getObjectRaw(PrimaryKey pk) {
        return new AuctionShopDb(pk.getStrValue());
    }

    public AuctionShopDb getAuctionShopDb(String userName) {
        return (AuctionShopDb)getObjectDb(userName);
    }

    public String getShopUserNameById(int id) {
        AuctionShopCache asc = new AuctionShopCache(this);
        return asc.getShopUserNameById(id);
    }

    /**
     * load
     *
     * @throws ErrMsgException
     * @todo Implement this cn.js.fan.base.ObjectDb method
     */
    public void load() {
        ResultSet rs = null;
        Conn conn = new Conn(connname);
        try {
            PreparedStatement ps = conn.prepareStatement(this.QUERY_LOAD);
            ps.setString(1, userName);
            primaryKey.setValue(userName);
            rs = conn.executePreQuery();
            if (rs.next()) {
                // shopName,address,tel,desciprtion,isValid,reason
                shopName = rs.getString(1);
                address = rs.getString(2);
                tel = rs.getString(3);
                desc = rs.getString(4);
                valid = rs.getInt(5)==0?false:true;
                reason = rs.getString(6);
                openDate = DateUtil.parse(rs.getString(7));
                id = rs.getInt(8);
                logo = rs.getString(9);
                logoWidth = rs.getInt(10);
                skinCode = rs.getString(11);
                recommanded = rs.getInt(12)==1;
                loaded = true;
            }
        } catch (SQLException e) {
            logger.error("load:" + e.getMessage());
        }
        finally {
            if (conn!=null) {
                conn.close();
                conn = null;
            }
        }
    }

    /**
     * save
     *
     * @return boolean
     * @throws ErrMsgException
     * @todo Implement this cn.js.fan.base.ObjectDb method
     */
    public boolean save() throws ErrMsgException {
        int rowcount = 0;
        Conn conn = null;
        try {
            conn = new Conn(connname);
            PreparedStatement ps = conn.prepareStatement(this.QUERY_SAVE);
            // shopName=?,address=?,tel=?,desciprtion=?,isValid=?,reason=?
            ps.setString(1, shopName);
            ps.setString(2, address);
            ps.setString(3, tel);
            ps.setString(4, desc);
            ps.setInt(5, valid?1:0);
            ps.setString(6, reason);
            ps.setString(7, logo);
            ps.setInt(8, logoWidth);
            ps.setString(9, skinCode);
            ps.setInt(10, recommanded?1:0);
            ps.setString(11, userName);
            rowcount = conn.executePreUpdate();
        } catch (SQLException e) {
            logger.error("save:" + e.getMessage());
        } finally {
            if (conn != null) {
                conn.close();
                conn = null;
            }
            AuctionShopCache uc = new AuctionShopCache(this);
            primaryKey.setValue(userName);
            uc.refreshSave(primaryKey);
        }
        return rowcount>0? true:false;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public void setShopName(String shopName) {
        this.shopName = shopName;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public void setValid(boolean valid) {
        this.valid = valid;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public void setOpenDate(java.util.Date openDate) {
        this.openDate = openDate;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public void setLogoWidth(int logoWidth) {
        this.logoWidth = logoWidth;
    }

    public void setSkinCode(String skinCode) {
        this.skinCode = skinCode;
    }

    public void setRecommanded(boolean recommanded) {
        this.recommanded = recommanded;
    }

    public String getUserName() {
        return userName;
    }

    public String getShopName() {
        return shopName;
    }

    public String getAddress() {
        return address;
    }

    public String getTel() {
        return tel;
    }

    public String getDesc() {
        return desc;
    }

    public boolean isValid() {
        return valid;
    }

    public String getReason() {
        return reason;
    }

    public java.util.Date getOpenDate() {
        return openDate;
    }

    public int getId() {
        return id;
    }

    public String getLogo() {
        return logo;
    }

    public int getLogoWidth() {
        return logoWidth;
    }

    public String getSkinCode() {
        return skinCode;
    }

    public boolean isRecommanded() {
        return recommanded;
    }

    private String shopName;
    private String address;
    private String tel;
    private String desc;
    private boolean valid;
    private String reason;
    private java.util.Date openDate;
    private int id;
    private String logo;
    private int logoWidth = LOGO_NO_WIDTH;
    private String skinCode;
    private boolean recommanded = false;
}

⌨️ 快捷键说明

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