Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.46 KB | None | 0 0
  1. from tkinter import*
  2. import sqlite3,pickle
  3.  
  4. conn = sqlite3.connect('Base1.db')
  5. cursor = conn.cursor()
  6.  
  7. sql ='create table if not exists Base1 (fio TEXT, passport TEXT, place TEXT, data TEXT, lg TEXT)'
  8. cursor.execute(sql)
  9.  
  10. count = cursor.execute("SELECT COUNT(*) FROM Base1").fetchone()[0]
  11. print(count)
  12.  
  13. cursor.execute("SELECT * FROM Base1")
  14. print(cursor.fetchall())
  15.  
  16. def fbuy():
  17.  
  18. def adultb():
  19. def buynext():
  20. fio = textbox1.get()
  21. passport = textbox2.get()
  22. place = textbox3.get()
  23. data = textbox4.get()
  24. lg = '---'
  25.  
  26. cursor.execute("SELECT * FROM Base1")
  27. result=cursor.fetchall()
  28. if result == []:
  29. sql = '''insert into Base1 values(?,?,?,?,?)'''
  30. cursor.execute(sql, (fio,passport,place,data,lg))
  31. count = cursor.execute("SELECT COUNT(*) FROM Base1").fetchone()[0]
  32. print(count)
  33. elif result != []:
  34. cursor.execute('''SELECT * FROM Base1 WHERE place = ?;''',(place,))
  35. result=cursor.fetchall()
  36. print(result)
  37. if result!=[]:
  38. error = Tk()
  39. error.title("Ошибка")
  40. error.geometry("500x200")
  41. lbl = Label(error, text = "Место уже занято, оформите билет заново")
  42. lbl.grid(row = 0, column = 4)
  43. print("Место уже занято")
  44. def back():
  45. error.destroy()
  46. butback = Button(error, text = "Назад", command = back)
  47. butback.grid(row = 2, column = 0, pady=10, sticky = W + E)
  48. else:
  49. sql = '''insert into Base1 values(?,?,?,?,?)'''
  50. cursor.execute(sql, (fio,passport,place,data,lg))
  51. conn.commit()
  52.  
  53. frame2.grid_remove()
  54. frame3.grid_remove()
  55. lbl2 = Label(frame1, text = "Введите информацию:")
  56. lbl2.grid(row = 0, column = 1)
  57. lbl2 = Label(frame1, text = "Фио")
  58. lbl2.grid(row = 1, column = 0)
  59. lbl2 = Label(frame1, text = "Серия и номер паспорта")
  60. lbl2.grid(row = 2, column = 0)
  61. lbl2 = Label(frame1, text = "Место")
  62. lbl2.grid(row = 3, column = 0)
  63. lbl2 = Label(frame1, text = "Дата рождения")
  64. lbl2.grid(row = 4, column = 0)
  65. textbox1 = Entry(frame1, width = 50)
  66. textbox1.focus_set()
  67. textbox1.grid(row = 1, column = 1)
  68. textbox2 = Entry(frame1, width = 50)
  69. textbox2.grid(row = 2, column = 1)
  70. textbox3 = Entry(frame1, width = 50)
  71. textbox3.grid(row = 3, column = 1)
  72. textbox4 = Entry(frame1, width = 50)
  73. textbox4.grid(row = 4, column = 1)
  74. frame1.grid(row = 2, column = 1, columnspan = 3)
  75.  
  76. butbuynext = Button(frame1, text = "Ввести данные", command = buynext)
  77. butbuynext.grid(row = 5, column = 1, pady=10, sticky = W + E)
  78.  
  79.  
  80. def lgb():
  81. def buynext():
  82. fio = textbox1.get()
  83. passport = textbox2.get()
  84. place = textbox3.get()
  85. data = textbox4.get()
  86. lg = textbox5.get()
  87.  
  88. cursor.execute("SELECT * FROM Base1")
  89. result=cursor.fetchall()
  90. if result == []:
  91. sql = '''insert into Base1 values(?,?,?,?,?)'''
  92. cursor.execute(sql, (fio,passport,place,data,lg))
  93. count = cursor.execute("SELECT COUNT(*) FROM Base1").fetchone()[0]
  94. print(count)
  95. elif result != []:
  96. cursor.execute('''SELECT * FROM Base1 WHERE place = ?;''',(place,))
  97. result=cursor.fetchall()
  98. print(result)
  99. if result!=[]:
  100. error = Tk()
  101. error.title("Ошибка")
  102. error.geometry("500x200")
  103. lbl = Label(error, text = "Место уже занято, оформите билет заново")
  104. lbl.grid(row = 0, column = 4)
  105. print("Место уже занято")
  106. def back():
  107. error.destroy()
  108. butback = Button(error, text = "Назад", command = back)
  109. butback.grid(row = 2, column = 0, pady=10, sticky = W + E)
  110. else:
  111. sql = '''insert into Base1 values(?,?,?,?,?)'''
  112. cursor.execute(sql, (fio,passport,place,data,lg))
  113. conn.commit()
  114.  
  115. frame1.grid_remove()
  116. frame3.grid_remove()
  117. lbl2 = Label(frame2, text = "Введите информацию:")
  118. lbl2.grid(row = 0, column = 1, )
  119. lbl2 = Label(frame2, text = "Фио")
  120. lbl2.grid(row = 1, column = 0)
  121. lbl2 = Label(frame2, text = "Серия и номер паспорта")
  122. lbl2.grid(row = 2, column = 0)
  123. lbl2 = Label(frame2, text = "Место")
  124. lbl2.grid(row = 3, column = 0)
  125. lbl2 = Label(frame2, text = "Дата рождения")
  126. lbl2.grid(row = 4, column = 0)
  127. lbl2 = Label(frame2, text = "Номер льготной карты")
  128. lbl2.grid(row = 5, column = 0)
  129. textbox1 = Entry(frame2,width = 50)
  130. textbox1.focus_set()
  131. textbox1.grid(row = 1, column = 1)
  132. textbox2 = Entry(frame2,width = 50)
  133. textbox2.grid(row = 2, column = 1)
  134. textbox3 = Entry(frame2,width = 50)
  135. textbox3.grid(row = 3, column = 1)
  136. textbox4 = Entry(frame2,width = 50)
  137. textbox4.grid(row = 4, column = 1)
  138. textbox5 = Entry(frame2,width = 50)
  139. textbox5.grid(row = 5, column = 1)
  140. frame2.grid(row = 2, column = 1, columnspan = 3)
  141.  
  142. butbuynext = Button(frame2, text = "Ввести данные", command = buynext)
  143. butbuynext.grid(row = 6, column = 1, pady=10, sticky = W + E)
  144.  
  145. def childb():
  146. def buynext():
  147. fio = textbox1.get()
  148. passport = textbox2.get()
  149. place = textbox3.get()
  150. data = textbox4.get()
  151. lg = '---'
  152.  
  153. cursor.execute("SELECT * FROM Base1")
  154. result=cursor.fetchall()
  155. if result == []:
  156. sql = '''insert into Base1 values(?,?,?,?,?)'''
  157. cursor.execute(sql, (fio,passport,place,data,lg))
  158. count = cursor.execute("SELECT COUNT(*) FROM Base1").fetchone()[0]
  159. print(count)
  160. elif result != []:
  161. cursor.execute('''SELECT * FROM Base1 WHERE place = ?;''',(place,))
  162. result=cursor.fetchall()
  163. print(result)
  164. if result!=[]:
  165. error = Tk()
  166. error.title("Ошибка")
  167. error.geometry("500x200")
  168. lbl = Label(error, text = "Место уже занято, оформите билет заново")
  169. lbl.grid(row = 0, column = 4)
  170. print("Место уже занято")
  171. def back():
  172. error.destroy()
  173. butback = Button(error, text = "Назад", command = back)
  174. butback.grid(row = 2, column = 0, pady=10, sticky = W + E)
  175.  
  176. cursor.execute('''SELECT * FROM Base1 WHERE passport = ?;''',(passport,))
  177. result=cursor.fetchall()
  178. print(result)
  179. if result == []:
  180. error = Tk()
  181. error.title("Ошибка")
  182. error.geometry("500x200")
  183. lbl = Label(error, text = "Родитель не найден, оформите билет заново")
  184. lbl.grid(row = 0, column = 4)
  185. print("Место уже занято")
  186. def back():
  187. error.destroy()
  188. butback = Button(error, text = "Назад", command = back)
  189. butback.grid(row = 2, column = 0, pady=10, sticky = W + E)
  190. else:
  191. sql = '''insert into Base1 values(?,?,?,?,?)'''
  192. cursor.execute(sql, (fio,passport,place,data,lg))
  193. conn.commit()
  194.  
  195. frame1.grid_remove()
  196. frame2.grid_remove()
  197.  
  198. lbl2 = Label(frame3, text = "Введите информацию:")
  199. lbl2.grid(row = 0, column = 1)
  200. lbl2 = Label(frame3, text = "Фио")
  201. lbl2.grid(row = 1, column = 0)
  202. lbl2 = Label(frame3, text = "Серия и номер паспорта родителя")
  203. lbl2.grid(row = 2, column = 0)
  204. lbl2 = Label(frame3, text = "Место")
  205. lbl2.grid(row = 3, column = 0)
  206. lbl2 = Label(frame3, text = "Дата рождения")
  207. lbl2.grid(row = 4, column = 0)
  208. textbox1 = Entry(frame3,width = 50)
  209. textbox1.focus_set()
  210. textbox1.grid(row = 1, column = 1)
  211. textbox2 = Entry(frame3,width = 50)
  212. textbox2.grid(row = 2, column = 1)
  213. textbox3 = Entry(frame3,width = 50)
  214. textbox3.grid(row = 3, column = 1)
  215. textbox4 = Entry(frame3,width = 50)
  216. textbox4.grid(row = 4, column = 1)
  217. frame3.grid(row = 2, column = 1, columnspan = 3)
  218.  
  219. butbuynext = Button(frame3, text = "Ввести данные", command = buynext)
  220. butbuynext.grid(row = 5, column = 1, pady=10, sticky = W + E)
  221.  
  222. buy = Tk()
  223. buy.title("Меню")
  224. buy.geometry("800x500")
  225. frame1=Frame(buy,bg='green',bd=5)
  226. frame2=Frame(buy,bg='red',bd=5)
  227. frame3=Frame(buy,bg='blue',bd=5)
  228. check = IntVar()
  229. rbtn1 = Radiobutton(buy, text = "Полный", value = 1, variable = check, command = adultb)
  230. rbtn2 = Radiobutton(buy, text = "Льготный", value = 2, variable = check, command = lgb)
  231. rbtn3 = Radiobutton(buy, text = "Детский", value = 3, variable = check, command = childb)
  232. lbl2 = Label(buy, text = "Выберите тип билета:")
  233. lbl2.grid(row = 0, column = 0, padx=30, pady=20)
  234. rbtn1.grid(row = 0, column = 1, padx=10, pady=20)
  235. rbtn2.grid(row = 0, column = 2, padx=10, pady=20)
  236. rbtn3.grid(row = 0, column = 3, padx=10, pady=20)
  237.  
  238. def printt():
  239. pr = Tk()
  240. pr.title("Печать билетов")
  241. pr.geometry("500x500")
  242. lbl=Label(pr, text = "Для возможности печати билетов нужно иметь права администратора!")
  243. lbl1=Label(pr, text = "Введите логин и пароль.")
  244. lbl.grid(row = 0, column = 0,columnspan=2)
  245. lbl1.grid(row = 1, column = 0)
  246. lbl2 = Label(pr, text = "login")
  247. lbl2.grid(row = 2, column = 0, sticky = W)
  248. lbl2 = Label(pr, text = "password")
  249. lbl2.grid(row = 3, column = 0, sticky = W)
  250. textbox1 = Entry(pr,width = 50)
  251. textbox1.focus_set()
  252. textbox1.grid(row = 2, column = 1)
  253. textbox2 = Entry(pr,width = 50)
  254. textbox2.grid(row = 3, column = 1)
  255.  
  256. def admin():
  257. login = 'admin'
  258. password = '1111'
  259. login1=textbox1.get()
  260. password1=textbox2.get()
  261. if login1==login and password1==password:
  262. print("\nБаза данных:")
  263. cursor.execute("SELECT * FROM Base1")
  264. result=cursor.fetchall()
  265. print(result)
  266. else:
  267. error = Tk()
  268. error.title("Ошибка")
  269. error.geometry("500x200")
  270. lbl = Label(error, text = "Неверный пароль или логин, попробуйте снова")
  271. lbl.grid(row = 0, column = 4)
  272. def back():
  273. error.destroy()
  274. butback = Button(error, text = "Назад", command = back)
  275. butback.grid(row = 2, column = 0, pady=10, sticky = W + E)
  276.  
  277. butadmin = Button(pr, text = "ОК",command = admin)
  278. butadmin.grid(row = 4, column = 1,columnspan = 2, padx=30, pady=30, sticky = W + E)
  279.  
  280. window = Tk()
  281. window.title("Меню")
  282. window.geometry("500x500")
  283. butbuy = Button(window, text = "Оформить билет", command = fbuy)
  284. butprint = Button(window, text = "Вывести билеты",command = printt)
  285. butbuy.grid(row = 2, column = 2, padx=200, pady=100, sticky = W + E)
  286. butprint.grid(row = 4, column = 2, padx=200, pady=100, sticky = W + E)
  287.  
  288. conn.commit()
  289. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement