private void dgrMorador_CellClick(object sender, DataGridViewCellEventArgs e) { btnInserir.Text = "Alterar"; PopularApartamento(); if (e.RowIndex != -1) { int ID = Convert.ToInt32(dgrMorador.Rows[e.RowIndex].Cells[0].Value.ToString()); BLL.BllMorador bllMorador = new BLL.BllMorador(); Morador morador = new Morador(); Endereco endereco = new Endereco(); morador = bllMorador.Return_Morador(ID); txtNome.Text = morador.MORADORNOME; txtDoc.Text = morador.MORADORCPF; txtRG.Text = morador.MORADORRG; txtDDD1.Text = morador.MORADORDDD1; txtDDD2.Text = morador.MORADORDDD2; cbxApartamento.SelectedValue = Convert.ToInt32(morador.MORADORAPART.ToString()); txtTel.Text = morador.MORADORDTEL; txtCel.Text = morador.MORADORDCEL; txtEmail.Text = morador.MORADOREMAIL; lblID.Text = morador.MORADORID.ToString(); } }
public void PopularListMorador() { dgrMorador.Rows.Clear(); BLL.BllMorador bllMorador = new BLL.BllMorador(); lstMorador = bllMorador.Return_ListMorador(); for (int i = 0; i < lstMorador.Count; i++) { dgrMorador.Rows.Add(lstMorador[i].MORADORID, lstMorador[i].MORADORNOME); } }
private void btnInserir_Click(object sender, EventArgs e) { Error = false; BLL.BllMorador bllMorador = new BLL.BllMorador(); if (!validarComponentes()) { if (btnInserir.Text == "Inserir") { Morador modelMorador = new Morador(); modelMorador.MORADORNOME = txtNome.Text; modelMorador.MORADORCPF = txtDoc.Text; modelMorador.MORADORRG = txtRG.Text; modelMorador.MORADORDTEL = txtTel.Text; modelMorador.MORADORDCEL = txtCel.Text; modelMorador.MORADORDDD1 = txtDDD1.Text; modelMorador.MORADORDDD2 = txtDDD2.Text; modelMorador.MORADORAPART = Convert.ToInt32(cbxApartamento.SelectedValue); if (ValidarEmail(txtEmail.Text)) { modelMorador.MORADOREMAIL = txtEmail.Text; } else { Error = true; } if (Error == false) { bllMorador.Insert_Morador(modelMorador); MetroMessageBox.Show(this, "Morador cadastrado com sucesso.", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } PopularListMorador(); LimparCampos(); } else if (btnInserir.Text == "Alterar") { Morador modelMorador = new Morador(); modelMorador.MORADORID = Convert.ToInt32(lblID.Text); modelMorador.MORADORNOME = txtNome.Text; modelMorador.MORADORCPF = txtDoc.Text; modelMorador.MORADORRG = txtRG.Text; modelMorador.MORADORDTEL = txtTel.Text; modelMorador.MORADORDCEL = txtCel.Text; modelMorador.MORADORDDD1 = txtDDD1.Text; modelMorador.MORADORDDD2 = txtDDD2.Text; modelMorador.MORADORAPART = Convert.ToInt32(cbxApartamento.SelectedValue); if (ValidarEmail(txtEmail.Text)) { modelMorador.MORADOREMAIL = txtEmail.Text; } else { Error = true; } if (Error == false) { bllMorador.Update_Proprietario(modelMorador); MetroMessageBox.Show(this, "Morador alterado com sucesso.", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } PopularListMorador(); LimparCampos(); } } }