⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logon.java

📁 eclipse java/jsp 航空管理系统
💻 JAVA
字号:
/*
 * Created on 2005-5-13
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package ddllogin.model;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
//import java.util.HashMap;
import java.util.StringTokenizer;

import zhangchunliang.model.AppMode;
//import java.util.*;
import ddllogin.form.LoginForm;
import kangyi.ConnectionPool.DbConnection;
/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Logon {
    /**
     * 
     * @uml.property name="db"
     * @uml.associationEnd multiplicity="(0 1)"
     */
    DbConnection db = null;

    Connection con=null;
    
    /*
     * name:         转换字符串方法
     * Description:  把屏幕上获取的中文字符串正确的传入MODEL中
     * @return       Str 转换完的字符串 
     */
    public String change(String s){
        String str=s;
        try{
            byte b[]=str.getBytes("ISO-8859-1");
            str=new String(b);
            return str;
        }
        catch(Exception e){
            return str;
        }
    }
    public String[] UserGrant(LoginForm lf){
    	
    	AppMode.registerUser();
        
        Statement sql=null;
        ResultSet rs=null;
        String id=lf.getUserName();
        id=change(id);
        String privselect="N";
        String privadd="N";
        String privdelete="N";
        String privupdate="N";
        String privadmin="N";
        String groupno;
        String strgrant[]={privselect,privadd,privdelete,privupdate,privadmin};
        try {
            db=new DbConnection();
            con=db.getCon();
            sql = con.createStatement();
            /*构造查询语句*/
            String condition = "select groupString from stuff " 
                               +"where sid=" 
                               + "'"+ id + "'";
            String condition1;
            rs=sql.executeQuery(condition);
            rs.first();
            System.out.println(rs.getString(1));
            /*得到员工所在的组*/
            String groupstring=rs.getString("groupstring");
            /*分析员工所在的组的字符串*/
            StringTokenizer fenxi=new StringTokenizer(groupstring,";");
            int n=fenxi.countTokens();
            while(fenxi.hasMoreTokens()){
                groupno=fenxi.nextToken();
                condition1="select * from privgroup " 
                           +"where groupno=" 
                           + "'"+ groupno + "'";
                rs=sql.executeQuery(condition1);
                rs.first();
                if(rs.getString(3).equals("Y")){
                    privselect="Y";   
                }
                if(rs.getString(4).equals("Y")){
                    privadd="Y";   
                }
                if(rs.getString(5).equals("Y")){
                    privdelete="Y";   
                }
                if(rs.getString(6).equals("Y")){
                    privupdate="Y";   
                }
                if(rs.getString(7).equals("Y")){
                    privadmin="Y";   
                }                
            }
            strgrant[0]=privselect;
            strgrant[1]=privadd;
            strgrant[2]=privdelete;
            strgrant[3]=privupdate;
            strgrant[4]=privadmin;
            con.close();
            db.d_close();
            AppMode.loginoutUser();
            return strgrant;
        } catch (SQLException e) {
        	
        	AppMode.loginoutUser();
        	
            System.out.print("操作失败"+e);
            return strgrant;
        }              
    }
    
    /*
     * name:         获得用户能管理的表名
     * describing:   通过登陆的ID获得此人能管理的表名
     * @return       String
     */
    
  /**  public String UserTable(LogonForm lf){
           
        Statement sql=null;
        ResultSet rs=null;
        String id=lf.getId();
        id=change(id);
        String tablename="null";
        try {
            db=new DbConnection();
            con=db.getCon();
            sql = con.createStatement();
           
            String condition = "select tablename from stuff,systable " 
                               +"where sid=" 
                               + "'"+ id + "'"
                               +"and stuff.depno=systable.depno";
            rs=sql.executeQuery(condition);
            rs.first();
            System.out.println(rs.getString(1));
            tablename=rs.getString(1);
            con.close();
            db.d_close();
            return tablename;
        }
        catch (SQLException e) {
            System.out.print("操作失败"+e);
            return tablename;
        }              
        
    }

这里到下边是我加的
    public List findTables(LogonForm lf){
        Statement sql=null;
        ResultSet rs=null;
        String id=lf.getId();
        List a=new ArrayList();
        id=change(id);
    try{
        db=new DbConnection();
        con=db.getCon();
        sql = con.createStatement();
        String condition = "select tablename from stuff,systable " 
        +"where sid=" 
        + "'"+ id + "'"
        +"and stuff.depno=systable.depno";
        rs=sql.executeQuery(condition);
        //rs.first();
        System.out.println("你好");
        //a.add(rs.getString(1));
        while(rs.next()){
            a.add(rs.getString(1));
        }
        System.out.println(a.get(1));
        System.out.println(a.get(2));
        System.out.println(a.size());
        con.close();
        db.d_close();
        return a;
        }catch(Exception e){
            System.out.println(e.getMessage());
            return a;
        }
        
        
    }
到这里是我加的*/
    
    
    
    
/**我们就用这个*/    
/**我添加的第二个方法,返回的是字符串*/
public String findTable(LoginForm lf){
	
	AppMode.registerUser();
	
    Statement sql=null;
    ResultSet rs=null;
    String id=lf.getUserName();
    StringBuffer stringBuffer=new StringBuffer();
    String str="";
    id=change(id);
try{
    db=new DbConnection();
    con=db.getCon();
    sql = con.createStatement();
    String condition = "select tablename from stuff,deptable " 
    +"where sid=" 
    + "'"+ id + "'"
    +"and stuff.depno=deptable.depno";
    rs=sql.executeQuery(condition);
    //rs.first();
    System.out.println("hello!");
    //stringBuffer.append(rs.getString(1)+";");
    while(rs.next()){
        stringBuffer.append(rs.getString(1)+";");
    }
    str=stringBuffer.toString();
    System.out.println(str);
    con.close();
    db.d_close();
    
    AppMode.loginoutUser();
    
    return str;
    }catch(Exception e){
    	
    	AppMode.loginoutUser();
    	
        System.out.println(e.getMessage());
        return str;
    }
    
}
/**到这里是我添加的第二个方法*/  

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -