基于python-tkinter + sql servers的销售管理系统设计

代码共1800多行,这里仅做部分展示

# coding=utf-8

import os
import pymssql
import tkinter as tk
import tkinter.messagebox
from tkinter import ttk





server = 
user =  
password =  
database =  

LOGO_PATH = "resources" + os.sep + "Library.ico"  # logo文件位置
IMAGE = "resources" + os.sep + "landing.png"
IMAGE2 = "resources" + os.sep + "meau1.png"


class Login():

    def __init__(self):

        self.win = tk.Tk()
        # 给主窗口设置标题内容
        self.win.title("销售管理系统")
        self.win.geometry('512x512')
        self.win.iconbitmap(LOGO_PATH)  # 设置logo
        photo = tkinter.PhotoImage(file=IMAGE)
        self.win.backgroud = tkinter.Label(self.win, image=photo)

        self.win.backgroud.grid()
        self.win.resizable(False, False)  # 锁死窗口大小

        # 创建一个账号输入框,并设置尺寸
        self.input_account = tk.Entry(self.win, width=14, font=("微软雅黑", 13))
        # 创建一个密码输入框,并设置尺寸
        self.input_password = tk.Entry(self.win, show='*', width=14, font=("微软雅黑", 13))

        # 创建一个登录系统的按钮
        self.login_button = tk.Button(self.win, command=self.user_login, text="用户登录")
        self.new_button = tk.Button(self.win, command=self.manager_login, text="管理员登录")

        self.gui_arrang()

        self.win.mainloop()

    # 完成布局
    def gui_arrang(self):

        self.input_account.place(x=190, y=208)
        self.input_password.place(x=190, y=252)
        self.login_button.place(x=190, y=300)
        self.new_button.place(x=270, y=300)
        account = self.input_account.get()

    def manager_login(self):
        account = self.input_account.get()  # 获取输入的账号
        pwd = self.input_password.get()  # 获取输入的密码

        sql = "select * from Sale_management_system.dbo.manager where empid='%s'" % account
        print(sql)
        try:
            cursor.execute(sql)
            result = cursor.fetchall()
            for row in result:
                manager_id = row[0]
                manager_pwd = row[2]
                print("账号:%s,\n\n密码:%s " % (manager_id, manager_pwd))
            if manager_pwd == pwd:
                self.win.destroy()
                manager_Meau(row[0], row[1])
            else:
                tkinter.messagebox.showwarning(title='警告', message='密码有误!')
                self.input_password.delete(0, 'end')
        except:
            print("error!!!")
            tkinter.messagebox.showwarning(title='警告', message='用户名或密码有误!')
            self.input_password.delete(0, 'end')
            self.input_account.delete(0, 'end')

    def user_login(self):
        account = self.input_account.get()  # 获取输入的账号
        pwd = self.input_password.get()  # 获取输入的密码

        sql = "select * from Sale_management_system.dbo.users where custid=%s" % account
        print(sql)
        try:
            cursor.execute(sql)
            result = list(cursor.fetchall())
            for row in result:
                user_id = row[0]
                user_pwd = row[2]
                print("账号:%s,\n\n密码:%s " % (user_id, user_pwd))
            if user_pwd == pwd:
                self.win.destroy()
                user_Meau(row[0], row[1])
            else:
                tkinter.messagebox.showwarning(title='警告', message='密码有误!')
                self.input_password.delete(0, 'end')

        except:
            print("error!!!")
            tkinter.messagebox.showwarning(title='警告', message='用户名或密码有误!')
            self.input_password.delete(0, 'end')
            self.input_account.delete(0, 'end')


class manager_Meau():
    def __init__(self, id, name):
        self.id = id
        self.name = name
        # 创建主窗口,用于容纳其它组件
        self.win = tk.Tk()
        self.win.geometry('800x617')
        # 给主窗口设置标题内容
        self.win.title("销售管理系统——主菜单")
        self.win.iconbitmap(LOGO_PATH)  # 设置logo
        photo = tkinter.PhotoImage(file=IMAGE2)
        self.win.backgroud = tkinter.Label(self.win, image=photo)
        self.win.backgroud.grid()
        self.win.resizable(False, False)  # 锁死窗口大小# 锁死窗口大小

        # 班级信息
        self.salesman_button = tk.Button(self.win, text="员工信息", bg="Skyblue", font=('幼圆', 15),
                                         command=lambda: manager_salesman(id, name, self.win))
        # 教材信息
        self.sales_order_button = tk.Button(self.win, text="订单信息", bg="Skyblue", font=('幼圆', 15),
                                            command=lambda: manager_order(id, name, self.win))
        # 学生信息
        self.department_button = tk.Button(self.win, text="部门信息", bg="Skyblue", font=('幼圆', 15),
                                           command=lambda: manager_department(id, name, self.win))
        # 新增病例
        self.customer_button = tk.Button(self.win, text="顾客信息", bg="Skyblue", font=('幼圆', 15),
                                         command=lambda: manager_customer(id, name, self.win))
        # 管理中心
        self.product_button = tk.Button(self.win, text="产品信息", bg="Skyblue", font=('幼圆', 15),
                                        command=lambda: manager_product(id, name, self.win))

        self.account_button = tk.Button(self.win, text="账号管理", bg="Skyblue", font=('幼圆', 15),
                                        command=lambda: manager_account(id, name, self.win))

        # 个人信息
        self.label_information = tk.Label(self.win, text=self.name + '(管理员)', bg="Dodgerblue", fg="white",
                                          font=('幼圆', 20))

        self.gui_arrang()

        self.win.mainloop()

    def gui_arrang(self):
        self.salesman_button.place(x=0, y=130, width=178, height=60)
        self.sales_order_button.place(x=0, y=190, width=178, height=60)
        self.department_button.place(x=0, y=250, width=178, height=60)
        self.customer_button.place(x=0, y=310, width=178, height=60)
        self.product_button.place(x=0, y=370, width=178, height=60)
        self.account_button.place(x=0, y=430, width=178, height=60)
        self.label_information.place(x=400, y=55)


class user_Meau():
    def __init__(self, id, name):
        self.id = id
        self.name = name
        # 创建主窗口,用于容纳其它组件
        self.win = tk.Tk()
        self.win.geometry('800x617')
        # 给主窗口设置标题内容
        self.win.title("销售管理系统——主菜单")
        self.win.iconbitmap(LOGO_PATH)  # 设置logo
        photo = tkinter.PhotoImage(file=IMAGE2)
        self.win.backgroud = tkinter.Label(self.win, image=photo)
        self.win.backgroud.grid()
        self.win.resizable(False, False)  # 锁死窗口大小# 锁死窗口大小

        # 教材信息
        self.sales_order_button = tk.Button(self.win, text="订单信息", bg="Skyblue", font=('幼圆', 15),
                                            command=lambda: user_order(id, name, self.win))

        # 新增病例
        self.customer_button = tk.Button(self.win, text="顾客信息", bg="Skyblue", font=('幼圆', 15),
                                         command=lambda: user_customer(id, name, self.win))
        # 管理中心
        self.product_button = tk.Button(self.win, text="产品信息", bg="Skyblue", font=('幼圆', 15),
                                        command=lambda: user_product(id, name, self.win))

        self.account_button = tk.Button(self.win, text="修改密码", bg="Skyblue", font=('幼圆', 15),
                                        command=lambda: user_account(id, name, self.win))

        # 个人信息
        self.label_information = tk.Label(self.win, text=self.name + '(用户)', bg="Dodgerblue", fg="white",
                                          font=('幼圆', 20))

        self.gui_arrang()

        self.win.mainloop()

    def gui_arrang(self):
        self.sales_order_button.place(x=0, y=130, width=178, height=60)
        self.customer_button.place(x=0, y=190, width=178, height=60)
        self.product_button.place(x=0, y=250, width=178, height=60)
        self.account_button.place(x=0, y=310, width=178, height=60)
        self.label_information.place(x=400, y=55)


class user_order():
    def __init__(self, id, name, parent_win):
        self.id = id
        self.name = name
        # 创建主窗口,用于容纳其它组件

        # 给主窗口设置标题内容
        parent_win.title("销售管理系统—订单信息")
        self.user_add_button = tk.Button(parent_win, text="* *", bg="LightSteelblue", font=('幼圆', 15),
                                         )
        self.user_delete_button = tk.Button(parent_win, text="* *", bg="LightSteelblue", font=('幼圆', 15),
                                            )
        self.user_change_button = tk.Button(parent_win, text="* *", bg="LightSteelblue", font=('幼圆', 15),
                                            )
        self.user_query_button = tk.Button(parent_win, text="查询", bg="LightSteelblue", font=('幼圆', 15),
                                           command=self.order_query)
        self.columns = ("编号", '日期', '员工编号', '顾客编号', '类别编号', '产品编号', '总价', '数量')
        self.tree = ttk.Treeview(parent_win, show="headings", height=18, columns=self.columns)

        self.tree.column("编号", width=70, anchor='center')
        self.tree.column("日期", width=140, anchor='center')
        self.tree.column("员工编号", width=70, anchor='center')
        self.tree.column("顾客编号", width=70, anchor='center')
        self.tree.column("类别编号", width=70, anchor='center')
        self.tree.column("产品编号", width=70, anchor='center')
        self.tree.column("总价", width=70, anchor='center')
        self.tree.column("数量", width=70, anchor='center')

        self.tree.heading("编号", text='编号')
        self.tree.heading("日期", text='日期')
        self.tree.heading("员工编号", text='员工编号')
        self.tree.heading("顾客编号", text='顾客编号')
        self.tree.heading("类别编号", text='类别编号')
        self.tree.heading("产品编号", text='产品编号')
        self.tree.heading("总价", text='编号')
        self.tree.heading("数量", text='编号')

        self.gui_arrang()

        parent_win.mainloop()

    def gui_arrang(self):
        self.user_add_button.place(x=180, y=130, width=156, height=60)
        self.user_delete_button.place(x=336, y=130, width=156, height=60)
        self.user_change_button.place(x=492, y=130, width=156, height=60)
        self.user_query_button.place(x=648, y=130, width=156, height=60)
        self.tree.place(x=180, y=220)

    def order_query(self):
        x = self.tree.get_children()
        for item in x:
            self.tree.delete(item)
        sql = 'select O.orderno,signdate,empid,custid,line_no,prodid,unitprice,quantity from Sale_management_system.dbo.salesorder as "O" join Sale_management_system.dbo.salesitem as "I" on O.orderno=I.orderno where O.custid=%s' % self.id
        print(sql)
        cursor.execute(sql)
        result = cursor.fetchall()
        if not result:
            tkinter.messagebox.showwarning(title='警告', message='您还没有订单!')
        else:
            for i in range(len(result)):
                self.tree.insert('', 'end', values=result[i])
                print(i)

有需要自行下载,长期解答

https://download.csdn.net/download/m0_52274008/58899827

你可能感兴趣的:(python,数据库开发,数据仓库)