package cn.com.origin.autocode.common.operations;

import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.kernel.TCUserService;
import com.teamcenter.rac.util.MessageBox;

public class SendToIcsOperation {
	private TCUserService userService;
	private TCSession session = null;
	public String parentStr = "";

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

	public boolean sendItemToClassification(TCComponentItem item, String icsID, Object[] names, String[] values) {
		try {
			if ((icsID == null) || (icsID.length() == 0)) {
				MessageBox.post("物料创建成功,未找到对应分类节点!", "提示", MessageBox.INFORMATION);
				return false;
			}
			if (item == null) {
				return false;
			}
			Object[] params = { item, icsID, names, values };
			Object returnValue = userService.call("sendItemToClassification", params);
			if (returnValue.equals("isAbstract")) {
				MessageBox.post("所选节点为抽象类，发送到分类失败!", "提示", MessageBox.INFORMATION);
			} else {
				MessageBox.post("物料创建成功且发送到分类成功!", "提示", MessageBox.INFORMATION);
			}
		} catch (Exception e) {
			e.printStackTrace();
			MessageBox.post("物料创建成功但发送分类出错!", "提示", MessageBox.INFORMATION);
			return false;
		}
		return true;
	}

	public String getClassificationByName(String parentID, String childName) {
		String returnValue = "";
		try {
			System.out.println("查询：");
			System.out.println("parentID:"+parentID);
			System.out.println("childName:"+childName);
			Object[] params = { parentID, childName };
			Object obj = userService.call("getClassificationID", params);
			returnValue = obj.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return returnValue;
	}

}
