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

import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

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

public class SICompany extends SIBasic {
  
  // 支店コード
  private String companyCode = "";
  
  // 支店名
  private String companyName = "";
  
  // メールアドレス
  private String companyMail = "";
  
  // 支店区分
  private int companyType = 1;
  
  // 紐付け担当者
  private String chargeCount = "0";
  
  // 公開フラグ
  private String publicFlg= "0";
  
  // 引き当て優先順位ベース
  private String priorityBase = "0";
  
  // 郵便番号１
  private String postCode1 = "";
  
  // 郵便番号２
  private String postCode2 = "";
  
  // 住所１
  private String address1 = "";
  
  // 住所２
  private String address2 = "";
  
  // 住所３
  private String address3 = "";
  
  // 電話番号１
  private String tel1 = "";
  
  // 電話番号２
  private String tel2 = "";
  
  // FAX番号１
  private String fax1 = "";
  
  // FAX番号２
  private String fax2 = "";
  
  // getter of 支店コード
  public String getCompanyCode() {
    return companyCode;
  }
  
  // getter of 支店名
  public String getCompanyName() {
    return companyName;
  }
  
  // getter of メールアドレス
  public String getCompanyMail() {
    return companyMail;
  }
  
  // getter of 支店区分
  public int getCompanyType() {
    return companyType;
  }
  
  // getter of 紐付け担当者
  public String getChargeCount() {
    return this.chargeCount;
  }
  
  // getter of 公開フラグ
  public String getPublicFlg() {
    return this.publicFlg;
  }
  
  // getter of 引き当て優先順位ベース
  public String getPriorityBase() {
    return this.priorityBase;
  }
  
  // getter of 郵便番号１
  public String getPostCode1() {
    return postCode1;
  }
  
  // getter of 郵便番号２
  public String getPostCode2() {
    return postCode2;
  }
  
  // getter of 住所１
  public String getAddress1() {
    return address1;
  }
  
  // getter of 住所２
  public String getAddress2() {
    return address2;
  }
  
  // getter of 住所３
  public String getAddress3() {
    return address3;
  }
  
  // getter of 電話番号１
  public String getTel1() {
    return tel1;
  }
  
  // getter of 電話番号２
  public String getTel2() {
    return tel2;
  }
  
  // getter of FAX番号１
  public String getFax1() {
    return fax1;
  }
  
  // getter of FAX番号２
  public String getFax2() {
    return fax2;
  }
  
  // setter of 支店コード
  public void setCompanyCode(String lCompanyCode) {
    if (SIUtil.isNull(lCompanyCode)) lCompanyCode = "";
    this.companyCode = SIUtil.changeTo(lCompanyCode.trim(), this.encode);
  }
  
  // setter of 支店名
  public void setCompanyName(String lCompanyName) {
    if (SIUtil.isNull(lCompanyName)) lCompanyName = "";
    this.companyName = SIUtil.changeTo(lCompanyName.trim(), this.encode);
  }
  
  // setter of メールアドレス
  public void setCompanyMail(String lCompanyMail) {
    if (SIUtil.isNull(lCompanyMail)) lCompanyMail = "";
    this.companyMail = SIUtil.changeTo(lCompanyMail.trim(), this.encode);
  }
  
  // setter of 支店区分
  public void setCompanyType(int lCompanyType) {
    this.companyType = lCompanyType;
  }
  
  // setter of 紐付け担当者
  public void setChargeCount(String lChargeCount) {
    if (SIUtil.isNull(lChargeCount)) lChargeCount = "0";
    this.chargeCount = SIUtil.changeTo(lChargeCount.trim(), this.encode);
  }
  
  // setter of 公開フラグ
  public void setPublicFlg(String lPublicFlg) {
    if (SIUtil.isNull(lPublicFlg)) lPublicFlg = "0";
    this.publicFlg = SIUtil.changeTo(lPublicFlg.trim(), this.encode);
  }
  
  // setter of 引き当て優先順位ベース
  public void setPriorityBase(String lPriorityBase) {
    if (SIUtil.isNull(lPriorityBase)) lPriorityBase = "0";
    this.priorityBase = SIUtil.changeTo(lPriorityBase.trim(), this.encode);
  }
  
  // setter of 郵便番号１
  public void setPostCode1(String postCode1) {
    if (SIUtil.isNull(postCode1)) postCode1 = "";
    this.postCode1 = postCode1;
  }
  
  // setter of 郵便番号２
  public void setPostCode2(String postCode2) {
    if (SIUtil.isNull(postCode2)) postCode2 = "";
    this.postCode2 = postCode2;
  }
  
  // setter of 住所１
  public void setAddress1(String address1) {
    if (SIUtil.isNull(address1)) address1 = "";
    this.address1 = address1;
  }
  
  // setter of 住所２
  public void setAddress2(String address2) {
    if (SIUtil.isNull(address2)) address2 = "";
    this.address2 = address2;
  }
  
  // setter of 住所３
  public void setAddress3(String address3) {
    if (SIUtil.isNull(address3)) address3 = "";
    this.address3 = address3;
  }
  
  // setter of 電話番号１
  public void setTel1(String tel1) {
    if (SIUtil.isNull(tel1)) tel1 = "";
    this.tel1 = tel1;
  }
  
  // setter of 電話番号２
  public void setTel2(String tel2) {
    if (SIUtil.isNull(tel2)) tel2 = "";
    this.tel2 = tel2;
  }
  
  // setter of FAX番号１
  public void setFax1(String fax1) {
    if (SIUtil.isNull(fax1)) fax1 = "";
    this.fax1 = fax1;
  }
  
  // setter of FAX番号２
  public void setFax2(String fax2) {
    if (SIUtil.isNull(fax2)) fax2 = "";
    this.fax2 = fax2;
  }
  
  /**
   * <b>getNameCollection</b> プルダウン作成
   * 
   * @param lConnection
   * @param custCode
   * @return
   */
  public static Collection getNameCollection(Connection lConnection) {
    StringBuffer lSqlBuf = new StringBuffer("SELECT branchname,branchcode FROM branchtbl a ");
    lSqlBuf.append(" WHERE EXISTS (SELECT * FROM CHARGETBL b ");
    lSqlBuf.append("  WHERE a.branchcode = b.belongingbranchcode) ");
    lSqlBuf.append(" ORDER BY branchcode ASC");
    
    Collection lResultColl = new ArrayList();
    
    try {
      lResultColl = SIDBUtil.getCollection(lConnection, lSqlBuf.toString(), true);
      SINameValue resultObj = new SINameValue();
      for (Iterator resultIte = lResultColl.iterator(); resultIte.hasNext();) {
        resultObj = (SINameValue) resultIte.next();
        if (resultObj.getName().equals("選択してください")) {
          resultObj.setValue("XX");
          break;
        }
      }
    } catch (SIDBAccessException e) {
      e.printStackTrace();
    }
    
    return lResultColl;
  }
  public static Collection getNameCollectionFull(Connection lConnection) {
    Collection lResultColl = new ArrayList();
    String lSql = "SELECT branchname,branchcode FROM branchtbl WHERE branchcode<>'999' ORDER BY branchcode ASC";
    try {
      lResultColl = SIDBUtil.getCollection(lConnection, lSql, true);
    } catch (SIDBAccessException e) {
      e.printStackTrace();
    }
    return lResultColl;
  }
  
  public static Collection getCollection2(Connection lConnection) {
    StringBuffer lSqlBuf = new StringBuffer("SELECT branchname,branchcode FROM branchtbl a ");
    lSqlBuf.append(" WHERE EXISTS (SELECT * FROM CHARGETBL b ");
    lSqlBuf.append("  WHERE a.branchcode = b.belongingbranchcode) ");
    lSqlBuf.append(" ORDER BY branchcode ASC");
    
    Collection lResultColl = new ArrayList();
    
    try {
      lResultColl = SIDBUtil.getCollection(lConnection, lSqlBuf.toString(), true);
    } catch (SIDBAccessException e) {
      e.printStackTrace();
    }
    
    return lResultColl;
  }
  
}