@@ -131,29 +131,48 @@ def on_reject():
131
131
button_box .rejected .connect (on_reject )
132
132
133
133
dialog .exec_ ()
134
- def get_employee_name (parent ,name_field_text = "Enter Employee Name" ):
134
+ def get_employee_name (parent , name_field_text = "Enter Employee Name" ):
135
135
page , main_layout = create_page_with_header (parent , "Employee Data Update" )
136
136
137
137
# Content frame
138
138
content_frame = create_styled_frame (page )
139
139
content_frame .setSizePolicy (QtWidgets .QSizePolicy .Preferred , QtWidgets .QSizePolicy .Expanding )
140
140
content_layout = QtWidgets .QVBoxLayout (content_frame )
141
+
141
142
# Form frame
142
143
form_frame = create_styled_frame (content_frame , min_size = (340 , 200 ), style = "background-color: #ffffff; border-radius: 15px; padding: 10px;" )
143
144
form_layout = QtWidgets .QVBoxLayout (form_frame )
145
+
144
146
# Form fields
145
147
name_label , name_field = create_input_field (form_frame , name_field_text )
146
148
search_button = create_styled_button (form_frame , "Search" , min_size = (100 , 30 ))
147
149
form_layout .addWidget (name_label )
148
150
form_layout .addWidget (search_button )
151
+ content_layout .addWidget (form_frame , 0 , QtCore .Qt .AlignHCenter | QtCore .Qt .AlignVCenter )
152
+ main_layout .addWidget (content_frame )
149
153
150
- search_button .clicked .connect (lambda : backend .check_name_in_staff ())
151
154
def on_search_button_clicked ():
152
- fetch = backend .check_name_in_staff ()
153
- if fetch :
154
- print (f"Employee data: { fetch [0 ]} , { fetch [1 ]} , { fetch [2 ]} , { fetch [3 ]} ," )
155
- else :
156
- print ("Employee not found." )
155
+ entered_name = name_field .text ().strip ()
156
+ if not entered_name :
157
+ QtWidgets .QMessageBox .warning (parent , "Input Error" , "Please enter an employee name." )
158
+ return
159
+
160
+ try :
161
+ cur = backend .cur
162
+ cur .execute ("SELECT * FROM staff WHERE name = ?" , (entered_name ,))
163
+ fetch = cur .fetchone ()
164
+ if fetch :
165
+ QtWidgets .QMessageBox .information (parent , "Employee Found" ,
166
+ f"Employee data:\n ID: { fetch [0 ]} \n Name: { fetch [1 ]} \n Dept: { fetch [2 ]} \n Role: { fetch [3 ]} " )
167
+ else :
168
+ QtWidgets .QMessageBox .information (parent , "Not Found" , "Employee not found." )
169
+ except Exception as e :
170
+ QtWidgets .QMessageBox .critical (parent , "Error" , f"An error occurred: { str (e )} " )
171
+
172
+ search_button .clicked .connect (on_search_button_clicked )
173
+
174
+ return page
175
+
157
176
158
177
#backend.check_name_in_staff()
159
178
def create_login_page (parent ,title , name_field_text = "Name :" , password_field_text = "Password :" , submit_text = "Submit" ,):
@@ -188,19 +207,25 @@ def create_login_page(parent ,title, name_field_text="Name :", password_field_te
188
207
content_layout .addWidget (form_frame , 0 , QtCore .Qt .AlignHCenter | QtCore .Qt .AlignVCenter )
189
208
main_layout .addWidget (content_frame )
190
209
191
- submit_button . clicked . connect ( lambda : on_login_button_clicked ( parent , name_edit , password_edit ))
210
+
192
211
193
212
return page , name_edit , password_edit , submit_button
194
- def on_login_button_clicked (parent ,name_field , password_field ):
195
- # Get the entered name and password
196
- name = name_field .text ()
197
- password = password_field .text ()
198
- # Check if the entered name and password are correct
199
- if name == "" and password == "" :
200
- # Show a message box with the entered name and password
201
- show_popup_message (parent , "Please enter your name and password." ,0 )
213
+ def on_login_button_clicked (parent , name_field , password_field ):
214
+ name = name_field .text ().strip ()
215
+ password = password_field .text ().strip ()
216
+
217
+ if not name or not password :
218
+ show_popup_message (parent , "Please enter your name and password." , 0 )
202
219
else :
203
- print (f"Name: { name } , Password: { password } " )
220
+ try :
221
+ # Ideally, here you'd call a backend authentication check
222
+ success = backend .check_admin (name , password )
223
+ if success :
224
+ QtWidgets .QMessageBox .information (parent , "Login Successful" , f"Welcome, { name } !" )
225
+ else :
226
+ QtWidgets .QMessageBox .warning (parent , "Login Failed" , "Incorrect name or password." )
227
+ except Exception as e :
228
+ QtWidgets .QMessageBox .critical (parent , "Error" , f"An error occurred during login: { str (e )} " )
204
229
205
230
def create_home_page (parent , on_admin_clicked , on_employee_clicked , on_exit_clicked ):
206
231
"""Create the home page with Admin, Employee, and Exit buttons."""
@@ -315,11 +340,11 @@ def create_add_employee_page(parent, title, submit_text="Submit",update_btn:bool
315
340
# Submit button
316
341
button_frame = create_styled_frame (form_frame , style = "padding: 7px;" )
317
342
button_layout = QtWidgets .QVBoxLayout (button_frame )
318
- update_button = create_styled_button (button_frame , "Update" , min_size = (150 , 0 ))
319
- submit_button = create_styled_button (button_frame , submit_text , min_size = (150 , 0 ))
320
343
if update_btn :
344
+ update_button = create_styled_button (button_frame , "Update" , min_size = (150 , 0 ))
321
345
button_layout .addWidget (update_button , 0 , QtCore .Qt .AlignHCenter )
322
346
else :
347
+ submit_button = create_styled_button (button_frame , submit_text , min_size = (150 , 0 ))
323
348
button_layout .addWidget (submit_button , 0 , QtCore .Qt .AlignHCenter )
324
349
325
350
@@ -353,12 +378,17 @@ def exit_app():
353
378
QtWidgets .QApplication .quit ()
354
379
355
380
def admin_login_menu_page (name , password ):
356
- result = backend .check_admin (name , password )
357
- if result :
358
- stacked_widget .setCurrentIndex (3 )
359
- else :
360
- print ("Invalid admin credentials" )
361
- show_popup_message (stacked_widget ,"Invalid admin credentials" ,0 )
381
+ try :
382
+ # Ideally, here you'd call a backend authentication check
383
+ success = backend .check_admin (name , password )
384
+ if success :
385
+ QtWidgets .QMessageBox .information (stacked_widget , "Login Successful" , f"Welcome, { name } !" )
386
+ stacked_widget .setCurrentIndex (3 )
387
+ else :
388
+ QtWidgets .QMessageBox .warning (stacked_widget , "Login Failed" , "Incorrect name or password." )
389
+ except Exception as e :
390
+ QtWidgets .QMessageBox .critical (stacked_widget , "Error" , f"An error occurred during login: { str (e )} " )
391
+ # show_popup_message(stacked_widget,"Invalid admin credentials",0)
362
392
363
393
def add_employee_form_submit (name , password , salary , position ):
364
394
if (
@@ -476,7 +506,7 @@ def fetch_employee_data(name):
476
506
main_window .setCentralWidget (central_widget )
477
507
478
508
# Set initial page
479
- stacked_widget .setCurrentIndex (0 )
509
+ stacked_widget .setCurrentIndex (5 )
480
510
481
511
return stacked_widget , {
482
512
"admin_name" : admin_name ,
0 commit comments