目录
文章目录
前言
一、目的和背景
二、数据库设置
1.概念结构设计
E-R图:
2.逻辑结构设计
管理员列表
游客列表
医院信息列表
部门信息表
护士信息表
药品信息表
医生资料表
病房信息表
患者信息表
护士护理记录表
病人用药记录表
3.物理结构设计
触发器设计
三、系统概要设计
1.框架设计
系统框架设计图:
2.功能实现
(1)Python代码
(2)代码所需图片
(3)MYSQL代码
(4)执行效果
四、注意
本文参考数据库课程设计:医院信息管理系统(pycharm+MySQL)_流光2021的博客-CSDN博客_数据库医院信息管理系统
修改了一些原文,也加入了自己的设计,简单分享介绍。想直接跑程序记得看 四、注意 ,里面都是自己犯的错和要修改的设置。
医院信息管理是一项琐碎、复杂而又十分细致的工作,这关系到医院体系能否运行起来这一关乎国民健康水平的重大问题。只有利用好了医院中每个医生、护士的各项资源,才能使得医院系统能够有序而条理的进行,更好的安排有限的医生和护士资源,安排患者就诊。医院信息管理实现对科室,医生,患者,护士等进行增、删、改、查操作。更好的安排有限的医生和护士资源,安排患者就诊。同时,在设计医院信息管理系统的同时也兼顾了药品的管理,使得我们在安排各项工作的时候能够更加清晰明了,也可以与药房管理系统和挂号管理系统相连接,更好的实现医院的管理功能。
表的详细结构如下所示:
字段名 |
字段类型 |
备注 |
是否为空 |
admin_id |
char(20) |
管理员账号(主键) |
否 |
admin_pass |
char(20) |
管理员密码 |
否 |
字段名 |
字段类型 |
备注 |
是否为空 |
stu_id |
char(20) |
游客账号(主键) |
否 |
stu_pass |
char(20) |
游客密码 |
否 |
字段名 |
字段类型 |
备注 |
是否为空 |
id |
char(20) |
编号(主键) |
否 |
hpname |
char(20) |
医院名称 |
否 |
hos |
char(20) |
院长 |
否 |
hadr |
char(20) |
地址 |
否 |
htel |
char(20) |
电话 |
否 |
字段名 |
字段类型 |
备注 |
是否为空 |
dpname |
char(10) |
科室名 |
否 |
dpno |
char(2) |
编号(主键) |
否 |
dpadr |
char(20) |
地址 |
否 |
dptel |
char(20) |
电话 |
否 |
字段名 |
字段类型 |
备注 |
是否为空 |
nno |
char(2) |
护士编号(主键) |
否 |
nnname |
char(10) |
护士名 |
否 |
nsex |
char(1) |
性别 |
否 |
nage |
int |
年龄 |
否 |
字段名 |
字段类型 |
备注 |
是否为空 |
dgno |
char(4) |
编号(主键) |
否 |
dgname |
char(20) |
药品名 |
否 |
dgpro |
char(20) |
厂家 |
否 |
dgnum |
int |
库存 |
否 |
dgprice |
int |
价格 |
否 |
字段名 |
字段类型 |
备注 |
是否为空 |
dno |
char(3) |
编号(主键) |
否 |
dname |
char(20) |
姓名 |
否 |
duty |
char(20) |
职称 |
否 |
dsex |
char(2) |
性别 |
否 |
dage |
int |
年龄 |
否 |
dpno |
char(2) |
科室(外键) |
否 |
字段名 |
字段类型 |
备注 |
是否为空 |
rno |
char(10) |
病房号(主键) |
否 |
radr |
char(20) |
地址 |
否 |
dpno |
char(5) |
科室号(外键) |
否 |
字段名 |
字段类型 |
备注 |
是否为空 |
pno |
char(20) |
编号(主键) |
否 |
pnome |
char(20) |
姓名 |
否 |
psex |
char(2) |
性别 |
否 |
page |
int |
年龄 |
否 |
dno |
char(3) |
医生编号(外键) |
否 |
rno |
char(10) |
科室(外键) |
否 |
illness |
char(20) |
病症 |
否 |
startdate |
date |
治疗时间 |
否 |
predictenddate |
date |
康复时间 |
否 |
字段名 |
字段类型 |
备注 |
是否为空 |
pno |
char(20) |
药品编号(外键) |
否 |
nno |
char(2) |
患者编号(外键) |
否 |
content |
char(20) |
用药次数 |
否 |
time |
datetime |
时间 |
否 |
字段名 |
字段类型 |
备注 |
是否为空 |
dgno |
char(4) |
药品编号(外键,主键) |
否 |
pno |
char(4) |
患者编号(外键,主键) |
否 |
num |
int |
用药次数 |
否 |
触发器代码:
CREATE TRIGGER chufa
AFTER DELETE ON pd FOR EACH ROW
BEGIN
delete from drug where dgno=old.dgno;
END
# (◕‿◕✿) ♪ 必须成功!
# ヾ(≧O≦)〃一次性通过~嗷~
import pymysql
from tkinter import ttk
import tkinter as tk
import tkinter.font as tkFont
from tkinter import * # 图形界面库
import tkinter.messagebox as messagebox # 弹窗
# 开始页面类
class StartPage:
def __init__(self , parent_window):
parent_window.update()
parent_window.destroy() # 销毁子界面
self.window = tk.Tk() # 初始框的声明
self.window.title('医院信息管理系统')
self.window.geometry('600x700') # 这里的乘是小x
# 创建一个图片管理类
photo = tk.PhotoImage(file="img3.png") # file:t图片路径
label = tk.Label(self.window ,
text="医院信息管理系统" ,
justify=tk.LEFT ,
image=photo ,
compound=tk.CENTER , # 设置为背景图片
font=("Verdana" , 20) ,
fg="black")
label.pack(pady=0) # 界面的长度
# 管理员登录
Button(self.window , text="管理员登陆" , font=tkFont.Font(size=16) , command=lambda: AdminPage(self.window) ,
width=30 ,
height=2 , fg='white' , bg='cornflowerblue' , activebackground='black' , activeforeground='white').pack()
# 游客登录
Button(self.window , text="游客登陆" , font=tkFont.Font(size=16) , command=lambda: StudentPage(self.window) ,
width=30 ,
height=2 , fg='white' , bg='orange' , activebackground='black' , activeforeground='white').pack()
# about页面
Button(self.window , text="关于" , font=tkFont.Font(size=16) , command=lambda: AboutPage(self.window) ,
width=30 ,
height=2 , fg='white' , bg='pink' , activebackground='black' , activeforeground='white').pack()
# 退出系统
Button(self.window , text='退出系统' , font=tkFont.Font(size=16) , command=self.window.destroy ,
width=30 ,
height=2 , fg='white' , bg='gray' , activebackground='black' , activeforeground='white').pack()
self.window.mainloop() # 主消息循环
# 管理员登陆页面的初始化
class AdminPage:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = tk.Tk() # 初始框的声明
self.window.title('管理员登陆页面')
self.window.geometry('600x650') # 这里的乘是小x
# 创建一个图片管理类
photo1 = tk.PhotoImage(file="登录.png") # file:t图片路径
label = tk.Label(self.window,
image=photo1 ,
compound=tk.CENTER , # 设置为背景图片
)
label.pack(pady=0) # 界面的长度
label = tk.Label(self.window , text='管理员登陆' , bg='cornflowerblue' , font=('Verdana' , 20) , width=40 , height=0)
label.pack()
Label(self.window , text='管理员账号:' , font=tkFont.Font(size=14)).pack(pady=25)
self.admin_username = tk.Entry(self.window , width=30 , font=tkFont.Font(size=14) , bg='Ivory')
self.admin_username.pack()
Label(self.window , text='管理员密码:' , font=tkFont.Font(size=14)).pack(pady=25)
self.admin_pass = tk.Entry(self.window , width=30 , font=tkFont.Font(size=14) , bg='Ivory' , show='*')
self.admin_pass.pack()
Button(self.window , text="登陆" , width=8 , font=tkFont.Font(size=12) ,
command=self.login , fg='white' , bg='gray' , activebackground='black' ,
activeforeground='white').pack(pady=20)
Button(self.window , text="返回首页" , width=8 , font=tkFont.Font(size=12) , command=self.back , fg='white' ,
bg='gray' , activebackground='black' , activeforeground='white').pack()
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
# 登录
def login(self):
print("正在登陆管理员管理界面")
print("输入用户名" , str(self.admin_username.get()))
print("输入密码" , str(self.admin_pass.get()))
admin_pass = None
# 数据库操作 查询管理员表
dp = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
) # 打开数据库连接
cur = dp.cursor() # 使用cursor()方法获取操作游标
sq = "SELECT * FROM admin_login_k WHERE admin_id = '%s'" % (self.admin_username.get()) # SQL 查询语句
try:
# 执行SQL语句
cur.execute(sq)
# 获取所有记录列表
results = cur.fetchall()
for row in results:
admin_id = row[0]
admin_pass = row[1]
# 打印结果
print("admin_id=%s,admin_pass=%s" % (admin_id , admin_pass))
except:
print("Error: unable to get data")
messagebox.showinfo('警告!' , '用户名或密码不正确!')
dp.close() # 关闭数据库连接
if self.admin_pass.get() == admin_pass:
Gongnengjiemian(self.window) # 进入管理员操作界面
else:
messagebox.showinfo('警告!' , '用户名或密码不正确!')
def back(self):
StartPage(self.window) # 显示主窗口 销毁本窗口
# 游客登陆页面的初始化
class StudentPage:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = tk.Tk() # 初始框的声明
self.window.title('游客登陆')
self.window.geometry('600x650') # 这里的乘是小x
# 创建一个图片管理类
photo1 = tk.PhotoImage(file="登录.png") # file:t图片路径
label = tk.Label(self.window,
image=photo1 ,
compound=tk.CENTER , # 设置为背景图片
)
label.pack(pady=0) # 界面的长度
label = tk.Label(self.window , text='游客登陆' , bg='orange' , font=('Verdana' , 20) , width=40 , height=0)
label.pack()
Label(self.window , text='游客账号:' , font=tkFont.Font(size=14)).pack(pady=15)
self.student_id = tk.Entry(self.window , width=30 , font=tkFont.Font(size=14) , bg='Ivory')
self.student_id.pack()
Label(self.window , text='游客密码:' , font=tkFont.Font(size=14)).pack(pady=10)
self.student_pass = tk.Entry(self.window , width=30 , font=tkFont.Font(size=14) , bg='Ivory' , show='*')
self.student_pass.pack()
Button(self.window , text="登陆" , width=8 , font=tkFont.Font(size=12) , command=self.login , fg='white' ,
bg='gray' , activebackground='black' , activeforeground='white').pack(pady=30)
Button(self.window , text="返回首页" , width=8 , font=tkFont.Font(size=12) , command=self.back , fg='white' ,
bg='gray' , activebackground='black' , activeforeground='white').pack()
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
# 登录函数
def login(self):
print(str(self.student_id.get()))
print(str(self.student_pass.get()))
stu_pass = None
# 数据库操作 查询管理员表
dbs = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
) # 打开数据库连接
cursors = dbs.cursor() # 使用cursor()方法获取操作游标
sqll = "SELECT * FROM stu_login_k WHERE stu_id = '%s'" % (self.student_id.get()) # SQL 查询语句
try:
# 执行SQL语句
cursors.execute(sqll)
# 获取所有记录列表
results = cursors.fetchall()
for row in results:
stu_id = row[0]
stu_pass = row[1]
# 打印结果
print("stu_id=%s,stu_pass=%s" % (stu_id , stu_pass))
except:
print("Error: unable to get data")
messagebox.showinfo('警告!' , '用户名或密码不正确!')
dbs.close() # 关闭数据库连接
print("正在登陆游客查看界面")
print("self:" , self.student_pass.get())
print("local:" , stu_pass)
if self.student_pass.get() == stu_pass:
StudentView(self.window , self.student_id.get()) # 进入学生信息查看界面
else:
messagebox.showinfo('警告!' , '用户名或密码不正确!')
def back(self):
StartPage(self.window) # 显示主窗口 销毁本窗口
# About页面
class AboutPage:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = tk.Tk() # 初始框的声明
self.window.title('关于')
self.window.geometry('300x400') # 这里的乘是小x
# 创建一个图片管理类
photo1 = tk.PhotoImage(file="about.png") # file:t图片路径
label = tk.Label(self.window,
image=photo1 ,
compound=tk.CENTER , # 设置为背景图片
)
label.pack(pady=0) # 界面的长度
label = tk.Label(self.window , text='医院信息管理系统' , bg='pink' , font=('Verdana' , 20) , width=30 , height=0)
label.pack()
Label(self.window , text='作者:王长信' , font=('Verdana' , 18)).pack(pady=15)
Label(self.window , text='' , font=('Verdana' , 18)).pack(pady=5)
Button(self.window , text="返回首页" , width=8 , font=tkFont.Font(size=12) , command=self.back).pack(pady=20)
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def back(self):
StartPage(self.window) # 显示主窗口 销毁本窗口
# 功能界面的初始化
class Gongnengjiemian:
def __init__(self , parent_window):
self.admin_pass = 'wjj1546314877'
self.admin_username = 'root'
parent_window.destroy() # 销毁主界面
self.window = tk.Tk() # 初始框的声明
self.window.title('功能选择界面')
self.window.geometry('500x700') # 这里的乘是小x
# 创建一个图片管理类
photo1 = tk.PhotoImage(file="gongneng.png") # file:t图片路径
label = tk.Label(self.window,
image=photo1 ,
compound=tk.CENTER , # 设置为背景图片
)
label.pack(pady=0) # 界面的长度
Button(self.window , text="科室管理" , width=18 , font=tkFont.Font(size=12) ,
command=lambda: AdminManage(self.window) , fg='white' , bg='aqua' , activebackground='black' ,
activeforeground='white').pack(pady=10)
Button(self.window , text="医生资料管理" , width=18 , font=tkFont.Font(size=12) ,
command=lambda: AdminManage1(self.window) , fg='white' , bg='lightskyblue' , activebackground='black' ,
activeforeground='white').pack(pady=10)
Button(self.window , text="护士资料管理" , width=18 , font=tkFont.Font(size=12) ,
command=lambda: AdminManage2(self.window) , fg='white' , bg='deepskyblue' , activebackground='black' ,
activeforeground='white').pack(pady=10)
Button(self.window , text="患者资料管理" , width=18 , font=tkFont.Font(size=12) ,
command=lambda: AdminManage3(self.window) , fg='white' , bg='dodgerblue' , activebackground='black' ,
activeforeground='white').pack(pady=10)
Button(self.window , text="药品资料管理" , width=18 , font=tkFont.Font(size=12) ,
command=lambda: AdminManage4(self.window) , fg='white' , bg='steelblue' , activebackground='black' ,
activeforeground='white').pack(pady=10)
Button(self.window , text="病房资料管理" , width=18 , font=tkFont.Font(size=12) ,
command=lambda: AdminManage5(self.window) , fg='white' , bg='cornflowerblue' , activebackground='black' ,
activeforeground='white').pack(pady=10)
Button(self.window , text="病人用药记录管理" , width=18 , font=tkFont.Font(size=12) ,
command=lambda: AdminManage6(self.window) , fg='white' , bg='royalblue' , activebackground='black' ,
activeforeground='white').pack(pady=10)
Button(self.window , text="护士护理记录管理" , width=18 , font=tkFont.Font(size=12) ,
command=lambda: AdminManage7(self.window) , fg='white' , bg='slateblue' , activebackground='black' ,
activeforeground='white').pack(pady=10)
Button(self.window , text="返回首页" , width=8 , font=tkFont.Font(size=12) , command=self.back , fg='white' ,
bg='gray' , activebackground='black' , activeforeground='white').pack()
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def back(self):
StartPage(self.window) # 显示主窗口 销毁本窗口
# 科室资料管理操作界面
class AdminManage:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = Tk() # 初始框的声明
self.window.title('科室资料操作界面')
self.frame_left_top = tk.Frame(width=300 , height=200)
self.frame_right_top = tk.Frame(width=300 , height=200)
self.frame_center = tk.Frame(width=500 , height=400)
self.frame_bottom = tk.Frame(width=650 , height=50)
# 定义下方中心列表区域
self.columns = ("科室名" , "编号" , "地址" , "电话")
self.tree = ttk.Treeview(self.frame_center , show="headings" , height=18 , columns=self.columns)
self.vbar = ttk.Scrollbar(self.frame_center , orient=VERTICAL , command=self.tree.yview)
# 定义树形结构与滚动条
self.tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.tree.column("科室名" , width=150 , anchor='center') # 表示列,不显示
self.tree.column("编号" , width=100 , anchor='center')
self.tree.column("地址" , width=120 , anchor='center')
self.tree.column("电话" , width=130 , anchor='center')
# 调用方法获取表格内容插入
self.tree.grid(row=0 , column=0 , sticky=NSEW)
self.vbar.grid(row=0 , column=1 , sticky=NS)
self.dpname = []
self.dpno = []
self.dpadr = []
self.dptel = []
# 打开数据库连接
dbs = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursors = dbs.cursor() # 使用cursor()方法获取操作游标
sqll = "SELECT * FROM vdepartment" # SQL 查询语句
try:
# 执行SQL语句
cursors.execute(sqll)
# 获取所有记录列表
results = cursors.fetchall()
for row in results:
self.dpname.append(row[0])
self.dpno.append(row[1])
self.dpadr.append(row[2])
self.dptel.append(row[3])
except:
print("Error: unable to get data")
messagebox.showinfo('警告!' , '数据库连接失败!')
dbs.close() # 关闭数据库连接
print("*********************** 科室 ***********************")
for i in range(min(len(self.dpname) , len(self.dpno) , len(self.dpadr) , len(self.dptel))): # 写入数据
self.tree.insert('' , i , values=(self.dpname[i] , self.dpno[i] , self.dpadr[i] , self.dptel[i]))
for col in self.columns: # 绑定函数,使表头可排序
self.tree.heading(col , text=col , command=lambda _col=col: self.tree_sort_column(self.tree , _col , False))
# 定义顶部区域
# 定义左上方区域
self.top_title = Label(self.frame_left_top , text="科室信息" , bg='aqua' , font=('Verdana' , 20))
self.top_title.grid(row=0 , column=0 , columnspan=2 , sticky=NSEW , padx=50 , pady=10)
self.left_top_frame = tk.Frame(self.frame_left_top)
self.var_dpname = StringVar() # 声明科室名
self.var_dpno = StringVar() # 声明编号
self.var_dpadr = StringVar() # 声明地址
self.var_dptel = StringVar() # 声明电话
# 科室名
self.right_top_dpname_label = Label(self.frame_left_top , text="科室名:" , font=('Verdana' , 15))
self.right_top_dpname_entry = Entry(self.frame_left_top , textvariable=self.var_dpname , font=('Verdana' , 15))
self.right_top_dpname_label.grid(row=1 , column=0) # 位置设置
self.right_top_dpname_entry.grid(row=1 , column=1)
# 编号
self.right_top_dpno_label = Label(self.frame_left_top , text="编号:" , font=('Verdana' , 15))
self.right_top_dpno_entry = Entry(self.frame_left_top , textvariable=self.var_dpno , font=('Verdana' , 15))
self.right_top_dpno_label.grid(row=2 , column=0) # 位置设置
self.right_top_dpno_entry.grid(row=2 , column=1)
# 地址
self.right_top_dpadr_label = Label(self.frame_left_top , text="地址:" , font=('Verdana' , 15))
self.right_top_dpadr_entry = Entry(self.frame_left_top , textvariable=self.var_dpadr , font=('Verdana' , 15))
self.right_top_dpadr_label.grid(row=3 , column=0) # 位置设置
self.right_top_dpadr_entry.grid(row=3 , column=1)
# 电话
self.right_top_dptel_label = Label(self.frame_left_top , text="电话:" , font=('Verdana' , 15))
self.right_top_dptel_entry = Entry(self.frame_left_top , textvariable=self.var_dptel , font=('Verdana' , 15))
self.right_top_dptel_label.grid(row=4 , column=0) # 位置设置
self.right_top_dptel_entry.grid(row=4 , column=1)
# 定义右上方区域
self.right_top_title = Label(self.frame_right_top , text="操作" , font=('Verdana' , 20))
self.tree.bind('' , self.click) # 左键获取位置
self.right_top_button1 = ttk.Button(self.frame_right_top , text='新建科室信息' , width=20 , command=self.new_row)
self.right_top_button2 = ttk.Button(self.frame_right_top , text='更新选中科室信息' , width=20 , command=self.updata_row)
self.right_top_button3 = ttk.Button(self.frame_right_top , text='删除选中科室信息' , width=20 , command=self.del_row)
self.right_top_button4 = ttk.Button(self.frame_right_top , text='查询科室信息' , width=20 ,
command=lambda: SelectDept(self.window))
# 位置设置
self.right_top_title.grid(row=1 , column=0 , pady=5)
self.right_top_button1.grid(row=2 , column=0 , padx=20 , pady=3)
self.right_top_button2.grid(row=3 , column=0 , padx=20 , pady=3)
self.right_top_button3.grid(row=4 , column=0 , padx=20 , pady=3)
self.right_top_button4.grid(row=5 , column=0 , padx=20 , pady=3)
# 整体区域定位
self.frame_left_top.grid(row=0 , column=0 , padx=2 , pady=5)
self.frame_right_top.grid(row=0 , column=1 , padx=30 , pady=30)
self.frame_center.grid(row=1 , column=0 , columnspan=2 , padx=4 , pady=5)
self.frame_bottom.grid(row=2 , column=0 , columnspan=2)
self.frame_left_top.grid_propagate(0)
self.frame_right_top.grid_propagate(0)
self.frame_center.grid_propagate(0)
self.frame_bottom.grid_propagate(0)
self.frame_left_top.tkraise() # 开始显示主菜单
self.frame_right_top.tkraise() # 开始显示主菜单
self.frame_center.tkraise() # 开始显示主菜单
self.frame_bottom.tkraise() # 开始显示主菜单
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def back(self):
Gongnengjiemian(self.window) # 显示主窗口 销毁本窗口
def click(self , event):
self.col = self.tree.identify_column(event.x) # 列
self.row = self.tree.identify_row(event.y) # 行
print(self.col) # 列
print(self.row) # 行
self.row_info = self.tree.item(self.row , "values")
self.var_dpname.set(self.row_info[0])
self.var_dpno.set(self.row_info[1])
self.var_dpadr.set(self.row_info[2])
self.var_dptel.set(self.row_info[3])
self.right_top_dpname_entry = Entry(self.frame_left_top , state='disabled' , textvariable=self.var_dpname ,
font=('Verdana' , 15))
print('')
# 点击标题进行排列
def tree_sort_column(self , tv , col , reverse): # Treeview、列名、排列方式
l = [(tv.set(k , col) , k) for k in tv.get_children('')]
l.sort(reverse=reverse) # 排序方式
# 在排序位置重新排列项目
for index , (val , k) in enumerate(l): # 根据排序后索引移动
tv.move(k , '' , index)
tv.heading(col , command=lambda: self.tree_sort_column(tv , col , not reverse)) # 重写标题,使之成为再点倒序的标题
def new_row(self):
print('新建')
print(self.var_dpname.get())
print(self.dpname)
if str(self.var_dpname.get()) in self.dpname:
messagebox.showinfo('警告!' , '该科室已存在!')
else:
if self.var_dpname.get() != '' and self.var_dpno.get() != '' and self.var_dpadr.get() != '' and self.var_dptel.get() != '':
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursors = db.cursor() # 使用cursor()方法获取操作游标
sqll = "INSERT INTO department(dpname, dpno, dpadr, dptel) VALUES('%s', '%s', '%s', '%s') " % (
self.var_dpname.get() , self.var_dpno.get() , self.var_dpadr.get() ,
self.var_dptel.get()) # SQL 插入语句
try:
cursors.execute(sqll) # 执行sql语句
db.commit() # 提交到数据库执行
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
self.dpname.append(self.var_dpname.get())
self.dpno.append(self.var_dpno.get())
self.dpadr.append(self.var_dpadr.get())
self.dptel.append(self.var_dptel.get())
self.tree.insert('' , len(self.dpname) - 1 , values=(
self.dpname[len(self.dpname) - 1] , self.dpno[len(self.dpname) - 1] ,
self.dpadr[len(self.dpname) - 1] , self.dptel[len(self.dpname) - 1]))
self.tree.update()
messagebox.showinfo('提示!' , '插入成功!')
else:
messagebox.showinfo('警告!' , '请填写科室数据')
def updata_row(self):
res = messagebox.askyesnocancel('警告!' , '是否更新所填数据?')
if res:
if self.var_dpname.get() == self.row_info[0]: # 如果所填学号 与 所选学号一致
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "UPDATE department SET dpno = '%s', dpadr = '%s', dptel = '%s' WHERE dpname= '%s'" % (
self.var_dpno.get() , self.var_dpadr.get() , self.var_dptel.get() ,
self.var_dpname.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '更新成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '更新失败,数据库连接失败!')
db.close() # 关闭数据库连接
dpname_index = self.dpname.index(self.row_info[0])
self.dpname[dpname_index] = self.var_dpname.get()
self.dpadr[dpname_index] = self.var_dpadr.get()
self.dptel[dpname_index] = self.var_dptel.get()
self.tree.item(self.tree.selection()[0] , values=(
self.var_dpname.get() , self.var_dpno.get() , self.var_dpadr.get() , self.var_dptel.get()))
else:
messagebox.showinfo('警告!' , '不能修改科室姓名!')
def del_row(self):
res = messagebox.askyesnocancel('警告!' , '是否删除所选数据?')
if res:
print(self.row_info[0]) # 鼠标选中的学号
print(self.tree.selection()[0]) # 行号
print(self.tree.get_children()) # 所有行
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "DELETE FROM department WHERE dpname = '%s'" % (self.row_info[0]) # SQL 删除语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '删除成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '删除失败,数据库连接失败!')
db.close() # 关闭数据库连接
dpname_index = self.dpname.index(self.row_info[0])
print(dpname_index)
del self.dpname[dpname_index]
del self.dpno[dpname_index]
del self.dpadr[dpname_index]
del self.dptel[dpname_index]
print(self.dpno)
self.tree.delete(self.tree.selection()[0]) # 删除所选行
print(self.tree.get_children())
# 医生资料管理操作界面
class AdminManage1:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = Tk() # 初始框的声明
self.window.title('医生资料管理界面')
self.frame_left_top = tk.Frame(width=300 , height=250)
self.frame_right_top = tk.Frame(width=200 , height=200)
self.frame_center = tk.Frame(width=500 , height=800)
self.frame_bottom = tk.Frame(width=700 , height=10)
# 定义下方中心列表区域
self.columns = ("编号" , "医生名" , "职称" , "性别" , "年龄" , "科室")
self.tree = ttk.Treeview(self.frame_center , show="headings" , height=18 , columns=self.columns)
self.vbar = ttk.Scrollbar(self.frame_center , orient=VERTICAL , command=self.tree.yview)
# 定义树形结构与滚动条
self.tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.tree.column("编号" , width=80 , anchor='center') # 表示列,不显示
self.tree.column("医生名" , width=80 , anchor='center')
self.tree.column("职称" , width=100 , anchor='center')
self.tree.column("性别" , width=70 , anchor='center')
self.tree.column("年龄" , width=80 , anchor='center')
self.tree.column("科室" , width=90 , anchor='center')
# 调用方法获取表格内容插入
self.tree.grid(row=0 , column=0 , sticky=NSEW)
self.vbar.grid(row=0 , column=1 , sticky=NS)
self.dno = []
self.dname = []
self.duty = []
self.dsex = []
self.dage = []
self.dpno = []
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "SELECT * FROM vdoctor" # SQL 查询语句
try:
# 执行SQL语句
cursor.execute(sql)
# 获取所有记录列表
results = cursor.fetchall()
for row in results:
self.dno.append(row[0])
self.dname.append(row[1])
self.duty.append(row[2])
self.dsex.append(row[3])
self.dage.append(row[4])
self.dpno.append(row[5])
except:
print("Error: unable to fetch data")
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
print("test***********************")
for i in range(min(len(self.dno) , len(self.dname) , len(self.duty) , len(self.dsex) , len(self.dage) ,
len(self.dpno))): # 写入数据
self.tree.insert('' , i , values=(
self.dno[i] , self.dname[i] , self.duty[i] , self.dsex[i] , self.dage[i] , self.dpno[i]))
for col in self.columns: # 绑定函数,使表头可排序
self.tree.heading(col , text=col , command=lambda _col=col: self.tree_sort_column(self.tree , _col , False))
# 定义顶部区域
# 定义左上方区域
self.top_title = Label(self.frame_left_top , text="医生信息" , bg='lightskyblue' , font=('Verdana' , 20))
self.top_title.grid(row=0 , column=0 , columnspan=2 , sticky=NSEW , padx=50 , pady=10)
self.left_top_frame = tk.Frame(self.frame_left_top)
self.var_dno = StringVar() # 声明医生编号
self.var_dname = StringVar() # 声明医生名字
self.var_duty = StringVar() # 声明职称
self.var_dsex = StringVar() # 声明性别
self.var_dage = StringVar() # 声明年龄
self.var_dpno = StringVar() # 声明科室
# 医生编号
self.right_top_dno_label = Label(self.frame_left_top , text="编号:" , font=('Verdana' , 15))
self.right_top_dno_entry = Entry(self.frame_left_top , textvariable=self.var_dno , font=('Verdana' , 15))
self.right_top_dno_label.grid(row=1 , column=0) # 位置设置
self.right_top_dno_entry.grid(row=1 , column=1)
# 姓名
self.right_top_dname_label = Label(self.frame_left_top , text="姓名:" , font=('Verdana' , 15))
self.right_top_dname_entry = Entry(self.frame_left_top , textvariable=self.var_dname , font=('Verdana' , 15))
self.right_top_dname_label.grid(row=2 , column=0) # 位置设置
self.right_top_dname_entry.grid(row=2 , column=1)
# 职称
self.right_top_duty_label = Label(self.frame_left_top , text="职称:" , font=('Verdana' , 15))
self.right_top_duty_entry = Entry(self.frame_left_top , textvariable=self.var_duty , font=('Verdana' , 15))
self.right_top_duty_label.grid(row=3 , column=0) # 位置设置
self.right_top_duty_entry.grid(row=3 , column=1)
# 性别
self.right_top_dsex_label = Label(self.frame_left_top , text="性别:" , font=('Verdana' , 15))
self.right_top_dsex_entry = Entry(self.frame_left_top , textvariable=self.var_dsex , font=('Verdana' , 15))
self.right_top_dsex_label.grid(row=4 , column=0) # 位置设置
self.right_top_dsex_entry.grid(row=4 , column=1)
# 年龄
self.right_top_dage_label = Label(self.frame_left_top , text="年龄:" , font=('Verdana' , 15))
self.right_top_dage_entry = Entry(self.frame_left_top , textvariable=self.var_dage , font=('Verdana' , 15))
self.right_top_dage_label.grid(row=5 , column=0) # 位置设置
self.right_top_dage_entry.grid(row=5 , column=1)
# 科室
self.right_top_dpno_label = Label(self.frame_left_top , text="科室:" , font=('Verdana' , 15))
self.right_top_dpno_entry = Entry(self.frame_left_top , textvariable=self.var_dpno , font=('Verdana' , 15))
self.right_top_dpno_label.grid(row=6 , column=0) # 位置设置
self.right_top_dpno_entry.grid(row=6 , column=1)
# 操作
self.right_top_title = Label(self.frame_right_top , text="操作:" , font=('Verdana' , 20))
self.tree.bind('' , self.click) # 左键获取位置
self.right_top_button1 = ttk.Button(self.frame_right_top , text='新建医生信息' , width=20 , command=self.new_row)
self.right_top_button2 = ttk.Button(self.frame_right_top , text='更新选中医生信息' , width=20 , command=self.updata_row)
self.right_top_button3 = ttk.Button(self.frame_right_top , text='删除选中医生信息' , width=20 , command=self.del_row)
self.right_top_button4 = ttk.Button(self.frame_right_top , text='查询医生信息' , width=20 ,
command=lambda: SelectDocter(self.window))
# 位置设置
self.right_top_title.grid(row=1 , column=0 , pady=5)
self.right_top_button1.grid(row=2 , column=0 , padx=20 , pady=5)
self.right_top_button2.grid(row=3 , column=0 , padx=20 , pady=5)
self.right_top_button3.grid(row=4 , column=0 , padx=20 , pady=5)
self.right_top_button4.grid(row=5 , column=0 , padx=20 , pady=5)
# 整体区域定位
self.frame_left_top.grid(row=0 , column=0 , padx=2 , pady=5)
self.frame_right_top.grid(row=0 , column=1 , padx=30 , pady=30)
self.frame_center.grid(row=1 , column=0 , columnspan=2 , padx=4 , pady=5)
self.frame_bottom.grid(row=2 , column=0 , columnspan=2)
self.frame_left_top.grid_propagate(0)
self.frame_right_top.grid_propagate(0)
self.frame_center.grid_propagate(0)
self.frame_bottom.grid_propagate(0)
self.frame_left_top.tkraise() # 开始显示主菜单
self.frame_right_top.tkraise() # 开始显示主菜单
self.frame_center.tkraise() # 开始显示主菜单
self.frame_bottom.tkraise() # 开始显示主菜单
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def back(self):
Gongnengjiemian(self.window) # 显示主窗口 销毁本窗口
def click(self , event):
self.col = self.tree.identify_column(event.x) # 列
self.row = self.tree.identify_row(event.y) # 行
print(self.col)
print(self.row)
self.row_info = self.tree.item(self.row , "values")
self.var_dno.set(self.row_info[0])
self.var_dname.set(self.row_info[1])
self.var_duty.set(self.row_info[2])
self.var_dsex.set(self.row_info[3])
self.var_dage.set(self.row_info[4])
self.var_dpno.set(self.row_info[5])
self.right_top_dno_entry = Entry(self.frame_left_top , state='disabled' , textvariable=self.var_dno ,
font=('Verdana' , 15))
print('')
def tree_sort_column(self , tv , col , reverse): # Treeview、列名、排列方式
l = [(tv.set(k , col) , k) for k in tv.get_children('')]
l.sort(reverse=reverse) # 排序方式
# rearrange items in sorted positions
for index , (val , k) in enumerate(l): # 根据排序后索引移动
tv.move(k , '' , index)
tv.heading(col , command=lambda: self.tree_sort_column(tv , col , not reverse)) # 重写标题,使之成为再点倒序的标题
def new_row(self):
print('123')
print(self.var_dno.get())
print(self.dno)
if str(self.var_dno.get()) in self.dno:
messagebox.showinfo('警告!' , '该医生已存在!')
else:
if self.var_dno.get() != '' and self.var_dname.get() != '' and self.var_duty.get() != '' and self.var_dsex.get() != '' and self.var_dage.get() != '' and self.var_dpno.get() != '':
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "INSERT INTO doctor(dno, dname, duty, dsex,dage,dpno) VALUES('%s', '%s', '%s', '%s','%s','%s') " % (
self.var_dno.get() , self.var_dname.get() , self.var_duty.get() , self.var_dsex.get() ,
self.var_dage.get() , self.var_dpno.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
self.dno.append(self.var_dno.get())
self.dname.append(self.var_dname.get())
self.duty.append(self.var_duty.get())
self.dsex.append(self.var_dsex.get())
self.dage.append(self.var_dage.get())
self.dpno.append(self.var_dpno.get())
self.tree.insert('' , len(self.dno) - 1 , values=(
self.dno[len(self.dno) - 1] , self.dname[len(self.dno) - 1] , self.duty[len(self.dno) - 1] ,
self.dsex[len(self.dno) - 1] , self.dage[len(self.dno) - 1] , self.dpno[len(self.dno) - 1]))
self.tree.update()
messagebox.showinfo('提示!' , '插入成功!')
else:
messagebox.showinfo('警告!' , '请填写医生数据')
def updata_row(self):
res = messagebox.askyesnocancel('警告!' , '是否更新所填数据?')
if res == True:
if self.var_dno.get() == self.row_info[0]: # 如果所填学号 与 所选学号一致
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "UPDATE doctor SET dname = '%s', duty = '%s',dsex='%s',dage='%s',dpno='%s' WHERE dno= '%s'" % (
self.var_dname.get() , self.var_duty.get() , self.var_dsex.get() , self.var_dage.get() ,
self.var_dpno.get() , self.var_dno.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '更新成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '更新失败,数据库连接失败!')
db.close() # 关闭数据库连接
dno_index = self.dno.index(self.row_info[0])
self.dname[dno_index] = self.var_dname.get()
self.duty[dno_index] = self.var_duty.get()
self.dsex[dno_index] = self.var_dsex.get()
self.dage[dno_index] = self.var_dage.get()
self.dpno[dno_index] = self.var_dpno.get()
self.tree.item(self.tree.selection()[0] , values=(
self.var_dno.get() , self.var_dname.get() , self.var_duty.get() , self.var_dsex.get() ,
self.var_dage.get() , self.var_dpno.get()))
else:
messagebox.showinfo('警告!' , '不能修改医生编号!')
def del_row(self):
res = messagebox.askyesnocancel('警告!' , '是否删除所选数据?')
if res:
print(self.row_info[0]) # 鼠标选中的学号
print(self.tree.selection()[0]) # 行号
print(self.tree.get_children()) # 所有行
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "DELETE FROM doctor WHERE dno = '%s'" % (self.row_info[0]) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '删除成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '删除失败,数据库连接失败!')
db.close() # 关闭数据库连接
dno_index = self.dno.index(self.row_info[0])
print(dno_index)
del self.dno[dno_index]
del self.dname[dno_index]
del self.duty[dno_index]
del self.dsex[dno_index]
del self.dage[dno_index]
del self.dpno[dno_index]
print(self.dno)
self.tree.delete(self.tree.selection()[0]) # 删除所选行
print(self.tree.get_children())
# 护士资料管理操作界面
class AdminManage2:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = Tk() # 初始框的声明
self.window.title('护士资料管理界面')
self.frame_left_top = tk.Frame(width=300 , height=200)
self.frame_right_top = tk.Frame(width=200 , height=200)
self.frame_center = tk.Frame(width=500 , height=400)
self.frame_bottom = tk.Frame(width=650 , height=50)
# 定义下方中心列表区域
self.columns = ("护士编号" , "护士名" , "性别" , "年龄")
self.tree = ttk.Treeview(self.frame_center , show="headings" , height=18 , columns=self.columns)
self.vbar = ttk.Scrollbar(self.frame_center , orient=VERTICAL , command=self.tree.yview)
# 定义树形结构与滚动条
self.tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.tree.column("护士编号" , width=150 , anchor='center') # 表示列,不显示
self.tree.column("护士名" , width=150 , anchor='center')
self.tree.column("性别" , width=100 , anchor='center')
self.tree.column("年龄" , width=100 , anchor='center')
# 调用方法获取表格内容插入
self.tree.grid(row=0 , column=0 , sticky=NSEW)
self.vbar.grid(row=0 , column=1 , sticky=NS)
self.nno = []
self.nname = []
self.nsex = []
self.nage = []
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "SELECT * FROM vnurse" # SQL 查询语句
try:
# 执行SQL语句
cursor.execute(sql)
# 获取所有记录列表
results = cursor.fetchall()
for row in results:
self.nno.append(row[0])
self.nname.append(row[1])
self.nsex.append(row[2])
self.nage.append(row[3])
except:
print("Error: unable to fetch data")
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
print("test***********************")
for i in range(min(len(self.nno) , len(self.nname) , len(self.nsex) , len(self.nage))): # 写入数据
self.tree.insert('' , i , values=(self.nno[i] , self.nname[i] , self.nsex[i] , self.nage[i]))
for col in self.columns: # 绑定函数,使表头可排序
self.tree.heading(col , text=col , command=lambda _col=col: self.tree_sort_column(self.tree , _col , False))
# 定义顶部区域
# 定义左上方区域
self.top_title = Label(self.frame_left_top , text="护士信息" , bg='deepskyblue' , font=('Verdana' , 20))
self.top_title.grid(row=0 , column=0 , columnspan=2 , sticky=NSEW , padx=50 , pady=10)
self.left_top_frame = tk.Frame(self.frame_left_top)
self.var_nno = StringVar() # 声明编号名
self.var_nname = StringVar() # 声明护士名
self.var_nsex = StringVar() # 声明性别
self.var_nage = StringVar() # 声明年龄
# 编号
self.right_top_nno_label = Label(self.frame_left_top , text="护士编号:" , font=('Verdana' , 15))
self.right_top_nno_entry = Entry(self.frame_left_top , textvariable=self.var_nno , font=('Verdana' , 15))
self.right_top_nno_label.grid(row=1 , column=0) # 位置设置
self.right_top_nno_entry.grid(row=1 , column=1)
# 护士名
self.right_top_nname_label = Label(self.frame_left_top , text="护士名:" , font=('Verdana' , 15))
self.right_top_nname_entry = Entry(self.frame_left_top , textvariable=self.var_nname , font=('Verdana' , 15))
self.right_top_nname_label.grid(row=2 , column=0) # 位置设置
self.right_top_nname_entry.grid(row=2 , column=1)
# 性别
self.right_top_nsex_label = Label(self.frame_left_top , text="性别:" , font=('Verdana' , 15))
self.right_top_nsex_entry = Entry(self.frame_left_top , textvariable=self.var_nsex , font=('Verdana' , 15))
self.right_top_nsex_label.grid(row=3 , column=0) # 位置设置
self.right_top_nsex_entry.grid(row=3 , column=1)
# 年龄
self.right_top_nage_label = Label(self.frame_left_top , text="年龄:" , font=('Verdana' , 15))
self.right_top_nage_entry = Entry(self.frame_left_top , textvariable=self.var_nage , font=('Verdana' , 15))
self.right_top_nage_label.grid(row=4 , column=0) # 位置设置
self.right_top_nage_entry.grid(row=4 , column=1)
# 定义右上方区域
self.right_top_title = Label(self.frame_right_top , text="操作:" , font=('Verdana' , 20))
self.tree.bind('' , self.click) # 左键获取位置
self.right_top_button1 = ttk.Button(self.frame_right_top , text='新建护士信息' , width=20 , command=self.new_row)
self.right_top_button2 = ttk.Button(self.frame_right_top , text='更新选中护士信息' , width=20 , command=self.updata_row)
self.right_top_button3 = ttk.Button(self.frame_right_top , text='删除选中护士信息' , width=20 , command=self.del_row)
self.right_top_button4 = ttk.Button(self.frame_right_top , text='查询护士信息' , width=20 ,
command=lambda: SelectNurse(self.window))
# 位置设置
self.right_top_title.grid(row=1 , column=0 , pady=0)
self.right_top_button1.grid(row=2 , column=0 , padx=20 , pady=5)
self.right_top_button2.grid(row=3 , column=0 , padx=20 , pady=5)
self.right_top_button3.grid(row=4 , column=0 , padx=20 , pady=5)
self.right_top_button4.grid(row=5 , column=0 , padx=20 , pady=5)
# 整体区域定位
self.frame_left_top.grid(row=0 , column=0 , padx=2 , pady=5)
self.frame_right_top.grid(row=0 , column=1 , padx=30 , pady=30)
self.frame_center.grid(row=1 , column=0 , columnspan=2 , padx=4 , pady=5)
self.frame_bottom.grid(row=2 , column=0 , columnspan=2)
self.frame_left_top.grid_propagate(0)
self.frame_right_top.grid_propagate(0)
self.frame_center.grid_propagate(0)
self.frame_bottom.grid_propagate(0)
self.frame_left_top.tkraise() # 开始显示主菜单
self.frame_right_top.tkraise() # 开始显示主菜单
self.frame_center.tkraise() # 开始显示主菜单
self.frame_bottom.tkraise() # 开始显示主菜单
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def back(self):
Gongnengjiemian(self.window) # 显示主窗口 销毁本窗口
def click(self , event):
self.col = self.tree.identify_column(event.x) # 列
self.row = self.tree.identify_row(event.y) # 行
print(self.col)
print(self.row)
self.row_info = self.tree.item(self.row , "values")
self.var_nno.set(self.row_info[0])
self.var_nname.set(self.row_info[1])
self.var_nsex.set(self.row_info[2])
self.var_nage.set(self.row_info[3])
self.right_top_nno_entry = Entry(self.frame_left_top , state='disabled' , textvariable=self.var_nno ,
font=('Verdana' , 15))
print('')
def tree_sort_column(self , tv , col , reverse): # Treeview、列名、排列方式
l = [(tv.set(k , col) , k) for k in tv.get_children('')]
l.sort(reverse=reverse) # 排序方式
# rearrange items in sorted positions
for index , (val , k) in enumerate(l): # 根据排序后索引移动
tv.move(k , '' , index)
tv.heading(col , command=lambda: self.tree_sort_column(tv , col , not reverse)) # 重写标题,使之成为再点倒序的标题
def new_row(self):
print('123')
print(self.var_nno.get())
print(self.nno)
if str(self.var_nno.get()) in self.nno:
messagebox.showinfo('警告!' , '该护士已存在!')
else:
if self.var_nno.get() != '' and self.var_nname.get() != '' and self.var_nsex.get() != '' and self.var_nage.get() != '':
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "INSERT INTO nurse(nno, nname, nsex, nage) VALUES('%s', '%s', '%s', '%s') " % (
self.var_nno.get() , self.var_nname.get() , self.var_nsex.get() , self.var_nage.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
self.nno.append(self.var_nno.get())
self.nname.append(self.var_nname.get())
self.nsex.append(self.var_nsex.get())
self.nage.append(self.var_nage.get())
self.tree.insert('' , len(self.nno) - 1 , values=(
self.nno[len(self.nno) - 1] , self.nname[len(self.nno) - 1] , self.nsex[len(self.nno) - 1] ,
self.nage[len(self.nno) - 1]))
self.tree.update()
messagebox.showinfo('提示!' , '插入成功!')
else:
messagebox.showinfo('警告!' , '请填写护士数据')
def updata_row(self):
res = messagebox.askyesnocancel('警告!' , '是否更新所填数据?')
if res == True:
if self.var_nno.get() == self.row_info[0]: # 如果所填学号 与 所选学号一致
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "UPDATE nurse SET nname = '%s', nsex = '%s', nage = '%s' WHERE nno= '%s'" % (
self.var_nname.get() , self.var_nsex.get() , self.var_nage.get() , self.var_nno.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '更新成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '更新失败,数据库连接失败!')
db.close() # 关闭数据库连接
nno_index = self.nno.index(self.row_info[0])
self.nname[nno_index] = self.var_nname.get()
self.nsex[nno_index] = self.var_nsex.get()
self.nage[nno_index] = self.var_nage.get()
self.tree.item(self.tree.selection()[0] , values=(
self.var_nno.get() , self.var_nname.get() , self.var_nsex.get() , self.var_nage.get()))
else:
messagebox.showinfo('警告!' , '不能修改护士编号!')
def del_row(self):
res = messagebox.askyesnocancel('警告!' , '是否删除所选数据?')
if res == True:
print(self.row_info[0]) # 鼠标选中的学号
print(self.tree.selection()[0]) # 行号
print(self.tree.get_children()) # 所有行
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "DELETE FROM nurse WHERE nno = '%s'" % (self.row_info[0]) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '删除成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '删除失败,数据库连接失败!')
db.close() # 关闭数据库连接
nno_index = self.nno.index(self.row_info[0])
print(nno_index)
del self.nno[nno_index]
del self.nname[nno_index]
del self.nsex[nno_index]
del self.nage[nno_index]
print(self.nno)
self.tree.delete(self.tree.selection()[0]) # 删除所选行
print(self.tree.get_children())
# 患者资料管理操作界面
class AdminManage3:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = Tk() # 初始框的声明
self.window.title('患者资料管理界面')
self.window.geometry('800x1000')
self.frame_left_top = tk.Frame(width=300 , height=350)
self.frame_right_top = tk.Frame(width=300 , height=200)
self.frame_center = tk.Frame(width=800 , height=800)
self.frame_bottom = tk.Frame(width=900 , height=30)
# 定义下方中心列表区域
self.columns = ("编号" , "患者名" , "性别" , "年龄" , "医生" , "病房" , "病症" , "治疗时间" , "康复时间")
self.tree = ttk.Treeview(self.frame_center , show="headings" , height=15 , columns=self.columns)
self.vbar = ttk.Scrollbar(self.frame_center , orient=VERTICAL , command=self.tree.yview)
# 定义树形结构与滚动条
self.tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.tree.column("编号" , width=60 , anchor='center') # 表示列,不显示
self.tree.column("患者名" , width=80 , anchor='center')
self.tree.column("性别" , width=60 , anchor='center')
self.tree.column("年龄" , width=50 , anchor='center')
self.tree.column("医生" , width=70 , anchor='center')
self.tree.column("病房" , width=80 , anchor='center')
self.tree.column("病症" , width=130 , anchor='center')
self.tree.column("治疗时间" , width=80 , anchor='center')
self.tree.column("康复时间" , width=80 , anchor='center')
# 调用方法获取表格内容插入
self.tree.grid(row=0 , column=0 , sticky=NSEW)
self.vbar.grid(row=0 , column=1 , sticky=NS)
self.pno = []
self.pname = []
self.psex = []
self.page = []
self.dno = []
self.rno = []
self.illness = []
self.startdate = []
self.predictenddate = []
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "SELECT * FROM vpatient" # SQL 查询语句
try:
# 执行SQL语句
cursor.execute(sql)
# 获取所有记录列表
results = cursor.fetchall()
for row in results:
self.pno.append(row[0])
self.pname.append(row[1])
self.psex.append(row[2])
self.page.append(row[3])
self.dno.append(row[4])
self.rno.append(row[5])
self.illness.append(row[6])
self.startdate.append(row[7])
self.predictenddate.append(row[8])
except:
print("Error: unable to fetch data")
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
print("test***********************")
for i in range(
min(len(self.pno) , len(self.pname) , len(self.psex) , len(self.page) , len(self.dno) , len(self.rno) ,
len(self.illness) , len(self.startdate) , len(self.predictenddate))): # 写入数据
self.tree.insert('' , i , values=(
self.pno[i] , self.pname[i] , self.psex[i] , self.page[i] , self.dno[i] , self.rno[i] ,
self.illness[i] ,
self.startdate[i] , self.predictenddate[i]))
for col in self.columns: # 绑定函数,使表头可排序
self.tree.heading(col , text=col , command=lambda _col=col: self.tree_sort_column(self.tree , _col , False))
# 定义顶部区域
# 定义左上方区域
self.top_title = Label(self.frame_left_top , text="患者信息" , bg='dodgerblue' , font=('Verdana' , 20))
self.top_title.grid(row=0 , column=0 , columnspan=2 , sticky=NSEW , padx=50 , pady=10)
self.left_top_frame = tk.Frame(self.frame_left_top)
self.var_pno = StringVar() # 声明编号
self.var_pname = StringVar() # 声明名字
self.var_psex = StringVar() # 声明性别
self.var_page = StringVar() # 声明年龄
self.var_dno = StringVar() # 声明医生
self.var_rno = StringVar() # 声明病房
self.var_illness = StringVar()
self.var_startdate = StringVar()
self.var_predictenddate = StringVar()
# 护士编号
self.right_top_pno_label = Label(self.frame_left_top , text="编号:" , font=('Verdana' , 15))
self.right_top_pno_entry = Entry(self.frame_left_top , textvariable=self.var_pno , font=('Verdana' , 15))
self.right_top_pno_label.grid(row=1 , column=0) # 位置设置
self.right_top_pno_entry.grid(row=1 , column=1)
# 护士姓名
self.right_top_pname_label = Label(self.frame_left_top , text="姓名:" , font=('Verdana' , 15))
self.right_top_pname_entry = Entry(self.frame_left_top , textvariable=self.var_pname , font=('Verdana' , 15))
self.right_top_pname_label.grid(row=2 , column=0) # 位置设置
self.right_top_pname_entry.grid(row=2 , column=1)
# 性别
self.right_top_psex_label = Label(self.frame_left_top , text="性别:" , font=('Verdana' , 15))
self.right_top_psex_entry = Entry(self.frame_left_top , textvariable=self.var_psex , font=('Verdana' , 15))
self.right_top_psex_label.grid(row=3 , column=0) # 位置设置
self.right_top_psex_entry.grid(row=3 , column=1)
# 年龄
self.right_top_page_label = Label(self.frame_left_top , text="年龄:" , font=('Verdana' , 15))
self.right_top_page_entry = Entry(self.frame_left_top , textvariable=self.var_page , font=('Verdana' , 15))
self.right_top_page_label.grid(row=4 , column=0) # 位置设置
self.right_top_page_entry.grid(row=4 , column=1)
# 医生
self.right_top_dno_label = Label(self.frame_left_top , text="医生编号:" , font=('Verdana' , 15))
self.right_top_dno_entry = Entry(self.frame_left_top , textvariable=self.var_dno , font=('Verdana' , 15))
self.right_top_dno_label.grid(row=5 , column=0) # 位置设置
self.right_top_dno_entry.grid(row=5 , column=1)
# 病房
self.right_top_rno_label = Label(self.frame_left_top , text="病房:" , font=('Verdana' , 15))
self.right_top_rno_entry = Entry(self.frame_left_top , textvariable=self.var_rno , font=('Verdana' , 15))
self.right_top_rno_label.grid(row=6 , column=0) # 位置设置
self.right_top_rno_entry.grid(row=6 , column=1)
# 病症
self.right_top_illness_label = Label(self.frame_left_top , text="病症:" , font=('Verdana' , 15))
self.right_top_illness_entry = Entry(self.frame_left_top , textvariable=self.var_illness ,
font=('Verdana' , 15))
self.right_top_illness_label.grid(row=7 , column=0) # 位置设置
self.right_top_illness_entry.grid(row=7 , column=1)
# 治疗时间
self.right_top_startdate_label = Label(self.frame_left_top , text="治疗时间:" , font=('Verdana' , 15))
self.right_top_startdate_entry = Entry(self.frame_left_top , textvariable=self.var_startdate ,
font=('Verdana' , 15))
self.right_top_startdate_label.grid(row=8 , column=0) # 位置设置
self.right_top_startdate_entry.grid(row=8 , column=1)
# 康复时间
self.right_top_predictenddate_label = Label(self.frame_left_top , text="康复时间:" , font=('Verdana' , 15))
self.right_top_predictenddate_entry = Entry(self.frame_left_top , textvariable=self.var_predictenddate ,
font=('Verdana' , 15))
self.right_top_predictenddate_label.grid(row=9 , column=0) # 位置设置
self.right_top_predictenddate_entry.grid(row=9 , column=1)
# 操作
self.right_top_title = Label(self.frame_right_top , text="操作:" , font=('Verdana' , 20))
self.tree.bind('' , self.click) # 左键获取位置
self.right_top_button1 = ttk.Button(self.frame_right_top , text='新建患者信息' , width=20 , command=self.new_row)
self.right_top_button2 = ttk.Button(self.frame_right_top , text='更新患者信息' , width=20 , command=self.updata_row)
self.right_top_button3 = ttk.Button(self.frame_right_top , text='删除患者信息' , width=20 , command=self.del_row)
self.right_top_button4 = ttk.Button(self.frame_right_top , text='查询患者信息' , width=20 ,
command=lambda: SelectPatient(self.window))
# 位置设置
self.right_top_title.grid(row=1 , column=0 , pady=5)
self.right_top_button1.grid(row=2 , column=0 , padx=20 , pady=5)
self.right_top_button2.grid(row=3 , column=0 , padx=20 , pady=5)
self.right_top_button3.grid(row=4 , column=0 , padx=20 , pady=5)
self.right_top_button4.grid(row=5 , column=0 , padx=20 , pady=5)
# 整体区域定位
self.frame_left_top.grid(row=0 , column=0 , padx=2 , pady=5)
self.frame_right_top.grid(row=0 , column=1 , padx=30 , pady=30)
self.frame_center.grid(row=1 , column=0 , columnspan=2 , padx=4 , pady=5)
self.frame_bottom.grid(row=2 , column=0 , columnspan=2)
self.frame_left_top.grid_propagate(0)
self.frame_right_top.grid_propagate(0)
self.frame_center.grid_propagate(0)
self.frame_bottom.grid_propagate(0)
self.frame_left_top.tkraise() # 开始显示主菜单
self.frame_right_top.tkraise() # 开始显示主菜单
self.frame_center.tkraise() # 开始显示主菜单
self.frame_bottom.tkraise() # 开始显示主菜单
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def back(self):
Gongnengjiemian(self.window) # 显示主窗口 销毁本窗口
def click(self , event):
self.col = self.tree.identify_column(event.x) # 列
self.row = self.tree.identify_row(event.y) # 行
print(self.col)
print(self.row)
self.row_info = self.tree.item(self.row , "values")
self.var_pno.set(self.row_info[0])
self.var_pname.set(self.row_info[1])
self.var_psex.set(self.row_info[2])
self.var_page.set(self.row_info[3])
self.var_dno.set(self.row_info[4])
self.var_rno.set(self.row_info[5])
self.var_illness.set(self.row_info[6])
self.var_startdate.set(self.row_info[7])
self.var_predictenddate.set(self.row_info[8])
self.right_top_pno_entry = Entry(self.frame_left_top , state='disabled' , textvariable=self.var_pno ,
font=('Verdana' , 15))
print('')
def tree_sort_column(self , tv , col , reverse): # Treeview、列名、排列方式
l = [(tv.set(k , col) , k) for k in tv.get_children('')]
l.sort(reverse=reverse) # 排序方式
# rearrange items in sorted positions
for index , (val , k) in enumerate(l): # 根据排序后索引移动
tv.move(k , '' , index)
tv.heading(col , command=lambda: self.tree_sort_column(tv , col , not reverse)) # 重写标题,使之成为再点倒序的标题
def new_row(self):
print('123')
print(self.var_pno.get())
print(self.pno)
if str(self.var_pno.get()) in self.pno:
messagebox.showinfo('警告!' , '该患者已存在!')
else:
if self.var_pno.get() != '' and self.var_pname.get() != '' and self.var_psex.get() != '' and self.var_page.get() != '' and self.var_dno.get() != '' and self.var_rno.get() != '' and self.var_illness.get() != '' and self.var_startdate.get() != '' and self.var_predictenddate.get() != '':
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "INSERT INTO patient(pno, pname, psex, page,dno,rno,illness,startdate,predictenddate) VALUES(" \
"'%s', '%s', '%s', '%s','%s','%s', '%s','%s','%s') " % (
self.var_pno.get() , self.var_pname.get() , self.var_psex.get() , self.var_page.get() ,
self.var_dno.get() , self.var_rno.get() , self.var_illness.get() , self.var_startdate.get() ,
self.var_predictenddate.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
self.pno.append(self.var_pno.get())
self.pname.append(self.var_pname.get())
self.psex.append(self.var_psex.get())
self.page.append(self.var_page.get())
self.dno.append(self.var_dno.get())
self.rno.append(self.var_rno.get())
self.illness.append(self.var_illness.get())
self.startdate.append(self.var_startdate.get())
self.predictenddate.append(self.var_predictenddate.get())
self.tree.insert('' , len(self.pno) - 1 , values=(
self.pno[len(self.pno) - 1] , self.pname[len(self.pno) - 1] , self.psex[len(self.pno) - 1] ,
self.page[len(self.pno) - 1] , self.dno[len(self.pno) - 1] , self.rno[len(self.pno) - 1] ,
self.illness[len(self.pno) - 1] , self.startdate[len(self.pno) - 1] ,
self.predictenddate[len(self.pno) - 1]))
self.tree.update()
messagebox.showinfo('提示!' , '插入成功!')
else:
messagebox.showinfo('警告!' , '请填写患者数据')
def updata_row(self):
res = messagebox.askyesnocancel('警告!' , '是否更新所填数据?')
if res == True:
if self.var_pno.get() == self.row_info[0]: # 如果所填学号 与 所选学号一致
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "UPDATE patient SET pname = '%s', psex = '%s',page='%s',dno='%s',rno='%s',illness='%s'," \
"startdate='%s',predictenddate='%s' WHERE pno= '%s'" % (
self.var_pname.get() , self.var_psex.get() , self.var_page.get() , self.var_dno.get() ,
self.var_rno.get() , self.var_illness.get() , self.var_startdate.get() ,
self.var_predictenddate.get() ,
self.var_pno.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '更新成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '更新失败,数据库连接失败!')
db.close() # 关闭数据库连接
pno_index = self.pno.index(self.row_info[0])
self.pname[pno_index] = self.var_pname.get()
self.psex[pno_index] = self.var_psex.get()
self.page[pno_index] = self.var_page.get()
self.dno[pno_index] = self.var_dno.get()
self.rno[pno_index] = self.var_rno.get()
self.illness[pno_index] = self.var_illness.get()
self.startdate[pno_index] = self.var_startdate.get()
self.predictenddate[pno_index] = self.var_predictenddate.get()
self.tree.item(self.tree.selection()[0] , values=(
self.var_pno.get() , self.var_pname.get() , self.var_psex.get() , self.var_page.get() ,
self.var_dno.get() , self.var_rno.get() , self.var_illness.get() , self.var_startdate.get() ,
self.var_predictenddate.get()))
else:
messagebox.showinfo('警告!' , '不能修改患者编号!')
def del_row(self):
res = messagebox.askyesnocancel('警告!' , '是否删除所选数据?')
if res:
print(self.row_info[0]) # 鼠标选中的学号
print(self.tree.selection()[0]) # 行号
print(self.tree.get_children()) # 所有行
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "DELETE FROM patient WHERE pno= '%s'" % (self.row_info[0]) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '删除成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '删除失败,数据库连接失败!')
db.close() # 关闭数据库连接
pno_index = self.pno.index(self.row_info[0])
print(pno_index)
del self.pno[pno_index]
del self.pname[pno_index]
del self.psex[pno_index]
del self.page[pno_index]
del self.dno[pno_index]
del self.rno[pno_index]
del self.illness[pno_index]
del self.startdate[pno_index]
del self.predictenddate[pno_index]
print(self.pno)
self.tree.delete(self.tree.selection()[0]) # 删除所选行
print(self.tree.get_children())
# 药品资料管理操作界面
class AdminManage4:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = Tk() # 初始框的声明
self.window.title('药品资料管理界面')
self.window.geometry('550x700')
self.frame_left_top = tk.Frame(width=300 , height=220)
self.frame_right_top = tk.Frame(width=300 , height=200)
self.frame_center = tk.Frame(width=600 , height=800)
self.frame_bottom = tk.Frame(width=600 , height=30)
# 定义下方中心列表区域
self.columns = ("编号" , "药品名" , "产名" , "库存" , "价格")
self.tree = ttk.Treeview(self.frame_center , show="headings" , height=15 , columns=self.columns)
self.vbar = ttk.Scrollbar(self.frame_center , orient=VERTICAL , command=self.tree.yview)
# 定义树形结构与滚动条
self.tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.tree.column("编号" , width=60 , anchor='center') # 表示列,不显示
self.tree.column("药品名" , width=200 , anchor='center')
self.tree.column("产名" , width=90 , anchor='center')
self.tree.column("库存" , width=60 , anchor='center')
self.tree.column("价格" , width=60 , anchor='center')
# 调用方法获取表格内容插入
self.tree.grid(row=0 , column=0 , sticky=NSEW)
self.vbar.grid(row=0 , column=1 , sticky=NS)
self.dgno = []
self.dgname = []
self.dgpro = []
self.dgnum = []
self.dgprice = []
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "SELECT * FROM vdrug" # SQL 查询语句
try:
# 执行SQL语句
cursor.execute(sql)
# 获取所有记录列表
results = cursor.fetchall()
for row in results:
self.dgno.append(row[0])
self.dgname.append(row[1])
self.dgpro.append(row[2])
self.dgnum.append(row[3])
self.dgprice.append(row[4])
except:
print("Error: unable to fetch data")
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
print("test***********************")
for i in range(
min(len(self.dgno) , len(self.dgname) , len(self.dgpro) , len(self.dgnum) , len(self.dgprice))): # 写入数据
self.tree.insert('' , i ,
values=(self.dgno[i] , self.dgname[i] , self.dgpro[i] , self.dgnum[i] , self.dgprice[i]))
for col in self.columns: # 绑定函数,使表头可排序
self.tree.heading(col , text=col , command=lambda _col=col: self.tree_sort_column(self.tree , _col , False))
# 定义顶部区域
# 定义左上方区域
self.top_title = Label(self.frame_left_top , text="药品信息" , bg='steelblue' , font=('Verdana' , 20))
self.top_title.grid(row=0 , column=0 , columnspan=2 , sticky=NSEW , padx=50 , pady=10)
self.left_top_frame = tk.Frame(self.frame_left_top)
self.var_dgno = StringVar() # 声明编号
self.var_dgname = StringVar() # 声明药品名
self.var_dgpro = StringVar() # 声明厂家
self.var_dgnum = StringVar() # 声明库存
self.var_dgprice = StringVar() # 声明价格
# 药品编号
self.right_top_dgno_label = Label(self.frame_left_top , text="编号:" , font=('Verdana' , 15))
self.right_top_dgno_entry = Entry(self.frame_left_top , textvariable=self.var_dgno , font=('Verdana' , 15))
self.right_top_dgno_label.grid(row=1 , column=0) # 位置设置
self.right_top_dgno_entry.grid(row=1 , column=1)
# 药品名
self.right_top_dgname_label = Label(self.frame_left_top , text="药品名:" , font=('Verdana' , 15))
self.right_top_dgname_entry = Entry(self.frame_left_top , textvariable=self.var_dgname , font=('Verdana' , 15))
self.right_top_dgname_label.grid(row=2 , column=0) # 位置设置
self.right_top_dgname_entry.grid(row=2 , column=1)
# 厂家
self.right_top_dgpro_label = Label(self.frame_left_top , text="厂家:" , font=('Verdana' , 15))
self.right_top_dgpro_entry = Entry(self.frame_left_top , textvariable=self.var_dgpro , font=('Verdana' , 15))
self.right_top_dgpro_label.grid(row=3 , column=0) # 位置设置
self.right_top_dgpro_entry.grid(row=3 , column=1)
# 库存
self.right_top_dgnum_label = Label(self.frame_left_top , text="库存:" , font=('Verdana' , 15))
self.right_top_dgnum_entry = Entry(self.frame_left_top , textvariable=self.var_dgnum , font=('Verdana' , 15))
self.right_top_dgnum_label.grid(row=4 , column=0) # 位置设置
self.right_top_dgnum_entry.grid(row=4 , column=1)
# 价钱
self.right_top_dgprice_label = Label(self.frame_left_top , text="价格:" , font=('Verdana' , 15))
self.right_top_dgprice_entry = Entry(self.frame_left_top , textvariable=self.var_dgprice ,
font=('Verdana' , 15))
self.right_top_dgprice_label.grid(row=5 , column=0) # 位置设置
self.right_top_dgprice_entry.grid(row=5 , column=1)
# 操作
self.right_top_title = Label(self.frame_right_top , text="操作" , font=('Verdana' , 20))
self.tree.bind('' , self.click) # 左键获取位置
self.right_top_button1 = ttk.Button(self.frame_right_top , text='新建药品信息' , width=20 , command=self.new_row)
self.right_top_button2 = ttk.Button(self.frame_right_top , text='更新药品信息' , width=20 , command=self.updata_row)
self.right_top_button3 = ttk.Button(self.frame_right_top , text='删除药品信息' , width=20 , command=self.del_row)
self.right_top_button4 = ttk.Button(self.frame_right_top , text='查询药品信息' , width=20 ,
command=lambda: SelectDrug(self.window))
# 位置设置
self.right_top_title.grid(row=1 , column=0 , pady=5)
self.right_top_button1.grid(row=2 , column=0 , padx=20 , pady=5)
self.right_top_button2.grid(row=3 , column=0 , padx=20 , pady=5)
self.right_top_button3.grid(row=4 , column=0 , padx=20 , pady=5)
self.right_top_button4.grid(row=5 , column=0 , padx=20 , pady=5)
# 整体区域定位
self.frame_left_top.grid(row=0 , column=0 , padx=2 , pady=5)
self.frame_right_top.grid(row=0 , column=1 , padx=30 , pady=30)
self.frame_center.grid(row=1 , column=0 , columnspan=2 , padx=4 , pady=5)
self.frame_bottom.grid(row=2 , column=0 , columnspan=2)
self.frame_left_top.grid_propagate(0)
self.frame_right_top.grid_propagate(0)
self.frame_center.grid_propagate(0)
self.frame_bottom.grid_propagate(0)
self.frame_left_top.tkraise() # 开始显示主菜单
self.frame_right_top.tkraise() # 开始显示主菜单
self.frame_center.tkraise() # 开始显示主菜单
self.frame_bottom.tkraise() # 开始显示主菜单
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def back(self):
Gongnengjiemian(self.window) # 显示主窗口 销毁本窗口
def click(self , event):
self.col = self.tree.identify_column(event.x) # 列
self.row = self.tree.identify_row(event.y) # 行
print(self.col)
print(self.row)
self.row_info = self.tree.item(self.row , "values")
self.var_dgno.set(self.row_info[0])
self.var_dgname.set(self.row_info[1])
self.var_dgpro.set(self.row_info[2])
self.var_dgnum.set(self.row_info[3])
self.var_dgprice.set(self.row_info[4])
self.right_top_dgno_entry = Entry(self.frame_left_top , state='disabled' , textvariable=self.var_dgno ,
font=('Verdana' , 15))
print('')
def tree_sort_column(self , tv , col , reverse): # Treeview、列名、排列方式
l = [(tv.set(k , col) , k) for k in tv.get_children('')]
l.sort(reverse=reverse) # 排序方式
# rearrange items in sorted positions
for index , (val , k) in enumerate(l): # 根据排序后索引移动
tv.move(k , '' , index)
tv.heading(col , command=lambda: self.tree_sort_column(tv , col , not reverse)) # 重写标题,使之成为再点倒序的标题
def new_row(self):
print('123')
print(self.var_dgno.get())
print(self.dgno)
if str(self.var_dgno.get()) in self.dgno:
messagebox.showinfo('警告!' , '该药品已存在!')
else:
if self.var_dgno.get() != '' and self.var_dgname.get() != '' and self.var_dgpro.get() != '' and self.var_dgnum.get() != '' and self.var_dgprice.get() != '':
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "INSERT INTO drug(dgno, dgname, dgpro, dgnum,dgprice) VALUES('%s', '%s', '%s', '%s','%s') " % (
self.var_dgno.get() , self.var_dgname.get() , self.var_dgpro.get() , self.var_dgnum.get() ,
self.var_dgprice.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
self.dgno.append(self.var_dgno.get())
self.dgname.append(self.var_dgname.get())
self.dgpro.append(self.var_dgpro.get())
self.dgnum.append(self.var_dgnum.get())
self.dgprice.append(self.var_dgprice.get())
self.tree.insert('' , len(self.dgno) - 1 , values=(
self.dgno[len(self.dgno) - 1] , self.dgname[len(self.dgno) - 1] , self.dgpro[len(self.dgno) - 1] ,
self.dgnum[len(self.dgno) - 1] , self.dgprice[len(self.dgno) - 1]))
self.tree.update()
messagebox.showinfo('提示!' , '插入成功!')
else:
messagebox.showinfo('警告!' , '请填写药品数据')
def updata_row(self):
res = messagebox.askyesnocancel('警告!' , '是否更新所填数据?')
if res:
if self.var_dgno.get() == self.row_info[0]: # 如果所填学号 与 所选学号一致
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "UPDATE drug SET dgname = '%s', dgpro = '%s',dgnum='%s',dgprice='%s' WHERE dgno= '%s'" % (
self.var_dgname.get() , self.var_dgpro.get() , self.var_dgnum.get() , self.var_dgprice.get() ,
self.var_dgno.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '更新成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '更新失败,数据库连接失败!')
db.close() # 关闭数据库连接
dgno_index = self.dgno.index(self.row_info[0])
self.dgname[dgno_index] = self.var_dgname.get()
self.dgpro[dgno_index] = self.var_dgpro.get()
self.dgnum[dgno_index] = self.var_dgnum.get()
self.dgprice[dgno_index] = self.var_dgprice.get()
self.tree.item(self.tree.selection()[0] , values=(
self.var_dgno.get() , self.var_dgname.get() , self.var_dgpro.get() , self.var_dgnum.get() ,
self.var_dgprice.get()))
else:
messagebox.showinfo('警告!' , '不能修改药品编号!')
def del_row(self):
res = messagebox.askyesnocancel('警告!' , '是否删除所选数据?')
if res:
print(self.row_info[0]) # 鼠标选中的学号
print(self.tree.selection()[0]) # 行号
print(self.tree.get_children()) # 所有行
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "DELETE FROM drug WHERE dgno = '%s'" % (self.row_info[0]) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '删除成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '删除失败,数据库连接失败!')
db.close() # 关闭数据库连接
dgno_index = self.dgno.index(self.row_info[0])
print(dgno_index)
del self.dgno[dgno_index]
del self.dgname[dgno_index]
del self.dgpro[dgno_index]
del self.dgnum[dgno_index]
del self.dgprice[dgno_index]
print(self.dgno)
self.tree.delete(self.tree.selection()[0]) # 删除所选行
print(self.tree.get_children())
# 病房资料管理
class AdminManage5:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = Tk() # 初始框的声明
self.window.title('病房资料操作界面')
self.frame_left_top = tk.Frame(width=300 , height=200)
self.frame_right_top = tk.Frame(width=200 , height=200)
self.frame_center = tk.Frame(width=500 , height=400)
self.frame_bottom = tk.Frame(width=650 , height=50)
# 定义下方中心列表区域
self.columns = ("病房号" , "地址" , "所属科室")
self.tree = ttk.Treeview(self.frame_center , show="headings" , height=18 , columns=self.columns)
self.vbar = ttk.Scrollbar(self.frame_center , orient=VERTICAL , command=self.tree.yview)
# 定义树形结构与滚动条
self.tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.tree.column("病房号" , width=150 , anchor='center') # 表示列,不显示
self.tree.column("地址" , width=150 , anchor='center')
self.tree.column("所属科室" , width=100 , anchor='center')
# 调用方法获取表格内容插入
self.tree.grid(row=0 , column=0 , sticky=NSEW)
self.vbar.grid(row=0 , column=1 , sticky=NS)
self.rno = []
self.radr = []
self.dpno = []
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "SELECT * FROM vroom" # SQL 查询语句
try:
# 执行SQL语句
cursor.execute(sql)
# 获取所有记录列表
results = cursor.fetchall()
for row in results:
self.rno.append(row[0])
self.radr.append(row[1])
self.dpno.append(row[2])
except:
print("Error: unable to fetch data")
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
print("test***********************")
for i in range(min(len(self.rno) , len(self.radr) , len(self.dpno))): # 写入数据
self.tree.insert('' , i , values=(self.rno[i] , self.radr[i] , self.dpno[i]))
for col in self.columns: # 绑定函数,使表头可排序
self.tree.heading(col , text=col , command=lambda _col=col: self.tree_sort_column(self.tree , _col , False))
# 定义顶部区域
# 定义左上方区域
self.top_title = Label(self.frame_left_top , text="病房信息" , bg='cornflowerblue' , font=('Verdana' , 20))
self.top_title.grid(row=0 , column=0 , columnspan=2 , sticky=NSEW , padx=50 , pady=10)
self.left_top_frame = tk.Frame(self.frame_left_top)
self.var_rno = StringVar() # 声明病房号
self.var_radr = StringVar() # 声明地址
self.var_dpno = StringVar() # 声明科室
# 病房号
self.right_top_rno_label = Label(self.frame_left_top , text="病房号:" , font=('Verdana' , 15))
self.right_top_rno_entry = Entry(self.frame_left_top , textvariable=self.var_rno , font=('Verdana' , 15))
self.right_top_rno_label.grid(row=1 , column=0) # 位置设置
self.right_top_rno_entry.grid(row=1 , column=1)
# 地址
self.right_top_radr_label = Label(self.frame_left_top , text="地址:" , font=('Verdana' , 15))
self.right_top_radr_entry = Entry(self.frame_left_top , textvariable=self.var_radr , font=('Verdana' , 15))
self.right_top_radr_label.grid(row=2 , column=0) # 位置设置
self.right_top_radr_entry.grid(row=2 , column=1)
# 科室
self.right_top_dpno_label = Label(self.frame_left_top , text="科室号:" , font=('Verdana' , 15))
self.right_top_dpno_entry = Entry(self.frame_left_top , textvariable=self.var_dpno , font=('Verdana' , 15))
self.right_top_dpno_label.grid(row=3 , column=0) # 位置设置
self.right_top_dpno_entry.grid(row=3 , column=1)
# 定义右上方区域
self.right_top_title = Label(self.frame_right_top , text="操作" , font=('Verdana' , 20))
self.tree.bind('' , self.click) # 左键获取位置
self.right_top_button1 = ttk.Button(self.frame_right_top , text='新建病房信息' , width=20 , command=self.new_row)
self.right_top_button2 = ttk.Button(self.frame_right_top , text='更新病房信息' , width=20 , command=self.updata_row)
self.right_top_button3 = ttk.Button(self.frame_right_top , text='删除选中病房信息' , width=20 , command=self.del_row)
# 位置设置
self.right_top_title.grid(row=1 , column=0 , pady=5)
self.right_top_button1.grid(row=2 , column=0 , padx=20 , pady=5)
self.right_top_button2.grid(row=3 , column=0 , padx=20 , pady=5)
self.right_top_button3.grid(row=4 , column=0 , padx=20 , pady=5)
# 整体区域定位
self.frame_left_top.grid(row=0 , column=0 , padx=2 , pady=5)
self.frame_right_top.grid(row=0 , column=1 , padx=30 , pady=30)
self.frame_center.grid(row=1 , column=0 , columnspan=2 , padx=4 , pady=5)
self.frame_bottom.grid(row=2 , column=0 , columnspan=2)
self.frame_left_top.grid_propagate(0)
self.frame_right_top.grid_propagate(0)
self.frame_center.grid_propagate(0)
self.frame_bottom.grid_propagate(0)
self.frame_left_top.tkraise() # 开始显示主菜单
self.frame_right_top.tkraise() # 开始显示主菜单
self.frame_center.tkraise() # 开始显示主菜单
self.frame_bottom.tkraise() # 开始显示主菜单
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def back(self):
Gongnengjiemian(self.window) # 显示主窗口 销毁本窗口
def click(self , event):
self.col = self.tree.identify_column(event.x) # 列
self.row = self.tree.identify_row(event.y) # 行
print(self.col)
print(self.row)
self.row_info = self.tree.item(self.row , "values")
self.var_rno.set(self.row_info[0])
self.var_radr.set(self.row_info[1])
self.var_dpno.set(self.row_info[2])
self.right_top_rno_entry = Entry(self.frame_left_top , state='disabled' , textvariable=self.var_rno ,
font=('Verdana' , 15))
print('')
def tree_sort_column(self , tv , col , reverse): # Treeview、列名、排列方式
l = [(tv.set(k , col) , k) for k in tv.get_children('')]
l.sort(reverse=reverse) # 排序方式
# rearrange items in sorted positions
for index , (val , k) in enumerate(l): # 根据排序后索引移动
tv.move(k , '' , index)
tv.heading(col , command=lambda: self.tree_sort_column(tv , col , not reverse)) # 重写标题,使之成为再点倒序的标题
def new_row(self):
print('123')
print(self.var_rno.get())
print(self.rno)
if str(self.var_rno.get()) in self.rno:
messagebox.showinfo('警告!' , '该病房已存在!')
else:
if self.var_rno.get() != '' and self.var_radr.get() != '' and self.var_dpno.get() != '':
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "INSERT INTO room(rno, radr, dpno) VALUES('%s', '%s', '%s') " % (
self.var_rno.get() , self.var_radr.get() , self.var_dpno.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
self.rno.append(self.var_rno.get())
self.radr.append(self.var_radr.get())
self.dpno.append(self.var_dpno.get())
self.tree.insert('' , len(self.rno) - 1 , values=(
self.rno[len(self.rno) - 1] , self.radr[len(self.rno) - 1] ,
self.dpno[len(self.rno) - 1]))
self.tree.update()
messagebox.showinfo('提示!' , '插入成功!')
else:
messagebox.showinfo('警告!' , '请填写病房数据')
def updata_row(self):
res = messagebox.askyesnocancel('警告!' , '是否更新所填数据?')
if res == True:
if self.var_rno.get() == self.row_info[0]: # 如果所填学号 与 所选学号一致
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "UPDATE room SET radr = '%s', dpno = '%s'WHERE rno= '%s'" % (
self.var_radr.get() , self.var_dpno.get() , self.var_rno.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '更新成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '更新失败,数据库连接失败!')
db.close() # 关闭数据库连接
rno_index = self.rno.index(self.row_info[0])
self.rno[rno_index] = self.var_rno.get()
self.radr[rno_index] = self.var_radr.get()
self.dpno[rno_index] = self.var_dpno.get()
self.tree.item(self.tree.selection()[0] , values=(
self.var_rno.get() , self.var_radr.get() , self.var_dpno.get()))
else:
messagebox.showinfo('警告!' , '不能修改病房号!')
def del_row(self):
res = messagebox.askyesnocancel('警告!' , '是否删除所选数据?')
if res == True:
print(self.row_info[0]) # 鼠标选中的学号
print(self.tree.selection()[0]) # 行号
print(self.tree.get_children()) # 所有行
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "DELETE FROM room WHERE rno = '%s'" % (self.row_info[0]) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '删除成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '删除失败,数据库连接失败!')
db.close() # 关闭数据库连接
rno_index = self.rno.index(self.row_info[0])
print(rno_index)
del self.rno[rno_index]
del self.radr[rno_index]
del self.dpno[rno_index]
print(self.rno)
self.tree.delete(self.tree.selection()[0]) # 删除所选行
print(self.tree.get_children())
# 病人用药记录管理
class AdminManage6:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = Tk() # 初始框的声明
self.window.title('患者用药记录')
self.frame_left_top = tk.Frame(width=300 , height=200)
self.frame_right_top = tk.Frame(width=200 , height=200)
self.frame_center = tk.Frame(width=500 , height=400)
self.frame_bottom = tk.Frame(width=650 , height=50)
# 定义下方中心列表区域
self.columns = ("药品号" , "患者号" , "用药次数")
self.tree = ttk.Treeview(self.frame_center , show="headings" , height=18 , columns=self.columns)
self.vbar = ttk.Scrollbar(self.frame_center , orient=VERTICAL , command=self.tree.yview)
# 定义树形结构与滚动条
self.tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.tree.column("药品号" , width=150 , anchor='center') # 表示列,不显示
self.tree.column("患者号" , width=150 , anchor='center')
self.tree.column("用药次数" , width=100 , anchor='center')
# 调用方法获取表格内容插入
self.tree.grid(row=0 , column=0 , sticky=NSEW)
self.vbar.grid(row=0 , column=1 , sticky=NS)
self.dgno = []
self.pno = []
self.num = []
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "SELECT * FROM vpd" # SQL 查询语句
try:
# 执行SQL语句
cursor.execute(sql)
# 获取所有记录列表
results = cursor.fetchall()
for row in results:
self.dgno.append(row[0])
self.pno.append(row[1])
self.num.append(row[2])
except:
print("Error: unable to fetch data")
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
print("test***********************")
for i in range(min(len(self.dgno) , len(self.pno) , len(self.num))): # 写入数据
self.tree.insert('' , i , values=(self.dgno[i] , self.pno[i] , self.num[i]))
for col in self.columns: # 绑定函数,使表头可排序
self.tree.heading(col , text=col , command=lambda _col=col: self.tree_sort_column(self.tree , _col , False))
# 定义顶部区域
# 定义左上方区域
self.top_title = Label(self.frame_left_top , text="病人用药记录" , bg='royalblue' , font=('Verdana' , 20))
self.top_title.grid(row=0 , column=0 , columnspan=2 , sticky=NSEW , padx=50 , pady=10)
self.left_top_frame = tk.Frame(self.frame_left_top)
self.var_dgno = StringVar() # 声明药品号
self.var_pno = StringVar() # 声明病人号
self.var_num = StringVar() # 声明次数
# 病房号
self.right_top_dgno_label = Label(self.frame_left_top , text="药品编号:" , font=('Verdana' , 15))
self.right_top_dgno_entry = Entry(self.frame_left_top , textvariable=self.var_dgno , font=('Verdana' , 15))
self.right_top_dgno_label.grid(row=1 , column=0) # 位置设置
self.right_top_dgno_entry.grid(row=1 , column=1)
# 地址
self.right_top_pno_label = Label(self.frame_left_top , text="患者编号:" , font=('Verdana' , 15))
self.right_top_pno_entry = Entry(self.frame_left_top , textvariable=self.var_pno , font=('Verdana' , 15))
self.right_top_pno_label.grid(row=2 , column=0) # 位置设置
self.right_top_pno_entry.grid(row=2 , column=1)
# 次数
self.right_top_num_label = Label(self.frame_left_top , text="用药次数:" , font=('Verdana' , 15))
self.right_top_num_entry = Entry(self.frame_left_top , textvariable=self.var_num , font=('Verdana' , 15))
self.right_top_num_label.grid(row=3 , column=0) # 位置设置
self.right_top_num_entry.grid(row=3 , column=1)
# 定义右上方区域
self.right_top_title = Label(self.frame_right_top , text="操作" , font=('Verdana' , 20))
self.tree.bind('' , self.click) # 左键获取位置
self.right_top_button1 = ttk.Button(self.frame_right_top , text='新建用药记录信息' , width=20 , command=self.new_row)
self.right_top_button2 = ttk.Button(self.frame_right_top , text='更新用药记录信息' , width=20 , command=self.updata_row)
self.right_top_button3 = ttk.Button(self.frame_right_top , text='删除选中用药记录信息' , width=20 , command=self.del_row)
# 位置设置
self.right_top_title.grid(row=1 , column=0 , pady=10)
self.right_top_button1.grid(row=2 , column=0 , padx=20 , pady=10)
self.right_top_button2.grid(row=3 , column=0 , padx=20 , pady=10)
self.right_top_button3.grid(row=4 , column=0 , padx=20 , pady=10)
# 整体区域定位
self.frame_left_top.grid(row=0 , column=0 , padx=2 , pady=5)
self.frame_right_top.grid(row=0 , column=1 , padx=30 , pady=30)
self.frame_center.grid(row=1 , column=0 , columnspan=2 , padx=4 , pady=5)
self.frame_bottom.grid(row=2 , column=0 , columnspan=2)
self.frame_left_top.grid_propagate(0)
self.frame_right_top.grid_propagate(0)
self.frame_center.grid_propagate(0)
self.frame_bottom.grid_propagate(0)
self.frame_left_top.tkraise() # 开始显示主菜单
self.frame_right_top.tkraise() # 开始显示主菜单
self.frame_center.tkraise() # 开始显示主菜单
self.frame_bottom.tkraise() # 开始显示主菜单
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def back(self):
Gongnengjiemian(self.window) # 显示主窗口 销毁本窗口
def click(self , event):
self.col = self.tree.identify_column(event.x) # 列
self.row = self.tree.identify_row(event.y) # 行
print(self.col)
print(self.row)
self.row_info = self.tree.item(self.row , "values")
self.var_dgno.set(self.row_info[0])
self.var_pno.set(self.row_info[1])
self.var_num.set(self.row_info[2])
self.right_top_dgno_entry = Entry(self.frame_left_top , state='disabled' , textvariable=self.var_dgno ,
font=('Verdana' , 15))
print('')
def tree_sort_column(self , tv , col , reverse): # Treeview、列名、排列方式
l = [(tv.set(k , col) , k) for k in tv.get_children('')]
l.sort(reverse=reverse) # 排序方式
# rearrange items in sorted positions
for index , (val , k) in enumerate(l): # 根据排序后索引移动
tv.move(k , '' , index)
tv.heading(col , command=lambda: self.tree_sort_column(tv , col , not reverse)) # 重写标题,使之成为再点倒序的标题
def new_row(self):
print('123')
print(self.var_dgno.get())
print(self.dgno)
if str(self.var_dgno.get()) in self.dgno:
messagebox.showinfo('警告!' , '该用药记录已存在!')
else:
if self.var_dgno.get() != '' and self.var_pno.get() != '' and self.var_num.get() != '':
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "INSERT INTO PD(dgno, pno, num) VALUES('%s', '%s', '%s') " % (
self.var_dgno.get() , self.var_pno.get() , self.var_num.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
self.dgno.append(self.var_dgno.get())
self.pno.append(self.var_pno.get())
self.num.append(self.var_num.get())
self.tree.insert('' , len(self.dgno) - 1 , values=(
self.dgno[len(self.dgno) - 1] , self.pno[len(self.dgno) - 1] ,
self.num[len(self.dgno) - 1]))
self.tree.update()
messagebox.showinfo('提示!' , '插入成功!')
else:
messagebox.showinfo('警告!' , '请填写病房数据')
def updata_row(self):
res = messagebox.askyesnocancel('警告!' , '是否更新所填数据?')
if res == True:
if self.var_dgno.get() == self.row_info[0]: # 如果所填学号 与 所选学号一致
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "UPDATE PD SET pno = '%s', num = '%s'WHERE dgno= '%s'" % (
self.var_pno.get() , self.var_num.get() , self.var_dgno.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '更新成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '更新失败,数据库连接失败!')
db.close() # 关闭数据库连接
dgno_index = self.dgno.index(self.row_info[0])
self.dgno[dgno_index] = self.var_dgno.get()
self.pno[dgno_index] = self.var_pno.get()
self.num[dgno_index] = self.var_num.get()
self.tree.item(self.tree.selection()[0] , values=(
self.var_dgno.get() , self.var_pno.get() , self.var_num.get()))
else:
messagebox.showinfo('警告!' , '不能修改药品号!')
def del_row(self):
res = messagebox.askyesnocancel('警告!' , '是否删除所选数据?')
if res == True:
print(self.row_info[0]) # 鼠标选中的学号
print(self.tree.selection()[0]) # 行号
print(self.tree.get_children()) # 所有行
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "DELETE FROM PD WHERE dgno = '%s'" % (self.row_info[0]) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '删除成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '删除失败,数据库连接失败!')
db.close() # 关闭数据库连接
dgno_index = self.dgno.index(self.row_info[0])
print(dgno_index)
del self.dgno[dgno_index]
del self.pno[dgno_index]
del self.num[dgno_index]
print(self.dgno)
self.tree.delete(self.tree.selection()[0]) # 删除所选行
print(self.tree.get_children())
# 护士护理记录管理
class AdminManage7:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = Tk() # 初始框的声明
self.window.title('护士护理记录操作界面')
self.frame_left_top = tk.Frame(width=300 , height=200)
self.frame_right_top = tk.Frame(width=200 , height=200)
self.frame_center = tk.Frame(width=500 , height=400)
self.frame_bottom = tk.Frame(width=650 , height=50)
# 定义下方中心列表区域
self.columns = ("患者编号" , "护士编号" , "护理内容" , "时间")
self.tree = ttk.Treeview(self.frame_center , show="headings" , height=18 , columns=self.columns)
self.vbar = ttk.Scrollbar(self.frame_center , orient=VERTICAL , command=self.tree.yview)
# 定义树形结构与滚动条
self.tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.tree.column("患者编号" , width=100 , anchor='center') # 表示列,不显示
self.tree.column("护士编号" , width=100 , anchor='center')
self.tree.column("护理内容" , width=150 , anchor='center')
self.tree.column("时间" , width=150 , anchor='center')
# 调用方法获取表格内容插入
self.tree.grid(row=0 , column=0 , sticky=NSEW)
self.vbar.grid(row=0 , column=1 , sticky=NS)
self.pno = []
self.nno = []
self.content = []
self.time = []
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "SELECT * FROM " # SQL 查询语句
try:
# 执行SQL语句
cursor.execute(sql)
# 获取所有记录列表
results = cursor.fetchall()
for row in results:
self.pno.append(row[0])
self.nno.append(row[1])
self.content.append(row[2])
self.time.append(row[3])
except:
print("Error: unable to fetch data")
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
print("test***********************")
for i in range(min(len(self.pno) , len(self.nno) , len(self.content) , len(self.time))): # 写入数据
self.tree.insert('' , i , values=(self.pno[i] , self.nno[i] , self.content[i] , self.time[i]))
for col in self.columns: # 绑定函数,使表头可排序
self.tree.heading(col , text=col , command=lambda _col=col: self.tree_sort_column(self.tree , _col , False))
# 定义顶部区域
# 定义左上方区域
self.top_title = Label(self.frame_left_top , text="护士护理记录" , bg='slateblue' , font=('Verdana' , 20))
self.top_title.grid(row=0 , column=0 , columnspan=2 , sticky=NSEW , padx=50 , pady=10)
self.left_top_frame = tk.Frame(self.frame_left_top)
self.var_pno = StringVar() # 声明病人编号
self.var_nno = StringVar() # 声明护士编号
self.var_content = StringVar() # 声明内容
self.var_time = StringVar() # 声明时间
# pno
self.right_top_pno_label = Label(self.frame_left_top , text="患者编号:" , font=('Verdana' , 15))
self.right_top_pno_entry = Entry(self.frame_left_top , textvariable=self.var_pno , font=('Verdana' , 15))
self.right_top_pno_label.grid(row=1 , column=0) # 位置设置
self.right_top_pno_entry.grid(row=1 , column=1)
# 护士编号
self.right_top_nno_label = Label(self.frame_left_top , text="护士编号:" , font=('Verdana' , 15))
self.right_top_nno_entry = Entry(self.frame_left_top , textvariable=self.var_nno , font=('Verdana' , 15))
self.right_top_nno_label.grid(row=2 , column=0) # 位置设置
self.right_top_nno_entry.grid(row=2 , column=1)
# 内容
self.right_top_content_label = Label(self.frame_left_top , text="护理内容:" , font=('Verdana' , 15))
self.right_top_content_entry = Entry(self.frame_left_top , textvariable=self.var_content ,
font=('Verdana' , 15))
self.right_top_content_label.grid(row=3 , column=0) # 位置设置
self.right_top_content_entry.grid(row=3 , column=1)
# 时间
self.right_top_time_label = Label(self.frame_left_top , text="时间:" , font=('Verdana' , 15))
self.right_top_time_entry = Entry(self.frame_left_top , textvariable=self.var_time , font=('Verdana' , 15))
self.right_top_time_label.grid(row=4 , column=0) # 位置设置
self.right_top_time_entry.grid(row=4 , column=1)
# 定义右上方区域
self.right_top_title = Label(self.frame_right_top , text="操作" , font=('Verdana' , 20))
self.tree.bind('' , self.click) # 左键获取位置
self.right_top_button1 = ttk.Button(self.frame_right_top , text='新建护理记录信息' , width=20 , command=self.new_row)
self.right_top_button2 = ttk.Button(self.frame_right_top , text='更新选中护理记录信息' , width=20 ,
command=self.updata_row)
self.right_top_button3 = ttk.Button(self.frame_right_top , text='删除选中护理记录信息' , width=20 , command=self.del_row)
# 位置设置
self.right_top_title.grid(row=1 , column=0 , pady=10)
self.right_top_button1.grid(row=2 , column=0 , padx=20 , pady=10)
self.right_top_button2.grid(row=3 , column=0 , padx=20 , pady=10)
self.right_top_button3.grid(row=4 , column=0 , padx=20 , pady=10)
# 整体区域定位
self.frame_left_top.grid(row=0 , column=0 , padx=2 , pady=5)
self.frame_right_top.grid(row=0 , column=1 , padx=30 , pady=30)
self.frame_center.grid(row=1 , column=0 , columnspan=2 , padx=4 , pady=5)
self.frame_bottom.grid(row=2 , column=0 , columnspan=2)
self.frame_left_top.grid_propagate(0)
self.frame_right_top.grid_propagate(0)
self.frame_center.grid_propagate(0)
self.frame_bottom.grid_propagate(0)
self.frame_left_top.tkraise() # 开始显示主菜单
self.frame_right_top.tkraise() # 开始显示主菜单
self.frame_center.tkraise() # 开始显示主菜单
self.frame_bottom.tkraise() # 开始显示主菜单
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def back(self):
Gongnengjiemian(self.window) # 显示主窗口 销毁本窗口
def click(self , event):
self.col = self.tree.identify_column(event.x) # 列
self.row = self.tree.identify_row(event.y) # 行
print(self.col)
print(self.row)
self.row_info = self.tree.item(self.row , "values")
self.var_pno.set(self.row_info[0])
self.var_nno.set(self.row_info[1])
self.var_content.set(self.row_info[2])
self.var_time.set(self.row_info[3])
self.right_top_pno_entry = Entry(self.frame_left_top , state='disabled' , textvariable=self.var_pno ,
font=('Verdana' , 15))
print('')
def tree_sort_column(self , tv , col , reverse): # Treeview、列名、排列方式
l = [(tv.set(k , col) , k) for k in tv.get_children('')]
l.sort(reverse=reverse) # 排序方式
# rearrange items in sorted positions
for index , (val , k) in enumerate(l): # 根据排序后索引移动
tv.move(k , '' , index)
tv.heading(col , command=lambda: self.tree_sort_column(tv , col , not reverse)) # 重写标题,使之成为再点倒序的标题
def new_row(self):
print('123')
print(self.var_pno.get())
print(self.pno)
if str(self.var_pno.get()) in self.pno:
messagebox.showinfo('警告!' , '该护理记录已存在!')
else:
if self.var_pno.get() != '' and self.var_nno.get() != '' and self.var_content.get() != '' and self.var_time.get() != '':
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "INSERT INTO PN(pno, nno, content, time) VALUES('%s', '%s', '%s', '%s') " % (
self.var_pno.get() , self.var_nno.get() , self.var_content.get() , self.var_time.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '数据库连接失败!')
db.close() # 关闭数据库连接
self.pno.append(self.var_pno.get())
self.nno.append(self.var_nno.get())
self.content.append(self.var_content.get())
self.time.append(self.var_time.get())
self.tree.insert('' , len(self.pno) - 1 , values=(
self.pno[len(self.pno) - 1] , self.nno[len(self.pno) - 1] , self.content[len(self.pno) - 1] ,
self.time[len(self.pno) - 1]))
self.tree.update()
messagebox.showinfo('提示!' , '插入成功!')
else:
messagebox.showinfo('警告!' , '请填写科室数据')
def updata_row(self):
res = messagebox.askyesnocancel('警告!' , '是否更新所填数据?')
if res:
if self.var_pno.get() == self.row_info[0]: # 如果所填学号 与 所选学号一致
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "UPDATE PN SET nno = '%s', content = '%s', time = '%s' WHERE pno= '%s'" % (
self.var_nno.get() , self.var_content.get() , self.var_time.get() , self.var_pno.get()) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '更新成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '更新失败,数据库连接失败!')
db.close() # 关闭数据库连接
pno_index = self.pno.index(self.row_info[0])
self.nno[pno_index] = self.var_nno.get()
self.content[pno_index] = self.var_content.get()
self.time[pno_index] = self.var_time.get()
self.tree.item(self.tree.selection()[0] , values=(
self.var_pno.get() , self.var_nno.get() , self.var_content.get() , self.var_time.get()))
else:
messagebox.showinfo('警告!' , '不能修改患者编号!')
def del_row(self):
res = messagebox.askyesnocancel('警告!' , '是否删除所选数据?')
if res:
print(self.row_info[0]) # 鼠标选中的学号
print(self.tree.selection()[0]) # 行号
print(self.tree.get_children()) # 所有行
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "DELETE FROM PN WHERE pno = '%s'" % (self.row_info[0]) # SQL 插入语句
try:
cursor.execute(sql) # 执行sql语句
db.commit() # 提交到数据库执行
messagebox.showinfo('提示!' , '删除成功!')
except:
db.rollback() # 发生错误时回滚
messagebox.showinfo('警告!' , '删除失败,数据库连接失败!')
db.close() # 关闭数据库连接
pno_index = self.pno.index(self.row_info[0])
print(pno_index)
del self.pno[pno_index]
del self.nno[pno_index]
del self.content[pno_index]
del self.time[pno_index]
print(self.pno)
self.tree.delete(self.tree.selection()[0]) # 删除所选行
print(self.tree.get_children())
# 游客登录后的界面初始化和操作
class StudentView:
def __init__(self , parent_window , student_id):
parent_window.destroy() # 销毁主界面
self.window = tk.Tk() # 初始框的声明
self.window.title('医院基本信息')
self.window.geometry('500x450') # 这里的乘是小x
label = tk.Label(self.window , text='医院信息查看' , bg='gold' , font=('Verdana' , 20) , width=30 , height=2)
label.pack(pady=20)
self.id = '编号:' + ''
self.hpname = '医院名称:' + ''
self.host = '院长:' + ''
self.hadr = '地址:' + ''
self.htel = '联系号码:' + ''
# 打开数据库连接
db = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursor = db.cursor() # 使用cursor()方法获取操作游标
sql = "SELECT * FROM h WHERE id = '%s'" % student_id # SQL 查询语句
try:
# 执行SQL语句
cursor.execute(sql)
# 获取所有记录列表
results = cursor.fetchall()
for row in results:
self.id = '编号:' + row[0]
self.hpname = '医院名称:' + row[1]
self.host = '院长:' + row[2]
self.hadr = '地址:' + row[3]
self.htel = '电话:' + row[4]
except:
print("Error: unable to fetch data")
db.close() # 关闭数据库连接
Label(self.window , text=self.id , font=('Verdana' , 18)).pack(pady=5)
Label(self.window , text=self.hpname , font=('Verdana' , 18)).pack(pady=5)
Label(self.window , text=self.host , font=('Verdana' , 18)).pack(pady=5)
Label(self.window , text=self.hadr , font=('Verdana' , 18)).pack(pady=5)
Label(self.window , text=self.htel , font=('Verdana' , 18)).pack(pady=5)
Button(self.window , text="返回首页" , width=8 , font=tkFont.Font(size=16) , command=self.back).pack(pady=25)
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def back(self):
StartPage(self.window) # 显示主窗口 销毁本窗口
# 查询科室
class SelectDept:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = Tk() # 初始框的声明
self.window.title('科室资料查询界面')
self.frame_left_top = tk.Frame(width=300 , height=200)
self.frame_right_top = tk.Frame(width=300 , height=200)
self.frame_center = tk.Frame(width=500 , height=100)
self.frame_bottom = tk.Frame(width=650 , height=50)
# 定义下方中心列表区域
self.columns = ("科室名" , "编号" , "地址" , "电话")
self.tree = ttk.Treeview(self.frame_center , show="headings" , height=18 , columns=self.columns)
self.vbar = ttk.Scrollbar(self.frame_center , orient=VERTICAL , command=self.tree.yview)
# 定义树形结构与滚动条
self.tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.tree.column("科室名" , width=100 , anchor='center') # 表示列,不显示
self.tree.column("编号" , width=100 , anchor='center')
self.tree.column("地址" , width=150 , anchor='center')
self.tree.column("电话" , width=150 , anchor='center')
# 定义顶部区域
# 定义左上方区域
self.top_title = Label(self.frame_left_top , text="查询科室信息" , bg='limegreen' , font=('Verdana' , 20))
self.top_title.grid(row=0 , column=0 , columnspan=2 , sticky=NSEW , padx=50 , pady=10)
self.left_top_frame = tk.Frame(self.frame_left_top)
self.var_dpname = StringVar() # 声明科室名
# 科室名
self.right_top_dpname_label = Label(self.frame_left_top , text="科室名:" , font=('Verdana' , 15))
self.right_top_dpname_entry = Entry(self.frame_left_top , textvariable=self.var_dpname , font=('Verdana' , 15))
self.right_top_dpname_label.grid(row=1 , column=0) # 位置设置
self.right_top_dpname_entry.grid(row=1 , column=1)
# 定义右上方区域
self.right_top_title = Label(self.frame_right_top , text="操作" , font=('Verdana' , 20))
self.tree.bind('' , self.click) # 左键获取位置
self.right_top_button1 = ttk.Button(self.frame_right_top , text='查询科室信息' , width=20 , command=self.select_row)
self.right_top_button2 = ttk.Button(self.frame_right_top , text='返回科室信息' , width=20 , command=lambda: AdminManage(self.window))
# 位置设置
self.right_top_title.grid(row=1 , column=0 , pady=10)
self.right_top_button1.grid(row=2 , column=0 , padx=20 , pady=5)
self.right_top_button2.grid(row=3 , column=0 , padx=20 , pady=5)
# 整体区域定位
self.frame_left_top.grid(row=0 , column=0 , padx=2 , pady=5)
self.frame_right_top.grid(row=0 , column=1 , padx=30 , pady=30)
self.frame_center.grid(row=1 , column=0 , columnspan=2 , padx=4 , pady=5)
self.frame_bottom.grid(row=2 , column=0 , columnspan=2)
self.frame_left_top.grid_propagate(0)
self.frame_right_top.grid_propagate(0)
self.frame_center.grid_propagate(0)
self.frame_bottom.grid_propagate(0)
self.frame_left_top.tkraise() # 开始显示主菜单
self.frame_right_top.tkraise() # 开始显示主菜单
self.frame_center.tkraise() # 开始显示主菜单
self.frame_bottom.tkraise() # 开始显示主菜单
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def select_row(self):
# 调用方法获取表格内容插入
self.tree.grid(row=0 , column=0 , sticky=NSEW)
self.vbar.grid(row=0 , column=1 , sticky=NS)
self.dpname = []
self.dpno = []
self.dpadr = []
self.dptel = []
# 打开数据库连接
dbs = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursors = dbs.cursor() # 使用cursor()方法获取操作游标
sqll = "SELECT * FROM department WHERE dpname= '%s'" % (self.var_dpname.get()) # SQL 查询语句
try:
# 执行SQL语句
cursors.execute(sqll)
# 获取所有记录列表
results = cursors.fetchall()
for row in results:
self.dpname.append(row[0])
self.dpno.append(row[1])
self.dpadr.append(row[2])
self.dptel.append(row[3])
except:
print("Error: unable to fetch data")
messagebox.showinfo('警告!' , '数据库连接失败!')
dbs.close() # 关闭数据库连接
print(self.dpname)
if len(self.dpname) == 0:
messagebox.showinfo('警告!' , '查询失败!')
for i in range(min(len(self.dpname) , len(self.dpno) , len(self.dpadr) , len(self.dptel))): # 写入数据
self.tree.insert('' , i , values=(self.dpname[i] , self.dpno[i] , self.dpadr[i] , self.dptel[i]))
for col in self.columns: # 绑定函数,使表头可排序
self.tree.heading(col , text=col , command=lambda _col=col: self.tree_sort_column(self.tree , _col , False))
def back(self):
AdminManage(self.window) # 显示主窗口 销毁本窗口
def click(self , event):
self.col = self.tree.identify_column(event.x) # 列
self.row = self.tree.identify_row(event.y) # 行
print(self.col) # 列
print(self.row) # 行
self.row_info = self.tree.item(self.row , "values")
self.var_dpname.set(self.row_info[0])
self.right_top_dpname_entry = Entry(self.frame_left_top , state='disabled' , textvariable=self.var_dpname ,
font=('Verdana' , 15))
print('')
# 点击标题进行排列
def tree_sort_column(self , tv , col , reverse): # Treeview、列名、排列方式
l = [(tv.set(k , col) , k) for k in tv.get_children('')]
l.sort(reverse=reverse) # 排序方式
# 在排序位置重新排列项目
for index , (val , k) in enumerate(l): # 根据排序后索引移动
tv.move(k , '' , index)
tv.heading(col , command=lambda: self.tree_sort_column(tv , col , not reverse)) # 重写标题,使之成为再点倒序的标题
# 查询医生
class SelectDocter:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = Tk() # 初始框的声明
self.window.title('医生资料查询界面')
self.frame_left_top = tk.Frame(width=300 , height=200)
self.frame_right_top = tk.Frame(width=300 , height=200)
self.frame_center = tk.Frame(width=500 , height=100)
self.frame_bottom = tk.Frame(width=650 , height=50)
# 定义下方中心列表区域
self.columns = ("编号" , "医生名" , "职称" , "性别" , "年龄" , "科室")
self.tree = ttk.Treeview(self.frame_center , show="headings" , height=18 , columns=self.columns)
self.vbar = ttk.Scrollbar(self.frame_center , orient=VERTICAL , command=self.tree.yview)
# 定义树形结构与滚动条
self.tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.tree.column("编号" , width=70 , anchor='center') # 表示列,不显示
self.tree.column("医生名" , width=80 , anchor='center')
self.tree.column("职称" , width=100 , anchor='center')
self.tree.column("性别" , width=70 , anchor='center')
self.tree.column("年龄" , width=90 , anchor='center')
self.tree.column("科室" , width=90 , anchor='center')
# 定义顶部区域
# 定义左上方区域
self.top_title = Label(self.frame_left_top , text="查询医生信息" , bg='mediumseagreen' , font=('Verdana' , 20))
self.top_title.grid(row=0 , column=0 , columnspan=2 , sticky=NSEW , padx=50 , pady=10)
self.left_top_frame = tk.Frame(self.frame_left_top)
self.var_dname = StringVar() # 声明医生名字
# 姓名
self.right_top_dname_label = Label(self.frame_left_top , text="姓名:" , font=('Verdana' , 15))
self.right_top_dname_entry = Entry(self.frame_left_top , textvariable=self.var_dname , font=('Verdana' , 15))
self.right_top_dname_label.grid(row=2 , column=0) # 位置设置
self.right_top_dname_entry.grid(row=2 , column=1)
# 定义右上方区域
self.right_top_title = Label(self.frame_right_top , text="操作" , font=('Verdana' , 20))
self.tree.bind('' , self.click) # 左键获取位置
self.right_top_button1 = ttk.Button(self.frame_right_top , text='查询医生信息' , width=20 , command=self.select_row)
self.right_top_button2 = ttk.Button(self.frame_right_top , text='返回医生信息' , width=20 , command=lambda: AdminManage1(self.window))
# 位置设置
self.right_top_title.grid(row=1 , column=0 , pady=10)
self.right_top_button1.grid(row=2 , column=0 , padx=20 , pady=5)
self.right_top_button2.grid(row=3 , column=0 , padx=20 , pady=5)
# 整体区域定位
self.frame_left_top.grid(row=0 , column=0 , padx=2 , pady=5)
self.frame_right_top.grid(row=0 , column=1 , padx=30 , pady=30)
self.frame_center.grid(row=1 , column=0 , columnspan=2 , padx=4 , pady=5)
self.frame_bottom.grid(row=2 , column=0 , columnspan=2)
self.frame_left_top.grid_propagate(0)
self.frame_right_top.grid_propagate(0)
self.frame_center.grid_propagate(0)
self.frame_bottom.grid_propagate(0)
self.frame_left_top.tkraise() # 开始显示主菜单
self.frame_right_top.tkraise() # 开始显示主菜单
self.frame_center.tkraise() # 开始显示主菜单
self.frame_bottom.tkraise() # 开始显示主菜单
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def select_row(self):
# 调用方法获取表格内容插入
self.tree.grid(row=0 , column=0 , sticky=NSEW)
self.vbar.grid(row=0 , column=1 , sticky=NS)
self.dno = []
self.dname = []
self.duty = []
self.dsex = []
self.dage = []
self.dpno = []
# 打开数据库连接
dbs = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursors = dbs.cursor() # 使用cursor()方法获取操作游标
sqll = "SELECT * FROM doctor WHERE dname= '%s'" % (self.var_dname.get()) # SQL 查询语句
try:
# 执行SQL语句
cursors.execute(sqll)
# 获取所有记录列表
results = cursors.fetchall()
for row in results:
self.dno.append(row[0])
self.dname.append(row[1])
self.duty.append(row[2])
self.dsex.append(row[3])
self.dage.append(row[4])
self.dpno.append(row[5])
except:
print("Error: unable to fetch data")
messagebox.showinfo('警告!' , '数据库连接失败!')
dbs.close() # 关闭数据库连接
if len(self.dname) == 0:
messagebox.showinfo('警告!' , '查询失败!')
for i in range(min(len(self.dno) , len(self.dname) , len(self.duty) , len(self.dsex) , len(self.dage) ,
len(self.dpno))): # 写入数据
self.tree.insert('' , i , values=(
self.dno[i] , self.dname[i] , self.duty[i] , self.dsex[i] , self.dage[i] , self.dpno[i]))
for col in self.columns: # 绑定函数,使表头可排序
self.tree.heading(col , text=col , command=lambda _col=col: self.tree_sort_column(self.tree , _col , False))
def back(self):
AdminManage1(self.window) # 显示主窗口 销毁本窗口
def click(self , event):
self.col = self.tree.identify_column(event.x) # 列
self.row = self.tree.identify_row(event.y) # 行
print(self.col) # 列
print(self.row) # 行
self.row_info = self.tree.item(self.row , "values")
self.var_dname.set(self.row_info[1])
self.right_top_dname_entry = Entry(self.frame_left_top , state='disabled' , textvariable=self.var_dname ,
font=('Verdana' , 15))
print('')
# 点击标题进行排列
def tree_sort_column(self , tv , col , reverse): # Treeview、列名、排列方式
l = [(tv.set(k , col) , k) for k in tv.get_children('')]
l.sort(reverse=reverse) # 排序方式
# 在排序位置重新排列项目
for index , (val , k) in enumerate(l): # 根据排序后索引移动
tv.move(k , '' , index)
tv.heading(col , command=lambda: self.tree_sort_column(tv , col , not reverse)) # 重写标题,使之成为再点倒序的标题
# 查询护士
class SelectNurse:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = Tk() # 初始框的声明
self.window.title('护士资料查询界面')
self.frame_left_top = tk.Frame(width=300 , height=200)
self.frame_right_top = tk.Frame(width=300 , height=200)
self.frame_center = tk.Frame(width=500 , height=100)
self.frame_bottom = tk.Frame(width=650 , height=50)
# 定义下方中心列表区域
self.columns = ("护士编号" , "护士名" , "性别" , "年龄")
self.tree = ttk.Treeview(self.frame_center , show="headings" , height=18 , columns=self.columns)
self.vbar = ttk.Scrollbar(self.frame_center , orient=VERTICAL , command=self.tree.yview)
# 定义树形结构与滚动条
self.tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.tree.column("护士编号" , width=150 , anchor='center') # 表示列,不显示
self.tree.column("护士名" , width=150 , anchor='center')
self.tree.column("性别" , width=100 , anchor='center')
self.tree.column("年龄" , width=100 , anchor='center')
# 定义顶部区域
# 定义左上方区域
self.top_title = Label(self.frame_left_top , text="查询护士信息" , bg='seagreen' , font=('Verdana' , 20))
self.top_title.grid(row=0 , column=0 , columnspan=2 , sticky=NSEW , padx=50 , pady=10)
self.left_top_frame = tk.Frame(self.frame_left_top)
self.var_nname = StringVar() # 声明医生名字
# 护士名
self.right_top_nname_label = Label(self.frame_left_top , text="护士名:" , font=('Verdana' , 15))
self.right_top_nname_entry = Entry(self.frame_left_top , textvariable=self.var_nname , font=('Verdana' , 15))
self.right_top_nname_label.grid(row=2 , column=0) # 位置设置
self.right_top_nname_entry.grid(row=2 , column=1)
# 定义右上方区域
self.right_top_title = Label(self.frame_right_top , text="操作" , font=('Verdana' , 20))
self.tree.bind('' , self.click) # 左键获取位置
self.right_top_button1 = ttk.Button(self.frame_right_top , text='查询护士信息' , width=20 , command=self.select_row)
self.right_top_button2 = ttk.Button(self.frame_right_top , text='返回护士信息' , width=20 , command=lambda: AdminManage2(self.window))
# 位置设置
self.right_top_title.grid(row=1 , column=0 , pady=10)
self.right_top_button1.grid(row=2 , column=0 , padx=20 , pady=5)
self.right_top_button2.grid(row=3 , column=0 , padx=20 , pady=5)
# 整体区域定位
self.frame_left_top.grid(row=0 , column=0 , padx=2 , pady=5)
self.frame_right_top.grid(row=0 , column=1 , padx=30 , pady=30)
self.frame_center.grid(row=1 , column=0 , columnspan=2 , padx=4 , pady=5)
self.frame_bottom.grid(row=2 , column=0 , columnspan=2)
self.frame_left_top.grid_propagate(0)
self.frame_right_top.grid_propagate(0)
self.frame_center.grid_propagate(0)
self.frame_bottom.grid_propagate(0)
self.frame_left_top.tkraise() # 开始显示主菜单
self.frame_right_top.tkraise() # 开始显示主菜单
self.frame_center.tkraise() # 开始显示主菜单
self.frame_bottom.tkraise() # 开始显示主菜单
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def select_row(self):
# 调用方法获取表格内容插入
self.tree.grid(row=0 , column=0 , sticky=NSEW)
self.vbar.grid(row=0 , column=1 , sticky=NS)
self.nno = []
self.nname = []
self.nsex = []
self.nage = []
# 打开数据库连接
dbs = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursors = dbs.cursor() # 使用cursor()方法获取操作游标
sqll = "SELECT * FROM nurse WHERE nname= '%s'" % (self.var_nname.get()) # SQL 查询语句
try:
# 执行SQL语句
cursors.execute(sqll)
# 获取所有记录列表
results = cursors.fetchall()
for row in results:
self.nno.append(row[0])
self.nname.append(row[1])
self.nsex.append(row[2])
self.nage.append(row[3])
except:
print("Error: unable to fetch data")
messagebox.showinfo('警告!' , '数据库连接失败!')
dbs.close() # 关闭数据库连接
if len(self.nname) == 0:
messagebox.showinfo('警告!' , '查询失败!')
for i in range(min(len(self.nno) , len(self.nname) , len(self.nsex) , len(self.nage))): # 写入数据
self.tree.insert('' , i , values=(self.nno[i] , self.nname[i] , self.nsex[i] , self.nage[i]))
for col in self.columns: # 绑定函数,使表头可排序
self.tree.heading(col , text=col , command=lambda _col=col: self.tree_sort_column(self.tree , _col , False))
def back(self):
AdminManage2(self.window) # 显示主窗口 销毁本窗口
def click(self , event):
self.col = self.tree.identify_column(event.x) # 列
self.row = self.tree.identify_row(event.y) # 行
print(self.col) # 列
print(self.row) # 行
self.row_info = self.tree.item(self.row , "values")
self.var_nname.set(self.row_info[1])
self.right_top_nname_entry = Entry(self.frame_left_top , state='disabled' , textvariable=self.var_nname ,
font=('Verdana' , 15))
print('')
# 点击标题进行排列
def tree_sort_column(self , tv , col , reverse): # Treeview、列名、排列方式
l = [(tv.set(k , col) , k) for k in tv.get_children('')]
l.sort(reverse=reverse) # 排序方式
# 在排序位置重新排列项目
for index , (val , k) in enumerate(l): # 根据排序后索引移动
tv.move(k , '' , index)
tv.heading(col , command=lambda: self.tree_sort_column(tv , col , not reverse)) # 重写标题,使之成为再点倒序的标题
# 查询患者
class SelectPatient:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = Tk() # 初始框的声明
self.window.title('患者资料查询界面')
self.frame_left_top = tk.Frame(width=300 , height=200)
self.frame_right_top = tk.Frame(width=300 , height=200)
self.frame_center = tk.Frame(width=800 , height=100)
self.frame_bottom = tk.Frame(width=650 , height=50)
# 定义下方中心列表区域
self.columns = ("编号" , "患者名" , "性别" , "年龄" , "医生" , "病房" , "病症" , "治疗时间" , "康复时间")
self.tree = ttk.Treeview(self.frame_center , show="headings" , height=18 , columns=self.columns)
self.vbar = ttk.Scrollbar(self.frame_center , orient=VERTICAL , command=self.tree.yview)
# 定义树形结构与滚动条
self.tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.tree.column("编号" , width=60 , anchor='center') # 表示列,不显示
self.tree.column("患者名" , width=80 , anchor='center')
self.tree.column("性别" , width=60 , anchor='center')
self.tree.column("年龄" , width=60 , anchor='center')
self.tree.column("医生" , width=80 , anchor='center')
self.tree.column("病房" , width=80 , anchor='center')
self.tree.column("病症" , width=130 , anchor='center')
self.tree.column("治疗时间" , width=80 , anchor='center')
self.tree.column("康复时间" , width=80 , anchor='center')
# 定义顶部区域
# 定义左上方区域
self.top_title = Label(self.frame_left_top , text="查询患者信息" , bg='forestgreen' , font=('Verdana' , 20))
self.top_title.grid(row=0 , column=0 , columnspan=2 , sticky=NSEW , padx=50 , pady=10)
self.left_top_frame = tk.Frame(self.frame_left_top)
self.var_pname = StringVar() # 声明名字
# 患者名
self.right_top_pname_label = Label(self.frame_left_top , text="姓名:" , font=('Verdana' , 15))
self.right_top_pname_entry = Entry(self.frame_left_top , textvariable=self.var_pname , font=('Verdana' , 15))
self.right_top_pname_label.grid(row=2 , column=0) # 位置设置
self.right_top_pname_entry.grid(row=2 , column=1)
# 定义右上方区域
self.right_top_title = Label(self.frame_right_top , text="操作" , font=('Verdana' , 20))
self.tree.bind('' , self.click) # 左键获取位置
self.right_top_button1 = ttk.Button(self.frame_right_top , text='查询患者信息' , width=20 , command=self.select_row)
self.right_top_button2 = ttk.Button(self.frame_right_top , text='返回患者信息' , width=20 , command=lambda: AdminManage3(self.window))
# 位置设置
self.right_top_title.grid(row=1 , column=0 , pady=10)
self.right_top_button1.grid(row=2 , column=0 , padx=20 , pady=5)
self.right_top_button2.grid(row=3 , column=0 , padx=20 , pady=5)
# 整体区域定位
self.frame_left_top.grid(row=0 , column=0 , padx=2 , pady=5)
self.frame_right_top.grid(row=0 , column=1 , padx=30 , pady=30)
self.frame_center.grid(row=1 , column=0 , columnspan=2 , padx=4 , pady=5)
self.frame_bottom.grid(row=2 , column=0 , columnspan=2)
self.frame_left_top.grid_propagate(0)
self.frame_right_top.grid_propagate(0)
self.frame_center.grid_propagate(0)
self.frame_bottom.grid_propagate(0)
self.frame_left_top.tkraise() # 开始显示主菜单
self.frame_right_top.tkraise() # 开始显示主菜单
self.frame_center.tkraise() # 开始显示主菜单
self.frame_bottom.tkraise() # 开始显示主菜单
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def select_row(self):
# 调用方法获取表格内容插入
self.tree.grid(row=0 , column=0 , sticky=NSEW)
self.vbar.grid(row=0 , column=1 , sticky=NS)
self.pno = []
self.pname = []
self.psex = []
self.page = []
self.dno = []
self.rno = []
self.illness = []
self.startdate = []
self.predictenddate = []
# 打开数据库连接
dbs = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursors = dbs.cursor() # 使用cursor()方法获取操作游标
sqll = "SELECT * FROM patient,doctor WHERE pname= '%s'and patient.dno=doctor.dno" % (self.var_pname.get()) # SQL 连接查询语句
try:
# 执行SQL语句
cursors.execute(sqll)
# 获取所有记录列表
results = cursors.fetchall()
for row in results:
self.pno.append(row[0])
self.pname.append(row[1])
self.psex.append(row[2])
self.page.append(row[3])
self.dno.append(row[4])
self.rno.append(row[5])
self.illness.append(row[6])
self.startdate.append(row[7])
self.predictenddate.append(row[8])
except:
print("Error: unable to fetch data")
messagebox.showinfo('警告!' , '数据库连接失败!')
dbs.close() # 关闭数据库连接
if len(self.pname) == 0:
messagebox.showinfo('警告!' , '查询失败!')
for i in range(
min(len(self.pno) , len(self.pname) , len(self.psex) , len(self.page) , len(self.dno) , len(self.rno) ,
len(self.illness) , len(self.startdate) , len(self.predictenddate))): # 写入数据
self.tree.insert('' , i , values=(
self.pno[i] , self.pname[i] , self.psex[i] , self.page[i] , self.dno[i] , self.rno[i] ,
self.illness[i] ,
self.startdate[i] , self.predictenddate[i]))
for col in self.columns: # 绑定函数,使表头可排序
self.tree.heading(col , text=col , command=lambda _col=col: self.tree_sort_column(self.tree , _col , False))
def back(self):
AdminManage3(self.window) # 显示主窗口 销毁本窗口
def click(self , event):
self.col = self.tree.identify_column(event.x) # 列
self.row = self.tree.identify_row(event.y) # 行
print(self.col) # 列
print(self.row) # 行
self.row_info = self.tree.item(self.row , "values")
self.var_pname.set(self.row_info[1])
self.right_top_pname_entry = Entry(self.frame_left_top , state='disabled' , textvariable=self.var_pname ,
font=('Verdana' , 15))
print('')
# 点击标题进行排列
def tree_sort_column(self , tv , col , reverse): # Treeview、列名、排列方式
l = [(tv.set(k , col) , k) for k in tv.get_children('')]
l.sort(reverse=reverse) # 排序方式
# 在排序位置重新排列项目
for index , (val , k) in enumerate(l): # 根据排序后索引移动
tv.move(k , '' , index)
tv.heading(col , command=lambda: self.tree_sort_column(tv , col , not reverse)) # 重写标题,使之成为再点倒序的标题
# 查询药品
class SelectDrug:
def __init__(self , parent_window):
parent_window.destroy() # 销毁主界面
self.window = Tk() # 初始框的声明
self.window.title('药品资料查询界面')
self.frame_left_top = tk.Frame(width=300 , height=200)
self.frame_right_top = tk.Frame(width=300 , height=200)
self.frame_center = tk.Frame(width=500 , height=100)
self.frame_bottom = tk.Frame(width=650 , height=50)
# 定义下方中心列表区域
self.columns = ("编号" , "药品名" , "产名" , "库存" , "价格")
self.tree = ttk.Treeview(self.frame_center , show="headings" , height=18 , columns=self.columns)
self.vbar = ttk.Scrollbar(self.frame_center , orient=VERTICAL , command=self.tree.yview)
# 定义树形结构与滚动条
self.tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.tree.column("编号" , width=60 , anchor='center') # 表示列,不显示
self.tree.column("药品名" , width=200 , anchor='center')
self.tree.column("产名" , width=90 , anchor='center')
self.tree.column("库存" , width=60 , anchor='center')
self.tree.column("价格" , width=60 , anchor='center')
# 定义顶部区域
# 定义左上方区域
self.top_title = Label(self.frame_left_top , text="查询药品信息" , bg='darkgreen' , font=('Verdana' , 20))
self.top_title.grid(row=0 , column=0 , columnspan=2 , sticky=NSEW , padx=50 , pady=10)
self.left_top_frame = tk.Frame(self.frame_left_top)
self.var_dgname = StringVar() # 声明名字
# 药品名
self.right_top_dgname_label = Label(self.frame_left_top , text="药品名:" , font=('Verdana' , 15))
self.right_top_dgname_entry = Entry(self.frame_left_top , textvariable=self.var_dgname , font=('Verdana' , 15))
self.right_top_dgname_label.grid(row=2 , column=0) # 位置设置
self.right_top_dgname_entry.grid(row=2 , column=1)
# 定义右上方区域
self.right_top_title = Label(self.frame_right_top , text="操作" , font=('Verdana' , 20))
self.tree.bind('' , self.click) # 左键获取位置
self.right_top_button1 = ttk.Button(self.frame_right_top , text='查询药品信息' , width=20 , command=self.select_row)
self.right_top_button2 = ttk.Button(self.frame_right_top , text='返回药品信息' , width=20 , command=lambda: AdminManage4(self.window))
# 位置设置
self.right_top_title.grid(row=1 , column=0 , pady=10)
self.right_top_button1.grid(row=2 , column=0 , padx=20 , pady=5)
self.right_top_button2.grid(row=3 , column=0 , padx=20 , pady=5)
# 整体区域定位
self.frame_left_top.grid(row=0 , column=0 , padx=2 , pady=5)
self.frame_right_top.grid(row=0 , column=1 , padx=30 , pady=30)
self.frame_center.grid(row=1 , column=0 , columnspan=2 , padx=4 , pady=5)
self.frame_bottom.grid(row=2 , column=0 , columnspan=2)
self.frame_left_top.grid_propagate(0)
self.frame_right_top.grid_propagate(0)
self.frame_center.grid_propagate(0)
self.frame_bottom.grid_propagate(0)
self.frame_left_top.tkraise() # 开始显示主菜单
self.frame_right_top.tkraise() # 开始显示主菜单
self.frame_center.tkraise() # 开始显示主菜单
self.frame_bottom.tkraise() # 开始显示主菜单
self.window.protocol("WM_DELETE_WINDOW" , self.back) # 捕捉右上角关闭点击
self.window.mainloop() # 进入消息循环
def select_row(self):
# 调用方法获取表格内容插入
self.tree.grid(row=0 , column=0 , sticky=NSEW)
self.vbar.grid(row=0 , column=1 , sticky=NS)
self.dgno = []
self.dgname = []
self.dgpro = []
self.dgnum = []
self.dgprice = []
# 打开数据库连接
dbs = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8'
)
cursors = dbs.cursor() # 使用cursor()方法获取操作游标
sqll = "SELECT * FROM drug WHERE dgname= '%s'" % (self.var_dgname.get()) # SQL 查询语句
try:
# 执行SQL语句
cursors.execute(sqll)
# 获取所有记录列表
results = cursors.fetchall()
for row in results:
self.dgno.append(row[0])
self.dgname.append(row[1])
self.dgpro.append(row[2])
self.dgnum.append(row[3])
self.dgprice.append(row[4])
except:
print("Error: unable to fetch data")
messagebox.showinfo('警告!' , '数据库连接失败!')
dbs.close() # 关闭数据库连接
if len(self.dgname) == 0:
messagebox.showinfo('警告!' , '查询失败!')
for i in range(
min(len(self.dgno) , len(self.dgname) , len(self.dgpro) , len(self.dgnum) , len(self.dgprice))): # 写入数据
self.tree.insert('' , i ,
values=(self.dgno[i] , self.dgname[i] , self.dgpro[i] , self.dgnum[i] , self.dgprice[i]))
for col in self.columns: # 绑定函数,使表头可排序
self.tree.heading(col , text=col , command=lambda _col=col: self.tree_sort_column(self.tree , _col , False))
def back(self):
AdminManage4(self.window) # 显示主窗口 销毁本窗口
def click(self , event):
self.col = self.tree.identify_column(event.x) # 列
self.row = self.tree.identify_row(event.y) # 行
print(self.col) # 列
print(self.row) # 行
self.row_info = self.tree.item(self.row , "values")
self.var_dgname.set(self.row_info[1])
self.right_top_dgname_entry = Entry(self.frame_left_top , state='disabled' , textvariable=self.var_dgname ,
font=('Verdana' , 15))
print('')
# 点击标题进行排列
def tree_sort_column(self , tv , col , reverse): # Treeview、列名、排列方式
l = [(tv.set(k , col) , k) for k in tv.get_children('')]
l.sort(reverse=reverse) # 排序方式
# 在排序位置重新排列项目
for index , (val , k) in enumerate(l): # 根据排序后索引移动
tv.move(k , '' , index)
tv.heading(col , command=lambda: self.tree_sort_column(tv , col , not reverse)) # 重写标题,使之成为再点倒序的标题
if __name__ == '__main__':
try:
# 打开数据库连接 连接测试
db = connect = pymysql.Connect(
host='localhost' ,
port=3306 ,
user='root' ,
passwd='wjj1546314877' ,
db='hospital' ,
charset='utf8' ,
)
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# 如果数据表不存在则创建表 若存在则跳过
# 设置主键唯一
sql = """
CREATE TABLE IF NOT EXISTS department(
dpname char(10) NOT NULL,
dpno char(1) NOT NULL,
dpadr char(20) default NULL,
dptel char(20) default NULL,
PRIMARY KEY (dpname)
) ENGINE = InnoDB
"""
cursor.execute(sql)
# 如果数据表不存在则创建表 若存在则跳过
sql = """
CREATE TABLE IF NOT EXISTS admin_login_k(
admin_id char(20) NOT NULL,
admin_pass char(20) default NULL,
PRIMARY KEY (admin_id)
) ENGINE = InnoDB
"""
cursor.execute(sql)
# 如果数据表不存在则创建表 若存在则跳过
sql = """
CREATE TABLE IF NOT EXISTS stu_login_k(
stu_id char(20) NOT NULL,
stu_pass char(20) default NULL,
PRIMARY KEY (stu_id)
) ENGINE = InnoDB
"""
cursor.execute(sql)
# 关闭数据库连接
db.close()
# 实例化Application
window = tk.Tk()
StartPage(window)
except:
messagebox.showinfo('错误!' , '连接数据库失败!')
about.png
gongneng.png
img3.png
登录.png
create schema hospital;
use hospital;
CREATE TABLE IF NOT EXISTS stu_login_k
(
stu_id char(20) NOT NULL,
stu_pass char(20) default NULL,
PRIMARY KEY (stu_id)
) ENGINE = InnoDB;
insert into stu_login_k values("1","123"),
("2","123"),
("3","123"),
("4","123"),
("5","123"),
("6","123"),
("7","123"),
("8","123"),
("9","123");
CREATE TABLE IF NOT EXISTS admin_login_k
(
admin_id char(20) NOT NULL,
admin_pass char(20) default NULL,
PRIMARY KEY (admin_id)
) ENGINE = InnoDB;
insert into admin_login_k values("root","wjj1546314877");
CREATE TABLE IF NOT EXISTS h
(
id char(20) NOT NULL,
hpname char(20) default NULL,
hos char(20),
hadr char(20),
htel char(20),
PRIMARY KEY (id)
) ENGINE = InnoDB;
insert into h values("1","哈尔滨工程大学医院","王长信","哈尔滨工程大学十公寓627","19995725990");
CREATE TABLE IF NOT EXISTS department
(
dpname char(10) NOT NULL,
dpno char(2) NOT NULL,
dpadr char(20) default NULL,
dptel char(20) default NULL,
PRIMARY KEY (dpno),
KEY key_dpno (dpno)
) ENGINE = InnoDB;
insert into department values("内科","01","一号楼514","04512340987"),
("外科","02","二号楼202","04514521234"),
("妇科","03","一号楼421","04510987654"),
("儿科","04","三号楼628","04511234567"),
("神经科","05","一号楼555","04519283746"),
("精神科","06","隔离所一栋01","04510987890"),
("五官科","07","三号楼101","04511029281"),
("放射线科","08","隔离所二栋11","04518888888"),
("检验科","09","二号楼456","04518787878");
create table nurse
(
nno char(2) primary key ,
nname char(10) unique ,
nsex char(1),
nage int,
KEY key_nno (nno)
);
insert into nurse values ("01","黎晓蓓",'女',21),
("02","闫春竹",'女',22),
("03","马琳",'女',23),
("04","苏诗文",'女',34),
("05","刘颖",'女',23),
("06","卿菲雨",'女',31),
("07","徐龙",'男',20),
("08","曲芊羽",'女',19);
create table drug
(
dgno char(4) primary key ,
dgname char(20),
dgpro char(20),
dgnum int check(dgnum>=0),
dgprice int check(dgprice>=0),
KEY key_dgno (dgno)
);
insert into drug values("0001","注射用苄星青霉素","哈尔滨制药厂",123,24),
("0002","三磷酸腺苷二钠","长春制药厂",213,34),
("0003","复方氨林巴比妥注射液","沈阳制药厂",121,25),
("0004","精蛋白生物合成人胰岛素注射液","北京制药厂",123,214),
("0005","胞磷胆碱钠","上海制药厂",1010,28),
("0006","艾司唑仑","广州制药厂",132,124),
("0007","头孢氨苄","哈尔滨制药厂",12,43),
("0008","异烟肼","长春制药厂",153,34),
("0009","去乙酰毛花苷","北京制药厂",53,123),
("0010","盐酸氟桂利嗪","广州制药厂",12,342),
("0011","甲氰咪呱","哈尔滨制药厂",32,102),
("0012","甲硫咪唑","广州制药厂",32,34),
("0013","丁胺卡那霉素","广州制药厂",12,240),
("0014","硝酸异山梨酯","哈尔滨制药厂",123,234),
("0015","多潘立酮","长春制药厂",143,535),
("0016","硫酸沙丁胺醇","北京制药厂",354,23),
("0017","喷托维林","广州制药厂",3242,534),
("0018","枸橼酸氯米芬","哈尔滨制药厂",544,53),
("0019","枸橼酸他莫昔芬","广州制药厂",233,465),
("0020","血塞通注射液","广州制药厂",532,42),
("0021","注射用头孢替唑钠","哈尔滨制药厂",1232,23),
("0022","注射用盐酸头孢替安","长春制药厂",124,27),
("0023","复方愈创木酚磺酸钾口服溶液","北京制药厂",1344,23),
("0024","克林霉素","广州制药厂",113,223),
("0025","盐酸胺碘酮","哈尔滨制药厂",132,26),
("0026","拉米夫定","广州制药厂",1030,23),
("0027","头孢克肟颗粒","广州制药厂",1040,16),
("0028","氟哌噻吨美利曲辛片","哈尔滨制药厂",123,53),
("0029","盐酸克林霉素棕榈酸酯分散片","广州制药厂",135,53);
create table doctor
(
dno char(3) primary key,
dname char(20),
duty char(20),
dsex char(2),
dage int check (dage>=0 and dage <=150),
dpno char(2),
foreign key (dpno) references department (dpno),
KEY key_dno (dno)
) ENGINE = InnoDB;
insert into doctor values ("101","李小明","中级医师","男",18,"01"),
("102","赵二猫","正高级医师","男",56,"01"),
("103","陈仁义","初级医师","女",20,"01"),
("201","陈省","初级医师","女",21,"02"),
("202","王雪清","副高级医师","女",32,"02"),
("203","赵彩结","正高级医师","女",50,"02"),
("301","王鹤男","中级医师","女",20,"03"),
("302","王风","初级医师","女",31,"03"),
("303","李文革","正高级医师","女",51,"03"),
("401","钱求和","初级医师","女",24,"04"),
("402","陈少杰","中级医师","男",26,"04"),
("403","拉普拉斯","正高级医师","男",59,"04"),
("501","赵意识","初级医师","女",31,"05"),
("502","陈打野","中级医师","男",29,"05"),
("503","欧上路","初级医师","男",31,"05"),
("601","陈小希","初级医师","女",51,"06"),
("602","陈欧皇","中级医师","男",29,"06"),
("603","傅杰","副高级医师","女",46,"06"),
("701","赵梦啥","初级医师","男",59,"07"),
("702","王来文","正高级医师","男",32,"07"),
("703","傅出","副高级医师","女",42,"07"),
("801","王疯子","初级医师","女",21,"08"),
("802","武曌","中级医师","男",25,"08"),
("803","蔡子杰","初级医师","女",21,"08"),
("901","谢好看","初级医师","女",21,"09"),
("902","陈真帅","中级医师","男",20,"09"),
("903","王猛","初级医师","男",21,"09");
create table room
(
rno char(10) primary key ,
radr char(20) unique,
dpno char(5),
foreign key (dpno) references department(dpno)
);
insert into room values ("1101","一号楼101","01"),
("1102","一号楼102","01"),
("1103","一号楼103","01"),
("2101","二号楼101","02"),
("2102","二号楼102","02"),
("2103","二号楼103","02"),
("1401","一号楼401","03"),
("1402","一号楼402","03"),
("1403","一号楼403","03"),
("1104","一号楼104","04"),
("1105","一号楼105","05"),
("1106","一号楼106","06"),
("1407","一号楼407","07"),
("1408","一号楼408","08"),
("1409","一号楼409","09");
create table patient
(
pno char(20) primary key,
pname char(20) not null,
psex char(2),
page int check (page>=0 and page <=150),
dno char(3),
rno char(10),
illness char(20),
startdate date,
predictenddate date,
foreign key (dno) references doctor(dno),
foreign key (rno) references room(rno),
KEY key_pno (pno)
);
insert into patient values ("0001","赵一","男",20,"101","1101","左脚踝粉碎性骨折","2019-12-20","2020-01-28"),
("0002","赵二","男",21,"101","1101","右脚踝粉碎性骨折","2018-11-20","2019-12-8"),
("0003","钱二","女",23,"201","2102","内出血","2018-11-22","2018-12-29"),
("0004","竹三","女",19,"301","1401","妇科炎症","2018-12-22","2018-12-23"),
("0005","李来武","男",6,"401","1104","多种抽动综合征","2018-11-10","2019-01-01"),
("0006","王系民","男",52,"501","1105","帕金森综合征","2018-11-24","2018-12-25"),
("0007","陈来文","女",54,"601","1106","强迫症","2018-12-15","2018-12-23"),
("0008","代乘一","男",22,"701","1407","额骨骨髓炎","2018-12-24","2018-12-25"),
("0009","高来基","女",34,"801","1408","核磁共振检测","2018-12-23","2018-12-26"),
("0010","吴总会","女",43,"901","1409","艾滋病检测","2018-12-22","2018-12-27"),
("0011","曹文龙","男",32,"102","1102","锁骨粉碎性骨折","2018-12-21","2019-01-25"),
("0012","陈高轶","男",26,"202","2102","呼吸不畅","2018-12-19","2019-01-26"),
("0013","陈温暖","男",29,"302","1401","子宫内膜炎","2018-12-18","2019-01-24"),
("0014","牛群","女",3,"402","1104","结节性硬化","2018-12-17","2019-01-27"),
("0015","李晶晶","女",61,"502","1105","老年性痴呆","2018-12-16","2019-01-28"),
("0016","李沁颍","男",23,"602","1106","抑郁症","2018-12-15","2019-01-26"),
("0017","刘馨雨","女",21,"702","1407","海绵窦血栓性静脉炎","2018-12-14","2019-01-25"),
("0018","方子健","男",34,"802","1408","数字减影血管造影检测","2018-12-13","2019-01-26"),
("0019","林威良","男",43,"902","1409","血液白细胞检测","2018-12-12","2019-01-24"),
("0020","王恩琦","女",27,"103","1101","手指粉碎性骨折","2018-12-12","2019-01-26"),
("0021","臧庆良","男",26,"203","2102","消化不良","2018-12-21","2019-01-29"),
("0022","李欢欢","女",18,"303","1401","盆腔炎","2018-12-22","2019-01-31"),
("0023","欧俊","男",6,"403","1104","小儿高热","2018-12-21","2019-01-30"),
("0024","全淑敏","男",43,"503","1105","孤独症","2018-12-22","2019-01-01"),
("0025","龚敬博","男",51,"603","1106","抑郁性神经症","2018-12-24","2019-01-22"),
("0026","代除一","女",21,"703","1407","球后视神经炎","2018-12-23","2019-01-23"),
("0027","郝凡","女",22,"803","1408","计算机X光检测","2018-12-22","2018-12-28"),
("0028","黎小蓓","女",21,"903","1409","血液常规检查","2018-12-21","2018-12-22");
create table PN
(
pno char(20),
nno char(2),
content char(20),
time datetime,
foreign key (pno) references patient(pno),
foreign key (nno) references nurse(nno)
);
insert into PN values ("0001","01","康复治疗1","2018-12-22 13:12:11"),
("0002","02","康复治疗2","2018-12-23 15:12:22"),
("0003","03","康复治疗3","2018-12-22 13:34:02"),
("0004","04","康复治疗4","2018-12-23 14:32:23"),
("0005","05","康复治疗1","2018-12-22 15:14:11"),
("0006","06","康复治疗2","2018-12-23 16:14:11"),
("0007","07","康复治疗3","2018-12-24 17:13:11"),
("0008","08","康复治疗4","2018-12-24 18:14:11"),
("0009","01","换药1","2018-12-22 19:27:21"),
("0001","02","换药2","2018-12-23 12:16:14"),
("0002","03","换药1","2018-12-26 13:15:15"),
("0003","04","换药1","2018-12-23 14:11:15"),
("0001","05","换药3","2018-12-24 15:42:16"),
("0002","06","换药2","2018-12-22 16:24:17"),
("0003","07","换药2","2018-12-23 17:14:18"),
("0004","08","康复治疗1","2018-12-26 18:25:43"),
("0005","01","康复治疗2","2018-12-24 19:52:12"),
("0006","02","康复治疗3","2018-12-22 20:15:45"),
("0007","03","康复治疗4","2018-12-24 21:43:34"),
("0008","04","康复治疗5","2018-12-24 22:32:42"),
("0009","05","康复治疗6","2018-12-22 23:23:24"),
("0001","06","康复治疗7","2018-12-24 00:12:31"),
("0005","07","康复治疗8","2018-12-25 01:53:41"),
("0004","08","康复治疗9","2018-12-23 02:32:42");
create table PD
(
dgno char(4),
pno char(4),
num int check(num>=0),
foreign key (dgno) references drug(dgno),
foreign key (pno) references patient(pno),
primary key (dgno,pno)
);
insert into PD values ("0001","0001",1),
("0002","0001",2),
("0001","0002",3),
("0003","0001",1),
("0004","0002",2),
("0005","0001",3),
("0004","0003",1),
("0011","0003",2),
("0005","0004",3),
("0011","0022",1),
("0012","0022",2),
("0023","0013",3),
("0023","0024",1),
("0014","0022",2),
("0015","0001",3),
("0014","0002",1),
("0021","0003",2),
("0025","0004",3),
("0021","0001",1),
("0022","0001",2),
("0021","0002",3),
("0023","0003",1),
("0024","0004",2),
("0025","0005",3),
("0024","0011",1),
("0021","0021",2),
("0025","0020",3),
("0011","0019",1),
("0022","0018",2),
("0001","0017",3),
("0003","0016",1),
("0024","0015",2),
("0015","0014",3),
("0014","0013",1),
("0021","0012",2),
("0015","0011",3),
("0006","0005",1),
("0007","0005",2),
("0008","0005",3),
("0009","0005",1),
("0010","0006",2),
("0016","0006",3),
("0017","0006",1),
("0018","0006",2),
("0019","0007",3),
("0005","0007",1),
("0025","0007",2),
("0023","0007",3),
("0024","0007",1),
("0021","0008",2),
("0028","0008",3),
("0002","0008",1),
("0001","0008",2),
("0025","0009",3),
("0011","0009",1),
("0022","0010",2),
("0001","0010",3),
("0003","0010",1),
("0024","0023",2),
("0015","0025",3),
("0014","0026",1),
("0021","0027",2),
("0013","0027",3),
("0020","0021",1),
("0007","0018",2),
("0020","0018",3);
delimiter //
create procedure sl_drug_patient(in ppno char(4))
begin
select pname 患者姓名,illness 病症,dgname 药物名,num 数量
from patient,drug,PD
where patient.pno = pd.pno
and drug.dgno = pd.dgno
and pd.pno = ppno;
end;
call sl_drug_patient("0001");
create procedure sl_doctor(in ppno char(4))
begin
select doctor.dname 医生姓名,doctor.duty 职务,dpname 科室名 from doctor,department
where department.dpno = doctor.dpno
and dno in
(select dno from patient
where ppno = pno);
end;
call sl_doctor("0001");
create procedure sl_department(in ddno char(4))
begin
select dname 医生姓名,dpname 科室名
from department,doctor
where department.dpno = doctor.dpno
and doctor.dno = ddno;
end;
call sl_department("302");
create procedure sl_room(in ddpno char(1))
begin
select dpname 科室名,rno 病房编号,radr 病房地址
from room,department
where ddpno = room.dpno
and room.dpno = department.dpno;
end;
call sl_room("1");
create procedure sl_money(in ppno char(4))
begin
select sum(num * dgprice) 应缴金额
from pd,patient,drug
where pd.pno = patient.pno
and drug.dgno = pd.dgno
and patient.pno = ppno;
end;
call sl_money("0023");
create procedure sl_doctor_patientnum(in ddno char(4))
begin
select count(*) 医生主治的患者数量 from patient
where patient.dno = ddno;
end;
call sl_doctor_patientnum("102");
create procedure sl_department_patientnum(in ddpno char(1))
begin
select count(*) 科室患者数 from patient,doctor,department
where patient.dno = doctor.dno
and department.dpno = doctor.dpno
and ddpno = department.dpno ;
end;
call sl_department_patientnum("2");
create procedure sl_department_patientname(in ddpno char(1))
begin
select pname 患者名,patient.pno 患者编号,dname 主治医师姓名,doctor.dno 主治医师编号
from patient,doctor,department
where patient.dno = doctor.dno
and department.dpno = doctor.dpno
and ddpno = department.dpno ;
end;
call sl_department_patientname("1");
create procedure sl_nurse(in nnno char(2))
begin
select nno 护士编号,nname 护士姓名 from nurse
where nno = nnno;
end;
call sl_nurse("05");
create procedure sl_patient_nurse(in ppno char(4))
begin
select pname,illness,content,time,nname
from nurse,patient,pn
where nurse.nno = pn.nno
and patient.pno = pn.pno
and patient.pno = ppno;
end;
call sl_patient_nurse("0002");
create procedure sl_patient_one_room(in ppno char(4))
begin
select A.pname,A.pno from patient A
where rno in
(select B.rno from patient B
where B.pno=ppno);
end;
call sl_patient_one_room("0002");
create procedure sl_room_patient(in rrno char(4))
begin
select pno,pname from patient
where rno = rrno;
end;
call sl_room_patient("1407");
create procedure del_patient(in ppno char(4))
begin
delete from PD where ppno = PD.pno;
delete from patient where ppno = patient.pno;
end;
call del_patient("0027");
create procedure del_drug(in ddgno char(4))
begin
delete from PD where ddgno = PD.dgno;
delete from drug where ddgno = drug.dgno;
end;
call del_drug("0029");
create view vadmin_login_k as select * from admin_login_k;
create view vstu_login_k as select * from stu_login_k;
create view vdepartment as select * from department;
create view vdoctor as select * from doctor;
create view vdrug as select * from drug;
create view vnurse as select * from nurse;
create view vpd as select * from pd;
create view as select * from pn;
create view vroom as select * from room;
create view vh as select * from h;
create view vpatient as select * from patient;
CREATE TRIGGER chufa
AFTER DELETE ON pd FOR EACH ROW
BEGIN
delete from drug where dgno=old.dgno;
END
登录页面:
功能选择页面:
插入操作:
查询操作:
希望大家都能一次性跑成功 ~ ~ ~