# -*- coding = utf-8 -*-
# @Time : 2022/5/6 19:29
# @Author : Architect
# @File : dataOperator.py
# @Software : PyCharm
import sys
from datetime import date
from prettytable import PrettyTable
from dataDictionary import DataDictionary
from dbConnector import connect_init
from pymysql.err import IntegrityError
def updateData(data_tuple):
conn = connect_init()
cursor = conn.cursor()
try:
print("UPDATE %s SET %s = '%s' WHERE %s = '%s';" % data_tuple)
cursor.execute("UPDATE %s SET %s = '%s' WHERE %s = '%s';" % data_tuple)
conn.commit()
print("--成功在 %s 数据表更新数据" % data_tuple[0])
except IntegrityError as error:
err_str = DataDictionary.error_dict[str(error)[1:5]]
if err_str:
print(err_str)
else:
print("--【警告】 信息删除失败,系统错误:\n", error)
print(error)
finally:
cursor.close()
conn.close()
def deleteData(data_tuple):
conn = connect_init()
cursor = conn.cursor()
try:
cursor.execute("DELETE FROM %s WHERE %s = '%s';"% data_tuple)
conn.commit()
print("--成功在 %s 数据表删除数据" % data_tuple[0])
except IntegrityError as error:
err_str = DataDictionary.error_dict[str(error)[1:5]]
if err_str:
print(err_str)
else:
print("--【警告】 信息删除失败,系统错误:\n", error)
print(error)
finally:
cursor.close()
conn.close()
def addData(table_name, data_tuple):
conn = connect_init()
cursor = conn.cursor()
try:
cursor.execute(DataDictionary.format_dict[table_name] % data_tuple)
conn.commit()
print("--成功插入数据信息到 %s 数据表" % table_name)
except IntegrityError as error:
err_str = DataDictionary.error_dict[str(error)[1:5]]
if err_str:
print(err_str)
else:
print("--【警告】 信息插入失败,系统错误:\n", error)
print(error)
finally:
cursor.close()
conn.close()
def addPatient():
table_name = "patients"
column_name = "pno"
capital = "P"
num_len = 4
pno = inputNum("> --编号(按ENTER自动填写):", capital, num_len, necessary=False)
pname = inputStr("> --姓名(必填):", necessary=True)
psex = inputStr("> --性别(男/女):", range=["男", "女"], necessary=True)
pbirth = inputNum("> --出生年份:", num_len=4, necessary=True)
paddress = inputStr("> --住址:", necessary=False)
pdate = inputDate("> --入院时间(yyyy-mm-dd):", necessary=False)
if pno == "":
pno = getDefaultNum(table_name, column_name, capital, num_len)
pbirth = int(pbirth)
addData(table_name, (pno, pname, psex, pbirth, paddress, pdate[0], pdate[1], pdate[2]))
def addDoctor():
table_name = "doctors"
column_name = "dno"
capital = "D"
num_len = 4
dno = inputNum("> --编号(按ENTER自动填写):", capital, num_len, necessary=False)
dname = inputStr("> --姓名(必填):", necessary=True)
dsex = inputStr("> --性别(男/女):", range=["男", "女"], necessary=True)
dbirth = inputNum("> --出生年份:", num_len=4, necessary=True)
ddept = inputStr("> --科室:", necessary=False)
dlevel = inputStr("> --职称:", necessary=False)
if dno == "":
dno = getDefaultNum(table_name, column_name, capital, num_len)
dbirth = int(dbirth)
addData(table_name, (dno, dname, dsex, dbirth, ddept, dlevel))
def addNurse():
table_name = "nurses"
column_name = "nno"
capital = "n"
num_len = 4
nno = inputNum("> --编号(按ENTER自动填写):", capital, num_len, necessary=False)
nname = inputStr("> --姓名(必填):", necessary=True)
nsex = inputStr("> --性别(男/女):", range=["男", "女"], necessary=True)
nbirth = inputNum("> --出生年份:", num_len=4, necessary=True)
ndept = inputStr("> --科室:", necessary=False)
nlevel = inputStr("> --职称:", necessary=False)
if nno == "":
nno = getDefaultNum(table_name, column_name, capital, num_len)
nbirth = int(nbirth)
addData(table_name, (nno, nname, nsex, nbirth, ndept, nlevel))
def addBed():
table_name = "beds"
column_name = "bno"
capital = "B"
num_len = 4
bno = inputNum("> --编号(按ENTER自动填写):", capital, num_len, necessary=False)
bprice = inputNum("> --床位价格(元/天):", necessary=True)
if bno == "":
bno = getDefaultNum(table_name, column_name, capital, num_len)
bprice = int(bprice)
addData(table_name, (bno, bprice))
def addDrug():
table_name = "drugs"
column_name = "dno"
capital = "M"
num_len = 5
dno = inputNum("> --编号(按ENTER自动填写):", capital, num_len, necessary=False)
dname = inputStr("> --药品学名(必填):", necessary=True)
dtype = inputStr("> --类型(中药/西药):", range=["中药", "西药"], necessary=True)
dprice = inputFloat("> --单价(元):", necessary=True)
dstorage = inputNum("> --库存:", necessary=True)
if dno == "":
dno = getDefaultNum(table_name, column_name, capital, num_len)
dprice = float(dprice)
dstorage = int(dstorage)
addData(table_name, (dno, dname, dtype, dprice, dstorage))
def addDiagnose():
table_name = "dp_rel"
column_name = "dpno"
capital = "DP"
num_len = 5
dpno = inputNum("> --编号(按ENTER自动填写):", capital, num_len, necessary=False)
dno = inputNum("> --医生编号:", "D", 4, necessary=True)
pno = inputNum("> --患者编号:", "P", 4, necessary=True)
illness = inputStr("> --诊断结果:", necessary=False)
if dpno == "":
dpno = getDefaultNum(table_name, column_name, capital, num_len)
addData(table_name, (dpno, dno, pno, illness))
def addDrugSell():
table_name = "drug_sell"
column_name = "dsno"
capital = "DS"
num_len = 5
dsno = inputNum("> --编号(按ENTER自动填写):", capital, num_len, necessary=False)
dpno = inputNum("> --诊断编号:", "DP", 5, necessary=True)
dno = inputNum("> --药品编号:", "M", 5, necessary=True)
dnum = inputNum("> --药品数量:", necessary=True)
dnum = int(dnum)
if dsno == "":
dsno = getDefaultNum(table_name, column_name, capital, num_len)
addData(table_name, (dsno, dno, dnum, dpno))
def addHost():
table_name = "host_rel"
column_name = "hno"
capital = "H"
num_len = 5
hno = inputNum("> --编号(按ENTER自动填写):", capital, num_len, necessary=False)
nno = inputNum("> --护士编号:", "N", 4, necessary=True)
pno = inputNum("> --病患编号:", "P", 4, necessary=True)
bno = inputNum("> --床位编号:", "B", 4, necessary=True)
hdate = inputDate("> --住院时间(yyyy-mm-dd):", necessary=False)
if hno == "":
hno = getDefaultNum(table_name, column_name, capital, num_len)
addData(table_name, (hno, nno, pno, bno, hdate[0], hdate[1], hdate[2]))
def inputNum(sentence, capital="", num_len=0, necessary=True):
while True:
no = input(sentence)
cp_len = len(capital)
if not necessary:
if no == "":
break
if num_len == 0:
if no[0:cp_len] == capital and is_int(no[cp_len:]):
break
else:
if no[0:cp_len] == capital and len(no) == num_len + cp_len and is_int(no[cp_len:]):
break
return no
def inputFloat(sentence, necessary=True):
while True:
f = input(sentence)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 基于Python和MySQL的医院管理系统源码+sql数据库(数据库课设).zip基于Python和MySQL的医院管理系统源码+sql数据库(数据库课设).zip基于Python和MySQL的医院管理系统源码+sql数据库(数据库课设).zip基于Python和MySQL的医院管理系统源码+sql数据库(数据库课设).zip基于Python和MySQL的医院管理系统源码+sql数据库(数据库课设).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
基于Python和MySQL的医院管理系统源码+sql数据库(数据库课设).zip (22个子文件)
Hospital Sys MyQLPython
hospital.py 4KB
dataInitiator.py 3KB
dbConnector.py 385B
dataSearcher.py 3KB
dataDictionary.py 2KB
mysql02.py 826B
dataOperator.py 10KB
dataReader.py 1KB
mysql files
2022.5.1 hospital triggers.sql 1KB
2022.5.1 hospital data insert.sql 579B
2022.5.1 hospital others.sql 898B
2022.5.1 hospital init.sql 5KB
mysql03.py 688B
data.xlsx 25KB
__pycache__
dataInitiator.cpython-39.pyc 3KB
dataReader.cpython-39.pyc 1KB
hospital.cpython-39.pyc 209B
dataDictionary.cpython-39.pyc 2KB
dataOperator.cpython-39.pyc 8KB
dataSearcher.cpython-39.pyc 2KB
dbConnector.cpython-39.pyc 429B
mysql01.py 1000B
共 22 条
- 1
资源评论
- Dr.Water2024-04-28发现一个宝藏资源,赶紧冲冲冲!支持大佬~
- qq_428444102024-03-04怎么能有这么好的资源!只能用感激涕零来形容TAT...
onnx
- 粉丝: 9681
- 资源: 5598
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- x64dbg-development-2022-09-07-14-52.zip
- 多彩吉安红色旅游网站-JAVA-基于springBoot多彩吉安红色旅游网站的设计与实现
- 本 repo 包含使用新 cv2 接口的 OpenCV-Python 库教程.zip
- 更新框架 (TUF) 的 Python 参考实现.zip
- Qos,GCC,pacing,Nack
- 章节1:Python入门视频
- 无需样板的 Python 类.zip
- ESP32 : 32-bit MCU & 2.4 GHz Wi-Fi & BT/BLE SoCs
- 博物馆文博资源库-JAVA-基于springBoot博物馆文博资源库系统设计与实现
- 旅游网站-JAVA-springboot+vue的桂林旅游网站系统设计与实现
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功