//EDITAR PELO DATAGRID private void BtnEditar_Click(object sender, EventArgs e) { if (MyMessageBox.Show(this, "", "Deseja editar?", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { pet.CodPet = Convert.ToInt16(dtGridPet.CurrentRow.Cells["codpet"].Value.ToString()); pet.Nome = dtGridPet.CurrentRow.Cells["nome"].Value.ToString(); pet.Especie = dtGridPet.CurrentRow.Cells["especie"].Value.ToString(); pet.Raca = dtGridPet.CurrentRow.Cells["raca"].Value.ToString(); pet.Porte = dtGridPet.CurrentRow.Cells["porte"].Value.ToString(); pet.Sexo = dtGridPet.CurrentRow.Cells["sexo"].Value.ToString(); pet.Cor = dtGridPet.CurrentRow.Cells["cor"].Value.ToString(); petBo.Editar(pet); } catch { MyMessageBox.Show(this, "Por favor preencha corretamente e tente novamente.", "NÃO foi possivel editar"); } } }
private void btnAlterar_Click(object sender, EventArgs e) { for (int i = 0; i < dataGridView1.RowCount; i++) { dataGridView1.Rows[i].DataGridView.Columns.Clear(); } try { //pega codigo bloco apartamento BA ba = new BA(); BABO babo = new BABO(); ba.Apto = txtApto.Text; ba.Bloco = txtBloco.Text; babo.BuscaCodBA(ba); if ((ba.Bloco == "") || (ba.Apto == "")) { MessageBox.Show("Bloco/Apartamento não encontrado"); txtApto.Clear(); txtBloco.Clear(); } else { lblBACod.Text = Convert.ToString(ba.Ba_Cod); try { //pega codigo morador Moradores mor = new Moradores(); MoradoresBO morBO = new MoradoresBO(); mor.Nome = txtTutor.Text; morBO.Buscar(mor); if (mor.Nome == "") { MessageBox.Show("Tutor não encontrado"); txtTutor.Clear(); } else { lblMoradorCod.Text = Convert.ToString(mor.CodMorador); //altera o pet try { Pets pets = new Pets(); PetsBO petsBO = new PetsBO(); pets.Nome = txtNome.Text; if ((pets.Nome == "") || (pets.Nome == null)) { MessageBox.Show("Nome do pet não identificado"); } else { pets.CodPet = Convert.ToInt16(lblCodPet.Text); pets.Nome = txtNome.Text.ToUpper(); pets.Moradores.CodMorador = Convert.ToInt16(lblMoradorCod.Text); pets.BA.Ba_Cod = Convert.ToInt16(lblBACod.Text); pets.Especie = cbbEspecie.SelectedItem.ToString(); petsBO.Editar(pets); MessageBox.Show("Pet editado com sucesso"); txtNome.Clear(); txtApto.Clear(); txtBloco.Clear();; txtTutor.Clear(); cbbEspecie.SelectedIndex = -1; txtBusca.Clear(); panel1.Enabled = false; btnAlterar.Enabled = false; btnExcluir.Enabled = false; lblCodPet.Text = ""; } } catch { MessageBox.Show("Verifique os dados e tente novamente"); } } } catch { MessageBox.Show("Verifique os dados e tente novamente"); } } } catch { MessageBox.Show("Verifique os dados e tente novamente"); } }