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

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

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

public class SICharge extends SIBasic {
  
  // 担当者コード
  private String chargeCode = "";
  
  // 担当者名
  private String chargeName = "";
  
  // メールアドレス
  private String email = "";
  
  // 所属支店コード
  private String belongingBranchCode = "";
  
  // 所属支店名
  private String belongingBranchName = "";
  
  // 紐付け受注明細フラグ
  private String detailCount = "0";
  
  // 表示フラグ
  private String enableFlg = "0";
  
  // 本社フラグ
  private String otherAddrFlg = "0";
  
  // getter of 担当者コード
  public String getChargeCode() {
    return chargeCode;
  }
  
  // getter of 担当者名
  public String getChargeName() {
    return chargeName;
  }
  
  // getter of メールアドレス
  public String getEmail() {
    return email;
  }
  
  // getter of 所属支店コード
  public String getBelongingBranchCode() {
    return belongingBranchCode;
  }
  
  // getter of 所属支店名
  public String getBelongingBranchName() {
    return belongingBranchName;
  }
  
  // getter of 紐付け受注明細フラグ
  public String getDetailCount() {
    return this.detailCount;
  }
  
  // getter of 表示フラグ
  public String getEnableFlg() {
    return this.enableFlg;
  }
  
  // getter of 本社フラグ
  public String getOtherAddrFlg() {
    return this.otherAddrFlg;
  }
  
  // setter of 担当者コード
  public void setChargeCode(String lChargeCode) {
    if (SIUtil.isNull(lChargeCode)) lChargeCode = "";
    this.chargeCode = SIUtil.changeTo(lChargeCode.trim(), this.encode);
  }
  
  // setter of 担当者名
  public void setChargeName(String lChargeName) {
    if (SIUtil.isNull(lChargeName)) lChargeName = "";
    this.chargeName = SIUtil.changeTo(lChargeName.trim(), this.encode);
  }
  
  // setter of メールアドレス
  public void setEmail(String lEmail) {
    if (SIUtil.isNull(lEmail)) lEmail = "";
    this.email = SIUtil.changeTo(lEmail.trim(), this.encode);
  }
  
  // setter of 所属支店コード
  public void setBelongingBranchCode(String lBelongingBranchCode) {
    if (SIUtil.isNull(lBelongingBranchCode)) lBelongingBranchCode = "";
    this.belongingBranchCode = SIUtil.changeTo(lBelongingBranchCode.trim(), this.encode);
  }
  
  // setter of 所属支店名
  public void setBelongingBranchName(String lBelongingBranchName) {
    if (SIUtil.isNull(lBelongingBranchName)) lBelongingBranchName = "";
    this.belongingBranchName = SIUtil.changeTo(lBelongingBranchName.trim(), this.encode);
  }
  
  // setter of 紐付け受注明細フラグ
  public void setDetailCount(String lDetailCount) {
    if (SIUtil.isNull(lDetailCount)) lDetailCount = "0";
    this.detailCount = SIUtil.changeTo(lDetailCount.trim(), this.encode);
  }
  
  // setter of 表示フラグ
  public void setEnableFlg(String enableFlg) {
    if (SIUtil.isNull(enableFlg)) enableFlg = "0";
    this.enableFlg = enableFlg;
  }
  
  // setter of 本社フラグ
  public void setOtherAddrFlg(String otherAddrFlg) {
    if (SIUtil.isNull(otherAddrFlg)) otherAddrFlg = "0";
    this.otherAddrFlg = otherAddrFlg;
  }
  
  public static Collection getCollection(Connection lConnection) {
    String lSql = "SELECT chargeName,chargeCode FROM chargetbl ORDER BY chargecode";
    Collection chargeColl = null;
    try {
      chargeColl = SIDBUtil.getCollection(lConnection, lSql, true);
    } catch (SIDBAccessException e) {
      e.printStackTrace();
      chargeColl = new ArrayList();
    } 
    return chargeColl;
  }
  
  public static Collection getCollection(Connection lConnection,String branchCode) {
    String lSql = "SELECT chargeName,chargeCode FROM chargetbl WHERE enableflg='1' AND belongingbranchcode="+SIDBUtil.SQL2Str(branchCode)+" ORDER BY chargecode";
    if (SIUtil.isNull(branchCode)) lSql = "SELECT chargeName,chargeCode FROM chargetbl WHERE enableflg='1' ORDER BY chargecode";
    Collection chargeColl = null;
    try {
      chargeColl = SIDBUtil.getCollection(lConnection, lSql, true);
    } catch (SIDBAccessException e) {
      e.printStackTrace();
      chargeColl = new ArrayList();
    } 
    return chargeColl;
  }
}