<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Collection" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.database.SzPageInfo" %>
<%@ page import="net.sz600.system.SzProperties" %>
<%@ page import="net.sz600.system.SzLevelNumber" %>
<%@ page import="net.sz600.system.SzPageHelp" %>
<%@ page import="net.sz600.flow.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ include file="/sessionInfo.jsp"%>
<head>
<BASE target=_self>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
</head>
<%
	//获取提交的参数
	String sType  = SzConvert.toZeroStr(request.getParameter("type"));	//关联的ID
	String sPKEY  = SzConvert.toZeroStr(request.getParameter("PKEY"));	//主表单信息ID
	String sPFORM = SzConvert.toZeroStr(request.getParameter("PFORM"));	//主表单信息ID
	String sFormID = SzConvert.toZeroStr(request.getParameter("FormID"));
    //找出关联的信息
    BdRelateForm bdRelateForm = new BdRelateForm();
    String addButton = bdRelateForm.addButton(sType);
    String selectButton = bdRelateForm.selectButton(sType, sFormID);	//选择一个

    String sPage = SzConvert.toZeroStr(request.getParameter("page"));
    String sSearch = SzConvert.strWriteData(request.getParameter("txtSearch"));
    String sSearchName = SzConvert.strWriteData(request.getParameter("txtSearchName"));
    //引用的时候,主表单下已经引用的不能列出来.
    String sCond = "1=1";
    //读取数据
    String sSearchCond = SzConvert.strWriteData(request.getParameter("searchCond"));
    String sSortField = SzConvert.toSpaceStr(request.getParameter("txtSortField")); 
    int iSortOrder    = Integer.parseInt(SzConvert.toZeroStr(request.getParameter("txtSortOrder"))); 

    //System.out.println("sSearchCond==" + sSearchCond);
	BdRelateValue bdRelateValue = new BdRelateValue(sType, SzConvert.toInt(sPKEY), sFormID, 0, sSortField, iSortOrder, 1, 1);
	String strDefaultCond = bdRelateValue.getDefaultCond();
	if (!strDefaultCond.equals("")) {
		sCond += " AND " + strDefaultCond;
	}
    if (sSortField.equals("")) { 
        sSortField = bdRelateValue.getSortField();
        iSortOrder = SzProperties.I_SortOrder_DESC;
      } 	
	int iCurrentPage = 1;    
    try {
        iCurrentPage =  Integer.parseInt(sPage);
    }catch(Exception e) {
    }

    Collection coll = bdRelateValue.getArrayList(sCond, sSortField, iSortOrder, iCurrentPage, sSearch); 

    Iterator iter = null;
    if (coll != null) {
    	iter = coll.iterator();
    } else {
    	out.println("读取不到数据");
    	return;
    }
    SzPageInfo pageInfo = bdRelateValue.getPageInfo();
    int iPageCount = pageInfo.getPageCount();
    int iRecordCount = pageInfo.getRecordCount();
    iCurrentPage = pageInfo.getCurrentPage();
    int i = 0;
    
 
%>
<!-----上面的工具栏------>
<%@ include file="title.jsp"%>
<table width="100%">
  <form name="formBar" method="post">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="PKEY" value="<%=sPKEY%>">  
  <input type="hidden" name="PFORM" value="<%=sPFORM%>">  
  <tr>
    <td>
    	<%=selectButton%>
    	<%=SzPageHelp.closeButton()%>
    	<% out.println( SzPageHelp.button("确定","javascript:RelateOk();") );%>    	
    </td>
  </tr>
  </form>
</table>
<!-----信息列表----->
<table width="100%" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <form name="formList" method="post">
  <input type="hidden" name="page" value="<%=iCurrentPage%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>"> 
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="PKEY" value="<%=sPKEY%>">  
  <input type="hidden" name="PFORM" value="<%=sPFORM%>">    
  <tr class="trClassTitle">
    <td width="5"><input type="checkbox" name="chkCheckAll" OnClick="javascript:CheckAll(formList, chkCheckAll, 'chkId');"></td>
	<%=bdRelateValue.printTableTitle()%>        	    
  </tr>
<%
    String value_str[] = null;
    int iKeyValue = 0;
    int iListFieldLen = 0;
    iListFieldLen = bdRelateValue.getListFieldLen() -1 ;
    int iKeyIndex = bdRelateValue.getKeyIndex();
    int iFormID = 0;

    while (iter != null && iter.hasNext()) {
    	value_str = (String[])iter.next();
    	if (value_str == null) {
    		continue;
    	}
    	iFormID = Integer.parseInt(value_str[0]);
    	iKeyValue = Integer.parseInt(value_str[iKeyIndex]);
    	
    	i++;
%>
  <tr  onMouseOver="javascript:this.className='trMouseOver'" onMouseOut="javascript:this.className='trMouseOut'">
    <td width="5" title="<%=i%>">
      <input type="checkbox" name="chkId" id="chkId" value="<%=iFormID%>,<%=iKeyValue%>">
    </td>
    <%=bdRelateValue.printTableValue(value_str)%>      
  </tr>
<%
    }
    out.println(SzPageHelp.outIndexTableTr(i, SzProperties.I_PageSize, iListFieldLen));
%>    
  </form>  
</table>   
<!-----下面的工具栏------>
<table width="100%">
  <form name="formPage" method="post">
  <input type="hidden" name="page" value="<%=iCurrentPage%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>"> 
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="PKEY" value="<%=sPKEY%>">  
  <input type="hidden" name="PFORM" value="<%=sPFORM%>">    
  <tr>
    <td align="right">
      <%@ include file="/share/page/page_include.jsp"%>
    </td>
  </tr>
  </form>
</table> 
<form name="formHidden" method="post">
  <input type="hidden" name="page" value="<%=iCurrentPage%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>"> 
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="PKEY" value="<%=sPKEY%>">  
  <input type="hidden" name="PFORM" value="<%=sPFORM%>">   
</form>
<script language="javascript" src="../../share/js/commonTool.js"></script>
<script language="javascript">  
  function Select() {
  	//传递当前formID, 主表单的关联ID,主表单的信息ID
  	var FormID = formBar.relateFormSelect.value;
  	
  	var vUrl = "relate_select.jsp?FormID=" + FormID;
	formHidden.action = vUrl;
	formHidden.submit();  	
  }  
  
  //确定建立关联关系
  function RelateOk() {
  	var vUrl = "relate_control.jsp?OPERATOR=relate";
	formList.action = vUrl;
	formList.submit();  	  
  }
 
</script>
