微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PyMySQL设计-进销存系统-删除,修改货物~设置

Hello,我又来啦

目录

删除货物

修改货物

设置

总目录


删除货物

首先删除货物,那是简简单单,常规操作,对吧?

    # 实现移除功能
    def remove(self):
        global choice  #因为它是一个全局变量,所以声明一下
        delete = input("请输入货物编号:")
        sql_delete = "delete from " + choice + " where id = " + delete#删除语句
        c = self.bbb_good(delete)#判断是否存在
        if c:
            cursor.execute(sql_delete)
            self.sql()
            print(color.green("成功移除!"))#colorama,有不了解的可以看我前面的文章~
        else:
            print(color.red("没有该货物!"))

    # 判断条件,判断数据库中有没有你要添加的id         这个函数其实早就定义过了
    def bbb_good(self,id):
        global choice
        sql_fetch = "select * from " + choice + " where id >= 1"
        cursor.execute(sql_fetch)
        results = cursor.fetchall()
        for item in results:
            if str(item[0]) == id:
                return True
        return False

修改货物

涉及到前面的文章,不了解的可以看看哦

    #实现修改功能
    def modify(self):
        global choice#全局变量
        sql_fetch = "select * from " + choice + " where id >= 1"
        cursor.execute(sql_fetch)
        results = cursor.fetchall()
        id = input("请输入货物编号:")
        if self.judge(id,isint = True):#判断是否为正整数
            id = int(id)
        else:
            print(color.red("请输入正整数!"))
            return 0
        long = len(results)
        if long >= id and id >= 1:#也可以用前面的bbb_good
            select = input("修改的类型?(名称,数量,单价)")
            if select == "名称":
                name = input("将" + color.green("名称") + "修改为?")
                sql_modify = "update " + choice + " set name = %s where id = %s"#修改语句
                cursor.execute(sql_modify,(name,id))
                self.sql()
            elif select == "数量":
                number = input("将" + color.green("数量") + "修改为?")
                sql_modify = "update " + choice + " set number = %s where id = %s"
                cursor.execute(sql_modify,(number,id))
                self.sql()
            elif select == "单价":
                price = input ("将" + color.green("单价") + "修改为?")
                sql_modify = "update " + choice + " set price = %s where id = %s"
                cursor.execute(sql_modify,(price,id))
                self.sql()
            else:
                print(color.red("输入有误!"))
        else:
            print("该货物不存在!")

    # 判断条件,判断输入的格式是否正确
    def judge(self,str,isint = False):
        if isint:
            try:
                res = int(str)
            except:
                print(color.red("您输入的数据格式为非整数"))
                return False
            else:
                return True
        else:
            try:
                res = float(str)
            except:
                print(color.red("您输入的数据格式为非小数"))
                return False
            else:
                return True

设置

哎呀,完了,要开始水了,不要说我呀QAQ

    #设置     是关于prettytable输出的设置
    def option(self):
        print(color.yellow("按下Enter键可以跳过指定设置"))
        a = input("查看表格样式:* (输入*) - (输入-) | (输入|) + (输入+)")
        if a == "*":#设置输出表格组成
            x.junction_char = "*"
        elif a == "-":
            x.junction_char = "-"
        elif a == "|":
            x.junction_char = "|"
        elif a == "+":
            x.junction_char = "+"
        a = input("查看表格风格(简约 认 精简):")#设置输出表格样式
        if a == "简约":
            x.set_style(pt.PLAIN_COLUMNS)
        elif a == "认":
            x.set_style(pt.DEFAULT)
        elif a == "精简":
            x.set_style(pt.MSWORD_FRIENDLY)

效果展示

认&“+”号

+------+--------+------+------+------+------+
| 编号 |  名称  | 数量 | 单价 | 单位 | 类型 |
+------+--------+------+------+------+------+
|  1   | pizza  |  10  |  86  |  g   | food |
|  2   | pasta  |  20  |  16  |  g   | food |
|  3   | 红烧肉 |  1   |  40  |  g   | food |
+------+--------+------+------+------+------+

简约

编号         名称         数量        单价        单位        类型        
 1          pizza          10          86          g          food
 2          pasta          20          16          g          food
 3          红烧肉         1           40          g          food

精简

| 编号 |  名称  | 数量 | 单价 | 单位 | 类型 |
|  1   | pizza  |  10  |  86  |  g   | food |
|  2   | pasta  |  20  |  16  |  g   | food |
|  3   | 红烧肉 |  1   |  40  |  g   | food |

OK,本篇结束啦,再发一两篇就发布完整代码!

喂喂,别走啊,都看到这了,真的不点个赞么?

总目录

------------

PyMySQL设计-进销存系统-多彩美化 删除表格 创建表格_琉璃果子的博客-CSDN博客

PyMySQL设计-进销存系统-配置及输入_琉璃果子的博客-CSDN博客

PyMySQL设计-进销存系统-查看_琉璃果子的博客-CSDN博客

-----------

原文地址:https://www.jb51.cc/wenti/3284303.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐