CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 Event Raising Issues with Codecharge

Print topic Send  topic

Author Message
marcwolf


Posts: 361
Posted: 02/05/2004, 5:59 PM

Help.

I have found that CCS does not trap the results of a raised event, and need to find out how to do that without breking the standard code that CCS generates

i.e. BeforeExecuteInsert

we do a check to see if there is a existing record or something liek that.

There is

We do a

form.errors.adderror "Duplicate Record"
form_beforeexecuteinsert = false
exit function

However I can check that the CCSventResult is False, however CCS does not act on this and preven further processing of the cmd.exec

How can we trap this.

It would be more descriptive if you 'Funtions' were listed as 'Subs' as it is only the onvalidate that uses the return ccsresult

Dave
_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
View profile  Send private message
peterr


Posts: 5971
Posted: 02/05/2004, 6:10 PM

I'm not sure why you need to trap the results of an event. What should happen with those results?

Based on your code sample looks like you're trying to validate something? If so, please use OnValidate event:
http://docs.codecharge.com/studio/html/ProgrammingTechn...Validation.html
http://docs.codecharge.com/studio/html/ProgrammingTechn...Validation.html

_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
marcwolf


Posts: 361
Posted: 02/05/2004, 6:33 PM

We are trying to stop the insertion of duplicate records where the uniqueness is based on several fields at once

Setting Unique on an individual control will not work as it only checks on ONE field.

Setting OnValidate on an individual control will not work as we can only check the value of other controls on that row and that does NOT include what is in the Grid collection i.e. row 1 is the same as row 5


Seting OnValidate on the Grid won't work as we cannot get access to individual row values.

The only real place we can do this check is just before the Update or Insert of the record as all the other records are now in the DB, however if there is a duplicate we can either let ODBC come up with an error - bad for the end users, or trap and stop the process.

Your code - if you were to trap the events would look like THIS for an insert...

 CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeExecuteInsert", Me)  
if   CCSEventResult then    Cmd.Exec(Errors)  
        CCSEventResult = CCRaiseEvent(CCSEvents, "AfterExecuteInsert", Me)  

I am loking at using the BeforeExecuteInsert to set the underlying Insert's CMD object CommandOperation property to someing strange and thus catching it with clscommand Exec process.

Any input?





_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
View profile  Send private message
peterr


Posts: 5971
Posted: 02/05/2004, 10:24 PM

Thanks for explaining. I was looking at the Record form as I didn't know you were working with a Grid.

Regarding the solution, I'm not sure if simply changing the code in one place would solve the issue as it would be an exception - we don't use such method in other places. Of course it might be a valid request to do this for all Events :-) Then there also may be a question what should happen whenever any other event fails? And if we utilize your solution then could this be easily made compatible with our generated .NET and Java? Or maybe we should create an additional event or a run-time property for the BeforeExecuteInsert event.
Therefore it's important that we can diagnose the patient before prescribing the pills. Now I understand your problem better and I can discuss it with our engineering.
In the meantime you may want to alter the generated code the way you like, at least until we find a better solution. You may also want to submit this to our support as an issue - you may even get a patch before any changes are fully implemented and officially released (if we find the need to do so).

_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
marcwolf


Posts: 361
Posted: 02/06/2004, 2:39 AM

Hi Peter

I have found a solution and its an intersting one - might help some of the readers.

Now - looking at both the Insert and the Update of the Grid's datasource I noticed that you were passing in the clsCommand instance, and also further investigation found that you were transferring the content of the grid row to the grid's controls before each update/insert.

So.. I did this with a Grid that had 2 controls text1, text2 - NOTE THIS IS PSUEDO CODE

  
Grid1_beforeExecuteInsert  
  
  dim  iRec  
  iRec = ccdlookup( "count(*)", "table", "txt1 = " & text1.value & " and txt2 = " & text2.value)  
  If iRec > 0 then  
    ' all your checking etc here  
     Grid1.Command.CommandOperation = 99  
    Session("errors") = Session("Errors") & "Text1 is duplicated"  
 end if  
    
End Function  

Whats is happening.
Ok - clsComman has an Exec function that uses a Select Case to work out the type of command passed by the CommandOperation

By Setting the CommandOperation to somethng that Exec cannot use - will skip the actual execution process and return no errors from clsCommand because the errors raiser has not been run.

Any use of the Errors collection will cause this process to fail - however one can use the Session("Errors") to display the list of problem on the Grid's BeforeShow event.

Its messy I know - but it will allow row by row validation on the Insert, and the Update (simplar code) before the actual record is placed into the DB, and also allow a graceful exit without saving the record for that row.

Took some fun to work out - but this is the level that I and our team is taking apart the generated code to work ut what is happening.

P.S. have a real nice fix for the dreaded Server time/Client Tme issues when the server is out of the country, can let you know the details is your interested.


_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
View profile  Send private message
peterr


Posts: 5971
Posted: 02/06/2004, 3:44 PM

Looks good. And whatever you were able to implement via Events, vs. modifying the main code, is "clean enough" :-)

Looks like we will be planning to add some new property to handle similar situations. Again - the key for us is it know what the problem is, not the solution. Unless the solution comes with an explanation of what problem it solves.

Thanks
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.