//Delete Employees employee management list---------------------------------------------------------------------------------------------------- public void deleteEmp(String id) { try { if (MessageBox.Show("Are you sure to Delete this record?", "Delete Category", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (DBEntities db = new DBEntities()) { if (id.StartsWith("D")) { driver = db.Drivers.Where(x => x.driverid == id).First(); db.Drivers.Remove(driver); db.SaveChanges(); } else if (id.StartsWith("C")) { cleaner = db.Cleaners.Where(x => x.cleanerid == id).First(); db.Cleaners.Remove(cleaner); db.SaveChanges(); } else if (id.StartsWith("hc")) { hf = db.HeadChefs.Where(x => x.headchefid == id).First(); db.HeadChefs.Remove(hf); db.SaveChanges(); } else if (id.StartsWith("M")) { manager = db.Managers.Where(x => x.Managerid == id).First(); db.Managers.Remove(manager); db.SaveChanges(); } else if (id.StartsWith("Rc")) { reception = db.Receptions.Where(x => x.receptionid == id).First(); db.Receptions.Remove(reception); db.SaveChanges(); } emp = db.Employees.Where(x => x.employeeId == id).First(); db.Employees.Remove(emp); db.SaveChanges(); } MessageBox.Show("Category Removed Successfully!!!"); clearempcardpanel(); Refresh(); } loadEmployees(); } //Exception handling catch (DbUpdateException) { MessageBox.Show("Forignkey supported no delete please salary and attendendence select user deletails delete", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (InvalidOperationException) { MessageBox.Show("InvalidOperation", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } }//----------------------------------------------------------------------------------------------------------------------------------------------------------------------
//edit employees ================================================== public void editemployee(String id) { status = "update"; btnSave.Text = "Update"; using (DBEntities db = new DBEntities()) { employeeModel = db.Employees.Where(x => x.employeeId == id).FirstOrDefault(); MessageBox.Show(employeeModel.employeeId, "Employee Access update"); txtempid.Text = employeeModel.employeeId; txtfname.Text = employeeModel.fname; txtlname.Text = employeeModel.lname; txtaddress.Text = employeeModel.address; txtemail.Text = employeeModel.email; txtdob.Value = Convert.ToDateTime(employeeModel.dob.ToString()); txtconatcno.Text = employeeModel.contactno.ToString(); txtbasicsal.Text = employeeModel.basicsalary.ToString(); txtnationality.Text = employeeModel.nationality; txtmatrialststus.Text = employeeModel.matrialstatus; txtnic.Text = employeeModel.nic; cmbgender.Text = employeeModel.gender; if (id.StartsWith("D")) { rbdriver.Text = employeeModel.designation; } picBoxEmp.Image = Util.convertBinaryToImage(employeeModel.image); if (id.StartsWith("D")) { driverModel = db.Drivers.Where(x => x.driverid == id).FirstOrDefault(); MessageBox.Show(driverModel.driverid, "Driver Access update"); cmbDriverSerivice.Text = driverModel.service; txtlicenceno.Text = driverModel.licenceNo.ToString(); cmbdrivertype.Text = driverModel.type; } else if (id.StartsWith("C")) { cleanerModel = db.Cleaners.Where(x => x.cleanerid == id).FirstOrDefault(); MessageBox.Show(cleanerModel.cleanerid, "Cleaners Access update"); txtclenertype.Text = cleanerModel.ctype; } else if (id.StartsWith("hc")) { HeadchefModel = db.HeadChefs.Where(x => x.headchefid == id).FirstOrDefault(); MessageBox.Show(HeadchefModel.headchefid, "HeadChefs Access update"); txtservice.Text = HeadchefModel.service; } else if (id.StartsWith("M")) { ManagerModel = db.Managers.Where(x => x.Managerid == id).FirstOrDefault(); MessageBox.Show(ManagerModel.Managerid, "Managers Access update"); cmbexperiecnce.Text = ManagerModel.experience; } else if (id.StartsWith("Rc")) { receptionModel = db.Receptions.Where(x => x.receptionid == id).FirstOrDefault(); MessageBox.Show(receptionModel.receptionid, "Receptions Access update"); cmblanguage.Text = receptionModel.language; } } }// end the edit details===================================================