Home > Problem, Projects/Experiments, Python > Python: My Orders Tracker P-1

Python: My Orders Tracker P-1



Learning : Pythn, sqlite, Database, SQL
Subject: Create a system to track the orders

Overview:
To track and manage the orders we making through the Internet, we will use the SQlite DateBase to store the data and Python to write the code.

Data we collect:
We will collect the following: order_date, order_ID, order_desc, order_price, shipment_price, order_quantity, order_link, order_img,

Functions: In this project we will create several functions related to the Order Management such as
– Add new Order.
– Edit an Order.
– Delete an Order.
– Show the orders.
Also we will use some of our older functions like date validation.

In Part 1:
– We will set-up the database, create the connection.
– We will create wote the code to create the table, and insert the zero-record.
– We will create the functions names, and the Main-Menu.

So, first code in this part is to import sqlite3, os
then, we will write the database connection as the commeing code:

# Create the data-base and name it as myorders.
db_conn = sqlite3.connect (“myorders.db”)

# set the connection.
c = db_conn.cursor()

Then, we will start writing the the code for the main menu and the functions names that we may have in the application, as in all our systems we will have the three most used function to Add, Edit and Delete the an Order, also we need to show the orders in our system/database, we also will use other function that will help us to Validate the user input such as Date-Validating.

Now, we will start to write the code, first the Main-Menu:

# The Main Menu

def main_menu():
    os.system('clear')
    print("\n==========[ Main Menu ]==========")
    print('     1. Add New Order.')
    print('     2. Edit an Order.')
    print('     3. Delete an Order.')
    print('     4. Show Orders.')
    print('     9. Exit.')
    
    user_choice = input("\n      Select from the Menu: > ") 
    
    # we will return the user choice.
    return user_choice



Now, we will have the all functions name with header code.

# All functions names with Header 


def add_order():
    os.system('clear')
    print("\n==========[ Add New Order ]==========")
    input('\n      Press any key to Contenu..')

def edit_order():
    os.system('clear')
    print("\n==========[ Edit an Order ]==========")
    input('\n      Press any key to Contenu..')
        
def del_order():
    os.system('clear')
    print("\n==========[ Delete an Order ]==========")
    input('\n      Press any key to Contenu..')    
        
def show_order():
    os.system('clear')



Last thing in this part, we will write the main while function in the body part that will call the Main_Menu and keep the user in the application until he/she select number 9 in the menu that mean Exit.

# running the menu and waiting for the user input.

    
while True :
    
    user_select = main_menu()
        
    if user_select == '1' :
        add_order()
        
    elif user_select == '2' :
        edit_order()
        
    elif user_select == '3' :
        del_order()  

    elif user_select == '4' :
        show_order()
        
    elif user_select == '9' :
        print('\n\n   Thank you for using this Appliation. ')
        break
            
    else :
        input('\n   Select Only from the list..  Press any key and try again..') 
    




In Next Post: In the coming post P2, we will write the codes for the Add new Order to the system also to Show the list of orders we have in the databse.


Part 1 Part 2 Part 3 Part 4



To Download my Python code (.py) files Click-Here




Follow me on Twitter..




By: Ali Radwani




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: