 package com.connor.erp.BomChgTransferToERP;
 
 import com.connor.erp.BomAddTransferToERP.AssemblyResult;
import com.connor.erp.BomAddTransferToERP.BomAdd;
import com.connor.erp.BomAddTransferToERP.BomAddEntry;
import com.connor.erp.BomAddTransferToERP.BomAddTransferDialog;
import com.connor.erp.BomImport.BomTransferDialog;
// import com.connor.erp.BomImport.TransferBomXMLWriter;
// import com.connor.erp.BomImport.ValidateBomXMLWriter;
 import com.connor.erp.ProcessImport.ValidateFailDialog;
 import com.connor.erp.materialquery.ViewStockOfERP.CMap;
import com.connor.erp.materialquery.ViewStockOfERP.CMap2;
import com.connor.erp.materialquery.ViewStockOfERP.CTable;
import com.connor.erp.processresource.EquipmentAcquiredFromERP.TCPreferenceUitl;
// import com.connor.erp.materialquery.ViewStockOfERP.CMap;
// import com.connor.erp.materialquery.ViewStockOfERP.CMap2;
// import com.connor.erp.materialquery.ViewStockOfERP.CTable;
// import com.connor.erp.toolkit.ActionType;
 import com.connor.erp.toolkit.AimType;
 import com.connor.erp.toolkit.FileType;
import com.connor.erp.toolkit.HttpUtil;
import com.connor.erp.toolkit.UtilApi;
// import com.connor.tcerp.conn.PlmErpIntegration;
 import com.teamcenter.rac.aif.AbstractAIFUIApplication;
 import com.teamcenter.rac.kernel.TCComponentItemRevision;
 import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCPreferenceService;
import com.teamcenter.rac.kernel.TCSession;
 import com.teamcenter.rac.kernel.TCUserService;
 import com.teamcenter.rac.util.MessageBox;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.io.File;
 import java.io.FileNotFoundException;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
import java.util.ResourceBundle;
import java.util.Vector;
 import javax.swing.Icon;
 import javax.swing.ImageIcon;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTabbedPane;
 import javax.swing.JTable;
 import javax.swing.SwingUtilities;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 import javax.swing.table.DefaultTableCellRenderer;
 import javax.swing.table.DefaultTableModel;
 import javax.swing.table.TableModel;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.TransformerException;
 
 /*     */ public class BomChgTransferDialog
 /*     */   extends BomTransferDialog
 /*     */ {
 /*     */   private static final long serialVersionUID = 1L;
 /*  73 */   private String user_id = "";
 /*     */   
 /*     */   private JCheckBox cbMerge;
 /*     */   
 /*     */   private JButton btnBomCheck;
 /*     */   
 /*     */   private JButton btnBomCompare;
 /*     */   
 /*     */   private JButton btnBomImportERP;
 /*     */   private ResourceBundle resource = ResourceBundle.getBundle("tcUser_erpUser");
 /*     */   private JButton btnCancel;
 /*     */   
 /*     */   private DefaultTableModel newTableModel;
 /*     */    private static String erpPreference = "connor_tc_to_erp_url";
 /*     */   private Vector<Object> newTableTitle;
 /*     */   
 /*     */   private CTable newTable;
 /*     */   private String msgString;
 /*     */   private DefaultTableModel compareTableModel;
 /*     */   private Vector<Object> compareTableTitle;
 /*     */   private CTable compareTable;
 /*     */   private JScrollPane newScrollPane;
 /*     */   private JScrollPane compareScrollPane;
 /*  96 */   private Vector<Vector<Object>> erpData = new Vector<Vector<Object>>();
 /*     */   
 /*  98 */   private JTabbedPane tabbedPane = null;
 
 
 /* 100 */   private int maxWidth = 0;
 /*     */   
 /*     */   public BomChgTransferDialog(TCSession session, AbstractAIFUIApplication app, List<TCComponentItemRevision> itemRevision, Map<String, Map<String, List<String>>> map, Vector<Vector<Object>> data) {
 /* 103 */     super(session, app, itemRevision, map, data);
 /* 104 */     System.out.println("BomChgTransferDialog::map==============" + map);
 /* 105 */     System.out.println("BomChgTransferDialog::itemRevision==============" + itemRevision);
 /* 106 */     System.out.println("BomChgTransferDialog::data==============" + data);
 /* 107 */     initUI();
 /*     */   }
 /*     */   
 /*     */   private void initUI() {
 /* 111 */     setTitle("变更BOM");
 /* 112 */     this.cbMerge = new JCheckBox("同件号同工序合并");
 /* 113 */     this.btnBomCheck = new JButton("BOM导入验证");
 /*     */     
 /* 115 */     this.btnBomCompare = new JButton("BOM比较");
 /* 116 */     this.btnBomCompare.setEnabled(false);
 /*     */     
 /* 118 */     this.btnBomImportERP = new JButton("BOM导入ERP系统");
 /* 119 */     this.btnBomImportERP.setEnabled(false);
 /*     */     
 /* 121 */     this.btnCancel = new JButton("取消");
 /*     */     
 /* 123 */     JPanel paneButton = new JPanel();
 /* 124 */     paneButton.add(this.cbMerge);
 /* 125 */     paneButton.add(this.btnBomCheck);
 /* 126 */     paneButton.add(this.btnBomCompare);
 /* 127 */     paneButton.add(this.btnBomImportERP);
 /* 128 */     paneButton.add(this.btnCancel);
 /*     */     
 /* 130 */     this.newTableTitle = new Vector();
 /* 131 */     this.newTableTitle.add("组织ID");
 /* 132 */     this.newTableTitle.add("装配件编码");
 /* 133 */     this.newTableTitle.add("子件编码");
 /* 134 */     this.newTableTitle.add("工序序号");
 /* 135 */     this.newTableTitle.add("数量");
 /*     */     
 /* 137 */     CMap2 cMap2 = new CMap2();
 /*     */     
 /* 139 */     this.newTableModel = new DefaultTableModel(this.data, this.newTableTitle);
 /* 140 */     this.newTable = new CTable((CMap)cMap2, this.newTableModel)
 /*     */       {
 /*     */         private static final long serialVersionUID = 1L;
 /*     */ 
 /*     */ 
 /*     */         
 /*     */         public boolean isCellEditable(int row, int column) {
 /* 147 */           return false;
 /*     */         }
 /*     */       };
 /*     */     
 /* 151 */     this.compareTableTitle = new Vector();
 /* 152 */     this.compareTableTitle.add("组织ID");
 /* 153 */     this.compareTableTitle.add("装配件编码");
 /* 154 */     this.compareTableTitle.add("子件编码");
 /* 155 */     this.compareTableTitle.add("工序序号");
 /* 156 */     this.compareTableTitle.add("数量");
 /* 157 */     this.compareTableTitle.add("状态");
 /* 158 */     this.compareTableModel = new DefaultTableModel(this.erpData, this.compareTableTitle);
 /* 159 */     this.compareTable = new CTable((CMap)cMap2, this.compareTableModel)
 /*     */       {
 /*     */         private static final long serialVersionUID = 1L;
 /*     */         public boolean isCellEditable(int i, int j) {
 /* 167 */           return false;
 /*     */         }
 /*     */       };
 /* 170 */     int totalWidth = UtilApi.FitTableColumns((JTable)this.newTable);
 /*     */     
 /* 172 */     JPanel paneMain = new JPanel(new BorderLayout());
 /*     */     
 /* 174 */     this.newScrollPane = new JScrollPane((Component)this.newTable);
 /*     */     
 /* 176 */     this.compareScrollPane = new JScrollPane((Component)this.compareTable);
 /*     */     
 /* 178 */     this.tabbedPane = new JTabbedPane(1);
 /* 179 */     this.tabbedPane.setTabPlacement(1);
 /* 180 */     Icon icon = new ImageIcon(("projectobject_16.png"));
 /* 181 */     this.tabbedPane.addTab("PLM新BOM", icon, this.newScrollPane, "PLM新BOM");
 /* 182 */     this.tabbedPane.addTab("与ERP旧BOM比较结果", icon, this.compareScrollPane, "与ERP旧BOM比较结果");
 /* 183 */     this.tabbedPane.setEnabledAt(1, false);
 /* 184 */     this.tabbedPane.addChangeListener(new ChangeListener()
 /*     */         {
 /*     */           public void stateChanged(ChangeEvent e)
 /*     */           {
 /* 188 */             if (BomChgTransferDialog.this.tabbedPane.getSelectedIndex() == 0) {
 /* 189 */               BomChgTransferDialog.this.cbMerge.setEnabled(true);
 /*     */             } else {
 /* 191 */               BomChgTransferDialog.this.cbMerge.setEnabled(false);
 /*     */             } 
 /*     */           }
 /*     */         });
 /*     */     
 /* 196 */     paneMain.add("Center", new JScrollPane(this.tabbedPane));
 /* 197 */     paneMain.add("South", paneButton);
 /* 198 */     getContentPane().add(paneMain);
 /* 199 */     this.maxWidth = totalWidth + 100;
 /* 200 */     setPreferredSize(new Dimension(this.maxWidth, 600));
 /*     */     
 /* 202 */     this.cbMerge.addItemListener(new ItemListener()
 /*     */         {
 /*     */           
 /*     */           public void itemStateChanged(ItemEvent ev)
 /*     */           {
 /* 207 */             if (BomChgTransferDialog.this.cbMerge.isEnabled()) {
 /* 208 */               if (ev.getStateChange() == 1) {
 /* 209 */                 int rowCount = BomChgTransferDialog.this.data.size();
 /* 210 */                 Vector<Vector<Object>> newData = new Vector<Vector<Object>>();
 /* 211 */                 Map<String, String> idToNumMap = new HashMap<String, String>();
 /* 212 */                 Map<String, Vector<Object>> idToRowDataMap = new HashMap<String, Vector<Object>>();
 /* 213 */                 for (int i = 0; i < rowCount; i++) {
 /* 214 */                   Vector<Object> rowData = BomChgTransferDialog.this.data.get(i);
 /* 215 */                   String processId = rowData.get(1).toString();
 /* 216 */                   String operId = rowData.get(2).toString();
 /* 217 */                   String seqNum = rowData.get(3).toString();
 /* 218 */                   String quantity = rowData.get(4).toString();
 /*     */                   
 /* 220 */                   String gongxu = seqNum.split("_")[0];
 /*     */                   
 /* 222 */                   String process_and_oper = String.valueOf(processId + "|" + operId) + "|" + gongxu;
 /* 223 */                   String seqNum_and_quantity = seqNum + "&&" + quantity;
 /*     */ 
 /*     */ 
 /*     */ 
 /*     */                   
 /* 228 */                   if (idToNumMap.containsKey(process_and_oper)) {
 /* 229 */                     int index = newData.indexOf(idToRowDataMap.get(process_and_oper));
 /* 230 */                     Vector<Object> newRowData = new Vector();
 /* 231 */                     String[] seqNum_and_quantityArrStr = ((String)idToNumMap.get(process_and_oper)).split("&&");
 /* 232 */                     String seqNum2 = seqNum_and_quantityArrStr[0];
 /* 233 */                     String quantity2 = seqNum_and_quantityArrStr[1];
 /* 234 */                     String sumQuantity = UtilApi.subZeroAndDot(String.valueOf(UtilApi.add(Double.parseDouble(quantity), Double.parseDouble(quantity2))));
 /* 235 */                     String newSeqNum = seqNum2 + "×" + quantity2 + ";" + seqNum + "×" + quantity;
 /* 236 */                     String newSeqNumAndQuantity = newSeqNum + "&&" + sumQuantity;
 /*     */                     
 /* 238 */                     idToNumMap.put(process_and_oper, newSeqNumAndQuantity);
 /* 239 */                     newRowData.add(rowData.get(0).toString());
 /* 240 */                     newRowData.add(processId);
 /* 241 */                     newRowData.add(operId);
 /* 242 */                     newRowData.add(newSeqNum);
 /* 243 */                     newRowData.add(sumQuantity);
 /* 244 */                     idToRowDataMap.put(process_and_oper, newRowData);
 /* 245 */                     newData.set(index, newRowData);
 /*     */                   } else {
 /* 247 */                     idToNumMap.put(process_and_oper, seqNum_and_quantity);
 /* 248 */                     idToRowDataMap.put(process_and_oper, rowData);
 /* 249 */                     newData.add(rowData);
 /*     */                   } 
 /*     */                 } 
 /* 252 */                 BomChgTransferDialog.this.newTableModel.setDataVector(newData, BomChgTransferDialog.this.newTableTitle);
 /* 253 */                 int oldWidth = UtilApi.FitTableColumns((JTable)BomChgTransferDialog.this.newTable);
 /* 254 */                 int newWidth = UtilApi.FitTableColumns((JTable)BomChgTransferDialog.this.compareTable);
 /* 255 */                 if (oldWidth > newWidth) {
 /* 256 */                   if (oldWidth > BomChgTransferDialog.this.maxWidth) {
 /* 257 */                     BomChgTransferDialog.this.maxWidth = oldWidth;
 /* 258 */                     BomChgTransferDialog.this.setPreferredSize(new Dimension(oldWidth, 400));
 /*     */                   }
 /*     */                 
 /* 261 */                 } else if (newWidth > BomChgTransferDialog.this.maxWidth) {
 /* 262 */                   BomChgTransferDialog.this.maxWidth = newWidth;
 /* 263 */                   BomChgTransferDialog.this.setPreferredSize(new Dimension(newWidth, 400));
 /*     */                 } 
 /*     */               } else {
 /*     */                 
 /* 267 */                 BomChgTransferDialog.this.newTableModel.setDataVector(BomChgTransferDialog.this.data, BomChgTransferDialog.this.newTableTitle);
 /* 268 */                 int oldWidth = UtilApi.FitTableColumns((JTable)BomChgTransferDialog.this.newTable);
 /* 269 */                 int newWidth = UtilApi.FitTableColumns((JTable)BomChgTransferDialog.this.compareTable);
 /* 270 */                 if (oldWidth > newWidth) {
 /* 271 */                   if (oldWidth > BomChgTransferDialog.this.maxWidth) {
 /* 272 */                     BomChgTransferDialog.this.maxWidth = oldWidth;
 /* 273 */                     BomChgTransferDialog.this.setPreferredSize(new Dimension(oldWidth, 400));
 /*     */                   }
 /*     */                 
 /* 276 */                 } else if (newWidth > BomChgTransferDialog.this.maxWidth) {
 /* 277 */                   BomChgTransferDialog.this.maxWidth = newWidth;
 /* 278 */                   BomChgTransferDialog.this.setPreferredSize(new Dimension(newWidth, 400));
 /*     */                 } 
 /*     */               } 
 /*     */             }
 /*     */           }
 /*     */         });
 /*     */ 
 /*     */ 
 /*     */     
 /* 287 */     this.btnBomCheck.addActionListener(new ActionListener()
 /*     */         {
 /*     */           public void actionPerformed(ActionEvent e)
 /*     */           {
 /* 291 */             BomChgTransferDialog.this.check();
 /*     */           }
 /*     */         });
 /*     */     
 /* 295 */     this.btnBomCompare.addActionListener(new ActionListener()
 /*     */         {
 /*     */           public void actionPerformed(ActionEvent e)
 /*     */           {
 /* 299 */             BomChgTransferDialog.this.compare();
 /*     */           }
 /*     */         });
 /*     */ 
 /*     */ 
 /*     */     
 /* 305 */     this.btnBomImportERP.addActionListener(new ActionListener()
 /*     */         {
 /*     */           public void actionPerformed(ActionEvent e)
 /*     */           {
 /* 309 */             BomChgTransferDialog.this.importToERP();
 /*     */           }
 /*     */         });
 /*     */     
 /* 313 */     this.btnCancel.addActionListener(new ActionListener()
 /*     */         {
 /*     */           public void actionPerformed(ActionEvent e)
 /*     */           {
 /* 317 */             BomChgTransferDialog.this.dispose();
 /*     */           }
 /*     */         });
 /*     */   }
 /*     */ 
 /*     */   
 /*     */   public void check() {
	 			System.out.println("check");
 /* 324 */  	   int rowCount = this.newTable.getRowCount();
	 /* 325 */     for (int i = 0; i < rowCount; i++) {
	 /* 326 */       if (this.newTable.getValueAt(i, 3).toString().trim().equals("")) {
	 /* 327 */         MessageBox.post(this.application.getDesktop().getShell(), "工序序号不能为空！", "错误", 1);
	 /*     */         return;
	 /*     */       } 
	 /*     */     } 
	 /*     */     try {
	 /* 332 */       this.user_id = this.session.getUser().getProperty("user_id");
	 /* 333 */     } catch (TCException ex) {
	 /* 334 */       ex.printStackTrace();
	 /*     */     } 
				 	List<BomAddEntry> entryMap=new ArrayList<BomAddEntry>();
					Map<String, List<BomAddEntry>> bomMap=new HashMap<String, List<BomAddEntry>>();
					
					List<Map<String, String>> list=new ArrayList<Map<String,String>>();
					
					String assembly = newTable.getValueAt(0, 1).toString();
					BomAddEntry bomAddEntry=new BomAddEntry();
					bomAddEntry.setAssembly_item(assembly.split("/")[0]);
///* 122 */             int rowCount = newTable.getRowCount();
/* 123 */             for (int i = 0; i < rowCount; i++) {
						
						
						if(assembly!=newTable.getValueAt(i, 1).toString()) {
							entryMap.add(bomAddEntry);
							bomAddEntry.setBOMLine(list);
							bomAddEntry=new BomAddEntry();
							assembly=newTable.getValueAt(i, 1).toString();
							bomAddEntry.setAssembly_item(assembly.split("/")[0]);
							list=new ArrayList<Map<String,String>>();
						}
						if(i==rowCount-1) {
							entryMap.add(bomAddEntry);
							bomAddEntry.setBOMLine(list);
							bomAddEntry=new BomAddEntry();
						}
						
						
/* 124 */               if (newTable.getValueAt(i, 3).toString().trim().equals("")) {
/* 125 */                 MessageBox.post(application.getDesktop().getShell(), "工序序号不能为空！", "错误", 1);
/*     */                 return;
/*     */               } 
						Map<String, String> jsonMap=new HashMap<String, String>();
						jsonMap.put("item", newTable.getValueAt(i, 2).toString().split("/")[0]);
						jsonMap.put("operation_seq_num",newTable.getValueAt(i, 3).toString().split("_")[0]);
						list.add(jsonMap);
/*     */             } 
						bomMap.put("BOM", entryMap);
// /*     */     try {
// /* 339 */       ValidateBomXMLWriter.createXML(this.user_id, xmlFilePath, FileType.bom, AimType.chg, this.map);
// /* 340 */     } catch (FileNotFoundException e1) {
// /* 341 */       e1.printStackTrace();
// /* 342 */     } catch (ParserConfigurationException e1) {
// /* 343 */       e1.printStackTrace();
// /* 344 */     } catch (TransformerException e1) {
// /* 345 */       e1.printStackTrace();
// /*     */     } 
// /*     */     
				List<AssemblyResult> results = doPost(bomMap,"BOMChgCheck");
				
				System.out.println("msg"+msgString);
// /* 348 */     String result = "";
//		 UtilApi.getErrorInfoFromCode(PlmErpIntegration.validateData(xmlFilePath));
 /*     */ 
 /*     */ 
 /*     */     
 /* 352 */     if (!msgString.equals("succ")) {
 /* 353 */       MessageBox.post(this.application.getDesktop().getShell(), msgString, "验证出现错误", MessageBox.INFORMATION);
 /*     */     
 /*     */     }
 /*     */     else {
 /*     */       
 /* 358 */       String errorInfo = BomChgImportXMLReader.loadElements(results,"1");
 System.out.println("errorInfo"+errorInfo);
// String errorInfo="";
 /* 359 */       if (errorInfo.equals("")) {
 /* 360 */         MessageBox.post(this.application.getDesktop().getShell(), "导入验证成功，可以执行导入操作！", "成功", 2);
 /* 361 */         this.btnBomCompare.setEnabled(true);
 /* 362 */         this.btnBomImportERP.setEnabled(true);
 /*     */       } else {
 /* 364 */         SwingUtilities.invokeLater((Runnable)new ValidateFailDialog("验证失败，请查看详细信息：", "警告", errorInfo));
 /*     */       } 
 /*     */     } 
 /*     */   }
 /*     */   
 /*     */   public void compare() {
 /*     */     
			 List<BomAddEntry> entryMap=new ArrayList<BomAddEntry>();
				Map<String, List<BomAddEntry>> bomMap=new HashMap<String, List<BomAddEntry>>();
						
				List<Map<String, String>> list=new ArrayList<Map<String,String>>();
				
				String assembly = newTable.getValueAt(0, 1).toString();
				BomAddEntry bomAddEntry=new BomAddEntry();
/* 122 */             int rowCount = newTable.getRowCount();
bomAddEntry.setAssembly_item(assembly.split("/")[0]);
	/* 123 */    for (int i = 0; i < rowCount; i++) {
					if(assembly!=newTable.getValueAt(i, 1).toString()) {
						entryMap.add(bomAddEntry);
						bomAddEntry.setBOMLine(list);
						bomAddEntry=new BomAddEntry();
						assembly=newTable.getValueAt(i, 1).toString();
						bomAddEntry.setAssembly_item(assembly.split("/")[0]);
						list=new ArrayList<Map<String,String>>();
					}
					if(i==rowCount-1) {
						entryMap.add(bomAddEntry);
						bomAddEntry.setBOMLine(list);
						bomAddEntry=new BomAddEntry();
					}
					
				
	               if (newTable.getValueAt(i, 3).toString().trim().equals("")) {
	                MessageBox.post(application.getDesktop().getShell(), "工序序号不能为空！", "错误", 1);
	                 return;
	               } 
					Map<String, String> jsonMap=new HashMap<String, String>();
					jsonMap.put("item", newTable.getValueAt(i, 2).toString().split("/")[0]);
					jsonMap.put("operation_seq_num",newTable.getValueAt(i, 3).toString().split("_")[0]+"_");
					jsonMap.put("quantity",newTable.getValueAt(i, 4).toString());
					list.add(jsonMap);
/*     */             } 
					bomMap.put("BOM", entryMap);
					List<CompareResult> results = doPost(bomMap,"CompareBOMdetail");
// /* 382 */     String result ="";
//		 UtilApi.getErrorInfoFromCode(PlmErpIntegration.compareBom(xmlFilePath));
 /*     */ 
 /*     */ 
 /*     */     
 /* 386 */     if (!msgString.equals("succ")) {
 /* 387 */       SwingUtilities.invokeLater((Runnable)new ValidateFailDialog("比较验证失败，请查看详细信息：", "警告", msgString));
 /*     */     
 /*     */     }
 /*     */     else {
 /*     */       
 /* 392 */       Vector<String> vec = new Vector<String>();
	 				
	 /* 393 */       this.erpData.clear();
	 			BomChgImportXMLReader.loadElements(results, erpData, vec);
// /* 394 */       BomChgCompareXMLReader.loadXMLDatas(new File(xmlFileName + "_r.xml"), this.erpData, vec);
 /* 395 */       this.tabbedPane.setEnabledAt(1, true);
 /* 396 */       this.tabbedPane.setSelectedIndex(1);
 /* 397 */       for (int i = 2; i < 6; i++) {
 /* 398 */         this.compareTable.getColumn(this.compareTable.getColumnName(i)).setCellRenderer(new MyDefaultTableCellRenderer());
 /*     */       }
 /* 400 */       int oldWidth = UtilApi.FitTableColumns((JTable)this.newTable);
 /* 401 */       int newWidth = UtilApi.FitTableColumns((JTable)this.compareTable);
 /* 402 */       if (oldWidth > newWidth) {
 /* 403 */         if (oldWidth > this.maxWidth) {
 /* 404 */           this.maxWidth = oldWidth;
 /* 405 */           setPreferredSize(new Dimension(oldWidth, 400));
 /*     */         }
 /*     */       
 /* 408 */       } else if (newWidth > this.maxWidth) {
 /* 409 */         this.maxWidth = newWidth;
 /* 410 */         setPreferredSize(new Dimension(newWidth, 400));
 /*     */       } 
 /*     */       
 /* 413 */       if (vec.size() == this.erpData.size()) {
	 
			 		Object obj[] = new Object[1];
			 		obj[0] = 1;
			 		TCUserService service = session.getUserService();
		   			try {
						service.call("openByPass", obj);
						int rev_num = this.ItemRevision.size();
						
						for (int i = 0; i < rev_num; i++) {
							
							this.ItemRevision.get(i).getRelatedComponent("IMAN_master_form_rev").setLogicalProperty("nhl8_BOMimpSucc", true);

						}
						
						
						 service.call("closeByPass", obj);
					} catch (TCException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
		   			this.btnBomImportERP.setEnabled(false);
 /* 414 */          MessageBox.post(this.application.getDesktop().getShell(), "与ERP中的BOM相同，无需导入！", "提示", 2);
 /*     */       }
 /*     */     } 
 /*     */   }
 /*     */ 
 /*     */   
 /*     */   public void importToERP() {
//	 导入			
	 		Map<String, String> userMap=new HashMap<String, String>();
			userMap.put("TCUser", user_id);
			List<UserList> doPost = DBUtils.doPost(userMap, session);
			UserList userList = doPost.get(0);
			 List<BomAdd> entryMap=new ArrayList<BomAdd>();
				Map bomMap=new HashMap();
				
				List<Map<String, Object>> list=new ArrayList<Map<String,Object>>();
//				if(resource.containsKey(user_id)) {
//					bomMap.put("creater", resource.getString(user_id));
//		      }else {
		     	 bomMap.put("creater", userList.getERP_USER_CODE());
//				}
				String assembly = newTable.getValueAt(0, 1).toString();
				BomAdd bomAddEntry=new BomAdd();
				int indx=0;
				String revisionString="";
				TCComponentItemRevision rev = ItemRevision.get(indx);
				try {
					String object_string = rev.getStringProperty("object_string");
					System.out.println(object_string);
					if(object_string.equals(assembly.split(" ")[0])) {
						revisionString=rev.getStringProperty("item_revision_id");
					}
				} catch (TCException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
				
				int rowCount = newTable.getRowCount();
				for (int i = 0; i < rowCount; i++) {
					bomAddEntry.setAssembly_item(assembly.split("/")[0]);
					bomAddEntry.setVersion(revisionString);
					if(assembly!=newTable.getValueAt(i, 1).toString()) {
						entryMap.add(bomAddEntry);
						bomAddEntry.setBOMLine(list);
						bomAddEntry=new BomAdd();
						assembly=newTable.getValueAt(i, 1).toString();
						try {
							indx++;
							TCComponentItemRevision rev2 = ItemRevision.get(indx);
							String object_string = rev2.getStringProperty("object_string");
							if(object_string.equals(assembly.split(" ")[0])) {
								revisionString=rev2.getStringProperty("item_revision_id");
								bomAddEntry.setVersion(revisionString);
								
							}
						} catch (TCException e2) {
							// TODO Auto-generated catch block
							e2.printStackTrace();
						}
						list=new ArrayList<Map<String,Object>>();
					}
					if(i==rowCount-1) {
						entryMap.add(bomAddEntry);
						bomAddEntry.setBOMLine(list);
						bomAddEntry=new BomAdd();
					}
		
		
					if (newTable.getValueAt(i, 3).toString().trim().equals("")) {
						MessageBox.post(application.getDesktop().getShell(), "工序序号不能为空！", "错误", 1);
						return;
					} 
					
					Map<String, Object> jsonMap=new HashMap<String, Object>();
					jsonMap.put("item", newTable.getValueAt(i, 2).toString().split("/")[0]);
					jsonMap.put("operation_seq_num",newTable.getValueAt(i, 3).toString());
					jsonMap.put("quantity",Double.valueOf(newTable.getValueAt(i, 4).toString()) );
					list.add(jsonMap);
				} 
					
				BomChgTransferOperation operation=new BomChgTransferOperation(application,session,entryMap,bomMap,BomChgTransferDialog.this);
				session.queueOperation(operation);
 /*     */   }
 /*     */ 
 /*     */   
 /*     */   public class MyDefaultTableCellRenderer
 /*     */     extends DefaultTableCellRenderer
 /*     */   {
 /*     */     private static final long serialVersionUID = 1L;
 /*     */ 
 /*     */     
 /*     */     public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
 /* 465 */       String fiveValue = table.getValueAt(row, 5).toString();
 /* 466 */       if (fiveValue.equals("删除")) {
 /* 467 */         setBackground(Color.RED);
 /* 468 */       } else if (fiveValue.equals("新增")) {
 /* 469 */         setBackground(Color.GREEN);
 /* 470 */       } else if (fiveValue.equals("修改")) {
 /* 471 */         setBackground(Color.YELLOW);
 /* 472 */       } else if (fiveValue.equals("未改")) {
 /* 473 */         setBackground(Color.WHITE);
 /*     */       } 
 /* 475 */       return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
 /*     */     }
 /*     */   }
 
 /*     */ private List doPost(Map<String, List<BomAddEntry>> itemCheckMap, String svr) {
		HashMap<String, String> preferenceHashMap = TCPreferenceUitl.getPreferenceHashMap(session, TCPreferenceService.TC_preference_site, erpPreference);
		String url = preferenceHashMap.get("url");
		String token = preferenceHashMap.get("token");
		JSONObject itemCheckJson = JSONObject.fromObject(itemCheckMap);
		String sid = null;
		try {
			System.out.println("开始发送请求");
			String args = itemCheckJson.toString();
			System.out.println(args);
			token = URLEncoder.encode(token,"UTF-8");
			svr = URLEncoder.encode(svr,"UTF-8");
			args = URLEncoder.encode(args,"UTF-8");
			String param = "usr="+token+"&svr="+svr+"&args="+args;
			
			System.out.println("url=============="+url);
			System.out.println("param==========="+args);
			String response = HttpUtil.doPost(url,param);
//			System.out.println("请求结果================"+response);
			JSONObject jsonObject = JSONObject.fromObject(response);
			System.out.println("json格式==============="+jsonObject);
			if(svr.equals("BOMChgCheck")) {
				msgString = jsonObject.getString("msg");
				if(jsonObject.has("cont")) {
					JSONObject jsonObject2 = jsonObject.getJSONObject("cont");
					
					if(jsonObject2.has("checkResult")) {
						JSONArray jsonObject3 = jsonObject2.getJSONArray("checkResult");
						List<AssemblyResult> list = JSONArray.toList(jsonObject3,AssemblyResult.class);
						return list;
					}
				}
			}else if (svr.equals("CompareBOMdetail")) {
				msgString = jsonObject.getString("msg");
				if(jsonObject.has("cont")) {
					JSONObject jsonObject2 = jsonObject.getJSONObject("cont");
					
					if(jsonObject2.has("compareResult")) {
						
						
						JSONArray jsonObject3 = jsonObject2.getJSONArray("compareResult");
//						JSONObject compare = jsonObject2.getJSONObject("compareResult");
//						assembly_item = compare.getString("assembly_item");
						List<CompareResult> list = JSONArray.toList(jsonObject3,CompareResult.class);
//						System.out.println(jsonObject3+"list"+list.size());
						
						return list;
					}
				}
			}
			
			
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		return null;
	}
// private String doPost1(Map itemCheckMap, String svr) {
//		HashMap<String, String> preferenceHashMap = TCPreferenceUitl.getPreferenceHashMap(session, TCPreferenceService.TC_preference_site, erpPreference);
//		String url = preferenceHashMap.get("url");
//		String token = preferenceHashMap.get("token");
//		JSONObject itemCheckJson = JSONObject.fromObject(itemCheckMap);
//		String sid = null;
//		try {
//			System.out.println("开始发送请求");
//			String args = itemCheckJson.toString();
//			System.out.println(args);
//			token = URLEncoder.encode(token,"UTF-8");
//			svr = URLEncoder.encode(svr,"UTF-8");
//			args = URLEncoder.encode(args,"UTF-8");
//			String param = "usr="+token+"&svr="+svr+"&args="+args;
//			
//			System.out.println("url=============="+url);
//			System.out.println("param==========="+args);
//			String response = HttpUtil.doGet(url+"?"+param);
////			System.out.println("请求结果================"+response);
//			
//			JSONObject jsonObject = JSONObject.fromObject(response);
//			System.out.println("json格式==============="+jsonObject);
//			msgString = jsonObject.getString("msg");
//			if(jsonObject.has("cont")) {
//				JSONObject jsonObject2 = jsonObject.getJSONObject("cont");
//				sid = jsonObject2.getString("sid");
//			}
//			
//		} catch (Exception e1) {
//			// TODO Auto-generated catch block
//			e1.printStackTrace();
//		}
//		return sid;
//	}
 /*     */   
 /*     */   public static void main(String[] args) throws Exception {
	 			
				}
// /* 481 */     String file_path = "C:\\70188_20130522095010011_compare_bom_chg.xml";
// /* 482 */     String txt_path = file_path.replaceAll("\\.xml$", "_r.txt");
// /* 483 */     System.out.println(txt_path);
// /* 484 */     if ((new File(txt_path)).exists()) {
// /* 485 */       Runtime run = Runtime.getRuntime();
// /* 486 */       run.exec("cmd /c start notepad \"" + txt_path + "\"");
// /*     */     } 
// /*     */   }
 /*     */ }

