@@ -131,29 +131,48 @@ def on_reject():
131131 button_box .rejected .connect (on_reject )
132132
133133 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" ):
135135 page , main_layout = create_page_with_header (parent , "Employee Data Update" )
136136
137137 # Content frame
138138 content_frame = create_styled_frame (page )
139139 content_frame .setSizePolicy (QtWidgets .QSizePolicy .Preferred , QtWidgets .QSizePolicy .Expanding )
140140 content_layout = QtWidgets .QVBoxLayout (content_frame )
141+
141142 # Form frame
142143 form_frame = create_styled_frame (content_frame , min_size = (340 , 200 ), style = "background-color: #ffffff; border-radius: 15px; padding: 10px;" )
143144 form_layout = QtWidgets .QVBoxLayout (form_frame )
145+
144146 # Form fields
145147 name_label , name_field = create_input_field (form_frame , name_field_text )
146148 search_button = create_styled_button (form_frame , "Search" , min_size = (100 , 30 ))
147149 form_layout .addWidget (name_label )
148150 form_layout .addWidget (search_button )
151+ content_layout .addWidget (form_frame , 0 , QtCore .Qt .AlignHCenter | QtCore .Qt .AlignVCenter )
152+ main_layout .addWidget (content_frame )
149153
150- search_button .clicked .connect (lambda : backend .check_name_in_staff ())
151154 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+
157176
158177 #backend.check_name_in_staff()
159178def 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
188207 content_layout .addWidget (form_frame , 0 , QtCore .Qt .AlignHCenter | QtCore .Qt .AlignVCenter )
189208 main_layout .addWidget (content_frame )
190209
191- submit_button . clicked . connect ( lambda : on_login_button_clicked ( parent , name_edit , password_edit ))
210+
192211
193212 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 )
202219 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 )} " )
204229
205230def create_home_page (parent , on_admin_clicked , on_employee_clicked , on_exit_clicked ):
206231 """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
315340 # Submit button
316341 button_frame = create_styled_frame (form_frame , style = "padding: 7px;" )
317342 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 ))
320343 if update_btn :
344+ update_button = create_styled_button (button_frame , "Update" , min_size = (150 , 0 ))
321345 button_layout .addWidget (update_button , 0 , QtCore .Qt .AlignHCenter )
322346 else :
347+ submit_button = create_styled_button (button_frame , submit_text , min_size = (150 , 0 ))
323348 button_layout .addWidget (submit_button , 0 , QtCore .Qt .AlignHCenter )
324349
325350
@@ -353,12 +378,17 @@ def exit_app():
353378 QtWidgets .QApplication .quit ()
354379
355380 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)
362392
363393 def add_employee_form_submit (name , password , salary , position ):
364394 if (
@@ -476,7 +506,7 @@ def fetch_employee_data(name):
476506 main_window .setCentralWidget (central_widget )
477507
478508 # Set initial page
479- stacked_widget .setCurrentIndex (0 )
509+ stacked_widget .setCurrentIndex (5 )
480510
481511 return stacked_widget , {
482512 "admin_name" : admin_name ,
0 commit comments