Я надеюсь, что вы уже решили ... но если нет, я пересмотрел ваш пример, используя pubsub и adodbapi.
Я использовал мои mdb и adodbapi из-за логики с использованием OpendDataBase, и .movenext не работает в моей установке Python 2.7.
enter code here
import wx
from wx.lib.pubsub import Publisher
import win32com.client
import adodbapi
adodbapi.adodbapi.verbose = True
# adds details to the sample printout
class FinanceInfo(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
Publisher().subscribe(self.showFrame, ("show.mainframe"))
zbox = wx.BoxSizer(wx.VERTICAL)
self.Description = wx.TextCtrl(self, -1, style=wx.TE_READONLY|wx.TE_MULTILINE, size=(200,204))
zbox.Add(self.Description,0, wx.EXPAND,15)
self.SetSizer(zbox)
def showFrame(self, msg):
"""
Shows the frame and shows the message sent in the
text control
"""
self.Description.SetValue(msg.data)
class Frame(wx.Frame):
def __init__(self, *args, **kwargs):
super(Frame, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
#self.FinancePanelInfo = FinanceInfo(self)
panel = wx.Panel(self, -1)
box1 = wx.BoxSizer(wx.HORIZONTAL)
box2 = wx.BoxSizer(wx.HORIZONTAL)
box3 = wx.BoxSizer(wx.HORIZONTAL)
box4 = wx.BoxSizer(wx.HORIZONTAL)
box5 = wx.BoxSizer(wx.HORIZONTAL)
all_box = wx.BoxSizer(wx.VERTICAL)
overall = wx.BoxSizer(wx.HORIZONTAL)
nb = wx.Notebook(panel)
page2 = FinanceInfo(nb)
nb.AddPage(page2, "Finance Information")
first = wx.StaticText(panel, label="First Name: ")
last = wx.StaticText(panel, label="Last Name: ")
self.DATA = wx.ListBox(panel, style=wx.LB_SINGLE, size=(100,100))
self.Bind(wx.EVT_LISTBOX, self.OnSelection, id=self.DATA.GetId())
self.CLYa = wx.StaticText(panel, label="")
self.P2Da = wx.StaticText(panel, label="")
self.PLYa = wx.StaticText(panel, label="")
self.FN = wx.TextCtrl(panel, size=(75,-1))
self.LN = wx.TextCtrl(panel, size=(75,-1))
Search = wx.Button(panel, label="Search Patient")
self.Bind(wx.EVT_BUTTON, self.pulldata, id=Search.GetId())
Close = wx.Button(panel, label="Close Viewer")
self.Bind(wx.EVT_BUTTON, self.OnClose, id=Close.GetId())
box1.Add(first, 0, wx.ALL, 5)
box2.Add(last, 0, wx.ALL, 5)
box1.Add(self.FN, 1, wx.ALL, 5)
box2.Add(self.LN, 1, wx.ALL, 5)
box3.Add(self.DATA, 1 , wx.ALL, 5)
box4.Add(Search, 0, wx.ALL, 5)
box5.Add(Close, 0, wx.ALL, 5)
all_box.Add(box1, 0, wx.LEFT)
all_box.Add(box2, 0, wx.LEFT)
all_box.Add(wx.StaticLine(panel), 0, wx.ALL|wx.EXPAND, 5)
all_box.Add(box3, 0, wx.CENTER)
all_box.Add(box4, 0, wx.CENTER)
all_box.Add(box5, 0, wx.CENTER)
overall.Add(all_box,0,wx.EXPAND)
overall.Add(nb, 1, wx.EXPAND)
panel.SetSizer(overall)
self.SetSize((500, 275))
self.SetTitle("Maxident Historical Data Viewer")
self.Centre()
self.Show(True)
def OnClose(self, event):
quit()
def pulldata(self, event):
firstname = str(self.FN.GetValue())
lastname = str(self.LN.GetValue())
access = pullID(firstname.strip(), lastname.strip())
dat = ""
for rec in access:
a = str(rec[0])
b = str(rec[1])
#PID = str(access.Fields("Patient Number").value)
name = str(a + ":" + b)
print name
self.DATA.Insert(name, 0)
#access.MoveNext()
access.close
def OnSelection(self, event):
x = str(self.DATA.GetStringSelection())
y = x.split(":")
PID = y[0]
#PID = "Rossini Gianni"
dati = pullfinancedata(PID)
righe =""
for line in dati:
print line
riga = str(line)
righe = righe + riga + "\n"
Publisher().sendMessage(("show.mainframe"), righe)
def pullID(name, firstname):
#name = "ROSSINI GIANNI"
#DB = r"d:\coop&mie_doc\pdci\iscritti_2007.mdb"
# db = engine.OpenDatabase(DB)
# data_source = "D:\coop&mie_doc\pdci\iscritti_2007.mdb"
# mdw ="C:\Programmi\File comuni\System\System.mdw"
# DSN = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=%s;Jet OLEDB:System Database=%s;" % (data_source, mdw)
SQL_statement = "select [name], [address] from [tessere_2008] where [name] LIKE '" + name.upper() + "%'"
#SQL_statement = "select [name], [address] from [tessere_2008] "
#access = db.OpenRecordset(sql)
# access = engine.Open(sql,conAccess,1,3)
_databasename = "d:\coop&mie_doc\pdci\iscritti_2007.mdb"
_table_name= 'tessere_2008'
_username = ''
_password = ''
_mdw = "C:\Programmi\File comuni\System\System.mdw"
constr = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;User Id=%s;Password=%s;Jet OLEDB:System Database=%s;' % (_databasename, _username, _password, _mdw)
#constr = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Jet OLEDB:System Database=%s;' % (_databasename, _mdw)
conAccess = adodbapi.connect(constr)
accessdb = conAccess.cursor()
# accessdb = msaccess.AccessDb()
# connAccess = accessdb.connect("D:\coop&mie_doc\pdci\iscritti_2007.mdb", "Yram", "","C:\Programmi\File comuni\System\System.mdw")
print SQL_statement
accessdb.execute(SQL_statement)
print 'result rowcount shows as= %d. (Note: -1 means "not known")' \
% (accessdb.rowcount,)
# fields = access.getFields()
# print fields
# for item in access:
# print item
#get the results
access = accessdb.fetchmany(1)
#print them
for rec in access:
print rec
return accessdb
def pullfinancedata(PID):
print "pullfinancedata"
print PID
#DB = r"d:\coop&mie_doc\pdci\iscritti_2007.mdb"
#engine = win32com.client.Dispatch(r'ADODB.Recordset')
#db = engine.OpenDatabase(DB)
_databasename = "d:\coop&mie_doc\pdci\iscritti_2007.mdb"
_table_name= 'tessere_2008'
_username = ''
_password = ''
_mdw = "C:\Programmi\File comuni\System\System.mdw"
constr = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;User Id=%s;Password=%s;Jet OLEDB:System Database=%s;' % (_databasename, _username, _password, _mdw)
#constr = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Jet OLEDB:System Database=%s;' % (_databasename, _mdw)
conAccess = adodbapi.connect(constr)
accessdb = conAccess.cursor()
#SQL_statement = "select [name], [address] from [tessere_2008] where [name] LIKE '" + name.upper() + "%'"
SQL_statement = "select * from [Tesseramento] where [anagra_iscritto]='" + PID + "'"
#access = db.OpenRecordset(sql)
print SQL_statement
accessdb.execute(SQL_statement)
print 'result rowcount shows as= %d. (Note: -1 means "not known")' \
% (accessdb.rowcount,)
dat = ""
#while not access.EOF:
# PD = "Payment Date:\t" + str(access.Fields("Payment Date").value) + '\n'
# PM = "Payment Method:\t" + str(access.Fields("Payment Method").value) + '\n'
# PP = "Patient Payment:\t" + str(access.Fields("Patient Payment").value) + '\n'
# IP = "Insurance Payment:\t" + str(access.Fields("Insurance Payment").value) + '\n'
# dat = dat + PD + PM + PP + IP + "\n ------------------ \n"
# access.MoveNext()
"""
THIS IS WHERE I NEED HELP!
"""
#get the results
access = accessdb.fetchmany(accessdb.rowcount)
#print them
#for rec in access:
# print rec
"""
I need this dat variable to be passed to the FinanceInfo class and
i've tried FinanceInfo.Description.SetValue(dat) but its not working
"""
return access
def main():
ex = wx.App()
Frame(None)
ex.MainLoop()
if __name__ == '__main__':
main()