| 1 |
drop table arcustomer; |
|---|
| 2 |
CREATE TABLE arcustomer |
|---|
| 3 |
(custno character varying(15) NOT NULL, |
|---|
| 4 |
company character varying(35), |
|---|
| 5 |
address1 character varying(35), |
|---|
| 6 |
address2 character varying(35), |
|---|
| 7 |
city character varying(35), |
|---|
| 8 |
state character varying(2), |
|---|
| 9 |
country character varying(60), |
|---|
| 10 |
czip character varying(10), |
|---|
| 11 |
pkid serial NOT NULL, |
|---|
| 12 |
CONSTRAINT pk_arcust PRIMARY KEY (pkid), |
|---|
| 13 |
CONSTRAINT arcustno UNIQUE (custno) |
|---|
| 14 |
) |
|---|
| 15 |
WITHOUT OIDS; |
|---|
| 16 |
ALTER TABLE arcustomer OWNER TO johnf; |
|---|
| 17 |
GRANT ALL ON TABLE arcustomer TO johnf; |
|---|
| 18 |
|
|---|
| 19 |
DROP TABLE contacts; |
|---|
| 20 |
|
|---|
| 21 |
CREATE TABLE contacts |
|---|
| 22 |
( |
|---|
| 23 |
custno character varying(15) NOT NULL, |
|---|
| 24 |
firstname character varying(20), |
|---|
| 25 |
lastname character varying(35), |
|---|
| 26 |
title character varying(20), |
|---|
| 27 |
phone character varying(15), |
|---|
| 28 |
email character varying(40), |
|---|
| 29 |
continent character varying(35), |
|---|
| 30 |
cont_note text, |
|---|
| 31 |
pkid serial NOT NULL, |
|---|
| 32 |
fk_arcust integer, |
|---|
| 33 |
CONSTRAINT pk_contact PRIMARY KEY (pkid) |
|---|
| 34 |
) |
|---|
| 35 |
|
|---|
| 36 |
WITHOUT OIDS; |
|---|
| 37 |
ALTER TABLE contacts OWNER TO johnf; |
|---|
| 38 |
GRANT ALL ON TABLE contacts TO johnf; |
|---|
| 39 |
|
|---|
| 40 |
insert into arcustomer (custno,company,address1,address2,city,state,country,czip) |
|---|
| 41 |
values('AAA','AAA company', '123 Main St.','','Wooland','CA','USA','95776'); |
|---|
| 42 |
insert into arcustomer (custno,company,address1,address2,city,state,country,czip) |
|---|
| 43 |
values('BBB','BBB company', '123 East St.','Apt 2','Wooland','CA','USA','95776'); |
|---|
| 44 |
insert into arcustomer (custno,company,address1,address2,city,state,country,czip) |
|---|
| 45 |
values('CCC','CCC company', '123 Walker St.','','Wooland','CA','USA','95776'); |
|---|
| 46 |
|
|---|
| 47 |
insert into contacts (custno,firstname,lastname,title,phone,email,continent,fk_arcust) |
|---|
| 48 |
values('AAA', 'Ed', 'Leafe', 'Mr.', '','ed@leafe.com','North America',1); |
|---|
| 49 |
insert into contacts (custno,firstname,lastname,title,phone,email,continent,fk_arcust) |
|---|
| 50 |
values('BBB', 'Paul', 'McNet', 'Mr.', '','p@ulmcnett.com','North America',2); |
|---|
| 51 |
insert into contacts (custno,firstname,lastname,title,phone,email,continent,fk_arcust) |
|---|
| 52 |
values('CCC', 'Larry', 'Long', 'Mr.', '','lalong@charter.net','North America',3); |
|---|
| 53 |
|
|---|
| 54 |
#!/usr/bin/env python |
|---|
| 55 |
# -*- coding: utf-8 -*- |
|---|
| 56 |
import os |
|---|
| 57 |
import sys |
|---|
| 58 |
import dabo |
|---|
| 59 |
import dabo.dEvents as dEvents |
|---|
| 60 |
import dabo.dException as dException |
|---|
| 61 |
dabo.ui.loadUI('wx') |
|---|
| 62 |
#the contact table |
|---|
| 63 |
class PubliccontactsBizobj(dabo.biz.dBizobj): |
|---|
| 64 |
def afterInit(self): |
|---|
| 65 |
self.DataSource = "public.contacts" |
|---|
| 66 |
self.KeyField = "pkid" |
|---|
| 67 |
self.addFrom("public.contacts") |
|---|
| 68 |
self.addField("firstname") |
|---|
| 69 |
self.addField("phone") |
|---|
| 70 |
self.addField("pkid") |
|---|
| 71 |
self.addField("lastname") |
|---|
| 72 |
self.addField("title") |
|---|
| 73 |
self.addField("custno") |
|---|
| 74 |
self.addField("continent") |
|---|
| 75 |
self.addField("email") |
|---|
| 76 |
self.addField("cont_note") |
|---|
| 77 |
self.addField("fk_arcust") |
|---|
| 78 |
self.NonUpdateFields=["pkid"] |
|---|
| 79 |
self.LinkField = "fk_arcust" |
|---|
| 80 |
self.ParentLinkField ="pkid" |
|---|
| 81 |
self.FillLinkFromParent = True |
|---|
| 82 |
|
|---|
| 83 |
def validateRecord(self): |
|---|
| 84 |
"""Returning anything other than an empty string from |
|---|
| 85 |
this method will prevent the data from being saved. |
|---|
| 86 |
""" |
|---|
| 87 |
ret = "" |
|---|
| 88 |
# Add your business rules here. |
|---|
| 89 |
return ret |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
#the customer table |
|---|
| 95 |
class PublicarcustBizobj(dabo.biz.dBizobj): |
|---|
| 96 |
def afterInit(self): |
|---|
| 97 |
self.DataSource = "public.arcustomer" |
|---|
| 98 |
self.addFrom("public.arcustomer") |
|---|
| 99 |
self.KeyField = "pkid" |
|---|
| 100 |
self.addField("czip") |
|---|
| 101 |
self.addField("city") |
|---|
| 102 |
self.addField("pkid") |
|---|
| 103 |
self.addField("state") |
|---|
| 104 |
self.addField("company") |
|---|
| 105 |
self.addField("address1") |
|---|
| 106 |
self.addField("address2") |
|---|
| 107 |
self.addField("country") |
|---|
| 108 |
self.addField("custno") |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
def validateRecord(self): |
|---|
| 112 |
"""Returning anything other than an empty string from |
|---|
| 113 |
this method will prevent the data from being saved. |
|---|
| 114 |
""" |
|---|
| 115 |
ret = "" |
|---|
| 116 |
# Add your business rules here. |
|---|
| 117 |
return ret |
|---|
| 118 |
|
|---|
| 119 |
class CustomerPanel(dabo.ui.dPanel): |
|---|
| 120 |
def afterInit(self): |
|---|
| 121 |
self.Sizer=vs=dabo.ui.dSizer('h') |
|---|
| 122 |
gs = dabo.ui.dGridSizer(MaxCols=4,HGap=3, VGap=3) |
|---|
| 123 |
gs.append(dabo.ui.dLabel(self, Caption="Cust #"), halign="right") |
|---|
| 124 |
gs.append(dabo.ui.dTextBox(self, RegID="txtCustomerID",TextLength = 10,DataSource ="public.arcustomer", DataField = "custno"), "expand", colSpan=3) |
|---|
| 125 |
gs.append(dabo.ui.dLabel(self, Caption="Address"), halign="right") |
|---|
| 126 |
gs.append(dabo.ui.dTextBox(self, RegID="txtAddress1",TextLength = 35,DataSource ="public.arcustomer", DataField = "address1"), "expand", colSpan=3) |
|---|
| 127 |
gs.append(dabo.ui.dLabel(self, Caption=""), halign="right") |
|---|
| 128 |
gs.append(dabo.ui.dTextBox(self, RegID="txtAddress2",TextLength = 35,DataSource ="public.arcustomert", DataField = "address2"), "expand", colSpan=3) |
|---|
| 129 |
gs.append(dabo.ui.dLabel(self, Caption="City"), halign="right") |
|---|
| 130 |
gs.append(dabo.ui.dTextBox(self, RegID="txtCity",DataSource ="public.arcustomer", DataField = "city"), "expand", colSpan=3) |
|---|
| 131 |
gs.append(dabo.ui.dLabel(self, Caption="Country"), halign="right") |
|---|
| 132 |
gs.append(dabo.ui.dTextBox(self, RegID="txtCountry1",DataSource ="public.arcust", DataField = "country"), "expand", colSpan=3) |
|---|
| 133 |
gs.append(dabo.ui.dLabel(self, Caption="State"), halign="right") |
|---|
| 134 |
gs.append(dabo.ui.dTextBox(self, RegID="txtSateID",ForceCase='upper',TextLength=2,DataSource ="public.arcustomer", DataField = "state")) |
|---|
| 135 |
gs.append(dabo.ui.dLabel(self, Caption="Zip"), halign="right") |
|---|
| 136 |
gs.append(dabo.ui.dTextBox(self, RegID="txtZipD",TextLength=10,DataSource ="public.arcustomer", DataField = "czip"), "expand") |
|---|
| 137 |
vs.append(gs,0,'x') |
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
class ContactsPanel(dabo.ui.dPanel): |
|---|
| 141 |
def afterInit(self): |
|---|
| 142 |
self.Sizer = dabo.ui.dSizer("v") |
|---|
| 143 |
hs=dabo.ui.dSizer("h") |
|---|
| 144 |
contactGrid = dabo.ui.dGrid(self,RegID="contgridID",AlternateRowColoring =True,ColumnCount=6,SelectionMode = "Row",Editable = True,MovableColumns = False) |
|---|
| 145 |
#self.contactGrid.bindEvent(dabo.dEvents.GridCellSelected,self.onGridCellSelected) |
|---|
| 146 |
contactGrid.DataSource = "public.contacts" |
|---|
| 147 |
contactGrid.Columns[0].Caption ="Title" |
|---|
| 148 |
contactGrid.Columns[0].DataField = "title" |
|---|
| 149 |
contactGrid.Columns[1].Caption ="First" |
|---|
| 150 |
contactGrid.Columns[1].DataField = "firstname" |
|---|
| 151 |
contactGrid.Columns[2].Caption ="Last" |
|---|
| 152 |
contactGrid.Columns[2].DataField = "lastname" |
|---|
| 153 |
contactGrid.Columns[3].Caption ="Email" |
|---|
| 154 |
contactGrid.Columns[3].DataField = "email" |
|---|
| 155 |
contactGrid.Columns[4].Caption ="Phone" |
|---|
| 156 |
contactGrid.Columns[4].DataField = "phone" |
|---|
| 157 |
contactGrid.Columns[5].Caption ="Continent" |
|---|
| 158 |
contactGrid.Columns[5].DataField = "continent" |
|---|
| 159 |
hs.append(contactGrid,1,'x') |
|---|
| 160 |
self.Sizer.append(hs,1,'x') |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
class MainForm(dabo.ui.dForm): |
|---|
| 164 |
def afterInit(self): |
|---|
| 165 |
self.Sizer=vs=dabo.ui.dSizer('v') |
|---|
| 166 |
custPanel=CustomerPanel(self) |
|---|
| 167 |
vs.append(custPanel,1,'x') |
|---|
| 168 |
vs.appendSpacer(8) |
|---|
| 169 |
hs= dabo.ui.dSizer('h') |
|---|
| 170 |
hs.append(dabo.ui.dButton(self, Caption="First",OnHit=self.first),0) |
|---|
| 171 |
hs.append(dabo.ui.dButton(self, Caption="Next",OnHit=self.next),0) |
|---|
| 172 |
hs.append(dabo.ui.dButton(self, Caption="Prior",OnHit=self.prior),0) |
|---|
| 173 |
hs.append(dabo.ui.dButton(self, Caption="Last",OnHit=self.last),0) |
|---|
| 174 |
vs.append(hs) |
|---|
| 175 |
vs.appendSpacer(8) |
|---|
| 176 |
contPanel=ContactsPanel(self) |
|---|
| 177 |
vs.append(contPanel,2,'x') |
|---|
| 178 |
vs.append(dabo.ui.dEditBox(self,DataSource="public.contacts",DataField="cont_note"),0,'x') |
|---|
| 179 |
vs.append(dabo.ui.dButton(self,Caption="Save", OnHit=self.save),0,'x') |
|---|
| 180 |
self.layout() |
|---|
| 181 |
self. requery() |
|---|
| 182 |
|
|---|
| 183 |
def save(self,evt): |
|---|
| 184 |
self.super(dataSource="public.contacts") |
|---|
| 185 |
|
|---|
| 186 |
def first(self,evt): |
|---|
| 187 |
self.super() |
|---|
| 188 |
|
|---|
| 189 |
def next(self,evt): |
|---|
| 190 |
self.super() |
|---|
| 191 |
|
|---|
| 192 |
def prior(self,evt): |
|---|
| 193 |
self.super() |
|---|
| 194 |
|
|---|
| 195 |
def last(self,evt): |
|---|
| 196 |
self.super() |
|---|
| 197 |
|
|---|
| 198 |
def createBizobjs(self): |
|---|
| 199 |
self.Application.addConnectFile("tutorial.cnxml") |
|---|
| 200 |
self.Connection = self.Application.getConnectionByName("tutorial") |
|---|
| 201 |
|
|---|
| 202 |
publicarcustBizobj = PublicarcustBizobj(self.Connection) |
|---|
| 203 |
self.addBizobj(publicarcustBizobj) |
|---|
| 204 |
|
|---|
| 205 |
publiccontactsBizobj = PubliccontactsBizobj(self.Connection) |
|---|
| 206 |
self.addBizobj(publiccontactsBizobj) |
|---|
| 207 |
publicarcustBizobj.addChild(publiccontactsBizobj) |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
if __name__ == "__main__": |
|---|
| 211 |
app = dabo.dApp() |
|---|
| 212 |
app.BasePrefKey = "bizObjTutor" |
|---|
| 213 |
app.setAppInfo("appName", "bizObject Tutorial ") |
|---|
| 214 |
app.MainFormClass = MainForm |
|---|
| 215 |
app.start() |
|---|