/**
 * Copyright (c) 2003-2004 System Integrator Corporation.
 *                 All Rights Reserved.
 */

package jp.co.sint.tools;

import java.sql.*;

import org.apache.log4j.Category;
import jp.co.sint.database.*;
import jp.co.sint.config.*;

/**
 * @version $Id: SIAdviceCmdtyError,v 1.0 2004/1/5 yamauchi Exp $
 * @author  yamauchi
 * <p>Description:ショップが、モールショップの「おすすめ商品数」以上に、おすすめ設定場合はエラーとなる
 * <p>History</p>
 * <p>Author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reason</p>
 * ============&nbsp;&nbsp;&nbsp;==========&nbsp;&nbsp;===========================<br>
 * yamauchi   2004/01/05  Original
 */

public class SIAdviceCmdtyError {
	//ログ用のインスタンスの生成
	private static Category log=Category.getInstance(SIConfig.SILOG4J_WEBSHOP_CATEGORY_NAME);

	/**
	 * <b>isEmpty</b>
	 * コンストラクタ
	 * @param  なし
	 * @return なし
	 * @throws なし
	 */
	public SIAdviceCmdtyError(){}

	/**
	 * <b>checkAmount</b>
	 * 値を比較し、基準値を以上の場合はエラー
	 * @param  コネクション
	 * @param  比較する値をえるSQL
	 * @param  基準値を得るSQL
	 * @return
	 * @throws なし
	 */
	public static boolean checkAmount(SICustomErrors lErrors,Connection lConnection, String lSqlStatement1,String lSqlStatement2,String lCheckedName1){
		int amount1=0;
		int amount2=0;
		try {

			amount1=Integer.parseInt(SIDBUtil.getFirstData(lConnection,lSqlStatement1));
			amount2=Integer.parseInt(SIDBUtil.getFirstData(lConnection,lSqlStatement2));

			if(amount1>=amount2){
				lErrors.addError(new SICustomError("input.data.amount.less",lCheckedName1,Integer.toString(amount2)));
				return false;
			  }else return true;
			}catch(SIDBAccessException dba){
			  dba.printStackTrace();
			  log.error("checkDuplicate:exception="+dba.toString());
			}
			return true;
	  	}

}

