/*
 * 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 java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import jp.mosp.common.CommonConst;
import jp.mosp.common.MosPMenuConst;
import jp.mosp.common.MosPVo;
import jp.mosp.common.common.MospException;
import jp.mosp.common.dto.MCodeDto;
import jp.mosp.common.utils.StringUtil;

/**
 * @author yoshida
 *
 */
public class LateReasonCardVo extends MosPVo {
	
	private static final long	serialVersionUID	= -6715261187985051137L;
	
	// パラメータ名
	/**
	 * txtLateReason
	 */
	public static final String	PRM_TXT_LATE_REASON	= "txtLateReason";
	
	// フィールド
	private String[]			aryLateReason;
	private String[]			aryTxtLateReason;
	
	// フィールド名及び制限
	/**
	 * 
	 */
	public String				NAM_LATE_REASON;
	/**
	 * 
	 */
	public int					LEN_LATE_REASON;
	

	/**
	 * コンストラクタ
	 */
	public LateReasonCardVo() {
		super();
		setViewPath(getClassName());
		aryLateReason = new String[0];
	}
	
	@Override
	protected void setSubTitle() {
		subTitle = CommonConst.TTL_LATE_REASON;
		createAryMenu(CMD_MENU_SYSTEM2, MosPMenuConst.getMenuReasonMaster());
	}
	
	@Override
	protected void setFieldsName() {
		NAM_LATE_REASON = CommonConst.NAM_ARRIVE_LATE + CommonConst.NAM_REASON;
		LEN_LATE_REASON = 15;
	}
	
	@Override
	public void setParams(HttpServletRequest request) {
		aryTxtLateReason = request.getParameterValues(PRM_TXT_LATE_REASON);
	}
	
	/**
	 * フィールド設定
	 * @param listLate	遅刻理由リスト
	 */
	@Override
	public void setFields(List<?> listLate) {
		// 配列の初期化
		aryLateReason = StringUtil.getBlankArrayOneDimension(10);
		// データの設定
		int i = 0;
		Iterator<?> it = listLate.iterator();
		while (it.hasNext()) {
			MCodeDto dto = (MCodeDto)it.next();
			aryLateReason[i] = escapeHTML(dto.getTName());
			i++;
		}
	}
	
	/**
	 * フィールドの妥当性確認
	 * @throws MospException MosP例外処理が発生した場合
	 */
	public void validate() throws MospException {
		// 妥当性確認開始時処理
		startValidation();
		for (int i = 0; i < aryTxtLateReason.length; i++) {
			// 文字列長確認
			checkLength(aryTxtLateReason[i], LEN_LATE_REASON, NAM_LATE_REASON, PRM_TXT_LATE_REASON + i);
		}
		// 妥当性確認終了時処理
		endValidation();
	}
	
	// アクセサメソッド
	/**
	 * @return aryLateReason
	 */
	public String[] getAryLateReason() {
		return aryLateReason.clone();
	}
	
	/**
	 * @return aryTxtLateReason
	 */
	public String[] getAryTxtLateReason() {
		return aryTxtLateReason.clone();
	}
	
	/**
	 * @param aryLateReason セットする aryLateReason
	 */
	public void setAryLateReason(String[] aryLateReason) {
		this.aryLateReason = aryLateReason.clone();
	}
	
	/**
	 * @param aryTxtLateReason セットする aryTxtLateReason
	 */
	public void setAryTxtLateReason(String[] aryTxtLateReason) {
		this.aryTxtLateReason = aryTxtLateReason.clone();
	}
	
}
