@@ -140,6 +140,47 @@ def previousUser(self):
140140
141141 def saveEvent (self ):
142142 pass
143+ event_name = self .event_name_line_edit .text ()
144+ start_time = self .Start_time_edit .time ().toString ()
145+ end_time = self .End_time_edit .time ().toString ()
146+ description = self .Description_text_edit .toPlainText ()
147+ # Get the date set on the calendar
148+ event_date = self .event_date_edit .text ()
149+ #Get the Get the username of the logged-in user
150+ username = self .username
151+ #Establishing a connection to the SQLite database named "Event.db"
152+ conn = sqlite3 .connect ("Event.db" )
153+ #Creating a cursor object to interact with the database
154+ cursor = conn .cursor ()
155+ #Creating the Events table if it does not exist
156+ cursor .execute ('''
157+ CREATE TABLE IF NOT EXISTS Events(
158+ EventID INTEGER PRIMARY KEY AUTOINCREMENT,
159+ EventName TEXT,
160+ StartTime TEXT,
161+ EndTime TEXT,
162+ Description TEXT,
163+ EventDate TEXT,
164+ Username TEXT,
165+ )
166+ ''' )
167+ #Insert the event details into the Event table
168+ cursor .execute ('''
169+ INSERT INTO Events (EventName, StartTime, EndTime, Description, EventDate, Username)
170+ VALUES (?,?,?,?,?,?)
171+ ''' , (event_name ,start_time ,end_time ,description ,event_date ,username ))
172+ #Commit the changes to the database
173+ conn .commit ()
174+ #Close the database connection to free up resources
175+ conn .close
176+ #Displays a success message to the user
177+ QMessageBox .information (self ,"Success" ,"Event saved successfully!" )
178+ except Exception as e :
179+ #Handle any exceptions that might occur during the process and display an error message
180+ QMessageBox .critical (self ,"Error" ,f"Failed to save event:{ str (e )} " )
181+
182+
183+
143184
144185 #####################################################################################################
145186 ## FUNCTION THAT ALLOWS USER TO SET THE EVENT FIELDS FOR A SPECIFIC USER FROM THE DATABASE ##
0 commit comments