File: n_svc_isempty.sru
Size: 7857
Date: Mon, 07 Apr 2008 21:31:13 +0200
$PBExportHeader$n_svc_isempty.sru
$PBExportComments$Check empty service
forward
global type n_svc_isempty from n_svc_base
end type
end forward

global type n_svc_isempty from n_svc_base
end type
global n_svc_isempty n_svc_isempty

forward prototypes
public function boolean of_isempty (readonly date adt)
public function boolean of_isempty (readonly decimal ad)
public function boolean of_isempty (readonly long al)
public function boolean of_isempty (readonly string as)
public function boolean of_isempty (readonly time at)
public function boolean of_isempty (readonly any aa)
public function boolean of_isempty (readonly datetime adt)
end prototypes

public function boolean of_isempty (readonly date adt);//===========================================================================
// Function: of_Isempty (public )
// Object: n_svc_isempty
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly Date adt
//---------------------------------------------------------------------------
// Returns: Boolean
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
date     ldt_invalid
integer  liy
integer  lim
integer  lid

// Initialize test values.
ldt_invalid = date("50/50/1900")
liy = Year(adt)
lim = Month(adt)
lid = Day(adt)

// Check for nulls.
IF IsNull(adt) Or IsNull(liy) or IsNull(lim) or IsNull(lid) THEN
   RETURN TRUE
END IF

// Check for invalid values.
IF adt = ldt_invalid Or liy < 0 or lim < 0 or lid < 0 THEN
   RETURN TRUE
END IF

// Passed all testing.
RETURN FALSE
end function

public function boolean of_isempty (readonly decimal ad);//===========================================================================
// Function: of_Isempty (public )
// Object: n_svc_isempty
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly Decimal ad
//---------------------------------------------------------------------------
// Returns: Boolean
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN (ISNULL(ad) OR ad = 0.00)
end function

public function boolean of_isempty (readonly long al);//===========================================================================
// Function: of_Isempty (public )
// Object: n_svc_isempty
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly Long al
//---------------------------------------------------------------------------
// Returns: Boolean
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN (ISNULL(al) OR al = 0)
end function

public function boolean of_isempty (readonly string as);//===========================================================================
// Function: of_Isempty (public )
// Object: n_svc_isempty
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly String as
//---------------------------------------------------------------------------
// Returns: Boolean
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN (ISNULL(as) OR TRIM(as) = CString.EMPTY)
end function

public function boolean of_isempty (readonly time at);//===========================================================================
// Function: of_Isempty (public )
// Object: n_svc_isempty
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly Time at
//---------------------------------------------------------------------------
// Returns: Boolean
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
integer  lih
integer  lim
integer  lis

// Initialize test values.
lih = Hour(at)
lim = Minute(at)
lis = Second(at)

// Check for nulls.
IF IsNull(at) Or IsNull(lih) or IsNull(lim) or IsNull(lis) THEN
   RETURN TRUE
END IF

// Check for invalid values.
IF lih < 0 or lim < 0 or lis < 0 THEN
   RETURN TRUE
END IF

// Passed all testing.
RETURN FALSE
end function

public function boolean of_isempty (readonly any aa);//===========================================================================
// Function: of_Isempty (public )
// Object: n_svc_isempty
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly Any aa
//---------------------------------------------------------------------------
// Returns: Boolean
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls
long ll_num
date ldt
time lt
Boolean lb = TRUE
decimal{2} ld

ls = lower(ClassName(aa))

CHOOSE CASE ls
   CASE CDatatype.string
      ls = aa
      lb = of_isempty(ls)
   CASE CDatatype.integer, CDatatype.int, CDatatype.long, CDatatype.ulong, CDatatype.unsignedlong, CDatatype.uint, CDatatype.unsignedint, CDatatype.unsignedinteger, CDatatype.double, CDatatype.real
      ll_num = aa
      lb = of_isempty(ll_num)
   CASE CDatatype.decimal
      ld = aa
      lb = of_isempty(ld)
   CASE CDatatype.date
      ldt = aa
      lb = of_isempty(ldt)
   CASE CDatatype.datetime
      ldt = DATE(aa)
      lb = of_isempty(ldt)
   CASE CDatatype.time
      lt = aa
      lb = of_isempty(lt)     
END CHOOSE

RETURN lb
end function

public function boolean of_isempty (readonly datetime adt);//===========================================================================
// Function: of_Isempty (public )
// Object: n_svc_isempty
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly Datetime adt
//---------------------------------------------------------------------------
// Returns: Boolean
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
date  ldt

//Check parameters
IF IsNull(adt) THEN
   RETURN FALSE
END IF

//There is only need to test the Date portion of the DateTime.
//Can't tell if time is invalid because 12am is 00:00:00:000000
ldt = Date(adt)

//Check for invalid date
IF NOT this.of_isempty(ldt) THEN
   RETURN FALSE
END IF

RETURN TRUE
end function

on n_svc_isempty.create
call super::create
end on

on n_svc_isempty.destroy
call super::destroy
end on