/*
 * MosP - Mind Open Source Project         http://www.mosp.jp/
 * Copyright (C) 1987-2009 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.common.part;

import jp.mosp.kintai.dao.CmRotationDao;
import jp.mosp.kintai.dto.CmRotationDto;

/**
 * 勤務パターン用Partクラス
 * @author yoshida
 *	@version	0.0.1
 */
public class RotationPart extends BasePart {

	/**
	 * コンストラクタ
	 */
	public RotationPart() {
		super();
	}

	/**
	 * コンストラクタ
	 * @param partInfo
	 */
	public RotationPart(PartInfo partInfo) {
		super(partInfo);
	}

	/**
	 * CM_ROTATIONテーブル用のDAO取得
	 * @return	初期化済みCmRotationDaoインスタンス
	 * @throws Exception
	 */
	public CmRotationDao getCmRotationDao() throws Exception {
		return (CmRotationDao) getPreparedDao(CmRotationDao.class.getCanonicalName());
	}

	/**
	 * 勤務パターン配列取得
	 * @param rotationCode
	 * @return	aryRotaiton	勤務パターン配列
	 * @throws Exception
	 */
	public String[] getRotationArray(String rotationCode) throws Exception {
		CmRotationDto dto = getCmRotationDao().findForKey(user.getKCode(), rotationCode);
		String[] aryRotaiton = new String[10];
		if (VariousPart.chkExistDto(dto)) {
			aryRotaiton[0] = dto.getDay1();
			aryRotaiton[1] = dto.getDay2();
			aryRotaiton[2] = dto.getDay3();
			aryRotaiton[3] = dto.getDay4();
			aryRotaiton[4] = dto.getDay5();
			aryRotaiton[5] = dto.getDay6();
			aryRotaiton[6] = dto.getDay7();
			aryRotaiton[7] = dto.getDay8();
			aryRotaiton[8] = dto.getDay9();
			aryRotaiton[9] = dto.getDay10();
		} else {
			aryRotaiton = new String[0];
		}
		return aryRotaiton;
	}

	/**
	 * 祝祭日フラグ取得
	 * @param rotationCode
	 * @return 0…false、1…true
	 * @throws Exception
	 */
	public boolean getPublicHolidayFlag(String rotationCode) throws Exception {
		CmRotationDto dto = getCmRotationDao().findForKey(user.getKCode(), rotationCode);
		if (VariousPart.chkExistDto(dto) && dto.getHolidayFlag() != 0) {
			return true;
		}
		return false;
	}

}
