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

import jp.mosp.common.CommonConst;
import jp.mosp.common.common.BaseVo;
import jp.mosp.common.common.MospConst;
import jp.mosp.common.common.MospException;
import jp.mosp.kintai.common.action.MosPCodeAction;
import jp.mosp.kintai.system.vo.LateReasonCardVo;

/**
 * @author yoshida
 *
 */
public class LateReasonCardAction extends MosPCodeAction {
	
	// コマンド
	private static final String	CMD_LATE_REASON_CARD_SHOW	= "S2320";	// 表示
	private static final String	CMD_LATE_REASON_CARD_UPDATE	= "S2328";	// 更新
																		
	
	/**
	 * コンストラクタ
	 */
	public LateReasonCardAction() {
		super();
	}
	
	/**
	 * アクション
	 */
	public void action() throws Exception {
		// VOの取得
		prepareVo(false);
		// 初期処理
		init();
		// コマンド毎の処理
		if (cmd.equals(CMD_LATE_REASON_CARD_SHOW)) {
			// 表示
			show();
		} else if (cmd.equals(CMD_LATE_REASON_CARD_UPDATE)) {
			// 遅刻理由更新
			update();
			// 表示
			show();
		} else {
			throw new MospException(MospConst.EX_CMD_INVALID);
		}
	}
	
	@Override
	protected BaseVo getSpecificVo() {
		return new LateReasonCardVo();
	}
	
	@Override
	protected void init() throws Exception {
		// DBコネクション取得
		getConnection();
		// PAYROLL権限確認
		confirmSystemAuth();
	}
	
	@Override
	protected void show() throws Exception {
		LateReasonCardVo vo = (LateReasonCardVo)getVo();
		// 遅刻理由
		vo.setFields(part().mospcode().findForCondition(CommonConst.TID_LATE_REASON));
	}
	
	@Override
	protected void update() throws Exception {
		LateReasonCardVo vo = (LateReasonCardVo)getVo();
		vo.setParams(request);
		// フィールドの妥当性確認
		vo.validate();
		String[] aryReason = vo.getAryTxtLateReason();
		for (int i = 0; i < aryReason.length; i++) {
			// 更新処理
			regist(CommonConst.TID_LATE_REASON, String.valueOf(i), aryReason[i], "");
		}
		// コミット
		commit();
		// メッセージ設定
		vo.setMessage(getMessage(MospConst.MSG_UPDATE, ""));
	}
	
}
