On Sunday 25 February 2007 13:00, Ken Dibble wrote:
> Platform: Win
> Python Version: 2.4.4 on win32
> Dabo Version: Version 0.8a; Revision
> UI Version: 2.6.3.3 on wxMSW
>
> Form has a dTextBox, regID = "keyBox", a dButton, and another dTextBox,
> regID = "thisBand".
>
>
Please read all the notes/ comments! This works on windows and Linux. It
does not mean it will work with a simple copy and paste. You have to make it
meet your needs. For example I'm using Postgres with schemas.
I created a table "musbands" with the following fields
CREATE TABLE musbands
(
bandname character varying(25),
musictype character varying(20),
pkid serial NOT NULL,
CONSTRAINT pkey PRIMARY KEY (pkid)
The primary key is named "pkid". The type "serial" is a auto increment
integer. I believe MySQL has something similar.
I populated the table with:
pkid bandname musictype
1 guns+roses rock
2 Police rock
3 lonestar country
Next I created a form (cdxml file) from the ClassDesigner that contained
three labels along with associated textboxes to display the data retrieved.
Next add a textbox for input with an RegID = keyBox
Then added a button. The button's onHit function is noted below.
Please note 'public' is my schema name for Postgres.
### Dabo Class Designer code. You many freely edit the code,
### but do not change the comments containing:
### 'Dabo Code ID: XXXX',
### as these are needed to link the code to the objects.
## *!* ## Dabo Code ID: dButton-dForm
def onHit(self, evt):
"""This is the code that runs when I click on the button" """
# the self.Form.keyBox.Value contain what the user typed
findPK = self.Form.keyBox.Value
#Since I only have one business object I'm not required to pass the
table
name
# but could have said myBizObj = self.Form.getBizobj("public.musbands")
# Note: the onHit function does not know about the business object
created
# in the "class PublicmusbandsBizobj"
myBizObj =self.Form.getBizobj()
#I could just set the complete SQL statement
#myBizObj.UserSQL = ("select * from musbands where pkid = %s" %
(findPK,))
# better yet avoid the use of the "findPK" variable
#myBizObj.UserSQL = ("select * from musbands where pkid = %s" %
(self.Form.keyBox.Value,))
# or I can set the where clause. Since you were setting the where
clause
I'll do the same
myBizObj.setWhereClause("pkid = "+findPK)
#OK I want to clean up the textbox value
self.Form.keyBox.Value = ''
# now I want to set the focus back to the textbox
self.Form.keyBox.setFocus()
# OK I now need to tell the form to requery - this will also refresh
the
display.
self.Form.requery()
## *!* ## Dabo Code ID: dForm-top
def createBizobjs(self):
"""Below is the business object created by the ClassDesigner. In your
case
you would remove the word 'public' because it refers to the schema in a
Postgres database."""
class PublicmusbandsBizobj(dabo.biz.dBizobj):
def afterInit(self):
self.DataSource = "public.musbands"
self.KeyField = "pkid"
self.addFrom("public.musbands")
self.addField("pkid")
self.addField("musictype")
self.addField("bandname")
def validateRecord(self):
"""Returning anything other than an empty string from
this method will prevent the data from being saved.
"""
ret = ""
# Add your business rules here.
return ret
publicmusbandsBizobj = PublicmusbandsBizobj(self.Connection)
self.addBizobj(publicmusbandsBizobj)
--
John Fabiani
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users