/**
 * Created on 2003/11/18
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package jp.co.sint.beans.mallmgr;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.http.HttpServletRequest;

import jp.co.sint.basic.SIBasic;
import jp.co.sint.basic.SILogin;
import jp.co.sint.basic.SIPayMethod;
import jp.co.sint.config.SIConfig;
import jp.co.sint.database.SIDBAccessException;
import jp.co.sint.database.SIDBUtil;
import jp.co.sint.database.SITableCondition;
import jp.co.sint.database.SITableConditionManager;
import jp.co.sint.tools.SIHTMLUtil;
import jp.co.sint.tools.SIUtil;
import jp.co.sint.tools.SIURLParameter;//7.1.1 ST0236 追加

import org.apache.log4j.Category;

/**
 * @author arai
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class UIPayMethodListCond extends SIBasic {
  //ログ用のインスタンスの生成
  private static Category log = Category.getInstance(SIConfig.SILOG4J_WEBSHOP_CATEGORY_NAME);
  
  //管理コード
  private String mallShopCodeTxt = "";
  
  //支払方法ID
  private String payMethodCodeTxt = "";
  
  //支払方法名称
  private String payMethodNameTxt = "";
  
  //支払区分
  private String paymentFlgTxt = "0";
  
  //手数料
  private String feeTxt = "0";
  
  //setter of 管理コード
  public void setMallShopCodeTxt(String lMallShopCodeTxt){
    if (SIUtil.isNull(lMallShopCodeTxt)) lMallShopCodeTxt="";
    this.mallShopCodeTxt=SIUtil.changeTo(lMallShopCodeTxt.trim(),this.encode);
  }
  
  //setter of 支払方法ID
  public void setPayMethodCodeTxt(String lPayMethodCodeTxt){
    if (SIUtil.isNull(lPayMethodCodeTxt)) lPayMethodCodeTxt="";
    this.payMethodCodeTxt=SIUtil.changeTo(lPayMethodCodeTxt.trim(),this.encode);
  }
  
  //setter of 支払方法名称
  public void setPayMethodNameTxt(String lPayMethodNameTxt){
    if (SIUtil.isNull(lPayMethodNameTxt)) lPayMethodNameTxt="";
    this.payMethodNameTxt=SIUtil.changeTo(lPayMethodNameTxt.trim(),this.encode);
  }
  
  //setter of 支払区分
  public void setPaymentFlgTxt(String lPaymentFlgTxt){
    if (SIUtil.isNull(lPaymentFlgTxt)) lPaymentFlgTxt="0";
    this.paymentFlgTxt=SIUtil.changeTo(lPaymentFlgTxt.trim(),this.encode);
  }
  
  //setter of 手数料
  public void setFeeTxt(String lFeeTxt){
    if (SIUtil.isNull(lFeeTxt)) lFeeTxt="";
    this.feeTxt=SIUtil.changeTo(lFeeTxt.trim(),this.encode);
  }
  
  //getter of 管理コード
  public String getMallShopCodeTxt(){
    return this.mallShopCodeTxt;
  }
  
  //getter of 支払方法ID
  public String getPayMethodCodeTxt(){
    return this.payMethodCodeTxt;
  }
  
  //getter of 支払方法名称
  public String getPayMethodNameTxt(){
    return this.payMethodNameTxt;
  }
  
  //getter of 支払区分
  public String getPaymentFlgTxt(){
    return this.paymentFlgTxt;
  }
  
  //getter of 手数料
  public String getFeeTxt(){
    return this.feeTxt;
  }
  
  public UIPayMethodListCond(){}
  
  //7.1.1 ST0236 修正 ここから
  public UIPayMethodListCond(HttpServletRequest lRequest,SIURLParameter lUrlParam){
    super.init(lRequest,lUrlParam);
  }
  //7.1.1 ST0236 修正 ここまで
  
  //7.1.1 ST0236 修正 ここから
  public void init(HttpServletRequest lRequest,SIURLParameter lUrlParam){
    super.init(lRequest,lUrlParam); 
    SILogin lLogin=SIHTMLUtil.getLogin(lRequest);
    
    this.setEncode(SIConfig.SIENCODE_SHIFT_JIS);
    if (lLogin.isShop()){
      this.setMallShopCodeTxt(lLogin.getMallShopCode());//ショップコード
    }else{
      this.setMallShopCodeTxt((String)lUrlParam.getParam("mallShopCodeTxt"));//ショップコード
    }
    this.setPayMethodCodeTxt((String)lUrlParam.getParam("payMethodCodeTxt"));//支払方法ID
    this.setPayMethodNameTxt((String)lUrlParam.getParam("payMethodNameTxt"));//支払方法名
    this.setPaymentFlgTxt((String)lUrlParam.getParam("paymentFlgTxt"));//支払区分
    this.setFeeTxt((String)lUrlParam.getParam("feeTxt"));//手数料
  }
  //7.1.1 ST0236 修正 ここまで
  
  public Collection getCollection(Connection lConnection, SILogin lLogin) throws SIDBAccessException {
    Statement statement = null;
    ResultSet resultSet = null;
    Collection payColl = new ArrayList();
    StringBuffer strBuf = new StringBuffer();
    SIPayMethod lpaymethod = new SIPayMethod();
    
    strBuf = new StringBuffer();
    strBuf.append(" SELECT * FROM PayMethodMTbl ");
    
    if (SIUtil.match(SIConfig.SIADMIN_MM,lLogin.getAdminType())){
      strBuf.append(" WHERE mallShopCode=").append(SIDBUtil.SQL2Str(lLogin.getMallShopCode()," "));
    }else if (SIUtil.match(SIConfig.SIADMIN_MS,lLogin.getAdminType())){
      strBuf.append(" WHERE 1=2 ");
    }else if (SIUtil.match(SIConfig.SIADMIN_SM,lLogin.getAdminType())){
      strBuf.append(" WHERE mallShopCode!=").append(SIDBUtil.SQL2Str(SIConfig.SIMALL.getMallShopCode()," "));
    }else if (SIUtil.match(SIConfig.SIADMIN_SS,lLogin.getAdminType())){
      strBuf.append(" WHERE mallShopCode=").append(SIDBUtil.SQL2Str(lLogin.getMallShopCode()," "));
    }else{
      strBuf.append(" WHERE 1=2 ");
    }
    
    strBuf.append(" ORDER BY mallShopCode ASC , payMethodCode ASC ");
    
    //検索の条件
    //出力順
    //実行
    try {
      statement = lConnection.createStatement();
      resultSet = statement.executeQuery(strBuf.toString());
      
      while (resultSet.next()) {
        lpaymethod = new SIPayMethod();
        lpaymethod.setEncode(SIConfig.SIENCODE_NONE);
        lpaymethod.setMallShopCode(resultSet.getString("mallShopCode"));
        lpaymethod.setPayMethodCode(resultSet.getString("payMethodCode"));
        lpaymethod.setPayMethodName(resultSet.getString("payMethodName"));
        lpaymethod.setPaymentFlg(resultSet.getString("paymentFlg"));
        lpaymethod.setFee(resultSet.getString("fee"));
        payColl.add(lpaymethod);
      }
    } catch (Exception ex) {
      log.debug("exception sql = " + strBuf.toString());
      throw new SIDBAccessException(ex);
    } finally {
      SIDBUtil.close(resultSet, statement);
    }
    return payColl;
  }

}
