py mysql结合面向对象,实现类似超市导购机器的功能【7.商品订单】

py mysql结合面向对象,实现类似超市导购机器的功能(自我总结)

步骤7:

商品订单相关操作实现,主要是各种查询操作

实现代码:

    def run(self):
        while True:
            print('-----商品订单-----')
            print('1.查看商品订单目录')
            print('2.查看商品订单详情')
            print('3.返回上一级')
            num = input('请输入操作类型:')
            if num == '1':
                # 查看商品订单目录
                sql = """select * from orders"""
                count = self.cs1.execute(sql)
                print('共计搜索到%s条商品订单' % count)
                orders_info = self.cs1.fetchall()
                for temp in orders_info:
                    t_len = len(temp)
                    for i in range(t_len):
                        if i == t_len - 1:
                            print('CustomerID:',temp[i])
                        elif i==0:
                            print('OrderID:',temp[i],end='')
                        else:
                            print('OrderDate:',temp[i], end='')

            elif num == '2':
                # 查看商品订单详情
                find_order=input('请输入查询订单号:')
                args='%'+find_order+'%'
                sql = """select ods.id,ods.order_date,c.name,odt.quantity from orders as ods,customers as c,order_detail as odt
                    where ods.customer_id=c.id and ods.id=odt.order_id and ods.id like %s;"""
                count = self.cs1.execute(sql,args)
                print('共计搜索到%s个商品订单' % count)
                orders_info = self.cs1.fetchall()
                for temp in orders_info:
                    t_len = len(temp)
                    for i in range(t_len):
                        if i == t_len - 1:
                            print('Quantity:',temp[i])
                        elif i==0:
                            print('OrderID:',temp[i],end='')
                        else:
                            print(temp[i], end='')

            elif num == '3':
                # 返回上一级
                break
            else:
                print('操作模块选择错误,请重新输入')

 

posted @ 2020-08-14 15:42  zhou&zhou  阅读(157)  评论(0)    收藏  举报