py mysql结合面向对象,实现类似超市导购机器的功能【3.主菜单目录】
py mysql结合面向对象,实现类似超市导购机器的功能(自我总结)
步骤3:
编写主菜单目录类,根据用户选择,调用不同类方法
注:因为登陆成功后,customers表中的is_login字段值会强制修改为1,表示已登陆状态,所以在退出登陆时,需要将对应客户的is_login值修改为0,未登录状态
实现代码 run():
def run(self): while True: print('-----模块分类-----') print('1.商品信息') print('2.商品种类') print('3.品牌信息') print('4.商品订单') print('5.个人信息') print('6.进入商城') print('7.退出登陆') num = input('请输入操作模块:') if num == '1': g_info = goods_info() g_info.run() elif num == '2': g_cate = goods_cate() g_cate.run() elif num == '3': g_brand = goods_brand() g_brand.run() elif num == '4': g_order = goods_orders() g_order.run() elif num == '5': _customerInfo = customer_info() _customerInfo.run() elif num=='6': _toshop=to_shop() _toshop.run() elif num == '7': sql="""select name,password from customers where is_login=1""" self.cs1.execute(sql) # print(count) for temp in self.cs1.fetchall(): l_name=temp[0] l_psw=temp[1] # print(l_name,l_psw) self.cs1.execute('update customers set is_login=0 where name=%s and password=%s',[l_name,l_psw])
#self.cs1.execute('update customers set is_login=0 where is_login=1') self.conn.commit() break else: print('操作模块选择错误,请重新输入')
----------END

浙公网安备 33010602011771号