示例#1
0
def home_del():
    '''
    功能:增加商品
    返回值:模板home_del.html
    
    '''
    username = session.get("username")
    if not username:
        return redirect('/login')
    if request.method == "GET":
        return render_template("home_del.html", username=username)
    elif request.method == "POST":
        f = request.form.get("selected")
        w = request.form.get("way")

        if f == "get_byid":
            g = goods.good()
            g.set_gid(w)
            gs = good_operation.get_byid(g)
            good_operation.delete_good(g)
            gs = (gs, )
            return render_template("home_del.html", gs=gs, username=username)
        elif f == "get_byname":
            g = goods.good()
            g.set_gname(w)
            gs = good_operation.get_byname(g)
            good_operation.delete_good_byname(g)
            gs = (gs, )
            return render_template("home_del.html", gs=gs, username=username)
示例#2
0
def home_find():
    '''
    功能:查询商品(查找所有、ID查找、名称查找、)
    返回值:模板home.html
    
    '''
    username = session.get("username")
    if not username:
        return redirect('/login')
    if request.method == "GET":
        return render_template("home.html", username=username)
    elif request.method == "POST":
        f = request.form.get("selected")
        w = request.form.get("way")
        if f == "get_all":
            gs = good_operation.get_all()
        elif f == "get_byid":
            g = goods.good()
            g.set_gid(w)
            gs = good_operation.get_byid(g)
            gs = (gs, )
        elif f == "get_byname":
            g = goods.good()
            g.set_gname(w)
            gs = good_operation.get_byname(g)
            gs = (gs, )

        elif f == "get_blurname":
            gs = good_operation.get_blurname(w)

        return render_template("home.html", gs=gs, username=username)
示例#3
0
def home_upd():
    '''
    功能:增加商品
    返回值:模板home_upd.html
    
    '''
    username = session.get("username")
    if not username:
        return redirect('/login')
    if request.method == "GET":
        return render_template("home_upd.html", username=username)
    elif request.method == "POST":
        gid = request.form.get("gid")
        gname = request.form.get("gname")
        gprice = request.form.get("gprice")
        gnums = request.form.get("gnums")
        g = goods.good()
        g.set_gid(gid)
        g.set_gname(gname)
        g.set_gprice(gprice)
        g.set_gnum(gnums)
        good_operation.update_good(g)
        gs = good_operation.get_byid(g)
        gs = (gs, )
        return render_template("home_upd.html", gs=gs, username=username)
示例#4
0
def home_add():
    '''
    功能:增加商品
    返回值:模板home_add.html
    
    '''
    username = session.get("username")
    if not username:
        return redirect('/login')
    if request.method == "GET":
        return render_template("home_add.html", username=username)
    elif request.method == "POST":
        gname = request.form.get("gname")
        gprice = request.form.get("gprice")
        gnums = request.form.get("gnums")
        g = goods.good()
        g.set_gname(gname)
        g.set_gprice(gprice)
        g.set_gnum(gnums)

        # 若数据库中该商品名已存在,则修改商品价格并在原库存上加上新增数量
        g_tmp = good_operation.get_byname(g)
        if g_tmp:
            g.set_gnum(int(g.get_gnum()) + (g_tmp[3]))
            g.set_gid(g_tmp[0])
            good_operation.update_good(g)
            gs = good_operation.get_byname(g)
            gs = (gs, )
            return render_template("home_add.html", gs=gs, username=username)

        good_operation.add_good(g)
        gs = good_operation.get_byname(g)
        gs = (gs, )
        return render_template("home_add.html", gs=gs, username=username)
示例#5
0
def main():
    menu()
    while True:
        op = input("请输入功能菜单:")

        if op == "1":
            name = input("请输入商品名称:")
            try:
                price = float(input("请输入商品单价:"))
                num = int(input("请输入商品数量:"))
            except:
                print("输入有误!")
                continue
            g = goods.good()
            g.set_gname(name)
            g.set_gprice(price)
            g.set_gnum(num)
            good_operation.add_good(g)
            print("商品添加成功!")

        elif op == "2":
            print("*" * 30 + "商品查询菜单" + "*" * 30)
            print("1.查询所有商品  2.通过商品ID查询  3.通过商品名称查询")
            opf = input("请输入查询菜单:")
            if opf == "1":
                rows = good_operation.get_all()
                print("-" * 40)
                print("{:<10}{:<10}{:<10}{:<10}".format(
                    "ID", "名称", "单价", "数量"))
                print("-" * 40)
                for one in rows:
                    print("{:<10}{:<10}{:<13}{:<10}".format(
                        one[0], one[1], one[2], one[3]))
                print("-" * 40)

            elif opf == "2":
                try:
                    gid = int(input("请输入商品ID:"))
                except:
                    print("输入有误!")
                    continue
                g = goods.good()
                g.set_gid(gid)
                row = good_operation.get_byid(g)
                print("-" * 40)
                print("{:<10}{:<10}{:<10}{:<10}".format(
                    "ID", "名称", "单价", "数量"))
                print("-" * 40)
                print("{:<10}{:<10}{:<13}{:<10}".format(
                    row[0], row[1], row[2], row[3]))
                print("-" * 40)

            elif opf == "3":
                name = input("请输入商品名称:")
                g = goods.good()
                g.set_gname(name)
                row = good_operation.get_byname(g)
                print("-" * 40)
                print("{:<10}{:<10}{:<10}{:<10}".format(
                    "ID", "名称", "单价", "数量"))
                print("-" * 40)
                print("{:<10}{:<10}{:<13}{:<10}".format(
                    row[0], row[1], row[2], row[3]))
                print("-" * 40)

            else:
                print("输入有误!")

        elif op == "3":
            try:
                gid = int(input("请输入要修改的商品ID:"))
                name = input("请输入修改后商品名称:")
                price = float(input("请输入修改后商品单价:"))
                num = int(input("请输入修改后商品数量:"))
            except:
                print("输入有误!")
                continue
            g = goods.good()
            g.set_gname(name)
            g.set_gprice(price)
            g.set_gnum(num)
            good_operation.update_good(g)
            print("商品增加成功!")

        elif op == "4":
            try:
                gid = int(input("请输入商品ID:"))
            except:
                print("输入有误!")
                continue
            g = goods.good()
            g.set_gid(gid)
            good_operation.delete_good(g)
            print("商品删除成功!")

        elif op == "5":
            sys.exit()

        else:
            print("输入有误!")
            continue