├── Employee Management System.py ├── ReadME.md └── preview.png /Employee Management System.py: -------------------------------------------------------------------------------- 1 | # Employee Management System Using Python - Sagar Developer 2 | 3 | from os import system 4 | import re 5 | # importing mysql connector 6 | import mysql.connector 7 | 8 | # making Connection 9 | con = mysql.connector.connect( 10 | host="localhost", user="root", password="", database="employee") 11 | 12 | # make a regular expression 13 | # for validating an Email 14 | regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b' 15 | # for validating an Phone Number 16 | Pattern = re.compile("(0|91)?[7-9][0-9]{9}") 17 | 18 | 19 | # Function to Add_Employ 20 | def Add_Employ(): 21 | print("{:>60}".format("-->>Add Employee Record<<--")) 22 | Id = input("Enter Employee Id: ") 23 | # checking If Employee Id is Exit Or Not 24 | if (check_employee(Id) == True): 25 | print("Employee ID Already Exists\nTry Again..") 26 | press = input("Press Any Key To Continue..") 27 | Add_Employ() 28 | Name = input("Enter Employee Name: ") 29 | # checking If Employee Name is Exit Or Not 30 | if (check_employee_name(Name) == True): 31 | print("Employee Name Already Exists\nTry Again..") 32 | press = input("Press Any Key To Continue..") 33 | Add_Employ 34 | Email_Id = input("Enter Employee Email ID: ") 35 | if(re.fullmatch(regex, Email_Id)): 36 | print("Valid Email") 37 | else: 38 | print("Invalid Email") 39 | press = input("Press Any Key To Continue..") 40 | Add_Employ() 41 | Phone_no = input("Enter Employee Phone No.: ") 42 | if(Pattern.match(Phone_no)): 43 | print("Valid Phone Number") 44 | else: 45 | print("Invalid Phone Number") 46 | press = input("Press Any Key To Continue..") 47 | Add_Employ() 48 | Address = input("Enter Employee Address: ") 49 | Post = input("Enter Employee Post: ") 50 | Salary = input("Enter Employee Salary: ") 51 | data = (Id, Name, Email_Id, Phone_no, Address, Post, Salary) 52 | # Instering Employee Details in 53 | # the Employee (empdata) Table 54 | sql = 'insert into empdata values(%s,%s,%s,%s,%s,%s,%s)' 55 | c = con.cursor() 56 | 57 | # Executing the sql Query 58 | c.execute(sql, data) 59 | 60 | # Commit() method to make changes in the table 61 | con.commit() 62 | print("Successfully Added Employee Record") 63 | press = input("Press Any Key To Continue..") 64 | menu() 65 | 66 | # Function To Check if Employee With 67 | # given Name Exist or not 68 | def check_employee_name(employee_name): 69 | # query to select all Rows from 70 | # employee(empdata) table 71 | sql = 'select * from empdata where Name=%s' 72 | 73 | # making cursor buffered to make 74 | # rowcount method work properly 75 | c = con.cursor(buffered=True) 76 | data = (employee_name,) 77 | 78 | # Execute the sql query 79 | c.execute(sql, data) 80 | 81 | # rowcount method to find number 82 | # of rowa with given values 83 | r = c.rowcount 84 | if r == 1: 85 | return True 86 | else: 87 | return False 88 | 89 | 90 | # Function To Check if Employee With 91 | # given Id Exist or not 92 | def check_employee(employee_id): 93 | # query to select all Rows from 94 | # employee(empdata) table 95 | sql = 'select * from empdata where Id=%s' 96 | 97 | # making cursor buffered to make 98 | # rowcount method work properly 99 | c = con.cursor(buffered=True) 100 | data = (employee_id,) 101 | 102 | # Execute the sql query 103 | c.execute(sql, data) 104 | 105 | # rowcount method to find number 106 | # of rowa with given values 107 | r = c.rowcount 108 | if r == 1: 109 | return True 110 | else: 111 | return False 112 | 113 | # Function to Display_Employ 114 | def Display_Employ(): 115 | print("{:>60}".format("-->> Display Employee Record <<--")) 116 | # query to select all rows from Employee (empdata) Table 117 | sql = 'select * from empdata' 118 | c = con.cursor() 119 | 120 | # Executing the sql query 121 | c.execute(sql) 122 | 123 | # Fetching all details of all the Employees 124 | r = c.fetchall() 125 | for i in r: 126 | print("Employee Id: ", i[0]) 127 | print("Employee Name: ", i[1]) 128 | print("Employee Email Id: ", i[2]) 129 | print("Employee Phone No.: ", i[3]) 130 | print("Employee Address: ", i[4]) 131 | print("Employee Post: ", i[5]) 132 | print("Employee Salary: ", i[6]) 133 | print("\n") 134 | press = input("Press Any key To Continue..") 135 | menu() 136 | 137 | # Function to Update_Employ 138 | def Update_Employ(): 139 | print("{:>60}".format("-->> Update Employee Record <<--\n")) 140 | Id = input("Enter Employee Id: ") 141 | # checking If Employee Id is Exit Or Not 142 | if(check_employee(Id) == False): 143 | print("Employee Record Not exists\nTry Again") 144 | press = input("Press Any Key To Continue..") 145 | menu() 146 | else: 147 | Email_Id = input("Enter Employee Email ID: ") 148 | if(re.fullmatch(regex, Email_Id)): 149 | print("Valid Email") 150 | else: 151 | print("Invalid Email") 152 | press = input("Press Any Key To Continue..") 153 | Update_Employ() 154 | Phone_no = input("Enter Employee Phone No.: ") 155 | if(Pattern.match(Phone_no)): 156 | print("Valid Phone Number") 157 | else: 158 | print("Invalid Phone Number") 159 | press = input("Press Any Key To Continue..") 160 | Update_Employ() 161 | Address = input("Enter Employee Address: ") 162 | # Updating Employee details in empdata Table 163 | sql = 'UPDATE empdata set Email_Id = %s, Phone_no = %s, Address = %s where Id = %s' 164 | data = (Email_Id, Phone_no, Address, Id) 165 | c = con.cursor() 166 | 167 | # Executing the sql query 168 | c.execute(sql, data) 169 | 170 | # commit() method to make changes in the table 171 | con.commit() 172 | print("Updated Employee Record") 173 | press = input("Press Any Key To Continue..") 174 | menu() 175 | 176 | # Function to Promote_Employ 177 | def Promote_Employ(): 178 | print("{:>60}".format("-->> Promote Employee Record <<--\n")) 179 | Id = input("Enter Employee Id: ") 180 | # checking If Employee Id is Exit Or Not 181 | if(check_employee(Id) == False): 182 | print("Employee Record Not exists\nTry Again") 183 | press = input("Press Any Key To Continue..") 184 | menu() 185 | else: 186 | Amount = int(input("Enter Increase Salary: ")) 187 | #query to fetch salary of Employee with given data 188 | sql = 'select Salary from empdata where Id=%s' 189 | data = (Id,) 190 | c = con.cursor() 191 | 192 | #executing the sql query 193 | c.execute(sql, data) 194 | 195 | #fetching salary of Employee with given Id 196 | r = c.fetchone() 197 | t = r[0]+Amount 198 | 199 | #query to update salary of Employee with given id 200 | sql = 'update empdata set Salary = %s where Id = %s' 201 | d = (t, Id) 202 | 203 | #executing the sql query 204 | c.execute(sql, d) 205 | 206 | #commit() method to make changes in the table 207 | con.commit() 208 | print("Employee Promoted") 209 | press = input("Press Any key To Continue..") 210 | menu() 211 | 212 | # Function to Remove_Employ 213 | def Remove_Employ(): 214 | print("{:>60}".format("-->> Remove Employee Record <<--\n")) 215 | Id = input("Enter Employee Id: ") 216 | # checking If Employee Id is Exit Or Not 217 | if(check_employee(Id) == False): 218 | print("Employee Record Not exists\nTry Again") 219 | press = input("Press Any Key To Continue..") 220 | menu() 221 | else: 222 | #query to delete Employee from empdata table 223 | sql = 'delete from empdata where Id = %s' 224 | data = (Id,) 225 | c = con.cursor() 226 | 227 | #executing the sql query 228 | c.execute(sql, data) 229 | 230 | #commit() method to make changes in the empdata table 231 | con.commit() 232 | print("Employee Removed") 233 | press = input("Press Any key To Continue..") 234 | menu() 235 | 236 | # Function to Search_Employ 237 | def Search_Employ(): 238 | print("{:>60}".format("-->> Search Employee Record <<--\n")) 239 | Id = input("Enter Employee Id: ") 240 | # checking If Employee Id is Exit Or Not 241 | if(check_employee(Id) == False): 242 | print("Employee Record Not exists\nTry Again") 243 | press = input("Press Any Key To Continue..") 244 | menu() 245 | else: 246 | #query to search Employee from empdata table 247 | sql = 'select * from empdata where Id = %s' 248 | data = (Id,) 249 | c = con.cursor() 250 | 251 | #executing the sql query 252 | c.execute(sql, data) 253 | 254 | #fetching all details of all the employee 255 | r = c.fetchall() 256 | for i in r: 257 | print("Employee Id: ", i[0]) 258 | print("Employee Name: ", i[1]) 259 | print("Employee Email Id: ", i[2]) 260 | print("Employee Phone No.: ", i[3]) 261 | print("Employee Address: ", i[4]) 262 | print("Employee Post: ", i[5]) 263 | print("Employee Salary: ", i[6]) 264 | print("\n") 265 | press = input("Press Any key To Continue..") 266 | menu() 267 | 268 | # Menu function to display menu 269 | def menu(): 270 | system("cls") 271 | print("{:>60}".format("************************************")) 272 | print("{:>60}".format("-->> Employee Management System <<--")) 273 | print("{:>60}".format("************************************")) 274 | print("1. Add Employee") 275 | print("2. Display Employee Record") 276 | print("3. Update Employee Record") 277 | print("4. Promote Employee Record") 278 | print("5. Remove Employee Record") 279 | print("6. Search Employee Record") 280 | print("7. Exit\n") 281 | print("{:>60}".format("-->> Choice Options: [1/2/3/4/5/6/7] <<--")) 282 | 283 | ch = int(input("Enter your Choice: ")) 284 | if ch == 1: 285 | system("cls") 286 | Add_Employ() 287 | elif ch == 2: 288 | system("cls") 289 | Display_Employ() 290 | elif ch == 3: 291 | system("cls") 292 | Update_Employ() 293 | elif ch == 4: 294 | system("cls") 295 | Promote_Employ() 296 | elif ch == 5: 297 | system("cls") 298 | Remove_Employ() 299 | elif ch == 6: 300 | system("cls") 301 | Search_Employ() 302 | elif ch == 7: 303 | system("cls") 304 | print("{:>60}".format("Have A NIce Day :)")) 305 | exit(0) 306 | else: 307 | print("Invalid Choice!") 308 | press = input("Press Any key To Continue..") 309 | menu() 310 | 311 | 312 | # Calling menu function 313 | menu() 314 | -------------------------------------------------------------------------------- /ReadME.md: -------------------------------------------------------------------------------- 1 | # Employee Management System Using Python & MySQL 🔥 2 | ## [Watch it on youtube](https://youtu.be/69lvI4tdqss) 3 | 4 | Join the channel to see more videos like this. [Sagar Developer](https://www.youtube.com/c/SagarDeveloper) 5 | 6 | ![Modal popup](/preview.png) 7 | -------------------------------------------------------------------------------- /preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-amsagar/EMS-Python/60b43f29256e2a3c956d747e03d4c918e67fc064/preview.png --------------------------------------------------------------------------------