/**
 * Copyright (c) 2003-2004 System Integrator Corporation.
 *                 All Rights Reserved.
 */
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.config.SIDBMultiConf;
import jp.co.sint.database.SIDBAccessException;
import jp.co.sint.database.SIDBUtil;
import jp.co.sint.tools.SIUtil;

import org.apache.log4j.Category;

/**
 * @version $Id: SIPurchase.java,v 1.0 Exp $
 * @author Fujita Jun <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>
 *         Fujita Jun 2005/08/26 Original
 */

public class SIPurchase extends SIBasic {
  //ログ用のインスタンスの生成
  private static Category log = Category.getInstance(SIConfig.SILOG4J_WEBSHOP_CATEGORY_NAME);
  
  public SIPurchase(){}
  
  //商品名1
  private String cmdtyName1="";

  //商品名2
  private String cmdtyName2="";

  //商品名3
  private String cmdtyName3="";

  //商品名4
  private String cmdtyName4="";

  //商品名5
  private String cmdtyName5="";

  //購入時期1
  private String purchaseTime1="";

  //購入時期2
  private String purchaseTime2="";

  //購入時期3
  private String purchaseTime3="";

  //購入時期4
  private String purchaseTime4="";

  //購入時期5
  private String purchaseTime5="";

  //使用年数1
  private String usedYear1="";

  //使用年数2
  private String usedYear2="";

  //使用年数3
  private String usedYear3="";

  //使用年数4
  private String usedYear4="";

  //使用年数5
  private String usedYear5="";

  //数量1
  private String amount1="";

  //数量2
  private String amount2="";

  //数量3
  private String amount3="";

  //数量4
  private String amount4="";

  //数量5
  private String amount5="";
  
  //画像1
  private String pictureUrl1 = "";
  
  //画像2
  private String pictureUrl2 = "";
  
  //画像3
  private String pictureUrl3 = "";
  
  //画像4
  private String pictureUrl4 = "";
  
  //画像5
  private String pictureUrl5 = "";

  //買取希望時期
  private String purchaseHopeTime ="";
  
  //詳細
  private String details ="";
  
  //顧客コード
  private String custCode = "";

  //氏名
  private String custName = "";

  //フリガナ
  private String custPronName = "";
  
  //郵便番号1
  private String postCode1 = "";

  //郵便番号2
  private String postCode2 = "";
  
  //住所1
  private String address1 = "";

  //住所2
  private String address2 = "";

  //住所3
  private String address3 = "";
  
  //連絡先電話番号1
  private String tel1 = "";

  //連絡先電話番号2
  private String tel2 = "";
  
  //連絡先FAX番号
  private String fax = "";
  
  //会社名
  private String companyName = "";

  //メールアドレス
  private String email = "";
  
  //郵便番号1(他)
  private String postCodeOther1 = "";

  //郵便番号2(他)
  private String postCodeOther2 = "";
  
  //住所1(他)
  private String addressOther1 = "";

  //住所2(他)
  private String addressOther2 = "";

  //住所3(他)
  private String addressOther3 = "";
  
  //連絡先電話番号1(他)
  private String telOther1 = ""; 

  public SIPurchase(String lCustCode) {
    setCustCode(lCustCode);
  }
  
  //setter of 商品名1 of setter
  public void setCmdtyName1(String lCmdtyName1){
    if (SIUtil.isNull(lCmdtyName1)) lCmdtyName1="";
    this.cmdtyName1=SIUtil.changeTo(lCmdtyName1.trim(),this.encode);
  }
  
  //setter of 商品名2 of setter
  public void setCmdtyName2(String lCmdtyName2){
    if (SIUtil.isNull(lCmdtyName2)) lCmdtyName2="";
    this.cmdtyName2=SIUtil.changeTo(lCmdtyName2.trim(),this.encode);
  }
  
  //setter of 商品名3 of setter
  public void setCmdtyName3(String lCmdtyName3){
    if (SIUtil.isNull(lCmdtyName3)) lCmdtyName3="";
    this.cmdtyName3=SIUtil.changeTo(lCmdtyName3.trim(),this.encode);
  }
  
  //setter of 商品名4 of setter
  public void setCmdtyName4(String lCmdtyName4){
    if (SIUtil.isNull(lCmdtyName4)) lCmdtyName4="";
    this.cmdtyName4=SIUtil.changeTo(lCmdtyName4.trim(),this.encode);
  }
  
  //setter of 商品名5 of setter
  public void setCmdtyName5(String lCmdtyName5){
    if (SIUtil.isNull(lCmdtyName5)) lCmdtyName5="";
    this.cmdtyName5=SIUtil.changeTo(lCmdtyName5.trim(),this.encode);
  }
  
  //setter of 購入時期1 of setter
  public void setPurchaseTime1(String lPurchaseTime1){
    if (SIUtil.isNull(lPurchaseTime1)) lPurchaseTime1="";
    this.purchaseTime1=SIUtil.changeTo(lPurchaseTime1.trim(),this.encode);
  }
  
  //setter of 購入時期2 of setter
  public void setPurchaseTime2(String lPurchaseTime2){
    if (SIUtil.isNull(lPurchaseTime2)) lPurchaseTime2="";
    this.purchaseTime2=SIUtil.changeTo(lPurchaseTime2.trim(),this.encode);
  }
  
  //setter of 購入時期3 of setter
  public void setPurchaseTime3(String lPurchaseTime3){
    if (SIUtil.isNull(lPurchaseTime3)) lPurchaseTime3="";
    this.purchaseTime3=SIUtil.changeTo(lPurchaseTime3.trim(),this.encode);
  }
  
  //setter of 購入時期4 of setter
  public void setPurchaseTime4(String lPurchaseTime4){
    if (SIUtil.isNull(lPurchaseTime4)) lPurchaseTime4="";
    this.purchaseTime4=SIUtil.changeTo(lPurchaseTime4.trim(),this.encode);
  }
  
  //setter of 購入時期5 of setter
  public void setPurchaseTime5(String lPurchaseTime5){
    if (SIUtil.isNull(lPurchaseTime5)) lPurchaseTime5="";
    this.purchaseTime5=SIUtil.changeTo(lPurchaseTime5.trim(),this.encode);
  }
  
  //setter of 使用年数1 of setter
  public void setUsedYear1(String lUsedYear1){
    if (SIUtil.isNull(lUsedYear1)) lUsedYear1="";
    this.usedYear1=SIUtil.changeTo(lUsedYear1.trim(),this.encode);
  }
  
  //setter of 使用年数2 of setter
  public void setUsedYear2(String lUsedYear2){
    if (SIUtil.isNull(lUsedYear2)) lUsedYear2="";
    this.usedYear2=SIUtil.changeTo(lUsedYear2.trim(),this.encode);
  }
  
  //setter of 使用年数3 of setter
  public void setUsedYear3(String lUsedYear3){
    if (SIUtil.isNull(lUsedYear3)) lUsedYear3="";
    this.usedYear3=SIUtil.changeTo(lUsedYear3.trim(),this.encode);
  }
  
  //setter of 使用年数4 of setter
  public void setUsedYear4(String lUsedYear4){
    if (SIUtil.isNull(lUsedYear4)) lUsedYear4="";
    this.usedYear4=SIUtil.changeTo(lUsedYear4.trim(),this.encode);
  }
  
  //setter of 使用年数5 of setter
  public void setUsedYear5(String lUsedYear5){
    if (SIUtil.isNull(lUsedYear5)) lUsedYear5="";
    this.usedYear5=SIUtil.changeTo(lUsedYear5.trim(),this.encode);
  }
  
  //setter of 数量1 of setter
  public void setAmount1(String lAmount1){
    if (SIUtil.isNull(lAmount1)) lAmount1="";
    this.amount1=SIUtil.changeTo(lAmount1.trim(),this.encode);
  }
  
  //setter of 数量2 of setter
  public void setAmount2(String lAmount2){
    if (SIUtil.isNull(lAmount2)) lAmount2="";
    this.amount2=SIUtil.changeTo(lAmount2.trim(),this.encode);
  }
  
  //setter of 数量3 of setter
  public void setAmount3(String lAmount3){
    if (SIUtil.isNull(lAmount3)) lAmount3="";
    this.amount3=SIUtil.changeTo(lAmount3.trim(),this.encode);
  }
  
  //setter of 数量4 of setter
  public void setAmount4(String lAmount4){
    if (SIUtil.isNull(lAmount4)) lAmount4="";
    this.amount4=SIUtil.changeTo(lAmount4.trim(),this.encode);
  }
  
  //setter of 数量5 of setter
  public void setAmount5(String lAmount5){
    if (SIUtil.isNull(lAmount5)) lAmount5="";
    this.amount5=SIUtil.changeTo(lAmount5.trim(),this.encode);
  }
  
  //setter of 画像URL1 of setter
  public void setPictureUrl1(String lPictureUrl1) {
    if (SIUtil.isNull(lPictureUrl1)) lPictureUrl1="";
    this.pictureUrl1=SIUtil.changeTo(lPictureUrl1.trim(),this.encode);
  }
  
  //setter of 画像URL2 of setter
  public void setPictureUrl2(String lPictureUrl2) {
    if (SIUtil.isNull(lPictureUrl2)) lPictureUrl2="";
    this.pictureUrl2=SIUtil.changeTo(lPictureUrl2.trim(),this.encode);
  }
  
  //setter of 画像URL3 of setter
  public void setPictureUrl3(String lPictureUrl3) {
      if (SIUtil.isNull(lPictureUrl3)) lPictureUrl3="";
      this.pictureUrl3=SIUtil.changeTo(lPictureUrl3.trim(),this.encode);
  }
  
  //setter of 画像URL4 of setter
  public void setPictureUrl4(String lPictureUrl4) {
      if (SIUtil.isNull(lPictureUrl4)) lPictureUrl4="";
      this.pictureUrl4=SIUtil.changeTo(lPictureUrl4.trim(),this.encode);
  }
  
  //setter of 画像URL5 of setter
  public void setPictureUrl5(String lPictureUrl5) {
      if (SIUtil.isNull(lPictureUrl5)) lPictureUrl5="";
      this.pictureUrl5=SIUtil.changeTo(lPictureUrl5.trim(),this.encode);
  }
  
  //買取希望時期 of setter
  public void setPurchaseHopeTime(String lPurchaseHopeTime){
    if (SIUtil.isNull(lPurchaseHopeTime))lPurchaseHopeTime="";
    this.purchaseHopeTime =lPurchaseHopeTime;
  }
  
  //詳細 of setter
  public void setDetails(String lDetails){
    if (SIUtil.isNull(lDetails))lDetails="";
    this.details =lDetails;
  }

  //顧客コード of setter
  public void setCustCode(String val) {
    if (SIUtil.isNull(val))
      val = "";
    val = SIUtil.changeTo(val.trim(), this.encode);
    this.custCode = val;
  }

  //氏名 of setter
  public void setCustName(String val) {
    if (SIUtil.isNull(val))
      val = "";
    this.custName = SIUtil.changeTo(val.trim(), this.encode);
  }

  //フリガナ of setter
  public void setCustPronName(String val) {
    if (SIUtil.isNull(val))
      val = "";
    this.custPronName = SIUtil.changeTo(val.trim(), this.encode);
  }

  //郵便番号1 of setter
  public void setPostCode1(String val) {
    if (SIUtil.isNull(val))
      val = "";
    val = SIUtil.changeTo(val.trim(), this.encode);
    this.postCode1 = val;
  }

  //郵便番号2 of setter
  public void setPostCode2(String val) {
    if (SIUtil.isNull(val))
      val = "";
    val = SIUtil.changeTo(val.trim(), this.encode);
    this.postCode2 = val;
  }
  
  //住所1 of setter
  public void setAddress1(String val) {
    if (SIUtil.isNull(val))
      val = "";
    this.address1 = SIUtil.changeTo(val.trim(), this.encode);
  }

  //住所2 of setter
  public void setAddress2(String val) {
    if (SIUtil.isNull(val))
      val = "";
    this.address2 = SIUtil.changeTo(val.trim(), this.encode);
  }

  //住所3 of setter
  public void setAddress3(String val) {
    if (SIUtil.isNull(val))
      val = "";
    this.address3 = SIUtil.changeTo(val.trim(), this.encode);
  }
  
  //連絡先電話番号1 of setter
  public void setTel1(String val) {
    if (SIUtil.isNull(val))
      val = "";
    val = SIUtil.changeTo(val.trim(), this.encode);
    this.tel1 = val;
  }
  
  //連絡先電話番号2 of setter
  public void setTel2(String val) {
    if (SIUtil.isNull(val))
      val = "";
    val = SIUtil.changeTo(val.trim(), this.encode);
    this.tel2 = val;
  }

  //連絡先FAX番号 of setter
  public void setFax(String val) {
    if (SIUtil.isNull(val))
      val = "";
    val = SIUtil.changeTo(val.trim(), this.encode);
    this.fax = val;
  }

  //会社名 of setter
  public void setCompanyName(String val) {
    if (SIUtil.isNull(val))
      val = "";
    this.companyName = SIUtil.changeTo(val.trim(), this.encode);
  }
  
  //メールアドレス of setter
  public void setEmail(String val) {
    if (SIUtil.isNull(val))
      val = "";
    this.email = SIUtil.changeTo(val.trim(), this.encode);
  }
  
  //郵便番号1(他) of setter
  public void setPostCodeOther1(String lPostCodeOther1) {
    if (SIUtil.isNull(lPostCodeOther1))
        lPostCodeOther1 = "";
    lPostCodeOther1 = SIUtil.changeTo(lPostCodeOther1.trim(), this.encode);
    this.postCodeOther1 = lPostCodeOther1;
  }

  //郵便番号2(他) of setter
  public void setPostCodeOther2(String lPostCodeOther2) {
    if (SIUtil.isNull(lPostCodeOther2))
        lPostCodeOther2 = "";
    lPostCodeOther2 = SIUtil.changeTo(lPostCodeOther2.trim(), this.encode);
    this.postCodeOther2 = lPostCodeOther2;
  }
  
  //住所1(他) of setter
  public void setAddressOther1(String lAddressOther1) {
    if (SIUtil.isNull(lAddressOther1))
        lAddressOther1 = "";
    this.addressOther1 = SIUtil.changeTo(lAddressOther1.trim(), this.encode);
  }

  //住所2(他) of setter
  public void setAddressOther2(String lAddressOther2) {
    if (SIUtil.isNull(lAddressOther2))
        lAddressOther2 = "";
    this.addressOther2 = SIUtil.changeTo(lAddressOther2.trim(), this.encode);
  }

  //住所3(他) of setter
  public void setAddressOther3(String lAddressOther3) {
    if (SIUtil.isNull(lAddressOther3))
        lAddressOther3 = "";
    this.addressOther3 = SIUtil.changeTo(lAddressOther3.trim(), this.encode);
  }
  
  //連絡先電話番号1(他) of setter
  public void setTelOther1(String lTelOther1) {
    if (SIUtil.isNull(lTelOther1))
        lTelOther1 = "";
    lTelOther1 = SIUtil.changeTo(lTelOther1.trim(), this.encode);
    this.telOther1 = lTelOther1;
  }


  //商品名1 of getter
  public String getCmdtyName1() {
    return this.cmdtyName1;
  }
  
  //商品名2 of getter
  public String getCmdtyName2() {
    return this.cmdtyName2;
  }
  
  //商品名3 of getter
  public String getCmdtyName3() {
    return this.cmdtyName3;
  }
  
  //商品名4 of getter
  public String getCmdtyName4() {
    return this.cmdtyName4;
  }
  
  //商品名5 of getter
  public String getCmdtyName5() {
    return this.cmdtyName5;
  }
  
  //購入時期1 of getter
  public String getPurchaseTime1() {
    return this.purchaseTime1;
  }
  
  //購入時期2 of getter
  public String getPurchaseTime2() {
    return this.purchaseTime2;
  }
  
  //購入時期3 of getter
  public String getPurchaseTime3() {
    return this.purchaseTime3;
  }
  
  //購入時期4 of getter
  public String getPurchaseTime4() {
    return this.purchaseTime4;
  }
  
  //購入時期5 of getter
  public String getPurchaseTime5() {
    return this.purchaseTime5;
  }
  
  //使用年数1 of getter
  public String getUsedYear1() {
    return this.usedYear1;
  }
  
  //使用年数2 of getter
  public String getUsedYear2() {
    return this.usedYear2;
  }
  
  //使用年数3 of getter
  public String getUsedYear3() {
    return this.usedYear3;
  }
  
  //使用年数4 of getter
  public String getUsedYear4() {
    return this.usedYear4;
  }
  
  //使用年数5 of getter
  public String getUsedYear5() {
    return this.usedYear5;
  }
  
  //数量1 of getter
  public String getAmount1() {
    return this.amount1;
  }
  
  //数量2 of getter
  public String getAmount2() {
    return this.amount2;
  }
  
  //数量3 of getter
  public String getAmount3() {
    return this.amount3;
  }
  
  //数量4 of getter
  public String getAmount4() {
    return this.amount4;
  }
  
  //数量5 of getter
  public String getAmount5() {
    return this.amount5;
  }
  
  //画像URL1 of getter
  public String getPictureUrl1() {
    return this.pictureUrl1;
  }
  
  //画像URL2 of getter
  public String getPictureUrl2() {
    return this.pictureUrl2;
  }
  
  //画像URL3 of getter
  public String getPictureUrl3() {
    return this.pictureUrl3;
  }
  
  //画像URL4 of getter
  public String getPictureUrl4() {
    return this.pictureUrl4;
  }
  
  //画像URL5 of getter
  public String getPictureUrl5() {
    return this.pictureUrl5;
  }
  
  //買取希望時期 of getter
  public String getPurchaseHopeTime() {
    return this.purchaseHopeTime;
  }
  
  //詳細 of getter
  public String getDetails() {
    return this.details;
  }
  
  //顧客コード of getter
  public String getCustCode() {
    return this.custCode;
  }

  //氏名 of getter
  public String getCustName() {
    return this.custName;
  }

  //フリガナ of getter
  public String getCustPronName() {
    return this.custPronName;
  }
  
  //郵便番号1 of getter
  public String getPostCode1() {
    return this.postCode1;
  }

  //郵便番号2 of getter
  public String getPostCode2() {
    return this.postCode2;
  }
  
  //住所1 of getter
  public String getAddress1() {
    return this.address1;
  }

  //住所2 of getter
  public String getAddress2() {
    return this.address2;
  }

  //住所3 of getter
  public String getAddress3() {
    return this.address3;
  }

  //住所まとめ
  public String getAddress() {
    return getAddress1() + getAddress2() + getAddress3();
  }
  
  //連絡先電話番号1 of getter
  public String getTel1() {
    return this.tel1;
  }
  
  //連絡先電話番号2 of getter
  public String getTel2() {
    return this.tel2;
  }
  
  //連絡先FAX番号 of getter
  public String getFax() {
    return this.fax;
  }
  
  //会社名 of getter
  public String getCompanyName() {
    return this.companyName;
  }
  
  //メールアドレス of getter
  public String getEmail() {
    return this.email;
  }

  //郵便番号1(他) of getter
  public String getPostCodeOther1() {
    return this.postCodeOther1;
  }

  //郵便番号2(他) of getter
  public String getPostCodeOther2() {
    return this.postCodeOther2;
  }
  
  //住所1(他) of getter
  public String getAddressOther1() {
    return this.addressOther1;
  }

  //住所2(他) of getter
  public String getAddressOther2() {
    return this.addressOther2;
  }

  //住所3(他) of getter
  public String getAddressOther3() {
    return this.addressOther3;
  }

  //住所まとめ(他)
  public String getAddressOther() {
    return getAddressOther1() + getAddressOther2() + getAddressOther3();
  }
  
  //連絡先電話番号1(他) of getter
  public String getTelOther1() {
    return this.telOther1;
  }


  /**
   * @return
   */
  public Category getLog() {
    return log;
  }

  /**
   * @param category
   */
  public void setLog(Category category) {
    log = category;
  }

  /**
   * @return
   */
  public String getEncode() {
    return encode;
  }

  /**
   * @param string
   */
  public void setEncode(String string) {
    if (SIUtil.isNull(string))
      string = "";
    this.encode = string.trim();
  }

  /**
   * <b>reset </b> 顧客コードから顧客情報を取得するSQLを書き出す
   * 
   * @param Connection
   * @return なし
   * @throws なし
   */
  public void reset(Connection lConnection) throws SIDBAccessException {
    setEncode(SIConfig.SIENCODE_NONE);

    StringBuffer lSqlBuf = new StringBuffer("SELECT aa.*,bb.DiscountRate,");
    lSqlBuf.append("(SELECT CASE WHEN SUM(PointOfIssue)<0 THEN 0 ELSE SUM(PointOfIssue) END AS Point ");
    lSqlBuf.append("FROM PointManMTbl WHERE EnableFlg=1 AND CustCode=aa.CustCode) AS MaxPoint,");
    lSqlBuf.append("(SELECT PayMethodName FROM PayMethodMTbl WHERE PayMethodCode=aa.PayMethodCode AND MallShopCode=");
    lSqlBuf.append(SIDBUtil.SQL2Str(SIConfig.SIMALL.getMallShopCode(), ") AS PayMethodName "));
    lSqlBuf.append("FROM CustTbl").append(SIDBMultiConf.SIALIAS_CURR_NAME).append("aa,");
    lSqlBuf.append("MemberLevelMTbl").append(SIDBMultiConf.SIALIAS_CURR_NAME).append("bb ");
    lSqlBuf.append("WHERE aa.MemberLevelCode=bb.MemberLevelCode ");
    lSqlBuf.append("AND aa.CustCode=" + SIDBUtil.SQL2Str(getCustCode()));

    setup(lConnection, lSqlBuf.toString());
  }

  /**
   * <b>setup </b> resetで取得したSQLを実行し、顧客情報をセットする
   * 
   * @param Connection
   * @return なし
   * @throws なし
   */
  private void setup(Connection lConnection, String lSql) {
    Statement lStatement = null;
    ResultSet lResultSet = null;
    try {
      log.debug("setup:lSql=" + lSql);

      lStatement = lConnection.createStatement();
      lResultSet = lStatement.executeQuery(lSql);

      if (lResultSet.next()) {
        this.setEncode(SIConfig.SIENCODE_NONE);
        this.setCustName(lResultSet.getString("custName")); //お客様名
        this.setCustPronName(lResultSet.getString("custPronName")); //お客様名カナ
        this.setPostCode1(lResultSet.getString("postCode1")); //郵便番号1
        this.setPostCode2(lResultSet.getString("postCode2")); //郵便番号2
        this.setAddress1(lResultSet.getString("address1")); //住所１
        this.setAddress2(lResultSet.getString("address2")); //住所２
        this.setAddress3(lResultSet.getString("address3")); //住所３
        this.setTel1(lResultSet.getString("storetel")); //店舗電話番号
        this.setTel2(lResultSet.getString("tel")); //連絡先電話番号
        this.setFax(lResultSet.getString("fax")); //連絡先FAX番号
        this.setCompanyName(lResultSet.getString("companyName")); //会社名
        this.setEmail(lResultSet.getString("email")); //メールアドレス      
      }
    } catch (SQLException sqle) {
      sqle.printStackTrace();
    } finally {
      SIDBUtil.close(lStatement, lResultSet);
    }
  }
}