diff --git a/new_python.py b/new_python.py new file mode 100644 index 0000000..817afa1 --- /dev/null +++ b/new_python.py @@ -0,0 +1,304 @@ +import sys +from tkinter import * + +from SqlClass import sqlclass +class Goods: + def __init__(self, kind, name, band, place, amount, cost, price, ): + self.kind = kind + self.name = name + self.band = band + self.place = place + self.amount = amount + self.cost = cost + self.price = price + + + +sql = sqlclass('localhost',3306,'root','2363305350','python_cs') + +def menu1(): + print(" ") + print(" ") + print(" ") + print(" ") + print(" ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ 超 市 管 理 系 统 ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆") + print(" ") + print(" ") + print(" ************* 1.增添商品 ************* ") + print(" ") + print(" ************* 2.查看商品大全 ************* ") + print(" ") + print(" ************* 3.查询商品 ************* ") + print(" ") + print(" ************* 4.删除商品 ************* ") + print(" ") + print(" ************* 5.修改商品 ************* ") + print(" ") + print(" ************* 0.退出系统 ************* ") + +def menu2(): + print(" ") + print(" ") + print(" ") + print(" ") + print(" ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ 超 市 管 理 系 统 ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆") + print(" ") + print(" ") + print(" ************* 1.查看商品大全 ************* ") + print(" ") + print(" ************* 2.查询商品 ************* ") + print(" ") + print(" ************* 3.购买商品 ************* ") + print(" ") + print(" ************* 0.退出系统 ************* ") + + +def change_menu(): + print(" ************* 1.修改种类 ************* ") + print(" ") + print(" ************* 2.修改名字 ************* ") + print(" ") + print(" ************* 3.修改数量 ************* ") + print(" ") + print(" ************* 4.修改品牌 ************* ") + print(" ") + print(" ************* 5.修改产地 ************* ") + print(" ") + print(" ************* 6.修改进价 ************* ") + print(" ") + print(" ************* 7.修改售价 ************* ") + print(" ") + print(" ************* 8.全部信息 ************* ") + print(" ") + + +def add(): + while True: + print('可输入的商品种类有:水果、日用品、饮料') + # with open('supermarket.txt', 'a') as f: + kind = input('请输入商品的种类:') + name = input('请输入商品的名称:') + band = input('请输入商品的品牌: ') + place = input('请输入商品的产地: ') + amount = input('请输入商品的数量:') + cost = input('请输入商品的进价:') + price = input('请输入商品的售价:') + # goods = Goods(kind, name, band, place, amount, cost, price) + ret = sql.sql_insert('t_commode',{'commod_type':kind,'commod_name':name,'commode_brand':band,'commode_pro':place,'commode_num':amount,'commode_jinjia':cost,'commode_shoujia':price}) + if ret> 0: + print('插入成功') + a = input('是否继续增加商品?(输入1继续,输入2返回菜单)') + if a == '1': + continue + else: + break + + +def view(): + # 查看商品大全 + data = sql.sql_query('t_commode') + print(('id','类别','名称','品牌','产地','数量','进价','售价')) + for i in data: + print(i) + # while True: + # with open("supermarket.txt", 'r') as f: + # lines = f.readlines() + # for line in lines: + # print(line) + # a = input('提示:输入‘2’返回菜单\n') + # if a == '2': + # break + + +def delete(): + while True: + discard = input("输入你想删除的商品id:") + ret = sql.sql_del('t_commode', f"commod_id='{discard}'") + if ret > 0: + print('删除成功') + a = input('提示:输入‘2’返回菜单\n') + if a == '2': + break + # with open('supermarket.txt', 'r+') as f: + # lines = f.readlines() + # f.seek(0) + # for line in lines: + # if discard not in line: + # f.write(line) + # f.truncate() + + +def revise(): + while True: + print('\n') + change_menu() + view() + name = input("请输入你想要修改的商品id: ") + x = int(input('请输入对应功能的数字:')) + + match x: + case 1: + new_info = input("请输入修改后的信息: ") + sql.sql_up('t_commode',{'commod_type':new_info},f"commod_id={name}") + case 2: + new_info = input("请输入修改后的信息: ") + sql.sql_up('t_commode',{'commod_name':new_info},f"commod_id={name}") + case 3: + new_info = input("请输入修改后的信息: ") + sql.sql_up('t_commode',{'commode_num':new_info},f"commod_id={name}") + case 4: + new_info = input("请输入修改后的信息: ") + sql.sql_up('t_commode',{'commode_brand':new_info},f"commod_id={name}") + case 5: + new_info = input("请输入修改后的信息: ") + sql.sql_up('t_commode',{'commode_pro':new_info},f"commod_id={name}") + case 6: + new_info = input("请输入修改后的信息: ") + sql.sql_up('t_commode',{'commod_jinjia':new_info},f"commod_id={name}") + case 7: + new_info = input("请输入修改后的信息: ") + sql.sql_up('t_commode',{'commod_shoujia':new_info},f"commod_id={name}") + case 8: + view() + print('修改成功') + a = input('提示:输入‘2’返回菜单\n') + if a == '2': + break + + +def research(): + while True: + search = input("请输入你想要查询的商品名称: ") + rest = sql.sql_query('t_commode',f"commod_name='{search}'") + print(rest) + a = input('提示:输入‘2’返回菜单\n') + if a == '2': + break + # with open("supermarket.txt", 'r') as f: + # lines = f.readlines() + # for line in lines: + # if search in line: + # print(line) + + +def purchase(): + while True: + view() + name = input('请输入你想购买的商品名称:') + amount = int(input('请输入你想购买的数量:')) + rest = sql.sql_query('t_commode',f"commod_name='{name}'") + shoujia =rest[0][7] + shuliang =rest[0][5] + shuliang -= int(amount) + print('一共花费:', (int(shoujia) * amount)) + sql.sql_up('t_commode',{'commode_num':shuliang},f"commod_name='{name}'") + a = input('提示:输入‘2’返回菜单\n') + if a == '2': + break + + +def main1(): + while True: + menu1() + print('\n') + x = int(input("请输入功能对应的数字:")) + match x: + case 0: + sys.exit() + case 1: + add() + case 2: + view() + case 3: + research() + case 4: + delete() + case 5: + revise() + case _: + print("输入有错,请重新输入") + +def main2(): + while True: + menu2() + print('\n') + x = int(input("请输入功能对应的数字:")) + match x: + case 0: + sys.exit() + case 1: + view() + case 2: + research() + case 3: + purchase() + case _: + print("输入有错,请重新输入") + +def login(): # 用来区分顾客、管理员和退出操作 + print('==========Welcome to Shopping Center==========') + user = input("用户请按1,管理员请按2,退出请按0:") + if user == '2': + login_administrator() + if user == '1': + login_view() + else: + return 0 +def login_administrator(): # 管理员输入 + user_name = input("请输入管理员登录名:") + user_pass = input("请输入管理员登录密码:") + data = sql.sql_query('t_ad', f"ad_acc='{user_name}'") + if len(data)==0: + print('账号输入错误哦!请重新输入') + login() + else: + if data[0][2] == user_pass: + print('登录成功') + main1() + else: + print('密码错误') + login_administrator() + # if user_name == "admin": + # password = input("请输入密码:") + # if password == "5678": + # print("欢迎您,伟大的管理员") + # main1() + # else: + # print("密码错误,请重新输入") + # login_administrator() + # else: + # print("账号输入错误哦!请重新输入") + # login() + +def login_view(): + # 设置登录窗口 + win = Tk() + win.title('登陆') + win.geometry('300x150') + win.resizable(0, 0) + # 设置账号 + Label(text='账号:').place(x=50, y=30) + uname = Entry(win) + uname.place(x=100, y=30) + # 设置密码 + Label(text='密码:').place(x=50, y=70) + pwd = Entry(win) + pwd.place(x=100, y=70) + # 登陆 + def denglu(): + username = uname.get() + password = pwd.get() + data = sql.sql_query('t_user',f"user_acc='{username}'") + if len(data)==0: + print('没有该用户') + else: + if data[0][2] == password: + print('登录成功') + main2() + else: + print('密码错误') + Button(text='登陆', command=denglu).place(x=100, y=110) + win.mainloop() + +if __name__ == '__main__': + login()