<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.database.*" %>
<%@ page import="net.sz600.system.SzProperties" %>
<%@ page import="net.sz600.system.SzPageHelp" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ page import="net.sz600.formCreate.*" %>
<%@ include file="sessionInfo2.jsp"%>
<head>
<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 moduleName = SzConvert.strWriteData(request.getParameter("moduleName"));
    String formName = SzConvert.strWriteData(request.getParameter("formName"));
    BdFormControl formControl = new BdFormControl();
		boolean isFormEngine = formControl.isFormEngine(moduleName);
%>
<%@ include file="/xml/formEngine2/title.jsp"%>
<table width="100%">
  <form name="formBar" method="post">
  <tr>
    <td align="left">
      <input type="button" value="保存" class="btnClass" OnClick="javascript:FormSave(formList, 'formControl.jsp');">            
      <input type="button" value="返回" class="btnClass" onClick="document.location.href='formIndex.jsp?module=<%=moduleName%>'">
    </td>
  </tr>
  </form>
</table>
<!-----信息列表----->
<%
		BdFormHelp bdFormHelp = new BdFormHelp();
    BdForm bdForm = new BdForm();
    BdFormInfo bdFormInfo = null;
    bdFormInfo = (BdFormInfo)bdForm.getFormInfo(moduleName, formName);
    if (bdFormInfo == null) {
      bdFormInfo = new BdFormInfo();
    }

    BdFormTableInfo bdFormTableInfo = null;
    Collection collFormTable = null;
    collFormTable = bdForm.getTableList(moduleName, formName);
    Iterator iterFormTable = null;
    if (collFormTable != null) {
      iterFormTable = collFormTable.iterator();
    }


    BdFormFieldInfo bdFormFieldInfo = null;
    Collection collFormField = null;
    Iterator iterFormField = null;
    collFormField = bdForm.getFieldList(moduleName, formName);
    if (collFormField != null) {
      iterFormField = collFormField.iterator();
    }
%>
<table width="100%" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <form name="formList" method="post">
  <input type="hidden" name="OPERATOR" value="FieldIndex">
  <input type="hidden" name="moduleName" value="<%=moduleName%>">
  <input type="hidden" name="formName" value="<%=formName%>">
  <tr class="trClassTitle2">
    <td>序号</td>
    <td>字段名</td>
    <td>字段说明</td>
    <td>字段类型</td>
    <td>长度</td>
    <td>字段状态</td>
    <td>所用控件</td>
    <td>索引状态</td>
    <td>删除索引</td>
    <td>创建索引</td>
  </tr> 
<%
    int j = 0;
    int i = 0;
    String tableName = "";
    String tableId = "";
    String objectStr = "";
    String tableType = "";
    String sIndexFieldName = "";
    String sIndexState = "";
    SzAlterTable szAlterTable = new SzAlterTable();
    while (iterFormTable != null && iterFormTable.hasNext()) {
        bdFormTableInfo = (BdFormTableInfo)iterFormTable.next();
        if (bdFormTableInfo.getGLID().equals("") || bdFormTableInfo.getGLBM().equals("")) {
            continue;
        }
        tableName = bdFormTableInfo.getGLBM();
        tableId = bdFormTableInfo.getGLID();
        if (bdFormTableInfo.getGLLX().equals("0")) {
            tableType = "普通表单";
        } else {
        	tableType = "明细表单";
        }
        //取得已索引的字段
        sIndexFieldName = szAlterTable.getIndexFieldName(tableName);
        
%>
  <tr class="trClassTitle2">
    <td colspan="19" align="left"><%=tableType%>&nbsp;<%=bdFormTableInfo.getGLBM()%></td>
  </tr>
<%              
        //读取字段
        objectStr = "";

        iterFormField = collFormField.iterator();
        while ((iterFormField != null && iterFormField.hasNext())) {
            bdFormFieldInfo = null;
            if (iterFormField != null && iterFormField.hasNext()) {
                bdFormFieldInfo = (BdFormFieldInfo)iterFormField.next();
            }
            if (!tableId.equals(bdFormFieldInfo.getTableId())) {
                continue;
            }

            if (bdFormFieldInfo == null) {
                bdFormFieldInfo = new BdFormFieldInfo();
                bdFormFieldInfo.setZDZT(1); // 默认是普通字段
                bdFormFieldInfo.setZDLX("nvarchar");
                bdFormFieldInfo.setZDCD("100");
            }
            objectStr += "," + bdFormFieldInfo.getZDID();
            
            sIndexState = "";
            if (sIndexFieldName.indexOf(bdFormFieldInfo.getZDMC()) >0) {
            	sIndexState = "已索引";
            }
%>
  <tr>
    <td align="center"><%=i + 1%></td>
    <td align="center"><%=bdFormFieldInfo.getZDMC()%></td>
    <td align="center"><%=bdFormFieldInfo.getZDSM()%></td>
    <td align="center"><%=bdFormFieldInfo.getZDLX()%></td>
    <td align="center"><%=bdFormFieldInfo.getZDCD()%></td>
    <td align="center"><%=bdFormHelp.getZDZTname(bdFormFieldInfo.getZDZT()) %></td>        
    <td align="center">
      <input type="hidden" name="ZDBJ<%=i%>" value="<%=bdFormFieldInfo.getZDBJ() %>">
			<%=bdFormHelp.getZDBJname(bdFormFieldInfo.getZDBJ()) %>
    </td>  
    <%
    if (sIndexFieldName.indexOf(bdFormFieldInfo.getZDMC()) >0) {
    	sIndexState = "已索引";
    %>
    <td align="center"><%=sIndexState%></td>   
    <td align="center"><input type="checkbox" name="delete<%=i%>" value="<%=bdFormFieldInfo.getZDMC()%>"></td>         
    <%
    } else {
    	out.println("<td></td><td></td>");
    }
    %>
	<td align="center"><input type="checkbox" name="create<%=i%>" value="<%=bdFormFieldInfo.getZDMC()%>"></td>
	<input type="hidden" name="table<%=i%>" value="<%=bdFormTableInfo.getGLBM()%>">
  </tr>
<%
            i ++;
       }
       j++;
   }

%>
  <tr class="trClassTitle2">
    <td>序号</td>
    <td>字段名</td>
    <td>字段说明</td>
    <td>字段类型</td>
    <td>长度</td>
    <td>字段状态</td>
    <td>所用控件</td>
    <td>索引状态</td>
    <td>删除索引</td>
    <td>创建索引</td>    
  </tr> 
  <input type="hidden" name="fieldCount" value="<%=i%>" >
  </form>
</table>

<br>

<!-----这里包含要提交的内容--->
<form name="formHidden" method="post">
</form>
<script language="javascript" src="../../share/js/commonTool.js"></script>
<script language="javascript">
  function FormSave(formName, url) {
   	formName.action = url;
    formName.submit();
  }

</script>
