Guest User

Untitled

a guest
Oct 29th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.61 KB | None | 0 0
  1. import tkinter
  2. import tkinter as tk # python 3
  3. from tkinter import font as tkfont, Entry, END # python 3
  4. # import Tkinter as tk # python 2
  5. # import tkFont as tkfont # python 2
  6. from tkinter import messagebox
  7. import Employee
  8. import pymysql.cursors
  9. from pymysql.connections import Connection
  10.  
  11.  
  12. class GUI(tk.Tk):
  13. def __init__(self, *args):
  14. tk.Tk.__init__(self, *args)
  15. self.shared_data = {
  16. "first_name": tk.StringVar(),
  17. "last_name": tk.StringVar(),
  18. "age": tk.StringVar(),
  19. "address": tk.StringVar(),
  20. "day_of_birth": tk.StringVar(),
  21. "month_of_birth": tk.StringVar(),
  22. "year_of_birth": tk.StringVar(),
  23. "health_care": tk.StringVar(),
  24. "health_care_id": tk.StringVar(),
  25. "employee_id": tk.StringVar(),
  26. "married": tk.StringVar(),
  27. "hInsurance": tk.StringVar(),
  28. "dInsurance": tk.StringVar(),
  29. "oInsurance": tk.StringVar(),
  30. "hTier": tk.StringVar(),
  31. "four01k": tk.StringVar(),
  32. "kContribution": tk.StringVar(),
  33. "pension": tk.StringVar(),
  34. "unionDues": tk.StringVar(),
  35. "payType": tk.StringVar(),
  36. "payAmount": tk.StringVar(),
  37. }
  38.  
  39. tk.Tk.wm_title(self, "Payroll Application")
  40.  
  41. #Creation of all the relevant Frames
  42.  
  43. container = tk.Frame(self)
  44. container.pack(side="top", fill="both", expand=True)
  45. container.grid_rowconfigure(200, weight=1)
  46. container.grid_columnconfigure(200, weight=1)
  47.  
  48. self.frames = {}
  49.  
  50. for F in (LoginPage, mainMenuPage, addEmpFrame, addEmpFrame1, addEmpFrame2, removeEmpFrame, EmpLookupFrame,
  51. calcPayRollFrame):
  52. frame = F(container, self)
  53. self.frames[F] = frame
  54. frame.grid(row=0, column=0, sticky="nsew")
  55.  
  56. self.raise_frame(LoginPage)
  57.  
  58. #Frame manipulation functions
  59.  
  60. def raise_frame(self, page_name):
  61. frame = self.frames[page_name]
  62. frame.tkraise()
  63.  
  64. def update_frame(self, page_name):
  65. frame = self.frames[page_name]
  66. frame.update()
  67.  
  68. def destroy_frame(self, page_name):
  69. frame = self.frames[page_name]
  70. frame.destroy()
  71.  
  72. #Frame Designs
  73. #Each frame written in a class format
  74.  
  75. class LoginPage(tk.Frame): #Login page Frame
  76. def __init__(self, parent, controller):
  77. tk.Frame.__init__(self, parent)
  78.  
  79. self.label_username = tk.Label(self, text="Username")
  80. self.label_password = tk.Label(self, text="Password")
  81.  
  82. self.entry_username = tk.Entry(self)
  83. self.entry_password = tk.Entry(self, show="*")
  84.  
  85. self.label_username.grid(row=0, column=0)
  86. self.label_password.grid(row=1, column=0)
  87. self.entry_username.grid(row=0, column=1)
  88. self.entry_password.grid(row=1, column=1)
  89.  
  90. self.checkbox = tk.Checkbutton(self, text="Keep me logged in")
  91. self.checkbox.grid(columnspan=2)
  92.  
  93. self.loginButton = tk.Button(self, text="Login", command=lambda: controller.raise_frame(self.submitLogin()))
  94. self.loginButton.grid(columnspan=2)
  95.  
  96. def submitLogin(self):
  97. l = self.entry_username.get()
  98. p = self.entry_password.get()
  99. attempt = Employee.Login(l, p)
  100. attempt.databaseSearchId(attempt.get_temp_id())
  101. if (attempt.check_login() == 1):
  102. return mainMenuPage
  103. elif (attempt.check_login() == 0):
  104. return LoginPage
  105.  
  106.  
  107. class mainMenuPage(tk.Frame): #Main Menu Frame, consists of the main navigation page, List box
  108. def __init__(self, parent, controller):
  109. tk.Frame.__init__(self, parent)
  110.  
  111. self.controller = controller
  112. self.row = []
  113.  
  114.  
  115. self.scrollbar = tk.Scrollbar(self)
  116. self.scrollbar.grid(row = 2, column= 2)
  117.  
  118. connection: Connection = pymysql.connect(host='localhost',
  119. port=3306,
  120. user='root',
  121. password='root',
  122. db='hrdb')
  123. cursorObject = connection.cursor()
  124. cursorObject.execute('SELECT `firstName`,`lastName` from `employeeprofile`')
  125. numrows = int(cursorObject.rowcount)
  126. for x in range(0, numrows):
  127. self.row.append(cursorObject.fetchone())
  128.  
  129. self.list1 = tk.Listbox(self, height=10, width=35)
  130. for x in self.row:
  131. self.list1.insert(END, x)
  132. self.list1.grid(row=2, column=0, columnspan=2)
  133.  
  134. self.scrollbar.config(command=self.list1.yview)
  135.  
  136. self.label = tk.Label(self, text="Search employee by typing his/her last name:")
  137. self.label.grid(row=0, column=1)
  138.  
  139. self.entry_username = tk.Entry(self)
  140. self.entry_username.grid(row=0, column=3)
  141.  
  142.  
  143. button = tk.Button(self, text='Add Employee', width=15,
  144. command=lambda: controller.raise_frame(addEmpFrame))
  145. button.grid(row=2, column=3)
  146. button = tk.Button(self, text='Remove Employee', width=15, command=lambda: controller.raise_frame(removeEmpFrame))
  147. button.grid(row=3, column=3)
  148. button = tk.Button(self, text='Employee Lookup', width=15, command=lambda: controller.raise_frame(EmpLookupFrame))
  149. button.grid(row=4, column=3)
  150. button = tk.Button(self, text='Calculate Pay Roll', width=15, command=lambda: controller.raise_frame(calcPayRollFrame))
  151. button.grid(row=5, column=3)
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. class addEmpFrame(tk.Frame): #One of the three registration Frames, Button NEXT moves to the next registration page
  159. def __init__(self, parent, controller):
  160. tk.Frame.__init__(self, parent)
  161.  
  162. self.controller = controller
  163.  
  164. empInfoLabel = tk.Label(self, text='Please enter Personal information.')
  165. empInfoLabel.grid(row=0, column=1)
  166.  
  167. labelFirstName = tk.Label(self, text="Employee First Name")
  168. labelFirstName.grid(row=1, column=0)
  169. labelLastName = tk.Label(self, text="Employee Last Name")
  170. labelLastName.grid(row=2, column=0)
  171. labelAge = tk.Label(self, text="Employee Age")
  172. labelAge.grid(row=3, column=0)
  173. labelAddress = tk.Label(self, text="Employee full address?(street, city, state, zip")
  174. labelAddress.grid(row=4, column=0)
  175. labelDOB = tk.Label(self, text="Employee day of birth")
  176. labelDOB.grid(row=5, column=0)
  177. labelMOB = tk.Label(self, text="Employee month of birth")
  178. labelMOB.grid(row=6, column=0)
  179. labelYOB = tk.Label(self, text="Employee year of birth")
  180. labelYOB.grid(row=7, column=0)
  181. labelHealthCare = tk.Label(self, text="Health Care (yes or no)")
  182. labelHealthCare.grid(row=8, column=0)
  183. labelHealthCareID = tk.Label(self, text="Employee health care id")
  184. labelHealthCareID.grid(row=9, column=0)
  185. labelEmployeeID = tk.Label(self, text="Employee id")
  186. labelEmployeeID.grid(row=10, column=0)
  187.  
  188. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["first_name"])
  189. userEntry.grid(row=1, column=1)
  190. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["last_name"])
  191. userEntry.grid(row=2, column=1)
  192. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["age"])
  193. userEntry.grid(row=3, column=1)
  194. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["address"])
  195. userEntry.grid(row=4, column=1)
  196. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["day_of_birth"])
  197. userEntry.grid(row=5, column=1)
  198. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["month_of_birth"])
  199. userEntry.grid(row=6, column=1)
  200. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["year_of_birth"])
  201. userEntry.grid(row=7, column=1)
  202. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["health_care"])
  203. userEntry.grid(row=8, column=1)
  204. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["health_care_id"])
  205. userEntry.grid(row=9, column=1)
  206. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["employee_id"])
  207. userEntry.grid(row=10, column=1)
  208.  
  209. nextButton = tk.Button(self, text='Next', command=lambda: controller.raise_frame(addEmpFrame1))
  210. nextButton.grid(row=12, column=1)
  211.  
  212. retButton = tk.Button(self, text='Main Menu', command=lambda: controller.raise_frame(mainMenuPage))
  213. retButton.grid(row=12, column=0)
  214.  
  215.  
  216. class addEmpFrame1(tk.Frame): #second registration page, button NEXT moves to the next registration page
  217. def __init__(self, parent, controller):
  218. tk.Frame.__init__(self, parent)
  219.  
  220. self.controller = controller
  221.  
  222. empInfo2Label = tk.Label(self, text='Please enter Insurance information.')
  223. empInfo2Label.grid(row=0, column=1)
  224.  
  225. labelMarried = tk.Label(self, text="Married? (yes or no)")
  226. labelMarried.grid(row=1, column=0)
  227. labelhInsurance = tk.Label(self, text="Health Care Insurance company")
  228. labelhInsurance.grid(row=2, column=0)
  229. labeldInsurance = tk.Label(self, text="Dental Care Insurance company")
  230. labeldInsurance.grid(row=3, column=0)
  231. labeloInsurance = tk.Label(self, text="Optical Care Insurance company")
  232. labeloInsurance.grid(row=4, column=0)
  233. labelhTier = tk.Label(self, text="hTier")
  234. labelhTier.grid(row=5, column=0)
  235.  
  236. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["married"])
  237. userEntry.grid(row=1, column=1)
  238. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["hInsurance"])
  239. userEntry.grid(row=2, column=1)
  240. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["dInsurance"])
  241. userEntry.grid(row=3, column=1)
  242. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["oInsurance"])
  243. userEntry.grid(row=4, column=1)
  244. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["hTier"])
  245. userEntry.grid(row=5, column=1)
  246.  
  247. nextButton = tk.Button(self, text='Next', command=lambda: controller.raise_frame(addEmpFrame2))
  248. nextButton.grid(row=7, column=1)
  249.  
  250. retButton = tk.Button(self, text='Main Menu', command=lambda: controller.raise_frame(mainMenuPage))
  251. retButton.grid(row=7, column=0)
  252.  
  253.  
  254. class addEmpFrame2(tk.Frame): #Final registration page, SUBMIT checks if exists in db, if not, Inserts
  255. def __init__(self, parent, controller):
  256. tk.Frame.__init__(self, parent)
  257.  
  258. self.controller = controller
  259.  
  260. empInfo3Label = tk.Label(self, text='Please enter Financial information.')
  261. empInfo3Label.grid(row=0, column=1)
  262.  
  263. label401k = tk.Label(self, text="401k (yes or no)")
  264. label401k.grid(row=1, column=0)
  265. labelkContribution = tk.Label(self, text="kContribution")
  266. labelkContribution.grid(row=2, column=0)
  267. labelPension = tk.Label(self, text="Pension (yes or no)")
  268. labelPension.grid(row=3, column=0)
  269. labelUnionDues = tk.Label(self, text="Union dues (yes or no)")
  270. labelUnionDues.grid(row=4, column=0)
  271. labelPayType = tk.Label(self, text="Pay type")
  272. labelPayType.grid(row=5, column=0)
  273. labelPayAmount = tk.Label(self, text="Pay amount")
  274. labelPayAmount.grid(row=6, column=0)
  275.  
  276. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["four01k"])
  277. userEntry.grid(row=1, column=1)
  278. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["kContribution"])
  279. userEntry.grid(row=2, column=1)
  280. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["pension"])
  281. userEntry.grid(row=3, column=1)
  282. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["unionDues"])
  283. userEntry.grid(row=4, column=1)
  284. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["payType"])
  285. userEntry.grid(row=5, column=1)
  286. userEntry = tk.Entry(self, textvariable=self.controller.shared_data["payAmount"])
  287. userEntry.grid(row=6, column=1)
  288.  
  289. submitButton = tk.Button(self, text='Submit', command=lambda: self.addEmployee(controller))
  290. submitButton.grid(row=8, column=1)
  291.  
  292. retButton = tk.Button(self, text='Main Menu', command=lambda: controller.raise_frame(mainMenuPage))
  293. retButton.grid(row=8, column=0)
  294.  
  295. def addEmployee(self, controller): #Checking and inserting function
  296.  
  297. temp_stat = 0
  298.  
  299. firstName = self.controller.shared_data["first_name"].get()
  300. lastName = self.controller.shared_data["last_name"].get()
  301. aGe = self.controller.shared_data["age"].get()
  302. addRess = self.controller.shared_data["address"].get()
  303. DOB = self.controller.shared_data["day_of_birth"].get()
  304. MOB = self.controller.shared_data["month_of_birth"].get()
  305. YOB = self.controller.shared_data["year_of_birth"].get()
  306. healthCare = self.controller.shared_data["health_care"].get()
  307. healthCareID = self.controller.shared_data["health_care_id"].get()
  308. employeeID = self.controller.shared_data["employee_id"].get()
  309. marry = self.controller.shared_data["married"].get()
  310. healthIns = self.controller.shared_data["hInsurance"].get()
  311. dentalIns = self.controller.shared_data["dInsurance"].get()
  312. opticalIns = self.controller.shared_data["oInsurance"].get()
  313. healthTier = self.controller.shared_data["hTier"].get()
  314. Four1k = self.controller.shared_data["four01k"].get()
  315. keyContribution = self.controller.shared_data["kContribution"].get()
  316. penSion = self.controller.shared_data["pension"].get()
  317. unionDues = self.controller.shared_data["unionDues"].get()
  318. payType = self.controller.shared_data["payType"].get()
  319. payAmount = self.controller.shared_data["payAmount"].get()
  320.  
  321. attempt = Employee.Register(firstName, lastName, aGe, addRess, DOB, MOB, YOB,
  322. healthCare, healthCareID, employeeID, marry, healthIns,
  323. dentalIns, opticalIns, healthTier, Four1k, keyContribution,
  324. penSion, unionDues, payType, payAmount)
  325. temp_stat = attempt.databaseInsert()
  326.  
  327. if(temp_stat == 1):
  328. messagebox.showinfo("Status", "Successfully Added")
  329. controller.raise_frame(mainMenuPage)
  330. controller.update_frame(mainMenuPage)
  331.  
  332. elif(temp_stat == 0):
  333. messagebox.showinfo("Status", "User Already Exists")
  334. controller.raise_frame(addEmpFrame)
  335.  
  336.  
  337. class removeEmpFrame(tk.Frame): #Under construction
  338. def __init__(self, parent, controller):
  339. tk.Frame.__init__(self, parent)
  340.  
  341. retButton = tk.Button(self, text='Main Menu', command=lambda: controller.raise_frame(mainMenuPage))
  342. retButton.grid(row=12, column=0)
  343.  
  344.  
  345. class EmpLookupFrame(tk.Frame): #Under Construction
  346. def __init__(self, parent, controller):
  347. tk.Frame.__init__(self, parent)
  348.  
  349. retButton = tk.Button(self, text='Main Menu', command=lambda: controller.raise_frame(mainMenuPage))
  350. retButton.grid(row=12, column=0)
  351.  
  352.  
  353. class calcPayRollFrame(tk.Frame): #Under construction
  354. def __init__(self, parent, controller):
  355. tk.Frame.__init__(self, parent)
  356.  
  357. retButton = tk.Button(self, text='Main Menu', command=lambda: controller.raise_frame(mainMenuPage))
  358. retButton.grid(row=12, column=0)
  359.  
  360.  
  361. if __name__ == "__main__":
  362. gui = GUI()
  363. gui.mainloop()
  364.  
  365. def clear_shared_data(self):
  366. for key, value in self.shared_data.items():
  367. print(value.get())
  368. value.set("")
  369.  
  370. command=lambda: (controller.clear_shared_data(), controller.raise_frame(addEmpFrame))
Add Comment
Please, Sign In to add comment