帮我写一个器件管理软件 有出库和入库功能 并且可以查询到历史记录 程序 有界面 功能全一点
时间: 2024-04-06 20:29:35 浏览: 57
出入库管理软件
3星 · 编辑精心推荐
好的,下面是一个带有界面的器件管理软件程序的示例,供您参考。这个程序使用了 Python 的 tkinter 模块来实现界面,使用了 SQLite 数据库来存储器件信息。
```python
import tkinter as tk
import sqlite3
import datetime
class InventoryApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.title("Inventory Management")
self.geometry("600x400")
self.create_widgets()
self.create_table()
def create_widgets(self):
# Create input fields and buttons
tk.Label(self, text="Name:").grid(row=0, column=0, padx=10, pady=10)
self.name_entry = tk.Entry(self)
self.name_entry.grid(row=0, column=1)
tk.Label(self, text="Model:").grid(row=1, column=0, padx=10, pady=10)
self.model_entry = tk.Entry(self)
self.model_entry.grid(row=1, column=1)
tk.Label(self, text="Quantity:").grid(row=2, column=0, padx=10, pady=10)
self.quantity_entry = tk.Entry(self)
self.quantity_entry.grid(row=2, column=1)
self.add_button = tk.Button(self, text="Add Item", command=self.add_item)
self.add_button.grid(row=3, column=0, padx=10, pady=10)
self.remove_button = tk.Button(self, text="Remove Item", command=self.remove_item)
self.remove_button.grid(row=3, column=1, padx=10, pady=10)
# Create output field and button
tk.Label(self, text="Search History:").grid(row=4, column=0, padx=10, pady=10)
self.history_output = tk.Text(self, width=50, height=10)
self.history_output.grid(row=5, column=0, columnspan=2)
self.search_button = tk.Button(self, text="Search", command=self.search_item)
self.search_button.grid(row=6, column=0, padx=10, pady=10)
def create_table(self):
# Create SQLite table
conn = sqlite3.connect('inventory.db')
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS inventory
(id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
model TEXT NOT NULL,
quantity INTEGER NOT NULL,
in_time TEXT NOT NULL,
out_time TEXT);''')
conn.commit()
conn.close()
def add_item(self):
# Add item to SQLite table
name = self.name_entry.get()
model = self.model_entry.get()
quantity = int(self.quantity_entry.get())
in_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
conn = sqlite3.connect('inventory.db')
c = conn.cursor()
c.execute("INSERT INTO inventory (name, model, quantity, in_time) VALUES (?, ?, ?, ?)", (name, model, quantity, in_time))
conn.commit()
conn.close()
self.name_entry.delete(0, tk.END)
self.model_entry.delete(0, tk.END)
self.quantity_entry.delete(0, tk.END)
def remove_item(self):
# Remove item from SQLite table
name = self.name_entry.get()
model = self.model_entry.get()
quantity = int(self.quantity_entry.get())
out_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
conn = sqlite3.connect('inventory.db')
c = conn.cursor()
c.execute("SELECT quantity FROM inventory WHERE name=? AND model=?", (name, model))
result = c.fetchone()
if result and result[0] >= quantity:
c.execute("UPDATE inventory SET quantity=quantity-?, out_time=? WHERE name=? AND model=?", (quantity, out_time, name, model))
conn.commit()
conn.close()
self.name_entry.delete(0, tk.END)
self.model_entry.delete(0, tk.END)
self.quantity_entry.delete(0, tk.END)
self.history_output.delete(1.0, tk.END)
self.history_output.insert(tk.END, "Item removed successfully.")
else:
conn.close()
self.history_output.delete(1.0, tk.END)
self.history_output.insert(tk.END, "Item not found or quantity not enough.")
def search_item(self):
# Search item from SQLite table and show history
name = self.name_entry.get()
model = self.model_entry.get()
conn = sqlite3.connect('inventory.db')
c = conn.cursor()
c.execute("SELECT * FROM inventory WHERE name=? AND model=?", (name, model))
result = c.fetchall()
conn.close()
self.history_output.delete(1.0, tk.END)
if result:
self.history_output.insert(tk.END, "History:\n")
for row in result:
self.history_output.insert(tk.END, "ID: {}, Name: {}, Model: {}, Quantity: {}, In Time: {}, Out Time: {}\n".format(row[0], row[1], row[2], row[3], row[4], row[5]))
else:
self.history_output.insert(tk.END, "Item not found.")
if __name__ == "__main__":
app = InventoryApp()
app.mainloop()
```
运行程序后,会弹出一个窗口,包含输入框、输出框和按钮。用户可以在输入框中输入或扫描器件信息,并选择是入库还是出库操作。当用户选择入库操作时,系统会将输入的信息存储到数据库中,并更新该器件的数量信息。当用户选择出库操作时,系统会检查该器件数量是否足够,如果足够则更新数量信息,并记录出库时间;如果不足,则提示用户数量不足无法出库。为了方便用户查询历史记录,程序会显示历史记录的输出框,用户可以输入器件名称或型号,然后系统会从数据库中查询并显示该器件的历史记录,包括入库时间、出库时间、数量等信息。
该程序在功能上与前一个程序相同,但具有更加友好的用户界面,易于使用。同样,该程序仅供参考,实际应用中还需要根据具体需求进行修改和完善。
阅读全文