コード例 #1
0
ファイル: ProductApp.py プロジェクト: Munir360/MiniProjectMB
def RunApp():
    user_input_main = menu_functions.main_menu()
    while user_input_main != "0":
        
        if user_input_main == "1":
            user_input_product = menu_functions.product_menu()
            
            while user_input_product != 5:
                
                if user_input_product == "1":
                    print_functions.print_list(products)
                    
                elif user_input_product == "2":
                    new_product_name = input("What product would you like to add? (Press 0 to cancel!) ")
                    new_price = float(input("What is the price of this product?"))
                    new_product_index = max([int(product["index"])for product in products]) + 1
                    if new_product_name == "0":
                        menu_functions.product_menu()
                    
                    new_product = {
                        "index": new_product_index, 
                        "name": new_product_name,
                        "price": new_price}
                    
                    update_functions.add_dict_to_list(new_product, products)
                    save_functions.save_dict_products_to_csv("products.csv", products)
                elif user_input_product == "3":
                    product_name = input("What product would you like to update? (Press 0 to cancel!)")
                    while True:
                        for product in products:
                            updated_product_name = input("Please enter the updated Product name")
                            if updated_product_name != "":
                                product['name'] = updated_product_name
                            updated_product_price = float(input("What is the updated price of this product?"))
                            if updated_product_price != "":
                                product['price'] = updated_product_price
                                break
                elif user_input_product == "4":
                    delete_product = input("What product would you like to delete? (Press 0 to cancel!)")
                    
                    for product in products:
                        
                        if product['name'] == delete_product:
                        
                            update_functions.delete_dict_in_list(product, products)
                            
                    if delete_product == "0":
                        menu_functions.product_menu()
                    
                elif user_input_product == "5":
                    
                    break
                else:
                    print("Bye Bye")
                    sys.exit()
                user_input_product = menu_functions.product_menu() 
            user_input_main = menu_functions.main_menu()
        elif user_input_main == "2":
            user_input_courier = menu_functions.courier_menu()
            
            while user_input_courier != 5:
                
                if user_input_courier == "1":
                    print_functions.print_list(couriers)
                    
                elif user_input_courier == "2":
                    new_courier_name = input("Which courier would you like to add? (Press 0 to cancel!)")
                    new_courier_phone = int(input("What is the contact number of the courier?"))
                    new_courier_index = max([int(courier["index"])for courier in couriers]) + 1
                    new_courier = {
                        "index": new_courier_index,
                        "name": new_courier_name,
                        "phone": new_courier_phone}
                    
                    update_functions.add_dict_to_list(new_courier, couriers)
                    save_functions.save_dict_couriers_to_csv("couriers.csv", couriers)
                    
                    if new_courier_name == "0":
                        menu_functions.courier_menu()
                    
                elif user_input_courier == "3":
                    courier_name = input("Which courier would you like to delete? (Press 0 to cancel!)")
                    
                    for courier in couriers:
                        
                        if courier['name'] == courier_name:
                            update_functions.delete_dict_in_list(courier, couriers)
                        if courier == "0":
                            menu_functions.courier_menu()
                    update_functions.delete_item_in_list(courier_name, couriers)
                    
                elif user_input_courier == "4":
                    courier_name = input("Which courier details would you like to update? (Press 0 to cancel!)")
                    
                    for courier in couriers:
                        
                        if courier['name'] == courier_name:
                            while True:
                                new_courier_name = input("Please enter the updated courier's name")
                                if new_courier_name != "":
                                    courier['name'] = new_courier_name
                                new_courier_phone = input("Please enter the updated phone number of the courier")
                                if new_courier_phone != "":
                                    courier['phone'] = new_courier_phone
                                    
                                break
                elif user_input_courier == "5":
                    break
                user_input_courier = menu_functions.courier_menu()
            user_input_main = menu_functions.main_menu()
        elif user_input_main == "3":
            user_input_order = menu_functions.order_menu()
            
            while user_input_order != 6:
                
                if user_input_order == "1":
                    print_functions.print_list(orders)
                    
                elif user_input_order == "2":
                    new_order_name = input("Please enter the name of the customer: ")
                    new_order_phone = input("Please enter the phone number of the customer: ")
                    new_order_address = input("Please enter the address of the customer: ")
                    print("The available couriers are::")
                    new_order = {
                        "customer_name": new_order_name,
                        "customer_phone": new_order_phone,
                        "customer_address": new_order_address,
                        "courier": text_functions.courier_list_select()["index"],
                        "status": "Preparing",
                        "items": text_functions.product_list_select()["index"]
                        }
                        
                        
                    update_functions.add_dict_to_list(new_order, orders)
                    
                elif user_input_order == "3":
                    order_name = input("Whose order status would you like to update? Press 0 to cancel! ")
                    
                    if order_name == "0":
                        menu_functions.order_menu()
                        
                    for order in orders:
                    
                        if order['customer_name'] == order_name:
                            print("The current status of this order is: ")
                            print(order['status'])
                        
                    new_status = input("What is the new status of this order? ")
                    
                    for order in orders:
                        
                        if order['customer_name'] == order_name:
                            order['status'] = new_status
                            print("The new order status is: " + new_status)
                    print(orders)
                    
                elif user_input_order == "4":
                    
                    order_name = input("Whose order would you like to update? ")
                    
                    for order in orders:
                        
                        if order['customer_name'] == order_name:
                            while True:
                                new_order_name = input("Please enter the updated name of the customer: ")
                                if new_order_name != "":
                                    order['customer_name'] = new_order_name
                                new_order_phone = input("Please enter the updated phone number of the customer: ")
                                if new_order_phone != "":
                                    order['customer_phone'] = new_order_phone
                                new_order_address = input("Please enter the updated address of the customer: ")
                                if new_order_address != "":
                                    order['customer_address'] = new_order_address
                                print("The available couriers are:")
                                
                                text_functions.courier_list_select()
                                
                                order['status'] = "Preparing"
                                print("The available items are:")
                                text_functions.product_list_select()
                                
                                break
                                
                            
                elif user_input_order == "5":
                    order_name = input("Whose order would you like to delete? ")
                    
                    for order in orders:
                        
                        if order['customer_name'] == order_name:
                            
                            update_functions.delete_dict_in_list(order, orders)
                            
                elif user_input_order == "6":
                    break
                    menu_functions.main_menu()
                user_input_order = menu_functions.order_menu()
            user_input_main = menu_functions.main_menu()
        elif user_input_main == "4":
            print("Your data has been saved, you will now exit the app")
            # save_functions.save_dict_products_to_csv("products.csv", products)
            # save_functions.save_dict_couriers_to_csv("couriers.csv", couriers)
            save_functions.save_dict_to_csv("orders.csv", orders)
            exit()
            
        elif user_input_main == "0":
            menu_functions.main_menu() 
コード例 #2
0
ファイル: ProductApp3.py プロジェクト: Munir360/MiniProjectMB
def RunApp():
    user_input_main = menu_functions.main_menu()
    while user_input_main != "0":

        if user_input_main == "1":
            user_input_product = menu_functions.product_menu()

            while user_input_product != 5:

                if user_input_product == "1":
                    print_functions.print_list(products)

                elif user_input_product == "2":
                    new_product = input(
                        "What product would you like to add? (Press 0 to cancel!) "
                    )

                    if new_product == "0":
                        menu_functions.product_menu()
                    update_functions.add_item_to_list(new_product, products)
                    save_functions.save_lists("products.txt", products)

                elif user_input_product == "3":
                    update_product = input(
                        "What product would you like to update? (Press 0 to cancel!)"
                    )

                    if update_product == "0":
                        menu_functions.product_menu()
                    updated_product = input(
                        "What would you like to update this to? (Press 0 to cancel!)"
                    )

                    if update_product == "0":
                        menu_functions.product_menu()
                    update_functions.update_item_in_list(
                        update_product, updated_product, products)

                elif user_input_product == "4":
                    delete_product = input(
                        "What product would you like to delete? (Press 0 to cancel!)"
                    )

                    if delete_product == "0":
                        menu_functions.product_menu()
                    update_functions.delete_item_in_list(
                        delete_product, products)

                elif user_input_product == "5":

                    break
                else:
                    print("Bye Bye")
                    sys.exit()
                user_input_product = menu_functions.product_menu()
            user_input_main = menu_functions.main_menu()
        elif user_input_main == "2":
            user_input_courier = menu_functions.courier_menu()

            while user_input_courier != 5:

                if user_input_courier == "1":
                    print_functions.print_list(couriers)

                elif user_input_courier == "2":
                    new_courier = input(
                        "Which courier would you like to add? (Press 0 to cancel!)"
                    )

                    if new_courier == "0":
                        menu_functions.courier_menu()
                    update_functions.add_item_to_list(new_courier, couriers)
                    save_functions.save_lists("couriers.txt", couriers)

                elif user_input_courier == "3":
                    delete_courier = input(
                        "Which courier would you like to delete? (Press 0 to cancel!)"
                    )

                    if delete_courier == "0":
                        menu_functions.courier_menu()
                    update_functions.delete_item_in_list(
                        delete_courier, couriers)

                elif user_input_courier == "4":
                    update_courier = input(
                        "Which name would you like to update? (Press 0 to cancel!)"
                    )

                    if update_courier == "0":
                        menu_functions.courier_menu()
                    updated_courier = input(
                        "What name you like to update this to? (Press 0 to cancel!)"
                    )

                    if updated_courier == "0":
                        menu_functions.courier_menu()
                    update_functions.update_item_in_list(
                        update_courier, updated_courier, couriers)
                    save_functions.save_lists("couriers.txt", couriers)
                elif user_input_courier == "5":
                    break
                user_input_courier = menu_functions.courier_menu()
            user_input_main = menu_functions.main_menu()
        elif user_input_main == "3":
            user_input_order = menu_functions.order_menu()

            while user_input_order != 6:

                if user_input_order == "1":
                    print_functions.print_list(orders)

                elif user_input_order == "2":
                    new_order_name = input(
                        "Please enter the name of the customer: ")
                    new_order_phone = input(
                        "Please enter the phone number of the customer: ")
                    new_order_address = input(
                        "Please enter the address of the customer: ")
                    print("The available couriers are::")
                    print(couriers)
                    new_order_courier = input(
                        "Please enter the courier you would like to deliver the order: "
                    )
                    new_order = {
                        "customer_name": new_order_name,
                        "customer_phone": new_order_phone,
                        "customer_address": new_order_address,
                        "courier": new_order_courier,
                        "status": "Preparing"
                    }

                    update_functions.add_dict_to_list(new_order, orders)
                    save_functions.save_dict_to_csv("orders.csv", new_order)

                elif user_input_order == "3":
                    order_name = input(
                        "Whose order status would you like to update? Press 0 to cancel! "
                    )

                    if order_name == "0":
                        menu_functions.order_menu()

                    for order in orders:

                        if order['customer_name'] == order_name:
                            print("The current status of this order is: ")
                            print(order['status'])

                    new_status = input(
                        "What is the new status of this order? ")

                    for order in orders:

                        if order['customer_name'] == order_name:
                            order['status'] = new_status
                            print("The new order status is: " + new_status)
                    print(orders)

                elif user_input_order == "4":

                    order_name = input(
                        "Whose order would you like to update? ")

                    for order in orders:

                        if order['customer_name'] == order_name:
                            while True:
                                new_order_name = input(
                                    "Please enter the updated name of the customer: "
                                )
                                if new_order_name != "":
                                    order['customer_name'] = new_order_name
                                new_order_phone = input(
                                    "Please enter the updated phone number of the customer: "
                                )
                                order['customer_phone'] = new_order_phone
                                if new_order_phone == " ":
                                    pass
                                new_order_address = input(
                                    "Please enter the updated address of the customer: "
                                )
                                order['customer_address'] = new_order_address
                                if new_order_address == " ":
                                    pass
                                print("The available couriers are::")
                                print(couriers)
                                new_order_courier = input(
                                    "Please enter the courier you would like to deliver the order: "
                                )
                                order['courier'] = new_order_courier
                                order['status'] = "Preparing"
                                if new_order_courier == " ":
                                    pass
                                break
                                # update_functions.add_dict_to_list(order, orders)

                elif user_input_order == "5":
                    order_name = input(
                        "Whose order would you like to delete? ")

                    for order in orders:

                        if order['customer_name'] == order_name:

                            update_functions.delete_dict_in_list(order, orders)

                elif user_input_order == "6":
                    save_functions.save_dict_to_csv("orders.csv", orders)
                    break
                    menu_functions.main_menu()
                user_input_order = menu_functions.order_menu()
            user_input_main = menu_functions.main_menu()

        elif user_input_main == "0":
            menu_functions.main_menu()
コード例 #3
0
def update_dict_in_list(dict_old, dict_new, list):
    if dict_old in list:
        list.remove(dict_old)
        list.append(dict_new)
        print_functions.print_list(list)
コード例 #4
0
def update_item_in_list(item_old, item_new, list):
    if item_old in list:
        list.remove(item_old)
        list.append(item_new)
        print_functions.print_list(list)
コード例 #5
0
def delete_item_in_list(item, list):
    if item in list:
        list.remove(item)
        print_functions.print_list(list)
コード例 #6
0
def add_item_to_list(item, list):
    list.append(item)
    print_functions.print_list(list)