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

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import jp.co.sint.config.SIConfig;
import jp.co.sint.database.SIDBAccessException;
import jp.co.sint.database.SIDBUtil;
import jp.co.sint.tools.SIUtil;

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 SIShopInfo extends SIBasic{
  //ログ用のインスタンスの生成
  private static Category log=Category.getInstance(SIConfig.SILOG4J_WEBSHOP_CATEGORY_NAME);
  
  private String shopCode = "";
  private String hTMLFileName = "";
  private String title = "";
  private String shopComment = "";
  
  public SIShopInfo(){}
  
  public SIShopInfo(String lShopCode){
    this.setShopCode( lShopCode);
  }
  
  /**
   * @return
   */
  public String getShopComment() {
    return shopComment;
  }
  
  /**
   * @return
   */
  public String getHTMLFileName() {
    return hTMLFileName;
  }
  
  public String getImageFileName(int lIndex,int lImageIndex){
    if (SIUtil.isNull(getShopCode()))return "";
    StringBuffer lImageFileNameBuf=new StringBuffer();
    lImageFileNameBuf.append(getShopCode()).append("/"+lImageIndex);
    lImageFileNameBuf.append(SIConfig.SISUFFIX_SHOP_INFO_IMAGE_NAME[lIndex]).append(".jpg");
    log.debug("getImageFileName:lImageFileNameBuf="+lImageFileNameBuf.toString()+",lIndex="+lIndex+",lImageIndex="+lImageIndex);
    return lImageFileNameBuf.toString();
  }
  
  public String getImageFileNameOnly(int lIndex,int lImageIndex){
    if (SIUtil.isNull(getShopCode()))return "";
    StringBuffer lImageFileNameOnlyBuf=new StringBuffer();
    lImageFileNameOnlyBuf.append(lImageIndex);
    lImageFileNameOnlyBuf.append(SIConfig.SISUFFIX_SHOP_INFO_IMAGE_NAME[lIndex]).append(".jpg");
    log.debug("getImageFileNameOnly:lImageFileNameOnlyBuf="+lImageFileNameOnlyBuf.toString()+",lIndex="+lIndex+",lImageIndex="+lImageIndex);
    return lImageFileNameOnlyBuf.toString();
  }
  
  /**
   * @return
   */
  public String getImageFileNameOnly1(int lIndex) {
    return getImageFileNameOnly(lIndex,1);
  }
  
  /**
   * @return
   */
  public String getImageFileNameOnly2(int lIndex) {
    return getImageFileNameOnly(lIndex,2);
  }
  
  /**
   * @return
   */
  public String getImageFileNameOnly3(int lIndex) {
    return getImageFileNameOnly(lIndex,3);
  }
  
  /**
   * @return
   */
  public String getImageFileNameOnly4(int lIndex) {
    return getImageFileNameOnly(lIndex,4);
  }
  
  /**
   * @return
   */
  public String getImageFileNameOnly5(int lIndex) {
    return getImageFileNameOnly(lIndex,5);
  }
  
  /**
   * @return
   */
  public String getImageFileNameOnly6(int lIndex) {
    return getImageFileNameOnly(lIndex,6);
  }
  
  /**
   * @return
   */
  public String getImageFileName1(int lIndex) {
    return getImageFileName(lIndex,1);
  }
  
  /**
   * @return
   */
  public String getImageFileName2(int lIndex) {
    return getImageFileName(lIndex,2);
  }
  
  /**
   * @return
   */
  public String getImageFileName3(int lIndex) {
    return getImageFileName(lIndex,3);
  }
  
  /**
   * @return
   */
  public String getImageFileName4(int lIndex) {
    return getImageFileName(lIndex,4);
  }
  
  /**
   * @return
   */
  public String getImageFileName5(int lIndex) {
    return getImageFileName(lIndex,5);
  }
  
  /**
   * @return
   */
  public String getImageFileName6(int lIndex) {
    return getImageFileName(lIndex,6);
  }
  
  /**
   * @return
   */
  public String getShopCode() {
    return shopCode;
  }
  
  /**
   * @return
   */
  public String getTitle() {
    return title;
  }
  
  /**
   * @param string
   */
  public void setShopComment(String string) {
    if (SIUtil.isNull(string)) string="";
    this.shopComment=SIUtil.changeTo(string.trim(),this.encode);
  }
  
  /**
   * @param string
   */
  public void setHTMLFileName(String string) {
    if (SIUtil.isNull(string)) string="";
    this.hTMLFileName=SIUtil.changeTo(string.trim(),this.encode);
  }
  
  /**
   * @param string
   */
  public void setShopCode(String string) {
    if (SIUtil.isNull(string)) string="";
    this.shopCode=SIUtil.changeTo(string.trim(),this.encode);
  }
  
  /**
   * @param string
   */
  public void setTitle(String string) {
    if (SIUtil.isNull(string)) string="";
    this.title=SIUtil.changeTo(string.trim(),this.encode);
  }
  
  public void reset(Connection lConnection)throws SIDBAccessException {
    Statement lStatement=null;
    ResultSet lResultSet=null;
    String lSql="SELECT * FROM ShopInfoMTbl WHERE ShopCode="+SIDBUtil.SQL2Str(shopCode);
    log.debug("reset:lSql="+lSql);
    try {
      lStatement=lConnection.createStatement();
      lResultSet=lStatement.executeQuery(lSql);
      
      if (lResultSet.next()){
        this.setEncode(SIConfig.SIENCODE_NONE);
        this.setHTMLFileName(lResultSet.getString("HTMLFileName"));
        this.setTitle(lResultSet.getString("Title"));
        this.setShopComment(lResultSet.getString("ShopComment"));
      } 
    }catch(SQLException sqle){
      sqle.printStackTrace();
    }finally{
      SIDBUtil.close(lStatement,lResultSet);
    }
  }
}