Post by Greg HillPost by Ken Mayer [dBVIPS]Greetings all ...
I have a form that has a rowset with a canSave event handler, which when
editing or adding rows appears to work properly.
However, because of the way this thing works, the user can click the 'X'
on the titlebar, and close the form in the middle of things, and somehow
manage to bypass the rowset's canSave event. Has anyone seen this before?
If so, what do you do to avoid it?
It's causing some problems for my client's app.
Like usual this is a fairly complex form, I couldn't post it because of
the myriad dependencies and I couldn't post the data (due to
confidentiality issues).
If I set the rowset's "modified" property to true in the form's canClose
event handler, the state property is showing as "1" ...
Argh. (I might be able to see this better if I were running on a
full-night's sleep, but I had a nasty bit of insomnia last night.)
Ken,
It has been working for me for a long time, on more than one form.
I use both the STATE and the MODIFIED to establish if something has been
if (this.parent.rowset.modified = true or (this.parent.rowset.state = 1 or
this.parent.rowset.state = 2))
nAns = msgbox('Save Changes?','Changes Were Made',35)
if nAns = 6
// Save routine
return class::Save_onclick()
elseif nAns = 7
form.yourQuery1.rowset.abandon()
return true
elseif nAns = 2
return false
endif
endif
return true
It sounds like the data is getting saved somewhere in the process of closing
before your cansave is processed.
But it would help to see your cansave routine, can you post it?
Yeah. I'm a bit flummoxed. Here's my canSave ... I thought I had all the
bases covered, but ...
function rowset_canSave
/*
This is a data check routine ...
First we do data validation, then
we check to see if we have a duplicate record.
The duplicate record is based on name, and phone
*/
local oForm
oForm = this.parent.parent
try
// Data Validation:
if this.state == 2 or this.state == 3
if empty( this.fields["DateEntered"].value )
msgbox( "Please make sure Date Entered is valid!",;
"Data Validation Error!", 16 )
// today's date
this.fields["DateEntered"].value := date()
oForm.DateEnteredDC.DateEntryfield.setFocus()
return false
endif // empty user ...
if empty( this.fields["Security"].value )
msgbox( "Please select your security code!",;
"Data Validation Error!", 16 )
oForm.SecurityCB.setFocus()
return false
endif // empty user ...
if empty( this.fields["TELEPHONE"].value )
msgbox( "Please enter customer Telephone Number!",;
"Data Validation Error!", 16 )
oForm.DataNB.curSel := 2 // page 2 of notebook
oForm.DataNB.PhoneEF.setFocus()
return false
endif // empty Telephone ...
endif // state == 3
// only check this when appending a new row:
if this.state == 3
// Duplicate Record:
local qTemp, rTemp, fTemp
qTemp = new query()
qTemp.database := oForm.MBI1
qTemp.sql := "select * from addressl"
qTemp.active := true
rTemp = qTemp.rowset
fTemp = rTemp.fields
rTemp.locateOptions := 1 // ignore length
// get values from record buffer
local bFound, cLName, cFName, cPhone, cAddress, cCity
cLName = this.fields["LAST"].value.rightTrim()
cFName = this.fields["FIRST"].value.rightTrim()
cPhone = this.fields["TELEPHONE"].value.rightTrim()
bFound = false
bFound = rTemp.applyLocate( [LAST=']+cLName+[' and ]+;
[FIRST=']+cFName+[' and ]+;
[TELEPHONE=']+cPhone+['] )
do while bFound
if bFound
cAddress = fTemp["Address"].value.rightTrim()
cCity = fTemp["Town"].value.rightTrim()
// ask user if this is really a duplicate?
if msgbox( "Name: "+cFName+" "+cLName+chr(13)+;
"Address: "+cAddress+chr(13)+;
"City: "+cCity+chr(13)+;
"Phone: "+cPhone+chr(13)+chr(13)+;
"Is this a duplicate record?",;
"Possible Duplicate!", 4+32 ) == 6
exit
endif
// if they said "No", then we need to try again:
bFound = rTemp.locateNext()
if not bFound
exit
endif
endif
enddo
// Let them know why we can't save it:
if bFound
msgbox( "Duplicate record found,"+chr(13)+;
"check data, and either"+chr(13)+;
"abandon, or ensure this"+chr(13)+;
"is a new customer.",;
"Duplicate Data", 16 )
return false
endif
endif // state = 3
// deal with saving values back to the various
// mailing lists -- because we are using the code as
// part of the value in the array, this should be
// easier than it might have been otherwise:
local cListValue, oNB
oNB = oForm.DataNB
// AList:
cListValue = oNB.AListCB.value
if not empty( cListValue )
// go to first space, should be 3 characters, but
// the code could be longer:
cListValue = left( cListValue, at( " ", cListValue ) - 1 )
endif
this.fields["ALIST"].value := cListValue
// BList:
cListValue = oNB.BListCB.value
if not empty( cListValue )
// go to first space, should be 3 characters, but
// the code could be longer:
cListValue = left( cListValue, at( " ", cListValue ) - 1 )
endif
this.fields["BLIST"].value := cListValue
// CList:
cListValue = oNB.CListCB.value
if not empty( cListValue )
// go to first space, should be 3 characters, but
// the code could be longer:
cListValue = left( cListValue, at( " ", cListValue ) - 1 )
endif
this.fields["CLIST"].value := cListValue
// DList:
cListValue = oNB.DListCB.value
if not empty( cListValue )
// go to first space, should be 3 characters, but
// the code could be longer:
cListValue = left( cListValue, at( " ", cListValue ) - 1 )
endif
this.fields["DLIST"].value := cListValue
// IList:
cListValue = oNB.IListCB.value
if not empty( cListValue )
// go to first space, should be 3 characters, but
// the code could be longer:
cListValue = left( cListValue, at( " ", cListValue ) - 1 )
endif
this.fields["ILIST"].value := cListValue
// CompList:
cListValue = oNB.CompListCB.value
if not empty( cListValue )
// go to first space, should be 3 characters, but
// the code could be longer:
cListValue = left( cListValue, at( " ", cListValue ) - 1 )
endif
this.fields["COMPLIST"].value := cListValue
// PPTList:
cListValue = oNB.PPTListCB.value
if not empty( cListValue )
// go to first space, should be 3 characters, but
// the code could be longer:
cListValue = left( cListValue, at( " ", cListValue ) - 1 )
endif
this.fields["PPTLIST"].value := cListValue
// User:
cListValue = oNB.UserCB.value
if not empty( cListValue )
// go to first space, should be 3 characters, but
// the code could be longer:
cListValue = left( cListValue, at( " ", cListValue ) - 1 )
endif
this.fields["USER"].value := cListValue
catch( exception e )
msgbox( "Error in canSave method:"+chr(13)+chr(13)+;
"Error: "+e.code+chr(13)+;
"Message: "+e.message+chr(13)+;
"Line: "+e.lineno,;
"Programmer Error!", 16 )
return false
endtry
return true
--
/(Opinions expressed are purely my own, not those of dataBased
Intelligence, Inc.)/
*Ken Mayer* [dBVIPS]
/Golden Stag Productions/
dBASE at goldenstag dot net
http://www.goldenstag.net/GSP
http://www.goldenstag.net/dbase/dBASEBooks.htm
http://www.goldenstag.net/dbase