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

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