Form VL_SAM105: Currency Converter

LANSA

Form VL_SAM105: Currency Converter
Name: VL_SAM105

Description: The following RDMLX form is uses both versions of the currency converter reusable component and demonstrates some simple functionality provided by these components.

Note: For this form to work correctly you will need to have added the fields, files and reusable components required.
FUNCTION OPTIONS(*DIRECT);
BEGIN_COM HEIGHT(316) LEFT(183) TOP(128) WIDTH(577);
DEFINE_COM CLASS(#VL_SAM104) NAME(#TOTAL) DISPLAYPOSITION(4) HEIGHT(41) LEFT(16) PARENT(#GPBX_1) TABPOSITION(2) TABSTOP(False) TOP(200);
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PHBN_2) CAPTION('Calculate Change') DISPLAYPOSITION(2) LEFT(344) PARENT(#COM_OWNER) TABPOSITION(4) TOP(112) WIDTH(193);
DEFINE_COM CLASS(#PRIM_STBR) NAME(#STBR_1) DISPLAYPOSITION(5) HEIGHT(24) LEFT(0) MESSAGEPOSITION(1) PARENT(#COM_OWNER) TABPOSITION(5) TABSTOP(False) TOP(265) WIDTH(569);
DEFINE_COM CLASS(#VL_SAM106) NAME(#TENDERED) DISPLAYPOSITION(4) LEFT(344) PARENT(#COM_OWNER) TABPOSITION(2) TABSTOP(False) TOP(16);
DEFINE_COM CLASS(#VL_SAM106) NAME(#CHANGE) DISPLAYPOSITION(3) LEFT(344) PARENT(#COM_OWNER) TABPOSITION(3) TABSTOP(False) TOP(64);
DEFINE_COM CLASS(#PRIM_LTVW) NAME(#ADDLIST) DISPLAYPOSITION(1) HEIGHT(129) LEFT(16) PARENT(#GPBX_1) TABPOSITION(1) TOP(16) WIDTH(305);
DEFINE_COM CLASS(#PRIM_LVCL) NAME(#LVCL_1) DISPLAYPOSITION(1) PARENT(#ADDLIST) SOURCE(#S_104VAL) WIDTH(61);
DEFINE_COM CLASS(#PRIM_LVCL) NAME(#LVCL_2) DISPLAYPOSITION(2) PARENT(#ADDLIST) SOURCE(#S_104CCDE) WIDTH(16) WIDTHTYPE(Remainder);
DEFINE_COM CLASS(#PRIM_LVCL) NAME(#LVCL_3) PARENT(#ADDLIST) SOURCE(#S_104BASE) VISIBLE(False) WIDTH(20);
DEFINE_COM CLASS(#VL_SAM106) NAME(#ADD) DISPLAYPOSITION(2) LEFT(16) PARENT(#GPBX_1) TABPOSITION(3) TABSTOP(False) TOP(152) WIDTH(224);
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PHBN_1) CAPTION('Add To List') DISPLAYPOSITION(3) LEFT(240) PARENT(#GPBX_1) TABPOSITION(4) TOP(168) WIDTH(81);
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PHBN_3) CAPTION('Clear List') DISPLAYPOSITION(5) LEFT(216) PARENT(#GPBX_1) TABPOSITION(5) TOP(216) WIDTH(81);
DEFINE_COM CLASS(#VL_SAM104) NAME(#HIDDEN) LEFT(344) PARENT(#COM_OWNER) TABSTOP(False) TOP(144) VISIBLE(False);
DEFINE_COM CLASS(#PRIM_GPBX) NAME(#GPBX_1) DISPLAYPOSITION(6) HEIGHT(249) LEFT(8) PARENT(#COM_OWNER) TABPOSITION(6) TABSTOP(False) TOP(8) WIDTH(329);
;
DEFINE FIELD(#AMOUNT) REFFLD(#S_104VAL);
DEFINE FIELD(#CURR) REFFLD(#S_104CCDE);
;
*;
* Initialise the Form;
*;
EVTROUTINE handling(#com_owner.Initialize);
SET #com_owner caption(*component_desc);
;
* Set some of the properties of the Visual Componenets;
Set #change ShowCurrCode('N');
Set #total Caption('Total');
Set #tendered Caption('Amount Tendered');
Set #change Caption('Change (In Default Currency)');
Set #add Caption('Amount to Add');
;
*;
* PLEASE NOTE:;
* The following code is only here to ensure that there is sample data in the files;
* so that this example can operate. This code will not exist in a working application;
* that will populate the tables via other means such as a direct feed from a stock;
* exchange.;
*;
EXECUTE SUBROUTINE(ADDCUR) WITH_PARMS('AUD' 1);
EXECUTE SUBROUTINE(ADDCUR) WITH_PARMS('USD' 0);
EXECUTE SUBROUTINE(ADDCUR) WITH_PARMS('FFR' 0);
EXECUTE SUBROUTINE(ADDCUR) WITH_PARMS('NZD' 0);
EXECUTE SUBROUTINE(ADDCONV) WITH_PARMS('AUD' 'FFR' 0 0 'I' 'USD');
EXECUTE SUBROUTINE(ADDCONV) WITH_PARMS('AUD' 'NZD' 1.3 1.2 'D' *BLANKS);
EXECUTE SUBROUTINE(ADDCONV) WITH_PARMS('AUD' 'USD' 0.5 0.4 'D' *BLANKS);
EXECUTE SUBROUTINE(ADDCONV) WITH_PARMS('USD' 'FFR' 10 9 'D' *BLANKS);
EXECUTE SUBROUTINE(ADDCONV) WITH_PARMS('NZD' 'USD' 0 0 'I' 'AUD');
*;
* END OF NOTE;
*;
;
ENDROUTINE;
;
*;
* Check for/add a record to the Currency file;
*;
SUBROUTINE NAME(ADDCUR) PARMS((#S_104CCDE *RECEIVED) (#S_104DFTC *RECEIVED));
FETCH FIELDS(#S_104CCDE #S_104DFTC) FROM_FILE(S_104CUR) WITH_KEY(#S_104CCDE);
IF_STATUS IS_NOT(*OKAY);
INSERT FIELDS(#S_104CCDE #S_104DFTC) TO_FILE(S_104CUR);
ENDIF;
ENDROUTINE;
;
*;
* Check for/add a record to the Conversion Factor file;
*;
SUBROUTINE NAME(ADDCONV) PARMS((#S_104FRCC *RECEIVED) (#S_104TOCC *RECEIVED) (#S_104CBR *RECEIVED) (#S_104CSR *RECEIVED) (#S_104TYPE *RECEIVED) (#S_104CCUR *RECEIVED));
FETCH FIELDS(#S_104FRCC #S_104TOCC #S_104CBR #S_104CSR #S_104TYPE #S_104CCUR) FROM_FILE(S_104CNV) WITH_KEY(#S_104FRCC #S_104TOCC);
IF_STATUS IS_NOT(*OKAY);
INSERT FIELDS(#S_104FRCC #S_104TOCC #S_104CBR #S_104CSR #S_104TYPE #S_104CCUR) TO_FILE(S_104CNV);
ENDIF;
ENDROUTINE;
;
;
*;
* Handle the click event on the "Calculate Change" button;
*;
EVTROUTINE HANDLING(#PHBN_2.Click);
* Ensure that the total is in the default currency;
Invoke #total.GoDefault;
;
* Change the Currency of the change field;
change #curr #tendered.Currency;
Set #change Currency(#curr);
;
* Change the Value of the change field;
change #amount #tendered.CurrentValue ;
set #change CurrentValue(#amount);
;
* Now that the change field is an exact copy of the tendered field, we change the;
* Change field back to the default currency as this is what we are going to give;
* change in;
Invoke #change.GoDefault;
;
Invoke #change.SubAmount ADDAMT(#total.CurrentValue) ADDCUR(#total.Currency);
ENDROUTINE;
;
*;
* Clear the list;
*;
EVTROUTINE HANDLING(#PHBN_3.Click);
Clr_List #ADDLIST;
;
Set #total CurrentValue(0);
Set #tendered CurrentValue(0);
Set #change CurrentValue(0);
ENDROUTINE;
;
*;
* Add the information to the list;
*;
EVTROUTINE HANDLING(#PHBN_1.Click);
* Move the details to the temp field and change to base currency;
change #curr #Add.Currency;
Set #hidden Currency(#curr);
change #amount #Add.CurrentValue ;
set #hidden CurrentValue(#amount);
Invoke #hidden.GoDefault;
;
CHANGE #S_104VAL #Add.CurrentValue;
CHANGE #S_104CCDE #Add.Currency;
CHANGE #S_104BASE #Hidden.CurrentValue;
;
* Finally add the entry to the list;
Add_Entry #ADDLIST;
;
Set #Add CurrentValue(0);
;
* Update the Total;
EXECUTE SUBROUTINE(CALCTTL);
ENDROUTINE;
;
*;
* Calculate the total;
*;
SUBROUTINE NAME(CALCTTL);
* Go through the list and get every value in the base currency;
CHANGE #amount *zero;
SELECTLIST #ADDLIST;
CHANGE #amount '#Amount + #S_104BASE';
ENDSELECT;
;
* Make sure that the Total Field is in the Default Currency;
Invoke #total.GoDefault;
Set #total CurrentValue(#amount);
ENDROUTINE;
END_COM;