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

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