MansoorSarookh commited on
Commit
d9401b5
·
verified ·
1 Parent(s): 62ee244

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -0
app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sqlite3
2
+ import streamlit as st
3
+
4
+ # --- DATABASE FUNCTIONS ---
5
+ # Initialize the SQLite database
6
+ def init_db():
7
+ conn = sqlite3.connect("project_management.db") # Creates a database file
8
+ c = conn.cursor()
9
+ # Create a table for projects
10
+ c.execute('''
11
+ CREATE TABLE IF NOT EXISTS projects (
12
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
13
+ name TEXT NOT NULL,
14
+ description TEXT,
15
+ start_date TEXT,
16
+ end_date TEXT,
17
+ priority TEXT,
18
+ budget REAL
19
+ )
20
+ ''')
21
+ conn.commit()
22
+ conn.close()
23
+
24
+ # Add a new project to the database
25
+ def add_project(name, description, start_date, end_date, priority, budget):
26
+ conn = sqlite3.connect("project_management.db")
27
+ c = conn.cursor()
28
+ c.execute("INSERT INTO projects (name, description, start_date, end_date, priority, budget) VALUES (?, ?, ?, ?, ?, ?)",
29
+ (name, description, start_date, end_date, priority, budget))
30
+ conn.commit()
31
+ conn.close()
32
+
33
+ # Retrieve all projects from the database
34
+ def view_projects():
35
+ conn = sqlite3.connect("project_management.db")
36
+ c = conn.cursor()
37
+ c.execute("SELECT * FROM projects")
38
+ rows = c.fetchall()
39
+ conn.close()
40
+ return rows
41
+
42
+ # Delete a project by ID
43
+ def delete_project(project_id):
44
+ conn = sqlite3.connect("project_management.db")
45
+ c = conn.cursor()
46
+ c.execute("DELETE FROM projects WHERE id=?", (project_id,))
47
+ conn.commit()
48
+ conn.close()
49
+
50
+ # --- STREAMLIT FRONT-END ---
51
+ def main():
52
+ st.title("Software Management Tool")
53
+ st.write("*Developed by Mansoor Sarookh, CS Student at GPGC Swabi*")
54
+
55
+ # Initialize the database
56
+ init_db()
57
+
58
+ # Sidebar menu
59
+ menu = ["Add New Project", "View All Projects", "Delete Project"]
60
+ choice = st.sidebar.selectbox("Menu", menu)
61
+
62
+ # Add New Project
63
+ if choice == "Add New Project":
64
+ st.subheader("Add New Project")
65
+ name = st.text_input("Project Name")
66
+ description = st.text_area("Project Description")
67
+ start_date = st.date_input("Start Date")
68
+ end_date = st.date_input("End Date")
69
+ priority = st.selectbox("Priority", ["Low", "Medium", "High"])
70
+ budget = st.number_input("Budget (in USD)", min_value=0.0, step=100.0)
71
+
72
+ if st.button("Add Project"):
73
+ if name and description:
74
+ add_project(name, description, str(start_date), str(end_date), priority, budget)
75
+ st.success(f"Project '{name}' added successfully!")
76
+ else:
77
+ st.error("Please fill in all required fields.")
78
+
79
+ # View All Projects
80
+ elif choice == "View All Projects":
81
+ st.subheader("All Projects")
82
+ data = view_projects()
83
+ if data:
84
+ for row in data:
85
+ st.write(f"*ID:* {row[0]} | *Name:* {row[1]} | *Description:* {row[2]}")
86
+ st.write(f"*Start Date:* {row[3]} | *End Date:* {row[4]} | *Priority:* {row[5]} | *Budget:* ${row[6]}")
87
+ st.write("---")
88
+ else:
89
+ st.info("No projects available. Add some projects first.")
90
+
91
+ # Delete a Project
92
+ elif choice == "Delete Project":
93
+ st.subheader("Delete a Project")
94
+ project_id = st.number_input("Enter Project ID to Delete", min_value=1, step=1)
95
+ if st.button("Delete"):
96
+ delete_project(project_id)
97
+ st.success(f"Project with ID {project_id} deleted successfully!")
98
+
99
+ if _name_ == "_main_":
100
+ main()