示例#1
0
def updateGoods():
    isList = raw_input(u"是否要列出所有商品 y or n")
    if isList == 'y':
        listGoods()
    id = raw_input(u"请选择要更新商品id:")
    regexId = re.compile(r'\d+')
    if not sql.getGoodsInfosById(id):
        print u"你选择的商品不存在"
        return False

    goodsName = raw_input(u"请输入商品名称:")
    goodsType = raw_input(u"请输入商品类别:")
    goodsPrice = inputPrice()
    if not goodsPrice: return False
    goodsNum = inputNum()
    if not goodsNum: return False

    goodsInfo = {
        'name': goodsName,
        'type': goodsType,
        'price': goodsPrice,
        'num': goodsNum
    }
    if not sql.updateData(id, goodsInfo):
        print u"更新失败"
        return False
    print u"更新成功"
    return True
示例#2
0
def delGoods():
    isList = raw_input(u"是否要列出所有商品 y or n")
    if isList == 'y':
        listGoods()
    id = raw_input(u"请选择要删除商品id:")
    regexId = re.compile(r'\d+')
    if not sql.getGoodsInfosById(id):
        print u"你选择的商品不存在"
        return False
    sql.delData(id)
    return True