diff --git a/cangku/.keep b/cangku/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/cangku/test.py b/cangku/test.py new file mode 100644 index 0000000000000000000000000000000000000000..a6db07105f2d1db08ca8ac392899b5c5f9f17255 --- /dev/null +++ b/cangku/test.py @@ -0,0 +1,805 @@ +from ctypes import alignment +from tkinter import * +import tkinter.messagebox +from tkinter import ttk +from turtle import bgcolor +import psycopg2 +import sys +import time + +def center(window, w, h): # 设置窗口大小且居中 + ws = window.winfo_screenwidth() + hs = window.winfo_screenheight() + x = (ws / 2) - (w / 2) + y = (hs / 2) - (h / 2) + window.geometry("{:.0f}x{:.0f}+{:.0f}+{:.0f}".format(w, h, x, y)) +def get_connect(): # 获取连接 + connect = psycopg2.connect(dbname="cangku", + user="admin",#r_1 + pw ="1qaz0p0p.",#rrrr_1111 + host="192.168.0.115", + port="26000") + connect.set_client_encoding('utf8') + return connect +def execute_sql(sql): # 执行SQL语句并返回执行结果的游标 + print(sql) + connect = get_connect() + cursor = connect.cursor() + cursor.execute(sql) + connect.commit() + return cursor +class Main(Frame): + """主窗口""" + flag = None + def __init__(self, master): + Frame.__init__(self, master) + self.pack(fill=BOTH, expand=YES) + self.master.geometry("1200x800") + self.master.title("仓库管理系统") + self.frame_top = Frame(self) + self.frame_top.pack(side="top", fill=X) + Label(self.frame_top, text="仓库管理系统", font=("微软雅黑", 30), fg='black', bg='#9DC3E7').pack(fill=X) + self.frame_bottom = Frame(self) # 下方frame + self.frame_bottom.pack(side="bottom", fill=BOTH, expand=YES) + frame_left = FrameLeft(self.frame_bottom) # 下方左边 + frame_left.pack(side="left", fill=Y) + self.frame_right = Home(self.frame_bottom) # 下方右边 + self.frame_right.pack(side="right", fill=BOTH, expand=YES) +def go_home(win): # 返回主页 + win.frame_right.destroy() + win.frame_right = Home(Main.flag.frame_bottom) + win.frame_right.pack(side="right", fill=BOTH, expand=YES) +def search_member(window): # 查询, 查看管理员信息 + window.frame_right.destroy() + window.frame_right = Frame(Main.flag.frame_bottom) + window.frame_right.pack(side="right", fill=BOTH, expand=YES) + frame_top = Frame(window.frame_right) + frame_top.pack(side='top', fill=BOTH) + frame_bottom = Frame(window.frame_right) + frame_bottom.pack(side='bottom', fill=BOTH, expand=YES) + Label(frame_top, text='查询查看管理员信息:', font=('楷体', 18), fg='blue').pack(side='left', fill=BOTH, expand=YES) + label_list = [Label(frame_top, text='管理员编号:'), Entry(frame_top), Label(frame_top, text='管理员姓名:'), + Entry(frame_top)] + for label in label_list: + label.pack(side="left", fill=X, expand=YES, padx=3, pady=2) + scrollbar = Scrollbar(frame_bottom) + scrollbar.pack(side='right', fill=Y) + tree = ttk.Treeview(frame_bottom, columns=list(range(5)), show='headings', yscrollcommand=scrollbar.set) + column_name = ["管理员编号", "姓名", "性别", "住址", "联系电话"] + for i in range(5): + tree.column(str(i), anchor='w') + tree.heading(str(i), text=column_name[i], anchor='w') + tree.pack(fill=BOTH, expand=YES) + for row in execute_sql("SELECT * FROM member;"): + tree.insert('', 'end', values=row) + scrollbar.config(command=tree.yview) + def show_all(): + [tree.delete(item) for item in tree.get_children()] + for new_row in execute_sql("SELECT * FROM member;"): + tree.insert('', 'end', values=new_row) + def no_search(event): + [tree.delete(item) for item in tree.get_children()] + sql = "SELECT * FROM member where mno={}" + for row_search in execute_sql(sql.format(label_list[1].get())): + tree.insert('', 'end', values=row_search) + def name_search(event): + [tree.delete(item) for item in tree.get_children()] + sql = "SELECT * FROM member where mname like '%{}%'" + for row_search in execute_sql(sql.format(label_list[3].get())): + tree.insert('', 'end', values=row_search) + + popup_menu = Menu(frame_bottom, tearoff=0) + def is_select(): # 判断Treeview中是否有行被选中 + flag = False + for elem in tree.selection(): + flag = True + return flag + def alter(): # 修改管理员信息 + if is_select(): + for elem in tree.selection(): + win = Toplevel() + win.grab_set() # 模态 + win.focus() + center(win, 300, 400) + labels = [Label(win, text='修改管理员信息', fg='blue', font=('楷体', 14)), + Label(win, text='管理员编号:' + tree.item(elem, 'values')[0]), + Label(win, text="姓名"), Entry(win), + Label(win, text="性别"), Entry(win), + Label(win, text="住址"), Entry(win), + Label(win, text="联系电话"), Entry(win)] + for l in labels: + l.pack() + def confirm(): # 确认添加事件 + sql = "update member set mname='%s', msex='%s', maddress='%s', mphone='%s' where mno='%s'" + data = [] + for text in labels[3::2]: # 切片 获取Entry, 再将其上面的文本内容添加到data里 + data.append(text.get()) + data.append(tree.item(elem, 'values')[0]) + try: + execute_sql(sql % tuple(data)) # 字符串格式化 + tkinter.messagebox.showinfo("SUCCEED", "修改成功!") + show_all() + win.destroy() + except psycopg2.Error: + tkinter.messagebox.showerror("ERROR", "输入有误!") + win.focus() + Button(win, text='确认修改', command=lambda: confirm()).pack() + else: + tkinter.messagebox.showerror("ERROR", "未选择管理员!") + def delete(): # 删除管理员信息 + if is_select(): + if tkinter.messagebox.askokcancel('警告', '确认删除该管理员信息吗?'): + for elem in tree.selection(): + try: + execute_sql("delete from member where mno='{}'".format(tree.item(elem, 'values')[0])) + tkinter.messagebox.showinfo('Succeed', '删除成功!') + show_all() + except psycopg2.Error: + tkinter.messagebox.showerror('Failed', '删除失败,请先删除该管理员的销售记录!') + else: + tkinter.messagebox.showerror('ERROR', '未选择管理员!') + def popup(event): # 弹出右键菜单 + popup_menu.post(event.x_root, event.y_root) + popup_menu.add_command(label='修改', command=lambda: alter()) + popup_menu.add_separator() + popup_menu.add_command(label='删除', command=lambda: delete()) + label_list[1].bind('', no_search) + label_list[3].bind('', name_search) + button = Button(frame_top, text='显示所有', font=('楷体', 14), command=show_all) + button.pack(side='left', fill=X, expand=YES, padx=3, pady=5) + tree.bind("", popup) +def search_wine(window): # 查询, 查看货物信息 + window.frame_right.destroy() + window.frame_right = Frame(Main.flag.frame_bottom) + window.frame_right.pack(side="right", fill=BOTH, expand=YES) + frame_top = Frame(window.frame_right) + frame_top.pack(side='top', fill=BOTH) + frame_bottom = Frame(window.frame_right) + frame_bottom.pack(side='bottom', fill=BOTH, expand=YES) + Label(frame_top, text='查询查看货物信息:', font=('楷体', 18), fg='blue').pack(side='left', fill=BOTH, expand=YES) + label_list = [Label(frame_top, text='货物编号'), Entry(frame_top, width=7), Label(frame_top, text='选择货物类型')] + for label in label_list: + label.pack(side="left", fill=X, expand=YES, padx=3, pady=2) + scrollbar = Scrollbar(frame_bottom) + scrollbar.pack(side='right', fill=Y) + tree = ttk.Treeview(frame_bottom, columns=list(range(7)), show='headings', yscrollcommand=scrollbar.set) + column_name = ["货物编号", "货物类型", "单价", "年份", "产地", "颜色", "是否售出"] + for i in range(7): + tree.column(str(i), width=100, anchor='w') + tree.heading(str(i), text=column_name[i], anchor='w') + tree.column('3', width=120) + tree.pack(fill=BOTH, expand=YES) + for row in execute_sql("SELECT * FROM wine;"): + tree.insert('', 'end', values=row) + scrollbar.config(command=tree.yview) + def show_all(): + [tree.delete(item) for item in tree.get_children()] + for new_row in execute_sql("SELECT * FROM wine;"): + tree.insert('', 'end', values=new_row) + def no_search(event): + [tree.delete(item) for item in tree.get_children()] + sql = "SELECT * FROM wine where wno={}" + for row_search in execute_sql(sql.format(label_list[1].get())): + tree.insert('', 'end', values=row_search) + def show_no(): + [tree.delete(item) for item in tree.get_children()] + for new_row in execute_sql("SELECT * FROM wine where wsaled='否'"): + tree.insert('', 'end', values=new_row) + def show_yes(): + [tree.delete(item) for item in tree.get_children()] + for new_row in execute_sql("SELECT * FROM wine where wsaled='是';"): + tree.insert('', 'end', values=new_row) + popup_menu = Menu(frame_bottom, tearoff=0) + def is_select(): # 判断Treeview中是否有行被选中 + flag = False + for elem in tree.selection(): + flag = True + return flag + def alter(): # 修改货物信息 + if is_select(): + for elem in tree.selection(): + win = Toplevel() + win.grab_set() # 模态 + win.focus() + center(win, 300, 400) + labels = [Label(win, text='修改货物信息', fg='blue', font=('楷体', 14)), + Label(win, text='货物编号:' + tree.item(elem, 'values')[0]), + Label(win, text="类型"), Entry(win), + Label(win, text="单价"), Entry(win), + Label(win, text="年份"), Entry(win), + Label(win, text="产地"), Entry(win), + Label(win, text="颜色"), Entry(win)] + for l in labels: + l.pack() + def confirm(): # 确认添加事件 + sql = "update wine set wtype='%s', wprice=%s, wyear=%s, waddress='%s', wcolor='%s' where wno='%s'" + data = [] + for text in labels[3::2]: # 切片 获取Entry, 再将其上面的文本内容添加到data里 + data.append(text.get()) + data.append(tree.item(elem, 'values')[0]) + try: + execute_sql(sql % tuple(data)) # 字符串格式化 + tkinter.messagebox.showinfo("SUCCEED", "修改成功!") + show_all() + win.destroy() + except psycopg2.Error: + tkinter.messagebox.showerror("ERROR", "输入有误!") + win.focus() + Button(win, text='确认修改', command=lambda: confirm()).pack() + else: + tkinter.messagebox.showerror("ERROR", "未选择货物!") + def delete(): # 删除货物信息 + if is_select(): + if tkinter.messagebox.askokcancel('警告', '确认删除该货物信息吗?'): + for elem in tree.selection(): + try: + execute_sql("delete from wine where wno='{}'".format(tree.item(elem, 'values')[0])) + tkinter.messagebox.showinfo('Succeed', '删除成功!') + show_all() + except psycopg2.Error: + tkinter.messagebox.showerror('Failed', '删除失败,请先删除该货物的销售记录!') + else: + tkinter.messagebox.showerror('ERROR', '未选择货物!') + def popup(event): # 弹出右键菜单 + popup_menu.post(event.x_root, event.y_root) + def price_sort(): + [tree.delete(item) for item in tree.get_children()] + for new_row in execute_sql("SELECT * FROM wine order by wprice"): + tree.insert('', 'end', values=new_row) + def age_sort(): + [tree.delete(item) for item in tree.get_children()] + for new_row in execute_sql("SELECT * FROM wine order by wyear"): + tree.insert('', 'end', values=new_row) + tree.heading("0", text="货物编号", command=lambda: show_all()) # 点击表头排序 + tree.heading("2", text="单价", command=lambda: price_sort()) # 点击表头排序 + tree.heading("3", text="年份", command=lambda: age_sort()) # 点击表头排序 + popup_menu.add_command(label='修改', command=lambda: alter()) + popup_menu.add_separator() + popup_menu.add_command(label='删除', command=lambda: delete()) + label_list[1].bind('', no_search) # 回车 按货物编号查询 + def show(event): + [tree.delete(item) for item in tree.get_children()] + for new_row in execute_sql("select * from wine where wtype='{}'".format(cmb.get())): + tree.insert('', 'end', values=new_row) + type_p = [] + for result in execute_sql("select distinct wtype from wine"): + type_p.append(result) + cmb = ttk.Combobox(frame_top, value=type_p, state='readonly', width=5) # 添加选择货物类型的下拉列表 + cmb.pack(side="left", fill=X, expand=YES, padx=3, pady=2) + cmb.bind("<>", show) + Label(frame_top, text='价格区间').pack(side="left", fill=X, expand=YES, padx=3, pady=2) + left = Entry(frame_top, width=8) + left.pack(side="left", fill=X, expand=YES, padx=0, pady=2) + Label(frame_top, text='至').pack(side="left", fill=X, expand=YES, padx=0, pady=2) + right = Entry(frame_top, width=8) + right.pack(side="left", fill=X, expand=YES, padx=0, pady=2) + def range_search(event): + [tree.delete(item) for item in tree.get_children()] + sql = "SELECT * FROM wine where wprice>={} and wprice<={};" + for new_row in execute_sql(sql.format(left.get(), right.get())): + tree.insert('', 'end', values=new_row) + right.bind('', range_search) + button_no = Button(frame_top, text='未售出', font=('楷体', 12), command=show_no) + button_yes = Button(frame_top, text='已售出', font=('楷体', 12), command=show_yes) + button = Button(frame_top, text='显示所有', font=('楷体', 12), command=show_all) + button_no.pack(side='left', fill=X, expand=YES, padx=3, pady=5) + button_yes.pack(side='left', fill=X, expand=YES, padx=3, pady=5) + button.pack(side='left', fill=X, expand=YES, padx=3, pady=5) + tree.bind("", popup) +def search_sets(window): # 查询, 查看物流信息 + window.frame_right.destroy() + window.frame_right = Frame(Main.flag.frame_bottom) + window.frame_right.pack(side="right", fill=BOTH, expand=YES) + frame_top = Frame(window.frame_right) + frame_top.pack(side='top', fill=BOTH) + frame_bottom = Frame(window.frame_right) + frame_bottom.pack(side='bottom', fill=BOTH, expand=YES) + Label(frame_top, text='查询查看物流信息:', font=('楷体', 18), fg='blue').pack(side='left', fill=BOTH, expand=YES) + label_list = [Label(frame_top, text='产品编号:'), Entry(frame_top), Label(frame_top, text='产品名称:'), + Entry(frame_top)] + for label in label_list: + label.pack(side="left", fill=X, expand=YES, padx=3, pady=2) + scrollbar = Scrollbar(frame_bottom) + scrollbar.pack(side='right', fill=Y) + tree = ttk.Treeview(frame_bottom, columns=list(range(4)), show='headings', yscrollcommand=scrollbar.set) + column_name = ["产品编号", "产品名称", "单价", "供货商"] + for i in range(4): + tree.column(str(i), anchor='w') + tree.heading(str(i), text=column_name[i], anchor='w') + tree.pack(fill=BOTH, expand=YES) + for row in execute_sql("SELECT * FROM sets;"): + tree.insert('', 'end', values=row) + scrollbar.config(command=tree.yview) + def show_all(): + [tree.delete(item) for item in tree.get_children()] + for new_row in execute_sql("SELECT * FROM sets;"): + tree.insert('', 'end', values=new_row) + def no_search(event): + [tree.delete(item) for item in tree.get_children()] + sql = "SELECT * FROM sets where sno={}" + for row_search in execute_sql(sql.format(label_list[1].get())): + tree.insert('', 'end', values=row_search) + def name_search(event): + [tree.delete(item) for item in tree.get_children()] + sql = "SELECT * FROM sets where sname like '%{}%'" + for row_search in execute_sql(sql.format(label_list[3].get())): + tree.insert('', 'end', values=row_search) + popup_menu = Menu(frame_bottom, tearoff=0) + def is_select(): # 判断Treeview中是否有行被选中 + flag = False + for elem in tree.selection(): + flag = True + return flag + def alter(): # 修改物流信息 + if is_select(): + for elem in tree.selection(): + win = Toplevel() + win.grab_set() # 模态 + win.focus() + center(win, 300, 400) + labels = [Label(win, text='修改物流信息', fg='blue', font=('楷体', 14)), + Label(win, text='产品编号:' + tree.item(elem, 'values')[0]), + Label(win, text="产品名称"), Entry(win), + Label(win, text="价格"), Entry(win), + Label(win, text="供货商"), Entry(win)] + for l in labels: + l.pack() + def confirm(): # 确认添加事件 + sql = "update sets set sname='%s', sprice='%s', sprovider='%s' where sno='%s'" + data = [] + for text in labels[3::2]: # 切片 获取Entry, 再将其上面的文本内容添加到data里 + data.append(text.get()) + data.append(tree.item(elem, 'values')[0]) + try: + execute_sql(sql % tuple(data)) # 字符串格式化 + tkinter.messagebox.showinfo("SUCCEED", "修改成功!") + show_all() + win.destroy() + except psycopg2.Error: + tkinter.messagebox.showerror("ERROR", "输入有误!") + win.focus() + Button(win, text='确认修改', command=lambda: confirm()).pack() + else: + tkinter.messagebox.showerror("ERROR", "未选择物流!") + def delete(): # 删除物流信息 + if is_select(): + if tkinter.messagebox.askokcancel('警告', '确认删除该物流吗?'): + for elem in tree.selection(): + try: + execute_sql("delete from sets where sno='{}'".format(tree.item(elem, 'values')[0])) + tkinter.messagebox.showinfo('Succeed', '删除成功!') + show_all() + except psycopg2.Error: + tkinter.messagebox.showerror('Failed', '删除失败,请先删除该物流的销售记录!') + else: + tkinter.messagebox.showerror('ERROR', '未选择物流!') + def popup(event): # 弹出右键菜单 + popup_menu.post(event.x_root, event.y_root) + def price_sort(): + [tree.delete(item) for item in tree.get_children()] + for new_row in execute_sql("SELECT * FROM sets order by sprice"): + tree.insert('', 'end', values=new_row) + tree.heading("0", text="产品编号", command=lambda: show_all()) # 点击表头排序 + tree.heading("2", text="价格", command=lambda: price_sort()) # 点击表头排序 + popup_menu.add_command(label='修改', command=lambda: alter()) + popup_menu.add_separator() + popup_menu.add_command(label='删除', command=lambda: delete()) + label_list[1].bind('', no_search) + label_list[3].bind('', name_search) + button = Button(frame_top, text='显示所有', font=('楷体', 14), command=show_all) + button.pack(side='left', fill=X, expand=YES, padx=3, pady=5) + tree.bind("", popup) +def search_sale(window): # 查询, 查看销售信息 + window.frame_right.destroy() + window.frame_right = Frame(Main.flag.frame_bottom) + window.frame_right.pack(side="right", fill=BOTH, expand=YES) + frame_top = Frame(window.frame_right) + frame_top.pack(side='top', fill=BOTH) + frame_bottom = Frame(window.frame_right) + frame_bottom.pack(side='bottom', fill=BOTH, expand=YES) + Label(frame_top, text='查询查看销售信息:', font=('楷体', 18), fg='blue').pack(side='left', fill=BOTH, expand=YES) + label_list = [Label(frame_top, text='管理员编号'), Entry(frame_top, width=10), + Label(frame_top, text='管理员姓名'), Entry(frame_top, width=10), + Label(frame_top, text='货物编号'), Entry(frame_top, width=10), + Label(frame_top, text='选择货物类型')] + for label in label_list: + label.pack(side="left", fill=X, expand=YES, padx=3, pady=2) + scrollbar = Scrollbar(frame_bottom) + scrollbar.pack(side='right', fill=Y) + tree = ttk.Treeview(frame_bottom, columns=list(range(13)), show='headings', yscrollcommand=scrollbar.set) + column_name = ["管理员编号", "姓名", "性别", "住址", "联系电话", "货物编号", + "货物类型", "单价", "年份", "产地", "颜色", "订单号", "销售日期"] + for i in range(13): + tree.column(str(i), width=50, anchor='w') + tree.heading(str(i), text=column_name[i], anchor='w') + tree.column('4', width=100) + tree.column('3', width=80) + tree.column('11', width=120) + tree.column('12', width=80) + tree.pack(fill=BOTH, expand=YES) + select_all = "select member.mno, mname, msex, maddress, mphone, wine.wno, wtype, wprice, wyear, waddress, " \ + "wcolor, sano, sadate from member, wine, sale where member.mno = sale.mno and wine.wno = sale.wno" + for row in execute_sql(select_all): + tree.insert('', 'end', values=row) + scrollbar.config(command=tree.yview) + def show_all(): # 显示所有销售信息 + [tree.delete(item) for item in tree.get_children()] + for new_row in execute_sql(select_all): + tree.insert('', 'end', values=new_row) + def mno_search(event): # 按管理员编号查找 + [tree.delete(item) for item in tree.get_children()] + sql = "select member.mno, mname, msex, maddress, mphone, wine.wno, wtype, wprice, wyear, waddress, " \ + "wcolor, sano, sadate from member, wine, sale where member.mno = sale.mno and " \ + "wine.wno = sale.wno and member.mno='{}'" + for row_search in execute_sql(sql.format(label_list[1].get())): + tree.insert('', 'end', values=row_search) + def mname_search(event): # 按管理员姓名查找 + [tree.delete(item) for item in tree.get_children()] + sql = "select member.mno, mname, msex, maddress, mphone, wine.wno, wtype, wprice, wyear, waddress, " \ + "wcolor, sano, sadate from member, wine, sale where member.mno = sale.mno and " \ + "wine.wno = sale.wno and member.mname like '%{}%'" + for row_search in execute_sql(sql.format(label_list[3].get())): + tree.insert('', 'end', values=row_search) + def wno_search(event): # 按货物编号查找 + [tree.delete(item) for item in tree.get_children()] + sql = "select member.mno, mname, msex, maddress, mphone, wine.wno, wtype, wprice, wyear, waddress, " \ + "wcolor, sano, sadate from member, wine, sale where member.mno = sale.mno and " \ + "wine.wno = sale.wno and wine.wno='{}'" + for row_search in execute_sql(sql.format(label_list[5].get())): + tree.insert('', 'end', values=row_search) + popup_menu = Menu(frame_bottom, tearoff=0) + def is_select(): # 判断Treeview中是否有行被选中 + flag = False + for elem in tree.selection(): + flag = True + return flag + def alter(): # 修改销售信息 + if is_select(): + for elem in tree.selection(): + win = Toplevel() + win.grab_set() # 模态 + win.focus() + center(win, 300, 600) + labels = [Label(win, text='修改销售信息', fg='blue', font=('楷体', 14)), + Label(win, text='订单编号:' + tree.item(elem, 'values')[0]), + Label(win, text="销售日期"), Entry(win)] + for l in labels: + l.pack() + Label(win, text="选择管理员编号:", fg='MediumBlue', font=("楷体", 12)).pack(pady=10) + cursor_c = execute_sql("SELECT mno FROM member;") + no_c = [] + for result in cursor_c.fetchall(): # 查询所有用户编号添加到下拉列表供用户选择 + no_c.append(result[0]) + cmb_c = ttk.Combobox(win, value=no_c, state='readonly') + cmb_c.pack(pady=2) + string_show_c = [StringVar(), StringVar(), StringVar(), StringVar()] + label_show_c = [Label(win), Label(win), Label(win), Label(win)] + init_name_c = ['姓名:', '性别:', '家庭住址:', '电话:'] + for i in range(4): + string_show_c[i].set(init_name_c[i]) + label_show_c[i]['textvariable'] = string_show_c[i] + label_show_c[i].pack(pady=2) + def show_c(event): + sql_select = "SELECT * FROM member where mno={};" + result_row = execute_sql(sql_select.format(cmb_c.get())).fetchone() + for j in range(4): + string_show_c[j].set(init_name_c[j] + result_row[j + 1]) + cmb_c.bind("<>", show_c) + Label(win, fg='MediumBlue', font=("楷体", 12), text="选择货物编号:").pack(pady=10) + cursor_p = execute_sql("SELECT wno FROM wine where wsaled='否'") + no_p = list() + no_p.append(tree.item(elem, 'values')[5]) + for result in cursor_p.fetchall(): # 查询所有货物编号名添加到下拉列表供用户选择 + no_p.append(result[0]) + cmb_p = ttk.Combobox(win, value=no_p, state='readonly') + cmb_p.pack(pady=2) + string_show_p = [StringVar(), StringVar(), StringVar(), StringVar(), StringVar()] + label_show_p = [Label(win), Label(win), Label(win), Label(win), Label(win)] + init_name_p = ['货物类型:', '单价:', '年份:', '产地:', '颜色:'] + for i in range(5): + string_show_p[i].set(init_name_p[i]) + label_show_p[i]['textvariable'] = string_show_p[i] + label_show_p[i].pack(pady=2) + def show_p(event): + sql_select = "SELECT * FROM wine where wno={};" + result_row = execute_sql(sql_select.format(cmb_p.get())).fetchone() + for j in range(5): + string_show_p[j].set(init_name_p[j] + str(result_row[j + 1])) + cmb_p.bind("<>", show_p) + def confirm(): + sql_update = "update sale set sadate='%s', mno='%s', wno='%s' where sano= '%s'" + data = (labels[3].get(), cmb_c.get(), cmb_p.get(), tree.item(elem, 'values')[11]) + try: + execute_sql(sql_update % data) + tkinter.messagebox.showinfo("SUCCEED", "修改成功") + execute_sql("update wine set wsaled='是' where wno='{}'".format(cmb_p.get())) + win.destroy() + show_all() + except psycopg2.Error: + tkinter.messagebox.showerror("Failed", "修改失败") + win.focus() + + Button(win, text='确认修改', command=lambda: confirm()).pack(pady=20) + else: + tkinter.messagebox.showerror("ERROR", "未选择销售信息!") + def delete(): # 删除货物信息 + if is_select(): + if tkinter.messagebox.askokcancel('警告', '确认删除该销售信息吗?'): + for elem in tree.selection(): + try: + execute_sql("delete from sale where sano='{}'".format(tree.item(elem, 'values')[11])) + tkinter.messagebox.showinfo('Succeed', '删除成功!') + show_all() + except psycopg2.Error: + tkinter.messagebox.showerror('Failed', '删除失败!') + else: + tkinter.messagebox.showerror('ERROR', '未选择销售信息!') + def popup(event): # 弹出右键菜单 + popup_menu.post(event.x_root, event.y_root) + def price_sort(): + [tree.delete(item) for item in tree.get_children()] + for new_row in execute_sql(select_all + " order by wprice"): + tree.insert('', 'end', values=new_row) + def date_sort(): + [tree.delete(item) for item in tree.get_children()] + for new_row in execute_sql(select_all + " order by sadate"): + tree.insert('', 'end', values=new_row) + tree.heading("7", text="单价", command=lambda: price_sort()) # 点击表头排序 + tree.heading("12", text="销售日期", command=lambda: date_sort()) # 点击表头排序 + popup_menu.add_command(label='修改', command=lambda: alter()) + popup_menu.add_separator() + popup_menu.add_command(label='删除', command=lambda: delete()) + label_list[1].bind('', mno_search) # 回车 按管理员编号查询 + label_list[3].bind('', mname_search) # 回车 按管理员姓名查询 + label_list[5].bind('', wno_search) # 回车 按货物编号查询 + def show(event): + [tree.delete(item) for item in tree.get_children()] + sql = "select member.mno, mname, msex, maddress, mphone, wine.wno, wtype, wprice, wyear, waddress, " \ + "wcolor, sano, sadate from member, wine, sale " \ + "where member.mno = sale.mno and wine.wno = sale.wno and wine.wtype='{}'" + for new_row in execute_sql(sql.format(cmb.get())): + tree.insert('', 'end', values=new_row) + type_p = [] + sql = "select distinct wtype from member,wine,sale where member.mno=sale.mno and wine.wno=sale.wno" + for result in execute_sql(sql): + type_p.append(result) + cmb = ttk.Combobox(frame_top, value=type_p, state='readonly', width=5) # 添加选择货物类型的下拉列表 + cmb.pack(side="left", fill=X, expand=YES, padx=3, pady=2) + cmb.bind("<>", show) + button = Button(frame_top, text='显示所有', font=('楷体', 14), command=show_all) + button.pack(side='left', fill=X, expand=YES, padx=3, pady=5) + tree.bind("", popup) +def add_sale(win): # 添加订单信息 + win.frame_right.destroy() + win.frame_right = Frame(Main.flag.frame_bottom) + win.frame_right.pack(side='right', fill=BOTH, expand=YES) + Label(win.frame_right, text="添 加 订 单 信 息:", fg='blue', font=('华文彩云', 16)).pack(pady=10) + string_time = time.strftime("%Y%m%d%H%M%S", time.localtime()) + Label(win.frame_right, text='订单号:' + string_time).pack(pady=10) + Label(win.frame_right, text="销售日期:" + time.strftime("%Y-%m-%d", time.localtime())).pack(pady=10) + Label(win.frame_right, text="选择管理员编号:", fg='MediumBlue', font=("楷体", 14)).pack(pady=10) + cursor_c = execute_sql("SELECT mno FROM member;") + no_c = [] + for result in cursor_c.fetchall(): # 查询所有用户编号添加到下拉列表供用户选择 + no_c.append(result[0]) + cmb_c = ttk.Combobox(win.frame_right, value=no_c, state='readonly') + cmb_c.pack(pady=2) + string_show_c = [StringVar(), StringVar(), StringVar(), StringVar()] + label_show_c = [Label(win.frame_right), Label(win.frame_right), Label(win.frame_right), Label(win.frame_right)] + init_name_c = ['姓名:', '性别:', '家庭住址:', '电话:'] + for i in range(4): + string_show_c[i].set(init_name_c[i]) + label_show_c[i]['textvariable'] = string_show_c[i] + label_show_c[i].pack(pady=2) + def show_c(event): + global string_time + string_time = time.strftime("%Y%m%d%H%M%S", time.localtime()) + sql_select = "SELECT * FROM member where mno={};" + result_row = execute_sql(sql_select.format(cmb_c.get())).fetchone() + for j in range(4): + string_show_c[j].set(init_name_c[j] + result_row[j + 1]) + print(string_show_c[j]) + cmb_c.bind("<>", show_c) + Label(win.frame_right, fg='MediumBlue', font=("楷体", 14), text="选择货物编号:").pack(pady=10) + cursor_p = execute_sql("SELECT wno FROM wine where wsaled='否';") + no_p = [] + for result in cursor_p.fetchall(): # 查询所有未售出货物编号名添加到下拉列表供用户选择 + no_p.append(result[0]) + cmb_p = ttk.Combobox(win.frame_right, value=no_p, state='readonly') + cmb_p.pack(pady=2) + string_show_p = [StringVar(), StringVar(), StringVar(), StringVar(), StringVar()] + label_show_p = [Label(win.frame_right), Label(win.frame_right), + Label(win.frame_right), Label(win.frame_right), Label(win.frame_right)] + init_name_p = ['货物类型:', '单价:', '年份:', '产地:', '颜色:'] + for i in range(5): + string_show_p[i].set(init_name_p[i]) + label_show_p[i]['textvariable'] = string_show_p[i] + label_show_p[i].pack(pady=2) + def show_p(event): + global string_time + string_time = time.strftime("%Y%m%d%H%M%S", time.localtime()) + sql_select = "SELECT * FROM wine where wno={};" + result_row = execute_sql(sql_select.format(cmb_p.get())).fetchone() + for j in range(5): + string_show_p[j].set(init_name_p[j] + str(result_row[j + 1])) + cmb_p.bind("<>", show_p) + def confirm(): + global string_time + sql = "insert into sale values('%s', '%s', '%s', '%s');" + print(sql) + data = (string_time, cmb_c.get(), cmb_p.get(), time.strftime("%Y-%m-%d", time.localtime())) + #print(sql % data) + try: + execute_sql(sql % data) + tkinter.messagebox.showinfo("SUCCEED", "添加成功") + execute_sql("update wine set wsaled='是' where wno='{}'".format(cmb_p.get())) + except psycopg2.Error: + tkinter.messagebox.showerror("Failed", "添加失败") + Button(win.frame_right, text='确认添加', command=lambda: confirm()).pack(pady=20) +class FrameLeft(Frame): # 左侧菜单栏 + def __init__(self, master): + Frame.__init__(self, master, bg='#9DC3E7', width=180, borderwidth=2) + self.pack_propagate(False) # 如果Frame中添加了其它组件,frame大小会变化, 用此方法固定frame大小 + self.create() + def create(self): + Button(self, text="主 页", bg='#5F97D2', font=('华文琥珀', 16), command=lambda: go_home(Main.flag)).pack(fill=X) + Label(self, text="查看信息", bg='#9DC3E7', fg='blue', font=("楷体", 16)).pack(fill=X) + Button(self, text="查看管理员信息",bg='#5F97D2', command=lambda: search_member(Main.flag)).pack(fill=X) + Button(self, text="查看货物信息",bg='#5F97D2', command=lambda: search_wine(Main.flag)).pack(fill=X) + Button(self, text="查看物流信息", bg='#5F97D2',command=lambda: search_sets(Main.flag)).pack(fill=X) + Button(self, text="查看销售信息",bg='#5F97D2', command=lambda: search_sale(Main.flag)).pack(fill=X) + Label(self, text="录入信息", bg='#9DC3E7', fg='blue', font=("楷体", 16)).pack(fill=X) + Button(self, text="添加管理员", bg='#5F97D2',command=lambda: self.add_setsr()).pack(fill=X) + Button(self, text="添加货物", bg='#5F97D2',command=lambda: self.add_wine()).pack(fill=X) + Button(self, text="添加物流", bg='#5F97D2',command=lambda: self.add_sets()).pack(fill=X) + Button(self, text="添加销售信息", bg='#5F97D2',command=lambda: add_sale(Main.flag)).pack(fill=X) + def quit_sys(): + if tkinter.messagebox.askokcancel('提示', '确认退出吗?'): + sys.exit(0) + Label(self, bg='#9DC3E7',font=("楷体", 16)).pack(fill=X) + Button(self, text="退出系统",bg='#5F97D2', font=('楷体', 14), command=lambda: quit_sys()).pack(fill=X) + @staticmethod + def add_setsr(): # 添加用户信息事件 + win = Toplevel() + win.grab_set() + win.focus() + center(win, 300, 400) + labels = [Label(win, text='管理员编号'), Entry(win), + Label(win, text="姓名"), Entry(win), + Label(win, text="性别"), Entry(win), + Label(win, text="住址"), Entry(win), + Label(win, text="联系电话"), Entry(win)] + for label in labels: + label.pack() + def confirm(): # 确认添加事件 + sql = "insert into member values('%s', '%s', '%s', '%s', '%s');" + data = [] + for text in labels[1::2]: # 切片 获取Entry, 再将其上面的文本内容添加到data里 + data.append(text.get()) + try: + execute_sql(sql % tuple(data)) # 字符串格式化 + tkinter.messagebox.showinfo("SUCCEED", "录入成功!") + win.destroy() + except psycopg2.Error: + tkinter.messagebox.showerror("ERROR", "输入有误!") + win.focus() + Button(win, text='确认', command=lambda: confirm()).pack() + @staticmethod + def add_wine(): # 添加货物事件 + win = Toplevel() + win.grab_set() + win.focus() + center(win, 300, 400) + labels = [Label(win, text='货物编号'), Entry(win), + Label(win, text="货物类型"), Entry(win), + Label(win, text="单价"), Entry(win), + Label(win, text="年份"), Entry(win), + Label(win, text="产地"), Entry(win), + Label(win, text="颜色"), Entry(win)] + for label in labels: + label.pack() + def confirm(): # 确认添加事件 + sql = "insert into wine values('%s', '%s', '%s', '%s', '%s', '%s', '否');" + data = [] + for text in labels[1::2]: + data.append(text.get()) + try: + execute_sql(sql % tuple(data)) + tkinter.messagebox.showinfo("SUCCEED", "录入成功!") + win.destroy() + except psycopg2.Error: + tkinter.messagebox.showerror("ERROR", "输入有误!") + win.focus() + Button(win, text='确认', command=lambda: confirm()).pack() + @staticmethod + def add_sets(): # 添加物流事件 + win = Toplevel() + win.grab_set() + win.focus() + center(win, 300, 360) + labels = [Label(win, text='产品编号'), Entry(win), + Label(win, text="产品名称"), Entry(win), + Label(win, text="单价"), Entry(win), + Label(win, text="供货商"), Entry(win)] + for label in labels: + label.pack() + def confirm(): # 确认添加事件 + sql = "insert into sets values('%s', '%s', '%s', '%s');" + data = [] + for text in labels[1::2]: + data.append(text.get()) + try: + execute_sql(sql % tuple(data)) + tkinter.messagebox.showinfo("SUCCEED", "录入成功!") + win.destroy() + except psycopg2.Error: + tkinter.messagebox.showerror("ERROR", "输入有误!") + win.focus() + Button(win, text='确认', command=lambda: confirm()).pack() +class Home(Frame): # 主页 + def __init__(self, master): + Frame.__init__(self, master) + self.label1 = Label(self,text=time.strftime('%Y-%m-%d %H:%M:%S %A', time.localtime(time.time())) + , font=("DBLCDTemp Black", 24),compound="center") + self.label1.after(1000, self.trickit) + self.label1.pack(pady=20) + self.label2 = Label(self,text = " 传统的仓库管理靠人为记忆,货物的信息记录不够全面、丰富,不能直观展示\ +奢侈货物的魅力,更不能充分提升货物给工作和生活带来的快乐和享受。\ +在货物数据方面,传统方式采用纸笔登记、粘贴纸质货物标记、时常需要组织相\ +关人员进行实物手工盘点,不仅工作效率低,浪费了大量人力、物力,而且由于\ +采用手工方式录入数据,极容易产生错误传统货物管理的细粒度非常差,例如:\ +货物什么时间销售的?产地在哪里?是否售出?销售频率如\ +何?管理员有哪些?货的类型等等这些,传统货物管理都无法追溯\ +到细节,货物生命周期管理非常粗放。",font=("DBLCDTemp Black", 14),wraplength = 580,) + self.label2.pack(pady=90) + def trickit(self): + currentTime = time.strftime('%Y-%m-%d %H:%M:%S %A', time.localtime(time.time())) + summary_text='欢迎!!!\n'+'智慧仓库管理系统从每一个细节帮您管理货物。\n'+currentTime + self.label1.config(text=summary_text) + self.update() + self.label1.after(1000, self.trickit) +root = Tk() # 登录界面 +center(root, 300, 220) +root.resizable(0, 0) +root.title("仓库管理系统") +frame = Frame(root) +frame.place(x=30, y=70) +labletext = Label(frame, text="请输入管理员账户密码", font=("宋体", 15)) +labletext.grid(row=0, column=1) +label_1 = Label(frame, text="账号:", font=("宋体", 12)) +label_1.grid(row=1, column=0) +entry = Entry(frame, show=None, font=("Arial", 12)) +entry.grid(row=1, column=1) +entry.focus() +label_2 = Label(frame, text="密码:", font=("宋体", 12)) +label_2.grid(row=2, column=0) +entry_password = Entry(frame, show="*", font=("Arial", 12)) +entry_password.grid(row=2, column=1) +def sign_in(event): # 登录 + cursor = get_connect().cursor() + #获得输入 + sql = "select rpassword from admin where ruser=" + entry.get() + try: + cursor.execute(sql) + password_input =1 # 获取用户输入的密码 + password_db = 1 # 获取数据中的密码 + print(password_db) + if password_input == password_db: # 判断用户输入的密码与数据库中的是否一致 + tkinter.messagebox.showinfo(title="succeed", message="登录成功") + root.destroy() # 销毁当前窗口 + new_win = Tk() # 进入主界面 + # center(root, root.winfo_screenwidth(), root.winfo_screenheight()) # 最大化,效果不好 + center(new_win, 1200, 800) + new_win.title("仓库管理系统") + app = Main(new_win) + Main.flag = app + center(app.master, 1200, 800) + else: + tkinter.messagebox.showerror(title="failed", message="密码错误") + except (psycopg2.Error, TypeError): + tkinter.messagebox.showerror(title="failed", message="密码错误") +entry_password.bind('', sign_in) # 密码输入框回车登录 +button_sign_in = Button(frame, text=' 登 录 ', fg='black', command=lambda: sign_in(None)) +button_sign_in.grid(row=3, column=1) +root.mainloop() + diff --git "a/cangku/\345\237\272\344\272\216opengauss\347\232\204\344\273\223\345\272\223\347\256\241\347\220\206\347\263\273\347\273\237.doc" "b/cangku/\345\237\272\344\272\216opengauss\347\232\204\344\273\223\345\272\223\347\256\241\347\220\206\347\263\273\347\273\237.doc" new file mode 100644 index 0000000000000000000000000000000000000000..dbc9ea2e0c20520037162730c45293e09558ac4b Binary files /dev/null and "b/cangku/\345\237\272\344\272\216opengauss\347\232\204\344\273\223\345\272\223\347\256\241\347\220\206\347\263\273\347\273\237.doc" differ