/*
 * MosP - Mind Open Source Project    http://www.mosp.jp/
 * Copyright (C) MIND Co., Ltd.       http://www.e-mind.co.jp/
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package jp.mosp.kintai.system.vo;

import javax.servlet.http.HttpServletRequest;

import jp.mosp.common.CommonConst;
import jp.mosp.common.MosPVo;
import jp.mosp.common.common.MospException;
import jp.mosp.kintai.common.dto.MSyozokuDto;

/**
 * @author yoshida
 *
 */
public class SyozokuMasterCardVo extends MosPVo {
	
	private static final long	serialVersionUID	= 9059074237970050656L;
	
	// 定数
	/**
	 * 
	 */
	public static final int		MODE_INSERT			= 0;
	/**
	 * 
	 */
	public static final int		MODE_UPDATE			= 1;
	/**
	 * 
	 */
	public static final int		MODE_SYSTEM			= 2;
	
	// パラメーター名
	/**
	 * 
	 */
	public static final String	PRM_TXT_S_CODE1		= "txtSCode1";
	/**
	 * 
	 */
	public static final String	PRM_TXT_S_CODE2		= "txtSCode2";
	/**
	 * 
	 */
	public static final String	PRM_TXT_S_CODE3		= "txtSCode3";
	/**
	 * 
	 */
	public static final String	PRM_TXT_S_NAME		= "txtSName";
	
	// フィールド
	private String				txtSCode1;
	private String				txtSCode2;
	private String				txtSCode3;
	private String				txtSName;
	
	// モード(0：新規登録、1：更新)
	private int					mode;
	
	// フィールド名及び制限
	/**
	 * 
	 */
	public String				NAM_S_CODE;
	/**
	 * 
	 */
	public String				NAM_S_CODE1;
	/**
	 * 
	 */
	public String				NAM_S_CODE2;
	/**
	 * 
	 */
	public String				NAM_S_CODE3;
	/**
	 * 
	 */
	public String				NAM_S_NAME;
	
	/**
	 * 
	 */
	public int					LEN_S_CODE1;
	/**
	 * 
	 */
	public int					LEN_S_CODE2;
	/**
	 * 
	 */
	public int					LEN_S_CODE3;
	/**
	 * 
	 */
	public int					LEN_S_NAME;
	

	/**
	 * 
	 */
	public SyozokuMasterCardVo() {
		super();
		mode = MODE_INSERT;
		setViewPath(getClassName());
	}
	
	@Override
	protected void setSubTitle() {
		subTitle = CommonConst.TTL_UNIT_MASTER;
		aryMenu = new String[][]{ { CMD_MENU_SYSTEM2, CommonConst.NAM_TO_MENU } };
	}
	
	@Override
	protected void setFieldsName() {
		NAM_S_CODE = CommonConst.NAM_STATION_CODE;
		NAM_S_CODE1 = NAM_S_CODE + "1";
		NAM_S_CODE2 = NAM_S_CODE + "2";
		NAM_S_CODE3 = NAM_S_CODE + "3";
		NAM_S_NAME = CommonConst.NAM_COMMON_MEISYO;
		LEN_S_CODE1 = 2;
		LEN_S_CODE2 = 2;
		LEN_S_CODE3 = 2;
		LEN_S_NAME = 20;
	}
	
	/**
	 * パラメータ設定
	 */
	@Override
	public void setParams(HttpServletRequest request) {
		txtSCode1 = request.getParameter(PRM_TXT_S_CODE1);
		txtSCode2 = request.getParameter(PRM_TXT_S_CODE2);
		txtSCode3 = request.getParameter(PRM_TXT_S_CODE3);
		txtSName = request.getParameter(PRM_TXT_S_NAME);
	}
	
	/**
	 * フィールド設定
	 * @param dto 所属リスト
	 */
	public void setFields(MSyozokuDto dto) {
		// データの設定
		// dto.getSCode()の長さによって３つに分ける
		txtSCode1 = dto.getSCode().substring(0, 2);
		if (dto.getSCode().length() > 3) {
			txtSCode2 = dto.getSCode().substring(2, 4);
		}
		if (dto.getSCode().length() > 5) {
			txtSCode3 = dto.getSCode().substring(4, 6);
		}
		txtSName = dto.getSName();
	}
	
	/**
	 * フィールド設定(DTOに対するVO情報のセット)
	 * @param dto 設定対象DTO
	 */
	public void setDtoFields(MSyozokuDto dto) {
		dto.setSCode(txtSCode1 + txtSCode2 + txtSCode3);
		dto.setSName(txtSName);
	}
	
	/**
	 * フィールドの妥当性確認
	 * @throws MospException	MosP例外処理が発生した場合
	 */
	public void validate() throws MospException {
		// 妥当性確認開始時処理
		startValidation();
		//必須確認
		checkRequired(txtSCode1, NAM_S_CODE1, PRM_TXT_S_CODE1);
		checkRequired(txtSName, NAM_S_NAME, PRM_TXT_S_NAME);
		//文字タイプ確認
		checkCode(txtSCode1, NAM_S_CODE1, PRM_TXT_S_CODE1);
		checkCode(txtSCode2, NAM_S_CODE2, PRM_TXT_S_CODE2);
		checkCode(txtSCode3, NAM_S_CODE3, PRM_TXT_S_CODE3);
		//文字列長確認
		checkLength(txtSCode1, LEN_S_CODE1, NAM_S_CODE1, PRM_TXT_S_CODE1);
		checkLength(txtSCode2, LEN_S_CODE2, NAM_S_CODE2, PRM_TXT_S_CODE2);
		checkLength(txtSCode3, LEN_S_CODE3, NAM_S_CODE3, PRM_TXT_S_CODE3);
		checkLength(txtSName, LEN_S_NAME, NAM_S_NAME, PRM_TXT_S_NAME);
		// 妥当性確認終了時処理
		endValidation();
	}
	
	@Override
	public String getDirectJs(Class<?> cls, Object obj) throws IllegalAccessException {
		StringBuffer sb = new StringBuffer();
		sb.append(super.getDirectJs(cls, obj));
		sb.append("var MODE = ");
		sb.append(mode);
		sb.append(";");
		return sb.toString();
	}
	
	// アクセサメッソド
	
	/**
	 * @return txtSCode1
	 */
	public String getEscTxtSCode1() {
		return escapeHTML(txtSCode1);
	}
	
	/**
	 * @return txtSCode2
	 */
	public String getEscTxtSCode2() {
		return escapeHTML(txtSCode2);
	}
	
	/**
	 * @return txtSCode3
	 */
	public String getEscTxtSCode3() {
		return escapeHTML(txtSCode3);
	}
	
	/**
	 * @return txtSName
	 */
	public String getEscTxtSName() {
		return escapeHTML(txtSName);
	}
	
	/**
	 * @return txtSCode1
	 */
	public String getTxtSCode1() {
		return txtSCode1;
	}
	
	/**
	 * @return txtSCode2
	 */
	public String getTxtSCode2() {
		return txtSCode2;
	}
	
	/**
	 * @return txtSCode3
	 */
	public String getTxtSCode3() {
		return txtSCode3;
	}
	
	/**
	 * @return txtSName
	 */
	public String getTxtSName() {
		return txtSName;
	}
	
	/**
	 * @return mode
	 */
	public int getMode() {
		return mode;
	}
	
	/**
	 * @param txtSCode1 セットする txtSCode1
	 */
	public void setTxtSCode1(String txtSCode1) {
		this.txtSCode1 = txtSCode1;
	}
	
	/**
	 * @param txtSCode2 セットする txtSCode2
	 */
	public void setTxtSCode2(String txtSCode2) {
		this.txtSCode2 = txtSCode2;
	}
	
	/**
	 * @param txtSCode3 セットする txtSCode3
	 */
	public void setTxtSCode3(String txtSCode3) {
		this.txtSCode3 = txtSCode3;
	}
	
	/**
	 * @param txtSName セットする txtSName
	 */
	public void setTxtSName(String txtSName) {
		this.txtSName = txtSName;
	}
	
	/**
	 * @param mode セットする mode
	 */
	public void setMode(int mode) {
		this.mode = mode;
	}
	
}
