private void btnDelete_Click(object sender, EventArgs e) { string id = dgvResult.Rows[dgvResult.CurrentCell.RowIndex].Cells[0].Value.ToString(); DialogResult dr = new DialogResult(); dr = MessageBox.Show("Do you really want to delete a record, ID = " + id + " ?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if ((int)dr == 6) { if (frmRemax.formToManage == "house") { if (frmLogin.admin != null) { frmLogin.admin.Houses = Remax.TabHouses(); frmLogin.admin.DeleteHouse(id); HouseDB.UpdateHousesDB(frmLogin.admin.Houses); } if (frmLogin.agent != null) { house = HouseDB.getHouse(id); if (house.IdAgent != frmLogin.agent.Id) { MessageBox.Show("The house added by another agent.You can not delete."); } else { frmLogin.agent.Houses = Remax.TabHouses(); frmLogin.agent.DeleteHouse(id); HouseDB.UpdateHousesDB(frmLogin.agent.Houses); } } } else if (frmRemax.formToManage == "client") { if (frmLogin.admin != null) { frmLogin.admin.Clients = Remax.TabClients(); frmLogin.admin.DeleteClient(id); ClientDB.UpdateClientsDB(frmLogin.admin.Clients); } else { frmLogin.agent.Clients = Remax.TabClients(); frmLogin.agent.DeleteClient(id); ClientDB.UpdateClientsDB(frmLogin.agent.Clients); } } else if (frmRemax.formToManage == "employee") { frmLogin.admin.Employees = Remax.TabEmployees(); frmLogin.admin.Languages = Remax.TabLanguages(); frmLogin.admin.DeleteEmployee(id); EmployeeDB.UpdateEmployeesDB(frmLogin.admin.Employees, frmLogin.admin.Languages); } } }
private void btnESave_Click(object sender, EventArgs e) { string gender = ""; gender = (radEFemale.Checked) ? "f" : "m"; Agent agent = (frmManage.mode == "edit")? new Agent(frmManage.agent.Id, txtEName.Text, txtEPhone.Text, txtEEmail.Text, cboERole.Text, gender, txtEAddress.Text, "1", listLanguages, txtEPassword.Text): new Agent(txtEName.Text, txtEPhone.Text, txtEEmail.Text, cboERole.Text, gender, txtEAddress.Text, "1", listLanguages, txtEPassword.Text); if (frmManage.mode == "add") { frmLogin.admin.Employees = Remax.TabEmployees(); frmLogin.admin.Languages = Remax.TabLanguages(); frmLogin.admin.AddEmployee(agent); EmployeeDB.UpdateEmployeesDB(frmLogin.admin.Employees, frmLogin.admin.Languages); } if (frmManage.mode == "edit") { frmLogin.admin.Employees = Remax.TabEmployees(); frmLogin.admin.Languages = Remax.TabLanguages(); frmLogin.admin.EditEmployee(agent); EmployeeDB.UpdateEmployeesDB(frmLogin.admin.Employees, frmLogin.admin.Languages); } this.Close(); }