/*
 * 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.MKihonDto;

/**
 * @author yoshida
 *
 */
public class FirstHumanAccountCardVo extends MosPVo {
	
	private static final long	serialVersionUID	= 2220781986812948427L;
	
	// 定数
	/**
	 * 
	 */
	public static final int		MODE_INSERT			= 0;
	/**
	 * 
	 */
	public static final int		MODE_VIEW			= 1;
	
	// パラメータ名
	/**
	 * 
	 */
	public static final String	PRM_TXT_K_CODE		= "txtKCode";
	/**
	 * 
	 */
	public static final String	PRM_TXT_USER_NAME	= "txtUserName";
	/**
	 * 
	 */
	public static final String	PRM_PLT_OFFICE		= "pltOffice";
	/**
	 * 
	 */
	public static final String	PRM_PLT_SECTION		= "pltSection";
	/**
	 * 
	 */
	public static final String	PRM_PLT_POSITION	= "pltPosition";
	
	// フィールド
	private String				txtKCode;
	private String				txtUserName;
	private String				pltOffice;
	private String				pltSection;
	private String				pltPosition;
	
	// プルダウンリスト
	/**
	 * 
	 */
	public String[][]			aryPltOfficeAll;
	/**
	 * 
	 */
	public String[][]			aryPltSectionAll;
	/**
	 * 
	 */
	public String[][]			aryPltPosition;
	
	// モード(0：新規登録、1:表示)
	private int					mode;
	
	// フィールド名及び制限
	/**
	 * 
	 */
	public String				NAM_K_CODE;
	/**
	 * 
	 */
	public String				NAM_USER_NAME;
	/**
	 * 
	 */
	public String				NAM_OFFICE;
	/**
	 * 
	 */
	public String				NAM_SECTION;
	/**
	 * 
	 */
	public String				NAM_POSITION;
	/**
	 * 
	 */
	public int					LEN_K_CODE;
	/**
	 * 
	 */
	public int					LEN_USER_NAME;
	

	/**
	 * コンストラクタ
	 */
	public FirstHumanAccountCardVo() {
		super();
		setViewPath(getClassName());
		mode = 0;
	}
	
	@Override
	protected void setSubTitle() {
		subTitle = CommonConst.TTL_ACCOUNT_MASTER;
		aryMenu = new String[][]{ { CMD_MENU_SYSTEM2, CommonConst.NAM_TO_MENU } };
	}
	
	@Override
	protected void setFieldsName() {
		NAM_K_CODE = CommonConst.NAM_K_CODE;
		NAM_USER_NAME = CommonConst.NAM_USER_NAME;
		NAM_OFFICE = CommonConst.NAM_OFFICE;
		NAM_SECTION = CommonConst.NAM_STATION;
		NAM_POSITION = CommonConst.NAM_POSITION1;
		LEN_K_CODE = CommonConst.LEN_K_CODE;
		LEN_USER_NAME = CommonConst.LEN_K_NAME;
	}
	
	/**
	 * 初期値設定
	 */
	public void setDefaultValues() {
		txtKCode = "";
		txtUserName = "";
	}
	
	@Override
	public void setParams(HttpServletRequest request) {
		txtKCode = request.getParameter(PRM_TXT_K_CODE);
		txtUserName = request.getParameter(PRM_TXT_USER_NAME);
		pltOffice = request.getParameter(PRM_PLT_OFFICE);
		pltSection = request.getParameter(PRM_PLT_SECTION);
		pltPosition = request.getParameter(PRM_PLT_POSITION);
	}
	
	/**
	 * フィールド設定
	 * @param dto	対象DTO
	 */
	public void setFields(MKihonDto dto) {
		txtKCode = dto.getKCode();
		txtUserName = dto.getSimei();
		pltOffice = dto.getJCode();
		pltSection = dto.getSCode();
		pltPosition = dto.getYCode() + CommonConst.STR_TIME_SEPARATOR + dto.getTokyu();
	}
	
	/**
	 * フィールドの妥当性確認
	 * @throws MospException MosP例外処理が発生した場合
	 */
	public void validate() throws MospException {
		// 妥当性確認開始時処理
		startValidation();
		// 必須確認
		checkRequired(txtKCode, NAM_K_CODE, PRM_TXT_K_CODE);
		checkRequired(txtUserName, NAM_USER_NAME, PRM_TXT_USER_NAME);
		// コード確認
		checkCode(txtKCode, NAM_K_CODE, PRM_TXT_K_CODE);
		// 文字列長確認
		checkLength(txtKCode, LEN_K_CODE, NAM_K_CODE, PRM_TXT_K_CODE);
		checkLength(txtUserName, LEN_USER_NAME, NAM_USER_NAME, PRM_TXT_USER_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 txtKCode
	 */
	public String getTxtKCode() {
		return txtKCode;
	}
	
	/**
	 * @return txtUserName
	 */
	public String getTxtUserName() {
		return txtUserName;
	}
	
	/**
	 * @return pltOffice
	 */
	public String getPltOffice() {
		return pltOffice;
	}
	
	/**
	 * @return pltSection
	 */
	public String getPltSection() {
		return pltSection;
	}
	
	/**
	 * @return pltPosition
	 */
	public String getPltPosition() {
		return pltPosition;
	}
	
	/**
	 * @return mode
	 */
	public int getMode() {
		return mode;
	}
	
	/**
	 * @param txtKCode セットする txtKCode
	 */
	public void setTxtKCode(String txtKCode) {
		this.txtKCode = txtKCode;
	}
	
	/**
	 * @param txtUserName セットする txtUserName
	 */
	public void setTxtUserName(String txtUserName) {
		this.txtUserName = txtUserName;
	}
	
	/**
	 * @param pltOffice セットする pltOffice
	 */
	public void setPltOffice(String pltOffice) {
		this.pltOffice = pltOffice;
	}
	
	/**
	 * @param pltSection セットする pltSection
	 */
	public void setPltSection(String pltSection) {
		this.pltSection = pltSection;
	}
	
	/**
	 * @param pltPosition セットする pltPosition
	 */
	public void setPltPosition(String pltPosition) {
		this.pltPosition = pltPosition;
	}
	
	/**
	 * @param mode セットする mode
	 */
	public void setMode(int mode) {
		this.mode = mode;
	}
	
}
