Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
KBizObj changes to allow default values (ie foreign keys
Message
De
12/03/2001 11:35:55
Rex Mahel
Realm Software, Llc
Ohio, États-Unis
 
 
À
12/03/2001 08:24:44
Information générale
Forum:
Visual FoxPro
Catégorie:
The Mere Mortals Framework
Divers
Thread ID:
00479312
Message ID:
00484080
Vues:
32
Gary,

I just emailed Kevin regarding a solution to this problem. My solution is similar to Kevin's View Parameter solution. I added an array (aDefaultValues[1,2]) to a KBizObj subclass. Next I added the following methods:
AddDefaultValue() and


*-- Populate the aDefaultValue array for later use.
PROCEDURE adddefaultvalue
LPARAMETER tcName, tcExpr
LOCAL ;
lnRows

lnRows = ALEN(This.aDefaultValues,1)

*!*************************************************
*!* If this is not the first view parameter to be
*!* added, add a new row to the array property
*!*************************************************
IF ! EMPTY(This.aDefaultValues[1,1])
lnRows = lnRows + 1
DIMENSION This.aDefaultValues[lnRows,2]
ENDIF

*!*****************************************************
*!* Store the specified valaues in the array property
*!*****************************************************
This.aDefaultValues[lnRows,1] = tcName
This.aDefaultValues[lnRows,2] = tcExpr
ENDPROC

*-- Populate new record fields with value from supplied expression
PROCEDURE setdefaultvalues
IF ! This.HasDefaultValues()
RETURN
ENDIF

LOCAL ;
lcField,;
lcExpr,;
lcFieldState

*-------------------------------------
*--- Set all default values (if any)
*-------------------------------------
FOR lnCount = 1 TO ALEN(This.aDefaultValues,1)
lcField = This.aDefaultValues[lnCount,1]
lcExpr = This.aDefaultValues[lnCount,2]
REPLACE (lcField) WITH &lcExpr
ENDFOR
ENDPROC


*-- Does this business object have any default values defined?
PROCEDURE hasdefaultvalues
RETURN ! EMPTY(This.aDefaultValues[1,1])
ENDPROC


*-- Sets the default value field's state so they will be saved to the table
PROCEDURE setdefaultvaluestate
IF ! This.HasDefaultValues()
RETURN
ENDIF

LOCAL ;
llTableBuffered,;
liCount,;
lcField

llTableBuffered = INLIST(CURSORGETPROP('Buffering'),DB_BUFLOCKTABLE, DB_BUFOPTTABLE)

*-----------------------------------
*--- Set all default field states
*-----------------------------------
FOR liCount = 1 TO ALEN(This.aDefaultValues,1)
lcField = This.aDefaultValues[liCount,1]
IF llTableBuffered
SCAN
IF IsAdding(ALIAS())
This.SetFldState(lcField)
ENDIF
ENDSCAN
ELSE
IF IsAdding(ALIAS())
This.SetFldState(lcField)
ENDIF
ENDIF
ENDFOR
ENDPROC


*-- Sets the field state for the given field
PROCEDURE setfldstate
LPARAMETER tcField

LOCAL ;
lcFieldState,;
lcFieldStateD

lcFieldState = GETFLDSTATE(tcField)
lcFieldStateD = ;
IIF(INLIST(lcFieldState,2,4),lcFieldState,;
IIF(lcFieldState = 1,2,4))
SETFLDSTATE(tcField,lcFieldStateD)
ENDPROC
<\pre>

In the OnNew method, add a call to This.SetDetaultValues() before the following code:


IF NOT EMPTY(lcSaveDBC)
SET DATABASE TO (lcSaveDBC)
ENDIF
<\pre>


Let me know if you need anything else, or if you have any problems.

HTH

Rex


>Rex,
>
>This is an a simular issue I've been trying to solve. My situation is, I would like the user to see the default values on the form as they are regular defaults to make entry easier. The problem with the "Save Changes" when escaping, is still a problem for me, so I was exploring setting field state to 3 for the defaulted fields. This will cause the problem that the those fields don't update to the underlying table. I would like to use the defaults defined in the view (which I am already updating from the table using Eric's eView utility). I am also using Mere Mortals and would like to put the enhancement in the correct locations and not break anything in the process. Any suggestions on how I can accomplish this?
>
>Gary.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform