File: n_ds.sru
Size: 7870
Date: Mon, 07 Apr 2008 21:30:58 +0200
$PBExportHeader$n_ds.sru
$PBExportComments$Base Datastore Object
forward
global type n_ds from datastore
end type
end forward

shared variables
Boolean #DisplayErrors = TRUE
end variables

global type n_ds from datastore
end type
global n_ds n_ds

type variables
private:
string is_lasterror
str_event istr_subscribers[]
string is_errortitle = "DBError"
end variables

forward prototypes
public function integer of_setdataobject (readonly string as_dataobjectname)
public function integer of_settransobject (readonly transaction atr)
public function long of_retrieve ()
public function long of_retrieve (readonly any aa[20])
public subroutine of_displayerrors (readonly boolean ab)
public function string of_getlasterror ()
public function string of_tostring ()
public function boolean of_subscribeevent (readonly powerobject apo_subscriber, readonly string as_subscribeevent, readonly string as_fireevent)
public subroutine of_clone (ref n_ds ads)
public subroutine of_seterrortitle (readonly string as_title)
public subroutine of_setdataobjectfromdatabase (readonly string as_dataobjectname, readonly transaction atr)
end prototypes

public function integer of_setdataobject (readonly string as_dataobjectname);/*
  <Name>        of_Setdataobject
  <Object>      n_ds
  <Access>      public 
  <Returns>     Integer
  <Throws>      

  <Arguments>   readonly String as_dataobjectname

  <Description> Dataobject checking and extendable for future functionality.

  <Author>      (Yeyi) Gabriel Abulencia
  <Company>     BAX Global

  <Updated>     Tuesday, 3. Jan. 2006
  <Version>     1.0
*/
n_svc_mgr lnv_svc
n_svc_isempty lnv_check

lnv_svc.of_LoadSvc(lnv_check, CSvc.ISEMPTY)

IF lnv_check.of_IsEmpty(as_dataobjectname) THEN RETURN CRet.FAILURE

this.DataObject = as_dataobjectname

TRY
   //try accessing a property to 
   //see if Dataobject is valid
   this.object.Datawindow.Syntax
CATCH (RuntimeError ex)
   MessageBox(ClassName(this) + " - of_SetDataobject", "The dataobject '" + &
            as_dataobjectname + "' is invalid or does not exist.", &
            Exclamation!)
   RETURN CRet.FAILURE
END TRY

RETURN CRet.SUCCESS
end function

public function integer of_settransobject (readonly transaction atr);/*
  <Name>        of_Settransobject
  <Object>      n_ds
  <Access>      public 
  <Returns>     Integer
  <Throws>      

  <Arguments>   readonly Transaction atr

  <Description> Provided for future functionality.

  <Author>      (Yeyi) Gabriel Abulencia
  <Company>     BAX Global

  <Updated>     Tuesday, 3. Jan. 2006
  <Version>     1.0
*/
RETURN SetTransObject(atr)
end function

public function long of_retrieve ();/*
  <Name>        of_Retrieve
  <Object>      n_ds
  <Access>      public 
  <Returns>     Long
  <Throws>      

  <Arguments>   

  <Description> Provided for adding future functionality.

  <Author>      (Yeyi) Gabriel Abulencia
  <Company>     BAX Global

  <Updated>     Tuesday, 3. Jan. 2006
  <Version>     1.0
*/
RETURN Retrieve()
end function

public function long of_retrieve (readonly any aa[20]);/*
  <Name>        of_Retrieve
  <Object>      n_ds
  <Access>      public 
  <Returns>     Long
  <Throws>      

  <Arguments>   readonly Any aa[20]

  <Description> Provided for future functionality.

  <Author>      (Yeyi) Gabriel Abulencia
  <Company>     BAX Global

  <Updated>     Tuesday, 3. Jan. 2006
  <Version>     1.0
*/
RETURN Retrieve(aa[1], aa[2], aa[3], aa[4], aa[5], aa[6], aa[7], aa[8], aa[9], aa[10]&
                  , aa[11], aa[12], aa[13], aa[14], aa[15], aa[16], aa[17], aa[18], aa[19], aa[20])
end function

public subroutine of_displayerrors (readonly boolean ab);/*
  <Name>        of_Displayerrors
  <Object>      n_ds
  <Access>      public 
  <Returns>     (none)
  <Throws>      

  <Arguments>   readonly Boolean ab

  <Description> Show a Messagebox when an error occurs 

  <Author>      (Yeyi) Gabriel Abulencia
  <Company>     BAX Global

  <Updated>     Tuesday, 3. Jan. 2006
  <Version>     1.0
*/
#DisplayErrors = ab
end subroutine

public function string of_getlasterror ();/*
  <Name>        of_Getlasterror
  <Object>      n_ds
  <Access>      public 
  <Returns>     String
  <Throws>      

  <Arguments>   

  <Description> Returns the last error message

  <Author>      (Yeyi) Gabriel Abulencia
  <Company>     BAX Global

  <Updated>     Tuesday, 3. Jan. 2006
  <Version>     1.0
*/
RETURN is_lasterror
end function

public function string of_tostring ();/*
  <Name>        of_Tostring
  <Object>      n_ds
  <Access>      public 
  <Returns>     String
  <Throws>      

  <Arguments>   

  <Description> Returns the data as string. Useful when debugging.

  <Author>      (Yeyi) Gabriel Abulencia
  <Company>     BAX Global

  <Updated>     Tuesday, 3. Jan. 2006
  <Version>     1.0
*/
RETURN Describe("Datawindow.Data")
end function

public function boolean of_subscribeevent (readonly powerobject apo_subscriber, readonly string as_subscribeevent, readonly string as_fireevent);/*
  <Name>        of_Subscribeevent
  <Object>      n_ds
  <Access>      public 
  <Returns>     Boolean
  <Throws>      

  <Arguments>   readonly PowerObject apo_subscriber
                readonly String as_subscribeevent
                readonly String as_fireevent

  <Description> Provided for future functionality.

  <Author>      (Yeyi) Gabriel Abulencia
  <Company>     BAX Global

  <Updated>     Tuesday, 3. Jan. 2006
  <Version>     1.0
*/
RETURN TRUE
end function

public subroutine of_clone (ref n_ds ads);/*
  <Name>        of_Clone
  <Object>      n_ds
  <Access>      public 
  <Returns>     (none)
  <Throws>      

  <Arguments>   reference n_ds ads

  <Description> Clones the current n_ds instance.

  <Author>      (Yeyi) Gabriel Abulencia
  <Company>     BAX Global

  <Updated>     Tuesday, 3. Jan. 2006
  <Version>     1.0
*/

blob lb

IF NOT ISVALID(ads) THEN ads = CREATE n_ds
this.GetFullState(lb)
ads.SetFullState(lb)
end subroutine

public subroutine of_seterrortitle (readonly string as_title);is_errortitle = as_title
end subroutine

public subroutine of_setdataobjectfromdatabase (readonly string as_dataobjectname, readonly transaction atr);n_svc_mgr lnv_svc
n_svc_dw_in_database lnv_db

lnv_svc.of_LoadSvc(lnv_db, "n_svc_dw_in_database")
IF NOT lnv_db.of_createfromdatabase(this, as_dataobjectname, atr) THEN
   //assign from library
   this.DataObject = as_dataobjectname
END IF
end subroutine

on n_ds.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_ds.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

event constructor;/*
  <Name>        Constructor
  <Object>      n_ds
  <Access>      public 
  <Returns>     Long
  <Throws>      

  <Arguments>   

  <Description> Set the default properties

  <Author>      (Yeyi) Gabriel Abulencia
  <Company>     BAX Global

  <Updated>     Tuesday, 3. Jan. 2006
  <Version>     1.0
*/
of_DisplayErrors(#DisplayErrors)
end event

event dberror;/*
  <Name>        Dberror
  <Object>      n_ds
  <Access>      public 
  <Returns>     Long
  <Throws>      

  <Arguments>   value Long sqldbcode
                value String sqlerrtext
                value String sqlsyntax
                value DwBuffer buffer
                value Long row

  <Description> Displays a MessageBox when an error occurs.

  <Author>      (Yeyi) Gabriel Abulencia
  <Company>     BAX Global

  <Updated>     Tuesday, 3. Jan. 2006
  <Version>     1.0
*/
is_lasterror = sqlerrtext

IF #DisplayErrors THEN
   MessageBox(is_errortitle + " - " + STRING(sqldbcode), sqlerrtext, StopSign!)
END IF
end event