You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

551 lines
22 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import tkinter as tk
import pymysql
conn = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',password='',
database='dzy',
charset='utf8',
autocommit=True)
cursor=conn.cursor()
window=tk.Tk()
window.title('登录界面')
window.geometry('450x150')
tk.Label(window,text='用户名:').place(x=50,y=20)
tk.Label(window,text='密码:').place(x=50,y=60)
var_usr_name=tk.StringVar()
var_usr_name.set('123123')
entry_user_name=tk.Entry(window,textvariable=var_usr_name)
entry_user_name.place(x=160,y=20)
var_usr_pwd=tk.StringVar()
entry_user_pwd=tk.Entry(window,textvariable=var_usr_pwd,show='*')
entry_user_pwd.place(x=160,y=60)
r_name=tk.StringVar()
r_info=tk.StringVar()
def change_com():
window3=tk.Toplevel()
window3.title('修改社区信息')
window3.geometry('600x300')
ori_name=r_name.get()
tk.Label(window3,text='社区名称:').place(x=50,y=100)
tk.Label(window3,text='社区简介:').place(x=50,y=200)
entry1=tk.Entry(window3,textvariable=r_name)
entry1.place(x=100,y=100)
entry2=tk.Entry(window3,textvariable=r_info)
entry2.place(x=100,y=200)
btn_confirm=tk.Button(window3,text='确认',command=lambda:confirm_change_com(window3,ori_name))
btn_confirm.place(x=200,y=250)
btn_cancel=tk.Button(window3,text='取消',command=lambda:cancel(window3))
btn_cancel.place(x=400,y=250)
def confirm_change(window0,ori_name):
sql="update residence_community set res_name='%s',res_infor='%s' where res_name='%s'"%(r_name.get(),r_info.get(),ori_name)
cursor.execute(sql)
conn.commit()
window0.destroy()
def cancel(window0):
window0.destroy()
def change_res():
window3=tk.Toplevel()
window3.title('修改小区信息')
window3.geometry('600x300')
ori_name=r_name.get()
tk.Label(window3,text='小区名称:').place(x=50,y=100)
tk.Label(window3,text='小区简介:').place(x=50,y=200)
entry1=tk.Entry(window3,textvariable=r_name)
entry1.place(x=100,y=100)
entry2=tk.Entry(window3,textvariable=r_info)
entry2.place(x=100,y=200)
btn_confirm=tk.Button(window3,text='确认',command=lambda:confirm_change(window3,ori_name))
btn_confirm.place(x=200,y=250)
btn_cancel=tk.Button(window3,text='取消',command=lambda:cancel(window3))
btn_cancel.place(x=400,y=250)
def change_hos():
window3=tk.Toplevel()
window3.title('修改医院信息')
window3.geometry('600x300')
ori_name=r_name.get()
tk.Label(window3,text='医院名称:').place(x=50,y=100)
tk.Label(window3,text='医院简介:').place(x=50,y=200)
entry1=tk.Entry(window3,textvariable=r_name)
entry1.place(x=100,y=100)
entry2=tk.Entry(window3,textvariable=r_info)
entry2.place(x=100,y=200)
btn_confirm=tk.Button(window3,text='确认',command=lambda:confirm_change_hos(window3,ori_name))
btn_confirm.place(x=200,y=250)
btn_cancel=tk.Button(window3,text='取消',command=lambda:cancel(window3))
btn_cancel.place(x=400,y=250)
def confirm_change_hos(window0,ori_name):
sql="update hospital set hos_name='%s',hos_infor='%s' where hos_name='%s'"%(r_name.get(),r_info.get(),ori_name)
cursor.execute(sql)
conn.commit()
window0.destroy()
def change_owner(listbox):
info=listbox.get(listbox.curselection())
info=info.split()
window4=tk.Toplevel()
window4.title('修改业主信息')
window4.geometry('400x300')
var_1=tk.StringVar()
var_1.set(info[0])
tk.Label(window4,text='身份证号').place(x=20,y=20)
entry_1=tk.Entry(window4,textvariable=var_1)
entry_1.place(x=100,y=20)
var_2=tk.StringVar()
var_2.set(info[1])
tk.Label(window4,text='姓名').place(x=20,y=40)
entry_2=tk.Entry(window4,textvariable=var_2)
entry_2.place(x=100,y=40)
var_3=tk.StringVar()
var_3.set(info[2])
tk.Label(window4,text='性别').place(x=20,y=60)
entry_3=tk.Entry(window4,textvariable=var_3)
entry_3.place(x=100,y=60)
var_4=tk.StringVar()
var_4.set(info[3])
tk.Label(window4,text='电话号码').place(x=20,y=80)
entry_4=tk.Entry(window4,textvariable=var_4)
entry_4.place(x=100,y=80)
var_5=tk.StringVar()
var_5.set(info[4])
tk.Label(window4,text='生日').place(x=20,y=100)
entry_5=tk.Entry(window4,textvariable=var_5)
entry_5.place(x=100,y=100)
var_6=tk.StringVar()
var_6.set(info[6])
tk.Label(window4,text='单元').place(x=20,y=120)
entry_6=tk.Entry(window4,textvariable=var_6)
entry_6.place(x=100,y=120)
var_7=tk.StringVar()
var_7.set(info[7])
tk.Label(window4,text='楼号').place(x=20,y=140)
entry_7=tk.Entry(window4,textvariable=var_7)
entry_7.place(x=100,y=140)
var_8=tk.StringVar()
var_8.set(info[8])
tk.Label(window4,text='门牌').place(x=20,y=160)
entry_8=tk.Entry(window4,textvariable=var_8)
entry_8.place(x=100,y=160)
btn_conf=tk.Button(window4,text='确认修改',command=lambda :confirm_change_owner(info,var_1,var_2,var_3,var_4,var_5,var_6,var_7,var_8,window4,listbox))
btn_conf.place(x=150,y=200)
btn_canc=tk.Button(window4,text='取消',command=lambda:cancel(window4))
btn_canc.place(x=250,y=200)
def change_patient(listbox):
info=listbox.get(listbox.curselection())
info=info.split()
window4=tk.Toplevel()
window4.title('修改病人信息')
window4.geometry('400x300')
var_1=tk.StringVar()
var_1.set(info[2])
tk.Label(window4,text='姓名').place(x=20,y=20)
entry_1=tk.Entry(window4,textvariable=var_1)
entry_1.place(x=100,y=20)
var_2=tk.StringVar()
var_2.set(info[3])
tk.Label(window4,text='性别').place(x=20,y=40)
entry_2=tk.Entry(window4,textvariable=var_2)
entry_2.place(x=100,y=40)
var_3=tk.StringVar()
var_3.set(info[4])
tk.Label(window4,text='电话号码').place(x=20,y=60)
entry_3=tk.Entry(window4,textvariable=var_3)
entry_3.place(x=100,y=60)
var_4=tk.StringVar()
var_4.set(info[5])
tk.Label(window4,text='住院时间').place(x=20,y=80)
entry_4=tk.Entry(window4,textvariable=var_4)
entry_4.place(x=100,y=80)
var_5=tk.StringVar()
var_5.set(info[6])
tk.Label(window4,text='出院时间').place(x=20,y=100)
entry_5=tk.Entry(window4,textvariable=var_5)
entry_5.place(x=100,y=100)
var_6=tk.StringVar()
var_6.set(info[7])
tk.Label(window4,text='现状').place(x=20,y=120)
entry_6=tk.Entry(window4,textvariable=var_6)
entry_6.place(x=100,y=120)
var_7=tk.StringVar()
var_7.set(info[1])
tk.Label(window4,text='编号').place(x=20,y=140)
entry_7=tk.Entry(window4,textvariable=var_7)
entry_7.place(x=100,y=140)
btn_conf=tk.Button(window4,text='确认修改',command=lambda :confirm_change_patient(info,var_1,var_2,var_3,var_4,var_5,var_6,var_7,window4,listbox))
btn_conf.place(x=150,y=200)
btn_canc=tk.Button(window4,text='取消',command=lambda:cancel(window4))
btn_canc.place(x=250,y=200)
def confirm_change_patient(info,var_1,var_2,var_3,var_4,var_5,var_6,var_7,windoww,listbox):
sql="update patient set pat_nums='{}',pat_name='{}',sex='{}',pho_nums='{}',in_time='{}',out_time='{}',situation='{}' where pat_nums='{}' and hos_nums='{}'".format(var_7.get(),var_1.get(),var_2.get(),var_3.get(),var_4.get(),var_5.get(),var_6.get(),info[1],info[0])
cursor.execute(sql)
listbox.delete(tk.ACTIVE)
new_item=[info[0],var_7.get(),var_1.get(),var_2.get(),var_3.get(),var_4.get(),var_5.get(),var_6.get()]
new_item=' '.join(new_item)
listbox.insert('end',new_item)
windoww.destroy()
def delete_owner(listbox):
info=listbox.get(listbox.curselection())
info=info.split()
sql="delete from owner where id='{}'".format(info[0])
cursor.execute(sql)
listbox.delete(tk.ACTIVE)
def delete_patient(listbox):
info=listbox.get(listbox.curselection())
info=info.split()
sql="delete from patient where pat_nums='{}'".format(info[2])
cursor.execute(sql)
listbox.delete(tk.ACTIVE)
def add_patient(listbox,hos_nums):
window4=tk.Toplevel()
window4.title('添加病人信息')
window4.geometry('400x300')
var_1=tk.StringVar()
tk.Label(window4,text='病人编号').place(x=20,y=20)
entry_1=tk.Entry(window4,textvariable=var_1)
entry_1.place(x=100,y=20)
var_2=tk.StringVar()
tk.Label(window4,text='姓名').place(x=20,y=40)
entry_2=tk.Entry(window4,textvariable=var_2)
entry_2.place(x=100,y=40)
var_3=tk.StringVar()
tk.Label(window4,text='性别').place(x=20,y=60)
entry_3=tk.Entry(window4,textvariable=var_3)
entry_3.place(x=100,y=60)
var_4=tk.StringVar()
tk.Label(window4,text='电话号码').place(x=20,y=80)
entry_4=tk.Entry(window4,textvariable=var_4)
entry_4.place(x=100,y=80)
var_5=tk.StringVar()
tk.Label(window4,text='住院时间').place(x=20,y=100)
entry_5=tk.Entry(window4,textvariable=var_5)
entry_5.place(x=100,y=100)
var_6=tk.StringVar()
tk.Label(window4,text='出院时间').place(x=20,y=120)
entry_6=tk.Entry(window4,textvariable=var_6)
entry_6.place(x=100,y=120)
var_7=tk.StringVar()
tk.Label(window4,text='现状').place(x=20,y=140)
entry_7=tk.Entry(window4,textvariable=var_7)
entry_7.place(x=100,y=140)
btn_conf=tk.Button(window4,text='确认添加',command=lambda :confirm_add_patient(var_1,var_2,var_3,var_4,var_5,var_6,var_7,window4,hos_nums,listbox))
btn_conf.place(x=150,y=200)
btn_canc=tk.Button(window4,text='取消',command=lambda:cancel(window4))
btn_canc.place(x=250,y=200)
def add_owner(listbox,res_nums):
window4=tk.Toplevel()
window4.title('添加业主信息')
window4.geometry('400x300')
var_1=tk.StringVar()
tk.Label(window4,text='身份证号').place(x=20,y=20)
entry_1=tk.Entry(window4,textvariable=var_1)
entry_1.place(x=100,y=20)
var_2=tk.StringVar()
tk.Label(window4,text='姓名').place(x=20,y=40)
entry_2=tk.Entry(window4,textvariable=var_2)
entry_2.place(x=100,y=40)
var_3=tk.StringVar()
tk.Label(window4,text='性别').place(x=20,y=60)
entry_3=tk.Entry(window4,textvariable=var_3)
entry_3.place(x=100,y=60)
var_4=tk.StringVar()
tk.Label(window4,text='电话号码').place(x=20,y=80)
entry_4=tk.Entry(window4,textvariable=var_4)
entry_4.place(x=100,y=80)
var_5=tk.StringVar()
tk.Label(window4,text='生日').place(x=20,y=100)
entry_5=tk.Entry(window4,textvariable=var_5)
entry_5.place(x=100,y=100)
var_6=tk.StringVar()
tk.Label(window4,text='单元').place(x=20,y=120)
entry_6=tk.Entry(window4,textvariable=var_6)
entry_6.place(x=100,y=120)
var_7=tk.StringVar()
tk.Label(window4,text='楼号').place(x=20,y=140)
entry_7=tk.Entry(window4,textvariable=var_7)
entry_7.place(x=100,y=140)
var_8=tk.StringVar()
tk.Label(window4,text='门牌').place(x=20,y=160)
entry_8=tk.Entry(window4,textvariable=var_8)
entry_8.place(x=100,y=160)
btn_conf=tk.Button(window4,text='确认添加',command=lambda :confirm_add_owner(var_1,var_2,var_3,var_4,var_5,var_6,var_7,var_8,window4,res_nums,listbox))
btn_conf.place(x=150,y=200)
btn_canc=tk.Button(window4,text='取消',command=lambda:cancel(window4))
btn_canc.place(x=250,y=200)
def confirm_change_owner(info,var_1,var_2,var_3,var_4,var_5,var_6,var_7,var_8,windoww,listbox):
sql="update owner set id='{}',name='{}',sex='{}',pho_nums='{}',birth_days='{}',unit='{}',floor='{}',door_nums='{}' where id='{}'".format(var_1.get(),var_2.get(),var_3.get(),var_4.get(),var_5.get(),var_6.get(),var_7.get(),var_8.get(),info[0])
cursor.execute(sql)
listbox.delete(tk.ACTIVE)
new_item=[var_1.get(),var_2.get(),var_3.get(),var_4.get(),var_5.get(),info[5],var_6.get(),var_7.get(),var_8.get()]
new_item=' '.join(new_item)
listbox.insert('end',new_item)
windoww.destroy()
def confirm_add_owner(var_1,var_2,var_3,var_4,var_5,var_6,var_7,var_8,windoww,res_nums,listbox):
sql="insert into owner values('{}','{}','{}','{}','{}','{}','{}','{}','{}')".format(var_1.get(),var_2.get(),var_3.get(),var_4.get(),var_5.get(),res_nums,var_6.get(),var_7.get(),var_8.get())
cursor.execute(sql)
a=[var_1.get(),var_2.get(),var_3.get(),var_4.get(),var_5.get(),res_nums,var_6.get(),var_7.get(),var_8.get()]
x=' '.join(a)
listbox.insert('end',x)
windoww.destroy()
def confirm_add_patient(var_1,var_2,var_3,var_4,var_5,var_6,var_7,windoww,hos_nums,listbox):
sql="insert into patient values('{}','{}','{}','{}','{}','{}','{}','{}')".format(hos_nums,var_1.get(),var_2.get(),var_3.get(),var_4.get(),var_5.get(),var_6.get(),var_7.get())
cursor.execute(sql)
a=[hos_nums,var_1.get(),var_2.get(),var_3.get(),var_4.get(),var_5.get(),var_6.get(),var_7.get()]
x=' '.join(a)
listbox.insert('end',x)
windoww.destroy()
def confirm_change_com(window0,ori_name):
sql="update community set com_name='%s',com_infor='%s' where com_name='%s'"%(r_name.get(),r_info.get(),ori_name)
cursor.execute(sql)
conn.commit()
window0.destroy()
def search(var_type,var_info):
t=var_type.get()
info=var_info.get()
if t=='医院':
sql='select * from hospital where hos_nums = "%s" ' % (info)
elif t=='病人':
info=info.split(',')
sql='select * from patient where hos_nums = "%s" and pat_nums="%s"' % (info[0],info[1])
elif t=='小区':
sql='select * from residence_community where res_nums = "%s" ' % (info)
elif t=='业主':
sql='select * from owner where name = "%s" ' % (info)
res=cursor.execute(sql)
if res==0:
tk.messagebox.showinfo(title='查询结果',message='未查询到相关信息')
else:
result=cursor.fetchall()
tk.messagebox.showinfo(title='查询结果',message=str(result))
def usr_login():
name=var_usr_name.get()
pwd=var_usr_pwd.get()
sql='select * from worker where name = "%s" ' % (name)
res=cursor.execute(sql)
if res:
results=cursor.fetchall()
a=results[0]
if pwd==a[4]:
#小区工作人员子系统
if 'r' in a[0]:
sql='select * from residence_community where res_nums = "%s" ' % (a[0])
cursor.execute(sql)
r=cursor.fetchone()
r_name.set(r[1])
r_info.set(r[2])
window2=tk.Toplevel(window)
window2.title('{}-小区管理系统'.format(r[1]))
window2.geometry('800x800')
tk.Label(window2,text='小区名称:{}'.format(r_name.get())).place(x=20,y=0)
tk.Label(window2,text='小区简介:{}'.format(r_info.get())).place(x=20,y=40)
btn_c=tk.Button(window2,text='修改小区信息',command=change_res)
btn_c.place(x=200,y=80)
tk.Label(window2,text='小区业主信息').place(x=350,y=250)
sql='select * from owner where res_com_nums = "%s" ' % (a[0])
cursor.execute(sql)
owners=cursor.fetchall()
owners=list(owners)
for i in range(len(owners)):
owners[i]=list(owners[i])
owners[i]=' '.join(owners[i])
listbox=tk.Listbox(window2,width=600)
for i in range(len(owners)):
listbox.insert(tk.END,owners[i])
listbox.place(x=10,y=300)
btn_cc=tk.Button(window2,text='修改该业主信息',command=lambda:change_owner(listbox))
btn_cc.place(x=50,y=700)
btn_delete=tk.Button(window2,text='删除该业主信息',command=lambda:delete_owner(listbox))
btn_delete.place(x=250,y=700)
btn_add=tk.Button(window2,text='新增业主信息',command=lambda:add_owner(listbox,a[0]))
btn_add.place(x=450,y=700)
elif 'h' in a[0]:
sql='select * from hospital where hos_nums = "%s" ' % (a[0])
cursor.execute(sql)
r=cursor.fetchone()
r_name.set(r[1])
r_info.set(r[2])
window2=tk.Toplevel(window)
window2.title('{}-医院管理系统'.format(r[1]))
window2.geometry('800x800')
tk.Label(window2,text='医院名称:{}'.format(r_name.get())).place(x=20,y=0)
tk.Label(window2,text='医院简介:{}'.format(r_info.get())).place(x=20,y=40)
btn_c=tk.Button(window2,text='修改医院信息',command=change_hos)
btn_c.place(x=200,y=80)
tk.Label(window2,text='医院病人信息').place(x=350,y=250)
sql='select * from patient where hos_nums = "%s" ' % (a[0])
cursor.execute(sql)
patients=cursor.fetchall()
patients=list(patients)
for i in range(len(patients)):
patients[i]=list(patients[i])
patients[i]=' '.join(patients[i])
listbox=tk.Listbox(window2,width=600)
for i in range(len(patients)):
listbox.insert(tk.END,patients[i])
listbox.place(x=10,y=300)
btn_cc=tk.Button(window2,text='修改该病人信息',command=lambda:change_patient(listbox))
btn_cc.place(x=50,y=700)
btn_delete=tk.Button(window2,text='删除该病人信息',command=lambda:delete_patient(listbox))
btn_delete.place(x=250,y=700)
btn_add=tk.Button(window2,text='新增病人信息',command=lambda:add_patient(listbox,a[0]))
btn_add.place(x=450,y=700)
else:
sql='select * from community where com_nums = "%s" ' % (a[0])
cursor.execute(sql)
r=cursor.fetchone()
r_name.set(r[1])
r_info.set(r[2])
window2=tk.Toplevel(window)
window2.title('{}-社区管理系统'.format(r[1]))
window2.geometry('800x800')
tk.Label(window2,text='社区名称:{}'.format(r_name.get())).place(x=20,y=0)
tk.Label(window2,text='社区简介:{}'.format(r_info.get())).place(x=20,y=40)
btn_c=tk.Button(window2,text='修改社区信息',command=change_com)
btn_c.place(x=200,y=80)
tk.Label(window2,text='查询类型:').place(x=20,y=120)
var_type=tk.StringVar()
r1=tk.Radiobutton(window2,text='医院',variable=var_type,value='医院')
r2=tk.Radiobutton(window2,text='病人',variable=var_type,value='病人')
r3=tk.Radiobutton(window2,text='小区',variable=var_type,value='小区')
r4=tk.Radiobutton(window2,text='业主',variable=var_type,value='业主')
r1.place(x=100,y=120)
r2.place(x=100,y=140)
r3.place(x=100,y=160)
r4.place(x=100,y=180)
var_info=tk.StringVar()
tk.Label(window2,text='查询信息:').place(x=20,y=220)
en=tk.Entry(window2,textvariable=var_info)
en.place(x=100,y=220)
btn_f=tk.Button(window2,text='查询',command=lambda:search(var_type,var_info))
btn_f.place(x=200,y=250)
tk.Label(window2,text='查询说明:').place(x=20,y=280)
tk.Label(window2,text='若查询医院,则输入医院的编号,如"h1"').place(x=20,y=300)
tk.Label(window2,text='若查询病人,则输入病人所在医院的编号和该病人的编号,并以逗号分隔,如"h1,p1"').place(x=20,y=320)
tk.Label(window2,text='若查询小区,则输入小区的编号,如"r1"').place(x=20,y=340)
tk.Label(window2,text='若查询业主,则输入业主的姓名,如"车路"').place(x=20,y=360)
else:
tk.messagebox.showerror(message='密码错误,请重试')
else:
sql='select * from owner where res_com_nums = "%s" ' % (a[4])
res=cursor.execute(sql)
if res:
results=cursor.fetchall()
a=results[0]
if pwd==a[3]:
sql='select res_name from residence_community where res_nums = "%s" ' % (a[5])
cursor.execute(sql)
r=cursor.fetchone()[0]
info='业主{}{}),生于{},居住于{}小区{}{}{}'.format(a[1],a[2],a[4],r,a[6],a[7],a[8])
tk.messagebox.showinfo(title='业主信息',message=info)
else:
sql='select * from patient where pat_name = "%s" ' % (name)
res=cursor.execute(sql)
if res:
result=cursor.fetchall()
a=result[0]
if pwd==a[4]:
sql='select hos_name from hospital where hos_nums = "%s" ' % (a[0])
cursor.execute(sql)
h=cursor.fetchone()[0]
info='患者{}{}),治疗医院为{},编号{},现{}'.format(a[2],a[3],h,a[1],a[7])
tk.messagebox.showinfo(title='病人信息',message=info)
else:
tk.messagebox.showerror(message='密码错误,请重试')
else:
tk.messagebox.showerror(message='用户不存在,请重试')
btn_login=tk.Button(window,text='登录',command=usr_login)
btn_login.place(x=170,y=100)
window.mainloop()
cursor.close()
conn.close()