標籤:style os io 資料 for 問題 cti 時間
曾經做過的一個Python小程式,讀取ACCESS資料庫,然後list資料
# -*- coding: cp936 -*-
import wx
import wx.lib
import sys,glob,random
import win32com.client
reload(sys)
sys.setdefaultencoding(‘utf-8‘)
class DemoFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,u"安全檢查",size=(800,600))
def adddate():
conn = win32com.client.Dispatch(r‘ADODB.Connection‘)
DSN = ‘PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=yb.mdb;‘
conn.Open(DSN)
rs = win32com.client.Dispatch(r‘ADODB.Recordset‘)
rs_name =‘aqjc‘
rs.Open(‘[‘+rs_name+‘]‘,conn,1,3)
if rs.recordcount==0:
sys.exit()
self.list.InsertColumn(0,u‘備忘‘,format=wx.LIST_FORMAT_CENTRE, width=-1)
self.list.InsertColumn(0,u‘發現問題‘,format=wx.LIST_FORMAT_CENTRE, width=-1)
self.list.InsertColumn(0,u‘時段‘,format=wx.LIST_FORMAT_CENTRE, width=-1)
self.list.InsertColumn(0,u‘時間‘,format=wx.LIST_FORMAT_CENTRE, width=-1)
self.list.InsertColumn(0,u‘崗位‘,format=wx.LIST_FORMAT_CENTRE, width=-1)
self.list.InsertColumn(0,u‘日期‘,format=wx.LIST_FORMAT_CENTRE, width=-1)
self.list.InsertColumn(0,u‘id‘,format=wx.LIST_FORMAT_CENTRE, width=-1)
while not rs.EOF:
index = self.list.InsertStringItem(sys.maxint,str(rs.Fields.Item(0).value))
self.list.SetStringItem(index,1,str(rs.Fields.Item(1).value))
self.list.SetStringItem(index,2,str(rs.Fields.Item(2).value).decode(‘utf-8‘).encode(‘gbk‘))
self.list.SetStringItem(index,3,str(rs.Fields.Item(3).value).decode(‘utf-8‘).encode(‘gbk‘))
self.list.SetStringItem(index,4,str(rs.Fields.Item(4).value))
self.list.SetStringItem(index,5,str(rs.Fields.Item(5).value).decode(‘utf-8‘).encode(‘gbk‘))
self.list.SetStringItem(index,6,str(rs.Fields.Item(6).value).decode(‘utf-8‘).encode(‘gbk‘))
rs.MoveNext()
rs.Close()
conn.Close()
hbox = wx.BoxSizer(wx.HORIZONTAL)
panel = wx.Panel(self,-1)
self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT,size=(800,600))
self.list.SetSingleStyle(wx.LC_REPORT|wx.LC_HRULES|wx.LC_VRULES,True,)
hbox.Add(self.list,1,1)
panel.SetSizer(hbox)
self.Centre()
adddate()
app = wx.PySimpleApp()
frame = DemoFrame()
frame.Show()
app.MainLoop()