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

📄 currentassetsaccess.java

📁 Athena酒店小组_Athena酒店管理系统
💻 JAVA
字号:
/* 
 * CurrentAssetsAccess.java
 *
 * Created on 2007年6月4日, 下午11:26
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package minco;

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

import plugin.*;
import helper.*;

/**
 * 实体类 CurrentAssets 的访问类
 * @author Minco
 * @version 1.0
 */
public class CurrentAssetsAccess
{
    private IDBResource dbRes;
    
   /**
    * 构造函数
    * @param dbRes 数据库资源
    */
    public CurrentAssetsAccess(IDBResource dbRes)
    {
	this.dbRes = dbRes;
    }

   /**
    * 对CurrentAssets表进行插入操作
    * @param currentAssets 要插入的流动资产信息
    * @return 影响的行数,如果发生错误,则返回-1
    */
    public int insert(CurrentAssets currentAssets)
    {
	try
	{
	    Connection conn = dbRes.getConnection();
	    String sql = "INSERT INTO CurrentAssets(AssetTime, Cash, ShortTermInvestments, Prepayments, Inventories, TaxRecoverable) " +
		    " VALUES(?, ?, ?, ?, ?, ?)";
	    PreparedStatement ps = conn.prepareStatement(sql);
	    ps.setObject(1, currentAssets.getAssetTime());
	    ps.setDouble(2, currentAssets.getCash());
	    ps.setDouble(3, currentAssets.getShortTermInvestments());
	    ps.setDouble(4, currentAssets.getPrepayments());
	    ps.setDouble(5, currentAssets.getInventories());
	    ps.setDouble(6, currentAssets.getTaxRecoverable());
	    
	    int rs = ps.executeUpdate();
	    return rs;
	}
	catch (SQLException ex)
	{
	    ex.printStackTrace();
	    return -1;
	}
    }

   /**
    * 对CurrentAssets表进行更新操作
    * @param currentAssets 要更新的流动资产信息
    * @return 影响的行数,如果发生错误,则返回-1
    */
    public int update(CurrentAssets currentAssets)
    {
	try
	{
	    Connection conn = dbRes.getConnection();
	    String sql = "UPDATE CurrentAssets SET Cash = ?, ShortTermInvestments = ?, " +
		    "Prepayments = ?, Inventories = ?, TaxRecoverable = ?) " +
		    "WHERE AssetTime = ?";
	    PreparedStatement ps = conn.prepareStatement(sql);	    
	    

	    ps.setDouble(1, currentAssets.getCash());
	    ps.setDouble(2, currentAssets.getShortTermInvestments());
	    ps.setDouble(3, currentAssets.getPrepayments());
	    ps.setDouble(4, currentAssets.getInventories());
	    ps.setDouble(5, currentAssets.getTaxRecoverable());
            ps.setObject(6, currentAssets.getAssetTime());

	    
	    int rs = ps.executeUpdate();
	    return rs;
	}
	catch (SQLException ex)
	{
	    ex.printStackTrace();
	    return -1;
	}
    }

   /**
    * 对CurrentAssets表进行删除操作
    * @param currentAssets 要删除的流动资产信息
    * @return 影响的行数,如果发生错误,则返回-1
    */
    public int delete(CurrentAssets currentAssets)
    {
	try
	{
	    Connection conn = dbRes.getConnection();
	    String sql = "DELETE FROM CurrentAssets WHERE AssetTime = ?";
	    PreparedStatement ps = conn.prepareStatement(sql);
	    
            ps.setObject(1, currentAssets.getAssetTime());
	    
	    int rs = ps.executeUpdate();
	    return rs;
	}
	catch (SQLException ex)
	{
	    ex.printStackTrace();
	    return -1;
	}
    }

   /**
    * 根据Time查询CurrentAssets表的信息
    * @param AssetTime 日期
    * @return 查询到的流动资产信息
    */
    public CurrentAssets getCurrentAssetsByTime(java.util.Date assetTime)
    {
	try
	{
	    Connection conn = dbRes.getConnection();
	    String sql = "SELECT * FROM CurrentAssets WHERE AssetTime = ?";
	    PreparedStatement ps = conn.prepareStatement(sql);
	    ps.setObject(1, assetTime);
	    ResultSet rs = ps.executeQuery();
	    ArrayList<CurrentAssets> currentAssets = new ArrayList<CurrentAssets>();
	    readData(currentAssets, rs);
	    if (currentAssets.size() != 1)
	    {
		return null;
	    }
	    return currentAssets.get(0);
	}
	catch (SQLException ex)
	{
	    ex.printStackTrace();
	    return null;
	}
    }

    /**
     * 返回CurrentAssets表的所有信息
     * @return 所有流动资产信息
     */
    public ArrayList<CurrentAssets> getAllCurrentAssets()
    {
	try
	{
	    Connection conn = dbRes.getConnection();
	    String sql = "SELECT * FROM CurrentAssets";
	    PreparedStatement ps = conn.prepareStatement(sql);
	    ResultSet rs = ps.executeQuery();
	    ArrayList<CurrentAssets> currentAssets = new ArrayList<CurrentAssets>();
	    readData(currentAssets, rs);
	    return currentAssets;
	}
	catch (SQLException ex)
	{
	    ex.printStackTrace();
	    return null;
	}
    }

   /**
    * 根据条件查询CurrentAssets表的信息
    * @param names 条件的名称
    * @param values 条件的值
    * @return 查询到的流动资产信息
     */
    public ArrayList<CurrentAssets> getCurrentAssetByCondition(ArrayList<String> names, ArrayList<Object> values)
    {
	try
	{
	    Connection conn = dbRes.getConnection();
	    String sql = "SELECT * FROM CurrentAssets " + SQLHelper.createCondition(names);
	    PreparedStatement ps = conn.prepareStatement(sql);
	    for(int i = 0; i < values.size(); i++)
	    {
		ps.setObject(i+1, values.get(i));
	    }
	    ResultSet rs = ps.executeQuery();
	    ArrayList<CurrentAssets> currentAssets = new ArrayList<CurrentAssets>();
	    readData(currentAssets, rs);
	    return currentAssets;
	}
	catch (SQLException ex)
	{
	    ex.printStackTrace();
	    return null;
	}
    }
    
    //读取数据
    private void readData(ArrayList<CurrentAssets> currentAsset, ResultSet rs) throws SQLException
    {
	while(rs.next())
	{
	    CurrentAssets currentAssets = new CurrentAssets();
	    currentAssets.setAssetTime(rs.getDate("AssetTime"));
	    currentAssets.setCash(rs.getDouble("Cash"));
	    currentAssets.setShortTermInvestments(rs.getDouble("ShortTermInvestments"));
	    currentAssets.setPrepayments(rs.getDouble("Prepayments"));
	    currentAssets.setInventories(rs.getDouble("Inventories"));
	    currentAssets.setTaxRecoverable(rs.getDouble("TaxRecoverable"));
	    currentAsset.add(currentAssets);
	}
    }
}

⌨️ 快捷键说明

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