/**
 * output package name
 */
package com.kingdee.eas.custom.gggl.client;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentEvent;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.ctrl.extendcontrols.KDBizPromptBox;
import com.kingdee.bos.ctrl.kdf.table.IRow;
import com.kingdee.bos.ctrl.kdf.table.KDTable;
import com.kingdee.bos.ctrl.kdf.table.event.KDTEditEvent;
import com.kingdee.bos.ctrl.kdf.table.event.KDTSelectEvent;
import com.kingdee.bos.ctrl.swing.KDPanel;
import com.kingdee.bos.ctrl.swing.KDTextField;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.bos.ui.face.IUIWindow;
import com.kingdee.bos.ui.face.UIFactory;
import com.kingdee.bos.ui.face.UIRuleUtil;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.basedata.org.CompanyOrgUnitInfo;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.common.client.OprtState;
import com.kingdee.eas.common.client.SysContext;
import com.kingdee.eas.common.client.UIContext;
import com.kingdee.eas.common.client.UIFactoryName;
import com.kingdee.eas.custom.gggl.AdvertInfo;
import com.kingdee.eas.custom.gggl.DTypeEnum;
import com.kingdee.eas.custom.gggl.ReceTypeInfo;
import com.kingdee.eas.custom.gggl.SaleContractFactory;
import com.kingdee.eas.custom.gggl.SaleContractInfo;
import com.kingdee.eas.util.SysUtil;
import com.kingdee.eas.util.client.MsgBox;
import com.kingdee.eas.xr.XRSQLFacadeFactory;
import com.kingdee.eas.xr.helper.DateDaySub;
import com.kingdee.eas.xr.helper.PersonXRHelper;
import com.kingdee.eas.xr.helper.TableXRHelper;
import com.kingdee.jdbc.rowset.IRowSet;

/**
 * output class name
 */
public class SaleContractEditUI extends AbstractSaleContractEditUI
{
	private static final Logger logger = CoreUIObject.getLogger(SaleContractEditUI.class);
	Component[] defaultRequired = {txtNumber,prmtcustomer,txthtAmount,zhlx,txtyjAmount,txthtnn,txtbeiz,txthtNum,txthtmc,pkBizDate,
			txtpp,comboStatus,prmtcompany,prmtzrPerson,prmtdeparment};
	/**
	 * output class constructor
	 */
	public SaleContractEditUI() throws Exception
	{
		super();
	}
	
	//注意：如果发布这个编辑界面 ，发布以后请把 分录  kdtE1 和 kdtE2 父类里面的 ：广告位编码字段 的 展现左树右表 的界面注销掉 ，要不然过滤不了. 就是下面的代码 
//	kdtE2_ggw_PromptBox.addSelectorListener(new SelectorListener() {
//	com.kingdee.eas.custom.gggl.client.AdvertListUI kdtE2_ggw_PromptBox_F7ListUI = null;
//	public void willShow(SelectorEvent e) {
//		if (kdtE2_ggw_PromptBox_F7ListUI == null) {
//			try {
//				kdtE2_ggw_PromptBox_F7ListUI = new com.kingdee.eas.custom.gggl.client.AdvertListUI();
//			} catch (Exception e1) {
//				e1.printStackTrace();
//			}
//			HashMap ctx = new HashMap();
//			ctx.put("bizUIOwner",javax.swing.SwingUtilities.getWindowAncestor(kdtE2_ggw_PromptBox_F7ListUI));
//			kdtE2_ggw_PromptBox_F7ListUI.setF7Use(true,ctx);
//			kdtE2_ggw_PromptBox.setSelector(kdtE2_ggw_PromptBox_F7ListUI);
//		}
//	}
//});
	
	/**
	 * output loadFields method
	 */
	public void loadFields()
	{
		super.loadFields();
		//租赁周期不可录入
		kdtE1.getColumn("zlzq").getStyleAttributes().setLocked(true);
		kdtE1.getColumn("seq").getStyleAttributes().setHided(true);
		kdtE2.getColumn("seq").getStyleAttributes().setHided(true);

	}

	/**
	 * output storeFields method
	 */
	public void storeFields()
	{
		super.storeFields();
	}
	
	/*
	 * onlaod方法
	 *
	 */
	public void onLoad() throws Exception {
		super.onLoad();
//		 setPreferredSize(getMaximumSize());
		if("ADDNEW".equals(oprtState)){
			//中庭
			if(getUIContext().get("djType")!=null && djType.getSelectedItem()!=null &&  "2".equals(getUIContext().get("djType").toString())){
				this.djType.setSelectedItem(DTypeEnum.zt);
				
		    	EntityViewInfo view = new EntityViewInfo();
				FilterInfo filInfo = new FilterInfo();
				filInfo.getFilterItems().add(new FilterItemInfo("treeid.id","JQcAAAAAgOrsyXfw" ,CompareType.EQUALS));//这个id是广告位管理里面 对应中庭
				view.setFilter(filInfo);
				KDBizPromptBox bizBox = (KDBizPromptBox) kdtE1.getColumn("ggw").getEditor().getComponent();//获取分录里面的F7字段
				bizBox.setEntityViewInfo(view);
				
				KDBizPromptBox bizBox2 = (KDBizPromptBox) kdtE2.getColumn("ggw").getEditor().getComponent();//获取分录里面的F7字段
				bizBox2.setEntityViewInfo(view);
			}
			
			//广告
			
			if( djType.getSelectedItem()!=null &&  djType.getSelectedItem()==DTypeEnum.gg){
				this.djType.setSelectedItem(DTypeEnum.gg);
				
		    	EntityViewInfo view = new EntityViewInfo();
				FilterInfo filInfo = new FilterInfo();
				filInfo.getFilterItems().add(new FilterItemInfo("treeid.id","JQcAAAAAgOrsyXfw" ,CompareType.NOTEQUALS));//这个id是广告位管理里面 对应中庭
				view.setFilter(filInfo);
				KDBizPromptBox bizBox = (KDBizPromptBox) kdtE1.getColumn("ggw").getEditor().getComponent();//获取分录里面的F7字段
				bizBox.setEntityViewInfo(view);
				
				KDBizPromptBox bizBox2 = (KDBizPromptBox) kdtE2.getColumn("ggw").getEditor().getComponent();//获取分录里面的F7字段
				bizBox2.setEntityViewInfo(view);
			}
		}else{
			//广告
			if( djType.getSelectedItem()!=null &&  djType.getSelectedItem()==DTypeEnum.gg){
				this.djType.setSelectedItem(DTypeEnum.gg);
				
		    	EntityViewInfo view = new EntityViewInfo();
				FilterInfo filInfo = new FilterInfo();
				filInfo.getFilterItems().add(new FilterItemInfo("treeid.id","JQcAAAAAgOrsyXfw" ,CompareType.NOTEQUALS));//这个id是广告位管理里面 对应中庭
				view.setFilter(filInfo);
				KDBizPromptBox bizBox = (KDBizPromptBox) kdtE1.getColumn("ggw").getEditor().getComponent();//获取分录里面的F7字段
				bizBox.setEntityViewInfo(view);
				
				KDBizPromptBox bizBox2 = (KDBizPromptBox) kdtE2.getColumn("ggw").getEditor().getComponent();//获取分录里面的F7字段
				bizBox2.setEntityViewInfo(view);
			}else{
		    	EntityViewInfo view = new EntityViewInfo();
				FilterInfo filInfo = new FilterInfo();
				filInfo.getFilterItems().add(new FilterItemInfo("treeid.id","JQcAAAAAgOrsyXfw" ,CompareType.EQUALS));//这个id是广告位管理里面 对应中庭
				view.setFilter(filInfo);
				KDBizPromptBox bizBox = (KDBizPromptBox) kdtE1.getColumn("ggw").getEditor().getComponent();//获取分录里面的F7字段
				bizBox.setEntityViewInfo(view);
				
				KDBizPromptBox bizBox2 = (KDBizPromptBox) kdtE2.getColumn("ggw").getEditor().getComponent();//获取分录里面的F7字段
				bizBox2.setEntityViewInfo(view);
			}
		}
		
			if((!"ADDNEW".equals(oprtState)) ){
				getAddRow(this.editData.getId()) ;
			}
		
		
		 TableXRHelper.getFootRow(kdtE1, new String[]{"zlAmount","zzAmount"});    /*分录合计*/
		 TableXRHelper.getFootRow(kdtE2, new String[]{"skAmount","recAmount"});    /*分录合计*/
		 setTableToSumField(kDTable1, new String[]{"skAmount","pAmount"});    /*分录合计*/
		 
	
		 

	}
	
	
	  /**
     * output 
     */
    public void getAddRow(BOSUuid id) throws BOSException, SQLException
    {
    	
    	StringBuffer sql=new StringBuffer();
    	sql.append(" select  '收款' type, ma.fname_l2 recType, bill.CFSALECONTRACTID htID, bill.fbizdate bizdate, en.FACTUALAMT  Amount   ");
    	sql.append(" from T_CAS_ReceivingBillentry en ");
    	sql.append(" left join  T_CAS_ReceivingBill bill on en.FRECEIVINGBILLID=bill.fid ");
    	sql.append(" left join  T_AR_OtherBillentry oen on en.FSOURCEBILLENTRYID=oen.fid ");
    	sql.append(" left join T_BD_Material ma on ma.fid=oen.FMATERIALID ");
    	sql.append(" where bill.CFISHY='1' and bill.CFSALECONTRACTID='"+id+"' ");
     	sql.append(" union all ");
     	sql.append(" select  '付款' type, ma.fname_l2 recType, pay.CFSALECONTRACTID htID, pay.fbizdate bizdate,payEntry.FACTUALAMT Amount ");
     	sql.append(" from T_CAS_PaymentBillEntry  payEntry   ");
     	sql.append(" left join T_CAS_PaymentBill  pay on payEntry.FPaymentBillID =  pay.fid  ");
     	sql.append(" left join T_AP_OtherBillentry oterEntry on oterEntry.fid =payEntry.FSOURCEBILLENTRYID");
     	sql.append(" left join T_BD_Material ma on ma.FID  = oterEntry.FMATERIALID ");
     	sql.append(" where pay.CFISHY='1' and pay.CFSALECONTRACTID='"+id+"'  ");
    	
    	
		IRowSet rowset=XRSQLFacadeFactory.getRemoteInstance().executeQuery(sql.toString(), null);
		while(rowset.next()){
			String type =rowset.getString("type");
			
			String recType =rowset.getString("recType");
			String bizdate =rowset.getString("bizdate");
			String Amount =rowset.getString("Amount");
			IRow row=	kDTable1.addRow();
			row.getCell("recType").setValue(recType);
			if(type.equals("收款")){
				row.getCell("skDate").setValue(bizdate);
				row.getCell("skAmount").setValue(Amount);
			}else{
				row.getCell("payDate").setValue(bizdate);
				row.getCell("pAmount").setValue(Amount);
			}
		
		
			
		}
		
    }
	
	/*
	 * 查看对应的排期表
	 * 
	 */
	protected void btnGgPq_actionPerformed(ActionEvent e) throws Exception {
		super.btnGgPq_actionPerformed(e);

		KDPanel PanelName=(KDPanel) kDTabbedPane1.getSelectedComponent();
    	if(PanelName.equals(kDPanel1)){

		if(kdtE1.getSelectManager().getActiveRowIndex()==-1){
			MsgBox.showConfirm2("请选择对应行！");
			SysUtil.abort();
		}
		int row=kdtE1.getSelectManager().getActiveRowIndex();
		if(kdtE1.getCell(row, "ggw").getValue()!=null){
			UIContext  context = new UIContext(this);
			String ggname=kdtE1.getCell(row, "ggw").getValue().toString();
			context.put("ggname", ggname);

			if(djType.getSelectedItem()==DTypeEnum.zt){
				IUIWindow create = UIFactory.createUIFactory(UIFactoryName.NEWWIN).create(AdvertManUI.class.getName(),context,null,OprtState.VIEW);
				create.show();
			}
			if(djType.getSelectedItem()==DTypeEnum.gg){
				IUIWindow create = UIFactory.createUIFactory(UIFactoryName.NEWWIN).create(AdvertGuangGaoPaiQiUI.class.getName(),context,null,OprtState.VIEW);
				create.show();
			}
		}else{
			MsgBox.showConfirm2("您选择的行：对应的广告位编码为空！");
			SysUtil.abort();
		}
    }


    	if(PanelName.equals(kDPanel2)){
    		if(kdtE2.getSelectManager().getActiveRowIndex()==-1){
    			MsgBox.showConfirm2("请选择对应行！");
    			SysUtil.abort();
    		}
    		int row=kdtE2.getSelectManager().getActiveRowIndex();
    		if(kdtE2.getCell(row, "ggw").getValue()!=null){
    			UIContext  context = new UIContext(this);
    			String ggname=kdtE2.getCell(row, "ggw").getValue().toString();
    			context.put("ggname", ggname);
    			if(djType.getSelectedItem()==DTypeEnum.zt){
    				IUIWindow create = UIFactory.createUIFactory(UIFactoryName.NEWWIN).create(AdvertManUI.class.getName(),context,null,OprtState.VIEW);
    				create.show();
    				}
    			
    			if(djType.getSelectedItem()==DTypeEnum.gg){
    				IUIWindow create = UIFactory.createUIFactory(UIFactoryName.NEWWIN).create(AdvertGuangGaoPaiQiUI.class.getName(),context,null,OprtState.VIEW);
    				create.show();
    				}
    		}else{
    			MsgBox.showConfirm2("您选择的行：对应的广告位编码为空！");
    			SysUtil.abort();
    		}
        }
	
	}

	public void onShow() throws Exception {
		super.onShow();
	}

	/**
	 * output actionEdit_actionPerformed
	 */
	public void actionEdit_actionPerformed(ActionEvent e) throws Exception
	{
		super.actionEdit_actionPerformed(e);
	}

	/**
	 * output actionRemove_actionPerformed
	 */
	public void actionRemove_actionPerformed(ActionEvent e) throws Exception
	{
		super.actionRemove_actionPerformed(e);
	}

	/**
	 * output actionAudit_actionPerformed
	 */
	public void actionAudit_actionPerformed(ActionEvent e) throws Exception
	{
		super.actionAudit_actionPerformed(e);
	}
	
	/**
	 * output actionUnAudit_actionPerformed
	 */
	public void actionUnAudit_actionPerformed(ActionEvent e) throws Exception
	{
		super.actionUnAudit_actionPerformed(e);
	}

	/**
	 * output getBizInterface method
	 */
	protected com.kingdee.eas.framework.ICoreBase getBizInterface() throws Exception
	{
		return com.kingdee.eas.custom.gggl.SaleContractFactory.getRemoteInstance();
	}

	/**
	 * output createNewDetailData method
	 */
	protected IObjectValue createNewDetailData(KDTable table)
	{
		return null;
	}

	/**
	 * output createNewData method
	 */
	protected com.kingdee.bos.dao.IObjectValue createNewData()
	{
		com.kingdee.eas.custom.gggl.SaleContractInfo objectValue = new com.kingdee.eas.custom.gggl.SaleContractInfo();
		objectValue.setCreator((com.kingdee.eas.base.permission.UserInfo)(com.kingdee.eas.common.client.SysContext.getSysContext().getCurrentUser()));
		objectValue.setBizDate(new Date());
		CompanyOrgUnitInfo info= SysContext.getSysContext().getCurrentFIUnit();
		if(SysContext.getSysContext().getCurrentUserInfo()!=null){
			PersonInfo uinf0= SysContext.getSysContext().getCurrentUserInfo().getPersonId();

			objectValue.setZrPerson(uinf0);
			objectValue.setCompany(info);
			objectValue.setDeparment(PersonXRHelper.getPosiMemByDeptUser(uinf0));
		}
		return objectValue;
	}

	protected void attachListeners() {
		// TODO Auto-generated method stub

	}
	protected void detachListeners() {
		// TODO Auto-generated method stub

	}
	protected KDTextField getNumberCtrl() {
		// TODO Auto-generated method stub
		return null;
	}
	protected void verifyInputForSave() throws Exception {
	}
	protected void verifyInputForSubmit() throws Exception {
		
		 BigDecimal zlAmount1= UIRuleUtil.getBigDecimal(UIRuleUtil.sum(kdtE1,"zlAmount"));
		 BigDecimal zzAmount1= UIRuleUtil.getBigDecimal(UIRuleUtil.sum(kdtE1,"zzAmount"));
		 BigDecimal zlAmount=BigDecimal.ZERO;
		 BigDecimal zzAmount=BigDecimal.ZERO;
		 //****判断租赁信息分录与收款计划分录金额要一致
		 for(int i=0;i<kdtE2.getRowCount();i++){
			 ReceTypeInfo info= (ReceTypeInfo) kdtE2.getCell(i, "recType").getValue();
			 if(info.getNumber().equals("001")){
			   BigDecimal skAmount=  UIRuleUtil.getBigDecimal(kdtE2.getCell(i, "skAmount").getValue());
			   zlAmount=zlAmount.add(skAmount);
			 }
			 if(info.getNumber().equals("002")){
			  BigDecimal skAmount=  UIRuleUtil.getBigDecimal(kdtE2.getCell(i, "skAmount").getValue());
			  zzAmount=zzAmount.add(skAmount);
			}
		 }
		 if(zlAmount1.compareTo(zlAmount)!=0){
				MsgBox.showWarning("租赁金额："+zlAmount1+"与收款计划中租赁费:"+zlAmount+"不一致！");
				SysUtil.abort();
		 }
		 /*
		  *to  勾选采购申请维修是解除制作费的控制
		  * 
		  */
		 
		 		SaleContractInfo sleContractinfo=SaleContractFactory.getRemoteInstance().getSaleContractInfo(new ObjectUuidPK(editData.getId()));
				if(sleContractinfo.get("purReset")!=null){							//界面有采购申请维修字段
					if(sleContractinfo.get("purReset").toString().equalsIgnoreCase("true")){//勾选采购申请维修是解除制作费的控制
						 
					}else{										
						if(zzAmount1.compareTo(zzAmount)!=0){								//未勾选采购申请维修是解除制作费的控制
							  MsgBox.showWarning("制作费："+zzAmount1+"与收款计划中制作费:"+zzAmount+"不一致！");
							  SysUtil.abort();}
						  }
				}else{																//界面没有采购申请维修字段
						if(zzAmount1.compareTo(zzAmount)!=0){
						  MsgBox.showWarning("制作费："+zzAmount1+"与收款计划中制作费:"+zzAmount+"不一致！");
						  SysUtil.abort();
					 	}
						
					}
					
				
				
		
		  
		 
	}
//	protected void pkBizDate_dataChanged(DataChangeEvent e) throws Exception {
		// TODO Auto-generated method stub
		//super.pkBizDate_dataChanged(e);

		//	if(this.pkBizDate.getValue()!=null){
		//	Date  	zlStartDate=(Date) this.pkBizDate.getValue();
		//	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
		//	String da=df.format(new Date());
		//	Date dd=df.parse(da);

		//	if(zlStartDate.before(dd)){
		//		MsgBox.showWarning("ss");
		//	}else{
		//		MsgBox.showWarning("zz");
		//	}
		//}
//	}
	//TODO 
	protected void verifyInput(ActionEvent e) throws Exception {
	
		if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(txthtmc.getText())) {
			throw new com.kingdee.eas.common.EASBizException(com.kingdee.eas.common.EASBizException.CHECKBLANK,new Object[] {"合同名称"});
		}
		if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(prmtcompany.getData())) {
			throw new com.kingdee.eas.common.EASBizException(com.kingdee.eas.common.EASBizException.CHECKBLANK,new Object[] {"公司"});
		}
		if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(prmtcustomer.getData())) {
			throw new com.kingdee.eas.common.EASBizException(com.kingdee.eas.common.EASBizException.CHECKBLANK,new Object[] {"客户"});
		}
//		if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(txthtAmount.getValue())) {
//			throw new com.kingdee.eas.common.EASBizException(com.kingdee.eas.common.EASBizException.CHECKBLANK,new Object[] {"合同含税金额"});
//		}
		if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(prmtzrPerson.getData())) {
			throw new com.kingdee.eas.common.EASBizException(com.kingdee.eas.common.EASBizException.CHECKBLANK,new Object[] {"责任人"});
		}
		if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(prmtdeparment.getData())) {
			throw new com.kingdee.eas.common.EASBizException(com.kingdee.eas.common.EASBizException.CHECKBLANK,new Object[] {"责任部门"});
		}
//		if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(txtbeiz.getText())) {
//			throw new com.kingdee.eas.common.EASBizException(com.kingdee.eas.common.EASBizException.CHECKBLANK,new Object[] {"备注"});
//		}
		for (int i=0,n=kdtE1.getRowCount();i<n;i++) {
			if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(kdtE1.getCell(i,"ggw").getValue())) {
				throw new com.kingdee.eas.common.EASBizException(com.kingdee.eas.common.EASBizException.CHECKBLANK,new Object[] {"广告位编号"});
			}
		}
		for (int i=0,n=kdtE1.getRowCount();i<n;i++) {
			if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(kdtE1.getCell(i,"zlStartDate").getValue())) {
				throw new com.kingdee.eas.common.EASBizException(com.kingdee.eas.common.EASBizException.CHECKBLANK,new Object[] {"租赁起始日期"});
			}
		}
		for (int i=0,n=kdtE1.getRowCount();i<n;i++) {
			if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(kdtE1.getCell(i,"zlEndDate").getValue())) {
				throw new com.kingdee.eas.common.EASBizException(com.kingdee.eas.common.EASBizException.CHECKBLANK,new Object[] {"租赁到期日期"});
			}
		}
		for (int i=0,n=kdtE1.getRowCount();i<n;i++) {
			if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(kdtE1.getCell(i,"zlzq").getValue())) {
				throw new com.kingdee.eas.common.EASBizException(com.kingdee.eas.common.EASBizException.CHECKBLANK,new Object[] {"租赁周期/月"});
			}
		}
		if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(txtpp.getText())) {
			throw new com.kingdee.eas.common.EASBizException(com.kingdee.eas.common.EASBizException.CHECKBLANK,new Object[] {"品牌"});
		}
		if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(txthtNum.getText())) {
			throw new com.kingdee.eas.common.EASBizException(com.kingdee.eas.common.EASBizException.CHECKBLANK,new Object[] {"合同号"});
		}
		if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(zhlx.getSelectedItem())) {
			throw new com.kingdee.eas.common.EASBizException(com.kingdee.eas.common.EASBizException.CHECKBLANK,new Object[] {"租户/非租户"});
		}
		int e1=kdtE1.getRowCount();
		int e2=kdtE2.getRowCount();
//		if(e1<1 || e2<1){
//			MsgBox.showWarning("租赁信息和收款计划必须存在一条分录");
//			SysUtil.abort();
//		}

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//		for (int i = 0; i < kdtE1.getRowCount(); i++) {
//			if(kdtE1.getCell(i, "ggw").getValue()!=null && kdtE1.getCell(i, "zlStartDate").getValue()!=null){
//			AdvertInfo advertInfo=(AdvertInfo) kdtE1.getCell(i, "ggw").getValue();
//			Date zlStartDate=(Date) kdtE1.getCell(i, "zlStartDate").getValue();
//			String  zlStartDates=  sdf.format(zlStartDate);
//			if(!"JQcAAAAAgOnsyXfw".equals(advertInfo.getTreeid().getId().toString())){
//				 boolean  flag=	Hyhelper.isGgwCheck(editData.getId(), editData.getId(), advertInfo.getId().toString(), zlStartDates);
//	             if(flag){
//	            		MsgBox.showWarning("广告位("+advertInfo.getName()+") :租赁开始日期与其他合同或排期有重复日期，请重新选择！");
//						SysUtil.abort();
//	             	}
//				}
//			}
//		}
	}


	public static String dayComparePrecise(Date fromDate,Date toDate){
		Calendar  from  =  Calendar.getInstance();
		from.setTime(fromDate);
		//        from.add(Calendar.DATE, -1);
		Calendar  to  =  Calendar.getInstance();
		to.setTime(toDate);
		//        to.add(Calendar.DATE, 1);
		int fromYear = from.get(Calendar.YEAR);
		int fromMonth = from.get(Calendar.MONTH);
		int fromDay = from.get(Calendar.DAY_OF_MONTH);
		int toYear = to.get(Calendar.YEAR);
		int toMonth = to.get(Calendar.MONTH);
		int toDay = to.get(Calendar.DAY_OF_MONTH);
		int year = toYear  -  fromYear;
		int month = toMonth  - fromMonth;
		int day = toDay  - fromDay;
		return (year*12+month)+"月"+day+"天";
	}

	@Override
	protected void kdtE1_tableSelectChanged(KDTSelectEvent e) throws Exception {
		super.kdtE1_tableSelectChanged(e);
	}
	
	
	protected void kdtE1_editStopped(KDTEditEvent e) throws Exception {
		// TODO Auto-generated method stub
		int rowIndex = e.getRowIndex();
		int colIndex = e.getColIndex();
		String fieldName = this.kdtE1.getColumnKey(colIndex);
		if ("zlStartDate".equalsIgnoreCase(fieldName)||"zlEndDate".equalsIgnoreCase(fieldName)) {
			if(this.kdtE1.getCell(rowIndex, "zlEndDate").getValue()!=null&&this.kdtE1.getCell(rowIndex, "zlStartDate").getValue()!=null){
				Date  	zlStartDate=(Date) this.kdtE1.getCell(rowIndex, "zlStartDate").getValue();
				Date  	zlEndDate=(Date) this.kdtE1.getCell(rowIndex, "zlEndDate").getValue();
				if(zlEndDate.getTime()<zlStartDate.getTime()){
					this.kdtE1.getCell(rowIndex, "zlStartDate").setValue(null);
					MsgBox.showWarning("租赁到期日期不能小于开始日期！");
					SysUtil.abort();
				}
			}
		}
		super.kdtE1_editStopped(e);
		if ("zlAmount".equalsIgnoreCase(fieldName)||"zzAmount".equalsIgnoreCase(fieldName)) {
			txthtAmount.setValue(UIRuleUtil.getBigDecimal(UIRuleUtil.sum(kdtE1,"zlAmount")).add(UIRuleUtil.getBigDecimal(UIRuleUtil.sum(kdtE1,"zzAmount"))));

		}

		// int rowIndex = e.getRowIndex();
		// int colIndex = e.getColIndex();
		// String fieldName = this.kdtE1.getColumnKey(colIndex);
		if ("zlStartDate".equalsIgnoreCase(fieldName)||"zlEndDate".equalsIgnoreCase(fieldName)) {
			if(this.kdtE1.getCell(rowIndex, "zlStartDate").getValue()!=null&&this.kdtE1.getCell(rowIndex, "zlEndDate").getValue()!=null){
				Date  	zlStartDate=(Date) this.kdtE1.getCell(rowIndex, "zlStartDate").getValue();
				Date  	zlEndDate=(Date) this.kdtE1.getCell(rowIndex, "zlEndDate").getValue();
				Calendar c = Calendar.getInstance();       
				c.setTime(zlEndDate);       
				c.add(Calendar.DAY_OF_MONTH,1);//+1天
				Date zlEndDate2 = c.getTime();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				String  zlStartDates=  sdf.format(zlStartDate);
				String  zlEndDates=  sdf.format(zlEndDate2);
				String mmdd=	DateDaySub.remainDateToString(zlStartDates, zlEndDates);
				this.kdtE1.getCell(rowIndex, "zlzq").setValue(mmdd);

			}

		}


	}



	@Override
	protected void initWorkButton() {
		actionAddNew.setVisible(false);
		actionCopy.setVisible(false);
		actionAttachment.setVisible(false);
		actionPrint.setVisible(false);
		actionPrintPreview.setVisible(false);
		actionUnAudit.setVisible(false);
		actionCreateFrom.setVisible(false);
		actionAddLine.setVisible(false);
		actionInsertLine.setVisible(false);
		actionRemoveLine.setVisible(false);
		super.initWorkButton();
	}
	@Override
	protected void kdtE2_editStopped(KDTEditEvent e) throws Exception {
		super.kdtE2_editStopped(e);

	}

	/*
	 * 新增行
	 * 
	 */
	

	public void actionAddLine_actionPerformed(ActionEvent e) throws Exception {
		super.actionAddLine_actionPerformed(e);
	}
	
	/*
	 * 插入行
	 */
	public void actionInsertLine_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionInsertLine_actionPerformed(e);
	}

	Set set = new HashSet();
	protected void kDPanel2_componentShown(ComponentEvent e) throws Exception {
		super.kDPanel2_componentShown(e);
		if(kdtE1.getRowCount()==0 ){
			MsgBox.showConfirm2("请先新增租赁信息行！");
			SysUtil.abort();
		}
		AdvertInfo info=null;
		for(int i =0;i<kdtE1.getRowCount();i++){
			IRow rowE1=kdtE1.getRow(i);
			if(rowE1.getCell("ggw").getValue()==null){
				int j=i+1;
				MsgBox.showConfirm2("第一个分录中，第："+j+" 行对应的 广告位编码为空！");
				SysUtil.abort();
			}
			
			info=(AdvertInfo)rowE1.getCell("ggw").getValue();
			String ggwid= info.getId().toString();
			set.add(ggwid);
		}
		
		if(info != null) {
			EntityViewInfo evi = new EntityViewInfo();
			FilterInfo filter = new FilterInfo();
			filter.getFilterItems().add(new FilterItemInfo("id", set, CompareType.INCLUDE));
			evi.setFilter(filter);
			KDBizPromptBox bizBox2 = (KDBizPromptBox) kdtE2.getColumn("ggw").getEditor().getComponent();//获取分录里面的F7字段
			bizBox2.setEntityViewInfo(evi);
		}
	}
	


}