从0基础学习Python (16)[进销存系统[案例]](v1.0版本)

从0基础学习Python (Day16)

进销存系统[案例]

​ 前面我们了解了面向对象的开发思想,并且学习了面向对象中的[封装和继承]

​ 今天上传一个自己的小案例,以这个案例为基本框架,用面向对象的思想进行更改,在完成多态的学习后,我们将一起完善这个进销存系统

​ 因为面向对象的编程思想以及实际开发比较难理解,今天我们只来看案例框架,以及基本功能的实现。
先熟悉,才可以更好的学习 😃
先熟悉,才可以更好的学习 😃
先熟悉,才可以更好的学习 😃

本案例使用了面向对象中的封装思想:

import os

# 将库存数据保存至储存
# all_dict = {"001": {"no": "001", "name": "铅笔", "jg": 6, "sl": 5, "dw": "个"},
#             "002": {"no": "002", "name": "刚笔", "jg": 8, "sl": 1, "dw": "个"}}
# with open("SMData.txt", "w", encoding="utf-8") as all_data:
#     all_data.write(str(all_dict))

all_dict = {}
print("===================进销存系统 V1.0======================")
print("1.货物录入")
print("2.货物修改")
print("3.货物移除")
print("4.货物展示")
print("5.按照货物名称统计货物")
print("6.统计总价")
print("7.按照货物名称统计总价")
print("8.货物状态")
print("=======================================================")


def dr_fz():
    if os.path.exists("SMData.txt"):
        with open("SMData.txt", "r", encoding="utf-8")as file:
            ret = file.read()
            global all_dict
            all_dict = eval(ret)
        print("数据加载完成.......")


dr_fz()


class Wenju():
    # 货物录入
    def aaa_fz(self):  # 录入
        while True:
            xh_xh1 = input("请输入编号:")
            if xh_xh1 in all_dict:
                print("该商品已存在")
                continue
            else:
                name1 = input("请输入名称:")
                jg1 = int(input("请输入价格:"))
                sl1 = int(input("请输入数量:"))
                dw1 = input("请输入单位:")
                all_dict1 = {"no": xh_xh1, "name": name1, "jg": jg1, "sl": sl1, "dw": dw1}
                all_dict.setdefault(xh_xh1, all_dict1)
            print("货物已添加")
            print("编号%s||名称%s||价格%s||数量%d||单位%s" % (xh_xh1, name1, jg1, sl1, dw1))
            return

    # 货物修改
    def bbb_fz(self):  # 修改
        while True:
            xh_xh2 = input("请输入你要更改信息的编号")
            if xh_xh2 not in all_dict:
                print("该商品不在我们系统中")
                continue
            else:
                name2 = input("请输入更改名称:")
                jg2 = int(input("请输入更改价格:"))
                sl2 = int(input("请输入更改数量:"))
                dw2 = input("请输入更改单位:")
                all_dict[xh_xh2] = {"no": xh_xh2, "name": name2, "jg": jg2, "sl": sl2, "dw": dw2}
                print("更改完成")
            print(all_dict)
            return

    # 货物移除
    def ccc_fz(self):  # 删除
        while True:
            xh_xh3 = input("请输入编号:")
            if xh_xh3 in all_dict:
                del all_dict[xh_xh3]
                print("删除成功")
                print(all_dict)
                return
            else:
                print("该商品已删除")
                continue

    # 货物展示
    def ddd_fz(self):  # 展示所有信息
        print("=======全部信息如下嘤嘤嘤========")
        for xh_xh4 in all_dict.values():
            print("编号%s||名称%s||价格%s||数量%d||单位%s" % (
                xh_xh4["no"], xh_xh4["name"], xh_xh4["jg"], xh_xh4["sl"], xh_xh4["dw"]))

    # 按照货物名称统计货物
    def eee_fz(self):  # 按名称统计
        while True:
            xh_xh5 = input("请输入你要查询的名称:")
            for xh_xh6 in all_dict.values():
                if xh_xh5 in xh_xh6["name"]:
                    print("编号%s||名称%s||价格%s||数量%d||单位%s" % (
                        xh_xh6["no"], xh_xh6["name"], xh_xh6["jg"], xh_xh6["sl"], xh_xh6["dw"]))
                    return
            else:
                print("查无此商品")
                continue

    # 统计总价
    def fff_fz(self):  # 计算总价
        a = 0
        for a1 in all_dict.values():
            a += a1["jg"]
            a *= a1["sl"]
        print("总价为%d" % a)

    # 按照货物名称统计总价按照货物名称统计总价
    def ggg_fz(self):  # 计算单个价钱
        a = 0
        for xh_xh7 in all_dict.values():
            a = int(xh_xh7["jg"]) * int(xh_xh7["sl"])
            print("%s的总价钱为%d" % (xh_xh7["name"], a))

    # 货物状态
    def hhh_fz(self):
        for xh_xh8 in all_dict.values():
            if xh_xh8["sl"] == 0:
                print("%s状态为断货" % xh_xh8["name"])
            elif 0 < xh_xh8["sl"] <= 10:
                print("%s状态为货源不足" % xh_xh8["name"])
            elif 10 < xh_xh8["sl"] <= 20:
                print("%s状态为货源充足" % xh_xh8["name"])
            else:
                print("%s状态为货物膨胀" % xh_xh8["name"])

    # 保存 数据据
    def dc_fz(self):
        with open("SMData.txt", "w", encoding="utf-8") as file:
            file.write(str(all_dict))
            i = 0
            while i <= 100:
                print("数据备份至云端,进度%d%%.....!!" % i)
                i += 1


while True:
    xh_xh = int(input("请输入你要进行的操作对应的序号:"))
    stationery = Wenju()
    if xh_xh == 1:
        stationery.aaa_fz()
    elif xh_xh == 2:
        stationery.bbb_fz()
    elif xh_xh == 3:
        stationery.ccc_fz()
    elif xh_xh == 4:
        stationery.ddd_fz()
    elif xh_xh == 5:
        stationery.eee_fz()
    elif xh_xh == 6:
        stationery.fff_fz()
    elif xh_xh == 7:
        stationery.ggg_fz()
    elif xh_xh == 8:
        stationery.hhh_fz()
    elif xh_xh == 9:
        stationery.dc_fz()
    else:
        xh_xh00 = int(input("输入1重来,输入其他字符结束"))
        if xh_xh00 == 1:
            continue
        else:
            print("再见,奥里给!!!!!!!!!!!!!!!!!!!!!!")
        break

Day16-------END

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值