/**
 * Copyright (c) 2003-2004 System Integrator Corporation.
 *                 All Rights Reserved.
 */
package jp.co.sint.basic;

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

import jp.co.sint.tools.*;
import jp.co.sint.config.*;

/**
 * @version $Id: SISrchCtgry.java,v 1.0 Exp $
 * @author  Jinwang Chen
 * <br>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>
 * J.W.Chen       2003/06/25  Original
 */

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

  //カテゴリコード
  private String ctgryCode="";

  //検索項目名リスト
  private String[] srchKeyName=new String[SIConfig.SISRCH_KEY_NAME_MAX];

  //使用制御リスト
  private String[] dispType=new String[SIConfig.SISRCH_KEY_NAME_MAX];;

  public SISrchCtgry(){
  }

  //setter of カテゴリコード
  public void setCtgryCode(String lCtgryCode){
    if (SIUtil.isNull(lCtgryCode)) lCtgryCode="";
    this.ctgryCode=SIUtil.changeTo(lCtgryCode.trim(),this.encode);
  }

  //setter of 検索項目名1
  public void setSrchKeyName1(String lSrchKeyName){
    setSrchKeyName(0,lSrchKeyName);
  }

  //setter of 検索項目名2
  public void setSrchKeyName2(String lSrchKeyName){
    setSrchKeyName(1,lSrchKeyName);
  }

  //setter of 検索項目名3
  public void setSrchKeyName3(String lSrchKeyName){
    setSrchKeyName(2,lSrchKeyName);
  }
  //
  public void setSrchKeyName(int lSeq,String lSrchKeyName){
    if (SIUtil.isNull(lSrchKeyName)) lSrchKeyName="";
    this.srchKeyName[lSeq]=SIUtil.changeTo(lSrchKeyName.trim(),this.encode);
  }

  //setter of 使用制御1
  public void setDispType1(String lDispType){
    setDispType(0,lDispType);
  }

  //setter of 使用制御2
  public void setDispType2(String lDispType){
    setDispType(1,lDispType);
  }

  //setter of 使用制御3
  public void setDispType3(String lDispType){
    setDispType(2,lDispType);
  }

  public void setDispType(int lSeq,String lDispType){
    if (SIUtil.isNull(lDispType)) lDispType="0";
    this.dispType[lSeq]=SIUtil.changeTo(lDispType.trim(),this.encode);
  }

  //getter of カテゴリコード
  public String getCtgryCode(){
    return this.ctgryCode;
  }

  //getter of 検索項目名1
  public String getSrchKeyName1(){
    return getSrchKeyName(0);
  }

  //getter of 検索項目名2
  public String getSrchKeyName2(){
    return getSrchKeyName(1);
  }

  //getter of 検索項目名3
  public String getSrchKeyName3(){
    return getSrchKeyName(2);
  }

  public String getSrchKeyName(int lSeq){
    if (SIUtil.isNull(srchKeyName[lSeq])) return "";
    else return this.srchKeyName[lSeq];
  }

  //getter of 使用制御1
  public String getDispType1(){
    return getDispType(0);
  }

  //getter of 使用制御2
  public String getDispType2(){
    return getDispType(1);
  }

  //getter of 使用制御3
  public String getDispType3(){
    return getDispType(2);
  }

  public String getDispType(int lSeq){
    if (SIUtil.isNull( srchKeyName[lSeq]))   return "0";
    else if (SIUtil.isNull( dispType[lSeq])) return "0";
    else return this.dispType[lSeq];
  }

  /**
   * <b>isDisable</b>
   * 使わないかどうかの判断
   * @param lSeq 検索項目に対する順番番号
   */
  public boolean isDisable(int lSeq){
    if (getDispType(lSeq).trim().equals("0")) return true;
    else return false;
  }

  /**
   * <b>isText</b>
   * 直接入力の項目でどうかの判断
   * @param lSeq 検索項目に対する順番番号
   */
  public boolean isText(int lSeq){
    if (this.getDispType(lSeq).trim().equals("1")) return true;
    else return false;
  }

  /**
   * <b>isCombox</b>
   * 一覧選択の項目でどうかの判断
   * @param lSeq 検索項目に対する順番番号
   */
  public boolean isCombox(int lSeq){
    if (this.getDispType(lSeq).trim().equals("2")) return true;
    else return false;
  }

  public void reset(Connection lConnection){
    Statement lStatement=null;
    ResultSet lResultSet=null;
    String lSql="SELECT * FROM SrchCtgryMTbl WHERE CtgryCode="+SIDBUtil.SQL2Str(ctgryCode);
    log.debug( "reset:lSql="+lSql);

    try {
      this.setEncode(SIConfig.SIENCODE_NONE);
      lStatement=lConnection.createStatement();
      lResultSet=lStatement.executeQuery(lSql);
      //各検索項目に対するデータを設定
      while (lResultSet.next()){
        setSrchKeyName(lResultSet.getInt("SrchKeyCode")-1,lResultSet.getString("SrchKeyName"));
        setDispType(lResultSet.getInt("SrchKeyCode")-1,lResultSet.getString("DispType"));
      }
    }catch(Exception e){
      e.printStackTrace();
    }finally{
      SIDBUtil.close(lStatement,lResultSet);
    }
  }
}