-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelete.py
More file actions
176 lines (154 loc) · 8.07 KB
/
Delete.py
File metadata and controls
176 lines (154 loc) · 8.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
from CarRenatlBackend import cursor, db
from Setup import DB_NAME
import streamlit as st
from Read import getAllDrivers, getAllDriverContacts, getAllCustomers, getAllLocations, getAllCarCategories, getAllCars, getAllDiscountCoupons, AllBookingDetails
import pandas as pd
def DeleteDriverUI():
with st.expander("Before Deleting"):
st.table(pd.DataFrame(getAllDrivers()))
with st.container():
selected_drivers = st.multiselect("Select DL's to be deleted", [driver["DL"] for driver in getAllDrivers()])
if st.button("Delete"):
for dl in selected_drivers:
DeleteDriver(dl)
def DeleteDriver(dl):
cursor.execute(f"use {DB_NAME}")
query = ("delete from driver_info where dl_number = %s")
cursor.execute(query, (dl,))
db.commit()
st.success("Driver's data deleted successfully", icon="✅")
with st.expander("After Deleting"):
st.table(getAllDrivers())
# ---------------------------------------------------------------------------------------------------------------------------
# Driver's Contacts
# ---------------------------------------------------------------------------------------------------------------------------
def DeleteDriverContactUI():
with st.expander("Before Deleting"):
st.table(getAllDriverContacts())
with st.container():
selected_contacts = st.multiselect("Select Contact's to be deleted", [driver["Contact"] for driver in getAllDriverContacts()])
if st.button("Delete"):
for contact in selected_contacts:
DeleteDriverContact(contact)
def DeleteDriverContact(contact):
cursor.execute(f"use {DB_NAME}")
query = ("delete from driver_contacts where phone_no = %s")
cursor.execute(query, (contact,))
db.commit()
st.success("Driver's Contact deleted successfully", icon="✅")
with st.expander("After Deleting"):
st.table(pd.DataFrame(getAllDriverContacts()))
# ---------------------------------------------------------------------------------------------------------------------------
# Customer Details
# ---------------------------------------------------------------------------------------------------------------------------
def DeleteCustomerByUsernameUI():
with st.expander("Before Deleting"):
st.table(getAllCustomers())
with st.container():
selected_customers = st.multiselect("Select Customer's Username to be deleted", [customer["Username"] for customer in getAllCustomers()])
if st.button("Delete"):
for customer in selected_customers:
DeleteCustomerByUsername(customer)
def DeleteCustomerByUsername(username):
cursor.execute(f"use {DB_NAME}")
query = ("delete from customer_info where username = %s")
cursor.execute(query, (username,))
db.commit()
st.success("Customer details deleted successfully", icon="✅")
with st.expander("After Deleting"):
st.table(pd.DataFrame(getAllCustomers()))
# -----------------------------------------------------------------------------------------------------------------------------
# Location details
# -----------------------------------------------------------------------------------------------------------------------------
def DeleteLocationByNameUI():
with st.expander("Before Deleting"):
st.table(getAllLocations())
with st.container():
selected_locations = st.multiselect("Select Location Name to be deleted", [location["Location Name"] for location in getAllLocations()])
if st.button("Delete"):
for location in selected_locations:
DeleteLocationByName(location)
def DeleteLocationByName(location_name):
cursor.execute(f"use {DB_NAME}")
query = ("delete from locations where location_name = %s")
cursor.execute(query, (location_name,))
db.commit()
st.success("Location details deleted successfully", icon="✅")
with st.expander("After Deleting"):
st.table(pd.DataFrame(getAllLocations()))
# ---------------------------------------------------------------------------------------------------------------------------------
# Car Category
# ---------------------------------------------------------------------------------------------------------------------------------
def DeleteCarCategoryByNameUI():
with st.expander("Before Deleting"):
st.table(getAllCarCategories())
with st.container():
selected_category = st.multiselect("Select Category Name to be deleted", [category["Name"] for category in getAllCarCategories()])
if st.button("Delete"):
for category in selected_category:
DeleteCarCategoryByName(category)
def DeleteCarCategoryByName(category_name):
cursor.execute(f"use {DB_NAME}")
query = ("delete from car_category where category_name = %s")
cursor.execute(query, (category_name,))
db.commit()
st.success("Car Category details deleted successfully", icon="✅")
with st.expander("After Deleting"):
st.table(pd.DataFrame(getAllCarCategories()))
# -----------------------------------------------------------------------------------------------------------------------------------------------
# Car details
# -----------------------------------------------------------------------------------------------------------------------------------------------
def DeleteCarRegNoUI():
with st.expander("Before Deleting"):
st.table(getAllCars())
with st.container():
selected_regNo = st.multiselect("Select Reg No. to be deleted", options=[car["Registration No"] for car in getAllCars()])
if st.button("Delete"):
for reg_no in selected_regNo:
DeleteCarRegNo(reg_no)
def DeleteCarRegNo(reg_no):
cursor.execute(f"use {DB_NAME}")
query = ("delete from car_details where registration_no = %s")
cursor.execute(query, (reg_no,))
db.commit()
st.success("Car details deleted successfully", icon="✅")
with st.expander("After Deleting"):
st.table(pd.DataFrame(getAllCars()))
# -----------------------------------------------------------------------------------------------------------------------------------------------
# Cadiscountr details
# -----------------------------------------------------------------------------------------------------------------------------------------------
def DeleteDiscountCouponUI():
with st.expander("Before Deleting"):
st.table(getAllDiscountCoupons())
with st.container():
selected_coupon = st.multiselect("Select Coupon Code to be deleted", options=[coupon["coupon_code"] for coupon in getAllDiscountCoupons()])
if st.button("Delete"):
for code in selected_coupon:
DeleteDiscountCoupon(code)
def DeleteDiscountCoupon(code):
cursor.execute(f"use {DB_NAME}")
query = ("delete from discount where coupon_code = %s")
cursor.execute(query, (code,))
db.commit()
st.success("Discount Coupon details deleted successfully", icon="✅")
with st.expander("After Deleting"):
st.table(pd.DataFrame(getAllDiscountCoupons()))
# ----------------------------------------------------------------------------------------------------------------------------------------------------
# Booking Details
# ----------------------------------------------------------------------------------------------------------------------------------------------------
def DeleteBookingDetailsUI():
with st.expander("Before Deleting"):
st.table(AllBookingDetails())
with st.container():
selected_booking = st.multiselect("Select Booking Id to be deleted", options=[booking["Booking Id"] for booking in AllBookingDetails()])
if st.button("Delete"):
for booking_id in selected_booking:
DeleteBookingDetails(booking_id)
def DeleteBookingDetails(booking_id):
cursor.execute(f"use {DB_NAME}")
query = ("delete from booking_details where booking_id = %s")
cursor.execute(query, (booking_id,))
db.commit()
st.success("Booking details deleted successfully", icon="✅")
with st.expander("After Deleting"):
st.table(pd.DataFrame(AllBookingDetails()))