/**
 * @author tyl
 * @Action  ini
 * 2011-3-15
 */
package cn.com.origin.autocodemanager.common.operations;

import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.kernel.TCUserService;
import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException;

public class GetCodeNumber {

	private TCUserService userService;

	public GetCodeNumber() {
		try {
			userService = (TCUserService) ((TCSession) AIFUtility.getCurrentApplication().getSession()).getUserService();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}



	public void delete_recycleID(String itemID) {
		// Object[] params = { counterName, itemID };
		if ((itemID == null) || (itemID.length() == 0)) {
			return;
		}
		itemID = itemID.replace(" ", "").trim();
		Object[] params = { itemID };
		try {
			userService.call("delete_recycleID", params);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @param patternCode
	 * @param codeLength
	 * @param startIndex
	 * @param endIndex
	 * @param increaseStep
	 * @return
	 * @throws ServiceException
	 */
	public String getCodeNumber(String patternCode, int codeLength, int startIndex, int maxValue, int increaseStep, String excludeStr) throws ServiceException {
		if (maxValue == startIndex) {
			return String.valueOf(maxValue);
		}
		if (startIndex < 1) {
			startIndex = 1;
		}
		if (maxValue < startIndex) {
			return String.valueOf(startIndex);
		}
		codeLength = String.valueOf(maxValue).length();
		Object[] params = { patternCode.replace(" ", "").trim(), codeLength, startIndex, maxValue, increaseStep, excludeStr };
//		System.out.println("patternCode===========" + patternCode);
//		System.out.println("codeLength===========" + codeLength);
//		System.out.println("startIndex===========" + startIndex);
//		System.out.println("endIndex===========" + maxValue);
//		System.out.println("increaseStep===========" + increaseStep);
//		System.out.println("excludeStr===========" + excludeStr);
		try {
			String str = "";
			str = (String) userService.call("queryPartNo", params);
			return str;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

}
