pymysql数据库的水果店销售系统之管理员端1.0

在框架上跟客户端1.0很像,就是删几个函数,加几个函数。获取数据、查看水果都是一样的;增删改也只是sql语句的变化,界面按键变了点,其他都没变。

客户端1.0

import tkinter as tk
from tkinter import ttk
import pymysql

# 建立连接
conn = pymysql.connect(host='localhost',
                       port=3306,
                       user='root',
                       database='db1',
                       password='123456',
                       charset='utf8')

# 拿游标
cur = conn.cursor(pymysql.cursors.DictCursor)

fruit_name = []
fruit_price = []
xu_hao = []

def get_shuju():
    # 获取数据
    cur.execute('select * from shop1;')
    lst = cur.fetchall()
    fruit_name.clear()
    fruit_price.clear()
    xu_hao.clear()
    for i in lst:
        fruit_name.append(i['name'])
        fruit_price.append(i['price'])
        xu_hao.append(i['id'])

    conn.commit()

# 上架就是数据库加一行数据
def add():
    # 开小窗
    winNew = tk.Toplevel(win)
    winNew.geometry('320x240')
    winNew.title('上架')
    lb2 = tk.Label(winNew, text='品名')
    lb2.place(relx=0.2, rely=0.2)
    lb2 = tk.Label(winNew, text='价格')
    lb2.place(relx=0.2, rely=0.4)
    ent_name = tk.Entry(winNew, bd=5, width=10)
    ent_name.place(relx=0.3, rely=0.2)
    ent_price = tk.Entry(winNew, bd=5, width=10)
    ent_price.place(relx=0.3, rely=0.4)

    # 数据库操作
    def ad():
        name = str(ent_name.get())
        price = int(float(ent_price.get()))
        sql = 'insert into shop1(name,price) values(%s,%s);'
        cur.execute(sql,(name,price))

    # 点击完成,进行增加数据操作
    bt_finish = tk.Button(winNew, text='完成', command=ad)
    bt_finish.place(relx=0.7, rely=0.8)

def delete():
    winNew = tk.Toplevel(win)
    winNew.geometry('320x240')
    winNew.title('下架')
    lb2 = tk.Label(winNew, text='序号')
    lb2.place(relx=0.2, rely=0.2)
    ent_id = tk.Entry(winNew, bd=5, width=10)
    ent_id.place(relx=0.3, rely=0.2)

    # 数据库操作
    def shan():
        id = int(ent_id.get())
        sql = 'delete from shop1 where id=%s ;'
        cur.execute(sql,id)

    # 关闭
    bt_finish = tk.Button(winNew, text='完成', command=shan)
    bt_finish.place(relx=0.7, rely=0.8)

def change():
    winNew = tk.Toplevel(win)
    winNew.geometry('320x240')
    winNew.title('调价')
    lb2 = tk.Label(winNew, text='序号')
    lb2.place(relx=0.2, rely=0.2)
    lb2 = tk.Label(winNew, text='价格')
    lb2.place(relx=0.2, rely=0.4)
    ent_id = tk.Entry(winNew, bd=5, width=10)
    ent_id.place(relx=0.3, rely=0.2)
    ent_price = tk.Entry(winNew, bd=5, width=10)
    ent_price.place(relx=0.3, rely=0.4)

    # 数据库操作
    def shan():
        id = int(ent_id.get())
        price = int(ent_price.get())
        sql = 'update shop1 set price=%s where id=%s;'
        cur.execute(sql,(price,id))

    # 关闭
    bt_finish = tk.Button(winNew, text='完成', command=shan)
    bt_finish.place(relx=0.7, rely=0.8)

# 界面
win = tk.Tk()
win['bg'] = '#BDBDBD'
win.title('超市')
win.geometry('775x750+400+20')

tk.Label(win, text='公平公平还是公平水果超市\n--------------------------------', width=30, fg='orange', bg='#DF3A01', font=('Arial', 20)).pack()
lb1 = tk.Message(win, text='我来鹅城只办三件事', width=300, fg='orange', bg='#DF3A01', font=('Arial', 20))
lb1.place(relx=0.1, rely=0.5, relwidth=0.8, relheight=0.1)
# 创建表格
table_head = ('fruit name', 'fruit price', 'xu_hao')
table_main = ttk.Treeview(win, height=13, show='headings', columns=table_head)

# 设置表头
table_main.heading('fruit name', text='水果名字')
table_main.heading('fruit price', text='水果价格(US刀了)')
table_main.heading('xu_hao', text='序号')
# 设置位置
table_main.place(x=20, y=80)
# 设置文字对齐
table_main.column('fruit name', width=200, anchor='center')
table_main.column('fruit price', width=200, anchor='center')
table_main.column('xu_hao', width=60, anchor='center')

# 查看水果函数
def table():
    get_shuju()
    x = table_main.get_children()
    for item in x:
        table_main.delete(item)
    for i in range(len(fruit_price)):
        table_main.insert('', i, values=(fruit_name[i], fruit_price[i], xu_hao[i]))

# 展示水果按钮
butt_table = tk.Button(win, text='查看水果', height=2, font=("Arial", 12), width=20, bg='black', fg='pink', command=table)
butt_table.place(x=160, y=280)

# 增加按钮
butt_main = tk.Button(win, text='上架', height=2, font=("Arial", 12), width=20, bg='black', fg='orange', command=add)
butt_main.place(x=75, y=500)
# 删除按钮
butt_main = tk.Button(win, text='下架', height=2, font=("Arial", 12), width=20, bg='black', fg='orange', command=delete)
butt_main.place(x=295, y=500)
# 修改按钮
butt_main = tk.Button(win, text='调价', height=2, font=("Arial", 12), width=20, bg='black', fg='orange', command=change)
butt_main.place(x=510, y=500)
# 关闭
btClose = tk.Button(win, text='关闭', command=win.destroy)
btClose.place(relx=0.8, rely=0.9)

win.mainloop()
cur.close()
conn.close()

我注释都写在代码里或者在上一个文章里,结果发的时候说我文章质量较低, 可能的原因为:篇幅太短,广告涉嫌违规,外链过多,缺少代码,图片涉嫌违规。

发上一个的时候我专门把图删了,以为是图的问题,结果可能是我打广告了或者缺少代码吧。

一、源码描述 本系统基于SSM(Spring+SpringMVC+MyBatis)框架,适用于毕业设计,采用javaweb,基于B/S模式,Myeclipse或者eclipse idea为开发工具,mysql数据库,感兴趣的朋友们可以下载研究一下。 二、功能介绍 1、用户注册:有用户进入系统后,可进行浏览水果蔬菜,若想购买水果蔬菜,必须先进行注册,注册需要填写账号、真实姓名、密码、电话、性别、地址等信息。 2、登录:用户在注册账号之后,就进行登录,然后可以购买水果蔬菜。 3、查看水果蔬菜:在进入系统后,用户可根据水果蔬菜的名字进行搜索,也可根据水果蔬菜的分类进行查看自己想查看的水果蔬菜。 4、加入购物车:用户在选中一个水果蔬菜后,可暂时把水果蔬菜放到购物车中,一起结账。 5、提交订单:用户进入购物车后,可以把加入购物车的水果蔬菜一起下单。 6、查看订单:用户在登录系统后,可以在查看订单里查看自己的订单。 7、水果蔬菜管理:管理员在登录系统后,可以对水果蔬菜进行增删操作,当管理员添加一个水果蔬菜后,该水果蔬菜就会在客户显示出来,当管理员把一个水果蔬菜删除后,该水果蔬菜就会下架,不会在商城首页中显示。 8、客户管理:管理员可对水果蔬菜进行增删改查操作,也可根据客户的名字进行查询单个客户信息。 9、分类管理:分类管理主要有一级分类和二级分类,二级分类是在一级分类的基础上进行的,一级分类和二级分类添加后,会在前台客户列出来。当添加一个水果蔬菜时,会选择水果蔬菜的二级分类,然后在前台就可以根据分类查询出该水果蔬菜。 10、订单管理:前台用户生成的订单,都会在该页面显示出来,并且管理员可对其进行操作。 三、注意事项 1、管理员账号:hsg 密码:hsg 2、开发环境为eclipse idea/Myeclipse均可,含数据库建立脚本,jdk7.0以上,tomcat7以上, 使用ssm框架,jsp/java语言开发。 3、采用jdbc连接方式,数据库版本>mysql5.7需要更改数据库连接等和增加连接驱动,兼容所有mysql版本 4、数据库连接src\applicationContext.xml中和src\com\util\db.java中修改, 5、如果你的mysql数据库密码为空,导入即可运行,方便快捷
好的,下面是一个简单的基于pymysql库连接MySQL实现学生宿舍管理系统的示例代码,供您参考: ```python import pymysql # 连接到数据库 conn = pymysql.connect(host='localhost', port=3306, user='root', password='your_password', db='your_database') # 创建游标对象 cursor = conn.cursor() # 创建学生表 sql_create_student_table = """ CREATE TABLE IF NOT EXISTS student ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(20), age INT, gender VARCHAR(10), dormitory_id INT, FOREIGN KEY (dormitory_id) REFERENCES dormitory(id) ) """ cursor.execute(sql_create_student_table) # 创建宿舍表 sql_create_dormitory_table = """ CREATE TABLE IF NOT EXISTS dormitory ( id INT PRIMARY KEY AUTO_INCREMENT, building VARCHAR(10), room_number INT, capacity INT ) """ cursor.execute(sql_create_dormitory_table) # 插入宿舍数据 sql_insert_dormitory = """ INSERT INTO dormitory (building, room_number, capacity) VALUES ('A', 101, 4), ('A', 102, 4), ('A', 103, 4), ('B', 201, 6), ('B', 202, 6), ('B', 203, 6) """ cursor.execute(sql_insert_dormitory) conn.commit() # 插入学生数据 sql_insert_student = """ INSERT INTO student (name, age, gender, dormitory_id) VALUES ('张三', 18, '男', 1), ('李四', 19, '男', 1), ('王五', 20, '女', 2), ('赵六', 21, '男', 3), ('钱七', 22, '女', 4), ('孙八', 23, '男', 5) """ cursor.execute(sql_insert_student) conn.commit() # 查询学生信息 sql_select_student = """ SELECT student.name, student.age, student.gender, dormitory.building, dormitory.room_number FROM student JOIN dormitory ON student.dormitory_id = dormitory.id """ cursor.execute(sql_select_student) results = cursor.fetchall() # 打印结果 print("学生信息") for row in results: name = row[0] age = row[1] gender = row[2] building = row[3] room_number = row[4] print(f"name: {name}, age: {age}, gender: {gender}, dormitory: {building}{room_number}") # 关闭游标和连接 cursor.close() conn.close() ``` 以上代码中,首先创建了一个学生表和一个宿舍表,然后插入了一些宿舍数据和学生数据,最后查询了学生信息并打印了结果。需要注意的是,这只是一个简单的示例,实际的学生宿舍管理系统需要更加完善和复杂的功能,例如添加、删除、修改学生信息、宿舍信息,查询宿舍剩余床位等等。您可以根据自己的需求进行修改和完善。 希望这能对您有所帮助。如果您还有其他问题,欢迎随时提出。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

在北京挖石油的日子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值