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

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import jp.mosp.common.CommonConst;
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 YukyuInformationCardVo extends MosPVo {
	
	private static final long	serialVersionUID		= 8784848856294588759L;
	
	// パラメーター名
	/**
	 * 
	 */
	public static final String	PRM_PLT_CF_MONTH		= "pltCFMonth";
	/**
	 * 
	 */
	public static final String	PRM_TXT_CF_DAYS			= "txtCFDays";
	/**
	 * 
	 */
	public static final String	PRM_PLT_CF_KBN			= "pltCFKbn";
	/**
	 * 
	 */
	public static final String	PRM_PLT_SUPPLY_MODEL	= "pltSupplyModel";
	/**
	 * 
	 */
	public static final String	PRM_TXT_STANDARD		= "txtStandard";
	/**
	 * 
	 */
	public static final String	PRM_TXT_DAYS			= "txtDays";
	/**
	 * 
	 */
	public static final String	PRM_TXT_INFO			= "txtInfo";
	
	// フィールド
	private String				pltCFMonth;
	private String				txtCFDays;
	private String				pltCFKbn;
	private String				pltSupplyModel;
	private String[]			aryTxtStandard;
	private String[]			aryTxtDays;
	private String[]			aryTxtInfo;
	
	// プルダウンリスト
	/**
	 * 
	 */
	public String[][]			aryPltCFKbn;
	/**
	 * 
	 */
	public String[][]			aryPltCFMonth;
	/**
	 * 
	 */
	public String[][]			aryPltSupplyModel;
	
	// フィールド名及び制限
	/**
	 * 
	 */
	public String				NAM_PROCESS_SET_UP;
	/**
	 * 
	 */
	public String				NAM_SUPPLY_CONDITION;
	/**
	 * 
	 */
	public String				NAM_CF_MONTH;
	/**
	 * 
	 */
	public String				NAM_CF_DAYS;
	/**
	 * 
	 */
	public String				NAM_CF_KBN;
	/**
	 * 
	 */
	public String				NAM_SUPPLY_MODEL;
	/**
	 * 
	 */
	public String				NAM_STANDARD;
	/**
	 * 
	 */
	public String				NAM_DAYS;
	/**
	 * 
	 */
	public String				NAM_INFO;
	/**
	 * 
	 */
	public int					LEN_CF_MONTH;
	/**
	 * 
	 */
	public int					LEN_CF_DAYS;
	/**
	 * 
	 */
	public int					LEN_STANDARD;
	/**
	 * 
	 */
	public int					LEN_DAYS;
	/**
	 * 
	 */
	public int					LEN_INFO;
	

	/**
	 * コンストラクタ
	 */
	public YukyuInformationCardVo() {
		super();
		setViewPath(getClassName());
		pltCFMonth = "";
		txtCFDays = "";
		pltCFKbn = "";
		pltSupplyModel = "";
		aryTxtStandard = new String[0];
		aryTxtDays = new String[0];
		aryTxtInfo = new String[0];
	}
	
	@Override
	protected void setSubTitle() {
		subTitle = CommonConst.TTL_PAID_HOLIDAY_MASTER;
		aryMenu = new String[][]{ { CMD_MENU_SYSTEM2, CommonConst.NAM_TO_MENU } };
	}
	
	@Override
	protected void setFieldsName() {
		NAM_PROCESS_SET_UP = CommonConst.NAM_CARRIED_FORWARD + CommonConst.NAM_PROCESS + CommonConst.NAM_SET_UP;
		NAM_SUPPLY_CONDITION = CommonConst.NAM_PAID_HOLIDAY + CommonConst.NAM_SUPPLY + CommonConst.NAM_CONDITION;
		NAM_CF_MONTH = CommonConst.NAM_CARRIED_FORWARD + CommonConst.NAM_PROCESS + CommonConst.NAM_MONTH;
		NAM_CF_DAYS = CommonConst.NAM_CARRIED_FORWARD + CommonConst.NAM_NUMBER_OF_DAYS;
		NAM_CF_KBN = CommonConst.NAM_CARRIED_FORWARD + CommonConst.NAM_COMMON_TYPE;
		NAM_SUPPLY_MODEL = "支給方法";
		NAM_STANDARD = CommonConst.NAM_SUPPLY + CommonConst.NAM_CONDITION;
		NAM_DAYS = CommonConst.NAM_SUPPLY + CommonConst.NAM_NUMBER_OF_DAYS;
		NAM_INFO = CommonConst.NAM_EXPLANATION;
		LEN_CF_MONTH = CommonConst.LEN_MONTH_DAY;
		LEN_CF_DAYS = CommonConst.LEN_MONTH_DAY;
		LEN_STANDARD = 2;
		LEN_DAYS = CommonConst.LEN_MONTH_DAY;
		LEN_INFO = 7;
	}
	
	/**
	 * 初期値設定
	 */
	public void setDefaultValues() {
		aryTxtStandard = StringUtil.getBlankArrayOneDimension(20);
		aryTxtDays = StringUtil.getBlankArrayOneDimension(20);
		aryTxtInfo = StringUtil.getBlankArrayOneDimension(20);
	}
	
	@Override
	public void setParams(HttpServletRequest request) {
		pltCFMonth = request.getParameter(PRM_PLT_CF_MONTH);
		txtCFDays = request.getParameter(PRM_TXT_CF_DAYS);
		pltCFKbn = request.getParameter(PRM_PLT_CF_KBN);
		pltSupplyModel = request.getParameter(PRM_PLT_SUPPLY_MODEL);
		aryTxtStandard = request.getParameterValues(PRM_TXT_STANDARD);
		aryTxtDays = request.getParameterValues(PRM_TXT_DAYS);
		aryTxtInfo = request.getParameterValues(PRM_TXT_INFO);
	}
	
	/**
	 * フィールド設定
	 * @param listYukyuInfo 有休情報リスト
	 */
	@Override
	public void setFields(List<?> listYukyuInfo) {
		// 配列の初期化
		aryTxtStandard = StringUtil.getBlankArrayOneDimension(20);
		aryTxtDays = StringUtil.getBlankArrayOneDimension(20);
		aryTxtInfo = StringUtil.getBlankArrayOneDimension(20);
		//データの設定		
		int i = 0;
		Iterator<?> it = listYukyuInfo.iterator();
		while (it.hasNext()) {
			MCodeDto dto = (MCodeDto)it.next();
			aryTxtStandard[i] = escapeHTML(dto.getTCode());
			aryTxtDays[i] = escapeHTML(dto.getTChange());
			aryTxtInfo[i] = escapeHTML(dto.getTName());
			i++;
		}
	}
	
	/**
	 * フィールドの妥当性確認（有給休暇処理）
	 * @throws MospException 	MosP例外処理が発生した場合
	 */
	public void validate() throws MospException {
		// 妥当性確認開始時処理
		startValidation();
		// 必須確認
		checkRequired(txtCFDays, NAM_CF_DAYS, PRM_TXT_CF_DAYS);
		checkRequired(pltCFKbn, NAM_CF_KBN, PRM_PLT_CF_KBN);
		// 文字列長確認
		checkLength(txtCFDays, LEN_CF_DAYS, NAM_CF_DAYS, PRM_TXT_CF_DAYS);
		// 文字列タイプ確認(半角数字)
		checkNumber(txtCFDays, NAM_CF_DAYS, PRM_TXT_CF_DAYS);
		for (int i = 0; i < aryTxtStandard.length; i++) {
			if (StringUtil.isNotNull(aryTxtStandard[i])) {
				// 文字列タイプ確認(半角数字)
				checkNumber(aryTxtStandard[i], NAM_STANDARD, i, PRM_TXT_STANDARD);
				checkLength(aryTxtStandard[i], LEN_STANDARD, NAM_STANDARD, i, PRM_TXT_STANDARD);
			} else {
				if (StringUtil.isNotNull(aryTxtDays[i])) {
					// 必須確認
					checkRequired(aryTxtStandard[i], NAM_STANDARD, i, PRM_TXT_STANDARD);
					checkRequired(aryTxtInfo[i], NAM_INFO, i, PRM_TXT_INFO);
					// 文字列タイプ確認(半角数字)
					checkNumber(aryTxtStandard[i], NAM_STANDARD, i, PRM_TXT_STANDARD);
					checkNumber(aryTxtDays[i], NAM_DAYS, i, PRM_TXT_DAYS);
					// 文字列長確認
					checkLength(aryTxtStandard[i], LEN_STANDARD, NAM_STANDARD, i, PRM_TXT_STANDARD);
					checkLength(aryTxtDays[i], LEN_DAYS, NAM_DAYS, i, PRM_TXT_DAYS);
					checkLength(aryTxtInfo[i], LEN_INFO, NAM_INFO, i, PRM_TXT_INFO);
				}
				if (StringUtil.isNotNull(aryTxtInfo[i])) {
					// 必須確認
					checkRequired(aryTxtStandard[i], NAM_STANDARD, i, PRM_TXT_STANDARD);
					checkRequired(aryTxtDays[i], NAM_DAYS, i, PRM_TXT_DAYS);
					// 文字列タイプ確認(半角数字)
					checkNumber(aryTxtStandard[i], NAM_STANDARD, i, PRM_TXT_STANDARD);
					checkNumber(aryTxtDays[i], NAM_DAYS, i, PRM_TXT_DAYS);
					// 文字列長確認
					checkLength(aryTxtStandard[i], LEN_STANDARD, NAM_STANDARD, i, PRM_TXT_STANDARD);
					checkLength(aryTxtDays[i], LEN_DAYS, NAM_DAYS, i, PRM_TXT_DAYS);
					checkLength(aryTxtInfo[i], LEN_INFO, NAM_INFO, i, PRM_TXT_INFO);
				}
			}
		} // 妥当性確認終了時処理
		endValidation();
	}
	
	// アクセサメソッド
	
	/**
	 * @return txtCFDays
	 */
	public String getEscTxtCFDays() {
		return escapeHTML(txtCFDays);
	}
	
	/**
	 * @return pltCFMonth
	 */
	public String getPltCFMonth() {
		return pltCFMonth;
	}
	
	/**
	 * @return txtCFDays
	 */
	public String getTxtCFDays() {
		return txtCFDays;
	}
	
	/**
	 * @return pltCFKbn
	 */
	public String getPltCFKbn() {
		return pltCFKbn;
	}
	
	/**
	 * @return pltSupplyModel
	 */
	public String getPltSupplyModel() {
		return pltSupplyModel;
	}
	
	/**
	 * @return aryTxtStandard
	 */
	public String[] getAryTxtStandard() {
		return aryTxtStandard.clone();
	}
	
	/**
	 * @return aryTxtDays
	 */
	public String[] getAryTxtDays() {
		return aryTxtDays.clone();
	}
	
	/**
	 * @return aryTxtInfo
	 */
	public String[] getAryTxtInfo() {
		return aryTxtInfo.clone();
	}
	
	/**
	 * @param pltCFMonth セットする pltCFMonth
	 */
	public void setPltCFMonth(String pltCFMonth) {
		this.pltCFMonth = pltCFMonth;
	}
	
	/**
	 * @param txtCFDays セットする txtCFDays
	 */
	public void setTxtCFDays(String txtCFDays) {
		this.txtCFDays = txtCFDays;
	}
	
	/**
	 * @param pltCFKbn セットする pltCFKbn
	 */
	public void setPltCFKbn(String pltCFKbn) {
		this.pltCFKbn = pltCFKbn;
	}
	
	/**
	 * @param pltSupplyModel セットする pltSupplyModel
	 */
	public void setPltSupplyModel(String pltSupplyModel) {
		this.pltSupplyModel = pltSupplyModel;
	}
	
}
