This is the part of the original mail which is missing in the mail archive.

johnf wrote:
> -- snip --
> 
> Below I have created a small application.  I hate the UI in this example.  So 
> would some kind reader post a better UI.  The code creates a one to many 
> relation between a customer table and the customer contacts table.  I have 
> added several buttons and extra lines to create the child relation and we 
> will go over that code in the next installment.  So far all we have done is 
> discuss the connection and added a bizObject to our code.  Next time we will 
> discuss what steps I took to create the child relation and what Dabo provides 
> to help the developer pass SQL statements to the database engine.
> 
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
> import os
> import sys
> import dabo
> import dabo.dEvents as dEvents
> import dabo.dException as dException
> dabo.ui.loadUI('wx')
> #the contact table
> class PubliccontactsBizobj(dabo.biz.dBizobj):
>       def afterInit(self):
>               self.DataSource = "public.contacts"
>               self.KeyField = "pkid"
>               self.addFrom("public.contacts")
>               self.addField("firstname")
>               self.addField("phone")
>               self.addField("pkid")
>               self.addField("lastname")
>               self.addField("title")
>               self.addField("custno")
>               self.addField("continent")
>               self.addField("email")
>               self.addField("cont_note")
>               self.addField("fk_arcust")
>               self.NonUpdateFields=["pkid"]
>               self.LinkField = "fk_arcust"
>               self.ParentLinkField ="pkid"
>               self.FillLinkFromParent = True
> 
>       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
> 
> 
> 
> 
> #the customer table
> class PublicarcustBizobj(dabo.biz.dBizobj):
>       def afterInit(self):
>               self.DataSource = "public.arcustomer"
>               self.addFrom("public.arcustomer")
>               self.KeyField = "pkid"
>               self.addField("czip")
>               self.addField("city")
>               self.addField("pkid")
>               self.addField("state")
>               self.addField("company")
>               self.addField("address1")
>               self.addField("address2")
>               self.addField("country")
>               self.addField("custno")
> 
> 
> 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
> 
> class CustomerPanel(dabo.ui.dPanel):
>       def afterInit(self):
>               self.Sizer=vs=dabo.ui.dSizer('h')
>               gs = dabo.ui.dGridSizer(MaxCols=4,HGap=3, VGap=3)
>               gs.append(dabo.ui.dLabel(self, Caption="Cust #"), 
> halign="right")
>               gs.append(dabo.ui.dTextBox(self, 
> RegID="txtCustomerID",TextLength = 
> 10,DataSource ="public.arcustomer", DataField = "custno"), "expand", 
> colSpan=3)
>               gs.append(dabo.ui.dLabel(self, Caption="Address"), 
> halign="right")
>               gs.append(dabo.ui.dTextBox(self, RegID="txtAddress1",TextLength 
> = 
> 35,DataSource ="public.arcustomer", DataField = "address1"), "expand", 
> colSpan=3)
>               gs.append(dabo.ui.dLabel(self, Caption=""), halign="right")
>               gs.append(dabo.ui.dTextBox(self, RegID="txtAddress2",TextLength 
> = 
> 35,DataSource ="public.arcustomert", DataField = "address2"), "expand", 
> colSpan=3)
>               gs.append(dabo.ui.dLabel(self, Caption="City"), halign="right")
>               gs.append(dabo.ui.dTextBox(self, RegID="txtCity",DataSource 
> ="public.arcustomer", DataField = "city"), "expand", colSpan=3)
>               gs.append(dabo.ui.dLabel(self, Caption="Country"), 
> halign="right")
>               gs.append(dabo.ui.dTextBox(self, RegID="txtCountry1",DataSource 
> ="public.arcust", DataField = "country"), "expand", colSpan=3)
>               gs.append(dabo.ui.dLabel(self, Caption="State"), halign="right")
>               gs.append(dabo.ui.dTextBox(self, 
> RegID="txtSateID",ForceCase='upper',TextLength=2,DataSource 
> ="public.arcustomer", DataField = "state"))
>               gs.append(dabo.ui.dLabel(self, Caption="Zip"), halign="right")
>               gs.append(dabo.ui.dTextBox(self, 
> RegID="txtZipD",TextLength=10,DataSource 
> ="public.arcustomer", DataField = "czip"), "expand")
>               vs.append(gs,0,'x')
>       
> 
> class ContactsPanel(dabo.ui.dPanel):
>       def afterInit(self):
>               self.Sizer = dabo.ui.dSizer("v")
>               hs=dabo.ui.dSizer("h")
>               contactGrid = 
> dabo.ui.dGrid(self,RegID="contgridID",AlternateRowColoring 
> =True,ColumnCount=6,SelectionMode = "Row",Editable = True,MovableColumns = 
> False)
>               
> #self.contactGrid.bindEvent(dabo.dEvents.GridCellSelected,self.onGridCellSelected)
>               contactGrid.DataSource = "public.contacts"
>               contactGrid.Columns[0].Caption ="Title"
>               contactGrid.Columns[0].DataField = "title"
>               contactGrid.Columns[1].Caption ="First"
>               contactGrid.Columns[1].DataField = "firstname"
>               contactGrid.Columns[2].Caption ="Last"
>               contactGrid.Columns[2].DataField = "lastname"
>               contactGrid.Columns[3].Caption ="Email"
>               contactGrid.Columns[3].DataField = "email"
>               contactGrid.Columns[4].Caption ="Phone"
>               contactGrid.Columns[4].DataField = "phone"
>               contactGrid.Columns[5].Caption ="Continent"
>               contactGrid.Columns[5].DataField = "continent"
>               hs.append(contactGrid,1,'x')
>               self.Sizer.append(hs,1,'x')
> 
> 
> class MainForm(dabo.ui.dForm):
>       def afterInit(self):
>               self.Sizer=vs=dabo.ui.dSizer('v')
>               custPanel=CustomerPanel(self)
>               vs.append(custPanel,1,'x')
>               vs.appendSpacer(8)
>               hs= dabo.ui.dSizer('h')
>               hs.append(dabo.ui.dButton(self, 
> Caption="First",OnHit=self.first),0)
>               hs.append(dabo.ui.dButton(self, 
> Caption="Next",OnHit=self.next),0)
>               hs.append(dabo.ui.dButton(self, 
> Caption="Prior",OnHit=self.prior),0)     
>               hs.append(dabo.ui.dButton(self, 
> Caption="Last",OnHit=self.last),0)
>               vs.append(hs)
>               vs.appendSpacer(8)
>               contPanel=ContactsPanel(self)
>               vs.append(contPanel,2,'x')
>               self.layout()
>               self. requery()
>               
>               
>       def first(self,evt):
>               self.super()
>       
>       def next(self,evt):
>               self.super()
>               
>       def prior(self,evt):
>               self.super()
>               
>       def last(self,evt):
>               self.super()
>               
>       def createBizobjs(self):
>               self.Application.addConnectFile("tutorial.cnxml")
>               self.Connection = 
> self.Application.getConnectionByName("tutorial")
>               
>               publicarcustBizobj = PublicarcustBizobj(self.Connection)
>               self.addBizobj(publicarcustBizobj)   
>               
>               publiccontactsBizobj = PubliccontactsBizobj(self.Connection)
>               self.addBizobj(publiccontactsBizobj)
>               publicarcustBizobj.addChild(publiccontactsBizobj)
>               
>               
> if __name__ == "__main__":
>       app = dabo.dApp()
>       app.BasePrefKey = "bizObjTutor"
>       app.setAppInfo("appName", "bizObject Tutorial ")
>       app.MainFormClass = MainForm
>       app.start()
> 
> As always if I have errors point them out.  Better yet provide the fix.



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to