<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="java.util.*" %>
<%@ 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.SzPageHelp" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ include file="sessionInfo2.jsp"%>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<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);
%>
<% if (isFormEngine) { %>
<%@ include file="title.jsp"%>
<% } else { %>
<%@ include file="simpleTitle.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>
<!-----信息列表----->
<%
    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="">
  <input type="hidden" name="moduleName" value="<%=moduleName%>">
  <input type="hidden" name="formName" value="<%=formName%>">
  <div id="divHidden" style="display:none">
  表格数量：<input type="text" name="tableCount" value="<%=bdFormInfo.getTableCount()%>">
  行数量：<input type="text" name="rowCount" value="<%=bdFormInfo.getRowCount()%>">
  列数量：<input type="text" name="cellCount" value="<%=bdFormInfo.getCellCount()%>">
  控件数量：<input type="text" name="objectCount" value="<%=bdFormInfo.getObjectCount()%>">
  </div>
  <tr class="trClassTitle2">
    <td rowspan="2">序号</td>
    <td rowspan="2">控件ID</td>
    <td rowspan="2">字段名</td>
    <td rowspan="2">字段说明</td>
    <td rowspan="2">字段类型</td>
    <td rowspan="2">长度</td>
    <td rowspan="2">可否空</td>
    <td rowspan="2">状态</td>
    <td rowspan="2">列表</td>
    <td colspan="4">列表显示属性</td>
    
    <td rowspan="2">所用控件</td>
    <td  rowspan="2" title="单击全部选中"><a href="#" OnClick="javascript:CheckAll('ZDCX', true);">查询</a></td>
    <td  rowspan="2" title="单击全部选中"><a href="#" OnClick="javascript:CheckAll('ZDDC', true);">导出</a></td>
    <td  rowspan="2" title="单击全部选中"><a href="#" OnClick="javascript:CheckAll('ZDDCB', true);">导出2</a></td>
    <td  rowspan="2" title="单击全部选中"><a href="#" OnClick="javascript:CheckAll('ZDDR', true);">导入</a></td>
    <td rowspan="2" >初始值</td>
    <td  rowspan="2" <% if (!isFormEngine) { out.println("style='display:none;'"); }%>>JS检查函数</td>
  </tr>
  <tr class="trClassTitle2">
  	    <td>对齐</td>
    <td>加粗</td>
    <td>颜色</td>
    <td>字数</td>
  </tr>  
<%
    int j = 0;
    int i = 1;
    String tableName = "";
    String tableId = "";
    String objectStr = "";
    String tableType = "";
    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 = "普通表单";
%>
  <tr class="trClassTitle2">
    <td colspan="19" align="left"><%=tableType%>&nbsp;<%=bdFormTableInfo.getGLBM()%></td>
  </tr>
<%            
        } else {
            tableType = "明细表单";
%>
  <tr class="trClassTitle">
    <td colspan="8" align="left"><%=tableType%>&nbsp;<%=bdFormTableInfo.getGLBM()%></td>
    <td>无</td>
    <td>&nbsp;</td>    
    <td>统计</td>
    <td>无</td>
    <td>&nbsp;</td>
    <td>&nbsp;</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();
%>
  <tr>
    <td>
      <input type="text" name="order<%=i%>" value="<%=i%>" class="txtClass30" size="3" <%if (i==1) {out.println("disabled");}%>  OnBlur="CheckOrder(<%=i%>);" >
    </td>
    <td align="center" title="双击设置公式：<%="\n"%><%=bdFormFieldInfo.getZDBY()%><%="\n"%><%=bdFormFieldInfo.getZDKZ()%>" OnMouseOver="style.cursor='hand'" OnDblClick="javascript:document.location.href='formFormula.jsp?moduleName=<%=moduleName%>&formName=<%=formName%>&fieldName=<%=bdFormFieldInfo.getZDMC()%>&fieldState=<%=bdFormFieldInfo.getZDZT()%>'">
    <% if (bdFormFieldInfo.getZDBY().equals("") 
    	&& bdFormFieldInfo.getZDKZ().equals("")
    	&& bdFormFieldInfo.getZDBQ().equals("")
    	&& bdFormFieldInfo.getZDGLMC().equals("")
    	) { %>
     <input type="text" class="txtClass50" OnMouseOver="style.cursor='hand'" name="objectId<%=i%>" value="<%=bdFormFieldInfo.getZDID()%>" readonly style="background:#D4D0C8;">
    <% } else { %>
     <input type="text" class="txtClass50" OnMouseOver="style.cursor='hand'" name="objectId<%=i%>" value="<%=bdFormFieldInfo.getZDID()%>" readonly style="background:#F29EEB;">    
    <% } %>

    </td>
    <td align="center"><input type="text" class="txtClass80" name="field<%=i%>" value="<%=bdFormFieldInfo.getZDMC()%>" OnBlur="CheckField(<%=i%>);"></td>
    <td align="center"><input type="text" class="txtClass100" name="name<%=i%>" value="<%=bdFormFieldInfo.getZDSM()%>"></td>
    <td align="center">
      <select  name="ZDLX<%=i%>" style="width:80;" onChange="javascript:ChangeZDLX(<%=i%>);">
        <option value="">==请选择==</option>
        <option value="int" <%if (bdFormFieldInfo.getZDLX().equals("int")) {%>selected<%}%>>int</option>
        <option value="nvarchar" <%if (bdFormFieldInfo.getZDLX().equals("nvarchar")) {%>selected<%}%>>nvarchar</option>
        <option value="numeric" <%if (bdFormFieldInfo.getZDLX().equals("numeric")) {%>selected<%}%>>numeric</option>
        <option value="ntext" <%if (bdFormFieldInfo.getZDLX().equals("ntext")) {%>selected<%}%>>ntext</option>
      </select>
    </td>
    <td align="center">
      <input type="text" class="txtClass50" name="ZDCD<%=i%>" value="<%=bdFormFieldInfo.getZDCD()%>">
    </td>
    <td align="center">
      <select  name="ZDKK<%=i%>" style="width:60;">
        <option value="0" <%if(bdFormFieldInfo.getZDKK() == 0) {%>selected<%}%>>可以</option>
        <option value="1" <%if(bdFormFieldInfo.getZDKK() == 1) {%>selected<%}%>>不可以</option>
        <option value="2" <%if(bdFormFieldInfo.getZDKK() == 2) {%>selected<%}%>>不可重复</option>
    </td>
    <td align="center">
      <select  name="ZDZT<%=i%>" style="width:80;" onChange="javascript:ChangeZDZT(<%=i%>);">
        <option value="">==请选择==</option>
        <option value="0" <%if(bdFormFieldInfo.getZDZT() == 0) {%>selected<%}%>>不使用</option>
        <option value="1" <%if(bdFormFieldInfo.getZDZT() == 1) {%>selected<%}%>>普通字段</option>
        <option value="2" <%if(bdFormFieldInfo.getZDZT() == 2) {%>selected<%}%>>关键ID</option>
        <option value="4" <%if(bdFormFieldInfo.getZDZT() == 4) {%>selected<%}%>>外键ID</option>
        <option value="3" <%if(bdFormFieldInfo.getZDZT() == 3) {%>selected<%}%>>标题字段</option>
      </select>
    </td>
    <td align="center">
      <input type="text" class="txtClass50" name="ZDLB<%=i%>" value="<%=bdFormFieldInfo.getZDLB()%>">
    </td>
    <!-- 2011-06-07增加，列表属性 -->
    <td align="center">
      <select  name="Align<%=i%>" style="width:50;">
        <option value="">===</option>
        <option value="left" <%if(bdFormFieldInfo.getAlign().equals("left")) {%>selected<%}%>>居左</option>
        <option value="center" <%if(bdFormFieldInfo.getAlign().equals("center")) {%>selected<%}%>>居中</option>
        <option value="right" <%if(bdFormFieldInfo.getAlign().equals("right")) {%>selected<%}%>>居右</option>
      </select>      
    </td>
    <td align="center">
      <select  name="Bold<%=i%>" style="width:50;">
        <option value="">===</option>
        <option value="bold" <%if(bdFormFieldInfo.getBold().equals("bold")) {%>selected<%}%>>粗体</option>
      </select>        
    </td>
    <td align="center">
      <select  name="Color<%=i%>" style="width:50;">
        <option value="">===</option>
        <option value="#211C1A" <%if(bdFormFieldInfo.getColor().equals("#211C1A")) {%>selected<%}%>>黑色</option>
        <option value="#FFFFFF" <%if(bdFormFieldInfo.getColor().equals("##FFFFFF")) {%>selected<%}%>>白色</option>
        <option value="#EEEAEA" <%if(bdFormFieldInfo.getColor().equals("##EEEAEA")) {%>selected<%}%>>灰色</option>
        <option value="blue" <%if(bdFormFieldInfo.getColor().equals("blue")) {%>selected<%}%>>蓝色</option>
        <option value="red" <%if(bdFormFieldInfo.getColor().equals("red")) {%>selected<%}%>>红色</option>
      </select>         
    </td>
    <td align="center">
      <input type="text" class="txtClass50" name="Maxlen<%=i%>" value="<%=bdFormFieldInfo.getMaxlen()%>">
    </td>            
        
    <td align="center">
      <input type="hidden" name="ZDBJ<%=i%>" value="<%=bdFormFieldInfo.getZDBJ() %>">
      <select  name="ZDBJ<%=i%>" disabled style="width:85;">
        <option value="">==请选择==</option>
        <option value="0" <%if(bdFormFieldInfo.getZDBJ() == 0) {%>selected<%}%>>普通text</option>
        <option value="1" <%if(bdFormFieldInfo.getZDBJ() == 1) {%>selected<%}%>>普通hidden</option>
        <option value="51" <%if(bdFormFieldInfo.getZDBJ() == 51) {%>selected<%}%>>自动流水编号</option>
        <option value="2" <%if(bdFormFieldInfo.getZDBJ() == 2) {%>selected<%}%>>本人姓名</option>
        <option value="3" <%if(bdFormFieldInfo.getZDBJ() == 3) {%>selected<%}%>>本人ID</option>
        <option value="33" <%if(bdFormFieldInfo.getZDBJ() == 33) {%>selected<%}%>>本人部门名称</option>
        <option value="34" <%if(bdFormFieldInfo.getZDBJ() == 34) {%>selected<%}%>>本人部门ID</option>
        <option value="4" <%if(bdFormFieldInfo.getZDBJ() == 4) {%>selected<%}%>>创建时间</option>
        <option value="4" <%if(bdFormFieldInfo.getZDBJ() == 44) {%>selected<%}%>>当前时间</option>
        <option value="42" <%if(bdFormFieldInfo.getZDBJ() == 42) {%>selected<%}%>>日期控件</option>
        <option value="43" <%if(bdFormFieldInfo.getZDBJ() == 43) {%>selected<%}%>>时间控件</option>
        <option value="5" <%if(bdFormFieldInfo.getZDBJ() == 5) {%>selected<%}%>>关联下拉列表</option>

        <option value="7" <%if(bdFormFieldInfo.getZDBJ() == 7) {%>selected<%}%>>textarea</option>
        <option value="41" <%if(bdFormFieldInfo.getZDBJ() == 41) {%>selected<%}%>>html编辑器</option>
        <option value="8" <%if(bdFormFieldInfo.getZDBJ() == 8) {%>selected<%}%>>树状编号</option>
        <option value="9" <%if(bdFormFieldInfo.getZDBJ() == 9) {%>selected<%}%>>树状下拉列表</option>
        <option value="10" <%if(bdFormFieldInfo.getZDBJ() == 10) {%>selected<%}%>>部门员工单选</option>
        <option value="11" <%if(bdFormFieldInfo.getZDBJ() == 11) {%>selected<%}%>>员工单选ID</option>
        <option value="12" <%if(bdFormFieldInfo.getZDBJ() == 12) {%>selected<%}%>>员工单选NAME</option>
        <option value="13" <%if(bdFormFieldInfo.getZDBJ() == 13) {%>selected<%}%>>员工多选ID</option>
        <option value="14" <%if(bdFormFieldInfo.getZDBJ() == 14) {%>selected<%}%>>员工多选NAME</option>
        <option value="21" <%if(bdFormFieldInfo.getZDBJ() == 21) {%>selected<%}%>>部门单选ID</option>
        <option value="22" <%if(bdFormFieldInfo.getZDBJ() == 22) {%>selected<%}%>>部门单选NAME</option>
        <option value="23" <%if(bdFormFieldInfo.getZDBJ() == 23) {%>selected<%}%>>部门多选ID</option>
        <option value="24" <%if(bdFormFieldInfo.getZDBJ() == 24) {%>selected<%}%>>部门多选NAME</option>

        <option value="31" <%if(bdFormFieldInfo.getZDBJ() == 31) {%>selected<%}%>>radio单选</option>
        <option value="32" <%if(bdFormFieldInfo.getZDBJ() == 32) {%>selected<%}%>>check多选</option>
        <option value="133" <%if(bdFormFieldInfo.getZDBJ() == 133) {%>selected<%}%>>下拉列表</option>

        <option value="6" <%if(bdFormFieldInfo.getZDBJ() == 6) {%>selected<%}%>>窗口ID单项</option>

      </select>
    </td>
    <td align="center">
      <%=SzPageHelp.checkbox("ZDCX" + i, bdFormFieldInfo.getZDCX()) %>      
    </td>
    <td align="center">
      <%=SzPageHelp.checkbox("ZDDC" + i, bdFormFieldInfo.getZDDC()) %>      
    </td>     
    <td align="center">
      <%=SzPageHelp.checkbox("ZDDCB" + i, bdFormFieldInfo.getZDDCB()) %>      
    </td>     
    <td align="center">
      <%=SzPageHelp.checkbox("ZDDR" + i, bdFormFieldInfo.getZDDR()) %>      
    </td>
    <td align="center">
      <input type="text" class="txtClass50" name="ZDCSZ<%=i%>" value="<%=bdFormFieldInfo.getZDCSZ()%>">
    </td>  
    <td align="center"  <% if (!isFormEngine) { out.println("style='display:none;'"); }%>>
      <input type="text" class="txtClass2" name="ZDHS<%=i%>" value="<%=bdFormFieldInfo.getZDHS()%>">
    </td>  
    <input type="hidden" name="ZDBY<%=i%>" value="<%=bdFormFieldInfo.getZDBY()%>" >
    <input type="hidden" name="ZDKZ<%=i%>" value="<%=bdFormFieldInfo.getZDKZ()%>" >
    <input type="hidden" name="ZDBQ<%=i%>" value="<%=bdFormFieldInfo.getZDBQ()%>" >
    <input type="hidden" name="ZDGLMC<%=i%>" value="<%=bdFormFieldInfo.getZDGLMC()%>" >
    <input type="hidden" name="ZDGLID<%=i%>" value="<%=bdFormFieldInfo.getZDGLID()%>" >
    <input type="hidden" name="ZDGLBM<%=i%>" value="<%=bdFormFieldInfo.getZDGLBM()%>" >            
  </tr>
<%
            i ++;
       }
%>
  <div  style="display:none">
    <input type="text" name="tableId<%=j%>" value="<%=bdFormTableInfo.getGLID()%>">
    <input type="text" name="table<%=j%>" value="<%=bdFormTableInfo.getGLBM()%>">
    <input type="text" name="tableClass<%=j%>" value="<%=bdFormTableInfo.getGLLM()%>">
    <input type="text" name="object<%=j%>" value="<%=objectStr%>">
    <input type="text" name="tableType<%=j%>" value="<%=bdFormTableInfo.getGLLX()%>">
    <input type="text" name="tableMain<%=j%>" value="<%=bdFormTableInfo.getGLZB()%>">    
  </div>
<%
        j++;
   }
%>
  <tr class="trClassTitle2">
    <td rowspan="2">序号</td>
    <td rowspan="2">控件ID</td>
    <td rowspan="2">字段名</td>
    <td rowspan="2">字段说明</td>
    <td rowspan="2">字段类型</td>
    <td rowspan="2">长度</td>
    <td rowspan="2">可否空</td>
    <td rowspan="2">状态</td>
    <td rowspan="2">列表</td>
    <td colspan="4">列表显示属性</td>
    
    <td rowspan="2">所用控件</td>
    <td  rowspan="2" title="单击全部选中"><a href="#" OnClick="javascript:CheckAll('ZDCX', true);">查询</a></td>
    <td  rowspan="2" title="单击全部选中"><a href="#" OnClick="javascript:CheckAll('ZDDC', true);">导出</a></td>
    <td  rowspan="2" title="单击全部选中"><a href="#" OnClick="javascript:CheckAll('ZDDCB', true);">导出2</a></td>
    <td  rowspan="2" title="单击全部选中"><a href="#" OnClick="javascript:CheckAll('ZDDR', true);">导入</a></td>
    <td rowspan="2" >初始值</td>
    <td  rowspan="2" <% if (!isFormEngine) { out.println("style='display:none;'"); }%>>JS检查函数</td>
  </tr>
  <tr class="trClassTitle2">
  	<td>对齐</td>
    <td>加粗</td>
    <td>颜色</td>
    <td>字数</td>
  </tr> 
  </form>
</table>

<!-----下面的工具栏------>
<table width="100%">
  <form name="formPage" method="post">
  <tr>
    <td align="left">
      <font color="red">
列表：0表示不显示；1表示显示，不限制长度；其他值为显示的长度<br>
点击上面的“查询”为全选；点击下面的“查询”为全部不选中<br>
双击“控件ID”可以设置公式、指定关联的外部方法

      </font>
    </td>
  </tr>
  </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) {

    var objectCount = parseInt(formName.objectCount.value);
    var oObject = null;
    var v = "";
    for (var i=0; i<=objectCount; i++) {
      oObject = eval("formName.field" + i);
      if (oObject != null) {
        v = oObject.value;
        if (!isLetterOrNumOrLine(v)) {
          alert("字段名只能是字母、数字、下划线");
          oObject.focus();
          //window.status = v;
          return;
        }
      }
    }

    //字段名只能是字母、数字
    //字段名不能重复
    formName.OPERATOR.value = "XMLFIELD";
    formName.action = url;
    formName.submit();

  }
    
  //当改变一个字段的名字时，检查是否有重复的
  function CheckField(iIndex) {
    var oObject = null;
    oObject = eval("formList.field" + iIndex);
    var vObject = oObject.value;

    if (!isLetterOrNumOrLine(vObject)) {
      alert("字段名只能是字母、数字、下划线");
      oObject.focus();
      //window.status = v;
      return;
    }

    var objectCount = parseInt(formList.objectCount.value);
    var v = "";
    for (var i=0; i<=objectCount; i++) {
      if (iIndex == i) {
        continue;
      }
      oObject = eval("formList.field" + i);

      if (oObject != null && oObject.value == vObject) {
        alert("字段名称已经存在");
        oObject.focus();
        break;
      }
    }
  }
  
  //当改变一个字段的名字时，检查是否有重复的
  function CheckOrder(iIndex) {
    var oObject = null;
    oObject = eval("formList.order" + iIndex);
    var vObject = oObject.value;

    if (!isNum(vObject)) {
      alert("序号只能是大于1的数字");
      oObject.focus();
      return;
    }
    if (parseInt(vObject) <=1) {
      alert("序号只能是大于1的数字");
      oObject.focus();
      return;
    }    
  }  

  //改变字段的类型
  function ChangeZDLX(i) {
    //var oZDLX = eval("formList.type" + i);
    var oZDLX = eval("formList.ZDLX" + i);
    var oZDCD = eval("formList.ZDCD" + i);
    var vZDLX = oZDLX.value;
    if (vZDLX == "int") {
      oZDCD.value = "4";
    } else if (vZDLX == "nvarchar") {
      oZDCD.value = "100";
    } else if (vZDLX == "numeric") {
      oZDCD.value = "8,2";
    }
  }

  function ChangeZDZT(i) {
    var oZDZT = eval("formList.ZDZT" + i);
    var oZDBJ = eval("formList.ZDBJ" + i);
    var oZDKK = eval("formList.ZDKK" + i);
    var oZDLB = eval("formList.ZDLB" + i);
    var vZDZT = oZDZT.value;
    if (vZDZT == "2" || vZDZT == "4") { //关键ID、外健ID
      oZDBJ.value = "1";
      oZDKK[1].selected = true;
    } else if (vZDZT == "3") {
      oZDKK[1].selected = true;
      oZDLB.checked = true;
    } else {
      oZDKK[0].selected = true;
      oZDLB.checked = false;
    }
  }
  
  function CheckAll(vChkId, flag) {
    var objectCount = parseInt(formList.objectCount.value);
    var e;
    for (var i=1; i<=objectCount; i++) {
      e = eval("formList." + vChkId + i);
      e.checked = flag;
    }
  }

  //window.status = "1".charCodeAt(0);   //得到码值
  //String.fromCharCode(65);   //还原字符
</script>
