package jp.co.sint.basic;

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

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

public class SIStorage extends SIBasic {
  String storageCode = "";
  String storageName = "";
  String email = "";
  String comment = "";
  boolean delFlg = true;
  
  public SIStorage() {}
  
  public SIStorage(String storageCode) {
    this.setStorageCode(storageCode);
  }
  
  public String getComment() {
    return comment;
  }
  
  public void setComment(String comment) {
    if (SIUtil.isNull(comment)) comment = "";
    this.comment = comment;
  }
  
  public boolean isDelflg() {
    return delFlg;
  }
  
  public void setDelFlg(boolean delFlg) {
    this.delFlg = delFlg;
  }
  
  public String getEmail() {
    return email;
  }
  
  public void setEmail(String email) {
    if (SIUtil.isNull(email)) email = "";
    this.email = email;
  }
  
  public String getStorageCode() {
    return storageCode;
  }
  
  public void setStorageCode(String storageCode) {
    if (SIUtil.isNull(storageCode)) storageCode = "";
    this.storageCode = storageCode;
  }
  
  public String getStorageName() {
    return storageName;
  }
  
  public void setStorageName(String storageName) {
    if (SIUtil.isNull(storageName)) storageName = "";
    this.storageName = storageName;
  }
  
  public boolean reset(Connection lConnection) {
    if (SIUtil.isNull(this.storageCode)) return false;
    boolean lResult = false;
    
    Statement lStatement = null;
    ResultSet lResultSet = null;
    
    try{
      lStatement = lConnection.createStatement();
      lResultSet = lStatement.executeQuery("SELECT * FROM storagetbl WHERE storagecode="+SIDBUtil.SQL2Str(this.storageCode));
      if (lResultSet.next()) {
        this.setStorageName(lResultSet.getString("storageName"));
        this.setEmail(lResultSet.getString("email"));
        this.setComment(lResultSet.getString("comment"));
        lResult = true;
      }
    }catch (Exception e) {
      e.printStackTrace();
    }finally{
      SIDBUtil.close(lResultSet, lStatement);
    }
    return lResult;
  }
}
