project QadFinancials > class BRegion > method ValidateComponent
Description
Write here all tests on database update (new / modify / delete) that cannot be coded with a validation mask.
The type of update can be found in tc_status (N/C/D).
If you find incorrect data, you must write an entry in tFcMessages (using SetMessage) and set the return status of this method to either +1 or -1.
Return status +1 = data will still be accepted.
Return status -1 = data will not be accepted.
This method is run from SetPublicTables, before transferring the received data into the class temp-tables.
Parameters
oiReturnStatus | output | integer | |
Internal usage
unused
program code (program/bregion.p)
<ANCESTOR-CODE>
define buffer bt_sRegion for t_sRegion.
/* ================================================= */
/* just one active means of transport can be default */
/* ================================================= */
assign vlDefaultOK = true
viFcReturnSuper = oiReturnStatus
oiReturnStatus = 0.
for each t_sRegion where
t_sRegion.tc_Status = "N":U or
t_sRegion.tc_Status = "C":U:
if t_sRegion.RegionIsDefault and
t_sRegion.RegionIsActive
then do:
/* ============================================================ */
/* if there is another active & default region from UI => error */
/* ============================================================ */
for each bt_sRegion:
if bt_sRegion.Country_ID = t_sRegion.Country_ID and
bt_sRegion.Region_ID <> t_sRegion.Region_ID and
bt_sRegion.tc_Status <> "D":U and
bt_sRegion.RegionIsActive = true and
bt_sRegion.RegionIsDefault = true
then do:
assign vlDefaultOK = false
vcRowid = t_sRegion.tc_Rowid.
leave.
end.
end.
if not vlDefaultOK
then leave.
/* ================================================== */
/* get all regions of the current country from the db */
/* ================================================== */
<Q-6 run RegionByIdCountry (all) (Read) (NoCache)
(input ?, (RegionID)
input t_sRegion.Country_ID, (CountryID)
output dataset tqRegionByIdCountry) in BRegion >
/* ======================================================================= */
/* if there is another active & default region in DB which is still active */
/* & default and not to be deleted after being treated by UI => error */
/* ======================================================================= */
for each tqRegionByIdCountry:
if tqRegionByIdCountry.tiRegion_ID <> t_sRegion.Region_ID and
tqRegionByIdCountry.tlRegionIsActive = true and
tqRegionByIdCountry.tlRegionIsDefault = true
then do:
find bt_sRegion where
bt_sRegion.Region_ID = tqRegionByIdCountry.tiRegion_ID
no-error.
if not available bt_sRegion or
(bt_sRegion.RegionIsDefault = true and
bt_sRegion.RegionIsActive = true and
bt_sRegion.tc_Status <> "D":U)
then do:
assign vlDefaultOK = false
vcRowid = t_sRegion.tc_Rowid.
leave.
end.
end.
end. /* for each tqRegionByIdCountry */
end. /* if t_sRegion.RegionIsDefault */
if not vlDefaultOK
then do:
assign vcMessage = trim(substitute(#T-8'Only one region can be default for country &1.':100(3531)t-8#,
vcCountryCode)).
<M-7 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input 't_sRegion.RegionIsDefault':U (icFieldName),
input t_sRegion.RegionIsDefault (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input vcRowid (icRowid),
input 'QADFIN-1235':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BRegion>
assign oiReturnStatus = -1.
end.
end. /* for each t_sRegion */
if oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.