public void DeleteEmployee(Employee add) { if (add is Manager) { string query = "DELETE FROM administration WHERE idAdministration='" + add.getDBid() + "';"; MySqlCommand cmd = new MySqlCommand(query, this.connection); cmd.ExecuteNonQuery(); string query2 = "DELETE FROM users WHERE person_id = '"+ add.getIdNumber() +"' AND type = 'manager';"; MySqlCommand cmd2 = new MySqlCommand(query2, this.connection); cmd2.ExecuteNonQuery(); } else if (add is Receptionist) { string query = "DELETE FROM reception WHERE idReception='" + add.getDBid() + "';"; MySqlCommand cmd = new MySqlCommand(query, this.connection); cmd.ExecuteNonQuery(); string query2 = "DELETE FROM users WHERE person_id = '" + add.getIdNumber() + "' AND type = 'reception';"; MySqlCommand cmd2 = new MySqlCommand(query2, this.connection); cmd2.ExecuteNonQuery(); } else if (add is Trainer) { string query = "DELETE FROM trainers WHERE idtrainer='" + add.getDBid() + "';"; MySqlCommand cmd = new MySqlCommand(query, this.connection); cmd.ExecuteNonQuery(); string query2 = "DELETE FROM users WHERE person_id = '" + add.getIdNumber() + "' AND type = 'trainer';"; MySqlCommand cmd2 = new MySqlCommand(query2, this.connection); cmd2.ExecuteNonQuery(); } else if (add is Instructor) { string query = "DELETE FROM instructor WHERE idInstructor='" + add.getDBid() + "';"; MySqlCommand cmd = new MySqlCommand(query, this.connection); cmd.ExecuteNonQuery(); string query2 = "DELETE FROM users WHERE person_id = '" + add.getIdNumber() + "' AND type = 'instructor';"; MySqlCommand cmd2 = new MySqlCommand(query2, this.connection); cmd2.ExecuteNonQuery(); } }
public void addEmployee(Employee add, String password) { string checkIfExsites = "Select * FROM users WHERE person_id = '"+ add.getIdNumber() +"' ;"; MySqlCommand cmdCheck = new MySqlCommand(checkIfExsites, this.connection); MySqlDataReader dataReader = cmdCheck.ExecuteReader(); int count = 0; while (dataReader.Read()) { count++; } dataReader.Close(); if (count > 0) { System.Windows.Forms.MessageBox.Show("ID allready in use"); return; } if (add is Manager) { string query = "INSERT INTO administration (F_Name, L_Name, Job_Description, Premission, Sal_Hour, phone_number, password, person_id, address, email) VALUES('" + add.getNameFirst() + "', '" + add.getNameLast() + "', 'manager', '" + add.getPermissionLevel() + "', '" + add.getSallaryPerHour() + "', '" + add.getPhoneNumber() + "', md5('" + password + "'), '" + add.getIdNumber() + "', '" + add.getHomeAddress() + "', '" + add.getEmailAddress() + "');"; MySqlCommand cmd = new MySqlCommand(query, this.connection); cmd.ExecuteNonQuery(); long customerDbId = cmd.LastInsertedId; string query2 = "INSERT INTO users (person_id, password, type) VALUES('" + add.getIdNumber() + "', md5('" + password + "'), 'manager');"; MySqlCommand cmd2 = new MySqlCommand(query2, this.connection); cmd2.ExecuteNonQuery(); System.Windows.Forms.MessageBox.Show("Manager was added"); } else if (add is Receptionist) { string query = "INSERT INTO reception (F_Name, L_Name, Job_Description, Premission, Sal_Hour, phone_number, password, person_id, address, email) VALUES('" + add.getNameFirst() + "', '" + add.getNameLast() + "', 'Receptionist', '" + add.getPermissionLevel() + "', '" + add.getSallaryPerHour() + "', '" + add.getPhoneNumber() + "', md5('" + password + "'), '" + add.getIdNumber() + "', '" + add.getHomeAddress() + "', '" + add.getEmailAddress() + "');"; MySqlCommand cmd = new MySqlCommand(query, this.connection); cmd.ExecuteNonQuery(); long customerDbId = cmd.LastInsertedId; string query2 = "INSERT INTO users (person_id, password, type) VALUES('" + add.getIdNumber() + "', md5('" + password + "'), 'reception');"; MySqlCommand cmd2 = new MySqlCommand(query2, this.connection); cmd2.ExecuteNonQuery(); System.Windows.Forms.MessageBox.Show("Reciption was added"); } else if (add is Trainer) { string query = "INSERT INTO trainers (F_Name, L_Name, Job_Description, Premission, Sal_Hour, phone_number, password, person_id, address, email, certificate) VALUES('" + add.getNameFirst() + "', '" + add.getNameLast() + "', 'trainer', '" + add.getPermissionLevel() + "', '" + add.getSallaryPerHour() + "', '" + add.getPhoneNumber() + "', md5('" + password + "'), '" + add.getIdNumber() + "', '" + add.getHomeAddress() + "', '" + add.getEmailAddress() + "', '" + ((Trainer)add).getTrainerCartificate() + "');"; MySqlCommand cmd = new MySqlCommand(query, this.connection); cmd.ExecuteNonQuery(); long customerDbId = cmd.LastInsertedId; string query2 = "INSERT INTO users (person_id, password, type) VALUES('" + add.getIdNumber() + "', md5('" + password + "'), 'trainer');"; MySqlCommand cmd2 = new MySqlCommand(query2, this.connection); cmd2.ExecuteNonQuery(); System.Windows.Forms.MessageBox.Show("Trainer was added"); } else if (add is Instructor) { string query = "INSERT INTO instructor (F_Name, L_Name, Job_Description, Premission, Sal_Hour, phone_number, password, person_id, address, email) VALUES('" + add.getNameFirst() + "', '" + add.getNameLast() + "', 'instructor', '" + add.getPermissionLevel() + "', '" + add.getSallaryPerHour() + "', '" + add.getPhoneNumber() + "', md5('" + password + "'), '" + add.getIdNumber() + "', '" + add.getHomeAddress() + "', '" + add.getEmailAddress() + "');"; MySqlCommand cmd = new MySqlCommand(query, this.connection); cmd.ExecuteNonQuery(); long customerDbId = cmd.LastInsertedId; string query2 = "INSERT INTO users (person_id, password, type) VALUES('" + add.getIdNumber() + "', md5('" + password + "'), 'instructor');"; MySqlCommand cmd2 = new MySqlCommand(query2, this.connection); cmd2.ExecuteNonQuery(); System.Windows.Forms.MessageBox.Show("Instructor was added"); } }
public String EditEmployee(Employee add) { int returnRows = 0; if (add is Manager) { string query = "UPDATE administration SET F_Name='" + add.getNameFirst() + "', L_Name='" + add.getNameLast() + "', Job_Description='manager', Premission='" + add.getPermissionLevel() + "', Sal_Hour='" + add.getSallaryPerHour() + "', phone_number='" + add.getPhoneNumber() + "', person_id='" + add.getIdNumber() + "', address='" + add.getHomeAddress() + "', email='" + add.getEmailAddress() + "' WHERE idAdministration='"+add.getDBid()+"';"; MySqlCommand cmd = new MySqlCommand(query, this.connection); returnRows = cmd.ExecuteNonQuery(); } else if (add is Receptionist) { string query = "UPDATE reception SET F_Name='" + add.getNameFirst() + "', L_Name='" + add.getNameLast() + "', Job_Description='reception', Premission='" + add.getPermissionLevel() + "', Sal_Hour='" + add.getSallaryPerHour() + "', phone_number='" + add.getPhoneNumber() + "', person_id='" + add.getIdNumber() + "', address='" + add.getHomeAddress() + "', email='" + add.getEmailAddress() + "' WHERE idReception='" + add.getDBid() + "';"; MySqlCommand cmd = new MySqlCommand(query, this.connection); returnRows = cmd.ExecuteNonQuery(); } else if (add is Trainer) { string query = "UPDATE trainers SET F_Name='" + add.getNameFirst() + "', L_Name='" + add.getNameLast() + "', Job_Description='trainer', Premission='" + add.getPermissionLevel() + "', Sal_Hour='" + add.getSallaryPerHour() + "', phone_number='" + add.getPhoneNumber() + "', person_id='" + add.getIdNumber() + "', address='" + add.getHomeAddress() + "', certificate=" + ((Trainer)add).getTrainerCartificate() + ",email='" + add.getEmailAddress() + "' WHERE idtrainer='" + add.getDBid() + "';"; MySqlCommand cmd = new MySqlCommand(query, this.connection); returnRows = cmd.ExecuteNonQuery(); } else if (add is Instructor) { string query = "UPDATE instructor SET F_Name='" + add.getNameFirst() + "', L_Name='" + add.getNameLast() + "', Job_Description='instructor', Premission='" + add.getPermissionLevel() + "', Sal_Hour='" + add.getSallaryPerHour() + "', phone_number='" + add.getPhoneNumber() + "', person_id='" + add.getIdNumber() + "', address='" + add.getHomeAddress() + "', email='" + add.getEmailAddress() + "' WHERE idInstructor='" + add.getDBid() + "';"; MySqlCommand cmd = new MySqlCommand(query, this.connection); returnRows = cmd.ExecuteNonQuery(); } if (returnRows <= 0) { return "No Employee Was Edited"; } else { return add.getNameFirst() + " " + add.getNameLast() + " was Edited"; } }