示例#1
0
def PlaceOrder(customer_id,product_id,create_date):
    buying_quantity = int(input("Enter quantity : "))
    search_sql = f"select product_quantity,product_price from product where product_id = {product_id};"
    # product_quantity,product_price
    db,cursor = Connection()
    #print(create_date)
    try:
        cursor.execute(search_sql)
        rs = cursor.fetchall()
        product_price = int(rs[0][1])
        # print(product_price)
        # print(f"Type of product id : {type(rs[0][0])}")
        if(int(rs[0][0]) >= buying_quantity):
            insert_sql = f"""insert into buying(customer_id,product_id,
                        buying_quantity,total_bill,buying_date)
                        values({customer_id},{product_id},{buying_quantity},{product_price*buying_quantity},
                        '{create_date}'
                        );
                        """
            cursor.execute(insert_sql)
            update_sql = f"""update product set product_quantity =  product_quantity - {buying_quantity}
                            where product_id = {product_id};
                        """
            cursor.execute(update_sql)
            db.commit()
            print("Added to your cart!!")
        else:
            print("Out of Stock")
    except Exception as e:
        print(e)
        db.rollback()
    else:
        db.close()
示例#2
0
def DeleteProduct(product_id):
    db, cursor = Connection()
    delete_sql = f"delete from product where product_id={product_id};"
    try:
        cursor.execute(delete_sql)
        db.commit()
    except Exception:
        db.rollback()
        print("Some error in deleting the product")
    else:
        print("Product deleted successfully")
    finally:
        db.close()
示例#3
0
def UpdateQuantity(product_id, product_quantity):
    try:
        db, cursor = Connection()
        update_sql = f"""
                        update product set product_quantity = product_quantity + {product_quantity}
                        where product_id like '{product_id}'; 
                    """
        cursor.execute(update_sql)
    except Exception:
        db.rollback()
    else:
        db.commit()
        print("Quantity updated successfully !")
    finally:
        db.close()
示例#4
0
def DeleteCustomer(customer_id):
    db,cursor = Connection()
    # flag=0
    delete_sql = f"delete from customer where customer_id = {customer_id};"
    search_sql = f"select * from customer where customer_id = {customer_id};"
    try:
        cursor.execute(search_sql)
        rs = cursor.fetchall()
        if(len(rs)>0):
            cursor.execute(delete_sql)
            db.commit()
            print("Customer deleted successfully")
        else:
            print("No such customer exists please check all the customers")
    except Exception:
        db.rollback()
        print("Some error in deleting the customer")
    else:
        pass
    finally:
        db.close()