-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow.py
More file actions
145 lines (130 loc) · 5.3 KB
/
show.py
File metadata and controls
145 lines (130 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import wx
import wx.grid
from connect import one_query
from frames import *
from helper_func import *
class Grid(GridFrame):
col_names=''
table_name=''
def delete(self, event):
wx.Yield()
i=get_input()
s='DELETE FROM '+self.table_name+' WHERE id = '+i
try:
one_query(s)
wx.MessageBox('删除完成','成功',wx.ICON_INFORMATION)
s = 'select '+','.join(self.col_names)+' from '+self.table_name+';'
data=one_query(s)
table = Table(head=self.col_names, body=data, changeable=True)
self.m_grid.SetTable(table=table, takeOwnership=True)
self.m_grid.AutoSize()
self.Layout()
except:
wx.MessageBox('数据有误,可能是有依赖项导致的,请重试','失败',wx.ICON_WARNING)
def add(self, event):
wx.Yield()
x=get_item(self.col_names).split(',')
col=[]
inp=[]
for i in range(len(self.col_names)):
if x[i].strip()!='':
col.append(self.col_names[i])
inp.append('"'+x[i]+'"')
s='INSERT INTO '+self.table_name+' ('+','.join(col)+') VALUES ('+','.join(inp)+');'
try:
one_query(s)
wx.MessageBox('添加完成','成功',wx.ICON_INFORMATION)
s = 'select '+','.join(self.col_names)+' from '+self.table_name+';'
data=one_query(s)
table = Table(head=self.col_names, body=data, changeable=True)
self.m_grid.SetTable(table=table, takeOwnership=True)
self.m_grid.AutoSize()
self.Layout()
except:
wx.MessageBox('数据有误,请重试','失败',wx.ICON_WARNING)
def mod(self, event):
wx.Yield()
i=get_input().strip()
s='SELECT * FROM '+self.table_name+' WHERE id= '+i+';'
# try:
col=self.col_names[:-1]
data=one_query(s)[0][:-1]
data=mod_item(col,data)
# print(data)
data=['"'+x.strip()+'"'for x in data.split(',')]
t=','.join([x+'='+y for x,y in zip(col,data)])
s='UPDATE '+self.table_name+' SET '+t+',add_time=CURRENT_TIMESTAMP WHERE id = '+i+';'
print(s)
one_query(s)
wx.MessageBox('修改完成','成功',wx.ICON_INFORMATION)
s = 'select '+','.join(self.col_names)+' from '+self.table_name+';'
data=one_query(s)
table = Table(head=self.col_names, body=data, changeable=True)
self.m_grid.SetTable(table=table, takeOwnership=True)
self.m_grid.AutoSize()
self.Layout()
# except:
# wx.MessageBox('数据有误,请重试','失败',wx.ICON_WARNING)
# def mod(self, event):
# wx.Yield()
# i=get_input()
# s='DELETE FROM '+self.table_name+' WHERE id = '+i
# try:
# one_query(s)
# wx.Yield()
# x=get_item(self.col_names).split(',')
# col=[]
# inp=[]
# for i in range(len(self.col_names)):
# if x[i].strip()!='':
# col.append(self.col_names[i])
# inp.append('"'+x[i]+'"')
# s='INSERT INTO '+self.table_name+' ('+','.join(col)+') VALUES ('+','.join(inp)+');'
# one_query(s)
# wx.MessageBox('修改完成','成功',wx.ICON_INFORMATION)
# s = 'select '+','.join(self.col_names)+' from '+self.table_name+';'
# data=one_query(s)
# table = Table(head=self.col_names, body=data, changeable=True)
# self.m_grid.SetTable(table=table, takeOwnership=True)
# self.m_grid.AutoSize()
# self.Layout()
# except:
# wx.MessageBox('无法修改,可能是有依赖项导致的,请重试','失败',wx.ICON_WARNING)
# return
# def CellChange(self, event):
# x,y = event.GetRow(),event.GetCol()
# val = self.m_grid.GetCellValue(x, y)
# if val == '':
# val = 'null'
# ColLabel = self.col_names[y]
# # self.data[x,0]
# ID_new = self.m_grid.GetCellValue(x,0)
# s = 'UPDATE ' + self.table_name + ' SET ' + ColLabel + ' = "' + val + '" WHERE id = "' + ID_new + '";'
# print(s)
# try:
# one_query(s)
# wx.MessageBox('修改完成','成功',wx.ICON_INFORMATION)
# s = 'select '+','.join(self.col_names)+' from '+self.table_name+';'
# data=one_query(s)
# table = Table(head=self.col_names, body=data, changeable=True)
# self.m_grid.SetTable(table=table, takeOwnership=True)
# self.m_grid.AutoSize()
# self.Layout()
# except:
# wx.MessageBox('数据有误,请重试','失败',wx.ICON_WARNING)
def show(col_names:tuple[str],table_name:str):
apps=wx.App()
frame=Grid(None)
frame.col_names=col_names
frame.table_name=table_name
s = 'SELECT '+','.join(col_names)+' FROM '+table_name+';'
data=one_query(s)
table = Table(head=col_names, body=data, changeable=True)
frame.m_grid.SetTable(table=table, takeOwnership=True)
frame.m_grid.AutoSize()
frame.Show()
apps.MainLoop()
if __name__ == '__main__':
col_names=('id','name','place_of_production','price','companyid','userid','add_time')
table_name='goods'
show(col_names,table_name)