package com.connor.erp.processresource.EquipmentAcquiredFromERP;

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 ORSendToIcsOperation {
  private TCUserService userService;
  
  private TCSession session = null;
  
  public String parentStr = "";
  
  public ORSendToIcsOperation() {
    this.session = (TCSession)AIFUtility.getCurrentApplication().getSession();
    try {
      this.userService = this.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("物料创建成功，未找到对应分类节点！", "提示", 2);
        return false;
      } 
      if (item == null)
        return false; 
      Object[] params = { item, icsID, names, values };
      Object returnValue = this.userService.call("sendItemToClassification", params);
      if (returnValue.equals("isAbstract")) {
        MessageBox.post("所选节点为抽象类，发送到分类失败！", "提示", 2);
        return false;
      } 
    } catch (Exception e) {
      e.printStackTrace();
      MessageBox.post("物料创建成功但发送分类出错", "提示", 2);
      return false;
    } 
    return true;
  }
  
  public String getClassificationByName(String parentID, String childName) {
    String returnValue = "";
    try {
      Object[] params = { parentID, childName };
      Object obj = this.userService.call("getClassificationID", params);
      returnValue = obj.toString();
    } catch (Exception e) {
      e.printStackTrace();
    } 
    return returnValue;
  }
}
