private String checkLogin(Properties ctx,int AD_User_ID,int AD_Role_ID,int AD_Client_ID,int AD_Org_ID,int M_Warehouse_ID){
  String loginInfo=null;
  String sql="SELECT u.Name || '@' || c.Name || '.' || o.Name || ' [' || INITCAP(USER) || ']' AS Text " + "FROM AD_User u, AD_Client c, AD_Org o, AD_User_Roles ur " + "WHERE u.AD_User_ID=?"+ " AND c.AD_Client_ID=?"+ " AND o.AD_Org_ID=?"+ " AND ur.AD_Role_ID=?"+ " AND ur.AD_User_ID=u.AD_User_ID"+ " AND (o.AD_Client_ID = 0 OR o.AD_Client_ID=c.AD_Client_ID)"+ " AND c.AD_Client_ID IN (SELECT AD_Client_ID FROM AD_Role_OrgAccess ca WHERE ca.AD_Role_ID=ur.AD_Role_ID)"+ " AND o.AD_Org_ID IN (SELECT AD_Org_ID FROM AD_Role_OrgAccess ca WHERE ca.AD_Role_ID=ur.AD_Role_ID)";
  try {
    PreparedStatement pstmt=DB.prepareStatement(sql,null);
    pstmt.setInt(1,AD_User_ID);
    pstmt.setInt(2,AD_Client_ID);
    pstmt.setInt(3,AD_Org_ID);
    pstmt.setInt(4,AD_Role_ID);
    ResultSet rs=pstmt.executeQuery();
    if (rs.next())     loginInfo=rs.getString(1);
    rs.close();
    pstmt.close();
  }
 catch (  SQLException e) {
    log.log(Level.SEVERE,sql,e);
  }
  if (loginInfo == null)   return null;
  KeyNamePair org=new KeyNamePair(AD_Org_ID,String.valueOf(AD_Org_ID));
  KeyNamePair wh=null;
  if (M_Warehouse_ID > 0)   wh=new KeyNamePair(M_Warehouse_ID,String.valueOf(M_Warehouse_ID));
  Timestamp date=null;
  String printer=null;
  Login login=new Login(ctx);
  login.loadPreferences(org,wh,date,printer);
  Env.setContext(ctx,"#ShowAcct","N");
  Env.setContext(ctx,"#ShowTrl","N");
  return loginInfo;
}

private String checkLogin ( Properties ctx , int AD_User_ID , int AD_Role_ID , int AD_Client_ID , int AD_Org_ID , int M_Warehouse_ID ) { String loginInfo = null ; String sql = "SELECT u.Name || '@' || c.Name || '.' || o.Name || ' [' || INITCAP(USER) || ']' AS Text " + "FROM AD_User u, AD_Client c, AD_Org o, AD_User_Roles ur " + "WHERE u.AD_User_ID=?" + " AND c.AD_Client_ID=?" + " AND o.AD_Org_ID=?" + " AND ur.AD_Role_ID=?" + " AND ur.AD_User_ID=u.AD_User_ID" + " AND (o.AD_Client_ID = 0 OR o.AD_Client_ID=c.AD_Client_ID)" + " AND c.AD_Client_ID IN (SELECT AD_Client_ID FROM AD_Role_OrgAccess ca WHERE ca.AD_Role_ID=ur.AD_Role_ID)" + " AND o.AD_Org_ID IN (SELECT AD_Org_ID FROM AD_Role_OrgAccess ca WHERE ca.AD_Role_ID=ur.AD_Role_ID)" ; try { PreparedStatement pstmt = DB . prepareStatement ( sql , null ) ; pstmt . setInt ( 1 , AD_User_ID ) ; pstmt . setInt ( 2 , AD_Client_ID ) ; pstmt . setInt ( 3 , AD_Org_ID ) ; pstmt . setInt ( 4 , AD_Role_ID ) ; ResultSet rs = pstmt . executeQuery ( ) ; if ( rs . next ( ) ) loginInfo = rs . getString ( 1 ) ; rs . close ( ) ; pstmt . close ( ) ; } catch ( SQLException e ) { log . log ( Level . SEVERE , sql , e ) ; } if ( loginInfo == null ) return null ; KeyNamePair org = new KeyNamePair ( AD_Org_ID , String . valueOf ( AD_Org_ID ) ) ; KeyNamePair wh = null ; if ( M_Warehouse_ID > 0 ) wh = new KeyNamePair ( M_Warehouse_ID , String . valueOf ( M_Warehouse_ID ) ) ; Timestamp date = null ; String printer = null ; Login login = new Login ( ctx ) ; login . loadPreferences ( org , wh , date , printer ) ; Env . setContext ( ctx , "#ShowAcct" , "N" ) ; Env . setContext ( ctx , "#ShowTrl" , "N" ) ; return loginInfo ; }
check login information and set context .
