<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.flow.*" %>
<%@ 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="/sessionInfo.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>
<%@ include file="title.jsp"%>
<%
    String moduleName = "";
    String formName = "";
    String sFlowID = SzConvert.toZeroStr(request.getParameter("FlowID"));     //流程ID
    String sStepID = SzConvert.toZeroStr(request.getParameter("StepID"));     //步骤ID 
    String sFormID = SzConvert.toZeroStr(request.getParameter("FormID"));  //表单ID 
    //根据表单取得moduleName, formName
    LcForm lcForm = new LcForm();
    LcFormInfo lcFormInfo = null;
    lcFormInfo = (LcFormInfo)lcForm.getInfoByKey(Integer.parseInt(sFormID));
    if (lcFormInfo != null) {
    	moduleName = lcFormInfo.getBDLJ();
    	formName = lcFormInfo.getBDBY1();
    }
    //System.out.println("moduleName=" + moduleName);
    //System.out.println("formName=" + formName);
    //取得流程名称
    LcFlow lcFlow = new LcFlow();
    String sFlowName = lcFlow.getMainByKey(Integer.parseInt(sFlowID));
    //取得步骤名称
    LcStep lcStep = new LcStep();
    String sStepName = lcStep.getMainByKey(Integer.parseInt(sStepID));
%>

<table width="100%">
  <form name="formBar" method="post">
  <tr>
    <td align="center">
      <input type="button" value="保存" OnClick="javascript:FormSave(formUpdate, 'popedom_control.jsp');">&nbsp;
      <input type="button" value="返回" onClick="document.location.href='index.jsp?type=<%=sFlowID%>'">
    </td>
  </tr>
  </form>
</table>
<!-----信息列表----->
<%
    BdFormControl bdFormControl = new BdFormControl();
    bdFormControl.getMapStatic(moduleName, formName);
    Map formMap  = bdFormControl.getFormMap();
    Map tableMap = bdFormControl.getTableMap();
    Map fieldMap = bdFormControl.getFieldMap();
    
	BdFormInfo bdFormInfo = null;
	bdFormInfo = (BdFormInfo)formMap.get(new String(moduleName + "-" + formName));  
    if (bdFormInfo == null) {
      bdFormInfo = new BdFormInfo();
    }
    
	BdFormTableInfo bdFormTableInfo = null;
	Collection collFormTable = null;
	collFormTable = (Collection)tableMap.get(new String(moduleName + "-" + formName));
	Iterator iterFormTable = null;

	//字段信息
	BdFormFieldInfo bdFormFieldInfo = null;
	Collection collFormField = null;
	collFormField = (Collection)fieldMap.get(new String(moduleName + "-" + formName));
	Iterator iterFormField = null;    

    if (collFormTable != null) {
      iterFormTable = collFormTable.iterator();
    }

    if (collFormField != null) {
      iterFormField = collFormField.iterator();
    }
%>
<b>表单名称：</b><%=bdFormInfo.getFormName() %>&nbsp;
<b>流程名称：</b><%=sFlowName %>&nbsp;
<b>步骤名称：</b><%=sStepName %>&nbsp;
<table width="100%" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <form name="formUpdate" method="post">
  <input type="hidden" name="moduleName" value="<%=moduleName%>">
  <input type="hidden" name="formName" value="<%=formName%>">
  <input type="hidden" name="FormID" value="<%=sFormID%>"> 
  <input type="hidden" name="FlowID" value="<%=sFlowID%>">
  <input type="hidden" name="StepID" value="<%=sStepID%>">
  <tr class="trClassTitle">
    <td width="45">可修改</td>
    <td>字段名</td>
    <td>中文名</td>

    <td width="45">可修改</td>    
    <td>字段名</td>
    <td>中文名</td>
    
    <td width="45">可修改</td>    
    <td>字段名</td>
    <td>中文名</td>
        
  </tr>   
<%
    int j = 0;
    int i = 0;
    String tableName = "";
    String tableId = "";
    String objectStr = "";
    String tableType = "";
    LcFieldPopedom lcFieldPopedom = new LcFieldPopedom();
    String strPopedom = lcFieldPopedom.getPopedomStr(Integer.parseInt(sFormID), Integer.parseInt(sFlowID), Integer.parseInt(sStepID) );
       

    String sCheck = "";
    while (iterFormTable != null && iterFormTable.hasNext()) {
        bdFormTableInfo = (BdFormTableInfo)iterFormTable.next();
        if (bdFormTableInfo.getGLBM().equals("")) {
            continue;
        }
        if (bdFormTableInfo.getGLLX().equals("1")) {
            continue;
        }        
        tableName = bdFormTableInfo.getGLBM();
        tableId = bdFormTableInfo.getGLID();
        //读取字段
        i=0;
        
        //本表已经设置的

%>
  <tr class="trClassTitle">
    <td colspan="20" align="left">对应的表：<%=bdFormTableInfo.getGLSM()%>&nbsp;<%=bdFormTableInfo.getGLBM()%>
      <input type="hidden" name="QXBM<%=j%>" value="<%=bdFormTableInfo.getGLBM()%>">
      &nbsp;
      <input type="checkbox" name="chkCheckAll" OnClick="javascript:CheckAll(formUpdate, chkCheckAll, 'QXZDMC<%=j%>');">全选
    </td>
  </tr>
<%
        sCheck = "";
        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 (i==0) {
            	out.println("<tr>");
            }
            sCheck = "";
            if (strPopedom.indexOf("," + tableName + "-" + bdFormFieldInfo.getZDID() + ",") >=0) {
              sCheck = "checked";
            }
            
%>
    <td align="center"><input type="checkbox" name="QXZDMC<%=j%>" value="<%=bdFormFieldInfo.getZDID()%>" <%=sCheck%> ></td>
    <td align="left"><%=bdFormFieldInfo.getZDMC()%></td>
    <td align="left"><%=bdFormFieldInfo.getZDSM()%></td>
<%
            i ++;
            if (i==3) {
            	i = 0;
				out.println("</tr>");
			}
       } //while ends
       if (i < 3) {
       	   for (int k=i; k<3; k++) {
    	       out.println("<td>&nbsp;</td>");
    	       out.println("<td>&nbsp;</td>");
    	       out.println("<td>&nbsp;</td>");
           }
       	   out.println("</tr>");
       }
       j++;
   }
%>
   <input type="hidden" name="tableCount" value="<%=j%>" >
  </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 = 
    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 ChangeZDLX(i) {
    var oZDLX = eval("formList.type" + 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;
    }
  }

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