From e4264f70bf427944b8f1fd725841b32e6f6d8128 Mon Sep 17 00:00:00 2001
From: caizhizhong <3287054223@qq.com>
Date: Mon, 27 May 2024 11:54:37 +0800
Subject: [PATCH] first commit
---
pythonProject1/.idea/.gitignore | 8 ++
.../inspectionProfiles/profiles_settings.xml | 6 +
pythonProject1/.idea/misc.xml | 7 +
pythonProject1/.idea/modules.xml | 8 ++
pythonProject1/.idea/pythonProject1.iml | 10 ++
pythonProject1/1.py | 63 +++++++++
.../__pycache__/warehouse_gui.cpython-312.pyc | Bin 0 -> 7116 bytes
pythonProject1/gui.py | 45 +++++++
pythonProject1/warehouse_gui.py | 126 ++++++++++++++++++
pythonProject1/登录.py | 51 +++++++
pythonProject1/登录.zip | Bin 0 -> 857 bytes
11 files changed, 324 insertions(+)
create mode 100644 pythonProject1/.idea/.gitignore
create mode 100644 pythonProject1/.idea/inspectionProfiles/profiles_settings.xml
create mode 100644 pythonProject1/.idea/misc.xml
create mode 100644 pythonProject1/.idea/modules.xml
create mode 100644 pythonProject1/.idea/pythonProject1.iml
create mode 100644 pythonProject1/1.py
create mode 100644 pythonProject1/__pycache__/warehouse_gui.cpython-312.pyc
create mode 100644 pythonProject1/gui.py
create mode 100644 pythonProject1/warehouse_gui.py
create mode 100644 pythonProject1/登录.py
create mode 100644 pythonProject1/登录.zip
diff --git a/pythonProject1/.idea/.gitignore b/pythonProject1/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/pythonProject1/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/pythonProject1/.idea/inspectionProfiles/profiles_settings.xml b/pythonProject1/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/pythonProject1/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pythonProject1/.idea/misc.xml b/pythonProject1/.idea/misc.xml
new file mode 100644
index 0000000..a50ac5b
--- /dev/null
+++ b/pythonProject1/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pythonProject1/.idea/modules.xml b/pythonProject1/.idea/modules.xml
new file mode 100644
index 0000000..fdd8fdf
--- /dev/null
+++ b/pythonProject1/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pythonProject1/.idea/pythonProject1.iml b/pythonProject1/.idea/pythonProject1.iml
new file mode 100644
index 0000000..2c80e12
--- /dev/null
+++ b/pythonProject1/.idea/pythonProject1.iml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pythonProject1/1.py b/pythonProject1/1.py
new file mode 100644
index 0000000..4354173
--- /dev/null
+++ b/pythonProject1/1.py
@@ -0,0 +1,63 @@
+import mysql.connector
+from mysql.connector import Error
+
+class Warehouse:
+ def __init__(self):
+ self.conn = self.create_connection()
+ self.cursor = self.conn.cursor()
+ self.create_table_if_not_exists()
+
+ def create_connection(self):
+ """创建数据库连接"""
+ try:
+ connection = mysql.connector.connect(
+ host='your_host', # 替换为你的数据库主机名
+ database='inventory_db', # 使用之前创建的数据库名
+ user='your_user', # 替换为你的数据库用户名
+ password='your_password' # 替换为你的数据库密码
+ )
+ print("成功连接到MySQL数据库")
+ return connection
+ except Error as e:
+ print(f"连接失败: {e}")
+ return None
+
+ def create_table_if_not_exists(self):
+ """如果表不存在,则创建表"""
+ query = """
+ CREATE TABLE IF NOT EXISTS items (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ item_name VARCHAR(255) NOT NULL,
+ quantity INT NOT NULL
+ )
+ """
+ try:
+ self.cursor.execute(query)
+ self.conn.commit()
+ print("items表已存在或已成功创建")
+ except Error as e:
+ print(f"创建表时出错: {e}")
+
+ # ...(保留原有的add_item, remove_item等方法逻辑,但内部实现改为使用SQL操作)
+
+ def add_item_to_db(self, item_name, quantity):
+ """向数据库添加商品"""
+ query = "INSERT INTO items (item_name, quantity) VALUES (%s, %s)"
+ values = (item_name, quantity)
+ try:
+ self.cursor.execute(query, values)
+ self.conn.commit()
+ print(f"已添加 {quantity} 个 {item_name} 到数据库。")
+ except Error as e:
+ print(f"插入数据时出错: {e}")
+
+ # ...(类似地,修改remove_item, update_stock, check_stock等方法以使用SQL查询和操作)
+
+ def close_connection(self):
+ """关闭数据库连接"""
+ if self.conn.is_connected():
+ self.cursor.close()
+ self.conn.close()
+ print("MySQL连接已关闭")
+
+# 记得在程序结束时调用close_connection来关闭数据库连接。
\ No newline at end of file
diff --git a/pythonProject1/__pycache__/warehouse_gui.cpython-312.pyc b/pythonProject1/__pycache__/warehouse_gui.cpython-312.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..a8f9ba3baff23b31c0cf5d6da4cd896f9de30f61
GIT binary patch
literal 7116
zcmb6dZE#an_P&>w_9b~uV@V7ButW-l6pe}nE32qbzz+=0uqt%xWp%gT%d;A4|>&m$Fte1RPmxJ={v6AU4vge6;vNDdQ`Im;?D
zZN$rn?7mfmNWCoalCzlwZLF8=DplEJ|3#h1scRXs0F7QO$)ho3*Q+gcAIig|j%NR1
zpVB-YW!X8kCF(^!kEX~zqV6nwIRZmOgJ|q7ZR6qJ)Lq(RXfrU%i3o5aWh$pOqi8-%
z+DzKH@Nh1sth^y($Y?M3C`=WcIZJZ=PUw%qDYh{pX=6nO_~=9yFemB&>qQQ5iC8L@
z9A?@|LwY-(HazE+ydC~v!0X8fN_iqn9sI6?MuBA~=_f8afha`IFity@Hgx*-dwsHB
z3PFbpc)RxmkcaK&!<*K(KNIjuf%a~%&%fW_{&dLG;g))ymi%2_j~r<44apsTU#5F+
z`vFx3*WO^Kqc@c1U9L`Fr|fbatkC3hsADKw0MB}WT&k`e+dzDMU_AB3K-yq{fY12psm~fhh_ma1l|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I&U&Y36sen&4rZGmL@n*#Bg2yPM@M9RJ4Te3sh0kc4(;;EIJi>N#Szi>jXSF
z@A2o?vC=l6IavE`b!nF$3)sL8K%lb9>d{@tc74|R59i;Uscm9no0!_xmDtubv8_9`
zwC6*|`0`KrNOPny%0^qFO&4uzCzke1RQd*uS;ab|PfYUn|M$9%*nCU?1LpbL9&Io>
z?WK|pI?^48Fh^Ai(pGGtNl`(i25g}RrfnB?D#K?UMBf|Khl;fOqKX6L3
zKio$}PxDw7cl-Ulb~epPe!ra7xqEwabGI~yBvKnJ>w{mw255jxo63gQ4y}Fl{(;tM
zW7UW}VXPb2G{y0+JoVyJFKwq^Y!{S@9TzCpf~h$z>$6pUx>Vi=Q3E0a%B5HlJy_hY
z;KXn84=T?G8>Dua#q$ch3Fw-RVVG}N2ebAo0_d8^5Kb68cu`mVxuyEJY2fiGt}Mk>
zCAg}QzR02^x1wmjI>A*Zxmr4h?eMC|#w53r_G=PcO}HhpBgxrw=965*KZ*5Ur2ZSO
eg=zVU0GgK>9b<){pbEh8FKxM|BU}wVlK%lFIvi^N
literal 0
HcmV?d00001
diff --git a/pythonProject1/gui.py b/pythonProject1/gui.py
new file mode 100644
index 0000000..0740120
--- /dev/null
+++ b/pythonProject1/gui.py
@@ -0,0 +1,45 @@
+from tkinter import*
+import tkinter as tk
+
+user_login ={'aaa':'123456','bbb':'888888','ccc':'333333'}
+count=0
+def login():
+ global count
+ username=entry_username.get()
+ if username not in user_login:
+ label_message.config(text='账号错误!')
+ else:
+ password=entry_password.get()
+ if password == user_login[username]:
+ label_message.config(text='登录成功!')
+ def open_new_window():
+ new_window = tk.Toplevel(root)
+ # 在新窗口中创建新的界面
+ root = tk.Tk()
+ button = tk.Button(root, text="Open New Window", command=open_new_window)
+ button.pack()
+ root.mainloop()
+ else:
+ label_message.config(text='密码错误!还可以尝试{}次'.format(2-count))
+ count=count+1
+ if count == 3:
+ label_message.config(text='登录失败!')
+ btn_login.config(state='disabled')
+
+window = Tk()
+window.title('用户登录')
+window.geometry('300x200')
+
+label_username=Label(window,text="账号:")
+label_username.pack()
+entry_username = Entry(window)
+entry_username.pack()
+label_passsword = Label(window,text="密码:")
+label_passsword.pack()
+entry_password = Entry(window,show='*')
+entry_password.pack()
+btn_login=Button(window,text="登录",command=login)
+btn_login.pack()
+label_message=Label(window,text="")
+label_message.pack()
+window.mainloop()
\ No newline at end of file
diff --git a/pythonProject1/warehouse_gui.py b/pythonProject1/warehouse_gui.py
new file mode 100644
index 0000000..19a5560
--- /dev/null
+++ b/pythonProject1/warehouse_gui.py
@@ -0,0 +1,126 @@
+class Warehouse:
+ def __init__(self):
+ # 使用字典存储商品及其库存,键为商品名称,值为库存数量
+ self.inventory = {}
+
+ def add_item(self, item_name, quantity):
+ """添加商品到仓库"""
+ if item_name in self.inventory:
+ self.inventory[item_name] += quantity
+ else:
+ self.inventory[item_name] = quantity
+ print(f"已添加 {quantity} 个 {item_name} 到仓库。")
+
+ def remove_item(self, item_name, quantity):
+ """从仓库移除商品"""
+ if item_name not in self.inventory:
+ print(f"{item_name} 不在仓库中。")
+ return
+
+ if self.inventory[item_name] < quantity:
+ print(f"库存不足,当前 {item_name} 只有 {self.inventory[item_name]} 个。")
+ return
+
+ self.inventory[item_name] -= quantity
+ if self.inventory[item_name] == 0:
+ del self.inventory[item_name]
+ print(f"已从仓库移除 {quantity} 个 {item_name}。")
+
+ def update_stock(self, item_name, new_quantity):
+ """更新商品的库存量"""
+ if item_name not in self.inventory:
+ print(f"{item_name} 不在仓库中,无法更新。")
+ return
+
+ self.inventory[item_name] = new_quantity
+ print(f"{item_name} 的库存已更新为 {new_quantity}。")
+
+ def check_stock(self, item_name=None):
+ """查询单个或所有商品的库存"""
+ if item_name is None:
+ # 打印所有库存
+ for item, quantity in self.inventory.items():
+ print(f"{item}: {quantity}")
+ elif item_name in self.inventory:
+ print(f"{item_name} 的库存为: {self.inventory[item_name]}")
+ else:
+ print(f"{item_name} 不在仓库中。")
+
+
+# 示例使用
+if __name__ == "__main__":
+ warehouse = Warehouse()
+ warehouse.add_item("苹果", 100)
+ warehouse.add_item("香蕉", 150)
+ warehouse.check_stock() # 查看所有库存
+ warehouse.remove_item("苹果", 30)
+ warehouse.update_stock("香蕉", 200)
+ warehouse.check_stock("苹果") # 查询特定商品库存t("Invalid choice. Please try again.")
+import tkinter as tk
+from tkinter import messagebox
+
+class WarehouseGUI:
+ def __init__(self, master):
+ self.master = master
+ master.title("仓库管理系统")
+
+ # 初始化仓库类
+ self.warehouse = Warehouse()
+
+ # 商品名称输入框
+ self.item_label = tk.Label(master, text="商品名称:")
+ self.item_label.pack()
+ self.item_entry = tk.Entry(master)
+ self.item_entry.pack()
+
+ # 库存数量输入框
+ self.quantity_label = tk.Label(master, text="库存数量:")
+ self.quantity_label.pack()
+ self.quantity_entry = tk.Entry(master)
+ self.quantity_entry.pack()
+
+ # 操作选择下拉菜单
+ self.operation_var = tk.StringVar(value="添加商品")
+ self.operation_menu = tk.OptionMenu(master, self.operation_var, "添加商品", "减少库存", "更新库存", "查看库存")
+ self.operation_menu.pack()
+
+ # 执行按钮
+ self.execute_button = tk.Button(master, text="执行", command=self.execute_operation)
+ self.execute_button.pack()
+
+ def execute_operation(self):
+ operation = self.operation_var.get()
+ item_name = self.item_entry.get()
+ try:
+ quantity = int(self.quantity_entry.get())
+ except ValueError:
+ messagebox.showerror("错误", "库存数量必须是整数!")
+ return
+
+ if operation == "添加商品":
+ self.warehouse.add_item(item_name, quantity)
+ elif operation == "减少库存":
+ self.warehouse.remove_item(item_name, quantity)
+ elif operation == "更新库存":
+ self.warehouse.update_stock(item_name, quantity)
+ elif operation == "查看库存":
+ if item_name:
+ self.show_stock(item_name)
+ else:
+ self.show_all_stock()
+
+ def show_stock(self, item_name):
+ stock = self.warehouse.check_stock(item_name)
+ messagebox.showinfo(f"{item_name} 的库存", f"{stock}")
+
+ def show_all_stock(self):
+ stock_info = "\n".join([f"{item}: {quantity}" for item, quantity in self.warehouse.inventory.items()])
+ messagebox.showinfo("所有库存", stock_info)
+
+def main():
+ root = tk.Tk()
+ app = WarehouseGUI(root)
+ root.mainloop()
+
+if __name__ == "__main__":
+ main()
\ No newline at end of file
diff --git a/pythonProject1/登录.py b/pythonProject1/登录.py
new file mode 100644
index 0000000..ebe702e
--- /dev/null
+++ b/pythonProject1/登录.py
@@ -0,0 +1,51 @@
+import tkinter as tk
+from tkinter import messagebox
+from warehouse_gui import WarehouseGUI # 假设这是仓库管理系统的GUI类
+
+
+class LoginGUI:
+ def __init__(self, master):
+ self.master = master
+ master.title("登录界面")
+
+ self.username_label = tk.Label(master, text="用户名:")
+ self.username_label.pack()
+ self.username_entry = tk.Entry(master)
+ self.username_entry.pack()
+
+ self.password_label = tk.Label(master, text="密码:")
+ self.password_label.pack()
+ self.password_entry = tk.Entry(master, show="*")
+ self.password_entry.pack()
+
+ self.login_button = tk.Button(master, text="登录", command=self.validate_login)
+ self.login_button.pack()
+
+ def validate_login(self):
+ username = self.username_entry.get()
+ password = self.password_entry.get()
+
+ # 这里应该有一个验证用户名和密码的逻辑,比如查询数据库
+ # 为了简化,这里直接使用硬编码的用户名和密码做示例
+ valid_username = "admin"
+ valid_password = "123456"
+
+ if username == valid_username and password == valid_password:
+ messagebox.showinfo("登录成功", "欢迎,管理员!")
+ self.master.destroy() # 销毁登录界面
+ self.start_warehouse_app() # 启动仓库管理系统界面
+ else:
+ messagebox.showerror("登录失败", "用户名或密码错误!")
+
+
+
+ def start_warehouse_app(self):
+ root = tk.Tk()
+ WarehouseGUI(root) # 假设WarehouseGUI是仓库管理系统的主界面类
+ root.mainloop()
+
+
+if __name__ == "__main__":
+ login_root = tk.Tk()
+ LoginGUI(login_root)
+ login_root.mainloop()
\ No newline at end of file
diff --git a/pythonProject1/登录.zip b/pythonProject1/登录.zip
new file mode 100644
index 0000000000000000000000000000000000000000..cc8a7e8d5d182055eb2dc6cab6204a8045979625
GIT binary patch
literal 857
zcmWIWW@Zs#U|`^2m>97=;`Y+Lyf2v;7&zG(7=Vaj>+wT-^a?6lLw)^k8%XR^{wTkw
zz;pSkOLqJodwpgt^OP}vE5Z6|T8GLyA>#+v{Dcj{0wh@(Zy#|eapEv_c8!QBFFis<*(HvyNy*|X)e&aAk@VcM
zPUq?3-%qCfKc^@w=`itRV|#wt$-K3{AG@40*v+hSrTq3Kp9NC4bPP14qfVUNu=Y^q
zCLyNN8v2uuMQ->fe%*Yzv{>tWTdoic;Ox^CsGEPoDf}ig{mnt9@I+
z*9mjV{@m8*OxF)xH9;^^d&Vx+<$_LPPmcS~v#b8+B-VVb+bQgGW>{3HV((9pr2&%L
zglbQ1{C9b+Qct>V#QMj*%D1$N3JQhpj?k&f=09Edi%tGX2MT$p{dF_=&L7~-$Rxsm
eJ3j!k1P~~INqFuE@MdKLi7*18DUjx42Jryd(2MQ>
literal 0
HcmV?d00001