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 btnCSave_Click(object sender, EventArgs e) { Client client = new Client(); if (frmManage.mode == "edit") { client.Id = frmManage.client.Id; } client.Name = txtCName.Text; client.Phone = txtCPhone.Text; client.Email = txtCEmail.Text; client.Comment = txtCComment.Text; client.IdAgent = (frmLogin.agent != null) ? frmLogin.agent.Id : cboAgent.SelectedValue.ToString(); client.Role = cboRole.Text; if (frmManage.mode == "add" && frmLogin.admin != null) { frmLogin.admin.Clients = Remax.TabClients(); frmLogin.admin.AddClient(client); ClientDB.UpdateClientsDB(frmLogin.admin.Clients); } if (frmManage.mode == "add" && frmLogin.agent != null) { frmLogin.agent.Clients = Remax.TabClients(); frmLogin.agent.AddClient(client); ClientDB.UpdateClientsDB(frmLogin.agent.Clients); } if (frmManage.mode == "edit" && frmLogin.admin != null) { client.Id = frmManage.client.Id; frmLogin.admin.Clients = Remax.TabClients(); frmLogin.admin.EditClient(client); ClientDB.UpdateClientsDB(frmLogin.admin.Clients); } if (frmManage.mode == "edit" && frmLogin.agent != null) { client.Id = frmManage.client.Id; frmLogin.agent.Clients = Remax.TabClients(); frmLogin.agent.EditClient(client); ClientDB.UpdateClientsDB(frmLogin.agent.Clients); } this.Close(); }