<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.Iterator" %>
<%@ 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.system.SzLevelNumber" %>
<%@ page import="net.sz600.organize.SzModule" %>
<%@ page import="net.sz600.organize.SzModuleInfo" %>
<%@ 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>
<%
    //获取提交的参数
    String sPage = SzConvert.toZeroStr(request.getParameter("page"));
    String sSearch = SzConvert.strWriteData(request.getParameter("txtSearch"));
    String sType = SzConvert.toZeroStr(request.getParameter("type"));   
    String FirstMKBH = SzConvert.toZeroStr(request.getParameter("FirstMKBH"));
    String SecondMKBH = SzConvert.toZeroStr(request.getParameter("SecondMKBH")); 
    
    //读取数据
    SzModuleApp szModule = new SzModuleApp();
    SzModuleInfo szModuleInfo = null;
    String sCond = "1=1";
		if (sType.equals("1")) {
			sCond = SzSqlConvert.getFuncLen() + "(MKBH)=" + SzLevelNumber.I_NUMBER_LEN;
		} else if (sType.equals("2")) {
			sCond =  SzSqlConvert.getFuncLen() + "(MKBH)<=" + SzLevelNumber.I_NUMBER_LEN * 2;
		}
    if (!FirstMKBH.equals("0")) {
    	sCond += " AND MKBH LIKE '" + FirstMKBH + "%'";
    }
    if (!SecondMKBH.equals("0")) {
    	sCond += " AND MKBH LIKE '" + SecondMKBH + "%'";
    }    


    String sSortField = "MKBH";
    int iSortOrder = SzProperties.I_SortOrder_ASC;
    int iCurrentPage = 1;
    try {
        iCurrentPage =  Integer.parseInt(sPage);
    }catch(Exception e) {
    }
    //Iterator iter = szModule.getArrayList(sCond, sSortField, iSortOrder, iCurrentPage, sSearch).iterator();
    Iterator iter = szModule.getArrayList(sCond, sSortField, iSortOrder, sSearch).iterator();
    SzPageInfo pageInfo = szModule.getPageInfo();
    int iPageCount = pageInfo.getPageCount();
    int iRecordCount = pageInfo.getRecordCount();
    iCurrentPage = pageInfo.getCurrentPage();
    int i = 0;
%>
<!-----上面的工具栏------>
<form name="formList" method="post">
<%@ include file="/share/title.jsp"%>
<table width="100%">
  <tr>
    <td>
    <% if (isSystemManager_SESSION) { %>    
      <input type="button" name="btnAdd" class="btnClass" value="添加" OnClick="javascript:FormSubmit(formList, 'update.jsp?OPERATOR=add&KEY=0');">
      <input type="button" name="btnDel" class="btnClass" value="删除" OnClick="javascript:FormSubmitConfirm(formList, 'control.jsp?OPERATOR=delete','确定要删除？');">
      <%=SzPageHelp.button("导到Excel", "javascript:FormSubmit(formList, 'control.jsp?OPERATOR=export');")%>
      <%=SzPageHelp.button("Excel导入", "javascript:ExcelImportWin('ModuleImport');")%>
    <% } %>   
       一级：<%=SzPageHelp.numberSelectTreeSubmit("SZXT_MK_APP", "MKID", "MKMC", "MKBH", "FirstMKBH", FirstMKBH, "", SzSqlConvert.getFuncLen() + "(MKBH)=" + SzLevelNumber.I_NUMBER_LEN) %>
			二级：<%
      sCond = " MKBH LIKE '" + FirstMKBH + "%' AND " + SzSqlConvert.getFuncLen() + "(MKBH)=" + SzLevelNumber.I_NUMBER_LEN * 2;
      out.println(SzPageHelp.numberSelectTreeSubmit("SZXT_MK_APP", "MKID", "MKMC", "MKBH", "SecondMKBH", SecondMKBH, "", sCond)); 
      %>      
      <input type="radio" name="type" value="0" <% if (sType.equals("0")) { %>checked<% } %> OnClick="javascript:FormSubmit(formList, 'index.jsp');">
      不限制      
      <input type="radio" name="type" value="1" <% if (sType.equals("1")) { %>checked<% } %> OnClick="javascript:FormSubmit(formList, 'index.jsp');">
      仅显示一级  
      <input type="radio" name="type" value="2" <% if (sType.equals("2")) { %>checked<% } %> OnClick="javascript:FormSubmit(formList, 'index.jsp');">
      仅显示两级             
    </td>
  </tr>
</table>

<!-----信息列表----->
<table width="100%" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">

  <input type="hidden" name="page" value="<%=iCurrentPage%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <tr class="trClassTitle">
    <td width="5"><input type="checkbox" name="chkCheckAll" OnClick="javascript:CheckAll(formList, chkCheckAll, 'chkId');"></td>
    <td>模块名称</td>
    <td>连接地址</td>
    <td width="105">模块属性</td>
    <td width="100">操作</td>
  </tr>
<%
    String s = "";
    String s2 = "";
    String MKTZID = "";
    while (iter != null && iter.hasNext()) {
        szModuleInfo = (SzModuleInfo)iter.next();
        s = szModule.getPropertyName(szModuleInfo.getMKQX());
        //s2 = szModule.getPopedomName(szModuleInfo.getMKSX());
        if (szModuleInfo.getMKTZID() == szModuleInfo.getMKID()) {
        	MKTZID = "<font color='red'>" + szModuleInfo.getMKTZID() + "</fonr>";
        } else {
        	MKTZID = "" + szModuleInfo.getMKTZID();
        }
        i++;
%>
  <tr  onMouseOver="javascript:this.className='trMouseOver'" onMouseOut="javascript:this.className='trMouseOut'">
		<% if (1 !=1) {%>
		<td width="5" title="<%=i%>"><input type="checkbox" name="chkId" id="chkId" disabled>&nbsp;</td>
    <% } else { %>
    <td width="5" title="<%=i%>"><input type="checkbox" name="chkId" id="chkId" value="<%=szModuleInfo.getMKBH()%>">&nbsp;</td>
    <% } %>
    <td title="<%=szModuleInfo.getMKBH()%>" id="td<%=szModuleInfo.getMKBH()%>"
        <% if (isSystemManager_SESSION) { %>
        OnMouseDown="javascript:ClickElement('<%=szModuleInfo.getMKBH()%>','<%=szModuleInfo.getMKMC()%>');" 
        OnMouseUp="javascript:UpElement('<%=szModuleInfo.getMKBH()%>','<%=szModuleInfo.getMKMC()%>');"
        <% } %>        
        OnSelectStart="return false;"
        >
      <%=SzLevelNumber.getLevelSpace(szModuleInfo.getMKBH())%><%=szModuleInfo.getMKMC()%>&nbsp;</td>
    <td><%=szModuleInfo.getMKLJDZ()%>&nbsp;</td>
    <td><%=s%>&nbsp;</td>
    <td><% if (isSystemManager_SESSION) { %>
      <a href="javascript:FormSubmit(formPage,'update.jsp?OPERATOR=update&KEY=<%=szModuleInfo.getMKID()%>');">修改</a>
      <a href="javascript:FormSubmit(formPage,'control.jsp?OPERATOR=behind&KEY=<%=szModuleInfo.getMKID()%>');">调前</a>
      <a href="javascript:FormSubmit(formPage,'control.jsp?OPERATOR=front&KEY=<%=szModuleInfo.getMKID()%>');">调后</a>
      <% } %>
    </td>
  </tr>
<%
    }
    out.println(SzPageHelp.outIndexTableTr(i, SzProperties.I_PageSize, 5));
%>

  
</table>
</form>
<!-----下面的工具栏------>
<table width="100%">
  <form name="formPage" method="post">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="FirstMKBH" value="<%=FirstMKBH%>">
  <input type="hidden" name="SecondMKBH" value="<%=SecondMKBH%>">      
  <tr>
    <td align="right">
      <%@ include file="/share/page/search_include.jsp"%>
    </td>
  </tr>
  </form>
</table>
<br>提示：如果一级模块有连接地址，不要在下面增加二级模块，否则无法进入二级模块。
<!-----这里包含要提交的内容--->
<form name="formHidden" method="post">
</form>
<script language="javascript">
  //第一个表示对象，form，第二个表示字符串
  function FormSubmit(oFormName, vUrl) {
  	//if (confirm("确定要删除？")) {
    	oFormName.action = vUrl;
    	oFormName.submit();
  	//}
  }
  function FormSubmitConfirm(oFormName, vUrl, vMessage) {
     if (confirm(vMessage)) {
    	oFormName.action = vUrl;
    	oFormName.submit();
     }
  }

  function GoUrl(vUrl) {
    document.location.href = vUrl;
  }

  //javascript参数的调用：
  //checkAll(formList,chkCheckAll,'chkId')
  //第一个表示对象，第二个表示对象，第三个表示字符串
  function CheckAll(oFormList, oChkCheckAll, vChkId) {
    var e;
    for (var i=0; i<oFormList.elements.length; i++) {
      e = oFormList.elements[i];
      if (e.name == vChkId) {
        e.checked = oChkCheckAll.checked;
      }
    }
  }
  
  //点下鼠标
  var vMKBH_PRIO = "";
  var vMKMC_PRIO = "";
  function ClickElement(vBH, vName) {
  	vMKBH_PRIO = vBH;
  	vMKMC_PRIO = vName;
  	event.srcElement.style.background = "#abcdef";
  }
  
  //松开鼠标
  function UpElement(vBH, vName) {
  	event.srcElement.style.background = "#abcdef";
 		var vMKBH = vBH;
 		var vM = "[" + vMKMC_PRIO + "]和[" + vName + "]确定要互换位置"
 		if (vMKBH_PRIO != "" && vMKBH != "" && vMKBH_PRIO != vMKBH) {
 	  	if (vMKBH_PRIO.length > vMKBH.length && vMKBH_PRIO.indexOf(vMKBH) ==0) {
 			alert("下级不能跟上级互换位置");
 	  	} else {
 	      event.srcElement.style.background = "#abcdef";
 	      if (confirm(vM)) { 
 					document.location.href="control.jsp?OPERATOR=change&MKBH_PRIO=" + vMKBH_PRIO + "&MKBH=" + vMKBH + "&type=<%=sType%>&FirstMKBH=<%=FirstMKBH%>";
 		  	}
 	  	}
 		}

    event.srcElement.style.background = "#ffffff";
    //找到之前的
    var tdObj = document.getElementById("td" + vMKBH_PRIO);
    if (tdObj != null) {
    	tdObj.style.background = "#ffffff";
    }
    vMKBH_PRIO = "";
  }
  
  
</script>
<script language="javascript">
  function ExcelImportWin(vModule) {
	var url ="../../share/page/excel_import_win.jsp?module=" + vModule;
	//window.showModalDialog(url,window,"status=no;dialogWidth=580px;dialogHeight=350px");
	window.open(url,"","left=100,top=100,scrollbars=yes,resizable=yes,status=yes,width=580,height=350");
  }
</script> 
