Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.87 KB | None | 0 0
  1. pyinstaller -w programname.py -F
  2.  
  3. # Copy and Paste Buttons BEGIN Here
  4.  
  5. def cut(self):
  6. self.clipboard_clear()
  7. self.clipboard_append(self.outline.focus_get().get())
  8. self.outline.focus_get().delete(0, END)
  9.  
  10. def copy(self):
  11. self.clipboard_clear()
  12. self.clipboard_append(self.outline.focus_get().get())
  13.  
  14. def paste(self):
  15. text = self.clipboard_get()
  16. self.outline.focus_get().insert(0, text)
  17.  
  18. def delete(self):
  19. self.outline.focus_get().delete(0, END)
  20.  
  21. def popup(self, event):
  22. event.widget.focus() # This moves the focus to the entry field you right click in.
  23. self.aMenu.post(event.x_root, event.y_root)
  24.  
  25. # Copy and Paste Buttons END Here
  26.  
  27. # For copy button
  28. self.aMenu = tk.Menu(self, tearoff=0)
  29. self.aMenu.add_command(label='Cut', command=self.cut)
  30. self.aMenu.add_command(label='Copy', command=self.copy)
  31. self.aMenu.add_command(label='Paste', command=self.paste)
  32. self.aMenu.add_command(label='Delete', command=self.delete)
  33.  
  34. import os
  35. import pypyodbc
  36. from tkinter import BOTH, END, LEFT
  37. from tkinter import ttk
  38. import tkinter as tk
  39.  
  40.  
  41. class Adder(ttk.Frame):
  42. """The adders gui and functions."""
  43. def __init__(self, parent, *args, **kwargs):
  44. ttk.Frame.__init__(self, parent, *args, **kwargs)
  45. self.root = parent
  46. self.init_gui()
  47.  
  48. # Copy and Paste Buttons BEGIN Here
  49.  
  50. def cut(self):
  51. self.clipboard_clear()
  52. self.clipboard_append(self.outline.focus_get().get())
  53. self.outline.focus_get().delete(0, END)
  54.  
  55. def copy(self):
  56. self.clipboard_clear()
  57. self.clipboard_append(self.outline.focus_get().get())
  58.  
  59. def paste(self):
  60. text = self.clipboard_get()
  61. self.outline.focus_get().insert(0, text)
  62.  
  63. def delete(self):
  64. self.outline.focus_get().delete(0, END)
  65.  
  66. def popup(self, event):
  67. event.widget.focus() # This moves the focus to the entry field you right click in.
  68. self.aMenu.post(event.x_root, event.y_root)
  69.  
  70. # Copy and Paste Buttons END Here
  71.  
  72. def on_help(self):
  73. answer = messagebox.showinfo("Info will go here.")
  74.  
  75. def on_quit(self):
  76. """Exits program."""
  77. root.quit()
  78.  
  79. def authenticate(self):
  80. return pypyodbc.connect('Driver={SQL Server};Server=srv201;Database=IDPXIDp;Trusted_Connection=yes;')
  81.  
  82. def calculate(self):
  83. firstname = str(self.first_entry.get())
  84. lastname = str(self.last_entry.get())
  85. license = str(self.lic_entry.get())
  86. if (firstname and not lastname and not license): # "You entered first name."
  87. try:
  88. connection = self.authenticate()
  89. except pypyodbc.Error as ex:
  90. sqlstate = ex.args[0]
  91. if sqlstate == '28000':
  92. self.output0.delete(0, END)
  93. self.output0.insert(0,"You do not have access.")
  94. cursor = connection.cursor()
  95. SQLCommand = ("SELECT LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
  96. "FROM dbo.V_MYTABLE_IT " # table name
  97. "with (nolock)"
  98. "WHERE FIRSTNAME = ?")
  99. Values = [firstname]
  100. cursor.execute(SQLCommand,Values)
  101. results = cursor.fetchmany(10)
  102. if results:
  103. self.output0.delete(0, END)
  104. self.output0.insert(0,results[0])
  105.  
  106. connection.close()
  107. else:
  108. self.output0.delete(0, END)
  109. self.output0.insert(0,"That name does not exist.")
  110.  
  111. elif len(firstname) == 0 and len(license) == 0: # "You entered last name."
  112. try:
  113. connection = pypyodbc.connect('Driver={SQL Server};Server=srv201;Database=IDPXIDp;Trusted_Connection=yes;')
  114. except pypyodbc.Error as ex:
  115. sqlstate = ex.args[0]
  116. if sqlstate == '28000':
  117. self.output0.delete(0, END)
  118. self.output0.insert(0,"You do not have access.")
  119. cursor = connection.cursor()
  120. SQLCommand = ("SELECT LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
  121. "FROM dbo.V_MYTABLE_IT " # table name
  122. "with (nolock)"
  123. "WHERE LASTNAME = ?")
  124. Values = [lastname]
  125. cursor.execute(SQLCommand,Values)
  126. results = cursor.fetchmany(10)
  127. if results:
  128. self.output0.delete(0, END)
  129. self.output0.insert(0,results[0])
  130.  
  131. connection.close()
  132. else:
  133. self.output0.delete(0, END)
  134. self.output0.insert(0,"That name does not exist.")
  135.  
  136. elif len(firstname) == 0 and len(lastname) == 0: # "You entered license."
  137. try:
  138. connection = pypyodbc.connect('Driver={SQL Server};Server=srv201;Database=IDPXIDp;Trusted_Connection=yes;')
  139. except pypyodbc.Error as ex:
  140. sqlstate = ex.args[0]
  141. if sqlstate == '28000':
  142. self.output0.delete(0, END)
  143. self.output0.insert(0,"You do not have access.")
  144. cursor = connection.cursor()
  145. SQLCommand = ("SELECT LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
  146. "FROM dbo.V_MYTABLE_IT " # table name
  147. "with (nolock)"
  148. "WHERE L_LICNUMBER = ?")
  149. Values = [license]
  150. cursor.execute(SQLCommand,Values)
  151. results = cursor.fetchmany(10)
  152. if results:
  153. self.output0.delete(0, END)
  154. self.output0.insert(0,results[0])
  155.  
  156. connection.close()
  157. else:
  158. self.output0.delete(0, END)
  159. self.output0.insert(0,"That license does not exist.")
  160.  
  161. elif (not firstname and not lastname and not license): # "You entered first name."
  162. try:
  163. connection = self.authenticate()
  164. except pypyodbc.Error as ex:
  165. sqlstate = ex.args[0]
  166. if sqlstate == '28000':
  167. self.output0.delete(0, END)
  168. self.output0.insert(0,"You do not have access.")
  169. cursor = connection.cursor()
  170. SQLCommand = ("SELECT LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
  171. "FROM dbo.V_MYTABLE_IT " # table name
  172. "with (nolock)"
  173. "WHERE FIRSTNAME = ?")
  174. Values = [firstname]
  175. cursor.execute(SQLCommand,Values)
  176. results = cursor.fetchmany(10)
  177. if results:
  178. self.output0.delete(0, END)
  179. self.output0.insert(0,"No data entered")
  180.  
  181. connection.close()
  182.  
  183. elif len(lastname) == 0: # "You entered first name and license."
  184. try:
  185. connection = pypyodbc.connect('Driver={SQL Server};Server=srv201;Database=IDPXIDp;Trusted_Connection=yes;')
  186. except pypyodbc.Error as ex:
  187. sqlstate = ex.args[0]
  188. if sqlstate == '28000':
  189. self.output0.delete(0, END)
  190. self.output0.insert(0,"You do not have access.")
  191. cursor = connection.cursor()
  192. SQLCommand = ("SELECT LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
  193. "FROM dbo.V_MYTABLE_IT " # table name
  194. "with (nolock)"
  195. "WHERE FIRSTNAME = ? AND L_LICNUMBER = ?")
  196. Values = [firstname, license] # make a list for user inputs
  197. cursor.execute(SQLCommand,Values)
  198. results = cursor.fetchmany(10)
  199. if results:
  200. self.output0.delete(0, END)
  201. self.output0.insert(0,results[0])
  202.  
  203. connection.close()
  204. else:
  205. self.output0.delete(0, END)
  206. self.output0['text'] = "That combination does not exist."
  207.  
  208. elif len(firstname) == 0: # "You entered last name and license."
  209. try:
  210. connection = pypyodbc.connect('Driver={SQL Server};Server=srv201;Database=IDPXIDp;Trusted_Connection=yes;')
  211. except pypyodbc.Error as ex:
  212. sqlstate = ex.args[0]
  213. if sqlstate == '28000':
  214. self.output0.delete(0, END)
  215. self.output0.insert(0,"You do not have access.")
  216. cursor = connection.cursor()
  217. SQLCommand = ("SELECT LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
  218. "FROM dbo.V_MYTABLE_IT " # table name
  219. "with (nolock)"
  220. "WHERE LASTNAME = ? AND L_LICNUMBER = ?")
  221. Values = [lastname, license]
  222. cursor.execute(SQLCommand,Values)
  223. results = cursor.fetchmany(10)
  224.  
  225. if results:
  226. self.output0.delete(0, END)
  227. self.output0.insert(0,results[0])
  228.  
  229. connection.close()
  230. else:
  231. self.output0.delete(0, END)
  232. self.output0.insert(0,"That combination does not exist.")
  233.  
  234. elif len(license) == 0: # "You entered first name and last name."
  235. try:
  236. connection = pypyodbc.connect('Driver={SQL Server};Server=srv201;Database=IDPXIDp;Trusted_Connection=yes;')
  237. except pypyodbc.Error as ex:
  238. sqlstate = ex.args[0]
  239. if sqlstate == '28000':
  240. self.output0.delete(0, END)
  241. self.output0.insert(0,"You do not have access.")
  242. cursor = connection.cursor()
  243. SQLCommand = ("SELECT LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
  244. "FROM dbo.V_MYTABLE_IT " # table name
  245. "with (nolock)"
  246. "WHERE FIRSTNAME = ? AND LASTNAME = ?")
  247. Values = [firstname, lastname]
  248. cursor.execute(SQLCommand,Values)
  249. results = cursor.fetchmany(10)
  250. if results:
  251. self.output0.delete(0, END)
  252. self.output0.insert(0,results[0])
  253.  
  254. connection.close()
  255. else:
  256. self.output0.delete(0, END)
  257. self.output0.insert(0,"That combination does not exist.")
  258. else:
  259. firstname = str(self.first_entry.get())
  260. lastname = str(self.last_entry.get())
  261. license = str(self.lic_entry.get())
  262. try:
  263. connection = pypyodbc.connect('Driver={SQL Server};Server=srv201;Database=IDPXIDp;Trusted_Connection=yes;')
  264. except pypyodbc.Error as ex:
  265. sqlstate = ex.args[0]
  266. if sqlstate == '28000':
  267. self.answer_label['text'] = "You do not have access."
  268. cursor = connection.cursor()
  269. SQLCommand = ("SELECT TOP (10) LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
  270. "FROM dbo.V_MYTABLE_IT " # table name
  271. "(nolock)"
  272. "WHERE FIRSTNAME = ? AND LASTNAME = ? AND L_LICNUMBER = ?")
  273. Values = [firstname, lastname, license]
  274. cursor.execute(SQLCommand,Values)
  275. results = cursor.fetchmany(10)
  276. if results:
  277. self.output0.delete(0, END)
  278. self.output0.insert(0,results[0])
  279.  
  280. connection.close()
  281. else:
  282. self.output0.delete(0, END)
  283. self.output0.insert(0,"That combination does not exist.")
  284.  
  285. def init_gui(self):
  286. """Builds GUI."""
  287. self.root.title('Verify')
  288. self.root.option_add('*tearOff', 'FALSE')
  289.  
  290. self.grid(column=0, row=0, sticky='nsew') # this starts the entire form
  291.  
  292. self.menubar = tk.Menu(self.root)
  293.  
  294. self.menu_file = tk.Menu(self.menubar)
  295. self.menu_file.add_command(label='About', command=self.on_help)
  296. self.menu_file.add_command(label='Exit', command=self.on_quit)
  297.  
  298. self.menu_edit = tk.Menu(self.menubar)
  299.  
  300. self.menubar.add_cascade(menu=self.menu_file, label='File')
  301. # self.menubar.add_cascade(menu=self.menu_edit, label='Help') # add other menu options
  302.  
  303. self.root.config(menu=self.menubar)
  304.  
  305. self.outline = tk.LabelFrame(self, height=80, width=900) # border frame
  306. self.outline.grid(column=0, row=1, columnspan=5, padx=5, ipady=10, pady=5)
  307.  
  308. # Text Labels
  309.  
  310. self.labelframespace = tk.Frame(self, height=0, width=100) # provides spacing BEFORE labels
  311. self.labelframespace.grid(column=0, row=1, columnspan=1)
  312.  
  313. self.first = tk.Label(self, text='FirstName:')
  314. self.first.grid(column=1, row=1, sticky='nw', padx=10, pady=20)
  315.  
  316. self.last = ttk.Label(self, text='LastName:')
  317. self.last.grid(column=2, row=1, sticky='nw', padx=10, pady=20)
  318.  
  319. self.lic = ttk.Label(self, text='License:')
  320. self.lic.grid(column=3, row=1, sticky='nw', padx=10, pady=20)
  321.  
  322. self.labelframespace = tk.Frame(self, height=0, width=50) # provides spacing AFTER labels
  323. self.labelframespace.grid(column=4, row=1, columnspan=1)
  324.  
  325. self.labelframespace = tk.Frame(self, height=0, width=200) # provides spacing AFTER labels
  326. self.labelframespace.grid(column=4, row=1, columnspan=1)
  327.  
  328. # Input Boxes and Button
  329.  
  330. self.first_entry = tk.Entry(self, width=28) # first input box
  331. self.first_entry.grid(sticky='', column=1, row=1)
  332. self.first_entry.bind("<Button-3>", self.popup)
  333.  
  334. self.last_entry = tk.Entry(self, width=28) # second input box
  335. self.last_entry.grid(sticky='', column=2, row=1)
  336. self.last_entry.bind("<Button-3>", self.popup)
  337.  
  338. self.lic_entry = tk.Entry(self, width=28) # third input box
  339. self.lic_entry.grid(sticky='', column=3, row=1)
  340. self.lic_entry.bind("<Button-3>", self.popup)
  341.  
  342. self.framespace = tk.Frame(self, height=5, width=896, bg='#E0E0E0') # provides spacing between input boxes and answer box
  343. self.framespace.grid(row=4, columnspan=5)
  344.  
  345. self.calc_button = ttk.Button(self, text='Search', command=self.calculate) # button
  346. self.calc_button.grid(column=4, row=1, columnspan=1, sticky='w', padx=14)
  347. self.calc_button.bind('<Return>', lambda e: self.calculate())
  348.  
  349. # For copy button
  350. self.aMenu = tk.Menu(self, tearoff=0)
  351. self.aMenu.add_command(label='Cut', command=self.cut)
  352. self.aMenu.add_command(label='Copy', command=self.copy)
  353. self.aMenu.add_command(label='Paste', command=self.paste)
  354. self.aMenu.add_command(label='Delete', command=self.delete)
  355.  
  356. # Output frame for answer
  357. self.entries = []
  358. self.output0 = tk.Entry(self, width=149, justify='center', bd='0', bg='#E0E0E0')
  359. self.output0.grid(column=0, row=6, columnspan=5, padx=1)
  360. self.output0.bind("<Button-3>", self.popup)
  361. self.entries.append(self.output0) # makes the answer not display multiple times on the same line
  362.  
  363. self.blank = tk.LabelFrame(self, height=5, bd=0,) # blank line
  364. self.blank.grid(row=16,)
  365.  
  366. if __name__ == '__main__':
  367. root = tk.Tk()
  368. Adder(root)
  369. root.resizable(width=False, height=False) # locks window from being resized
  370. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement