二级菜单

setOption.java
package setOption;

import com.connection;
import java.sql.*;
public class setOption
{
	private int GroupID;
	private int parentid;
	private String GroupName;
	private String space;
	private String strsql;
	private String html;
	private connection dblink;
	private Statement  stmt;
	public setOption()
	{
		dblink = new connection();
		GroupID=0;
		parentid=0;
		GroupName="";
		html="";
		strsql="";
		stmt=null;
	}
	
	public String setGroupOptions(int level,int parentID,int val,String grouptype,String userid)
	{
		try
		{
			Connection CB=dblink.getConnection();
			stmt=CB.createStatement();
			strsql="select * from tGroupInfo where GroupType='"+grouptype+"' and CreateUserID='"+userid+"'";
			if(parentID >0)
			{
				strsql+=" and ParentID ="+parentID+"";
			}
			else
			{
				html+="<option value=0";
				if(val==0)
					html+=" selected";
				html+=">無上級組</option>\n";
				strsql+=" and ParentID = 0";
			}
		///	
			//WriteLog.getInstance().WriteLogFile("SQl_One:-------"+strsql);
			
			ResultSet rs=stmt.executeQuery(strsql);
			//WriteLog.getInstance().WriteLogFile("level==========:"+level);
			//WriteLog.getInstance().WriteLogFile("space==========:"+space);
			
			while(rs.next())
			{
				space=separator("--",level);
				GroupID=rs.getInt("GroupID");
				GroupName=strrequest(rs.getString("GroupName"));
		
				html+="<option value="+GroupID+"";
				if(GroupID==val)
					html+=" selected";
				html+=">"+space+""+GroupName+"</option>\n";
				strsql="select * from tGroupInfo where ParentID="+GroupID+"";
				//WriteLog.getInstance().WriteLogFile("SQl_Two:-------"+strsql);
				Statement substmt=CB.createStatement();
				ResultSet RS=substmt.executeQuery(strsql);
				
				if(RS.next())
				{
					//WriteLog.getInstance().WriteLogFile("login in GroupID:-------"+GroupID);
					level++;
					setGroupOptions(level,GroupID,val,grouptype,userid);
					level--;
				}
			/*	else
				{
					WriteLog.getInstance().WriteLogFile("not login in GroupID:-------"+GroupID);
					
				}*/
				RS.close();
				substmt.close();
			}
            rs.close();
		}
		catch(Exception e)
		{
			//WriteLog.getInstance().WriteLogFile("Exception==========:"+e.toString());
			System.out.print(e.toString());
		}
		//WriteLog.getInstance().WriteLogFile("String==========:"+html);
		return html;
	}
	//search admin userid
	public String getAdminUserID()
	{
	  String AdminUserID = "0";	
      try
      {
        Connection CB=dblink.getConnection();
		stmt=CB.createStatement();
		strsql="select Usr_ID from tUser where Usr_Role='Admin' limit 0,1";
		ResultSet rs=stmt.executeQuery(strsql);
		if(rs.next())
		{
			AdminUserID = rs.getString("Usr_ID");	
		}
        rs.close();
      }
      catch(Exception e)
	  {
			//WriteLog.getInstance().WriteLogFile("Exception==========:"+e.toString());
			System.out.print(e.toString());
	  }
	  return AdminUserID;
	}
	
	
	public String setGroup(int level,int parentID,String grouptype,String userid)
	{
		try
		{
			Connection CB=dblink.getConnection();
			stmt=CB.createStatement();
			strsql="select * from tGroupInfo where GroupType='"+grouptype+"' and CreateUserID='"+userid+"'";
			if(parentID >0)
			{
				strsql+=" and ParentID ="+parentID+"";
			}
			else
			{
				strsql+=" and ParentID = 0";
			}
		///	
			//WriteLog.getInstance().WriteLogFile("SQl_One:-------"+strsql);
			
			ResultSet rs=stmt.executeQuery(strsql);
			//WriteLog.getInstance().WriteLogFile("level==========:"+level);
			//WriteLog.getInstance().WriteLogFile("space==========:"+space);
			
			while(rs.next())
			{
				space=separator("--",level);
				GroupID=rs.getInt("GroupID");
				GroupName=strrequest(rs.getString("GroupName"));
				html+="<tr onMouseOver=\"mOvr(this,'#C0D8F0')\" onMouseOut=\"mOut(this,'#FFFFFF')\" onClick=\"selectDept('"+GroupID+"')\" style=\"cursor:hand\">";
			    html+="<td width=\"92%\" class=\"td8\"> "+space+""+GroupName+"</td><td width=\"8%\"><img src=\"../../images/jiantou1.gif\" width=\"8\" height=\"9\"></td></tr>";
				strsql="select * from tGroupInfo where ParentID="+GroupID+"";
				//WriteLog.getInstance().WriteLogFile("SQl_Two:-------"+strsql);
				Statement substmt=CB.createStatement();
				ResultSet RS=substmt.executeQuery(strsql);
				
				if(RS.next())
				{
					//WriteLog.getInstance().WriteLogFile("login in GroupID:-------"+GroupID);
					level++;
					setGroup(level,GroupID,grouptype,userid);
					level--;
				}
			/*	else
				{
					WriteLog.getInstance().WriteLogFile("not login in GroupID:-------"+GroupID);
					
				}*/
				RS.close();
				substmt.close();				
			}
			rs.close();
		}
		catch(Exception e)
		{
			//WriteLog.getInstance().WriteLogFile("Exception==========:"+e.toString());
			System.out.print(e.toString());
		}
		//WriteLog.getInstance().WriteLogFile("String==========:"+html);
		return html;
	}
	public String getGroupID(int parentID,int val)
	{
		try
		{
			Connection CB=dblink.getConnection();
			stmt=CB.createStatement();
			strsql="select GroupID,ParentID from tGroupInfo where ParentID="+val+"";
			ResultSet rs=stmt.executeQuery(strsql);
			while(rs.next())
			{
				GroupID=rs.getInt("GroupID");
				parentid=rs.getInt("ParentID");
				html+=rs.getString("GroupID")+",";
				strsql="select * from tGroupInfo where ParentID="+GroupID+"";
				Statement substmt=CB.createStatement();
				ResultSet RS=substmt.executeQuery(strsql);				
				if(RS.next())
				{
					getGroupID(parentid,GroupID);
				}
				RS.close();
				substmt.close();
			}
            rs.close();
		}
		catch(Exception e)
		{
			System.out.print(e.toString());
		}
		return html;
	}	
//復隅煦路睫	
	public String separator(String str,int level)
	{
		String Str="";
		for(int i=0;i<level;i++)
		{
			Str+=str;
		}
		return Str;
	}

	 private String strrequest(String input){//殿隙BIG5鎢/甜蔚杻忷睫瘍蛌趙
	 if(input!=null){
	 
			 try   {

			 //  public static String replaceHTML(String input) 
		char ch=' ';
		StringBuffer buf=new StringBuffer(input.length()+6);
		if(input==null || input.length()==0)return input;
		for(int i=0 ;i<input.length(); i++){
			ch=input.charAt(i);  
			 if(ch=='<')buf.append("<");
			else if(ch=='>')buf.append(">");
			else if(ch=='\'')buf.append("´");
			else if(ch=='\"')buf.append(""");
			//else if(ch==' ')buf.append(" ");
			else
				buf.append(ch);
		}
		input=buf.toString();

		 byte[] b_inputtemp=input.getBytes("ISO8859_1");
		 String temp=new String(b_inputtemp,"big5"); 
		 return temp;
	   }
	   catch(Exception e){	 
		 return input;
		 }
	}
else
return "";
}
}
<%@page language="java"%>
<%@page contentType="text/html;charset=big5"%>
<%@page import ="java.sql.*"%>
<%@page import ="java.util.*"%>
<%@page import ="java.io.*"%>
<%@ include file="/inc/strRequest.jsp" %>
<%@ include file="/inc/sessionsec.jsp" %>
<jsp:useBean id="DBconn" scope="page" class="com.connection" />
<jsp:useBean id="setoption" scope="page" class="setOption.setOption" />
<%
 String user = (String)session.getAttribute("user");
 String userid = (String)session.getAttribute("userid");
 String  url="";
 //String userid=(String)session.getAttribute("userid");
 /*String App_ID=str(request.getParameter("App_ID"));
 if(App_ID.equals(""))
 App_ID=str((String)session.getAttribute("App_ID"));
 session.setAttribute("App_ID",App_ID);
 String CurrentPage="";*/
  String App_ID="",grouptype="", GroupMember="",LinkManID="";
 App_ID=(String)session.getAttribute("App_ID");
 if(App_ID.equals("5"))
 {
	  grouptype="Public";
	  url="publicgroupList.jsp";
  }
 else 
 {
	  grouptype="Private";
	  url="privategroupList.jsp";
  }
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<link href="../style.css" rel="stylesheet" type="text/css">
<script language="javascript">
	function CheckValue(){
		 if(document.form1.GroupName.value==""){
			alert("請輸入組名稱!");
			document.form1.GroupName.focus();
			return false;
		 }
	    if(document.form1.GroupList.value=="" || document.form1.GroupList.value==null)
		  {
		  alert("請選擇上級組!");
		  document.form1.GroupList.focus();
		  return false;
		  }
		  document.form1.action='saveGroup.jsp';
		  document.form1.submit();
	  }
	function ShowItem(){
		var szRef = "select/selectGroupMember.jsp";
		window.open(szRef,"scie","screenX=100,screenY=100,left=200,top=200,width=650px,height=450px,scroll=no");
	}
</script>
<title>KinYip SMS System (Add Group)</title>
</head>
<body>
<form name="form1" method="post" action="">
<table width="80%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
	<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><span class="td8">您當前位置:<a href="/blank.jsp">首頁</a><img name="meun_r2_c7" src="../top/arrow.gif" border="0">短信系統<img name="meun_r2_c7" src="../top/arrow.gif" border="0">通訊錄<img name="meun_r2_c7" src="../top/arrow.gif" border="0">添加        用戶:<%= strrequest(user)%> </span> </td>
      </tr>
    </table>
	<br>
	<table width=800 border="0" align="center" cellpadding="3" cellspacing="0">
  		<tr>
    		<td align="center" bgcolor="#C0D8F0" class="td8"> 添加組</td>
  		</tr>
	</table>
	<br>
	<table width=800 border="0" cellspacing="1" cellpadding="2" align="center" bgcolor="#C0D8F0">
  		<tr>
    		<td width="155" bgcolor="#ccddee" class="td8"> 組編號</td>
    		<td width="236" bgcolor="#FFFFFF"> 
        		<input class="input" style="width:90% " type="text" name="GroupNo"  value="系統自動生成"disabled>
        	</td>
    		<td width="155" bgcolor="#ccddee" class="td8"> 組名稱</td>
    		<td width="233" bgcolor="#FFFFFF"> 
        		<input class="input" style="width:90% " type="text" name="GroupName">
				<font color="red">*</font></td>
  		</tr>
  		<tr>
    		<td bgcolor="#ccddee" class="td8"> 組描述</td>
    		<td bgcolor="#FFFFFF"> 
				<input class="input" style="width:90% " type="text" name="Remark"></td>
    		<td bgcolor="#ccddee" class="td8"> 上級組</td>
    		<td bgcolor="#FFFFFF"> 
				<select name="GroupList" class="input" style="width:90% " >
			  <%= setoption.setGroupOptions(0,0,0,grouptype,userid)%>
			  </select></td>
  		</tr> 
		<tr>
    		<td bgcolor="#ccddee" class="td8"><a href="#" onClick="ShowItem()"> 添加組成員</a></td>
    		<td bgcolor="#FFFFFF" colspan=3> 
    		  <input class="input" style="width:96% " type="text" name="GroupMember" value="<%=GroupMember%>" readonly></td>
  		</tr>  		
		</table>
<br>
			<input id="LinkManID" name="LinkManID"  type="hidden" value="<%=LinkManID%>">
<table width=800 border="0" align="center" cellpadding="3" cellspacing="0" bgcolor="#C0D8F0">
  			<tr height="20">
				<td align="center">
					<a href="#" onClick="return CheckValue()" ><img src="../images/save_back_ch.gif" width="65" height="19" border="0"></a>   
					<a href="javascript:window.location='<%=url%>'"><img src="../images/back.gif" width="58" height="19" border="0"></a>
				</td>
  			</tr>
		</table>
	</td>
  </tr>
</table>
</form>
<% 		
        session.removeAttribute("idList2");
		session.removeAttribute("nameList2");
		session.removeAttribute("titleList2");
		session.removeAttribute("mobileList2");
 %>
</body>
</html>
 
 

你可能感兴趣的:(JavaScript,html,sql,jsp,css)