航班管理系统-机票预订
摘要
该系统为航班管理系统,本系统是基于Python语言,通过对航班管理工作的日常分析,确定了具体的研究目标以及业务功能。采用了结构化的设计方法设计了一个简单的框架,通过编程实现了对航班信息的添加、修改、删除、查询,并且使用数据库存储信息。
1.引言
1.1 背景
由于本学期开设了python课,同时也开设了软件工程的课。于是我与另外的两名同学组队以python语言为主体的,结合数据库知识,一起做了一个航空管理系统。
又由于现在python期末作业也需要每人做一个项目,正好我在软件工程项目中,我负责是做数据库接口的部分,于是将这个程序用作Python的期末项目。
1.2 意义
由于完成这个项目,不是我一个人的功劳,所以首先要感谢我的同学。在完成这个项目同时我不仅对Python越来越熟悉,理解了Python的简便和灵活;而且也学会了在小团队中,进行项目开发,如何与其他的项目负责人沟通,交流。
1.3 相关研究
航班管理系统是使用计算机软件系统管理航班的一种方式。决定仿照市面上的航班管理系统的所有的功能的基础上,做出一个简易的航班管理系统。
- 系统结构
① 数据使用mysql数据库进行保存。需要配合Python的两个库,sqlalchemy和pymysql。MySQL 是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。SQLAlchemy“采用简单的Python语言,为高效和高性能的数据库访问设计,实现了完整的企业级持久模型”。 PyMySQL是在 Python3.x 版本中用于连接 MySQL 服务器的一个库,Python2中是使用mysqldb。
② 页面都是使用python中的Tkinter库来创造,Tkinter库(模块)是Python的标准Tk GUI 工具包的接口。Tkinter可以在大多数的Unix和Windows平台下使用。TK8.0的后续版本可以实现本地窗口风格,并良好地运行在绝大多数平台中。Tkinter 是 Python 的标准 GUI 库。Python 使用 Tkinter 可以快速的创建 GUI 应用程序。
由于 Tkinter 是内置到 python 的安装包中、只要安装好 Python 之后就能 import Tkinter 库、而且 IDLE 也是用 Tkinter 编写而成、对于简单的图形界面 Tkinter 还是能应付自如。
Tkinter的提供各种控件,如按钮,标签和文本框,一个GUI应用程序中使用。
- 实现代码
3.0 数据库接口
调用了sqlalchemy库里的关于数据类型的类,以及连接,操作数据库所需要的类。并且创建好类,作为数据库中我们所需要的表。分别是Account_Table(账号表),Passenger_Table(乘客信息表),Airline_Company_Table(航空公司表), Travel_Agency_Table(旅行社表), Flight_Information_Table(航班信息表), Order_information_table(订单表)。其中包含有关于操作这个表的方法:添加,删除,查看,修改等。
1. from sqlalchemy import Column, Integer,String, create_engine,and_
2. from sqlalchemy.orm import sessionmaker
3. from sqlalchemy.ext.declarative import declarative_base
4.
5. # 初始化数据库连接:
6. engine = create_engine('mysql+pymysql://root:aaa@qq.com:3306/test_sqlalchemy',echo=False)
7.
8. # 创建连接池DBSession类型:
9. DBSession = sessionmaker(bind=engine)
10.
11. # 创建对象的基类:
12. Base = declarative_base()
13. Base.metadata.create_all(engine)
14.
15. # 定义User对象:
16. class User(Base):
17. # 表的名字:
18. __tablename__ = 'user'
19.
20. # 表的结构:
21. id = Column(String(20), primary_key=True)
22. name = Column(String(20))
23.
24.
25.
26. class Account_Table(Base): #账号表
27. __tablename__ = 'account_table'
28.
29. User = Column(String(20), primary_key=True) #账号
30. Password = Column(String(30),nullable=False) #密码
31. ID_Number = Column(String(100)) #身份证号码或者护照号码或者其他ID码
32. Category = Column(String(10)) #账号类别
33.
34.
35. #-------------管理员操作--------------
36. #添加账号
37. def Insert_Account(n_user,n_password,n_id,n_category):
38. session = DBSession()
39. new_Accout = Account_Table(User = n_user,Password = n_password,
40. ID_Number = n_id,
41. Category = n_category)
42. session.add(new_Accout)
43. try:
44. session.commit()
45. except Exception as e:
46. session.rollback()
47.
48. session.close()
49.
50. #删除账号
51. def Delete_Account(del_user):
52. session = DBSession()
53.
54. result = session.query(Account_Table).filter(Account_Table.User == del_user).delete()
55. session.commit()
56. session.close()
57.
58.
59. #查看账号
60. def Query_Account(cate):
61. session = DBSession()
62. result = session.query(Account_Table).filter(Account_Table.Category == cate)
63. try:
64. session.commit()
65. return result
66.
67. except Exception as e:
68. session.rollback()
69.
70. session.close()
71. def Query_Cate(q_user):
72. session = DBSession()
73.
74.
75. try:
76. result = session.query(Account_Table).filter(Account_Table.User == q_user).one()
77. session.commit()
78. return result.Category
79.
80. except Exception as e:
81. session.rollback()
82.
83.
84. #修改账号
85.
86. #--------
87.
88. class Passenger_Table(Base): #乘客信息表
89. __tablename__ = 'passenger_table'
90.
91.
92. Name = Column(String(20)) #1乘客姓名
93. Sex = Column(String(10)) #2性别
94. Workplace = Column(String(50)) #3工作单位
95.
96. ID_Card_Number = Column(String(100),primary_key=True) #4乘客身份证号
97.
98. travel_time = Column(String(20)) #5旅行出发时间
99. place_travel_start = Column(String(10)) #6旅行始发地
100. place_travel_end = Column(String(10)) #7旅行目的地
101. requirement_berths = Column(String(50)) #8舱位要求
102.
103.
104.
105. Flight_No = Column(String(20)) #9航班号码
106. Travel_agency_No = Column(String(20)) #10旅行社号码
107. Order_NO = Column(String(20)) #11订单号码
108.
109. #-------------旅客操作-------------------------------------
110. #添加个人信息
111. def Insert_Passenger(n_Name,n_Sex,n_Workplace,n_ID_Card_Number,n_travel_time,n_place_travel_start,n_place_travel_end,n_requirement_berths,n_Flight_No,n_Travel_agency_No,n_Order_NO):
112. session = DBSession()
113. new_Passenger = Passenger_Table(Name = n_Name,
114. Sex = n_Sex,
115. Workplace = n_Workplace,
116. ID_Card_Number = n_ID_Card_Number,
117. travel_time = n_travel_time,
118. place_travel_start = n_place_travel_start,
119. place_travel_end = n_place_travel_end,
120. requirement_berths = n_requirement_berths,
121. Flight_No = n_Flight_No,
122. Travel_agency_No = n_Travel_agency_No,
123. Order_NO = n_Order_NO)
124.
125. session.add(new_Passenger)
126. try:
127. session.commit()
128. except Exception as e:
129. session.rollback()
130.
131. session.close()
132.
133.
134. #删除个人信息
135. def Delete_Passenger(del_ID_Card_Number):
136. session = DBSession()
137.
138. result = session.query(Passenger_Table).filter(Passenger_Table.ID_Card_Number == del_ID_Card_Number).delete()
139.
140. session.commit()
141. session.close()
142.
143. #修改个人信息
144. def Update_Passenger(ID,Pos,Update_value):
145. session = DBSession()
146.
147. if Update_value != '':
148. if Pos == 0:
149. session.query(Passenger_Table).filter(Passenger_Table.ID_Card_Number == ID).update({Passenger_Table.Name:Update_value})
150. elif Pos == 1:
151. session.query(Passenger_Table).filter(Passenger_Table.ID_Card_Number == ID).update({Passenger_Table.Sex:Update_value})
152. elif Pos == 2:
153. session.query(Passenger_Table).filter(Passenger_Table.ID_Card_Number == ID).update({Passenger_Table.Workplace:Update_value})
154. elif Pos == 3:
155. session.query(Passenger_Table).filter(Passenger_Table.ID_Card_Number == ID).update({Passenger_Table.ID_Card_Number:Update_value})
156. elif Pos == 4:
157. session.query(Passenger_Table).filter(Passenger_Table.ID_Card_Number == ID).update({Passenger_Table.travel_time:Update_value})
158. elif Pos == 5:
159. session.query(Passenger_Table).filter(Passenger_Table.ID_Card_Number == ID).update({Passenger_Table.place_travel_start:Update_value})
160. elif Pos == 6:
161. session.query(Passenger_Table).filter(Passenger_Table.ID_Card_Number == ID).update({Passenger_Table.place_travel_end:Update_value})
162. elif Pos == 7:
163. session.query(Passenger_Table).filter(Passenger_Table.ID_Card_Number == ID).update({Passenger_Table.requirement_berths:Update_value})
164. elif Pos == 8:
165. session.query(Passenger_Table).filter(Passenger_Table.ID_Card_Number == ID).update({Passenger_Table.Flight_No:Update_value})
166. elif Pos == 9:
167. session.query(Passenger_Table).filter(Passenger_Table.ID_Card_Number == ID).update({Passenger_Table.Travel_agency_No:Update_value})
168. elif Pos == 10:
169. session.query(Passenger_Table).filter(Passenger_Table.ID_Card_Number == ID).update({Passenger_Table.Order_NO:Update_value})
170. else:
171. print("POS Err")
172. else :
173. print('Update_value: NULL')
174.
175. session.commit()
176. session.close()
177.
178. #查看对于旅行社的旅客信息
179. def Query_Passenger(T_No):
180. session = DBSession()
181. result = session.query(Passenger_Table).filter(Passenger_Table.Travel_agency_No == T_No)
182. try:
183. session.commit()
184. return result
185.
186. except Exception as e:
187. session.rollback()
188.
189. session.close()
190.
191. #--------------------------------------
192.
193.
194. class Airline_Company_Table(Base): #航空公司表
195. __tablename__ = 'airline_company_table'
196.
197. No = Column(String(100),primary_key = True)
198. Name = Column(String(20))
199.
200.
201. #添加航公司的名字和号码
202. def Insert_Company(n_No,n_Name):
203. session = DBSession()
204.
205. new_Company = Airline_Company_Table(No = n_No,
206. Name = n_Name)
207. session.add(new_Company)
208.
209. session.commit()
210. session.close()
211. #删除航空公司名字和号码
212. def Delete_Company(del_No):
213. session = DBSession()
214.
215. result = session.query(Airline_Company_Table).filter(Airline_Company_Table.No == del_No).delete()
216.
217. session.commit()
218. session.close()
219. #删除账号查询的航空公司名字和号码
220. def Delete_Company_from_Account(del_user):
221. session = DBSession()
222.
223. Account_result = session.query(Account_Table).filter(Account_Table.User == del_user).one()
224.
225. AIN = Account_result.ID_Number
226.
227. result = session.query(Airline_Company_Table).filter(Airline_Company_Table.No == AIN).delete()
228. session.commit()
229. session.close()
230.
231. #查看航空公司名字和号码
232. def Query_Company(que_No):
233. session = DBSession()
234. result = session.query(Airline_Company_Table).filter(Airline_Company_Table.No == que_No)
235. try:
236. session.commit()
237. return result
238.
239.
240. except Exception as e:
241. session.rollback()
242.
243. session.close()
244.
245. #------------------------------------
246.
247.
248. class Travel_Agency_Table(Base): #旅行社表
249. __tablename__ = 'travel_agency_table'
250.
251. No = Column(String(100),primary_key = True)
252. Name = Column(String(20))
253.
254. #添加旅行社的号码
255. def Insert_Travel_Agency(n_No,n_Name):
256. session = DBSession()
257.
258. new_Travel_Agency = Travel_Agency_Table(No = n_No,
259. Name = n_Name)
260. session.add(new_Travel_Agency)
261.
262. session.commit()
263. session.close()
264. #删除旅行社名字和号码
265. def Delete_Travel_Agency(del_No):
266. session = DBSession()
267.
268. result = session.query(Travel_Agency_Table).filter(Travel_Agency_Table.No == del_No).delete()
269.
270. session.commit()
271. session.close()
272.
273. #删除账号查询的旅行社的名字
274. def Delete_Travel_Agency_from_Account(del_user):
275. session = DBSession()
276.
277. Account_result = session.query(Account_Table).filter(Account_Table.User == del_user).one()
278.
279.
280. AIN = Account_result.ID_Number
281.
282. result = session.query(Travel_Agency_Table).filter(Travel_Agency_Table.No == AIN).delete()
283. session.commit()
284. session.close()
285.
286. #查看旅行社名字和号码
287. def Query_Travel_Agency(que_No):
288. session = DBSession()
289. result = session.query(Travel_Agency_Table).filter(Travel_Agency_Table.No == que_No)
290. try:
291. session.commit()
292. return result
293.
294. except Exception as e:
295. session.rollback()
296.
297. session.close()
298.
299.
300.
301.
302. #---------------------------------
303.
304.
305.
306.
307. class Flight_Information_Table(Base): #航班信息表
308. __tablename__ = 'flight_information_table'
309.
310. Flight_no = Column(String(20),primary_key = True) #1航班号码
311. air_company_No = Column(String(20)) #2航空公司号码
312. origin = Column(String(10)) #3航班始发地
313. destination = Column(String(10)) #4航班目的地
314.
315. Aircraft_type = Column(String(10)) #5飞机型号
316. Num_P = Column(String(20)) #6乘客数
317. #Seats = Column(Integer) #座位数
318. #remaining_seats = Column(Integer) #剩余座位数
319.
320. scheduled_start_time = Column(String(20)) #7航班起飞时间
321. scheduled_arrival_time = Column(String(20)) #8航班预计到达时间
322. price = Column(String(50)) #9航班价格
323.
324.
325. #---------------------------航空公司操作---------------------------------
326. #添加航班
327. def Insert_Flight(n_Flight_no,n_air_company_No,n_origin,n_destination,n_Aircraft_type,n_Num_p,n_scheduled_start_time,n_scheduled_arrival_time,n_price):
328. session = DBSession()
329.
330. new_Flight = Flight_Information_Table(Flight_no = n_Flight_no,
331. air_company_No = n_air_company_No,
332. origin = n_origin,
333. destination = n_destination,
334. Aircraft_type = n_Aircraft_type,
335. Num_P = n_Num_p,
336. scheduled_start_time = n_scheduled_start_time,
337. scheduled_arrival_time = n_scheduled_arrival_time,
338. price = n_price)
339.
340. session.add(new_Flight)
341.
342. session.commit()
343. session.close()
344.
345. #删除航班
346. def Delete_Flight(del_Flight_no):
347. session = DBSession()
348.
349. result = session.query(Flight_Information_Table).filter(Flight_Information_Table.Flight_no == del_Flight_no).delete()
350.
351. print(result)
352. session.commit()
353. session.close()
354.
355. #查看航班信息
356. def Query_Flight(ACNO):
357.
358. session = DBSession()
359. result = session.query(Flight_Information_Table).filter(Flight_Information_Table.air_company_No == ACNO)
360. try:
361. session.commit()
362. return result
363.
364.
365. except Exception as e:
366. session.rollback()
367.
368. session.close()
369.
370. #修改航班信息
371. def Update_Flight(No,Pos,Update_value):
372. session = DBSession()
373.
374. if Update_value != '':
375. if Pos == 0:
376. session.query(Flight_Information_Table).filter(Flight_Information_Table.Flight_no == No).update({Flight_Information_Table.Flight_no:Update_value})
377. elif Pos == 1:
378. session.query(Flight_Information_Table).filter(Flight_Information_Table.Flight_no == No).update({Flight_Information_Table.air_company_No:Update_value})
379. elif Pos == 2:
380. session.query(Flight_Information_Table).filter(Flight_Information_Table.Flight_no == No).update({Flight_Information_Table.origin:Update_value})
381. elif Pos == 3:
382. session.query(Flight_Information_Table).filter(Flight_Information_Table.Flight_no == No).update({Flight_Information_Table.destination:Update_value})
383. elif Pos == 4:
384. session.query(Flight_Information_Table).filter(Flight_Information_Table.Flight_no == No).update({Flight_Information_Table.Aircraft_type:Update_value})
385. elif Pos == 5:
386. session.query(Flight_Information_Table).filter(Flight_Information_Table.Flight_no == No).update({Flight_Information_Table.Num_P:Update_value})
387. elif Pos == 6:
388. session.query(Flight_Information_Table).filter(Flight_Information_Table.Flight_no == No).update({Flight_Information_Table.scheduled_start_time:Update_value})
389. elif Pos == 7:
390. session.query(Flight_Information_Table).filter(Flight_Information_Table.Flight_no == No).update({Flight_Information_Table.scheduled_arrival_time:Update_value})
391. elif Pos == 8:
392. session.query(Flight_Information_Table).filter(Flight_Information_Table.Flight_no == No).update({Flight_Information_Table.price:Update_value})
393. else:
394. print("POS Err")
395. else :
396. print('Update_value: NULL')
397.
398. session.commit()
399. session.close()
400.
401. #-----------------------------------------------------------------
402.
403.
404.
405. class Order_information_table(Base): #订单表
406. __tablename__ = 'order_information_table'
407.
408. Order_no = Column(String(20),primary_key = True) #订单号码
409. ID_Card_Number = Column(String(100)) #身份证号码
410. Travel_agency_No = Column(String(20)) #旅行社号码
411. Flight_no = Column(String(20)) #航班号码
412. price = Column(String(20)) #价格
413. code_get_ticket = Column(String(20)) #取票码
414. #---------订单操作-----------
415. #添加订单
416. def Insert_Order(n_Order_no,n_ID_Card_Number,n_Travel_agency_No,n_Flight_no,n_price,n_code_get_ticket):
417. session = DBSession()
418.
419. new_Order = Order_information_table(Order_no = n_Order_no,
420. ID_Card_Number = n_ID_Card_Number,
421. Travel_agency_No = n_Travel_agency_No,
422. Flight_no = n_Flight_no,
423. price = n_price,
424. code_get_ticket = n_code_get_ticket)
425. session.add(new_Order)
426.
427. session.commit()
428. session.close()
429.
430. #删除订单
431. def Delete_Order(del_Order_no):
432. session = DBSession()
433.
434. result = session.query(Order_information_table).filter(Order_information_table.Order_no == del_Order_no).delete()
435.
436. session.commit()
437. session.close()
438.
439. #查看订单
440. def Query_Order(O_NO):
441.
442. session = DBSession()
443. result = session.query(Order_information_table).filter(Order_information_table == O_NO)
444. try:
445. session.commit()
446. return result
447.
448.
449. except Exception as e:
450. session.rollback()
451.
452. session.close()
453.
454.
455. #修改订单
456. def Update_Order(No,Pos,Update_value):
457. session = DBSession()
458.
459. if Update_value != '':
460. if Pos == 0:
461. session.query(Order_information_table).filter(Order_information_table.Order_no == No).update({Order_information_table.Order_no:Update_value})
462. elif Pos == 1:
463. session.query(Order_information_table).filter(Order_information_table.Order_no == No).update({Order_information_table.ID_Card_Number:Update_value})
464. elif Pos == 2:
465. session.query(Order_information_table).filter(Order_information_table.Order_no == No).update({Order_information_table.Travel_agency_No:Update_value})
466. elif Pos == 3:
467. session.query(Order_information_table).filter(Order_information_table.Order_no == No).update({Order_information_table.Flight_no.Seats:Update_value})
468. elif Pos == 4:
469. session.query(Order_information_table).filter(Order_information_table.Order_no == No).update({Order_information_table.price:Update_value})
470. elif Pos == 5:
471. session.query(Order_information_table).filter(Order_information_table.Order_no == No).update({Order_information_table.code_get_ticket:Update_value})
472. else:
473. print("POS Err")
474. else :
475. print('Update_value: NULL')
476.
477. session.commit()
478. session.close()
479. #---------------------------------------------
480.
481.
482. #目前仅有显示功能,不可以返回值
483. def Query_Table_ALL(table):
484. session = DBSession()
485. result = session.query(table).all()
486. try:
487. session.commit()
488. if table.__tablename__ == 'account_table':
489. return result
490. elif table.__tablename__ == 'passenger_table':
491. return result
492. elif table.__tablename__ == 'airline_company_table':
493. return result
494. elif table.__tablename__ == 'travel_agency_table':
495. return result
496. elif table.__tablename__ == 'flight_information_table':
497. return result
498. elif table.__tablename__ == 'order_information_table':
499. return result
500.
501. except Exception as e:
502. session.rollback()
503.
504. session.close()
505.
506.
507.
508.
509.
510.
511.
512.
513.
514.
515.
516.
517.
518. #-------------------------
519.
520.
521.
522. #旅客实操
523. #Insert_Passenger('林肯郡','440813199945460125','张家口','北京',12,1128885)
524. #Delete_Passenger('440813199945460125')
525. #Update_Passenger('440813199945460125',0,'')
526.
527. #航空公司实操
528.
529. #订单实操
530.
531.
532. Base.metadata.create_all(engine)
533.
534. '''''
535.
536. #创建表
537.
538.
539. # 创建session对象:
540. session = DBSession()
541. # 创建新User对象:
542. new_user = User(id='5', name='Bob')
543. # 添加到session:
544. session.add(new_user)
545. # 提交即保存到数据库:
546. session.commit()
547. # 关闭session:
548. session.close()
549.
550. # 创建Session:
551. session = DBSession()
552. # 创建Query查询,filter是where条件,最后调用one()返回唯一行,如果调用all()则返回所有行:
553. #user = session.query(User).filter(User.id=='5').one()
554. user = session.query(User).all()
555. # 打印类型和对象的name属性:
556. print('type:', type(user))
557. print(user)
558.
559. for each in user:
560. print(each.id,each.name)
561. # 关闭Session:
562. session.close()
563. '''
3.1 登陆界面
登陆界面是创造了一个LoginPage的类,在类的构造函数里面设置好框的大小,然后调用createPage函数创造各个tkinter的部件。再利用usr_sign_up函数来执行注册操作,logincheck函数来实现登录。
1. # -*- coding: utf-8 -*-
2. """
3. Created on Tue May 26 16:15:00 2020
4.
5. """
6. import interface
7. from interface import Account_Table, Passenger_Table, Airline_Company_Table, Travel_Agency_Table, Flight_Information_Table, Order_information_table, Query_Table_ALL
8.
9. import tkinter as tk
10. import pickle
11. import Admin_mainpage as Admin
12. import Customer_mainpage as Customer
13. import Airplane_mainpage as Airplane
14. import Tourist_agency_mainpage as Tourist_agency
15. import tkinter.messagebox as messagebox
16.
17. class LoginPage(object):
18. def __init__(self,master = None):
19. self.root = master #定义一个LoginPage类的内部变量,传入的值为window
20.
21. self.username = tk.StringVar()#设置tkinter的字符串变量username
22. self.password = tk.StringVar()#设置tkinter的字符串变量password
23.
24. self.createPage()
25.
26. def createPage(self):
27. self.root.geometry("500x350") #设置窗口的大小
28.
29. self.root.resizable(0,0)
30.
31. self.page1 = tk.Frame(self.root)
32. self.page1.pack()
33.
34.
35. tk.Label(self.page1, text = '账号用户名:').grid(row=1,stick=tk.W, pady=10)
36. tk.Entry(self.page1, textvariable=self.username).grid(row=1, column=1,stick=tk.E)
37.
38. tk.Label(self.page1, text = '账号密码:').grid(row=2,stick=tk.W,pady=10)
39. tk.Entry(self.page1, textvariable=self.password, show='*').grid(row=2, column=1, stick=tk.E)
40.
41. self.username.set("admin")#可以在这里修改账号用户名文本框里面的默认值
42. self.password.set("123456")#可以在这里修改密码文本框里面的默认值
43.
44. tk.Button(self.page1, text='登录', command=self.logincheck).grid(row=3, column=0, pady=5)
45. tk.Button(self.page1, text='注册旅客账号', command=self.usr_sign_up).grid(row=3, column=1, pady=5)
46. tk.Button(self.page1, text='退出', command=self.exit).grid(row=3, column=2, pady=5)
47.
48. tk.Label(self.page1,bg="green",text="欢迎来到Python航空管理系统\nby group 13\n管理员:admin 密码:123456",font=(None,11)).grid(row=4,column=1)
49.
50. #创建管理员账号
51. Exist = 0
52. result = Account_Table.Query_Account('Admin')
53. for row in result:
54. if row.User == '':
55. Exist = 0
56. else:
57. Exist = 1
58. if Exist == 0:
59. Account_Table.Insert_Account('admin','123456','-1','Admin')
60. else:
61. pass
62.
63. def logincheck(self):
64. usr_name = self.username.get()
65. usr_pwd = self.password.get()
66.
67. result = Query_Table_ALL(Account_Table)
68. Acccount_pwd_dict = dict()
69. Account_User_list = list()
70. if result == None:
71. pass
72. else:
73. for row in result:
74. Account_User_list.append(row.User)
75. Acccount_pwd_dict[row.User] = row.Password
76.
77.
78. permission = Account_Table.Query_Cate(usr_name)
79.
80. if usr_name in Account_User_list:
81.
82. if usr_pwd == Acccount_pwd_dict[usr_name]:
83.
84. if permission == "Customer":#如果该账号的性质是旅客
85. messagebox.showinfo(title="欢迎使用",message="欢迎旅客账号!\nHow are you?"+usr_name)
86. self.username.set("")
87. self.password.set("")
88. self.page1.destroy()
89. Customer.Customers_MainPage(self.root,usr_name)
90.
91. elif permission == "Company":#如果该账号的性质是航空公司
92. messagebox.showinfo(title="欢迎使用",message="欢迎航空公司账号!\nHow are you?"+usr_name)
93. self.username.set("")
94. self.password.set("")
95. self.page1.destroy()
96. Airplane.Airplane_Mainpage(self.root,usr_name)
97.
98. elif permission == "T_agency":#如果该账号的性质是旅行社
99. messagebox.showinfo(title="欢迎使用",message="欢迎旅行社账号!\nHow are you?"+usr_name)
100. self.username.set("")
101. self.password.set("")
102. self.page1.destroy()
103. Tourist_agency.Tourist_agency_Mainpage(self.root,usr_name)
104.
105. elif permission == "Admin":#如果该账号性质是管理员
106. messagebox.showinfo(title="欢迎使用",message="欢迎管理员账号!\nHow are you?"+usr_name)
107. self.username.set("")
108. self.password.set("")
109. self.page1.destroy()
110. Admin.Admin_MainPage(self.root,"admin")
111. else:
112. messagebox.showerror(title="错误",message="账号密码错误")
113. self.username.set("")
114. self.password.set("")
115. else:
116. is_sign_up = messagebox.askyesno(title="欢迎使用",message = "该账号还未注册,需要现在就注册成旅客账号吗")
117. if is_sign_up:
118. self.usr_sign_up()
119.
120. def usr_sign_up(self):
121. self.root.geometry("400x400") #设置窗口的大小
122.
123. self.root.resizable(0,0)
124.
125.
126. def sign_to():#注册旅客账号函数
127.
128. def check_id(new_id):#判断身份证号是否正确函数
129. if len(new_id) != 18:#如果身份证号码不是18位
130. return 0
131. elif new_id[0:2] not in ["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65"]:
132. return 0
133. else:
134. return 1
135.
136. new_name = new_user_name.get()#获取账号用户名
137.
138. new_pwd = new_user_pwd.get()#获取账号密码
139.
140. new_pwd_confirm = new_user_pwd_confirm.get()#获取再次确认密码
141.
142. new_id = new_user_id.get()#获取旅客身份证
143.
144.
145. #读取用户名,身份证放入列表
146. result = Query_Table_ALL(Account_Table)
147. Account_User_list = list()
148. if result == None:
149. pass
150. else:
151. for row in result:
152. Account_User_list.append(row.User)
153.
154. ID_result = Account_Table.Query_Account('Customer')
155. ID_list = list()
156. if ID_result == None:
157. pass
158. else:
159. for row in ID_result:
160. ID_list.append(row.ID_Number)
161.
162. if new_name == "":#没有输入用户名
163. new_user_name.set("")
164. new_user_pwd.set("")
165. new_user_pwd_confirm.set("")
166. new_user_id.set("")
167. messagebox.showerror(title = "错误",message = "请输入用户名")
168.
169. elif new_name != "" and (new_name in Account_User_list):#查询用户名是否已经被注册
170. new_user_name.set("")
171. new_user_pwd.set("")
172. new_user_pwd_confirm.set("")
173. new_user_id.set("")
174. messagebox.showerror(title = "错误",message = "该用户名已被注册过")
175.
176. elif new_pwd == "":#没有输入密码
177. new_user_pwd_confirm.set("")
178. messagebox.showerror(title = "错误",message = "请输入密码")
179.
180.
181. elif new_pwd_confirm == "":#没有输入再次确认密码
182. messagebox.showerror(title = "错误",message = "请再次输入密码")
183.
184. elif new_pwd_confirm != new_pwd:#再次确认密码不同于账户密码
185. new_user_pwd.set("")
186. new_user_pwd_confirm.set("")
187. messagebox.showerror(title = "错误",message = "两次输入的密码不一致")
188.
189. elif new_id == "":#如果旅客身份证号没有输入
190. new_user_id.set("")
191. messagebox.showerror(title = "错误",message = "请输入旅客身份证")
192.
193. elif new_id != "" and (new_id in ID_list):#在这里判断身份证是否已经注册过,谢了
194. new_user_id.set("")
195. messagebox.showerror(title = "错误",message = "该身份证已被注册过")
196.
197. elif check_id(new_id) == 0:
198. new_user_id.set("")
199. messagebox.showerror(title = "错误",message = "旅客身份证输入格式不正确")
200.
201. else:
202. Account_Table.Insert_Account(new_name,new_pwd,new_id,'Customer')
203.
204. messagebox.showinfo(title="注册成功",message = "旅客账户注册成功!")
205.
206. self.page2.destroy()
207. self.username.set("")
208. self.password.set("")
209. self.createPage()#返回登录界面
210.
211. def come_back_to_login():
212. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回登录界面?")
213. if is_come_back_to_login:
214. self.page2.destroy()
215. self.username.set("")
216. self.password.set("")
217. self.createPage()
218.
219. def close():
220. is_close = messagebox.askyesno("是否退出","是否真的要退出?")
221. if is_close:
222. self.page2.destroy()
223. self.root.destroy()
224.
225. self.page1.destroy()
226. self.page2 = tk.Frame(self.root)
227. self.page2.pack()
228.
229. new_user_name = tk.StringVar()#旅客账号用户名
230. new_user_pwd = tk.StringVar()#旅客账号密码
231. new_user_pwd_confirm = tk.StringVar()#再次确认的密码
232. new_user_id = tk.StringVar()#旅客账号ID
233.
234. tk.Label(self.page2,text="注册旅客账号").grid(row=0,stick=tk.W)
235.
236. tk.Label(self.page2,text = "账号用户名:").grid(row=1,pady=10,stick=tk.W)
237. tk.Entry(self.page2, textvariable=new_user_name).grid(row=1, column=1,stick = tk.E)
238.
239. tk.Label(self.page2, text = '账号密码:').grid(row=2, stick=tk.W, pady=10)
240. tk.Entry(self.page2, textvariable=new_user_pwd, show='*').grid(row=2, column=1, stick=tk.E)
241.
242. tk.Label(self.page2,text="再次确认密码:").grid(row=3,stick=tk.W,pady=10)
243. tk.Entry(self.page2,textvariable=new_user_pwd_confirm,show="*").grid(row=3,column=1,stick=tk.E)
244.
245. tk.Label(self.page2,text="旅客身份证:").grid(row=4,column=0,stick=tk.W,pady=10)
246. tk.Entry(self.page2,textvariable = new_user_id).grid(row=4,column=1,stick=tk.E)
247.
248.
249. tk.Button(self.page2, text='注册', command=sign_to).grid(row=6, column=0, pady=5)
250. tk.Button(self.page2, text='返回登录界面', command=come_back_to_login).grid(row=6, column=1, pady=5)
251. tk.Button(self.page2, text="退出", command=close).grid(row=6,column = 2,pady = 5)
252.
253. def exit(self):
254. is_exit = messagebox.askyesno("退出","是否真的退出")
255. if is_exit:
256. self.page1.destroy()
257. self.root.destroy()
258.
3.2 管理员界面
管理员界面也是创造了一个类, 在类的构造函数里面设置好框的大小,然后调用createPage函数创造各个tkinter的部件。并且创建出方法:添加旅客账号,删除旅客账号,查询旅客账号;添加旅行社账号,删除旅行社账号,查询旅行社账号;添加航空公司账号,删除航空公司账号,查询航空公司账号。
1. # -*- coding: utf-8 -*-
2. """
3. Created on Wed May 27 12:40:53 2020
4.
5. """
6. import interface
7. from interface import Account_Table, Passenger_Table, Airline_Company_Table, Travel_Agency_Table, Flight_Information_Table, Order_information_table, Query_Table_ALL
8.
9. import tkinter as tk
10. import LoginPage as Login
11. import tkinter.messagebox as messagebox
12. #import view
13.
14. class Admin_MainPage(object):
15. def __init__(self,master = None,usrs = None):
16. self.root = master #定义内部变量root
17.
18. self.user = usrs
19.
20. self.createPage_admin()
21.
22. def createPage_admin(self):
23. self.root.geometry("500x250")
24. self.root.resizable(0,0)
25.
26. self.page3 = tk.Frame(self.root)
27. self.page3.pack()
28.
29. tk.Label(self.page3,text="欢迎管理员"+self.user).grid(row=0,column=0)
30. tk.Button(self.page3,text="注册航空公司账号",command=self.add_air_plane_account_number).grid(row=1,column=0,pady=5,padx=5)
31. tk.Button(self.page3,text="删除航空公司账号",command=self.delete_air_plane_account_number).grid(row = 1,column=1,padx=5,pady=5)
32. tk.Button(self.page3,text="查看航空公司账号",command=self.check_airplane_account_number).grid(row = 1,column = 2,padx = 5,pady = 5)
33.
34. tk.Button(self.page3,text="注册旅客账号",command=self.add_customer_account_number).grid(row=2,column=0,pady=5,padx=5)
35. tk.Button(self.page3,text="删除旅客账号",command=self.delete_customer_account_number).grid(row=2,column=1,padx=5,pady=5)
36. tk.Button(self.page3,text="查看旅客账号",command=self.check_customer_account_number).grid(row = 2,column = 2,padx = 5,pady = 5)
37.
38. tk.Button(self.page3,text="注册旅行社账号",command=self.add_tourist_agency_account_number).grid(row=3,column=0,pady=5,padx=5)
39. tk.Button(self.page3,text="删除旅行社账号",command=self.delete_tourist_agency_account_number).grid(row=3,column=1,pady=5,padx=5)
40. tk.Button(self.page3,text="查看旅行社账号",command=self.check_tourist_agency_account_number).grid(row = 3,column = 2,padx = 5,pady = 5)
41.
42.
43. tk.Button(self.page3,text="注销用户",command=self.reback_login).grid(row=5,column=4,pady=5,padx=5)
44. tk.Button(self.page3,text="退出",command = self.close).grid(row=5,column=5,pady=5,padx=5)
45.
46. #-----------------------------添加航空公司账户----------------------------------------------------------#
47. def add_air_plane_account_number(self):
48.
49. self.root.geometry("400x400") #设置窗口的大小
50.
51. self.root.resizable(0,0)
52.
53. def close():
54. is_close = messagebox.askyesno("是否退出","是否真的退出")
55. if is_close:
56. self.page4.destroy()
57. self.root.destroy()
58.
59. def come_back_main_admin():
60. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回管理员界面")
61. if is_come_back_to_login:
62. self.page4.destroy()
63. self.createPage_admin()
64.
65. def sign_to_airplane():
66. new_name = new_user_name.get()
67. new_pwd = new_user_pwd.get()
68. new_pwd_confirm = new_user_pwd_confirm.get()
69. company_name = new_user_company_name.get()
70. company_number = new_user_company_number.get()
71.
72.
73.
74. #读取用户名,公司名,公司编号放入列表
75. result = Query_Table_ALL(Account_Table)
76. Account_User_list = list()
77. if result == None:
78. pass
79. else:
80. for row in result:
81. Account_User_list.append(row.User)
82.
83. C_No_result = Query_Table_ALL(Airline_Company_Table)
84. Company_No_list = list()
85. if C_No_result == None:
86. pass
87. else:
88. for row in C_No_result:
89. Company_No_list.append(row.No)
90. C_Name_result = Query_Table_ALL(Airline_Company_Table)
91. Company_Name_list = list()
92. if C_Name_result == None:
93. pass
94. else:
95. for row in C_Name_result:
96. Company_Name_list.append(row.Name)
97.
98.
99. if new_name == "":
100. new_user_pwd.set("")
101. new_user_pwd_confirm.set("")
102. new_user_company_name.set("")
103. new_user_company_number.set("")
104. messagebox.showerror(title = "错误",message = "请输入用户名")
105.
106. elif new_name != "" and (new_name in Account_User_list):#判断航空公司的用户名是否有相同
107. new_user_name.set("")
108. new_user_pwd.set("")
109. new_user_pwd_confirm.set("")
110. new_user_company_name.set("")
111. new_user_company_number.set("")
112. messagebox.showerror(title = "错误",message = "该用户名已被注册过")
113.
114.
115. elif new_pwd == "":
116. new_user_pwd_confirm.set("")
117. messagebox.showerror(title = "错误",message = "请输入密码")
118.
119. elif new_pwd_confirm == "":
120. messagebox.showerror(title = "错误",message = "请再次输入密码")
121.
122. elif new_pwd_confirm != new_pwd:
123. new_user_pwd.set("")
124. new_user_pwd_confirm.set("")
125. messagebox.showerror(title = "错误",message = "两次输入的密码不一致")
126.
127. elif company_name == "":#如果航空公司名为空
128. messagebox.showerror(title = "错误",message = "请输入航空公司名")
129.
130. elif company_name != "" and (company_name in Company_Name_list): #判断航空公司名是否重复
131. new_user_company_name.set("")
132. messagebox.showerror(title = "错误",message = "该公司名已被注册过")
133.
134. elif company_number == "":#如果航空公司编号为空
135. messagebox.showerror(title = "错误",message = "请输入航空公司编号")
136.
137.
138. elif company_number != "" and (company_number in Company_No_list): #判断航空公司编号是否重复
139. new_user_company_number.set("")
140. messagebox.showerror(title = "Error",message = "该公司编号已被注册过")
141.
142. else:
143. Account_Table.Insert_Account(new_name,new_pwd,company_number,'Company')
144. Airline_Company_Table.Insert_Company(company_number,company_name)
145.
146.
147.
148. messagebox.showinfo(title="注册成功",message = "航空公司账号注册成功")
149.
150. self.page4.destroy()
151.
152. new_user_name.set("")
153. new_user_pwd.set("")
154. new_user_pwd_confirm.set("")
155.
156. self.createPage_admin()
157.
158. self.page3.destroy()
159.
160. self.page4 = tk.Frame(self.root)
161. self.page4.pack()
162.
163. new_user_name = tk.StringVar()#航空公司账号用户名
164. new_user_pwd = tk.StringVar()#密码
165. new_user_pwd_confirm = tk.StringVar()#再次确认密码
166. new_user_company_name = tk.StringVar()#航空公司名字
167. new_user_company_number = tk.StringVar()#航空公司编号
168.
169. tk.Label(self.page4,text="添加航空公司账号").grid(row=0,stick=tk.W)
170.
171. tk.Label(self.page4,text = "账号用户名:").grid(row=1,pady=10,stick=tk.W)
172. tk.Entry(self.page4, textvariable=new_user_name).grid(row=1, column=1,stick = tk.E)
173.
174. tk.Label(self.page4, text ='账号密码:').grid(row=2, stick=tk.W, pady=10)
175. tk.Entry(self.page4, textvariable=new_user_pwd, show='*').grid(row=2, column=1, stick=tk.E)
176.
177. tk.Label(self.page4,text="再次确认密码:").grid(row=3,stick=tk.W,pady=10)
178. tk.Entry(self.page4,textvariable=new_user_pwd_confirm,show="*").grid(row=3,column=1,stick=tk.E)
179.
180. tk.Label(self.page4,text="航空公司名:").grid(row=4,stick=tk.W,pady=10)
181. tk.Entry(self.page4,textvariable=new_user_company_name).grid(row=4,column=1,stick=tk.E)
182.
183. tk.Label(self.page4,text="航空公司编号:").grid(row=5,stick=tk.W,pady=10)
184. tk.Entry(self.page4,textvariable=new_user_company_number).grid(row=5,column=1,stick=tk.E)
185.
186. tk.Button(self.page4, text="注册", command=sign_to_airplane).grid(row=6, column=0, pady=5)
187. tk.Button(self.page4, text='返回管理员界面', command=come_back_main_admin).grid(row=6, column=1, pady=5)
188. tk.Button(self.page4, text="退出", command=close).grid(row=6, column=4, pady=5)
189.
190. #------------------------------------删除航空公司账户-------------------------------------------------------#
191. def delete_air_plane_account_number(self):
192.
193. def close():
194. is_close = messagebox.askyesno("是否退出","是否真的退出")
195. if is_close:
196. self.page5.destroy()
197. self.root.destroy()
198.
199. def come_back_main_admin():
200. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回管理员界面?")
201. if is_come_back_to_login:
202. self.page5.destroy()
203. self.createPage_admin()
204.
205. def delete_airplane():
206. delete_user_name = user_name.get()
207. delete_user_pwd = user_pwd.get()
208.
209. result = Account_Table.Query_Account('Company')
210. Acccount_pwd_dict = dict()
211. Account_User_list = list()
212. if result == None:
213. pass
214. else:
215. for row in result:
216. Account_User_list.append(row.User)
217. Acccount_pwd_dict[row.User] = row.Password
218.
219.
220. if delete_user_name == "":#用户名为空
221. messagebox.showerror(title = "错误",message = "请输入要删除的用户名")
222.
223. elif delete_user_pwd == "":#密码为空
224. messagebox.showerror(title = "错误",message = "请输入该用户名的密码")
225.
226. elif delete_user_name not in Account_User_list:#用户名不存在
227. messagebox.showerror(title = "错误",message = "没有该用户名的航空公司账号")
228. user_name.set("")
229. user_pwd.set("")
230.
231. elif (delete_user_name in Account_User_list) and (delete_user_pwd != Acccount_pwd_dict[delete_user_name]):
232. messagebox.showerror(title = "错误",message = "密码错误")
233. user_name.set("")
234. user_pwd.set("")
235.
236. else:
237. Airline_Company_Table.Delete_Company_from_Account(delete_user_name)
238. Account_Table.Delete_Account(delete_user_name)
239.
240.
241. messagebox.showinfo(title="删除完成",message = "成功删除该航空公司账号")
242.
243. self.page5.destroy()
244.
245. user_name.set("")
246. user_pwd.set("")
247.
248. self.createPage_admin()
249.
250. self.page3.destroy()
251.
252. self.page5 = tk.Frame(self.root)
253. self.page5.pack()
254.
255. user_name = tk.StringVar()
256. user_pwd = tk.StringVar()
257.
258. tk.Label(self.page5,text="删除航空公司账号").grid(row=0,stick=tk.W)
259.
260. tk.Label(self.page5,text = "账号用户名:").grid(row=1,pady=10,stick=tk.W)
261. tk.Entry(self.page5, textvariable=user_name).grid(row=1, column=1,stick = tk.E)
262.
263. tk.Label(self.page5, text = '账号密码:').grid(row=2, stick=tk.W, pady=10)
264. tk.Entry(self.page5, textvariable=user_pwd, show='*').grid(row=2, column=1, stick=tk.E)
265.
266. tk.Button(self.page5, text="删除", command=delete_airplane).grid(row=3, column=0, pady=5)
267. tk.Button(self.page5, text='返回管理员界面', command=come_back_main_admin).grid(row=3, column=1, pady=5)
268. tk.Button(self.page5, text="退出", command=close).grid(row=3, column=4, pady=5)
269.
270. #--------------------------------查询航空公司账户------------------------------------------------#
271. def check_airplane_account_number(self):
272.
273. def close_this_window():
274. window_sign_up.destroy()
275.
276.
277. window_sign_up = tk.Toplevel(self.page3)
278. window_sign_up.geometry("350x200")
279. window_sign_up.title("查看航空公司账号")
280. window_sign_up.resizable(0,0)
281.
282.
283. Account_Company = Account_Table.Query_Account("Company")
284. Ac_dict = dict()
285. if Account_Company == None:
286. pass
287. else:
288. for row in Account_Company:
289. Ac_dict[row.User] = row.Password
290.
291. len_Ac = len(Ac_dict)
292.
293. str2=str()
294. for each in Ac_dict:
295. str2=str2+"账号:"+each+" "
296. str2 = str2+"密码:"+Ac_dict[each]+"\n"
297.
298. str1 = str("一共有%d个账户是航空公司的账号" %len_Ac)
299.
300. tk.Label(window_sign_up,text=str1).place(x=85,y=0)
301. tk.Label(window_sign_up,text=str2).place(x=90,y=30)
302.
303. tk.Button(window_sign_up,text="OK",command=close_this_window).pack(side=tk.BOTTOM)
304.
305. #----------------------------------添加旅客账号----------------------------------------------------------
306. def add_customer_account_number(self):
307.
308. self.root.geometry("400x400") #设置窗口的大小
309.
310. self.root.resizable(0,0)
311.
312. def close():
313. is_close = messagebox.askyesno("是否退出","是否真的退出")
314. if is_close:
315. self.page6.destroy()
316. self.root.destroy()
317.
318. def come_back_main_admin():
319. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回管理员界面")
320. if is_come_back_to_login:
321. self.page6.destroy()
322. self.createPage_admin()
323.
324. def sign_to_customer():
325.
326. def check_id(new_id):#判断身份证号是否正确函数
327. if len(new_id) != 18:#如果身份证号码不是18位
328. return 0
329. elif new_id[0:2] not in ["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65"]:
330. return 0
331. else:
332. return 1
333.
334. new_name = new_user_name.get()
335.
336. new_pwd = new_user_pwd.get()
337.
338. new_pwd_confirm = new_user_pwd_confirm.get()
339.
340. new_id = new_user_id.get()#获取旅客身份证
341.
342.
343. #读取用户名,身份证放入列表
344. result = Query_Table_ALL(Account_Table)
345. Account_User_list = list()
346. if result == None:
347. pass
348. else:
349. for row in result:
350. Account_User_list.append(row.User)
351.
352. ID_result = Account_Table.Query_Account('Customer')
353. ID_list = list()
354. if ID_result == None:
355. pass
356. else:
357. for row in ID_result:
358. ID_list.append(row.ID_Number)
359.
360. if new_name == "":
361. new_user_name.set("")
362. new_user_pwd.set("")
363. new_user_pwd_confirm.set("")
364. new_user_id.set("")
365. messagebox.showerror(title = "错误",message = "请输入用户名")
366.
367. elif new_name != "" and (new_name in Account_User_list):
368. new_user_name.set("")
369. new_user_pwd.set("")
370. new_user_pwd_confirm.set("")
371. new_user_id.set("")
372. messagebox.showerror(title = "错误",message = "该用户名已被注册过")
373.
374. elif new_pwd == "":
375. new_user_pwd_confirm.set("")
376. messagebox.showerror(title = "错误",message = "请输入密码")
377.
378. elif new_pwd_confirm == "":
379. messagebox.showerror(title = "错误",message = "请再次输入密码")
380.
381. elif new_pwd_confirm != new_pwd:
382. new_user_pwd.set("")
383. new_user_pwd_confirm.set("")
384. messagebox.showerror(title = "错误",message = "两次输入的密码不一致")
385.
386. elif new_id == "":#如果旅客身份证号没有输入
387. messagebox.showerror(title = "错误",message = "请输入旅客身份证")
388.
389. elif new_id != "" and (new_id in ID_list):#在这里判断身份证是否已经注册过,谢了
390. new_user_id.set("")
391. messagebox.showerror(title = "错误",message = "该身份证已被注册过")
392.
393. else:
394. print("旅客账号用户名:"+new_name)
395. print("旅客账号密码:"+new_pwd)
396. print("再次确认的密码:"+new_pwd_confirm)
397. print("旅客身份证号:"+new_id)
398.
399. Account_Table.Insert_Account(new_name,new_pwd,new_id,'Customer')
400.
401. messagebox.showinfo(title="注册成功",message = "旅客账户注册成功!")
402.
403. self.page6.destroy()
404.
405. new_user_name.set("")
406. new_user_pwd.set("")
407. new_user_pwd_confirm.set("")
408.
409. self.createPage_admin()
410.
411. self.page3.destroy()
412.
413. self.page6 = tk.Frame(self.root)
414. self.page6.pack()
415.
416. new_user_name = tk.StringVar()#旅客账号用户名
417. new_user_pwd = tk.StringVar()#旅客账号密码
418. new_user_pwd_confirm = tk.StringVar()#再次确认的密码
419. new_user_id = tk.StringVar()#旅客账号ID
420.
421. tk.Label(self.page6,text="注册旅客账号").grid(row=0,stick=tk.W)
422.
423. tk.Label(self.page6,text = "账号用户名:").grid(row=1,pady=10,stick=tk.W)
424. tk.Entry(self.page6, textvariable=new_user_name).grid(row=1, column=1,stick = tk.E)
425.
426. tk.Label(self.page6, text = '账号密码:').grid(row=2, stick=tk.W, pady=10)
427. tk.Entry(self.page6, textvariable=new_user_pwd, show='*').grid(row=2, column=1, stick=tk.E)
428.
429. tk.Label(self.page6,text="再次确认密码:").grid(row=3,stick=tk.W,pady=10)
430. tk.Entry(self.page6,textvariable=new_user_pwd_confirm,show="*").grid(row=3,column=1,stick=tk.E)
431.
432. tk.Label(self.page6,text="旅客身份证:").grid(row=4,column=0,stick=tk.W,pady=10)
433. tk.Entry(self.page6,textvariable = new_user_id).grid(row=4,column=1,stick=tk.E)
434.
435. tk.Button(self.page6, text="注册", command=sign_to_customer).grid(row=5, column=0, pady=5)
436. tk.Button(self.page6, text='返回管理员界面', command=come_back_main_admin).grid(row=5, column=1, pady=5)
437. tk.Button(self.page6, text="退出", command=close).grid(row=5, column=2, pady=5)
438.
439. #--------------------------------删除旅客账号------------------------------------------------------
440. def delete_customer_account_number(self):
441.
442. def close():
443. is_close = messagebox.askyesno("是否退出","是否真的退出")
444. if is_close:
445. self.page7.destroy()
446. self.root.destroy()
447.
448. def come_back_main_admin():
449. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回管理员界面")
450. if is_come_back_to_login:
451. self.page7.destroy()
452. self.createPage_admin()
453.
454. def delete_customer():
455. delete_user_name = user_name.get()
456. delete_user_pwd = user_pwd.get()
457.
458. result = Account_Table.Query_Account('Customer')
459. Acccount_pwd_dict = dict()
460. Account_User_list = list()
461. if result == None:
462. pass
463. else:
464. for row in result:
465. Account_User_list.append(row.User)
466. Acccount_pwd_dict[row.User] = row.Password
467.
468. if delete_user_name == "":
469. messagebox.showerror(title = "错误",message = "请输入要删除的用户名")
470.
471. elif delete_user_pwd == "":
472. messagebox.showerror(title = "错误",message = "请输入该用户名的密码")
473.
474. elif delete_user_name not in Account_User_list:
475. messagebox.showerror(title = "错误",message = "没有该用户名的旅客账号")
476. user_name.set("")
477. user_pwd.set("")
478.
479. elif (delete_user_name in Account_User_list) and (delete_user_pwd != Acccount_pwd_dict[delete_user_name]):
480. messagebox.showerror(title = "错误",message = "密码错误")
481. user_name.set("")
482. user_pwd.set("")
483.
484. else:
485. Account_Table.Delete_Account(delete_user_name)
486.
487. messagebox.showinfo(title="删除完成",message = "成功删除该旅客账号")
488.
489. self.page7.destroy()
490.
491. user_name.set("")
492. user_pwd.set("")
493.
494. self.createPage_admin()
495.
496.
497.
498. self.page3.destroy()
499.
500. self.page7 = tk.Frame(self.root)
501. self.page7.pack()
502.
503. user_name = tk.StringVar()
504. user_pwd = tk.StringVar()
505.
506. tk.Label(self.page7,text="删除旅客账号").grid(row=0,stick=tk.W)
507.
508. tk.Label(self.page7,text = "账号用户名:").grid(row=1,pady=10,stick=tk.W)
509. tk.Entry(self.page7, textvariable=user_name).grid(row=1, column=1,stick = tk.E)
510.
511. tk.Label(self.page7, text = '账号密码:').grid(row=2, stick=tk.W, pady=10)
512. tk.Entry(self.page7, textvariable=user_pwd, show='*').grid(row=2, column=1, stick=tk.E)
513.
514. tk.Button(self.page7, text="删除", command=delete_customer).grid(row=3, column=0, pady=5)
515. tk.Button(self.page7, text='返回管理员界面', command=come_back_main_admin).grid(row=3, column=1, pady=5)
516. tk.Button(self.page7, text="退出", command=close).grid(row=3, column=4, pady=5)
517.
518. #------------------------------查询旅客账号-----------------------------------------------------
519. def check_customer_account_number(self):
520. def close_this_window():
521. window_sign_up.destroy()
522.
523. window_sign_up = tk.Toplevel(self.page3)
524. window_sign_up.geometry("350x200")
525. window_sign_up.title("查看旅客账号")
526. window_sign_up.resizable(0,0)
527.
528.
529. Account_Company = Account_Table.Query_Account("Customer")
530. Ac_dict = dict()
531. if Account_Company == None:
532. pass
533. else:
534. for row in Account_Company:
535. Ac_dict[row.User] = row.Password
536.
537. len_Ac = len(Ac_dict)
538.
539. str2=str()
540. for each in Ac_dict:
541. str2=str2+"账号:"+each+" "
542. str2 = str2+"密码:"+Ac_dict[each]+"\n"
543.
544. str1 = str("一共有%d个账户是旅客的账号" %len_Ac)
545.
546. tk.Label(window_sign_up,text=str1).place(x=85,y=0)
547. tk.Label(window_sign_up,text=str2).place(x=90,y=30)
548.
549. tk.Button(window_sign_up,text="OK",command=close_this_window).pack(side=tk.BOTTOM)
550.
551. #--------------------------------------添加旅行社账号----------------------------------------------
552. def add_tourist_agency_account_number(self):
553.
554. self.root.geometry("400x400") #设置窗口的大小
555.
556. self.root.resizable(0,0)
557.
558. def close():
559. is_close = messagebox.askyesno("是否退出","是否真的退出")
560. if is_close:
561. self.page8.destroy()
562. self.root.destroy()
563.
564. def come_back_main_admin():
565. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回管理员界面")
566. if is_come_back_to_login:
567. self.page8.destroy()
568. self.createPage_admin()
569.
570. def sign_to_customer():
571. new_name = new_user_name.get()
572. new_pwd = new_user_pwd.get()
573. new_pwd_confirm = new_user_pwd_confirm.get()
574. company_name = new_user_company_name.get()
575. company_number = new_user_company_number.get()
576.
577. #读取用户名,旅行社名,旅行社编号放入列表
578. result = Query_Table_ALL(Account_Table)
579. Account_User_list = list()
580. if result == None:
581. pass
582. else:
583. for row in result:
584. Account_User_list.append(row.User)
585.
586. T_agency_No_result = Query_Table_ALL(Travel_Agency_Table)
587. T_agency_No_list = list()
588. if T_agency_No_result == None:
589. pass
590. else:
591. for row in T_agency_No_result:
592. T_agency_No_list.append(row.No)
593.
594. T_agency_Name_result = Query_Table_ALL(Travel_Agency_Table)
595. T_agency_Name_list = list()
596. if T_agency_Name_result == None:
597. pass
598. else:
599. for row in T_agency_Name_result:
600. T_agency_Name_list.append(row.Name)
601.
602. if new_name == "":
603. new_user_pwd.set("")
604. new_user_pwd_confirm.set("")
605. new_user_company_name.set("")
606. new_user_company_number.set("")
607. messagebox.showerror(title = "错误",message = "请输入用户名")
608.
609. elif new_name != "" and (new_name in Account_User_list):
610. new_user_name.set("")
611. new_user_pwd.set("")
612. new_user_pwd_confirm.set("")
613. new_user_company_name.set("")
614. new_user_company_number.set("")
615. messagebox.showerror(title = "错误",message = "该用户名已被注册过")
616.
617. elif new_pwd == "":
618. new_user_pwd_confirm.set("")
619. messagebox.showerror(title = "错误",message = "请输入密码")
620.
621. elif new_pwd_confirm == "":
622. messagebox.showerror(title = "错误",message = "请再次输入密码")
623.
624. elif new_pwd_confirm != new_pwd:
625. new_user_pwd.set("")
626. new_user_pwd_confirm.set("")
627. messagebox.showerror(title = "错误",message = "两次输入的密码不一致")
628.
629. elif company_name == "":#如果旅行社名为空
630. messagebox.showerror(title = "错误",message = "请输入旅行社名")
631.
632. elif company_name != "" and (company_name in T_agency_Name_list): #判断旅行社名是否重复
633. new_user_company_name.set("")
634. messagebox.showerror(title = "错误",message = "该旅行社名已被注册过")
635.
636. elif company_number == "":#如果旅行社编号为空
637. messagebox.showerror(title = "错误",message = "请输入旅行社编号")
638.
639. elif company_number != "" and (company_number in T_agency_No_list): #判断旅行社编号是否重复
640. new_user_company_number.set("")
641. messagebox.showerror(title = "错误",message = "该旅行社编号已被注册过")
642.
643. else:
644. Account_Table.Insert_Account(new_name,new_pwd,company_number,'T_agency')
645. Travel_Agency_Table.Insert_Travel_Agency(company_number,company_name)
646.
647. messagebox.showinfo(title="注册成功",message = "旅行社账号注册成功")
648.
649. self.page8.destroy()
650.
651. new_user_name.set("")
652. new_user_pwd.set("")
653. new_user_pwd_confirm.set("")
654.
655. self.createPage_admin()
656.
657. self.page3.destroy()
658.
659. self.page8 = tk.Frame(self.root)
660. self.page8.pack()
661.
662. new_user_name = tk.StringVar()#旅行社账号用户名
663. new_user_pwd = tk.StringVar()#密码
664. new_user_pwd_confirm = tk.StringVar()#再次确认密码
665. new_user_company_name = tk.StringVar()#旅行社名字
666. new_user_company_number = tk.StringVar()#旅行社编号
667.
668. tk.Label(self.page8,text="添加旅行社账号").grid(row=0,stick=tk.W)
669.
670. tk.Label(self.page8,text = "账号用户名:").grid(row=1,pady=10,stick=tk.W)
671. tk.Entry(self.page8, textvariable=new_user_name).grid(row=1, column=1,stick = tk.E)
672.
673. tk.Label(self.page8, text = '账号密码:').grid(row=2, stick=tk.W, pady=10)
674. tk.Entry(self.page8, textvariable=new_user_pwd, show='*').grid(row=2, column=1, stick=tk.E)
675.
676. tk.Label(self.page8,text="再次确认密码:").grid(row=3,stick=tk.W,pady=10)
677. tk.Entry(self.page8,textvariable=new_user_pwd_confirm,show="*").grid(row=3,column=1,stick=tk.E)
678.
679. tk.Label(self.page8,text="旅行社名字:").grid(row=4,stick=tk.W,pady=10)
680. tk.Entry(self.page8,textvariable=new_user_company_name).grid(row=4,column=1,stick=tk.E)
681.
682. tk.Label(self.page8,text="旅行社编号:").grid(row=5,stick=tk.W,pady=10)
683. tk.Entry(self.page8,textvariable=new_user_company_number).grid(row=5,column=1,stick=tk.E)
684.
685. tk.Button(self.page8, text="注册", command=sign_to_customer).grid(row=6, column=0, pady=5)
686. tk.Button(self.page8, text='返回管理员界面', command=come_back_main_admin).grid(row=6, column=1, pady=5)
687. tk.Button(self.page8, text="退出", command=close).grid(row=6, column=4, pady=5)
688.
689. #-----------------------------删除旅行社账号----------------------------------------------------
690. def delete_tourist_agency_account_number(self):
691.
692. def close():
693. is_close = messagebox.askyesno("是否退出","是否真的退出")
694. if is_close:
695. self.page9.destroy()
696. self.root.destroy()
697.
698. def come_back_main_admin():
699. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回管理员界面")
700. if is_come_back_to_login:
701. self.page9.destroy()
702. self.createPage_admin()
703.
704. def delete_tourist_agency():
705. delete_user_name = user_name.get()
706. delete_user_pwd = user_pwd.get()
707.
708. result = Account_Table.Query_Account('T_agency')
709. Acccount_pwd_dict = dict()
710. Account_User_list = list()
711. if result == None:
712. pass
713. else:
714. for row in result:
715. Account_User_list.append(row.User)
716. Acccount_pwd_dict[row.User] = row.Password
717. print(Acccount_pwd_dict)
718.
719. if delete_user_name == "":
720. messagebox.showerror(title = "错误",message = "请输入要删除的用户名")
721.
722. elif delete_user_pwd == "":
723. messagebox.showerror(title = "错误",message = "请输入该用户名的密码")
724.
725. elif delete_user_name not in Account_User_list:
726. messagebox.showerror(title = "错误",message = "没有该用户名的旅客账号")
727. user_name.set("")
728. user_pwd.set("")
729.
730. elif (delete_user_name in Account_User_list) and (delete_user_pwd != Acccount_pwd_dict[delete_user_name]):
731. messagebox.showerror(title = "错误",message = "密码错误")
732. user_name.set("")
733. user_pwd.set("")
734.
735. else:
736. Travel_Agency_Table.Delete_Travel_Agency_from_Account(delete_user_name)
737. Account_Table.Delete_Account(delete_user_name)
738.
739.
740. messagebox.showinfo(title="删除完成",message = "成功删除该旅客账号")
741.
742. self.page9.destroy()
743.
744. user_name.set("")
745. user_pwd.set("")
746.
747. self.createPage_admin()
748.
749.
750.
751. self.page3.destroy()
752.
753. self.page9 = tk.Frame(self.root)
754. self.page9.pack()
755.
756. user_name = tk.StringVar()
757. user_pwd = tk.StringVar()
758.
759. tk.Label(self.page9,text="删除旅行社账号").grid(row=0,stick=tk.W)
760.
761. tk.Label(self.page9,text = "用户账号名:").grid(row=1,pady=10,stick=tk.W)
762. tk.Entry(self.page9, textvariable=user_name).grid(row=1, column=1,stick = tk.E)
763.
764. tk.Label(self.page9, text = '账户密码:').grid(row=2, stick=tk.W, pady=10)
765. tk.Entry(self.page9, textvariable=user_pwd, show='*').grid(row=2, column=1, stick=tk.E)
766.
767. tk.Button(self.page9, text="删除", command=delete_tourist_agency).grid(row=3, column=0, pady=5)
768. tk.Button(self.page9, text='返回管理员界面', command=come_back_main_admin).grid(row=3, column=1, pady=5)
769. tk.Button(self.page9, text="退出", command=close).grid(row=3, column=4, pady=5)
770.
771. #---------------------------查询旅行社账号-----------------------------------------------------------------
772. def check_tourist_agency_account_number(self):
773. def close_this_window():
774. window_sign_up.destroy()
775.
776. window_sign_up = tk.Toplevel(self.page3)
777. window_sign_up.geometry("350x200")
778. window_sign_up.title("查看旅行社账号")
779. window_sign_up.resizable(0,0)
780.
781. Account_T_agency = Account_Table.Query_Account("T_agency")
782. Ac_dict = dict()
783. if Account_T_agency == None:
784. pass
785. else:
786. for row in Account_T_agency:
787. Ac_dict[row.User] = row.Password
788.
789. len_Ac = len(Ac_dict)
790.
791. str2=str()
792. for each in Ac_dict:
793. str2=str2+"账号:"+each+" "
794. str2 = str2+"密码:"+Ac_dict[each]+"\n"
795.
796.
797. str1 = str("一共有%d个账户是旅行社的账号" %len_Ac)
798.
799. tk.Label(window_sign_up,text=str1).place(x=85,y=0)
800. tk.Label(window_sign_up,text=str2).place(x=90,y=30)
801.
802. tk.Button(window_sign_up,text="OK",command=close_this_window).pack(side=tk.BOTTOM)
803.
804. def close(self):
805. is_close = messagebox.askyesno("是否退出","是否真的退出")
806. if is_close:
807. self.page3.destroy()
808. self.root.destroy()
809.
810. def reback_login(self):
811. is_reback_login = messagebox.askyesno("是否注销","是否注销并返回登录界面")
812. if is_reback_login:
813. self.page3.destroy()
814. Login.LoginPage(self.root)
3.3 航空公司界面
客户公司界面也是创造了一个类, 在类的构造函数里面设置好框的大小,然后调用createPage函数创造各个tkinter的部件。并且创建出方法:添加航班信息,删除航班信息,修改航班信息,查询航班信息。
1. # -*- coding: utf-8 -*-
2. """
3. Created on Thu May 28 23:27:00 2020
4.
5. """
6.
7. import interface
8. from interface import Account_Table, Passenger_Table, Airline_Company_Table, Travel_Agency_Table, Flight_Information_Table, Order_information_table, Query_Table_ALL
9.
10. import tkinter as tk
11. import LoginPage as Login
12. import tkinter.messagebox as messagebox
13. import pickle
14.
15.
16. class Airplane_Mainpage(object):
17. def __init__(self,master = None,usrs = None):
18. self.root = master #定义内部变量root
19.
20. self.user = usrs
21. print(self.user)
22.
23. self.createPage_airplane()
24.
25. def createPage_airplane(self):
26. self.root.geometry("500x550")
27. self.root.resizable(0,0)
28.
29. self.page11 = tk.Frame(self.root)
30. self.page11.pack()
31.
32. tk.Label(self.page11,text="欢迎来到航空公司界面!用户:"+self.user).grid(row=0,column=0)
33.
34. tk.Button(self.page11,text="增加航班信息",command=self.add_plane).grid(row=1,column = 0,padx=5,pady=5)
35. tk.Button(self.page11,text="删除航班信息",command=self.delete_plane).grid(row=1,column = 1,padx=5,pady=5)
36.
37. tk.Button(self.page11,text="修改航班信息",command = self.change_plane).grid(row = 2,column = 0,padx=5,pady=5)
38. tk.Button(self.page11,text="查看航班信息",command = self.check_plane_information).grid(row = 2,column = 1,padx=5,pady=5)
39.
40. tk.Button(self.page11,text="注销用户",command = self.comeback).grid(row = 3,column = 0, padx=5,pady=5)
41. tk.Button(self.page11,text="退出",command = self.close).grid(row = 3,column = 1, padx=5,pady=5)
42.
43. #----------------------添加航班信息--------------------------------------------------------------------
44. def add_plane(self):
45.
46. def confirm():
47. ID = plane_id.get()
48. start_place = plane_start_place.get()
49. end_place = plane_end_place.get()
50. Type = plane_type.get()
51. numbers = plane_numbers.get()
52. start_time = plane_start_time.get()
53. end_time = plane_end_time.get()
54. price = plane_price.get()
55.
56.
57. #查询该账号的ID,并生成旅客ID列表
58. ares = Account_Table.Query_Account('Company')
59. AC_ID = ''
60. for row in ares :
61. if self.user == row.User:
62. AC_ID = row.ID_Number
63. result = Flight_Information_Table.Query_Flight(AC_ID)
64. FNOlist = list()
65. for row in result:
66. FNOlist.append(row.Flight_no)
67. print(row.Flight_no,
68. row.air_company_No,
69. row.origin,
70. row.destination,
71. row.Aircraft_type,
72. #row.Num_p,
73. row.scheduled_start_time,
74. row.scheduled_arrival_time)
75. print("&")
76. print(FNOlist)
77.
78.
79. if ID == "":
80. messagebox.showerror(title="错误",message="航班编号没有填写!")
81. plane_id.set("")
82. plane_start_place.set("")
83. plane_end_place.set("")
84. plane_type.set("")
85. plane_numbers.set("")
86. plane_start_time.set("")
87. plane_end_time.set("")
88.
89. elif ID in FNOlist:#航班号码重复
90. messagebox.showerror(title="错误",message="该航班号码已存在")
91. plane_id.set("")
92. plane_start_place.set("")
93. plane_end_place.set("")
94. plane_type.set("")
95. plane_numbers.set("")
96. plane_start_time.set("")
97. plane_end_time.set("")
98.
99. elif start_place == "":
100. messagebox.showerror(title="错误",message="航班始发地没有填写!")
101. plane_start_place.set("")
102. plane_end_place.set("")
103. plane_type.set("")
104. plane_numbers.set("")
105. plane_start_time.set("")
106. plane_end_time.set("")
107.
108. elif end_place== "":
109. messagebox.showerror(title="错误",message="航班目的地没有填写!")
110. plane_end_place.set("")
111. plane_type.set("")
112. plane_numbers.set("")
113. plane_start_time.set("")
114. plane_end_time.set("")
115.
116. elif Type == "":
117. messagebox.showerror(title="错误",message="航班机型没有填写!")
118. plane_type.set("")
119. plane_numbers.set("")
120. plane_start_time.set("")
121. plane_end_time.set("")
122.
123. elif numbers == "":
124. messagebox.showerror(title="错误",message="航班乘客数没有填写!")
125. plane_numbers.set("")
126. plane_start_time.set("")
127. plane_end_time.set("")
128.
129. elif start_time =="":
130. messagebox.showerror(title="Error",message="航班起飞时间没有填写!")
131. plane_start_time.set("")
132. plane_end_time.set("")
133.
134. elif len(start_time) != 16 or (start_time[4] != "-" and start_time[7] != "-" and start_time[13] != ":"):#2020-01-31 10:30
135. messagebox.showerror(title="错误",message="航班起飞时间格式不正确 格式不正确")
136. plane_start_time.set("")
137. plane_end_time.set("")
138.
139. elif start_time[5:7] not in ["01","02","03","04","05","06","07","08","09","10","11","12"]:
140. messagebox.showerror(title="错误",message="航班起飞时间格式不正确 月份填写错误")
141. plane_start_time.set("")
142. plane_end_time.set("")
143.
144. elif (start_time[5:7] in ["01","03","05","07","08","10","12"]) and (start_time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]):
145. messagebox.showerror(title="错误",message="航班起飞时间格式不正确 大月")
146. plane_start_time.set("")
147. plane_end_time.set("")
148.
149. elif (start_time[5:7] in ["04","06","09","11"]) and (start_time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"]):
150. messagebox.showerror(title="错误",message="航班起飞时间格式不正确 小月")
151. plane_start_time.set("")
152. plane_end_time.set("")
153.
154. elif (start_time[5:7] in ["02"]) and (start_time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29"]):
155. messagebox.showerror(title="错误",message="航班起飞时间格式不正确 闰年")
156. plane_start_time.set("")
157. plane_end_time.set("")
158.
159. elif start_time[11:13] not in ["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"]:
160. messagebox.showerror(title="错误",message="航班起飞时间格式不正确 小时")
161. plane_start_time.set("")
162. plane_end_time.set("")
163.
164. elif start_time[14:16] not in ["00","01","02","03","04","05","06","07","08","09","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"]:
165. messagebox.showerror(title="错误",message="航班起飞时间格式不正确 分钟")
166. plane_start_time.set("")
167. plane_end_time.set("")
168.
169. elif end_time == "":
170. messagebox.showerror(title="Error",message="航班预计到达时间没有填写!")
171. plane_end_time.set("")
172.
173. elif len(end_time) != 16 or (end_time[4] != "-" and end_time[7] != "-" and end_time[13] != ":"):#2020-01-31 10:30
174. messagebox.showerror(title="错误",message="航班预计到达时间格式不正确 格式不正确")
175. plane_end_time.set("")
176.
177. elif end_time[5:7] not in ["01","02","03","04","05","06","07","08","09","10","11","12"]:
178. messagebox.showerror(title="错误",message="航班预计到达时间格式不正确 月份填写错误")
179. plane_end_time.set("")
180.
181. elif (end_time[5:7] in ["01","03","05","07","08","10","12"]) and (end_time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]):
182. messagebox.showerror(title="错误",message="航班预计到达时间格式不正确 大月")
183. plane_end_time.set("")
184.
185. elif (end_time[5:7] in ["04","06","09","11"]) and (end_time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"]):
186. messagebox.showerror(title="错误",message="航班预计到达时间格式不正确 小月")
187. plane_end_time.set("")
188.
189. elif (end_time[5:7] in ["02"]) and (end_time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29"]):
190. messagebox.showerror(title="错误",message="航班预计到达时间格式不正确 闰年")
191. plane_end_time.set("")
192.
193. elif end_time[11:13] not in ["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"]:
194. messagebox.showerror(title="错误",message="航班预计到达时间格式不正确 小时")
195. plane_end_time.set("")
196.
197. elif end_time[14:16] not in ["00","01","02","03","04","05","06","07","08","09","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"]:
198. messagebox.showerror(title="错误",message="航班预计到达时间格式不正确 分钟")
199. plane_end_time.set("")
200.
201.
202. elif end_time == start_time:
203. messagebox.showerror(title="错误",message="航班预计到达时间不能与航班起飞时间相同")
204. plane_end_time.set("")
205.
206. elif price == "":
207. messagebox.showerror(title="错误",message="请填写价格")
208. plane_price.set("")
209.
210. else:
211. Flight_Information_Table.Insert_Flight(ID,AC_ID,start_place,end_place,Type, numbers,start_time,end_time,price)
212.
213. #查询乘客
214. C_result = Query_Table_ALL(Passenger_Table)
215. C_NO_list = list()#乘客身份证列表
216. C_Tdict = dict()#乘客出发时间字典
217. C_S_Pdict = dict()#乘客始发地字典
218. C_E_Pdict = dict()#乘客目的地字典
219. CFdict = dict()#乘客航班号
220. sit_num = 0#已有乘客数
221. now_Num = 0#安排乘客数
222. for row in C_result:
223. Num = int(numbers)
224.
225. if row.Flight_No == ID:
226. sit_num += 1
227. C_ID = row.ID_Card_Number
228. C_NO_list.append(C_ID)
229. C_Tdict[C_ID] = row.travel_time
230. C_S_Pdict[C_ID] = row.place_travel_start
231. C_E_Pdict[C_ID] = row.place_travel_end
232. CFdict[C_ID] = row.Flight_No
233. print(C_ID)
234. print(C_S_Pdict)
235. print(start_place)
236.
237. if CFdict[C_ID] == '-1' and C_Tdict[C_ID] == start_time[:10] and C_S_Pdict[C_ID] == start_place and C_E_Pdict[C_ID] == end_place and sit_num < Num:
238. print("匹配成功")
239. Passenger_Table.Update_Passenger(C_ID,8,ID)
240. now_Num += 1
241. else:
242. print("匹配失败")
243. pass
244.
245.
246. messagebox.showinfo(title="添加成功",message = "已为%d个乘客安排航班"%now_Num)
247.
248. messagebox.showinfo(title="操作成功",message = "增加航班信息成功!")
249. self.page12.destroy()
250. self.createPage_airplane()
251.
252. def comeback():
253. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回航空公司界面")
254. if is_come_back_to_login:
255. self.page12.destroy()
256. self.createPage_airplane()
257.
258. def close():
259. is_close = messagebox.askyesno("是否退出","是否真的退出")
260. if is_close:
261. self.page12.destroy()
262. self.root.destroy()
263.
264. self.page11.destroy()
265.
266. self.page12 = tk.Frame(self.root)
267. self.page12.pack()
268.
269. plane_id = tk.StringVar()#航班编号
270. plane_start_place = tk.StringVar()#航班始发地
271. plane_end_place = tk.StringVar()#航班目的地
272. plane_type = tk.StringVar()#航班机型
273. plane_numbers= tk.StringVar()#航班乘客数
274. plane_start_time = tk.StringVar()#航班起飞时间
275. plane_end_time = tk.StringVar()#航班预计到达时间
276. plane_price = tk.StringVar()#航班价格
277.
278.
279. tk.Label(self.page12,text="增加航班界面").grid(row=0,stick=tk.W)
280.
281. tk.Label(self.page12,text="航班编号:").grid(row=1,pady=10,stick=tk.W)
282. tk.Entry(self.page12, textvariable=plane_id).grid(row=1, column=1,stick = tk.E)
283.
284. tk.Label(self.page12,text="航班始发地:").grid(row=2,pady=10,stick=tk.W)
285. tk.Entry(self.page12, textvariable=plane_start_place).grid(row=2, column=1,stick = tk.E)
286.
287. tk.Label(self.page12,text="航班目的地:").grid(row=3,pady=10,stick=tk.W)
288. tk.Entry(self.page12, textvariable=plane_end_place).grid(row=3, column=1,stick = tk.E)
289.
290. tk.Label(self.page12,text="航班机型:").grid(row=4,pady=10,stick=tk.W)
291. tk.Entry(self.page12, textvariable=plane_type).grid(row=4, column=1,stick = tk.E)
292.
293. tk.Label(self.page12,text="航班乘客数:").grid(row=5,pady=10,stick=tk.W)
294. tk.Entry(self.page12, textvariable=plane_numbers).grid(row=5, column=1,stick = tk.E)
295.
296. tk.Label(self.page12,text="航班起飞时间:").grid(row=6,pady=10,stick=tk.W)
297. tk.Entry(self.page12, textvariable=plane_start_time).grid(row=6, column=1,stick = tk.E)
298.
299. tk.Label(self.page12,text="航班预计达到时间:").grid(row=7,pady=10,stick=tk.W)
300. tk.Entry(self.page12, textvariable=plane_end_time).grid(row=7, column=1,stick = tk.E)
301.
302. tk.Label(self.page12,text="航班价格:").grid(row=8,pady=10,stick=tk.W)
303. tk.Entry(self.page12, textvariable=plane_price).grid(row=8, column=1,stick = tk.E)
304.
305. tk.Button(self.page12, text='确定', command=confirm).grid(row=9, column=0, padx=5,pady=5)
306.
307. tk.Button(self.page12, text='返回', command=comeback).grid(row=9, column=1, padx=5,pady=5)
308.
309. tk.Button(self.page12,text = "退出",command = close).grid(row=10, column=0, padx=5,pady=5)
310.
311. tk.Label(self.page12,text="航班起飞时间格式:2020-01-31 10:00").grid(row=12,pady=10,stick=tk.W)
312. tk.Label(self.page12,text="航班预计达到时间格式:2020-01-31 10:00").grid(row=13,pady=10,stick=tk.W)
313.
314. #---------------------------------------删除航班---------------------------------------------------------------------------------------------
315. def delete_plane(self):
316.
317. def confirm():
318.
319. F_NO = delete_num.get()
320.
321. #查询该账号的ID,并生成航班No列表
322. ares = Account_Table.Query_Account('Company')
323. AC_ID = ''
324. for row in ares :
325. if self.user == row.User:
326. AC_ID = row.ID_Number
327. #print("*")
328. #print(AC_ID)
329. result = Flight_Information_Table.Query_Flight(AC_ID)
330. FNOlist = list()
331. for row in result:
332. FNOlist.append(row.Flight_no)
333. print(row.Flight_no,
334. row.air_company_No,
335. row.origin,
336. row.destination,
337. row.Aircraft_type,
338. row.Num_P,
339. row.scheduled_start_time,
340. row.scheduled_arrival_time)
341. print("&")
342. print(F_NO)
343. print(FNOlist)
344.
345. if F_NO == '':
346. messagebox.showerror(title="错误",message="请输入航班编号")
347. elif F_NO not in FNOlist :
348. print("无此航班")
349. messagebox.showerror(title="错误",message="没有符合该航班编号的航班")
350. else:#无法跳转到删除语句
351. #查询乘客
352. C_result = Query_Table_ALL(Passenger_Table)
353. C_NO_list = list()#乘客身份证列表
354. now_num = 0
355. for row in C_result:
356. C_ID = row.ID_Card_Number
357. C_NO_list.append(row.ID_Card_Number)
358. if F_NO == row.Flight_No:
359. Passenger_Table.Update_Passenger(C_ID,8,'-1')
360. now_num += 1
361.
362. print('C_NO_list')
363. print(C_NO_list)
364. messagebox.showinfo(title="取消成功",message = "已为%d个乘客取消航班"%now_num)
365.
366.
367.
368.
369.
370.
371.
372. Flight_Information_Table.Delete_Flight(F_NO)
373. messagebox.showinfo(title="操作成功",message = "删除该航班信息成功!")
374. self.page13.destroy()
375. self.createPage_airplane()
376.
377. def comeback():
378. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回航空公司界面")
379. if is_come_back_to_login:
380. self.page13.destroy()
381. self.createPage_airplane()
382.
383. def close():
384. is_close = messagebox.askyesno("退出","是否真的退出")
385. if is_close:
386. self.page13.destroy()
387. self.root.destroy()
388.
389. self.page11.destroy()
390.
391. self.page13 = tk.Frame(self.root)
392. self.page13.pack()
393.
394. delete_num = tk.StringVar()
395.
396. tk.Label(self.page13,text="请输入你要删除的航班编号").grid(row=0,pady=10,stick=tk.W)
397. tk.Entry(self.page13,textvariable = delete_num).grid(row=0,column=1, padx=5,pady=5)
398.
399. tk.Button(self.page13, text='确定', command=confirm).grid(row=1, column=0, padx=5,pady=5)
400.
401. tk.Button(self.page13, text='返回', command=comeback).grid(row=1, column=1, padx=5,pady=5)
402.
403. tk.Button(self.page13,text = "退出",command = close).grid(row=2, column=0, padx=5,pady=5)
404.
405. #-------------------------修改航班信息---------------------------------------------------------------------------
406. def change_plane(self):
407.
408. def confirm():
409.
410.
411.
412.
413. def confirm_18():
414.
415. company = plane_company.get()
416. start_place = plane_start_place.get()
417. end_place = plane_end_place.get()
418. Type = plane_type.get()
419. numbers = plane_numbers.get()
420. start_time = plane_start_time.get()
421. end_time = plane_end_time.get()
422. price = plane_price.get()
423.
424. change_flag = 0
425. O_NO_change_flag = 0
426.
427. if company == "" and start_place == "" and end_place== "" and Type == "" and numbers == "" and start_time =="" and end_time == "" and price == '':
428. messagebox.showerror(title="错误",message="不可以全部为空")
429. change_flag = 0
430. else:
431.
432. if company == "":
433. pass
434. else:
435. Flight_Information_Table.Update_Flight(ID,1,company)
436. print("航班航空公司:",company)
437. change_flag = 1
438.
439. if start_place == "":
440. pass
441. else:
442. Flight_Information_Table.Update_Flight(ID,2,start_place)
443. print("航班始发地:",start_place)
444. change_flag = 1
445. O_NO_change_flag = 1
446.
447.
448. if end_place== "":
449. pass
450. else:
451. Flight_Information_Table.Update_Flight(ID,3,end_place)
452. print("航班目的地:",end_place)
453. change_flag = 1
454. O_NO_change_flag = 1
455.
456. if Type == "":
457. pass
458. else:
459. Flight_Information_Table.Update_Flight(ID,4,Type)
460. print("航班机型:",Type)
461. change_flag = 1
462.
463. if numbers == "":
464. pass
465. else:
466. Flight_Information_Table.Update_Flight(ID,5,numbers)
467. print("航班乘客数:",numbers)
468. change_flag = 1
469.
470. if start_time =="":
471. pass
472. else:
473. if len(start_time) != 16 or (start_time[4] != "-" and start_time[7] != "-" and start_time[13] != ":"):#2020-01-31 10:30
474. messagebox.showerror(title="错误",message="航班起飞时间格式不正确 格式不正确")
475. plane_start_time.set("")
476. change_flag = 0
477.
478. elif start_time[5:7] not in ["01","02","03","04","05","06","07","08","09","10","11","12"]:
479. messagebox.showerror(title="错误",message="航班起飞时间格式不正确 月份填写错误")
480. plane_start_time.set("")
481. change_flag = 0
482.
483. elif (start_time[5:7] in ["01","03","05","07","08","10","12"]) and (start_time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]):
484. messagebox.showerror(title="错误",message="航班起飞时间格式不正确 大月")
485. plane_start_time.set("")
486. change_flag = 0
487.
488. elif (start_time[5:7] in ["04","06","09","11"]) and (start_time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"]):
489. messagebox.showerror(title="错误",message="航班起飞时间格式不正确 小月")
490. plane_start_time.set("")
491. change_flag = 0
492.
493. elif (start_time[5:7] in ["02"]) and (start_time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29"]):
494. messagebox.showerror(title="错误",message="航班起飞时间格式不正确 闰年")
495. plane_start_time.set("")
496. change_flag = 0
497.
498. elif start_time[11:13] not in ["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"]:
499. messagebox.showerror(title="错误",message="航班起飞时间格式不正确 小时")
500. plane_start_time.set("")
501. change_flag = 0
502.
503. elif start_time[14:16] not in ["00","01","02","03","04","05","06","07","08","09","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"]:
504. messagebox.showerror(title="错误",message="航班起飞时间格式不正确 分钟")
505. plane_start_time.set("")
506. change_flag = 0
507.
508. else:
509. Flight_Information_Table.Update_Flight(ID,6,start_time)
510. print("航班起飞时间",start_time)
511. change_flag = 1
512. O_NO_change_flag = 1
513.
514. if end_time == "":
515. pass
516. else:
517.
518. if len(end_time) != 16 or (end_time[4] != "-" and end_time[7] != "-" and end_time[13] != ":"):#2020-01-31 10:30
519. messagebox.showerror(title="错误",message="航班预计到达时间格式不正确 格式不正确")
520. plane_end_time.set("")
521. change_flag = 0
522.
523. elif end_time[5:7] not in ["01","02","03","04","05","06","07","08","09","10","11","12"]:
524. messagebox.showerror(title="错误",message="航班预计到达时间格式不正确 月份填写错误")
525. plane_end_time.set("")
526. change_flag = 0
527.
528. elif (end_time[5:7] in ["01","03","05","07","08","10","12"]) and (end_time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]):
529. messagebox.showerror(title="错误",message="航班预计到达时间格式不正确 大月")
530. plane_end_time.set("")
531. change_flag = 0
532.
533. elif (end_time[5:7] in ["04","06","09","11"]) and (end_time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"]):
534. messagebox.showerror(title="错误",message="航班预计到达时间格式不正确 小月")
535. plane_end_time.set("")
536. change_flag = 0
537.
538. elif (end_time[5:7] in ["02"]) and (end_time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29"]):
539. messagebox.showerror(title="错误",message="航班预计到达时间格式不正确 闰年")
540. plane_end_time.set("")
541. change_flag = 0
542.
543. elif end_time[11:13] not in ["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"]:
544. messagebox.showerror(title="错误",message="航班预计到达时间格式不正确 小时")
545. plane_end_time.set("")
546. change_flag = 0
547.
548. elif end_time[14:16] not in ["00","01","02","03","04","05","06","07","08","09","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"]:
549. messagebox.showerror(title="错误",message="航班预计到达时间格式不正确 分钟")
550. plane_end_time.set("")
551. change_flag = 0
552.
553. elif end_time == start_time_in_mysql:
554. messagebox.showerror(title="错误",message="航班预计到达时间不能与航班起飞时间相同")
555. plane_end_time.set("")
556. change_flag = 0
557. else:
558. Flight_Information_Table.Update_Flight(ID,7,end_time)
559. print("航班预计降落时间",end_time)
560. change_flag = 1
561.
562. if price == "":
563. pass
564. else:
565. if price == "":
566. messagebox.showerror(title="错误",message="请填写航班价格")
567. plane_price.set("")
568. change_flag = 0
569. else:
570. Flight_Information_Table.Update_Flight(ID,8,price)
571. change_flag = 1
572. if O_NO_change_flag == 1:
573. result = Query_Table_ALL(Passenger_Table)
574. CIDlist = list()
575. for row in result:
576. if row.Flight_No == ID:
577. CIDlist.append(row.ID_Card_Number)
578.
579. for row in CIDlist:
580. Passenger_Table.Update_Passenger(row,10,'-1')
581.
582. if(change_flag == 1):
583. messagebox.showinfo(title="操作成功",message = "修改航班信息成功!")
584. self.page15.destroy()
585. self.createPage_airplane()
586.
587. #查询航班
588. F_result = Query_Table_ALL(Flight_Information_Table)
589. F_Tdict = dict()#航班出发时间字典
590. F_S_Pdict = dict()#航班始发地字典
591. F_E_Pdict = dict()#航班目的地字典
592. FN_Pdict = dict()#航班最大乘客数字典
593. for row in F_result:
594. F_Tdict[row.Flight_no] = row.scheduled_start_time
595. F_S_Pdict[row.Flight_no] = row.origin
596. F_E_Pdict[row.Flight_no] = row.destination
597. FN_Pdict[row.Flight_no] = row.Num_P
598.
599. #查询乘客
600. C_result = Query_Table_ALL(Passenger_Table)
601. C_NO_list = list()#乘客身份证列表
602. C_Tdict = dict()#乘客出发时间字典
603. C_S_Pdict = dict()#乘客始发地字典
604. C_E_Pdict = dict()#乘客目的地字典
605. CFdict = dict()#乘客航班号
606. sit_num = 0#已有乘客数
607. now_Num = 0#安排乘客数
608. now_DNum = 0#取消乘客数
609. for row in C_result:
610. Num = int(FN_Pdict[ID])
611.
612. if row.Flight_No == ID:
613. sit_num += 1
614. C_ID = row.ID_Card_Number
615. C_NO_list.append(C_ID)
616. C_Tdict[C_ID] = row.travel_time
617. C_S_Pdict[C_ID] = row.place_travel_start
618. C_E_Pdict[C_ID] = row.place_travel_end
619. CFdict[C_ID] = row.Flight_No
620.
621. if CFdict[C_ID] == '-1':#检查是否有未安排航班的乘客
622. #修改的信息与乘客信息是否匹配,而且仍有座位
623. if C_Tdict[C_ID] == F_Tdict[ID][:10] and C_S_Pdict[C_ID] == F_S_Pdict[ID] and C_E_Pdict[C_ID] == F_E_Pdict[ID] and sit_num < Num:
624. print("匹配成功")
625. Passenger_Table.Update_Passenger(C_ID,8,ID)#匹配成功则添加航班编号进乘客信息
626. now_Num += 1
627. else:
628. print("匹配失败")
629. pass
630. else:#已安排航班的乘客
631. #修改的信息与乘客信息完全匹配
632. if C_Tdict[C_ID] == F_Tdict[ID][:10] and C_S_Pdict[C_ID] == F_S_Pdict[ID] and C_E_Pdict[C_ID] == F_E_Pdict[ID]:
633. pass
634. else:#不匹配则取消该乘客航班
635. Passenger_Table.Update_Passenger(C_ID,8,'-1')
636. now_DNum += 1
637. if now_Num != 0:
638. messagebox.showinfo(title="添加成功",message = "已为%d个乘客安排航班"%now_Num)
639.
640. if now_DNum != 0:
641. messagebox.showinfo(title="添加成功",message = "已为%d个乘客取消航班"%now_DNum)
642.
643. def comeback_change():
644. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回航空公司界面")
645. if is_come_back_to_login:
646. self.page15.destroy()
647. self.createPage_airplane()
648.
649. ID = plane_id.get()
650.
651. start_time_in_mysql = ''
652. result = Query_Table_ALL(Flight_Information_Table)
653. for row in result:
654. if ID == row.Flight_no:
655. start_time_in_mysql = row.scheduled_start_time
656. print("库里的时间:",start_time_in_mysql)
657.
658. #查询该账号的ID,并生成旅客ID列表
659. ares = Account_Table.Query_Account('Company')
660. AC_ID = ''
661. for row in ares :
662. if self.user == row.User:
663. AC_ID = row.ID_Number
664. #print("*")
665. #print(AC_ID)
666. result = Flight_Information_Table.Query_Flight(AC_ID)
667. FNOlist = list()
668. for row in result:
669. FNOlist.append(row.Flight_no)
670. print(row.Flight_no,
671. row.air_company_No,
672. row.origin,
673. row.destination,
674. row.Aircraft_type,
675. #row.Num_p,
676. row.scheduled_start_time,
677. row.scheduled_arrival_time)
678. print("&")
679. print(FNOlist)
680.
681. print("航班编号:",ID)
682.
683. if ID in FNOlist :#如果有该航空编号的飞机
684.
685. plane_company = tk.StringVar()
686. plane_start_place = tk.StringVar()
687. plane_end_place = tk.StringVar()
688. plane_type = tk.StringVar()
689. plane_numbers= tk.StringVar()
690. plane_start_time = tk.StringVar()
691. plane_end_time = tk.StringVar()#航班预计到达时间
692. plane_price = tk.StringVar()#价格
693.
694.
695. messagebox.showinfo(title="成功",message = "找到符合编号的航班")
696. self.page14.destroy()
697.
698.
699. self.page15 = tk.Frame(self.root)
700. self.page15.pack()
701.
702. tk.Label(self.page15,text="修改航班信息").grid(row=0,pady=10,stick=tk.W)
703.
704. tk.Label(self.page15,text="航班始发地:").grid(row=1,pady=10,stick=tk.W)
705. tk.Entry(self.page15, textvariable=plane_start_place).grid(row=1, column=1,stick = tk.E)
706.
707. tk.Label(self.page15,text="航班目的地:").grid(row=2,pady=10,stick=tk.W)
708. tk.Entry(self.page15, textvariable=plane_end_place).grid(row=2, column=1,stick = tk.E)
709.
710. tk.Label(self.page15,text="航班机型:").grid(row=3,pady=10,stick=tk.W)
711. tk.Entry(self.page15, textvariable=plane_type).grid(row=3, column=1,stick = tk.E)
712.
713. tk.Label(self.page15,text="航班乘客数:").grid(row=4,pady=10,stick=tk.W)
714. tk.Entry(self.page15, textvariable=plane_numbers).grid(row=4, column=1,stick = tk.E)
715.
716. tk.Label(self.page15,text="航班起飞时间:").grid(row=5,pady=10,stick=tk.W)
717. tk.Entry(self.page15, textvariable=plane_start_time).grid(row=5, column=1,stick = tk.E)
718.
719. tk.Label(self.page15,text="航班预计达到时间:").grid(row=6,pady=10,stick=tk.W)
720. tk.Entry(self.page15, textvariable=plane_end_time).grid(row=6, column=1,stick = tk.E)
721.
722. tk.Label(self.page15,text="航班价格:").grid(row=7,pady=10,stick=tk.W)
723. tk.Entry(self.page15, textvariable=plane_price).grid(row=7, column=1,stick = tk.E)
724.
725. tk.Button(self.page15, text='确定', command=confirm_18).grid(row=8, column=0, padx=5,pady=5)
726.
727. tk.Button(self.page15, text='返回', command=comeback_change).grid(row=8, column=1, padx=5,pady=5)
728.
729. tk.Button(self.page15,text = "退出",command = close).grid(row=9, column=0, padx=5,pady=5)
730.
731. tk.Label(self.page15,text="航班起飞时间格式:2020-01-31 10:00").grid(row=10,pady=10,stick=tk.W)
732. tk.Label(self.page15,text="航班预计达到时间格式:2020-01-31 10:00").grid(row=11,pady=10,stick=tk.W)
733. else :#如果找不到该航空编号的飞机 弹出弹窗说没有
734. messagebox.showerror(title="失败",message = "失败!找不到符合编号的航班")
735. plane_id.set("")
736.
737. def comeback():
738. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回航空公司界面")
739. if is_come_back_to_login:
740. self.page14.destroy()
741. self.createPage_airplane()
742.
743. def close():
744. is_close = messagebox.askyesno("是否退出","是否真的退出")
745. if is_close:
746. self.page14.destroy()
747. self.root.destroy()
748.
749. self.page11.destroy()
750.
751. self.page14 = tk.Frame(self.root)
752. self.page14.pack()
753.
754.
755.
756. plane_id = tk.StringVar()
757.
758.
759.
760. tk.Label(self.page14,text="修改航班信息").grid(row=0,pady=10,stick=tk.W)
761.
762. tk.Label(self.page14,text="航班编号:").grid(row=1,pady=10,stick=tk.W)
763. tk.Entry(self.page14, textvariable=plane_id).grid(row=1, column=1,stick = tk.E)
764.
765.
766. tk.Button(self.page14, text='确定', command=confirm).grid(row=2, column=0, padx=5,pady=5)
767.
768. tk.Button(self.page14, text='返回', command=comeback).grid(row=2, column=1, padx=5,pady=5)
769.
770. tk.Button(self.page14,text = "退出",command = close).grid(row=3, column=0, padx=5,pady=5)
771.
772.
773.
774.
775.
776. #--------------------查看航班信息----------------------------------------------------------------------
777. def check_plane_information(self):
778. def close_this_window():
779. window_sign_up.destroy()
780.
781. window_sign_up = tk.Toplevel(self.page11)
782. window_sign_up.geometry("500x200")#你可以用这个调整窗口大小
783. window_sign_up.title("查看航班信息")
784. window_sign_up.resizable(0,0)
785.
786. num = 0
787.
788. ID = ""
789. AC_ID = ""
790. start_place = ""
791. end_place = ""
792. Type = ""
793. numbers = ""
794. start_time = ""
795. end_time = ""
796. price = ""
797.
798.
799.
800. sb = tk.Scrollbar(window_sign_up)
801. sb.pack(side = tk.RIGHT,fill = "y")
802.
803. lb = tk.Listbox(window_sign_up,yscrollcommand = sb.set,width = 100,height = 100)
804.
805. lb.pack(side=tk.LEFT,fill="both")
806.
807. sb.config(command = lb.yview)
808.
809. #查询该账号的ID,并生成旅客ID列表
810. ares = Account_Table.Query_Account('Company')
811. AC_ID = ''
812. for row in ares :
813. if self.user == row.User:
814. AC_ID = row.ID_Number
815. #print("*")
816. #print(AC_ID)
817. result = Flight_Information_Table.Query_Flight(AC_ID)
818. #FNOlist = list()
819. for row in result:
820. ID = '航班编号:'+row.Flight_no
821. AC_ID = '所属航空公司:'+row.air_company_No
822. start_place = '航班始发地:'+row.origin
823. end_place = '航班目的地:'+row.destination
824. Type = '机型:'+row.Aircraft_type
825. numbers = '乘客数:'+row.Num_P
826. start_time = '起飞时间:'+row.scheduled_start_time
827. end_time = '预计到达时间:'+row.scheduled_arrival_time
828. price = '航班价格' + row.price
829.
830. lb.insert('end',ID)
831. lb.insert('end',AC_ID)
832. lb.insert('end',start_place)
833. lb.insert('end',end_place)
834. lb.insert('end',Type)
835. lb.insert('end',numbers)
836. lb.insert('end',start_time)
837. lb.insert('end',end_time)
838. lb.insert('end',price)
839.
840. lb.insert('end',"---------------------------------------------------------------------")
841.
842. num = num + 1
843.
844. ID = ""
845. AC_ID = ""
846. start_place = ""
847. end_place = ""
848. Type = ""
849. numbers = ""
850. start_time = ""
851. end_time = ""
852.
853.
854.
855.
856. str1= str("一共有%d个航班信息" %num)#加上你统计来的航班个数
857. tk.Label(window_sign_up,text=str1).place(x=200,y=0)
858. tk.Button(window_sign_up,text="OK",command=close_this_window).place(x=250,y=170)
859.
860.
861. def comeback(self):
862. is_comeback = messagebox.askyesno("是否注销","是否注销并返回登录界面")
863. if is_comeback:
864. self.page11.destroy()
865. Login.LoginPage(self.root)
866.
867. def close(self):
868. is_close = messagebox.askyesno("是否退出","是否真的退出")
869. if is_close:
870. self.page11.destroy()
871. self.root.destroy()
3.4 旅行社界面
旅行社界面也是创造了一个类, 在类的构造函数里面设置好框的大小,然后调用createPage函数创造各个tkinter的部件。并且创建出方法:添加旅客信息,删除旅客信息,修改旅客信息,查询旅客信息。
1. # -*- coding: utf-8 -*-
2. """
3. Created on Thu May 28 23:59:17 2020
4.
5. """
6.
7. import interface
8. from interface import Account_Table, Passenger_Table, Airline_Company_Table, Travel_Agency_Table, Flight_Information_Table, Order_information_table, Query_Table_ALL
9.
10. import tkinter as tk
11. import LoginPage as Login
12. import tkinter.messagebox as messagebox
13. import pickle
14.
15. class Tourist_agency_Mainpage(object):
16. def __init__(self,master = None,usrs = None):
17. self.root = master #定义内部变量root
18.
19. self.user = usrs
20. print("#")
21. print(self.user)
22.
23. self.createPage_tourist_agency()
24.
25.
26. def createPage_tourist_agency(self):#旅行社主界面
27.
28. self.root.geometry("500x400")
29. self.root.resizable(0,0)
30.
31. def comeback():
32. is_comeback = messagebox.askyesno("是否注销","是否注销并返回登陆界面")
33. if is_comeback:
34. self.page13.destroy()
35. Login.LoginPage(self.root)
36.
37. def close():
38. is_close = messagebox.askyesno("是否退出","是否真的退出")
39. if is_close:
40. self.page13.destroy()
41. self.root.destroy()
42.
43. self.page13 = tk.Frame(self.root)
44. self.page13.pack()
45.
46. tk.Label(self.page13,text="欢迎来到旅行社界面!用户:"+self.user).grid(row=0,column=0)
47.
48. tk.Button(self.page13,text="增加旅客信息",command=self.add_customer_information).grid(row=1,column = 0,padx=5,pady=5)
49. tk.Button(self.page13,text="查看旅客信息",command = self.check_customer_information).grid(row = 1,column = 1,padx=5,pady=5)
50.
51. tk.Button(self.page13,text="修改旅客信息",command = self.change_customer_information).grid(row = 2,column = 1,padx=5,pady=5)
52. tk.Button(self.page13,text="删除旅客信息",command = self.delete_customer_information).grid(row = 2,column = 0,padx=5,pady=5)
53.
54. tk.Button(self.page13,text="注销用户",command = comeback).grid(row = 3,column = 0, padx=5,pady=5)
55. tk.Button(self.page13,text="退出",command = close).grid(row = 3,column = 1, padx=5,pady=5)
56.
57. #------------------------------------------#增加旅客界面-----------------------------------------------
58. def add_customer_information(self):
59.
60. def comeback():
61. is_comeback = messagebox.askyesno("是否返回","是否返回旅行社界面")
62. if is_comeback:
63. self.page14.destroy()
64. self.createPage_tourist_agency()
65.
66. def close():
67. is_close = messagebox.askyesno("是否退出","是否真的退出")
68. if is_close:
69. self.page14.destroy()
70. self.root.destroy()
71.
72. def confirm():
73.
74. def check_id(new_id):#判断身份证号是否正确函数
75. if len(new_id) != 18:#如果身份证号码不是18位
76. return 0
77. elif new_id[0:2] not in ["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65"]:
78. return 0
79. else:
80. return 1
81.
82.
83. name = customer_name.get()#乘客姓名
84. sex = customer_sex.get()#性别
85. job = customer_job.get()#工作单位
86. ID = customer_id.get()#乘客身份证号
87. time = customer_time.get()#旅行出发时间
88. start_place = customer_start_place.get()#旅行始发地
89. end_place = customer_end_place.get()#旅行目的地
90. planesit = customer_planesit.get()#舱位要求
91.
92. #查找旅行社编号
93. result = Query_Table_ALL(Account_Table)
94. Userlist = list()
95. TIDdict = dict()
96. for row in result:
97. Userlist.append(row.User)
98. TIDdict[row.User] = row.ID_Number
99.
100. result = Query_Table_ALL(Passenger_Table)
101. CIDlist = list()
102. for row in result :
103. CIDlist.append(row.ID_Card_Number)
104. print(CIDlist)
105.
106. if name == "":#姓名未填写
107. messagebox.showerror(title="错误",message="请输入旅客姓名")
108. customer_name.set("")
109. customer_sex.set("")
110. customer_job.set("")
111. customer_id.set("")
112. customer_time.set("")
113. customer_start_place.set("")
114. customer_end_place.set("")
115. customer_planesit.set("")
116.
117. elif sex == "":#性别未填写
118. messagebox.showerror(title="错误",message="请输入旅客性别")
119. customer_sex.set("")
120. customer_job.set("")
121. customer_id.set("")
122. customer_time.set("")
123. customer_start_place.set("")
124. customer_end_place.set("")
125. customer_planesit.set("")
126.
127. elif sex != "F" and sex!= "M": #性别不男不女
128. messagebox.showerror(title="错误",message="旅客性别必须写F或者M")
129. customer_sex.set("")
130. customer_job.set("")
131. customer_id.set("")
132. customer_time.set("")
133. customer_start_place.set("")
134. customer_end_place.set("")
135. customer_planesit.set("")
136.
137. elif job == "":#工作单位未填写
138. messagebox.showerror(title="错误",message="请输入旅客工作单位")
139. customer_job.set("")
140. customer_id.set("")
141. customer_time.set("")
142. customer_start_place.set("")
143. customer_end_place.set("")
144. customer_planesit.set("")
145.
146. elif ID == "":#身份证号未填写
147. messagebox.showerror(title="错误",message="请输入旅客身份证号码")
148. customer_id.set("")
149. customer_time.set("")
150. customer_start_place.set("")
151. customer_end_place.set("")
152. customer_planesit.set("")
153.
154. elif ID in CIDlist:
155. messagebox.showerror(title="错误",message="该身份证已注册进旅客信息")
156. customer_id.set("")
157. customer_time.set("")
158. customer_start_place.set("")
159. customer_end_place.set("")
160. customer_planesit.set("")
161.
162. #elif check_id(ID) == 0:
163. #customer_id.set("")
164. #messagebox.showerror(title = "错误",message = "旅客身份证输入格式不正确")
165.
166. elif time == "":#旅行出发时间
167. messagebox.showerror(title="错误",message="请输入旅客旅行出发时间")
168. customer_time.set("")
169. customer_start_place.set("")
170. customer_end_place.set("")
171. customer_planesit.set("")
172.
173. elif len(time) != 10 or (time[4] != "-" and time[7] != "-"): #2020-12-05
174. messagebox.showerror(title="错误",message="旅客旅行出发时间格式不正确 本来格式就不对")
175. customer_time.set("")
176. customer_start_place.set("")
177. customer_end_place.set("")
178. customer_planesit.set("")
179.
180. elif time[5:7] not in ["01","02","03","04","05","06","07","08","09","10","11","12"]:
181. messagebox.showerror(title="错误",message="旅客旅行出发时间格式不正确 月份填写错误")
182. customer_time.set("")
183. customer_start_place.set("")
184. customer_end_place.set("")
185. customer_planesit.set("")
186.
187. elif (time[5:7] in ["01","03","05","07","08","10","12"]) and (time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]):
188. messagebox.showerror(title="错误",message="旅客旅行出发时间格式不正确 大月 31天")
189. customer_time.set("")
190. customer_start_place.set("")
191. customer_end_place.set("")
192. customer_planesit.set("")
193.
194. elif (time[5:7] in ["04","06","09","11"]) and (time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"]):
195. messagebox.showerror(title="错误",message="旅客旅行出发时间格式不正确 小月 30天")
196. customer_time.set("")
197. customer_start_place.set("")
198. customer_end_place.set("")
199. customer_planesit.set("")
200.
201. elif (time[5:7] in ["02"]) and (time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29"]):
202. messagebox.showerror(title="错误",message="旅客旅行出发时间格式不正确 闰年")
203. customer_time.set("")
204. customer_start_place.set("")
205. customer_end_place.set("")
206. customer_planesit.set("")
207.
208. elif start_place =="":#旅行始发地未写
209. messagebox.showerror(title="错误",message="请输入旅客旅行始发地")
210. customer_start_place.set("")
211. customer_end_place.set("")
212. customer_planesit.set("")
213.
214. elif end_place == "":#旅行目的地未写
215. messagebox.showerror(title="错误",message="请输入旅客旅行目的地")
216. customer_end_place.set("")
217. customer_planesit.set("")
218.
219. elif planesit == "":#舱位要求未写
220. messagebox.showerror(title="错误",message="请输入旅客航班舱位要求")
221. customer_planesit.set("")
222.
223. else:
224.
225. #查询航班
226. F_result = Query_Table_ALL(Flight_Information_Table)
227. F_NO_list = list()#航班编号列表
228. F_Tdict = dict()#航班出发时间字典
229. F_S_Pdict = dict()#航班始发地字典
230. F_E_Pdict = dict()#航班目的地字典
231. Final_FNO = '-1'#最后要添加的航班编号
232. flight_sit = 0#航班座位数
233.
234. for row in F_result:
235. RFNO = row.Flight_no#航班编号
236. F_NO_list.append(RFNO)
237. F_Tdict[RFNO] = row.scheduled_start_time[:10]
238. F_S_Pdict[RFNO] = row.origin
239. F_E_Pdict[RFNO] = row.destination
240. print(RFNO)
241. print(F_S_Pdict[RFNO])
242. print(start_place)
243.
244. print("^^^")
245. print(row.scheduled_start_time[:10])
246. print(time)
247. if F_Tdict[RFNO] == time and F_S_Pdict[RFNO] == start_place and F_E_Pdict[RFNO] == end_place :
248.
249. print(F_S_Pdict[RFNO])
250. print(start_place)
251. Final_FNO = RFNO
252. flight_sit = int(row.Num_P)
253. messagebox.showinfo(title="匹配成功",message = "有相应航班,正在安排")
254. else:
255.
256. pass
257.
258. print("Final_FNO:")
259. print(Final_FNO)
260.
261. print("flight_sit:")
262. print(flight_sit)
263.
264. #检查乘客是否已满
265. if Final_FNO != '-1':
266. sit_num = 0
267.
268. Sit_num_result = Query_Table_ALL(Passenger_Table)
269. for row in Sit_num_result :
270. if row.Flight_No == Final_FNO:
271. sit_num += 1
272. if sit_num > flight_sit:
273. Final_FNO = '-1'
274. messagebox.showinfo(title="已满",message = "但航班已满,已取消")
275. else:
276. pass
277. print("sit_sum")
278. print(sit_num)
279. else:
280. pass
281. print("Final_FNO:")
282. print(Final_FNO)
283.
284. #添加旅客【添加了旅行社编号】
285. Passenger_Table.Insert_Passenger(name,sex,job,ID,time,start_place,end_place,planesit,Final_FNO,TIDdict[self.user],'-1')
286.
287. #添加订单
288.
289. print('@')
290. print(F_NO_list)
291. print(F_Tdict)
292. print(F_S_Pdict)
293. print(F_E_Pdict)
294.
295. messagebox.showinfo(title="添加成功",message = "添加旅客信息成功")
296. self.page14.destroy()
297. self.createPage_tourist_agency()
298.
299.
300. self.page13.destroy()
301.
302.
303. self.root.geometry("500x500")
304. self.root.resizable(0,0)
305.
306. self.page14 = tk.Frame(self.root)
307. self.page14.pack()
308.
309. customer_name = tk.StringVar()#乘客姓名
310. customer_sex = tk.StringVar()#性别
311. customer_job = tk.StringVar()#工作单位
312. customer_id = tk.StringVar()#乘客身份证号
313. customer_time = tk.StringVar()#旅行出发时间
314. customer_start_place = tk.StringVar()#旅行始发地
315. customer_end_place = tk.StringVar()#旅行目的地
316. customer_planesit = tk.StringVar()#舱位要求
317.
318. tk.Label(self.page14,text="增加旅客信息界面").grid(row=0,stick=tk.W)
319.
320. tk.Label(self.page14, text="旅客姓名:").grid(row=1,pady=10,stick=tk.W)
321. tk.Entry(self.page14, textvariable=customer_name).grid(row=1, column=1,stick = tk.E)
322.
323. tk.Label(self.page14,text="旅客性别:(F/M)").grid(row=2,pady=10,stick=tk.W)
324. tk.Entry(self.page14, textvariable=customer_sex).grid(row=2, column=1,stick = tk.E)
325.
326. tk.Label(self.page14,text="旅客工作单位:").grid(row=3,pady=10,stick=tk.W)
327. tk.Entry(self.page14, textvariable=customer_job).grid(row=3, column=1,stick = tk.E)
328.
329. tk.Label(self.page14,text="旅客身份证号码:").grid(row=4,pady=10,stick=tk.W)
330. tk.Entry(self.page14, textvariable=customer_id).grid(row=4, column=1,stick = tk.E)
331.
332. tk.Label(self.page14,text="旅客旅行出发时间:").grid(row=5,pady=10,stick=tk.W)
333. tk.Entry(self.page14, textvariable=customer_time).grid(row=5, column=1,stick = tk.E)
334.
335. tk.Label(self.page14,text="旅客旅行始发地:").grid(row=6,pady=10,stick=tk.W)
336. tk.Entry(self.page14, textvariable=customer_start_place).grid(row=6, column=1,stick = tk.E)
337.
338. tk.Label(self.page14,text="旅客旅行目的地").grid(row=7,pady=10,stick=tk.W)
339. tk.Entry(self.page14, textvariable=customer_end_place).grid(row=7, column=1,stick = tk.E)
340.
341. tk.Label(self.page14,text="旅客航班舱位要求:").grid(row=8,pady=10,stick=tk.W)
342. tk.Entry(self.page14, textvariable=customer_planesit).grid(row=8, column=1,stick = tk.E)
343.
344. tk.Button(self.page14, text='确定', command=confirm).grid(row=9, column=0, padx=5,pady=5)
345.
346. tk.Button(self.page14, text='返回旅行社界面', command=comeback).grid(row=9, column=1, padx=5,pady=5)
347.
348. tk.Button(self.page14,text = "退出",command = close).grid(row=10, column=0, padx=5,pady=5)
349.
350. tk.Label(self.page14,text="旅客旅行出发时间格式:2020-01-31").grid(row=11,pady=10,stick=tk.W)
351.
352. #---------------------------------修改旅行社信息--------------------------------------------------------
353. def change_tourist_agency_informations(self):
354.
355. def confirm():
356.
357. agency_num = tourist_agency_num.get()
358. agency_name = tourist_agency_name.get()
359.
360. result = Query_Table_ALL(Travel_Agency_Table)
361. TNolist = list()
362. TNamelist = list()
363. TNameDict = dict()
364. for row in result:
365. TNolist.append(row.No)
366. TNamelist.append(row.Name)
367. TNameDict[row.No] = row.Name
368.
369. if agency_num == "":#旅行社编号未填写
370. messagebox.showerror(title = "错误",message = "请输入旅行社编号")
371. elif agency_num in TNolist:#旅行社编号重复
372. messagebox.showerror(title = "错误",message = "旅行社编号重复")
373.
374. elif agency_name == "":#旅行社姓名未填写
375. messagebox.showerror(title = "错误",message = "请输入旅行社姓名")
376.
377. elif agency_name in TNamelist:#旅行社姓名重复
378. messagebox.showerror(title = "错误",message = "旅行社姓名重复")
379.
380. else:
381.
382. #记得将修改好的旅行社编号和姓名重新写入到数据库中谢了
383. print("旅行社编号 = ",agency_num)
384. print("旅行社姓名 = ",agency_name)
385. messagebox.showinfo(title="操作成功",message = "修改旅行社信息成功")
386. self.page15.destroy()
387. self.createPage_tourist_agency()
388.
389. def comeback():
390. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回旅行社界面")
391. if is_come_back_to_login:
392. self.page15.destroy()
393. self.createPage_tourist_agency()
394.
395. def close():
396. is_close = messagebox.askyesno("是否退出","是否真的退出")
397. if is_close:
398. self.page15.destroy()
399. self.root.destroy()
400.
401. self.page13.destroy()
402.
403. self.page15 = tk.Frame(self.root)
404. self.page15.pack()
405.
406.
407. tourist_agency_num = tk.StringVar()#旅行社编号
408. tourist_agency_name = tk.StringVar()#旅行社名字
409.
410. tk.Label(self.page15,text="更改旅行社信息").grid(row=0,stick=tk.W)
411.
412. tk.Label(self.page15,text="旅行社编号:").grid(row=3,pady=10,stick=tk.W)
413. tk.Entry(self.page15, textvariable=tourist_agency_num).grid(row=3, column=1,stick = tk.E)
414.
415. tk.Label(self.page15,text="旅行社名字:").grid(row=4,pady=10,stick=tk.W)
416. tk.Entry(self.page15, textvariable=tourist_agency_name).grid(row=4, column=1,stick = tk.E)
417.
418. #tk.Label(self.page15,text="旅行社目的地:").grid(row=5,pady=10,stick=tk.W)
419. #tk.Entry(self.page15, textvariable=tourist_agency_target).grid(row=5, column=1,stick = tk.E)
420.
421. tk.Button(self.page15, text='确定', command=confirm).grid(row=5, column=0, padx=5,pady=5)
422.
423. tk.Button(self.page15, text='返回旅行社界面', command=comeback).grid(row=5, column=1, padx=5,pady=5)
424.
425. tk.Button(self.page15, text='退出', command=close).grid(row=6, column=0,padx=5, pady=5)
426.
427. #---------------------删除旅客信息-----------------------------------------------------------------
428. def delete_customer_information(self):
429.
430. def come_back():
431. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回旅行社界面")
432. if is_come_back_to_login:
433. self.page16.destroy()
434. self.createPage_tourist_agency()
435.
436. def close():
437. is_close = messagebox.askyesno("是否退出","是否真的要退出?")
438. if is_close:
439. self.page16.destroy()
440. self.root.destroy()
441.
442. def delete():
443. ID = customer_id.get()
444.
445. #获取乘客的ID码生成列表
446.
447. ares = Account_Table.Query_Account('T_agency')
448. T_ID = ''
449. for row in ares :
450. if self.user == row.User:
451. T_ID = row.ID_Number
452. #print("*")
453. #print(T_ID)
454. result = Passenger_Table.Query_Passenger(T_ID)
455. CIDlist = list()
456. for row in result:
457. CIDlist.append(row.ID_Card_Number)
458. print(CIDlist)
459.
460.
461. if ID == '':
462. messagebox.showerror(title="错误",message="请输入旅客身份证号")
463.
464. elif ID not in CIDlist:
465. print("无此乘客")
466. messagebox.showerror(title="错误",message="没有符合该身份证号的旅客")
467. else:
468. Order_information_table.Delete_Order(O_NO)
469. Passenger_Table.Delete_Passenger(ID)
470. messagebox.showinfo("删除成功","删除成功")
471. self.page16.destroy()
472. self.createPage_tourist_agency()
473.
474.
475. self.page13.destroy()
476.
477.
478. self.page16 = tk.Frame(self.root)
479. self.page16.pack()
480.
481. customer_id = tk.StringVar()
482.
483. tk.Label(self.page16,text="删除旅客信息").grid(row=0,stick=tk.W)
484.
485. tk.Label(self.page16,text = "输入身份证号:").grid(row=1,column = 0,pady=10,stick=tk.W)
486. tk.Entry(self.page16, textvariable=customer_id).grid(row=1, column=1,stick = tk.E)
487.
488. tk.Button(self.page16, text='删除', command=delete).grid(row=2, column=0, pady=5)
489. tk.Button(self.page16, text='返回旅行社界面', command=come_back).grid(row=2, column=1, pady=5)
490. tk.Button(self.page16, text="退出", command=close).grid(row=2,column = 2,pady = 5)
491.
492.
493. #-----------------------------修改旅客信息--------------------------------------------------------------
494. def change_customer_information(self):
495.
496. def confirm():
497.
498. def confirm_18():
499. name = customer_name.get()#乘客姓名
500. sex = customer_sex.get()#性别
501. job = customer_job.get()#工作单位
502. time = customer_time.get()#旅行出发时间
503. start_place = customer_start_place.get()#旅行始发地
504. end_place = customer_end_place.get()#旅行目的地
505. planesit = customer_planesit.get()#舱位要求
506.
507. change_flag = 0
508.
509. O_NO_change_flag = 0
510.
511. if name == "" and sex == "" and job == "" and time == "" and start_place =="" and end_place == "" and planesit == "":
512. messagebox.showerror(title="错误",message="不可以全部为空")
513. else:
514. if name == "":#姓名未填写
515. pass
516. else:
517. Passenger_Table.Update_Passenger(ID,0,name)
518. change_flag = 1
519. print("旅客姓名:",name)
520.
521. if sex == "":#性别未填写
522. pass
523. elif sex != "F" and sex!= "M": #性别不能男不女
524. messagebox.showerror(title="错误",message="旅客性别必须写F或者M")#!!此处的处理完会直接打印修改完成 ,需修改完善
525.
526. else:
527. Passenger_Table.Update_Passenger(ID,1,sex)
528. change_flag = 1
529. print("旅客性别:",sex)
530.
531.
532.
533. if job == "":#工作单位未填写
534. pass
535. else:
536. Passenger_Table.Update_Passenger(ID,2,job)
537. change_flag = 1
538. print("旅客工作单位:",job)
539.
540. if time == "":#旅行出发时间
541. pass
542. else:
543. if len(time) != 10 or (time[4] != "-" and time[7] != "-"): #2020-12-05
544. messagebox.showerror(title="错误",message="旅客旅行出发时间格式不正确 本来格式就不对")
545. customer_time.set("")
546. customer_start_place.set("")
547. customer_end_place.set("")
548. customer_planesit.set("")
549.
550. elif time[5:7] not in ["01","02","03","04","05","06","07","08","09","10","11","12"]:
551. messagebox.showerror(title="错误",message="旅客旅行出发时间格式不正确 月份填写错误")
552. customer_time.set("")
553. customer_start_place.set("")
554. customer_end_place.set("")
555. customer_planesit.set("")
556.
557. elif (time[5:7] in ["01","03","05","07","08","10","12"]) and (time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]):
558. messagebox.showerror(title="错误",message="旅客旅行出发时间格式不正确 大月 31天")
559. customer_time.set("")
560. customer_start_place.set("")
561. customer_end_place.set("")
562. customer_planesit.set("")
563.
564. elif (time[5:7] in ["04","06","09","11"]) and (time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"]):
565. messagebox.showerror(title="错误",message="旅客旅行出发时间格式不正确 小月 30天")
566. customer_time.set("")
567. customer_start_place.set("")
568. customer_end_place.set("")
569. customer_planesit.set("")
570.
571. elif (time[5:7] in ["02"]) and (time[8:10] not in ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29"]):
572. messagebox.showerror(title="错误",message="旅客旅行出发时间格式不正确 闰年")
573. customer_time.set("")
574. customer_start_place.set("")
575. customer_end_place.set("")
576. customer_planesit.set("")
577. else:
578. Passenger_Table.Update_Passenger(ID,4,time)
579. O_NO_change_flag = 1
580. change_flag = 1
581. print("旅客旅行时间:",time)
582.
583. if start_place =="":#旅行始发地未写
584. pass
585. else:
586. Passenger_Table.Update_Passenger(ID,5,start_place)
587. O_NO_change_flag = 1
588. change_flag = 1
589. print("旅客旅行始发地:",start_place)
590.
591. if end_place == "":#旅行目的地未写
592. pass
593. else:
594. Passenger_Table.Update_Passenger(ID,6,end_place)
595. O_NO_change_flag = 1
596. change_flag = 1
597. print("旅客旅行目的地:",end_place)
598.
599. if planesit == "":#舱位要求未写
600. pass
601. else:
602. Passenger_Table.Update_Passenger(ID,7,planesit)
603. change_flag = 1
604. print("航班舱位要求",planesit)
605.
606. if(change_flag == 1):
607. messagebox.showinfo(title="修改成功",message = "修改旅客信息成功")
608. if(O_NO_change_flag == 1):
609. Passenger_Table.Update_Passenger(ID,10,'-1')
610.
611. #查询航班
612. F_result = Query_Table_ALL(Flight_Information_Table)
613. F_NO_list = list()#航班编号列表
614. F_Tdict = dict()#航班出发时间字典
615. F_S_Pdict = dict()#航班始发地字典
616. F_E_Pdict = dict()#航班目的地字典
617. Final_FNO = '-1'#最后要添加的航班编号
618. flight_sit = 0#航班座位数
619.
620.
621.
622. this_result = Query_Table_ALL(Passenger_Table)
623. C_Tdict = dict()
624. C_S_Pdict = dict()
625. C_E_Pdict = dict()
626. C_FNOdict = dict()
627. for row in this_result:
628. C_Tdict[row.ID_Card_Number] = row.travel_time
629. C_S_Pdict[row.ID_Card_Number] = row.place_travel_start
630. C_E_Pdict[row.ID_Card_Number] = row.place_travel_end
631. C_FNOdict[row.ID_Card_Number] = row.Flight_No
632.
633. print(C_Tdict)
634. print(C_S_Pdict)
635. print(C_E_Pdict)
636. print(C_FNOdict)
637.
638. print(C_Tdict[ID])
639. print(C_S_Pdict[ID])
640. print(C_E_Pdict[ID])
641. print(C_FNOdict[ID])
642. for row in F_result:
643. RFNO = row.Flight_no#航班编号
644. F_NO_list.append(RFNO)
645. F_Tdict[RFNO] = row.scheduled_start_time[:10]
646. F_S_Pdict[RFNO] = row.origin
647. F_E_Pdict[RFNO] = row.destination
648. print(RFNO)
649. print(F_S_Pdict[RFNO])
650.
651. print("^^^")
652. print(row.scheduled_start_time[:10])
653.
654. if F_Tdict[RFNO] == C_Tdict[ID] and F_S_Pdict[RFNO] == C_S_Pdict[ID] and F_E_Pdict[RFNO] == C_E_Pdict[ID] :
655. print(F_S_Pdict[RFNO])
656. print(start_place)
657. Final_FNO = RFNO#匹配成功,读取航班编号
658. flight_sit = int(row.Num_P)
659. messagebox.showinfo(title="匹配成功",message = "有相应航班,正在安排")
660. else:
661. pass
662.
663.
664. print("Final_FNO:")
665. print(Final_FNO)
666.
667. print("flight_sit:")
668. print(flight_sit)
669.
670. #检查乘客是否已满
671. if Final_FNO != '-1':
672. sit_num = 0
673.
674. Sit_num_result = Query_Table_ALL(Passenger_Table)
675. for row in Sit_num_result :
676. if row.Flight_No == Final_FNO:
677. sit_num += 1
678. if sit_num > flight_sit:
679. Final_FNO = '-1'
680. messagebox.showinfo(title="已满",message = "但航班已满,已取消")
681. else:
682. pass
683. print("sit_sum")
684. print(sit_num)
685. else:
686. pass
687. print("Final_FNO:")
688. print(Final_FNO)
689.
690. #添加航班编号
691. if Final_FNO != '-1':
692. messagebox.showinfo(title="成功",message = "已安排到符合修改信息之后的航班")
693. Passenger_Table.Update_Passenger(ID,8,Final_FNO)
694. else:
695. messagebox.showinfo(title="匹配成功",message = "修改后的信息与航班不匹配,已经取消航班")
696. Passenger_Table.Update_Passenger(ID,8,Final_FNO)
697. pass
698.
699.
700.
701. self.page18.destroy()
702. self.createPage_tourist_agency()
703.
704. def comeback_18():
705. is_comeback = messagebox.askyesno("是否返回","是否返回旅行社界面")
706. if is_comeback:
707. self.page18.destroy()
708. self.createPage_tourist_agency()
709.
710. def close_18():
711. is_close = messagebox.askyesno("是否退出","是否真的退出")
712. if is_close:
713. self.page18.destroy()
714. self.root.destroy()
715.
716. ares = Account_Table.Query_Account('T_agency')
717. T_ID = ''
718. for row in ares :
719. if self.user == row.User:
720. T_ID = row.ID_Number
721. #print("*")
722. #print(T_ID)
723. result = Passenger_Table.Query_Passenger(T_ID)
724. CIDlist = list()
725. for row in result:
726. CIDlist.append(row.ID_Card_Number)
727. print(CIDlist)
728.
729. ID = customer_id.get()
730. if ID in CIDlist :#如果该ID是已经添加到了数据库上面的
731. #这里判断之后记得缩进
732. customer_name = tk.StringVar()#乘客姓名
733. customer_sex = tk.StringVar()#性别
734. customer_job = tk.StringVar()#工作单位
735. customer_time = tk.StringVar()#旅行出发时间
736. customer_start_place = tk.StringVar()#旅行始发地
737. customer_end_place = tk.StringVar()#旅行目的地
738. customer_planesit = tk.StringVar()#舱位要求
739.
740. messagebox.showinfo(title="成功",message = "找到符合该身份证号的旅客")
741.
742.
743. self.page17.destroy()
744.
745. self.page18= tk.Frame(self.root)
746. self.page18.pack()
747.
748. tk.Label(self.page18,text="旅客姓名:").grid(row=0,pady=10,stick=tk.W)
749. tk.Entry(self.page18, textvariable=customer_name).grid(row=0, column=1,stick = tk.E)
750.
751. tk.Label(self.page18,text="旅客性别:(F/M)").grid(row=1,pady=10,stick=tk.W)
752. tk.Entry(self.page18, textvariable=customer_sex).grid(row=1, column=1,stick = tk.E)
753.
754. tk.Label(self.page18,text="旅客工作单位:").grid(row=2,pady=10,stick=tk.W)
755. tk.Entry(self.page18, textvariable=customer_job).grid(row=2, column=1,stick = tk.E)
756.
757. #tk.Label(self.page18,text="旅客身份证号码:").grid(row=3,pady=10,stick=tk.W)
758. #tk.Entry(self.page18, textvariable=customer_id).grid(row=3, column=1,stick = tk.E)
759.
760. tk.Label(self.page18,text="旅客旅行出发时间:").grid(row=3,pady=10,stick=tk.W)
761. tk.Entry(self.page18, textvariable=customer_time).grid(row=3, column=1,stick = tk.E)
762.
763. tk.Label(self.page18,text="旅客旅行始发地:").grid(row=4,pady=10,stick=tk.W)
764. tk.Entry(self.page18, textvariable=customer_start_place).grid(row=4, column=1,stick = tk.E)
765.
766. tk.Label(self.page18,text="旅客旅行目的地").grid(row=5,pady=10,stick=tk.W)
767. tk.Entry(self.page18, textvariable=customer_end_place).grid(row=5, column=1,stick = tk.E)
768.
769. tk.Label(self.page18,text="旅客航班舱位要求:").grid(row=6,pady=10,stick=tk.W)
770. tk.Entry(self.page18, textvariable=customer_planesit).grid(row=6, column=1,stick = tk.E)
771.
772. tk.Button(self.page18, text='确定', command=confirm_18).grid(row=7, column=0, padx=5,pady=5)
773.
774. tk.Button(self.page18, text='返回旅行社界面', command=comeback_18).grid(row=7, column=1, padx=5,pady=5)
775.
776. tk.Button(self.page18,text = "退出",command = close_18).grid(row=8, column=0, padx=5,pady=5)
777.
778. tk.Label(self.page18,text="旅客旅行出发时间格式:2020-01-31").grid(row=9,pady=10,stick=tk.W)
779.
780.
781.
782. else:
783. messagebox.showerror(title="错误",message = "找不到该身份证的匹配旅客信息")
784. customer_id.set("")
785.
786. def comeback():
787. is_comeback = messagebox.askyesno("是否返回","是否返回旅行社界面")
788. if is_comeback:
789. self.page17.destroy()
790. self.createPage_tourist_agency()
791.
792. def close():
793. is_close = messagebox.askyesno("是否退出","是否真的退出")
794. if is_close:
795. self.page17.destroy()
796. self.root.destroy()
797.
798. self.page13.destroy()
799.
800. self.root.geometry("500x450")
801. self.root.resizable(0,0)
802.
803.
804. self.page17 = tk.Frame(self.root)
805. self.page17.pack()
806.
807. customer_id = tk.StringVar()#乘客身份证号
808.
809. tk.Label(self.page17,text= "修改旅客信息界面").grid(row=0,pady=10,stick=tk.W)
810.
811. tk.Label(self.page17,text="请输入旅客身份证号码:").grid(row=1,pady=0,stick=tk.W)
812. tk.Entry(self.page17, textvariable=customer_id).grid(row=1, column=1,stick = tk.E)
813.
814. tk.Button(self.page17, text='确定', command=confirm).grid(row=2, column=0, padx=5,pady=5)
815.
816. tk.Button(self.page17, text='返回旅行社界面', command=comeback).grid(row=2, column=1, padx=5,pady=5)
817.
818. tk.Button(self.page17,text = "退出",command = close).grid(row=3, column=0, padx=5,pady=5)
819.
820. #-----------------------------查看旅客信息--------------------------------------------------------------
821. def check_customer_information(self):
822. def close_this_window():
823. window_sign_up.destroy()
824.
825. num = 0
826.
827. name = ''
828. sex = ''
829. job = ''
830. ID = ''
831. time = ''
832. start_place = ''
833. end_place = ''
834. planesit = ''
835.
836.
837. window_sign_up = tk.Toplevel(self.page13)
838. window_sign_up.geometry("500x200")#你可以用这个调整窗口大小
839. window_sign_up.title("查看旅客信息")
840. window_sign_up.resizable(0,0)
841.
842.
843. sb = tk.Scrollbar(window_sign_up)
844. sb.pack(side = tk.RIGHT,fill = "y")
845.
846. lb = tk.Listbox(window_sign_up,yscrollcommand = sb.set,width = 100,height = 100)
847. lb.pack(side=tk.LEFT,fill="both")
848.
849.
850. sb.config(command = lb.yview)
851.
852. #查询该账号的ID,并生成旅客ID列表
853. ares = Account_Table.Query_Account('T_agency')
854. T_ID = ''
855. for row in ares :
856. if self.user == row.User:
857. T_ID = row.ID_Number
858. #print("*")
859. #print(T_ID)
860. result = Passenger_Table.Query_Passenger(T_ID)
861. CIDlist = list()
862. for row in result:
863. CIDlist.append(row.ID_Card_Number)
864. print(CIDlist)
865.
866. #result = Passenger_Table.Query_Passenger(self.user)
867. num = 0
868.
869. for row in result:
870. name = "旅客姓名:" + row.Name
871. if row.Sex == "F":
872. sex = "旅客性别:"+"女"
873. elif row.Sex == "M":
874. sex = "旅客性别:"+"男"
875.
876. job = "旅客工作单位:"+row.Workplace,
877. ID = "旅客身份证号码:"+row.ID_Card_Number,
878. time = "旅客旅行出发时间:" + row.travel_time
879. start_place = "旅客旅行始发地:"+ row.place_travel_start
880. end_place = "旅客旅行目的地:"+row.place_travel_end
881. planesit = "旅客航班舱位要求:" + row.requirement_berths
882.
883. lb.insert('end',name)
884. lb.insert('end',sex)
885. lb.insert('end',job)
886. lb.insert('end',ID)
887. lb.insert('end',time)
888. lb.insert('end',start_place)
889. lb.insert('end',end_place)
890. lb.insert('end',planesit)
891. lb.insert('end',"---------------------------------------------------------------------")
892.
893. num = num + 1
894.
895. name = ""
896. sex = ""
897. job = ""
898. ID = ""
899. time = ""
900. start_place = ""
901. end_place = ""
902. planesit = ""
903.
904.
905.
906.
907. str1= str("一共有%d个旅客信息" %num)#加上你统计来的旅客个数
908. tk.Label(window_sign_up,text=str1).place(x=200,y=0)
909. tk.Button(window_sign_up,text="OK",command=close_this_window).place(x=250,y=170)
910.
3.5 旅客界面
旅客界面也是创造了一个类, 在类的构造函数里面设置好框的大小,然后调用createPage函数创造各个tkinter的部件。并且创建出方法: 确认订单,取票。
1. # -*- coding: utf-8 -*-
2. """
3. Created on Thu May 28 18:10:32 2020
4.
5. """
6.
7. import interface
8. from interface import Account_Table, Passenger_Table, Airline_Company_Table, Travel_Agency_Table, Flight_Information_Table, Order_information_table, Query_Table_ALL
9.
10.
11. import tkinter as tk
12. import LoginPage as Login
13. import pickle
14. import tkinter.messagebox as messagebox
15. import random
16. import string
17.
18. class Customers_MainPage(object):
19. def __init__(self,master = None,usrs = None):
20. self.root = master #定义内部变量root
21.
22. self.user = usrs
23. print(self.user)
24.
25. self.createPage_customer()
26.
27. def createPage_customer(self):
28. self.root.geometry("500x400")
29. self.root.resizable(0,0)
30.
31. self.page10 = tk.Frame(self.root)
32. self.page10.pack()
33.
34. tk.Label(self.page10,text="欢迎来到旅客界面!用户:"+self.user).grid(row=0,stick=tk.W)
35.
36. tk.Button(self.page10,text="确认订单",command=self.makesure_and_pay).grid(row = 1,column=0,padx=5,pady=5)
37. tk.Button(self.page10,text="取票",command=self.getticket).grid(row = 1,column=1,padx=5,pady=5)
38.
39. tk.Button(self.page10,text="注销用户",command=self.reback_to_login).grid(row = 2,column=0,padx=5,pady=5)
40. tk.Button(self.page10,text="退出",command=self.close).grid(row = 2,column=1,padx=5,pady=5)
41.
42. def makesure_and_pay(self):#确认订单
43. def confirm():
44.
45. def comeback_confirm():
46. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回旅客界面")
47. if is_come_back_to_login:
48. self.page13.destroy()
49. self.createPage_customer()
50.
51. def close_confirm():
52. is_close = messagebox.askyesno("是否退出","是否真的退出")
53. if is_close:
54. self.page13.destroy()
55. self.root.destroy()
56.
57. customer_id = new_customer_id.get()
58. if customer_id == "":#身份证没有填入
59. messagebox.showerror("错误","请输入身份证号")
60. else:
61.
62. #查询本账号的身份证
63. ares = Account_Table.Query_Account('Customer')
64. AC_ID = ''
65. for row in ares :
66. if self.user == row.User:
67. AC_ID = row.ID_Number
68.
69. if customer_id != AC_ID:#身份证填入的跟本账号的身份证不一致
70. messagebox.showerror("错误","输入的身份证号不是跟本账户的身份证号一致,请重新输入")
71. new_customer_id.set("")
72. else:
73.
74. p_f_ares = Query_Table_ALL(Passenger_Table)
75. F_NOdict = dict()#根据身份证为key的,航班编号字典
76. P_IDlist = list()
77. O_NOdict = dict()
78.
79. for row in p_f_ares :
80. P_IDlist.append(row.ID_Card_Number)#每一行的身份证信息
81. F_NOdict[row.ID_Card_Number] = row.Flight_No#每一行的航班号
82. O_NOdict[row.ID_Card_Number] = row.Order_NO#每一行的订单号
83.
84.
85. if AC_ID in P_IDlist:#如果该身份证号码在旅客信息里面找到
86. result = Query_Table_ALL(Passenger_Table)
87.
88. self.page11.destroy()
89.
90. self.page13 = tk.Frame(self.root)
91. self.page13.pack()
92.
93. self.root.geometry("500x500")
94. self.root.resizable(0,0)
95.
96. tk.Label(self.page13,text="旅客检查信息").grid(row=0,stick=tk.W)
97.
98. for row in result:
99. if row.ID_Card_Number == AC_ID:#单独列出该身份证的旅客信息
100. str1 = "旅客姓名:%s\n" %(row.Name)
101. str2 = "旅客性别:%s\n" %(row.Sex)
102. str3 = "旅客工作单位:%s\n" %(row.Workplace)
103. str4 = "旅客身份证号码:%s\n" %(row.ID_Card_Number)
104. str5 = "旅客旅行时间:%s\n" %(row.travel_time)
105. str6 = "旅客旅行始发地:%s\n" %(row.place_travel_start)
106. str7 = "旅客旅行目的地:%s\n" %(row.place_travel_end)
107. str8 = "航班舱位要求:%s\n" %(row.requirement_berths)
108.
109.
110.
111. tk.Label(self.page13,text=str1).grid(row=1,stick=tk.W)
112. tk.Label(self.page13,text=str2).grid(row=2,stick=tk.W)
113. tk.Label(self.page13,text=str3).grid(row=3,stick=tk.W)
114. tk.Label(self.page13,text=str4).grid(row=4,stick=tk.W)
115. tk.Label(self.page13,text=str5).grid(row=5,stick=tk.W)
116. tk.Label(self.page13,text=str6).grid(row=6,stick=tk.W)
117. tk.Label(self.page13,text=str7).grid(row=7,stick=tk.W)
118. tk.Label(self.page13,text=str8).grid(row=8,stick=tk.W)
119.
120. if F_NOdict[AC_ID] == "-1":
121. tk.Label(self.page13,text="没有符合的航班").grid(row = 10,stick = tk.W)
122. else:
123. if O_NOdict[AC_ID] == '-1':
124. tk.Button(self.page13, text='生成订单', command=self.pay).grid(row=11, column=0, padx=5,pady=5)
125. else:
126. pass
127.
128. #tk.Button(self.page13, text='确认信息并付款', command=self.pay).grid(row=11, column=0, padx=5,pady=5)
129.
130. tk.Button(self.page13, text='返回', command=comeback_confirm).grid(row=11, column=1, padx=5,pady=5)
131.
132. tk.Button(self.page13,text = "退出",command = close_confirm).grid(row=11, column=2, padx=5,pady=5)
133. else:
134. messagebox.showerror("错误","没有找到该身份证号旅客的信息,请联系旅行社或者重新输入正确的身份证号")
135. new_customer_id.set("")
136.
137.
138. def comeback():
139. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回旅客界面")
140. if is_come_back_to_login:
141. self.page11.destroy()
142. self.createPage_customer()
143.
144. def close():
145. is_close = messagebox.askyesno("是否退出","是否真的退出")
146. if is_close:
147. self.page11.destroy()
148. self.root.destroy()
149.
150. self.page10.destroy()
151.
152. self.page11 = tk.Frame(self.root)
153. self.page11.pack()
154.
155.
156. new_customer_id = tk.StringVar()
157. new_customer_id.set("440105199901071077")
158.
159. tk.Label(self.page11,text="确定订单信息").grid(row=0,column = 1,stick=tk.W)
160.
161. tk.Label(self.page11,text="请输入身份证号:").grid(row=1,pady=10,stick=tk.W)
162. tk.Entry(self.page11, textvariable=new_customer_id).grid(row=1, column=1,stick = tk.E)
163.
164. tk.Button(self.page11, text='确认', command=confirm).grid(row=8, column=0, padx=5,pady=5)
165.
166. tk.Button(self.page11, text='返回旅客界面', command=comeback).grid(row=8, column=1, padx=5,pady=5)
167.
168. tk.Button(self.page11,text = "退出",command = close).grid(row=8, column=2, padx=5,pady=5)
169.
170.
171. def getticket(self):#取票
172.
173. def confirm():
174. number = ticket_number.get()
175. ID = order_id.get()
176.
177. #查询本账号的身份证
178. ares = Account_Table.Query_Account('Customer')
179. AC_ID = ''
180. for row in ares :
181. if self.user == row.User:
182. AC_ID = row.ID_Number
183.
184. p_f_ares = Query_Table_ALL(Passenger_Table)
185. O_NOdict = dict()
186. for row in p_f_ares:
187. O_NOdict[row.ID_Card_Number] = row.Order_NO
188.
189. result = Query_Table_ALL(Order_information_table)
190. codedict = dict()
191. for row in result:
192. codedict[row.Order_no] = row.code_get_ticket
193.
194.
195. if ID == "":
196. messagebox.showerror(title = "错误",message = "请输入订单号")
197. elif number == "":
198. messagebox.showerror(title = "错误",message = "请输入取票码")
199. elif ID != O_NOdict[AC_ID]:
200. #如果订单号不匹配
201. messagebox.showerror(title = "错误",message = "订单号不匹配")
202. elif number != codedict[O_NOdict[AC_ID]] :
203. #如果取票码不匹配
204. messagebox.showerror(title = "错误",message = "取票码不匹配")
205.
206. else:#订单号和取票码都匹配
207. Passenger_Table.Update_Passenger(AC_ID,10,'-1')
208. messagebox.showinfo(title="操作成功",message = "出票成功")
209. #打印相关的一部分的旅客信息与航班信息即可
210. self.page12.destroy()
211. self.createPage_customer()
212.
213. def comeback():
214. is_come_back_to_login = messagebox.askyesno("是否返回","是否返回旅客界面")
215. if is_come_back_to_login:
216. self.page12.destroy()
217. self.createPage_customer()
218.
219. def close():
220. is_close = messagebox.askyesno("是否退出","是否真的要退出")
221. if is_close:
222. self.page12.destroy()
223. self.root.destroy()
224.
225.
226.
227.
228.
229. self.page10.destroy()
230.
231. self.page12 = tk.Frame(self.root)
232. self.page12.pack()
233.
234. ticket_number = tk.StringVar()#取票码
235. order_id = tk.StringVar()#订单号
236.
237. tk.Label(self.page12,text="请输入取票码:").grid(row=0,pady=10,stick=tk.W)
238. tk.Entry(self.page12, textvariable=ticket_number).grid(row=0, column=1,stick = tk.E)
239.
240. tk.Label(self.page12,text="请输入订单号:").grid(row=1,pady=10,stick=tk.W)
241. tk.Entry(self.page12, textvariable=order_id).grid(row=1, column=1,stick = tk.E)
242.
243. tk.Button(self.page12, text='取票', command=confirm).grid(row=8, column=0, padx=5,pady=5)
244.
245. tk.Button(self.page12, text='返回旅客界面', command=comeback).grid(row=8, column=1, padx=5,pady=5)
246.
247. tk.Button(self.page12,text = "退出",command = close).grid(row=8, column=2, padx=5,pady=5)
248.
249. def pay(self):
250.
251. def comeback():
252. self.page14.destroy()
253. self.createPage_customer()
254.
255. def close():
256. is_close = messagebox.askyesno("是否退出","是否真的要退出")
257. if is_close:
258. self.page14.destroy()
259. self.root.destroy()
260.
261. self.page13.destroy()
262.
263. self.page14 = tk.Frame(self.root)
264. self.page14.pack()
265.
266. Order_no = ''
267. ID_Card_Number = ''
268. Travel_agency_No = ''
269. Flight_no = ''
270. price = ''
271. code_get_ticket = ''
272.
273.
274.
275. #查询本账号的身份证
276. ares = Account_Table.Query_Account('Customer')
277. AC_ID = ''
278. for row in ares :
279. if self.user == row.User:
280. AC_ID = row.ID_Number
281.
282. p_f_ares = Query_Table_ALL(Passenger_Table)
283. F_NOdict = dict()#根据身份证为key的,航班编号字典
284. P_IDlist = list()
285. O_NOlist = list()
286. O_NOdict = dict()
287. T_NOdict = dict()
288.
289. for row in p_f_ares :
290. P_IDlist.append(row.ID_Card_Number)#每一行的身份证信息
291. O_NOlist.append(row.Order_NO)
292.
293. F_NOdict[row.ID_Card_Number] = row.Flight_No#每一行的航班号
294. O_NOdict[row.ID_Card_Number] = row.Order_NO#每一行的订单号
295. T_NOdict[row.ID_Card_Number] = row.Travel_agency_No
296.
297. result = Query_Table_ALL(Flight_Information_Table)
298. Pricedict = dict()
299. for row in result:
300. Pricedict[row.Flight_no] = row.price
301.
302.
303. result = Query_Table_ALL(Order_information_table)
304. O_NOlist = list()
305. for row in result:
306. O_NOlist.append(row.Order_no)
307.
308. Order_ran_str = ''.join(random.sample(string.digits, 8))
309.
310. while Order_ran_str in O_NOlist:
311. Order_ran_str = ''.join(random.sample(string.digits, 8))
312.
313. code_ran_str = ''.join(random.sample(string.ascii_letters+string.digits, 8))
314.
315.
316.
317. Order_no = Order_ran_str
318. ID_Card_Number = AC_ID
319. Travel_agency_No = T_NOdict[AC_ID]
320. Flight_no = F_NOdict[AC_ID]
321. price = Pricedict[Flight_no]
322. code_get_ticket = code_ran_str
323.
324.
325. Order_information_table.Insert_Order(Order_no,ID_Card_Number,Travel_agency_No,Flight_no,price,code_get_ticket)
326. Passenger_Table.Update_Passenger(AC_ID,10,Order_no)
327.
328.
329.
330.
331. tk.Label(self.page14,text="订单生成成功").grid(row=0,pady=10,stick=tk.W)
332.
333.
334. #ran_str = ''.join(random.sample(string.digits, 8))
335.
336. tk.Label(self.page14,text="订单号:"+Order_ran_str).grid(row=1,pady=10,stick=tk.W)
337.
338.
339. #ran_str = ''.join(random.sample(string.ascii_letters+string.digits, 8))
340.
341. tk.Label(self.page14,text="取票码:"+code_ran_str).grid(row=2,pady=10,stick=tk.W)
342.
343. tk.Label(self.page14,text="请凭借订单号和取票码取票").grid(row=3,pady=10,stick=tk.W)
344.
345. tk.Button(self.page14, text='返回旅客界面', command=comeback).grid(row=4, column=0, padx=5,pady=5)
346.
347. tk.Button(self.page14,text = "退出",command = close).grid(row=4, column=1, padx=5,pady=5)
348.
349.
350. def reback_to_login(self):
351. is_reback_login = messagebox.askyesno("是否注销","是否注销账号返回登录界面")
352. if is_reback_login:
353. self.page10.destroy()
354. Login.LoginPage(self.root)
355.
356. def close(self):
357. is_close = messagebox.askyesno("是否退出","是否真的退出")
358. if is_close:
359. self.page10.destroy()
360. self.root.destroy()
- 实验结果
运行此程序需要安装mysql数据库,手动安全pymysql,sqlalchemy库之后,在“创建mysql数据库”中,将pycreate_database.py里的connetion = pymysql.connect(host = ‘localhost’,port = 3306, user = ‘root’, password=‘123456’)修改为与自己mysql连接一致的信息。之后双击Test.py创建数据库。
登录页面:
管理员页面:
添加航空公司:
删除航空公司:
查看航空公司:
添加旅客:
删除旅客:
查看旅客:
添加旅行社:
删除旅行社:
查看旅行社:
航空公司:
添加航班信息
删除航班信息
修改航班信息
查询航班信息
旅行社:
添加旅客信息
删除旅客信息
修改旅客信息
查询旅客信息。
旅客:
确认订单
取票
上一篇: 通过微信WEUI实现图片上传,后台PHP该如何处理?
下一篇: php如何获取Access的字段名称