package com.connor.chint.sap2.assignfactoryno;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import com.connor.chint.sap2.bombuilder.BomBuildDialogController;
import com.connor.chint.sap2.util.KUtil;
import com.connor.chint.sap2.util.ProgressBar;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentItem;
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 plm.xi.com.chintelectric.DT_FACTORY_NUMBER_REQITEMSITEM;

public class FactoryNoZYDialogController {

	private AbstractAIFApplication app;
	private FactoryNoZYDialog dialog;
	
	protected List<FactoryNoZYBean> beanList = new ArrayList<>();
	private String prefix;
	private TCSession session;
	protected Vector<String> lsms = new Vector<String>();
	protected List<DT_FACTORY_NUMBER_REQITEMSITEM> fNoLists = new ArrayList<DT_FACTORY_NUMBER_REQITEMSITEM>();
	protected TCComponent projCon = null;
	private static String TYPE_PROJECTCON = "ZT2_ProjectCon";
	private int min	= 0;
	private int max = 0;
	
	
	
	public FactoryNoZYDialogController(AbstractAIFApplication app, FactoryNoZYDialog factoryNoDialog, String actionInfo) {
		this.app = app;
		this.dialog = factoryNoDialog;
		this.prefix = actionInfo;
		this.session = (TCSession) app.getSession();
	}

	
	
	public boolean checkXMFJ() throws TCException
	{
		boolean flag = false;	
		for(FactoryNoZYBean bean:beanList)
		{
			String name = bean.getCcpRev().getProperty("object_name");
			System.out.println("name:"+name);
			if(name.equals("Ŀ"))
			{
				flag = true;
			}
			if(name.contains(""))
			{
				flag = true;
				break;
			}
		}
		System.out.println("flag:"+flag);
		return flag;
	}
	
	
	
	
	
	public boolean readData(ProgressBar pb) throws Exception{
		//TODO ļвƷôǰ׺ȡǰλûǰ׺Թ̶Ϊ׼ĳͨжϣѡzt2_byq_typeֵ
				//ZCY:KYN61-40.5;KYN28A-24;KYN28A-12;NKM6-12
				//ZCG:XGN15-12;HXGN15-12;XGN2-12;XGN77-40.5;XGN66-12;NHM6-12
				//BJ:
				//MXQ:ĸ
		TCPreferenceService pre=session.getPreferenceService();
		String[] types=pre.getStringValues("zt2_byq_type");
		Map<String, String> typeMap=new HashMap<>();
		for (int i = 0; i < types.length; i++) {
			typeMap.put(types[i].split(":")[0], types[i].split(":")[1]);
			
		}
		InterfaceAIFComponent target = app.getTargetComponent();
		if(target == null || !(target instanceof TCComponentItem)) {
			return false;
		}
		TCComponentItem proj = (TCComponentItem) target;
		TCComponentFolder ccpFolder = KUtil.getCCPFolderFromProject(proj);//Ŀ->Ʒļ
		dialog.factorNoFolder = KUtil.getCCBHFolderFromProject(proj);//Ŀ->ļ
		
		AIFComponentContext[] contexts22 = ((TCComponent) target).whereReferencedByTypeRelation(null,null);
		for(int i=0;i<contexts22.length;i++)
		{
			String type = contexts22[i].getComponent().getType();
			if(TYPE_PROJECTCON.equals(type))
			{
				System.out.println("ҵZT2_ProjectCon͵Ķ:"+contexts22[i].getComponent());
				projCon = (TCComponent) contexts22[i].getComponent();
				break;
			}
			
		}
		
		
		if (ccpFolder == null) {
			KUtil.info(dialog, "δҵļУ" + KUtil.NAME_FOLDER_CCP);
			return false;
		}
		AIFComponentContext[] ccpItems = ccpFolder.getChildren();
		int len = ccpItems == null ? 0 : ccpItems.length;
		if (len == 0) {
			KUtil.info(dialog, "ļΪգ" + KUtil.NAME_FOLDER_CCP);
			return false;
		}
		//pb.showDialog();
		//TODO ϲƥҲҪʾ
		int zcy=-1,zcg=-1,bj=-1,mxq=-1;
		int h_num = 0;
		for (int i = 0; i < len; i++) {
			InterfaceAIFComponent c = ccpItems[i].getComponent();
			pb.setText("ض" + c + "( " + (i + 1) + " / " + len + " )");
			if (c instanceof TCComponentItem) {
				String cctype="";
				boolean hasType=false;
				for(Map.Entry<String, String> me:typeMap.entrySet()) {
					String name=c.getProperty("object_name");
					String key=me.getKey();
					String[] value=me.getValue().split(";");
					for (int j = 0; j < value.length; j++) {
						if(name.contains(value[j] )) {
							cctype=key;
							hasType=true;
							break;
						}
					}
					if(hasType==true) {
						break;
					}
					
				}
				switch(cctype) {
				case "ZCY":
					zcy++;
					break;
				case "ZCG":
					zcg++;
					break;
				case "BJ":
					bj++;
					break;
				case "MXQ":
					mxq++;
					break;
				default:
					break;
				}
				
				TCComponentItemRevision rev = ((TCComponentItem) c).getLatestItemRevision();
				System.out.println("ҵ" + c + ", °汾" + rev);
				String type = rev.getType();
				if (rev != null && type.equals("Part Revision")) {
					FactoryNoZYBean bean = new FactoryNoZYBean(beanList.size()+1, rev);
					beanList.add(bean);
					dialog.tm_bom.addRow(bean.getRowData(dialog.qz,typeMap));//TODO ǰ׺Ҫ޸
					String code = bean.getP_code();
					if(!code.equals(""))
					{
						h_num++;
						lsms.add(code);
					}
				}
			}
		}
		String[] prefixString=new String[typeMap.size()];
		SimpleDateFormat sdf=new SimpleDateFormat("yyMM");
		Date date=new Date();
		String dateString=sdf.format(date);
		int i1=0;
		for(Map.Entry<String, String> me:typeMap.entrySet()) {
			String key=me.getKey();
			prefixString[i1]=key+dateString;
					i1++;
		}
		//ݿ⣬Ϊͨû㿪·Ҳ޸ѡ
		Connection conn=null;
		conn=dialog.connect(conn);
		String[] typeString=new String[] {"ZCY","ZCG","BJ","MXQ"};
		
		String query="select * from CHINT_FLOW WHERE TIME='"+dateString+"'";
		
		Statement stmt = conn.createStatement();
		ResultSet rs_get = null;
		for (int i = 0; i < typeString.length; i++) {
			String selectQuery="select * from CHINT_FLOW where TYPE='"+typeString[i]+"' and TIME='"+dateString+"'";
			String insertQuery="insert into CHINT_FLOW (TYPE,TIME,FLOW) values ('"+typeString[i]+"','"+dateString+"','001')";
			rs_get = stmt.executeQuery(selectQuery);
			if(rs_get.next()) {
				if (rs_get != null) {
					rs_get.close();
				}
			}else {
				rs_get = stmt.executeQuery(insertQuery);
				if (rs_get != null) {
					rs_get.close();
				}
			}
			
		}
		rs_get = stmt.executeQuery(query);
		String[] values=new String[4];
		int count=0;
		while (rs_get.next()) {
			 String type=rs_get.getString("TYPE");
			 String time=rs_get.getString("TIME");
			 String flow=rs_get.getString("FLOW");
			 values[count]=type+";"+time+";"+flow;
			 count++;
		}
		
		dialog.disconnect(conn, stmt, rs_get);
	
		//ûĳ͵ľͲҪʾΧ
		for (int i = 0; i < values.length; i++) {
			String id=values[i].split(";")[0]+values[i].split(";")[1]+values[i].split(";")[2];
			TCComponent[] comps=session.search(" ID", new String[] {" ID"}, new String [] {id});
			if(comps!=null) {
				String lsm="";
				switch(values[i].split(";")[0]) {
				case "ZCY":
					if(zcy<0) {
						lsm= "";
						dialog.jtf_zcy.setVisible(false);
//						dialog.panel2.remove(dialog.jtf_zcy);
					}else {
						//жǷǵǰ·
						
						lsm= values[i].split(";")[0]+":"+values[i].split(";")[2]+"-"+String.format("%03d", zcy+Integer.valueOf(values[i].split(";")[2]));
//						dialog.jtf_zcy.setVisible(true);
					}
					dialog.jtf_zcy.setText(lsm);
					break;
				case "ZCG":
					if(zcg<0) {
						lsm= "";
						dialog.jtf_zcg.setVisible(false);
//						dialog.panel2.remove(dialog.jtf_zcg);
					}else {
						dialog.jtf_zcg.setVisible(true);
						lsm =values[i].split(";")[0]+":" +values[i].split(";")[2]+"-"+String.format("%03d", zcg+Integer.valueOf(values[i].split(";")[2]));
					}
					dialog.jtf_zcg.setText(lsm);
					break;
				case "BJ":
					if(bj<0) {
						lsm= "";
						dialog.jtf_bj.setVisible(false);
//						dialog.panel2.remove(dialog.jtf_bj);
					}else {
						dialog.jtf_bj.setVisible(true);
						lsm =values[i].split(";")[0]+":" + values[i].split(";")[2]+"-"+String.format("%03d", bj+Integer.valueOf(values[i].split(";")[2]));
					}
					dialog.jtf_bj.setText(lsm);
					break;
				case "MXQ":
					if(mxq<0) {
						lsm= "";	
						dialog.jtf_mxq.setVisible(false);
						dialog.panel2.remove(dialog.jtf_mxq);
					}else {
						dialog.jtf_mxq.setVisible(true);
						lsm =values[i].split(";")[0]+":" + values[i].split(";")[2]+"-"+String.format("%03d", mxq+Integer.valueOf(values[i].split(";")[2]));
					}
					dialog.jtf_mxq.setText(lsm);
					break;
				default:
					break;
				}
			}
			
		}
		return true;
		
	
	}
	public static void main(String[] args) {
		Vector<String> vecs2 = new Vector<String>();
		int code = Integer.parseInt("042");
		System.out.println("code:["+code+"]");
		vecs2.add(String.valueOf(code));
		for(int i=40;i<45;i++)
		{
			System.out.println("i:"+i);
			int index = vecs2.indexOf(String.valueOf(Integer.parseInt(""+i)));
			if(index!=-1)
			{
				System.out.println("index:"+index);
				System.out.println("ֵͬ");
				vecs2.remove(""+i);
				//vecs2.removeElementAt(index);
				continue;
			}
			vecs2.add(""+i);
		}
		
		for(int i=0;i<vecs2.size();i++)
		{
			System.out.println("vec:"+vecs2.get(i));
		}
	}
	public String lsm(String lsm) {
		if(lsm.length()==0) {
			return lsm;
		}else {
			lsm=lsm.split(":")[1].split("-")[1];
			int lsmInt=Integer.valueOf(lsm)+1;
			lsm=String.format("%03d", lsmInt);
			return lsm;
		}
	}
	public Map<String,String> addMap(Map<String, String> rangeMap,String text){
		String[] type=text.split(":");
		if(type.length>1) {
			rangeMap.put(type[0], type[1]);	
		}
		return rangeMap;
	}
	/*createCode=1ʾ½createCode=0ʾҪ½*/
	public void assign(ProgressBar pb,int index2,int createCode) throws Exception{
		//еı
		Map<String, String> rangeMap=new HashMap<>();
		rangeMap=addMap(rangeMap, dialog.jtf_zcy.getText());
		rangeMap=addMap(rangeMap, dialog.jtf_zcg.getText());
		rangeMap=addMap(rangeMap, dialog.jtf_bj.getText());
		rangeMap=addMap(rangeMap, dialog.jtf_mxq.getText());
		
		
		
		
		index2=dialog.t_bom.getRowCount();
		Map<String, List<String>> map=new HashMap<>();
		Map<String, String> repeatMap=new HashMap<>();
		
		StringBuilder sb=new StringBuilder("");
		for (int i = 0; i < index2; i++) {
			String prefix=(String) dialog.t_bom.getValueAt(i, 5);//ˮǰ׺
			String flowNo=(String) dialog.t_bom.getValueAt(i, 6);//ˮ
			if(flowNo.trim().length()>0) {
				if(repeatMap.containsValue(prefix+flowNo)) {
					for(Map.Entry<String, String> me:repeatMap.entrySet()) {
						if(me.getValue().equals(prefix+flowNo)) {
							
							sb.append(""+me.getKey()+"ˮ"+(i+1)+"ظ\n");
							break;
						}
					}
				}else {
					
					repeatMap.put(i+1+"", prefix+flowNo);
				}
			}else {
				
				sb.append(""+(i+1)+"ˮδд\n");
				continue;
			}
			
			List<String> value=map.get(prefix);
			if(value!=null) {
				
				if(value.contains(flowNo)) {
//				sb.append(""+(i+1)+"ˮظ\n");
					continue;
//				throw new Exception(""+(i+1)+"ˮظ");
				}else {
					for(Map.Entry<String, String> me:rangeMap.entrySet()) {
						if(prefix.startsWith(me.getKey())) {
							String[] range=me.getValue().split("-");
							int r1=Integer.valueOf(range[0]);
							int r2=Integer.valueOf(range[1]);
							int r=Integer.valueOf(flowNo);
							if(r>r2||r<r1) {
								sb.append(""+(i+1)+"ˮддָΧڵˮ\n");	
								break;
							}else {
								value.add(flowNo);
								map.put(prefix, value);
							}
						}
					}
				}
			}else {
				for(Map.Entry<String, String> me:rangeMap.entrySet()) {
					if(prefix.startsWith(me.getKey())) {
						String[] range=me.getValue().split("-");
						int r1=Integer.valueOf(range[0]);
						int r2=Integer.valueOf(range[1]);
						int r=Integer.valueOf(flowNo);
						if(r>r2||r<r1) {
							sb.append(""+(i+1)+"ˮддָΧڵˮ\n");	
							break;
						}else {
							value=new ArrayList<>();
							value.add(flowNo);
							map.put(prefix, value);
						}
					}
				}
			}
			
		}
		
		if(sb.length()>0) {
			throw new Exception("⣬飺\n"+sb.toString());
		}
		//½ҰѶճָλ
		int len = beanList.size();
//		System.out.println("len==========="+len);
//		System.out.println("createCode==========="+createCode);
		if(len==0) {
			return;
		}
		Map<String, TCComponentItemRevision> facMap=new HashMap<>();
		StringBuilder sb2=new StringBuilder("");
		if(createCode==0) {
			
			for (int i = 0; i < len; i++) {
				TCComponentItemRevision ccpRev=beanList.get(i).getCcpRev();
				String item_id=(String)dialog.t_bom.getValueAt(i, 5)+(String)dialog.t_bom.getValueAt(i, 6);
				//ѯǷڣٴ
				TCComponent[] item=session.search(" ID", new String[] {" ID"}, new String[] {item_id});
				if(item==null||item.length==0) {
					facMap.put(item_id, ccpRev);
				}else {
					sb2.append("ڳŶ"+item_id+"\n");
				}
			}
		}else {
			for (int i = 0; i < len; i++) {
				TCComponentItemRevision ccpRev=beanList.get(i).getCcpRev();
				String item_id=(String)dialog.t_bom.getValueAt(i, 5)+(String)dialog.t_bom.getValueAt(i, 6);
				//ѯǷڣٴ
				facMap.put(item_id, ccpRev);
				
			}
		}
		
		if(sb2.length()>0) {
			
			throw new Exception("ʧܣ\n"+sb2.toString());
		}else {
			if(createCode==0) {
				
				for(Map.Entry<String, TCComponentItemRevision> me:facMap.entrySet()) {
					String item_id=me.getKey();
					TCComponentItemRevision rev=me.getValue();
					TCComponentItem item = KUtil.newItem(session,BomBuildDialogController.TYPE_FACTORYNO,item_id,item_id);
					TCComponent[] comps= rev.getRelatedComponents(BomBuildDialogController.REL_FACTORYNO);
					rev.cutOperation(BomBuildDialogController.REL_FACTORYNO, comps);
					rev.add(BomBuildDialogController.REL_FACTORYNO, item);
					
					TCComponentFolder folder = dialog.factorNoFolder;
					if(folder!=null)
					{
						folder.cutOperation("contents", comps);
						folder.add("contents", item);
					}
				}
			}else {
//				System.out.println("ʼ");
				for(Map.Entry<String, TCComponentItemRevision> me:facMap.entrySet()) {
					String item_id=me.getKey();
					System.out.println(item_id);
					TCComponentItemRevision rev=me.getValue();
					System.out.println(rev.getProperty("item_id"));
					TCComponent[] item = session.search(" ID", new String[] {" ID"}, new String[] {item_id});
					TCComponent[] comps= rev.getRelatedComponents(BomBuildDialogController.REL_FACTORYNO);
					rev.cutOperation(BomBuildDialogController.REL_FACTORYNO, comps);
//					System.out.println("1111111");
					rev.add(BomBuildDialogController.REL_FACTORYNO, item[0]);
					
					
				}
			}
		}
		
		if(createCode==0) {
			
			//޸ѡzt2_ZYˮ
			Map<String,String> lsmMap=new HashMap<>();
			String lsm="";
			lsm=lsm(dialog.jtf_zcy.getText());
			if(lsm.length()>0) {
				lsmMap.put(dialog.jtf_zcy.getText().split(":")[0], lsm);
			}
			
			lsm=lsm(dialog.jtf_zcg.getText());
			if(lsm.length()>0) {
				lsmMap.put(dialog.jtf_zcg.getText().split(":")[0], lsm);
			}
			
			lsm=lsm(dialog.jtf_bj.getText());
			if(lsm.length()>0) {
				lsmMap.put(dialog.jtf_bj.getText().split(":")[0], lsm);
			}
			
			lsm=lsm(dialog.jtf_mxq.getText());
			if(lsm.length()>0) {
				lsmMap.put(dialog.jtf_mxq.getText().split(":")[0], lsm);
			}
			
			SimpleDateFormat sdf=new SimpleDateFormat("yyMM");
			String dateString=sdf.format(new Date());
			List<String> sqlList=new ArrayList<>();
			for (Map.Entry<String, String> me:lsmMap.entrySet()) {
				sqlList.add("update CHINT_FLOW set TIME='"+dateString+"', FLOW='"+me.getValue()+"' where TYPE='"+me.getKey()+"' and TIME='"+dateString+"'");
			}
			Connection conn=null;
			conn=dialog.connect(conn);
			Statement stmt = conn.createStatement();
			ResultSet rs_get = null;
			for (int i = 0; i < sqlList.size(); i++) {
				rs_get = stmt.executeQuery(sqlList.get(i));
				if ((rs_get.next())) {
					System.out.println(" update2==========");
				}
				if (rs_get != null) {
					rs_get.close();
				}
			}
			
			
			dialog.disconnect(conn, stmt, rs_get);
		}
		
		
		
		pb.disposeDialog();
		KUtil.info(dialog, "Ž");
		
		
		if(true) {
			return;
		}
		
		if(lsms.size()==beanList.size())
		{
			throw new Exception("Ŀ");
		}
		Vector<String> vecs = new Vector<String>();
		Vector<String> vecs2 = new Vector<String>();
		for(int i=min;i<=max;i++)
		{
			vecs2.add(String.valueOf(i));
		}
		
		int index=0;
		for(int i=0;i<len;i++)
		{
			Object obj = dialog.t_bom.getValueAt(i, 6);
			if(obj.equals(""))
			{
				throw new Exception(""+(i+1)+"ˮδд");
			}
			
			if(obj!=null && !obj.equals(""))
			{
				String code = String.valueOf(obj);
				
				if(vecs2.indexOf(String.valueOf(Integer.parseInt(code)))==-1 && beanList.get(i).getFactNoItem()==null)
				{
					throw new Exception(""+(i+1)+"ˮддָΧڵˮ");
				}
				if(vecs.indexOf(code)!=-1)
				{
					throw new Exception(""+(i+1)+""+(vecs.indexOf(code)+1)+"ˮظΪϷͬIDĳ룬");
				}
				if(beanList.get(i).getFactNoItem()!=null)
				{
					index++;
				}
				vecs.add(code);
				
			}
		}
		
		if(vecs.size()<len)
		{
			throw new Exception("Ϊÿһз");
		}
		DT_FACTORY_NUMBER_REQITEMSITEM items[] = new DT_FACTORY_NUMBER_REQITEMSITEM[len];
		
		pb.showDialog();
		for (int i = 0; i < len; i++) {
			pb.setText("...( " + (i + 1) + " / " + len + " )");
			Object obj = dialog.t_bom.getValueAt(i, 6);
			String newId = "";
			FactoryNoZYBean bean = beanList.get(i);
			
			//DT_FACTORY_NUMBER_REQITEMSITEM item = new DT_FACTORY_NUMBER_REQITEMSITEM();
			
			String con_id = projCon==null?"":projCon.getProperty("item_id");
			String wbs = projCon==null?"":projCon.getProperty("zt2_WBSNo");
			/*
			item.setPSPID(con_id);
			item.setZPSPID(wbs);
			item.setMATNR(bean.getMaterialNo());
			item.setZZD(bean.getSite());
			item.setZGH(bean.getTankNo());
			item.setSERNR(bean.getFactNoItemID());
			item.setWERKS("M008"); 	//ѹĬMOO8
			*/
			if(index!=0) {
				int code=0;
				if(obj!=null && !obj.equals("")) {
					code = Integer.parseInt((String) obj);
					int cind = vecs.indexOf(obj);
					System.out.println("cind:"+cind);
					System.out.println("code"+code);
					//vecs.remove(""+code);		
					vecs.remove(cind);
				}else
				{
					String str = vecs.get(0);
					code = Integer.parseInt(str);
					vecs.remove(0);
				}								
				newId= beanList.get(i).assign(session,prefix,dialog,code);
			}
			else {
				newId= beanList.get(i).assign(session,prefix,dialog,-1);			
			}
			if(newId!=null) {
				dialog.t_bom.setValueAt(newId.substring(0, 7), i, 5);
				dialog.t_bom.setValueAt(newId.substring(7,newId.length()), i,6);
			}
			
			//items[i] = item;
		}
		//sendFactoryNo(items);
		pb.disposeDialog();
		KUtil.info(dialog, "Ž");
	}
	public void assign(ProgressBar pb) throws Exception{
		int len = beanList.size();
		if(len==0) {
			return;
		}
		if(lsms.size()==beanList.size())
		{
			throw new Exception("Ŀ");
		}
		Vector<String> vecs = new Vector<String>();
		Vector<String> vecs2 = new Vector<String>();
		for(int i=min;i<=max;i++)
		{
			vecs2.add(String.valueOf(i));
		}
		
		int index=0;
		for(int i=0;i<len;i++)
		{
			Object obj = dialog.t_bom.getValueAt(i, 6);
			if(obj.equals(""))
			{
				throw new Exception(""+(i+1)+"ˮδд");
			}
			
			if(obj!=null && !obj.equals(""))
			{
				String code = String.valueOf(obj);
				
				if(vecs2.indexOf(String.valueOf(Integer.parseInt(code)))==-1 && beanList.get(i).getFactNoItem()==null)
				{
					throw new Exception(""+(i+1)+"ˮддָΧڵˮ");
				}
				if(vecs.indexOf(code)!=-1)
				{
					throw new Exception(""+(i+1)+""+(vecs.indexOf(code)+1)+"ˮظΪϷͬIDĳ룬");
				}
				if(beanList.get(i).getFactNoItem()!=null)
				{
					index++;
				}
				vecs.add(code);
				
			}
		}
		
		if(vecs.size()<len)
		{
			throw new Exception("Ϊÿһз");
		}
		DT_FACTORY_NUMBER_REQITEMSITEM items[] = new DT_FACTORY_NUMBER_REQITEMSITEM[len];
		
		pb.showDialog();
		for (int i = 0; i < len; i++) {
			pb.setText("...( " + (i + 1) + " / " + len + " )");
			Object obj = dialog.t_bom.getValueAt(i, 6);
			String newId = "";
			FactoryNoZYBean bean = beanList.get(i);
			
			//DT_FACTORY_NUMBER_REQITEMSITEM item = new DT_FACTORY_NUMBER_REQITEMSITEM();
			
			String con_id = projCon==null?"":projCon.getProperty("item_id");
			String wbs = projCon==null?"":projCon.getProperty("zt2_WBSNo");
			/*
			item.setPSPID(con_id);
			item.setZPSPID(wbs);
			item.setMATNR(bean.getMaterialNo());
			item.setZZD(bean.getSite());
			item.setZGH(bean.getTankNo());
			item.setSERNR(bean.getFactNoItemID());
			item.setWERKS("M008"); 	//ѹĬMOO8
			*/
			if(index!=0) {
				int code=0;
				if(obj!=null && !obj.equals("")) {
					code = Integer.parseInt((String) obj);
					int cind = vecs.indexOf(obj);
					System.out.println("cind:"+cind);
					System.out.println("code"+code);
					//vecs.remove(""+code);		
					vecs.remove(cind);
				}else
				{
					String str = vecs.get(0);
					code = Integer.parseInt(str);
					vecs.remove(0);
				}								
				newId= beanList.get(i).assign(session,prefix,dialog,code);
			}
			else {
				newId= beanList.get(i).assign(session,prefix,dialog,-1);			
			}
			if(newId!=null) {
				dialog.t_bom.setValueAt(newId.substring(0, 7), i, 5);
				dialog.t_bom.setValueAt(newId.substring(7,newId.length()), i,6);
			}
			
			//items[i] = item;
		}
		//sendFactoryNo(items);
		pb.disposeDialog();
		KUtil.info(dialog, "Ž");
	}

	public void recovery()
	{
		int len = beanList.size();
		for (int i = 0; i < len; i++) {
			dialog.t_bom.setValueAt(beanList.get(i).getP_code(), i,6);
		}
	}
	
	
	
	
	
	
}
