嗨,我的代码有问题,当在 onbutton 方法中 n 将数字 100 或更少作为参数时,它工作得很好。但是当数字超过 100 时,我的电脑死机并最终崩溃。我需要简化我的代码,并希望它以任何方式工作。有什么建议么?我知道我的代码中有一些 sql 选择,但不要注意它们只是将它们视为数字和文本,在第一次选择中它给出了我想要创建的静态文本的数量,在第二次选择中它需要我的内容想填。
import wx
import pyodbc
cnxn = pyodbc.connect("DRIVER={SQL Server Native Client 11.0};SERVER=10.75.79.215;DATABASE=HUB_DATA;UID=sa;PWD=password")
cursor = cnxn.cursor()
########################################################################
class RandomPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent, color):
"""Constructor"""
wx.Panel.__init__(self, parent)
self.SetBackgroundColour(color)
class scroll(wx.ScrolledWindow):
def __init__(self, parent, color):
wx.ScrolledWindow.__init__(self, parent)
self.SetBackgroundColour(color)
self.SetScrollbars(4,4,5000,5000)
########################################################################
class MainPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
topSplitter = wx.SplitterWindow(self)
hSplitter = wx.SplitterWindow(topSplitter)
panelOne = RandomPanel(hSplitter, "white")
panelTwo = RandomPanel(hSplitter, "white")
hSplitter.SplitVertically(panelOne, panelTwo)
hSplitter.SetSashGravity(0.5)
self.panelThree = scroll(topSplitter, "white")
topSplitter.SplitHorizontally(hSplitter, self.panelThree)
topSplitter.SetSashGravity(0.5)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(topSplitter, 1, wx.EXPAND)
self.SetSizer(sizer)
txtOne = wx.StaticText(panelOne, -1, label = "piradoba", pos = (20,10))
self.txtTwo = wx.StaticText(panelOne, -1, label = "", pos = (40,80))
self.txtplace = wx.TextCtrl(panelOne, pos = (20,30))
button = wx.Button(panelOne, label = "search", pos = (40,100))
button.Bind(wx.EVT_BUTTON, self.Onbutton)
self.ctrls1 = []
self.ctrls2 = []
self.ctrls3 = []
self.ctrls4 = []
self.ctrls5 = []
self.ctrls6 = []
self.ctrls7 = []
self.ctrls8 = []
self.ctrls9 = []
self.ctrls10 = []
self.ctrls11 = []
self.ctrls12 = []
self.ctrls13 = []
self.ctrls14 = []
def Onbutton(self, event):
var=self.txtplace.GetValue()
if len(var) == 9 or len(var) == 11:
self.txtTwo.SetLabel("True")
cursor.execute("""SELECT COUNT(DPVLDT) as raodenoba
FROM [HBGE_Reports].[dbo].[hub_DDJPFile] s
where exists (SELECT [ZGDCS]
FROM [HUB_DATA].[dbo].[SSCUSTP] d
where [ZGIDNO]=?
and
s.DPACS=d.ZGDCS)""",str(var))
raw = cursor.fetchone()
n = raw.raodenoba
for i in range(n):
self.ctrls1.append(wx.StaticText(self.panelThree, label = '', pos = (20, 30 * i)))
self.ctrls2.append(wx.StaticText(self.panelThree, label = '', pos = (120, 30 * i)))
self.ctrls3.append(wx.StaticText(self.panelThree, label = '', pos = (220, 30 * i)))
self.ctrls4.append(wx.StaticText(self.panelThree, label = '', pos = (320, 30 * i)))
self.ctrls5.append(wx.StaticText(self.panelThree, label = '', pos = (420, 30 * i)))
self.ctrls6.append(wx.StaticText(self.panelThree, label = '', pos = (520, 30 * i)))
self.ctrls7.append(wx.StaticText(self.panelThree, label = '', pos = (620, 30 * i)))
self.ctrls8.append(wx.StaticText(self.panelThree, label = '', pos = (720, 30 * i)))
self.ctrls9.append(wx.StaticText(self.panelThree, label = '', pos = (820, 30 * i)))
self.ctrls10.append(wx.StaticText(self.panelThree, label = '', pos = (920, 30 * i)))
self.ctrls11.append(wx.StaticText(self.panelThree, label = '', pos = (1020, 30 * i),size=(10,10)))
self.ctrls12.append(wx.StaticText(self.panelThree, label = '', pos = (1220, 30 * i),size=(50,100)))
self.ctrls13.append(wx.StaticText(self.panelThree, label = '', pos = (1420, 30 * i),size=(50,100)))
self.ctrls14.append(wx.StaticText(self.panelThree, label = '', pos = (1620, 30 * i),size=(50,100)))
cursor.execute("""declare @a varchar(20)
set @a=?
SELECT [DPVLDT]
,[DPCPDT]
,[DPACB]
,[DPACS]
,[DPACX]
,[DPCYCD]
,[DPDLCD]
,[RCY_AMOUNT]
,[LCY_AMOUNT]
,[DPBLBL]
,[DPNAR1]
,[DPNAR2]
,[DPNAR3]
,[DPNAR4]
FROM [HBGE_Reports].[dbo].[hub_DDJPFile] s
where exists (SELECT [ZGDCS]
FROM [HUB_DATA].[dbo].[SSCUSTP] d
where [ZGIDNO]=@a
and
s.DPACS=d.ZGDCS)
order by [DPVLDT] desc""", str(var))
rows = cursor.fetchall()
for i in range(n):
self.ctrls1[i].SetLabel(str(rows[i].DPVLDT))
self.ctrls2[i].SetLabel(str(rows[i].DPCPDT))
self.ctrls3[i].SetLabel(str(rows[i].DPACB))
self.ctrls4[i].SetLabel(str(rows[i].DPACS))
self.ctrls5[i].SetLabel(str(rows[i].DPACX))
self.ctrls6[i].SetLabel(str(rows[i].DPCYCD))
self.ctrls7[i].SetLabel(str(rows[i].DPDLCD))
self.ctrls8[i].SetLabel(str(rows[i].RCY_AMOUNT))
self.ctrls9[i].SetLabel(str(rows[i].LCY_AMOUNT))
self.ctrls10[i].SetLabel(str(rows[i].DPBLBL))
self.ctrls11[i].SetLabel(str(rows[i].DPNAR1))
self.ctrls12[i].SetLabel(str(rows[i].DPNAR2))
self.ctrls13[i].SetLabel(str(rows[i].DPNAR3))
self.ctrls14[i].SetLabel(str(rows[i].DPNAR4))
########################################################################
class MainFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="test",
size=(800,600))
panel = MainPanel(self)
self.Show()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
app.MainLoop()