pycharm写一个新冠物资管理系统要求提供源代码
时间: 2023-08-25 07:47:30 浏览: 113
好的,以下是一个简单的新冠物资管理系统的源代码示例,你可以将其保存为main.py文件并在PyCharm中运行。
```python
import pandas as pd
import sqlite3
def create_table():
conn = sqlite3.connect('materials.db')
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS materials
(id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
quantity INT NOT NULL,
unit TEXT NOT NULL);''')
conn.commit()
conn.close()
def add_material():
name = input("请输入物资名称:")
quantity = int(input("请输入物资数量:"))
unit = input("请输入物资单位:")
conn = sqlite3.connect('materials.db')
c = conn.cursor()
c.execute("INSERT INTO materials (name, quantity, unit) VALUES (?, ?, ?)", (name, quantity, unit))
conn.commit()
conn.close()
print("物资添加成功!")
def delete_material():
id = int(input("请输入物资ID:"))
conn = sqlite3.connect('materials.db')
c = conn.cursor()
c.execute("DELETE FROM materials WHERE id=?", (id,))
conn.commit()
conn.close()
print("物资删除成功!")
def modify_material():
id = int(input("请输入物资ID:"))
name = input("请输入物资名称:")
quantity = int(input("请输入物资数量:"))
unit = input("请输入物资单位:")
conn = sqlite3.connect('materials.db')
c = conn.cursor()
c.execute("UPDATE materials SET name=?, quantity=?, unit=? WHERE id=?", (name, quantity, unit, id))
conn.commit()
conn.close()
print("物资修改成功!")
def view_materials():
conn = sqlite3.connect('materials.db')
c = conn.cursor()
c.execute("SELECT * FROM materials")
rows = c.fetchall()
df = pd.DataFrame(rows, columns=['ID', '名称', '数量', '单位'])
print(df)
conn.close()
def count_materials():
conn = sqlite3.connect('materials.db')
c = conn.cursor()
c.execute("SELECT SUM(quantity) FROM materials")
total = c.fetchone()[0]
print("物资总数为:", total)
conn.close()
def main():
create_table()
while True:
print("欢迎使用新冠物资管理系统!")
print("1. 添加物资")
print("2. 删除物资")
print("3. 修改物资")
print("4. 查看物资清单")
print("5. 统计物资数量")
print("0. 退出系统")
choice = int(input("请选择操作:"))
if choice == 1:
add_material()
elif choice == 2:
delete_material()
elif choice == 3:
modify_material()
elif choice == 4:
view_materials()
elif choice == 5:
count_materials()
elif choice == 0:
print("感谢使用新冠物资管理系统,再见!")
break
else:
print("无效的选择,请重新输入!")
if __name__ == '__main__':
main()
```
该程序使用sqlite3作为数据库,包含添加、删除、修改、查看和统计物资信息的功能。你可以根据需要进行修改和扩展。注意在运行程序前需要安装pandas库。
阅读全文