package com.connor.erp.ProcessImport.ProcessChgTransferToERP;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.SwingUtilities;

import com.connor.erp.toolkit.IsContinueDialog;
import com.connor.erp.toolkit.UtilApi;
import com.teamcenter.rac.aif.AbstractAIFCommand;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentMEOPRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;

public class ProcessChgTransferToERPCommand
/*     */   extends AbstractAIFCommand
/*     */ {
/*     */   private TCSession session;
/*     */   private AbstractAIFUIApplication application;
/*     */   private List<TCComponentItemRevision> listProcessRevisions;
/*     */   private StringBuffer detailInfo;
/*  49 */   private List<String[]> listRowDatas = (List)new ArrayList<String>();
/*     */   
/*  51 */   private Map<String, List<String>> map = new HashMap<String, List<String>>();
/*     */   
/*  53 */   private List<TCComponentForm> listProcessRevMasters = new ArrayList<TCComponentForm>();
/*     */ 
/*     */   
/*     */   private boolean isPrivilege;
/*     */ 
/*     */   
/*     */   private boolean isDepartmentNull = false;
/*     */ 
/*     */ 
/*     */   
/*     */   public ProcessChgTransferToERPCommand(TCSession pSession, AbstractAIFUIApplication app, List<TCComponentItemRevision> listProcessRevisions, StringBuffer detailInfo, boolean isPrivilege) {
/*  64 */     this.session = pSession;
/*  65 */     this.application = app;
/*  66 */     this.listProcessRevisions = listProcessRevisions;
/*  67 */     this.detailInfo = detailInfo;
/*  68 */     this.isPrivilege = isPrivilege;
/*  69 */     postDialog();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void postDialog() {
/*  76 */     int listSize = this.listProcessRevisions.size();
/*  77 */     for (int i = 0; i < listSize; i++) {
/*  78 */       TCComponentItemRevision meprocessRevision = this.listProcessRevisions.get(i);
/*     */       try {
/*  80 */         this.listProcessRevMasters.add((TCComponentForm)meprocessRevision.getRelatedComponent("IMAN_master_form_rev"));
/*  81 */       } catch (TCException e2) {
/*  82 */         e2.printStackTrace();
/*     */       } 
/*  84 */       TCComponentBOMLine bomline = UtilApi.getNewBOMLine(this.session, meprocessRevision, null);
/*  85 */       String process_item_id = "";
/*     */       try {
/*  87 */         process_item_id = meprocessRevision.getProperty("item_id");
/*  88 */       } catch (TCException e1) {
/*  89 */         e1.printStackTrace();
/*     */       } 
/*  91 */       String part_item_id = process_item_id.substring(0, process_item_id.length() - 2);
/*  92 */       List<String> list = new ArrayList<String>();
/*     */       try {
/*  94 */         AIFComponentContext[] opers = bomline.getChildren();
/*  95 */         int childCount = opers.length;
/*  96 */         int operNum = 0;
/*  97 */         for (int j = 0; j < childCount; j++) {
/*  98 */           TCComponentBOMLine operBom = (TCComponentBOMLine)opers[j].getComponent();
/*  99 */           TCComponentItemRevision itemRevision = operBom.getItemRevision();
/* 100 */           if (itemRevision instanceof TCComponentMEOPRevision || itemRevision.getType().equals("NHL8_RigOutGXRevision")) {
///* 101 */             TCComponentMEOPRevision operRevision = (TCComponentMEOPRevision)itemRevision;
/* 102 */             if (itemRevision.getTCClass().getSuperClass().toString().equals("NHL8_MEOPRevision") || itemRevision.getType().equals("NHL8_RigOutGXRevision")) {
/* 103 */               if ((itemRevision.getReferenceListProperty("release_status_list")).length == 0) {
/* 104 */                 if (!this.isPrivilege) {
/* 105 */                   MessageBox.post(itemRevision + " 对象未发布", "警告", 4);
/*     */                   return;
/*     */                 } 
/* 108 */                 this.detailInfo.append(itemRevision + " 对象未发布<br>");
/*     */               } 
/*     */               
/* 111 */               String[] rowData = new String[7];
/* 112 */               rowData[0] = part_item_id;
/* 113 */               String bl_sequence_no = operBom.getProperty("bl_sequence_no");
/* 114 */               rowData[1] = bl_sequence_no;
/* 115 */               rowData[2] = itemRevision.getProperty("object_name");
/* 116 */               TCComponentForm form = (TCComponentForm)itemRevision.getRelatedComponent("IMAN_master_form_rev");
/* 117 */               String[] formProNames = { "nhl8_StandardWH", "nhl8_AuxiliaryWH" };
/* 118 */               String[] formProValues = form.getProperties(formProNames);
/* 119 */               if (formProValues[0].equals("")) {
/* 120 */                 rowData[4] = "0";
/*     */               } else {
/* 122 */                 rowData[4] = formProValues[0];
/*     */               } 
/* 124 */               if (formProValues[1].equals("")) {
/* 125 */                 rowData[5] = "0";
/*     */               } else {
/* 127 */                 rowData[5] = formProValues[1];
/*     */               } 
/* 129 */               rowData[6] = "";
/* 130 */               AIFComponentContext[] children = operBom.getChildren();
/* 131 */               int childCount2 = children.length;
/* 132 */               boolean existEquipment = false;
/* 133 */               for (int k = 0; k < childCount2; k++) {
/* 134 */                 if (((TCComponentBOMLine)children[k].getComponent()).getItem().getType().equals("NHL8_Equipments")) {
/* 135 */                   String equ_id = "";
/*     */                   try {
/* 137 */                     equ_id = children[k].getComponent().getProperty("bl_item_item_id").substring(4);
/* 138 */                   } catch (Exception e) {
/* 139 */                     e.printStackTrace();
/*     */                   } 
/* 141 */                   rowData[3] = equ_id;
/* 142 */                   list.add(bl_sequence_no + ";" + equ_id);
/* 143 */                   existEquipment = true;
/*     */                   break;
/*     */                 } 
/*     */               } 
/* 147 */               if (!existEquipment) {
/* 148 */                 this.isDepartmentNull = true;
/*     */               }
/* 150 */               this.listRowDatas.add(rowData);
/* 151 */               operNum++;
/*     */             } 
/*     */           } 
/*     */         } 
/*     */         
/* 156 */         if (operNum == 0) {
/* 157 */           MessageBox.post(this.application.getDesktop().getShell(), meprocessRevision + "下面没有任何的工序对象！", "警告", 4);
/*     */           return;
/*     */         } 
/* 160 */       } catch (TCException e) {
/* 161 */         e.printStackTrace();
/*     */       } 
/* 163 */       this.map.put(part_item_id, list);
/*     */     } 
/* 165 */     if (this.isPrivilege) {
/* 166 */       if (!this.detailInfo.toString().equals("")) {
/* 167 */         setRunnable((Runnable)new IsContinueDialog(this, "所选部分工艺/工序对象未发布", this.detailInfo.toString()));
/*     */       } else {
/* 169 */         setRunnable((Runnable)new ProcessChgTransferToERPDialog(this.session, this.application, this.listRowDatas, this.map, this.listProcessRevMasters, this.isDepartmentNull));
/*     */       } 
/*     */     } else {
/* 172 */       setRunnable((Runnable)new ProcessChgTransferToERPDialog(this.session, this.application, this.listRowDatas, this.map, this.listProcessRevMasters, this.isDepartmentNull));
/*     */     } 
/*     */   }
/*     */   
/*     */   public void postDialog2() {
/* 177 */     SwingUtilities.invokeLater((Runnable)new ProcessChgTransferToERPDialog(this.session, this.application, this.listRowDatas, this.map, this.listProcessRevMasters, this.isDepartmentNull));
/*     */   }
/*     */ }
