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:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
|
#!/usr/bin/python
from Tkinter import *
import MySQLdb
# item entry form --------entry_item.py
## Connect to DB ***************************************
conn = MySQLdb.connect(host='localhost' , user='root', db='mind0')
##Create a cursor
curs = conn.cursor()
## *****************************************************
# Root level form
class MyApp:
def __init__(self):
window = Tk()
window.title('ITEM Entry Form')
frame = Frame(window)
frame.pack()
## BEGIN Fields ***********************************************
self.fields = {}
#-------------- Item ID
l = Label(frame, text="Item ID:")
l.grid(row=0, column=0)
self.fields['itemID'] = Entry(frame)
self.fields['itemID'].grid(row=0, column=1)
#-------------- Alias
l = Label(frame, text="Alias:")
l.grid(row=2, column=0) #was 30
self.fields['alias'] = Entry(frame)
self.fields['alias'].grid(row=2, column=1)
#-------------- Item Type ID => Listbox
l = Label(frame, text="Item Type ID:")
l.grid(row=4, column=0) #was 2
self.fields['fk_itemTypeID'] = Entry(frame)
self.fields['fk_itemTypeID'].grid(row=4, column=1)
#-------------- Manufacturer => Listbox
l = Label(frame, text="Manufacturer:")
l.grid(row=6, column=0)
self.fields['fk_mfactID'] = Entry(frame)
self.fields['fk_mfactID'].grid(row=6, column=1)
#-------------- Vendor Puchased From
l = Label(frame, text="Vendor Puchased From:")
l.grid(row=8, column=0)
self.fields['fk_vendID'] = Entry(frame)
self.fields['fk_vendID'].grid(row=8, column=1)
#-------------- Vendors Part Number:
l = Label(frame, text="Vendors Part Number:")
l.grid(row=10, column=0)
self.fields['itemPartNo'] = Entry(frame)
self.fields['itemPartNo'].grid(row=10, column=1)
#-------------- ModelNumber
l = Label(frame, text="ModelNumber: ")
l.grid(row=12, column=0)
self.fields['itemModelNo'] = Entry(frame)
self.fields['itemModelNo'].grid(row=12, column=1)
#-------------- Serial Number
l = Label(frame, text="Serial Number:")
l.grid(row=14, column=0)
self.fields['itemSerialNo'] = Entry(frame)
self.fields['itemSerialNo'].grid(row=14, column=1)
#-------------- Description
l = Label(frame, text="Description:")
l.grid(row=16, column=0)
self.fields['description'] = Entry(frame)
self.fields['description'].grid(row=16, column=1)
#-------------- Purchase Order No:
l = Label(frame, text="Purchase Order No:")
l.grid(row=18, column=0)
self.fields['fk_itemPONo'] = Entry(frame)
self.fields['fk_itemPONo'].grid(row=18, column=1)
#-------------- Item Cost:
l = Label(frame, text="Item Cost:")
l.grid(row=20, column=0)
self.fields['itemCost'] = Entry(frame)
self.fields['itemCost'].grid(row=20, column=1)
#-------------- Warranty Expiration
l = Label(frame, text="Warranty Expiration:")
l.grid(row=22, column=0)
self.fields['itemWarrExp'] = Entry(frame)
self.fields['itemWarrExp'].grid(row=22, column=1)
#-------------- Last user assigned => Listbox
l = Label(frame, text="Last user assigned:")
l.grid(row=24, column=0)
self.fields['fk_lastUserID'] = Entry(frame)
self.fields['fk_lastUserID'].grid(row=24, column=1)
#-------------- User Assigned => Listbox
l = Label(frame, text="User Assigned:")
l.grid(row=28, column=0)
self.fields['fk_userID'] = Entry(frame)
self.fields['fk_userID'].grid(row=28, column=1)
#-------------- Ready to issue? (Checkbutton)
#checkbutton ready? YesNo
l = Label(frame, text="Ready to issue?:")
l.grid(row=30, column=0)
var = IntVar()
self.fields['ready'] = Checkbutton(frame,variable=var, text='Select if YES')
self.fields['ready'].var = var
self.fields['ready'].grid(row=30, column=1)
#-------------- Issued to user => Checkbutton
l = Label(frame, text="Issued to user?:")
l.grid(row=32, column=0)
var = IntVar()
self.fields['issued'] = Checkbutton(frame,variable=var, text='Select if YES')
self.fields['issued'].var = var
self.fields['issued'].grid(row=32, column=1)
#-------------- LoanedLoaned => Checkbutton
l = Label(frame, text="Loaned?:")
l.grid(row=34, column=0)
var = IntVar()
self.fields['loaned'] = Checkbutton(frame,variable=var, text='Select if YES')
self.fields['loaned'].var = var
self.fields['loaned'].grid(row=34, column=1)
#To BE CHANGED TO RADIOBUTTON
#-------------- Item Location
l = Label(frame, text="Item location?:")
l.grid(row=36, column=0)
var = IntVar()
self.fields['fk_locID'] = Radiobutton(frame, text="Orlando", variable=var, value=1).pack(anchor=W).grid(row=34, column=1)
self.fields['fk_locID'] = Radiobutton(frame, text="Tampa", variable=var, value=2).pack(anchor=W).grid(row=34, column=2)
self.fields['fk_locID'] = Radiobutton(frame, text="Wtr Hvn", variable=var, value=3).pack(anchor=W).grid(row=34, column=3)
#self.fields['fk_locID'].grid(row=34, column=1)
###############################
#-------------- Comment
l = Label(frame, text="Comment:")
l.grid(row=38, column=0)
self.fields['comment'] = Entry(frame)
self.fields['comment'].grid(row=38, column=1)
## END Fields ************************************************
## BEGIN Buttons ########
submitbtn = Button(frame, text="Insert", command=self.do_insert)
submitbtn.grid(row=300, column=0)
#..........
clearbtn = Button(frame, text="Clear", command=self.do_clear)
clearbtn.grid(row=300, column=1)
## END Buttons ##########
window.mainloop()
## Insert and Clear functions
def do_clear(self):
self.fields['itemID'].delete(0,END)
self.fields['fk_itemTypeID'].delete(0,END)
self.fields['fk_mfactID'].delete(0,END)
self.fields['itemModelNo'].delete(0,END)
self.fields['description'].delete(0,END)
self.fields['fk_lastUserID'].delete(0,END)
self.fields['ready'].var.set(0)
self.fields['itemPartNo'].delete(0,END)
self.fields['itemSerialNo'].delete(0,END)
self.fields['fk_itemPONo'].delete(0,END)
self.fields['itemCost'].delete(0,END)
self.fields['itemWarrExp'].delete(0,END)
self.fields['fk_userID'].delete(0,END)
self.fields['loaned'].var.set(0)
self.fields['comment'].delete(0,END)
self.fields['alias'].delete(0,END)
self.fields['fk_vendID'].delete(0,END)
self.fields['fk_locID'].var.set(0) # #To BE CHANGED TO RADIOBUTTON
self.fields['issued'].var.set(0)
def do_insert(self):
global curs
sql = "insert into item (itemID,alias,fk_itemTypeID,fk_mfactID,fk_vendID,itemPartNo,itemModelNo,itemSerialNo,description,fk_itemPONo,itemCost,itemWarrExp,fk_lastUserID,fk_userID,ready,issued,loaned,fk_locID,comment) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');"%(
self.fields['itemID'].get(),
self.fields['alias'].get(),
self.fields['fk_itemTypeID'].get(),
self.fields['fk_mfactID'].get(),
self.fields['fk_vendID'].get(),
self.fields['itemPartNo'].get(),
self.fields['itemModelNo'].get(),
self.fields['itemSerialNo'].get(),
self.fields['description'].get(),
self.fields['fk_itemPONo'].get(),
self.fields['itemCost'].get(),
self.fields['itemWarrExp'].get(),
self.fields['fk_lastUserID'].get(),
self.fields['fk_userID'].get(),
self.fields['ready'].var.get(),
self.fields['issued'].var.get(),
self.fields['loaned'].var.get(),
self.fields['fk_locID'].var.get(), #To BE CHANGED TO RADIOBUTTON
self.fields['comment'].get())
curs.execute(sql)
conn.commit()
print sql
if __name__=="__main__":
MyApp()
|