<%@ 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.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=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 = true;
%>
<%@ 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:SelectHelp();">
      <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="">
  <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 colspan="9">手机属性</td>
    <td rowspan="2">序号</td>
  </tr>
  
  <tr class="trClassTitle2">
	<td><a href="#" OnClick="javascript:CheckAll('AppList', true);">列表</a></td>
	<td><a href="#" OnClick="javascript:CheckAll('AppAdd', true);">添加</a></td>
	<td><a href="#" OnClick="javascript:CheckAll('AppReadonly', true);">只读</a></td>
	<td><a href="#" OnClick="javascript:CheckAll('AppAddBr', true);">换行</a></td>
	<td>添加样式</td>
	<td>关联</td>
	<td>弹出选择</td>
	<td>人员选择</td>	
	<td><a href="#" OnClick="javascript:CheckAll('AppDetail', true);">详情</a></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="21" align="left"><%=tableType%>&nbsp;<%=bdFormTableInfo.getGLBM()%></td>
  </tr>
<%            
        } else {
            tableType = "明细表单";
%>
  <tr class="trClassTitle2">
    <td colspan="6" 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();
%>
  <tr>
    <td align="center">
      <input type="hidden" name="order<%=i%>" value="<%=i%>" class="txtClass30" size="3" readonly style="background:#D4D0C8;">
      <%=i %>
    </td>
    <td align="center">
	    <input type="text" class="txtClass50" OnMouseOver="style.cursor='hand'" name="objectId<%=i%>" value="<%=bdFormFieldInfo.getZDID()%>" readonly style="background:#D4D0C8;">
    </td>
    <td align="center"><input type="text" class="txtClass80" name="field<%=i%>" value="<%=bdFormFieldInfo.getZDMC()%>" readonly style="background:#D4D0C8;"></td>
    <td align="center"><input type="text" class="txtClass100" name="name<%=i%>" value="<%=bdFormFieldInfo.getZDSM()%>" readonly style="background:#D4D0C8;"></td>  
    <td align="center">
      <input type="hidden" name="ZDBJ<%=i%>" value="<%=bdFormFieldInfo.getZDBJ() %>">
      <input type="text" class="txtClass80" value="<%=bdFormHelp.getZDBJname(bdFormFieldInfo.getZDBJ()) %>" readonly style="background:#D4D0C8;">
    </td>      
    <td align="center">
      <%=SzPageHelp.checkbox("AppList" + i, bdFormFieldInfo.getAppList()) %>      
    </td>
    <td align="center">
      <%=SzPageHelp.checkbox("AppAdd" + i, bdFormFieldInfo.getAppAdd()) %>      
    </td> 
    <td align="center">
      <%=SzPageHelp.checkbox("AppReadonly" + i, bdFormFieldInfo.getAppReadonly()) %>      
    </td>  
    <td align="center">
      <%=SzPageHelp.checkbox("AppAddBr" + i, bdFormFieldInfo.getAppAddBr()) %>      
    </td>                  
    <td align="center">
      <input type="text" class="txtClass80" name="AppAddCss<%=i%>" value="<%=bdFormFieldInfo.getAppAddCss()%>" OnDblClick="javascript:CssSelect('<%=i%>');">
    </td>  
    <td align="center">
    <% if (bdFormFieldInfo.getZDBJ() == 31
    		|| bdFormFieldInfo.getZDBJ() == 32
    		|| bdFormFieldInfo.getZDBJ() == 133 ) { %>
      <input type="text" class="txtClass80" name="AppRelate<%=i%>" value="<%=bdFormFieldInfo.getAppRelate()%>" OnDblClick="javascript:OptionsSelect('<%=i%>');">
    <% } %>
    </td> 
    <td align="center">
    <% if (bdFormFieldInfo.getZDBJ() == 0 || bdFormFieldInfo.getZDBJ() == 7) { %>
      <input type="text" class="txtClass80" name="AppOpenSelect<%=i%>" value="<%=bdFormFieldInfo.getAppOpenSelect()%>" OnDblClick="javascript:OpenSelect('<%=i%>');">
    <% } %>
    </td> 
    <td align="center">
    <% if (bdFormFieldInfo.getZDBJ() == 0 || bdFormFieldInfo.getZDBJ() == 7) { %>
      <input type="text" class="txtClass80" name="AppUserSelect<%=i%>" value="<%=bdFormFieldInfo.getAppUserSelect()%>" OnDblClick="javascript:UserSelect('<%=i%>');">
    <% } %>
    </td>           
    <td align="center">
      <%=SzPageHelp.checkbox("AppDetail" + i, bdFormFieldInfo.getAppDetail()) %>      
    </td>
    <td width="30" align="center"><%=i%></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()%>" >
    
    <input type="hidden"  name="ZDLX<%=i%>" value="<%=bdFormFieldInfo.getZDLX()%>">
    <input type="hidden" name="ZDCD<%=i%>" value="<%=bdFormFieldInfo.getZDCD()%>">
    <input type="hidden" name="ZDKK<%=i%>" value="<%=bdFormFieldInfo.getZDKK()%>">
    <input type="hidden" name="ZDLB<%=i%>" value="<%=bdFormFieldInfo.getZDLB()%>">
    <input type="hidden" name="Align<%=i%>" value="<%=bdFormFieldInfo.getAlign()%>">
    <input type="hidden" name="Bold<%=i%>" value="<%=bdFormFieldInfo.getBold()%>">
    <input type="hidden" name="Color<%=i%>" value="<%=bdFormFieldInfo.getColor()%>">
    <input type="hidden" name="Maxlen<%=i%>" value="<%=bdFormFieldInfo.getMaxlen()%>">
    <input type="hidden" name="ZDCX<%=i%>" value="<%=bdFormFieldInfo.getZDCX()%>">
    <input type="hidden" name="ZDDC<%=i%>" value="<%=bdFormFieldInfo.getZDDC()%>">
    <input type="hidden" name="ZDDR<%=i%>" value="<%=bdFormFieldInfo.getZDDR()%>">
    <input type="hidden" name="ZDCSZ<%=i%>" value="<%=bdFormFieldInfo.getZDCSZ()%>">
    <input type="hidden" name="ZDHS<%=i%>" value="<%=bdFormFieldInfo.getZDHS()%>">
    <input type="hidden" name="ZDZT<%=i%>" value="<%=bdFormFieldInfo.getZDZT()%>">              
  </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++;
   }
    
   if (i == 1 && j == 0) {
	   out.println("<tr><td colspan='21' height='100' align='center'>不存在数据表和字段，请进入“编辑界面”-“增加表格”。请注意浏览器是否拦截了“编辑界面”窗口</td></tr>");
   }
%>
  <tr class="trClassTitle2">
    <td>序号</td>
    <td>控件ID</td>
    <td>字段名</td>
    <td>字段说明</td>
    <td>所用控件</td>
	<td><a href="#" OnClick="javascript:CheckAll('AppList', false);">列表</a></td>
	<td><a href="#" OnClick="javascript:CheckAll('AppAdd', false);">添加</a></td>
	<td><a href="#" OnClick="javascript:CheckAll('AppReadonly', false);">只读</a></td>
	<td><a href="#" OnClick="javascript:CheckAll('AppAddBr', false);">换行</a></td>
	<td>添加样式</td>
	<td>关联</td>
	<td>弹出选择</td>
	<td>人员选择</td>	
	<td><a href="#" OnClick="javascript:CheckAll('AppDetail', false);">详情</a></td>
	<td>序号</td>
  </tr>  
  </form>
</table>

<!-----下面的工具栏------>
<table width="100%">
  <form name="formPage" method="post">
  <tr>
    <td align="left">
      <font color="red">

      </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 CheckAll(vChkId, flag) {
    var objectCount = parseInt(formList.objectCount.value);
    var e;
    for (var i=1; i<objectCount; i++) {
      e = eval("formList." + vChkId + i);
      if (e != null) {
        e.checked = flag;
      }
    }
  }
  
  function FormSave(formName, url) {
	if (confirm("确定要保存？")) {
    	//字段名只能是字母、数字
    	//字段名不能重复
    	formName.OPERATOR.value = "XMLFIELD_APP";
    	formName.action = url;
    	formName.submit();
    }
  }
  
  function CssSelect(i) {
    var obj = "formList.AppAddCss" + i; 
    var url = "css/cssSelect.jsp?Object=" + obj;    
    //window.showModalDialog(url,window,"status=no;dialogWidth=730px;dialogHeight=460px"); 
    window.open(url,"","left=100,top=100,scrollbars=yes,resizable=yes,status=yes,width=750,height=560");      
  }
  function OptionsSelect(i) {
    var obj = "formList.AppRelate" + i; 
    var url = "options/optionsSelect.jsp?Object=" + obj;    
    //window.showModalDialog(url,window,"status=no;dialogWidth=730px;dialogHeight=460px"); 
    window.open(url,"","left=100,top=100,scrollbars=yes,resizable=yes,status=yes,width=750,height=560");      
       
  }
  function OpenSelect(i) {
    var obj = "formList.AppOpenSelect" + i; 
    var url = "openselect/formSelectApp.jsp?Object=" + obj + "&module=<%=moduleName%>";    
    //window.showModalDialog(url,window,"status=no;dialogWidth=730px;dialogHeight=460px"); 
    window.open(url,"","left=100,top=100,scrollbars=yes,resizable=yes,status=yes,width=750,height=560");      
       
  }  
  function UserSelect(i) {
    var obj = "formList.AppUserSelect" + i; 
    var url = "userSelect/selectApp.jsp?Object=" + obj + "&module=<%=moduleName%>";    
    //window.showModalDialog(url,window,"status=no;dialogWidth=730px;dialogHeight=460px"); 
    window.open(url,"","left=100,top=100,scrollbars=yes,resizable=yes,status=yes,width=750,height=560");      
       
  }  
  
  function SelectHelp() {
  /*
  	//列表全选
  	CheckAll('AppList', true);
  	//添加全选
  	CheckAll('AppAdd', true);
  	//只读全选
  	//CheckAll('AppReadonly', true);    
  	//换行全选
  	CheckAll('AppAddBr', true);    		
  	//详情全选
  	CheckAll('AppDetail', true);   
  */	
  	//hidden默认不选，本人ID，部门ID默认不选
    var objectCount = parseInt(formList.objectCount.value);
    var e;
    var eAppList;
    var eAppAdd;
    var eAppDetail;
    var eAppAddBr;
    var eAppReadonly;
    var v;
    for (var i=1; i<objectCount; i++) {
      e = eval("formList.ZDBJ" + i);
      if (e != null) {
        v = e.value;
        eAppList = eval("formList.AppList" + i);
        eAppAdd = eval("formList.AppAdd" + i);
        eAppDetail = eval("formList.AppDetail" + i);
        eAppAddBr = eval("formList.AppAddBr" + i);
        eAppReadonly = eval("formList.AppReadonly" + i);
        if (v == "1" || v == "3" || v == "34") {
          eAppList.checked = false;
          eAppAdd.checked = false;
          eAppDetail.checked = false;
          eAppAddBr.checked = false;
        } else {
       	  eAppList.checked = true;
       	  eAppAdd.checked = true;
       	  eAppDetail.checked = true;
       	  eAppAddBr.checked = true;
        }
        
        //那些只读：日期，姓名，部门
        if (v == "4" || v == "44" || v == "42" || v == "43" || v == "2" || v == "33") {
          eAppReadonly.checked = true;
        } else {
       	  eAppReadonly.checked = false;
        }        

      }//if (e != null) {
    }//for (var i=1; i<objectCount; i++) {  		  	
  }  
</script>
