数据库课程设计:仓库管理系统

本文介绍了数据库课程设计中的仓库管理系统,系统包含产品信息表、进出库表的创建,支持产品入库、出库、借出管理和盘库功能。通过合理数据库架构设计,如SQL Server作为后端,确保稳定性和性能,同时提供灵活的查询功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

创建产品信息表和进出库表:系统可以创建数据库表格用于存储产品信息、库存数量和进出库记录。产品信息表包括产品ID、名称和价格等字段,进出库表包括记录ID、产品ID、数量、类型(入库或出库)、日期等字段。

产品入库管理:管理员可以通过系统界面填写入库单,包括选择产品、输入入库数量和日期等信息。确认入库后,系统会将相关信息记录到进出库表中,并更新产品的库存数量。

产品出库管理:管理员可以使用系统界面填写出库单,选择要出库的产品、输入出库数量和日期等信息。确认出库后,系统将相应的记录添加到进出库表中,并更新产品的库存数量。

借出管理:系统支持借出功能,管理员可以使用系统生成借条,并记录借出的产品信息。借出后,系统会相应地减少产品的库存数量。当产品归还时,管理员可以在系统中进行归还操作,系统将更新库存数量。

初始库存设置:系统允许管理员设置产品的初始库存值,并设定库存的上下警戒限。这些值可以在系统中进行配置,以便系统根据设定的阈值进行库存警报和提醒。

盘库功能:系统提供盘库功能,管理员可以选择进行月度或年度的盘库。在盘库过程中,系统会与实际库存进行对比,以便发现差异并进行调整。

查询功能:系统提供灵活的查询功能,管理员可以按照出库单、入库单、产品、时间等条件进行查询。管理员可以根据需求获取特定时间段的进出库记录,查看特定产品的入库和出库情况,或者查询当前库存情况。查询结果将在系统界面上显示或以报表形式呈现。

数据库架构:

使用合适的数据库管理系统(如SQL Server)作为后端数据库,提供稳定性和性能优化。

设计合理的表结构和关系,以便支持系统功能和查询需求。

数据表设计:

创建产品信息表(Product):包括产品ID(主键)、名称、价格字段。

创建进出库表(Inventory):包括记录ID(主键)、产品ID(外键)、数量、类型(入库或出库)、日期等字段。

import tkinter as tk
import tkinter.messagebox as messagebox
import pyodbc


server = 'LAP'
database = 'Warehouse_management'

driver = '{ODBC Driver 17 for SQL Server}'

# 建立数据库连接
conn = pyodbc.connect(f'SERVER={server};DATABASE={database};Trusted_Connection=yes;DRIVER={driver}')

# 创建产品信息表
def create_product_table():
    try:
        cursor = conn.cursor()
        cursor.execute('''
            CREATE TABLE Product (
                ProductID INT PRIMARY KEY,
                Name NVARCHAR(50),
                Price DECIMAL(10, 2)
            )
        ''')
        conn.commit()
        messagebox.showinfo('成功', '创建产品信息表成功')
    except Exception as e:
        messagebox.showerror('错误', f'创建产品信息表失败:{str(e)}')

# 创建进出库表
def create_inventory_table():
    try:
        cursor = conn.cursor()
        cursor.execute('''
            CREATE TABLE Inventory (
                ID INT IDENTITY(1,1) ,
                ProductID INT,
                Quantity INT,
                Type NVARCHAR(10),
                Date DATE,
                FOREIGN KEY (ProductID) REFERENCES Product(ProductID)
            )
        ''')
        conn.commit()
        messagebox.showin('成功', '创建进出库表成功')
    except Exception as e:
        messagebox.shower('错误', f'创建进出库表失败:{str(e)}')

# 产品入库管理
def add_inventory():
    product_id = entry_product_id.get()
    quantity = entry_quantity.get()
    date = entry_date.get()
    try:
        cursor = conn.cursor()
        cursor.execute('INSERT INTO Inventory (ProductID, Quantity, Type, Date) VALUES (?, ?, ?, ?)', (product_id, quantity, '入库', date))
        conn.commit()
        messagebox.showin('成功', '产品入库成功')
    except Exception as e:
        messagebox.showerror('错误', f'产品入库失败:{str(e)}')

# 产品出库管理
def remove_inventory():
    product_id = entry_product_id.get()
    quantity = entry_quantity.get()
    date = entry_date.get()
    try:
        cursor = conn.cursor()
        cursor.execute('INSERT INTO Inventory (ProductID, Quantity, Type, Date) VALUES (?, ?, ?, ?)', (product_id, quantity, '出库', date))
        conn.commit()
        messagebox.showinfo('成功', '产品出库成功')
    except Exception as e:
        messagebox.showerror('错误', f'产品出库失败:{str(e)}')

# 借出管理
def lend_product():
    product_id = entry_product_id.get()
    quantity = entry_quantity.get()
    date = entry_date.get()
    try:
        cursor = conn.cursor()
        cursor.execute('INSERT INTO Inventory (ProductID, Quantity, Type, Date) VALUES (?, ?, ?, ?)', (product_id, quantity, '借出', date))
        conn.commit()
        messagebox.showin('成功', '借出产品成功')
    except Exception as e:
        messagebox.showerror('错误', f'借出产品失败:{str(e)}')

# 归还管理
def return_product():
    product_id = entry_product_id.get()
    quantity = entry_quantity.get()
    date = entry_date.get()
    try:
        cursor = conn.cursor()
        cursor.execute('INSERT INTO Inventory (ProductID, Quantity, Type, Date) VALUES (?, ?, ?, ?)', (product_id, quantity, '归还', date))
        conn.commit()
        messagebox.showinfo('成功', '归还产品成功')
    except Exception as e:
        messagebox.showerror('错误', f'归还产品失败:{str(e)}')

# 设置初始库存
def set_initial_inventory():
    product_id = entry_product_id.get()
    quantity = entry_quantity.get()
    try:
        cursor = conn.cursor()
        cursor.execute('INSERT INTO Inventory (ProductID, Quantity, Type) VALUES (?, ?, ?)', (product_id, quantity, '初始库存'))
        conn.commit()
        messagebox.showinfo('成功', '设置初始库存成功')
    except Exception as e:
        messagebox.showerror('错误', f'设置初始库存失败:{str(e)}')

# 盘库
def perform_stocktaking():
    try:
        cursor = conn.cursor()
        cursor.execute('''
            SELECT p.Name, i.Quantity
            FROM Product p
            INNER JOIN (
                SELECT ProductID, SUM(CASE WHEN Type = '入库' THEN Quantity ELSE -Quantity END) AS Quantity
                FROM Inventory
                GROUP BY ProductID
            ) i ON p.ProductID = i.ProductID
        ''')
        result = cursor.fetch()
        messagebox.showinfo('盘库结果', '\n'.join([f'{row.Name}: {row.Quantity}' for row in result]))
    except Exception as e:
        messagebox.showerror('错误', f'盘库失败:{str(e)}')

# 查询产品入库情况
def view_product_in():
    product_id = entry_product_id.get()
    try:
        cursor = conn.cursor()
        cursor.execute('SELECT * FROM Inventory WHERE ProductID = ? AND Type = ?', (product_id, '入库'))
        result = cursor.fetchall()
        messagebox.showinfo('产品入库情况', '\n'.join([f'ID: {row.ID}, Quantity: {row.Quantity}, Date: {row.Date}' for row in result]))
    except Exception as e:
        messagebox.showerror('错误', f'查询产品入库情况失败:{str(e)}')

# 查询产品出库情况
def view_product_out():
    product_id = entry_product_id.get()
    try:
        cursor = conn.cursor()
        cursor.execute('SELECT * FROM Inventory WHERE ProductID = ? AND Type = ?', (product_id, '出库'))
        result = cursor.fetchall()
        messagebox.showinfo('产品出库情况', '\n'.join([f'ID: {row.ID}, Quantity: {row.Quantity}, Date: {row.Date}' for row in result]))
    except Exception as e:
        messagebox.shower('错误', f'查询产品出库情况失败:{str(e)}')

# 查询当前库存情况
def view_inventory():
    try:
        cursor = conn.cursor()
        cursor.execute('''
            SELECT p.Name, i.Quantity
            FROM Product p
            INNER JOIN (
                SELECT ProductID, SUM(CASE WHEN Type = '入库' THEN Quantity ELSE -Quantity END) AS Quantity
                FROM Inventory
                GROUP BY ProductID
            ) i ON p.ProductID = i.ProductID
        ''')
        result = cursor.fetchall()
        messagebox.showinfo('当前库存情况', '\n'.join([f'{row.Name}: {row.Quantity}' for row in result]))
    except Exception as e:
        messagebox.showerror('错误', f'查询当前库存情况失败:{str(e)}')

# 创建GUI窗口
window = tk.Tk()
window.title('仓库管理系统')

# 创建产品信息表按钮
btn_create_product_table = tk.Button(window, text='创建产品信息表', command=create_product_table)
btn_create_product_table()

# 创建进出库表按钮
btn_create_inventory_table = tk.Button(window, text='创建进出库表', command=create_inventory_table)
btn_create_inventory_table.pack()

# 产品ID输入框
label_product_id = tk.Label(window, text='产品ID')
label_product_id.pack()
entry_product_id = tk.Entry(window)
entry_product_id.pack()

# 数量输入框
label_quantity = tk.Label(window, text='数量')
label_quantity.pack()
entry_quantity = tk(window)
entry_quantity.pack()

# 日期输入框
label_date = tk.Label(window, text='日期(YYYY-MM-DD)')
label_date.pack()
entry_date = tk.Entry(window)
entry_date.pack()

# 产品入库按钮
btn_add_inventory = tk.Button(window, text='产品入库', 
                              command=add_inventory)
btn_add_inventory.pack()

# 产品出库按钮
btn_remove_inventory = tk.Button(window, text='产品出库', 
                                 command=remove_inventory)
btn_remove_inventory.pack()

# 借出产品按钮
btn_lend_product = tk.Button(window, text='借出产品', 
                             command=lend_product)
btn_lend_product.pack()



# 设置初始库存按钮
btn_set_initial_inventory = tk.Button(window, text='设置初始库存', 
                                      command=set_initial_inventory)
btn_set_initial_inventory()

# 盘库按钮
btn_perform_stocktaking = tk.Button(window, text='盘库', 
                                    command=perform_stocktaking)
btn_perform_stocktaking.pack()

# 查询产品入库情况按钮
btn_view_product_in = tk.Button(window, text='查询产品入库情况', 
                                command=view_product_in)
btn_view_product_in.pack()

# 查询产品出库情况按钮
btn_view_product_out = tk.Button(window, text='查询产品出库情况', 
                                 command=view_product_out)
btn_view_product_out.pack()

# 查询当前库存情况按钮
btn_view_inventory = tk.Button(window, text='查询当前库存情况', 
                               command=view_inventory)
btn_view_inventory.pack()

# 运行GUI窗口
window.mainloop()

这个程序是仓库管理系统的程序,刚刚课程设计完,把它拿出来晒晒... 和大家分享下... 算不上很好的美餐,但也能抵得住寒冷... 总会有需要的人,希望能为需要的人提供分参考资料... 仓库系统课程设计具体内容如下: 仓库管理中的物资主要指企业生成所需要的各种设备。进货时经检查合同确认为有效托收以后,进行验货入库。填写入库单、进行入库登记。企业各部门根据所需的物资设备总额和部门生产活动的需要提出物资需求申请。计划员根据部门申请开出物资设备出库单,仓库管理员根据出库单核对发放设备。设备使用完,及时归还入库,填写入库单。因此,系统主要功能包括: 仓库管理各种信息的输入、查询、修改和维护。包括入库、出库、需求信息的输入。查询要求以单项条件、组合条件与模糊条件查询。 设备采购报表的生成。 库存管理中加入最低和最高储备字段,对仓库中物资设备实现监控和报警。 各部门对物资需求的管理。 现有库存信息包括:现有设备号、现有数目、总数目、最大库存、最小库存。 设备入库信息包括:设备号、入库时间、供应商、供应商电话、入库数量、价格、采购员等。 设备出库信息包括:设备号、使用部门、出库时间、出库状况、经手人、出库数量、领取人、用途等。 设备采购信息包括:采购的设备号、采购员、供应商、采购数量、采购时间等。 设备归还信息包括:归还的设备号、归还部门、归还数目、归还时间、经手人等。 设备需求信息包括:需求的部门、需求的设备号、需求数量、需求时间等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

哭哭啼啼的小天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值