def user_login(userobj, today, weekoftoday): """ 主菜单的2号菜单登录系统模块 :param userobj: 当前用户对象 :param today: 菜单显示的日期 :param weekoftoday: 菜单显示的星期 :return: """ quitflag = False while not quitflag: if userobj.islogin: # 如果用户已经登录,菜单功能2为个人中心,调用另一个菜单模板 index_user_center print( template.index_user_center.format( userobj.name, today, common.numtochr(weekoftoday))) _chooseflag = False while not _chooseflag: _choose = input("选择功能:") if _choose not in ("1", "2", "3", "4", "5", "6"): common.show_message("选择正确的功能编号!", "ERROR") continue else: _chooseflag = True # 返回上级菜单 if _choose == "6": quitflag = True else: # 根据用户按键开始处理,从 template 模块查找各按键对应的模块,通过反射来执行 func_dict = template.user_center_func modulepy = __import__(func_dict[_choose]["module"]) # 1,2,5号键为users类方法, if _choose in ('1', '2', '5'): modulesobj = getattr(modulepy, "users") classobj = getattr(modulesobj, "Users") func = getattr(classobj, func_dict[_choose]["func"]) else: # 3,4为 report 模块的方法 modulesobj = getattr(modulepy, "report") func = getattr(modulesobj, func_dict[_choose]["func"]) func(userobj) else: # 用户未登录,调用 Users类的登录模块 userobj.login() quitflag = True
def user_login(userobj, today, weekoftoday): """ 主菜单的2号菜单登录系统模块 :param userobj: 当前用户对象 :param today: 菜单显示的日期 :param weekoftoday: 菜单显示的星期 :return: """ quitflag = False while not quitflag: if userobj.islogin: # 如果用户已经登录,菜单功能2为个人中心,调用另一个菜单模板 index_user_center print(template.index_user_center.format(userobj.name, today, common.numtochr(weekoftoday))) _chooseflag = False while not _chooseflag: _choose = input("选择功能:") if _choose not in ("1", "2", "3", "4", "5", "6"): common.show_message("选择正确的功能编号!", "ERROR") continue else: _chooseflag = True # 返回上级菜单 if _choose == "6": quitflag = True else: # 根据用户按键开始处理,从 template 模块查找各按键对应的模块,通过反射来执行 func_dict = template.user_center_func modulepy = __import__(func_dict[_choose]["module"]) # 1,2,5号键为users类方法, if _choose in ('1', '2', '5'): modulesobj = getattr(modulepy, "users") classobj = getattr(modulesobj, "Users") func = getattr(classobj, func_dict[_choose]["func"]) else: # 3,4为 report 模块的方法 modulesobj = getattr(modulepy, "report") func = getattr(modulesobj, func_dict[_choose]["func"]) func(userobj) else: # 用户未登录,调用 Users类的登录模块 userobj.login() quitflag = True
if __name__ == "__main__": today = datetime.now().strftime("%Y-%m-%d") weekoftoday = date.weekday(datetime.now()) curruser = Users() # 初始化对账单 report.create_statement_main() # -------- 开始主程序 ------------------- exitflag = False while not exitflag: # 如果用户登录了,显示登录的界面; 未登录显示未登录的界面 if not curruser.islogin: print( template.index_default_menu.format( "", today, common.numtochr(weekoftoday))) else: print( template.index_logined_menu.format( "欢迎您: {0}".format(curruser.name), today, common.numtochr(weekoftoday))) choose = common.input_msg("选择功能编号[1-5]: ", ("1", "2", "3", "4", "5")).strip() if choose == "5": exitflag = True continue # 1 购物商城 if choose == "1": curruser.db_load()
if __name__ == "__main__": today = datetime.now().strftime("%Y-%m-%d") weekoftoday = date.weekday(datetime.now()) curruser = Users() # 初始化对账单 report.create_statement_main() # -------- 开始主程序 ------------------- exitflag = False while not exitflag: # 如果用户登录了,显示登录的界面; 未登录显示未登录的界面 if not curruser.islogin: print(template.index_default_menu.format("", today, common.numtochr(weekoftoday))) else: print(template.index_logined_menu.format("欢迎您: {0}".format(curruser.name), today, common.numtochr(weekoftoday))) choose = common.input_msg("选择功能编号[1-5]: ", ("1", "2", "3", "4", "5")).strip() if choose == "5": exitflag = True continue # 1 购物商城 if choose == "1": curruser.db_load() doshopping(curruser) # 2 用户登录