INTRODUCTION
The Dairy Farm Management System (DFMS) is a comprehensive
software solution designed to assist dairy farmers in managing their operations
efficiently. As the dairy industry faces increasing pressures from market
demands, labor costs, and the need for precise record-keeping, a robust
management system becomes essential.
Purpose and Objectives
The primary purpose of the DFMS is to streamline various aspects of dairy
farming, including:
Animal Management: Keeping detailed records of each cow, including
breed, age, health status, and milk yield. This information helps farmers
make informed decisions about breeding, healthcare, and production.
Milk Production Tracking: Monitoring daily milk production volumes
and quality. This allows farmers to analyze trends over time, optimize
feeding practices, and improve overall productivity.
Inventory Management: Managing feed supplies, veterinary supplies,
and other inventory items essential for daily operations. This ensures that
farmers have the necessary resources on hand without overstocking.
Employee Management: Keeping track of employee roles,
responsibilities, and payroll. Efficient management of human resources is
crucial in maintaining a productive workforce.
Benefits of the System
1. Improved Efficiency: Automating record-keeping reduces the time spent
on manual tasks, allowing farmers to focus on more critical aspects of
their operations.
1
2. Data-Driven Decisions: Access to real-time data and historical records
empowers farmers to make informed decisions based on trends and
analytics.
3. Cost Reduction: By optimizing milk production and inventory
management, farmers can reduce waste and lower operational costs.
4. Enhanced Animal Health: Regular monitoring of animal health and
production data leads to better care and increased milk yield.
5. Scalability: As the farm grows, the system can be expanded to
accommodate more animals, employees, and inventory items without a
significant overhaul.
Technologies Used
The DFMS is developed using:
Python: A versatile programming language that enables rapid
development and easy maintenance.
MySQL: A robust relational database management system that
efficiently handles data storage and retrieval.
Conclusion
The Dairy Farm Management System represents a significant advancement in
how dairy farmers manage their operations. By leveraging technology to
automate and streamline processes, farmers can enhance productivity, reduce
costs, and ensure better care for their livestock. This project serves as a valuable
tool for both small and large-scale dairy operations, promoting sustainable
farming practices in an increasingly competitive market.
2
FRONT END: PYTHON
BACK END: MYSQL
PYTHON:
Python is an interpreted, object-oriented high-level programming language with
dynamic semantics developed by Guido Van Rossum. It was originally released
in 1991. Designed to be easy as well as fun, the name “Python” is a nod to the
British comedy group Monty Python. Python has a reputation as a beginner-
friendly language, replacing Java as the most widely used introductory language
because it handles much of the complexity for the user, allowing beginners to
focus on fully grasping programming concepts rather than minute details.
Python is used for server-side web development, software development,
mathematics, and system scripting, and is popular for Rapid Application
Development and as a scripting or glue language to tie existing components
because of its high-level, built-in data structures, dynamic typing, and dynamic
binding. Program maintenance costs are reduced with Python due to the easily
learned syntax and emphasis on readability. Additionally, Python’s support of
modules and packages facilitates modular programs and reuse of code. Python
is an open source community language, so numerous independent programmers
are continually building libraries and functionality for it.
3
MYSQL:
MYSQL is a SQL-based relational database management system for web
databases. Use MySQL for various applications, including data cleansing, data
warehousing, online shopping, logging software, and portals. MySQL can store
everything from a single record to a complete product inventory. The
application of MySQL varies based on the need. It can associate with any
scripting language like PHP or Perl and create websites.
4
Source Code:
import mysql.connector
# Function to establish database connection
def db_connection():
try:
return mysql.connector.connect(
host='localhost',
user='root',
password='admin',
database='dairy_farm'
except mysql.connector.Error as err:
print(f"Error: {err}")
return None
# CRUD Operations for Cows
def add_cow(name, breed, age, health_status):
conn = db_connection()
if conn:
cursor = conn.cursor()
5
cursor.execute("INSERT INTO Cows (name, breed, age, health_status)
VALUES (%s, %s, %s, %s)",
(name, breed, age, health_status))
conn.commit()
cursor.close()
conn.close()
print("Cow added successfully.")
else:
print("Failed to connect to the database.")
def get_cows():
conn = db_connection()
if conn:
cursor = conn.cursor()
cursor.execute("SELECT * FROM Cows")
cows = cursor.fetchall()
cursor.close()
conn.close()
return cows
return []
def update_cow(cow_id, name, breed, age, health_status):
6
conn = db_connection()
if conn:
cursor = conn.cursor()
cursor.execute("UPDATE Cows SET name=%s, breed=%s, age=%s,
health_status=%s WHERE id=%s",
(name, breed, age, health_status, cow_id))
conn.commit()
cursor.close()
conn.close()
print("Cow updated successfully.")
else:
print("Failed to connect to the database.")
def delete_cow(cow_id):
conn = db_connection()
if conn:
cursor = conn.cursor()
cursor.execute("DELETE FROM Cows WHERE id=%s", (cow_id,))
conn.commit()
cursor.close()
conn.close()
print("Cow deleted successfully.")
7
else:
print("Failed to connect to the database.")
# CRUD Operations for Milk Production
def add_milk_production(cow_id, production_date, quantity):
conn = db_connection()
if conn:
cursor = conn.cursor()
cursor.execute("INSERT INTO Milk_Production (cow_id,
production_date, quantity) VALUES (%s, %s, %s)",
(cow_id, production_date, quantity))
conn.commit()
cursor.close()
conn.close()
print("Milk production record added successfully.")
else:
print("Failed to connect to the database.")
def get_milk_production():
conn = db_connection()
if conn:
cursor = conn.cursor()
8
cursor.execute("SELECT * FROM Milk_Production")
production = cursor.fetchall()
cursor.close()
conn.close()
return production
return []
# CRUD Operations for Employees
def add_employee(name, role, salary):
conn = db_connection()
if conn:
cursor = conn.cursor()
cursor.execute("INSERT INTO Employees (name, role, salary) VALUES
(%s, %s, %s)",
(name, role, salary))
conn.commit()
cursor.close()
conn.close()
print("Employee added successfully.")
else:
print("Failed to connect to the database.")
9
def get_employees():
conn = db_connection()
if conn:
cursor = conn.cursor()
cursor.execute("SELECT * FROM Employees")
employees = cursor.fetchall()
cursor.close()
conn.close()
return employees
return []
# Main function to demonstrate functionality
def main():
while True:
print("\nDairy Farm Management System")
print("1. Add Cow")
print("2. View Cows")
print("3. Update Cow")
print("4. Delete Cow")
print("5. Add Milk Production")
print("6. View Milk Production")
print("7. Add Employee")
10
print("8. View Employees")
print("9. Exit")
choice = input("Choose an option: ")
if choice == '1':
name = input("Enter cow name: ")
breed = input("Enter breed: ")
age = int(input("Enter age: "))
health_status = input("Enter health status: ")
add_cow(name, breed, age, health_status)
elif choice == '2':
cows = get_cows()
print("Current Cows in the Farm:")
for cow in cows:
print(cow)
elif choice == '3':
cow_id = int(input("Enter cow ID to update: "))
name = input("Enter new name: ")
breed = input("Enter new breed: ")
11
age = int(input("Enter new age: "))
health_status = input("Enter new health status: ")
update_cow(cow_id, name, breed, age, health_status)
elif choice == '4':
cow_id = int(input("Enter cow ID to delete: "))
delete_cow(cow_id)
elif choice == '5':
cow_id = int(input("Enter cow ID: "))
production_date = input("Enter production date (YYYY-MM-DD): ")
quantity = float(input("Enter quantity: "))
add_milk_production(cow_id, production_date, quantity)
elif choice == '6':
production_records = get_milk_production()
print("Milk Production Records:")
for record in production_records:
print(record)
elif choice == '7':
name = input("Enter employee name: ")
12
role = input("Enter role: ")
salary = float(input("Enter salary: "))
add_employee(name, role, salary)
elif choice == '8':
employees = get_employees()
print("Employees:")
for emp in employees:
print(emp)
elif choice == '9':
print("Exiting the system.")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()
13
Python Output:
14
15
16
17
18
MYSQL Output:
19
20
21