<%@ page import="java.io.*, java.util.*"%>
<%@ page language="java" contentType="text/html;charset=utf-8"%>
<%@ page import="com.eactive.eai.common.EAITable"%>
<%@ page import="com.eactive.eai.common.messagekey.*"%>

<%
    MessageKeyManager manager = MessageKeyManager.getInstance();
    String[]          alls    = manager.getAllKeyNames();
    String            action  = request.getParameter("actionType");
    
    String selectedKey = request.getParameter("selectedKey");
    if(selectedKey == null && alls.length>1) {
    	selectedKey = alls[0];
    }
    if ("reload".equals(action)){
    	//I를 "," 로 분리 해야됨
    	manager.reload(selectedKey.substring(0,selectedKey.length()-1),selectedKey.substring(selectedKey.length()-1) );
    }else if ("reloadAll".equals(action)){
    	manager.reload();
    }else {
    	;
    }
       
    MessageKeyVO vo = null;
    if(selectedKey != null){    
    	vo = manager.getMessageKey(selectedKey);
    }
    String voName = (String)vo.getName();
    String adptName = voName.substring(0, voName.length()-1);
    String exrTp = voName.substring(voName.length()-1);
    
%>
<html>
    <head>
        <title>
            MessageKey Manager
        </title>
        <script>
        function doAction() {
            document.frm.submit();
        }
        function managerReload(){ 
        	document.frm.actionType.value="reload";
        	document.frm.submit();
        	
        }
        function managerReloadAll(){
        	document.frm.actionType.value="reloadAll";
        	document.frm.submit();
        }        
        function doSearch(){
        	
        	var searchValue = document.frm.adptName.value+document.frm.exrTp.value;
        	document.frm.selectedKey.value = searchValue;
        	document.frm.submit();
        }
        function enterEvent(){
        	if(window.event.keyCode==13){
        		doSearch();
        	}
        }
        </script>
    </head>
    <body>
        <p style="font-size:12pt;">
        <b>메세지키 관리</b> <br><br>
        </p>
        <form name="frm" action="">
        <input type="hidden" name="actionType" value="">
        <table width="800" border=0 bgcolor='black' cellpadding="1" cellspacing="1">
	        <tr bgcolor='white'>
	            <td align='right' width='350' bgcolor="#ccccff">어댑터명 + 기능구분 :&nbsp;&nbsp;</td>
	            <td align='left'>&nbsp;<select name="selectedKey" onchange="doAction();" style="width:98%;" >
	            <%
	                for(int i=0;i<alls.length;i++) {
	            %>
	                <option value="<%=alls[i]%>" <%= (alls[i].equals(selectedKey)) ? "selected" : "" %>><%=alls[i]%>
	            <%  
	                }
	            %></select>
	            </td>
	            <td width='50'><input type="button" name="reload" value="reload" onClick="managerReload()" /></td>
	            <td width='70'><input type="button" name="reloadAll" value="reloadAll" onClick="managerReloadAll()" /></td>
	        </tr>
	        <tr bgcolor='white'>
	        	<td align='right' bgcolor="#ccccff">어댑터명 : &nbsp;&nbsp;</td>
	        	<td align='left' >&nbsp;<input type="edit" name="adptName" onkeydown="enterEvent()" value="<%=adptName%>" style="width:98%;" /></td> 
	            <td colspan=2 rowspan=2 align='center'><input type="button" name="search" value="search" onClick="doSearch()" /></td>
	        </tr>
	        <tr bgcolor='white'>
	        	<td align='right' bgcolor="#ccccff">기능구분 : &nbsp;&nbsp;</td>
	        	<td align='left' >&nbsp;<input type="edit" name="exrTp" onkeydown="enterEvent()" value="<%=exrTp%>"style="width:98%;"/></td> 
	        </tr>
        </table>
        <br>
        <table width="800" border=0 bgcolor='black' cellpadding="1" cellspacing="1">
        <tr bgcolor='white'>
            <td align='right' colspan=2 bgcolor="#003366">&nbsp; <font color="yellow"><b>내용</b> &nbsp;</font></td>
        </tr>
<%
    if(vo != null) {
%>        
        <tr bgcolor='white'>
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; 어댑터명  : &nbsp;&nbsp;</td>
            <td align='left' style="height:40px;">&nbsp;<input type="text" name="AdptIoBwkNm" style="width:98%" value="<%=adptName%>" readonly></td>
        </tr>
        
        <tr bgcolor='white'>
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; 메시지유형 : &nbsp;&nbsp;</td>
            <td align='left' style="height:40px;">&nbsp;
            <select name="MsgTp">
            <%
                int msgTypeLength = EAITable.MSG_TYPES.length;
                
                for(int i=0; i<msgTypeLength; i++) {
            %>
            <option value="<%=EAITable.MSG_TYPES[i]%>" <%= (EAITable.MSG_TYPES[i].equals(vo.getMsgTp())) ? "selected" : "" %>><%=EAITable.MSG_TYPE_NAMES[i]%>
            <%
                }
            %>
            </select>
            </td>
        </tr>
        <tr bgcolor='white'>
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; 기능구분 : &nbsp;&nbsp;</td>
            <td align='left' style="height:40px;">&nbsp;<select name="ExrTp">
            <%
                int exrTypeLength = EAITable.EXR_TYPES.length;
                
                for(int i=0; i<exrTypeLength; i++) {
            %>
            <option value="<%=EAITable.EXR_TYPES[i]%>" <%= (EAITable.EXR_TYPES[i].equals(vo.getExrTp())) ? "selected" : "" %>><%=EAITable.EXR_TYPE_NAMES[i]%>
            <%
                }
            %>
            </select>
        </tr>
        <%
        int groupSize = vo.getAlMsgGroups().size();	
        for(int g=0; g<groupSize; g++ ) {
%>
		<tr bgcolor='white'>
            <td align='right' height="5" bgcolor="#003366" colspan="2">&nbsp;<font color="yellow"><b>Group[<%= g %>]</b> &nbsp;</font></td>
        </tr>
<%
        	MessageKeyGroupVO group = vo.getMessageKeyGroup(g);        	
        	int fldSize  = group.getMessageKeyFldLength();
            for(int i=0; i<fldSize; i++) {
                
        %>
        <tr bgcolor='white'>
            <td align='right' height="5" bgcolor="#003366" colspan="2">&nbsp;<font color="yellow"><b>Field[<%= i %>]</b> &nbsp;</font></td>
        </tr>
        <tr bgcolor='white'>
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; 업무필드명 : &nbsp;&nbsp;</td>
            <td align='left' style="height:40px;">&nbsp;<input type="text" name="BwkColNm" style="width:98%" value="<%=group.getMessageKeyFld(i).getBwkColNm()%>"></td>
        </tr>
        <tr bgcolor='white'>
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; 클래스명 : &nbsp;&nbsp;</td>
            <td align='left' style="height:40px;">&nbsp;<input type="text" name="BwkClassNm" style="width:98%" value="<%=group.getMessageKeyFld(i).getBwkClassNm()%>"></td>
        </tr>
        
        <tr bgcolor='white'>
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; 필드시작위치 : &nbsp;&nbsp;</td>
            <td align='left' style="height:40px;">&nbsp;<input type="text" name="BwkColStart" style="width:98%" value="<%=group.getMessageKeyFld(i).getBwkColStart()%>"></td>
        </tr>
        
        <tr bgcolor='white'>
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; 필드길이 : &nbsp;&nbsp;</td>
            <td align='left' style="height:40px;">&nbsp;<input type="text" name="BwkColLength" style="width:98%" value="<%=group.getMessageKeyFld(i).getBwkColLength()%>"></td>
        </tr>
        <tr bgcolor='white'>
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; 정상값 : &nbsp;&nbsp;</td>
            <td align='left' style="height:40px;">&nbsp;<input type="text" name="BwkColDef" style="width:98%" value="<%=group.getMessageKeyFld(i).getBwkColDef()%>"></td>
        </tr>
<% 
        	}
        }           
    }
%>
        
        </table>
        </form>
    </body>
</html>