I am working on my first Alpha Five project and wanted to share some cool features I found. I am creating a grid for references and I need a certain amount of each type; Professional, Personal and Educational. I wanted to be able to do this on the front-end instead of telling the user that they had done something wrong through validation. Here is how I solved the problem.
In the OnInitialValueCalculate event I put the following code:
The code will fill out the type field with each of the selections in a disabled field for the user. BTW, getsql is a class I wrote to handle all of the SQL connection and retrieval.
Since I wanted to control how many records were generated, I put the following code in the OnGridExecute event:
This will not allow inserts once the user has three records created. The user can delete a record and the system will know what record was deleted and will be allow the user to insert a new record with the correct type.
Rod
In the OnInitialValueCalculate event I put the following code:
Code:
dim newsql as getsql dim result as SQL::resultset newsql.connect = "SIS" newsql.args.ADD("userid",2) newsql.sqlquery = "SELECT Sum( if( type = 'Professional' , 1, 0) ) AS professional, Sum( if( type = 'Educational' , 1, 0) ) AS educational, Sum( if( type = 'Personal' , 1, 0) ) AS personal FROM reference WHERE user_iduser = :userid" result = newsql.querySQL() SELECT CASE result.data("professional") < 1 e.newValues.type = "Professional" CASE result.data("educational") < 1 e.newValues.type = "Educational" CASE result.data("personal") < 1 e.newValues.type = "Personal" end SELECT
Since I wanted to control how many records were generated, I put the following code in the OnGridExecute event:
Code:
dim newsql as getsql local dim result as SQL::resultset local newsql.connect = "SIS" newsql.args.Add("userid",2) newsql.sqlquery = "SELECT COUNT(*) AS references FROM reference WHERE user_iduser = :userid" result = newsql.QuerySQL() if result.data("references") = 3 e.tmpl.DetailView.edit.allow_insert = .f. end if
Rod
Comment