public void Insert(Filho filho) { try { var connection = new MySqlConnection(Dao.connectionstring); connection.Open(); string sql = $"insert into {table} (nome, idade, idPaiFk) " + "values (@nome, @idade, @idPaiFk);"; var command = new MySqlCommand(sql, connection); command.Parameters.AddWithValue("@nome", filho.Nome); command.Parameters.AddWithValue("@idade", filho.Idade); command.Parameters.AddWithValue("@idPaiFk", filho.Pai.Id); command.ExecuteNonQuery(); connection.Close(); } catch (Exception ex) { throw ex; } }
public void BuscarFilhos() { dgvFilhos.DataSource = null; var filhos = new Filho(); dgvFilhos.DataSource = filhos.Buscar("SELECT ID, IDPai, NomeFilho AS Nome, Idade, Sexo FROM Filhos WHERE IDPai =" + IdSelecionado); foreach (DataGridViewColumn column in dgvFilhos.Columns) { if (column.Name == "Nome" || column.Name == "Idade" || column.Name == "Sexo") { if (column.Name == "Idade" || column.Name == "Sexo") { column.Width = 70; } else { column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } } else { column.Visible = false; } } }
public Filho PesquisarPorId(int id) { try { var sql = "SELECT * FROM filho WEHERE id = @id"; command = new MySqlCommand(sql, connection); command.Parameters.AddWithValue("@id", id); dataReader = command.ExecuteReader(); //receber o resultado da consulta Filho filho = new Filho(); if (dataReader.Read()) { filho.Id = Convert.ToInt32(dataReader["id"]); filho.IdPai = Convert.ToInt32(dataReader["idPai"]); filho.IdMae = Convert.ToInt32(dataReader["idMae"]); filho.Nome = dataReader["nome"].ToString(); filho.dtCadastro = dataReader["dtCadastro"].ToString(); } return(filho); } catch (Exception erro) { throw new Exception("Erro ao registrar dado" + erro); } }
public void Edit(Filho filho) { try { var connection = new MySqlConnection(Dao.connectionstring); connection.Open(); string sql = $"update {table} set " + "nome = @nome, " + "idade = @idade, " + "idPaiFk = @idPaiFk " + "where id = @id;"; var command = new MySqlCommand(sql, connection); command.Parameters.AddWithValue("@nome", filho.Nome); command.Parameters.AddWithValue("@idade", filho.Idade); command.Parameters.AddWithValue("@idPaiFk", filho.Pai.Id); command.Parameters.AddWithValue("@id", filho.Id); command.ExecuteNonQuery(); connection.Close(); } catch (Exception ex) { throw ex; } }
public List <Filho> PesquisarPorNome(string nome) { try { var sql = "SELECT * FROM filho WHERE nome LIKE '%" + nome + "%' "; command = new MySqlCommand(sql, connection); dataReader = command.ExecuteReader(); List <Filho> listaFilho = new List <Filho>(); while (dataReader.Read()) { Filho filho = new Filho(); filho.Id = Convert.ToInt32(dataReader["id"]); filho.Nome = dataReader["nome"].ToString(); filho.dtCadastro = dataReader["dtCadastro"].ToString(); listaFilho.Add(filho); } return(listaFilho); } catch (Exception erro) { throw new Exception("Erro ao registrar dado " + erro); } }
// GET: filho public ActionResult Index() { var filhos = DB.RetornaTodos(); List <Filho> listfilho = new List <Filho>(); foreach (DataRow i in filhos.Rows) { Pai p = new Pai { Id = Int32.Parse(i["paiId"].ToString()), Nome = i["paiNome"].ToString(), Cpf = i["paiCpf"].ToString() }; Filho f = new Filho { Id = Int32.Parse(i["filhoId"].ToString()), Nome = i["filhoNome"].ToString(), Idade = i["filhoIdade"].ToString(), Pai = p }; listfilho.Add(f); } return(View(listfilho)); }
public Animal Reproduz() { Animal filho = new Animal(); Filho.Nasce(); return(Filho); }
static void Main(string[] args) { DataContext dc = new DataContext(@"Data Source=.\sqlexpress;Initial Catalog=vs2010;Integrated Security=True"); dc.Log = Console.Out; Table<Filho> filhosDoAdao = dc.GetTable<Filho>(); ObjectDumper.Write(filhosDoAdao); Console.WriteLine(); Filho ooops = new Filho() { NomeFilho = "TIANA", CodigoPessoa = 1 }; filhosDoAdao.InsertOnSubmit(ooops); dc.SubmitChanges(); ObjectDumper.Write(dc.GetTable<Filho>()); Console.WriteLine(); filhosDoAdao.DeleteOnSubmit(ooops); dc.SubmitChanges(); ObjectDumper.Write(dc.GetTable<Filho>()); Console.ReadKey(); }
public Filho PesquisarPorId(int id) { try { var sql = "SELECT * FROM filho WHERE id = @id"; command = new MySqlCommand(sql, connection); command.Parameters.AddWithValue("@id", id); dataReader = command.ExecuteReader(); //command.ExecuteNonQuery(); Filho filho = new Filho(); if (dataReader.Read()) { filho.Id = Convert.ToInt32(dataReader["id"]); filho.Nome = dataReader["nome"].ToString(); filho.dtCadsatro = dataReader["dtCadastro"].ToString(); } return(filho); } catch (Exception erro) { throw new Exception("Erro de insercao" + erro); } }
void LocalReport_SubreportProcessing(object sender, Microsoft.Reporting.WinForms.SubreportProcessingEventArgs e) { var id = int.Parse(e.Parameters["IdPai"].Values[0].ToString()); var filho = new Filho(); var dt = filho.ExecutarSelect("SELECT * FROM Filhos WHERE IdPai=" + id); e.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("FilhosDataSet", dt)); }
public void CriarNovoFilho() { Filho novoFilho = new Filho(ifNomeNovoFilho.text, int.Parse(ifIdadeNovoFilho.text), SexoFilho); listaFilhos.Add(novoFilho); SaveAndLoad.instance.Save(listaFilhos, QuestController.instance.ListOfQuests, UserID); AtualizarListaFilhos(); }
public static void Executar() { SemFilho semFilho = new SemFilho(); Console.WriteLine(semFilho.Fortuna()); Filho filho = new Filho(); Console.WriteLine(filho.HonrarNome()); }
private void btnSalvarFilho_Click(object sender, EventArgs e) { if (IdSelecionado == 0 && txtNome.Text == string.Empty) { MessageBox.Show("Selecione uma pessoa antes de inserir o filho!"); return; } if (IdSelecionado == 0 && txtNome.Text != string.Empty) { MessageBox.Show("Necessário Salvar a pessoa antes de inserir os filhos!"); return; } if (txtNomeFilho.Text == string.Empty) { MessageBox.Show("Nome do Filho é obrigatório!"); txtNomeFilho.Focus(); return; } var filho = new Filho(); filho.IdPai = IdSelecionado; filho.NomeFilho = txtNomeFilho.Text; if (!string.IsNullOrEmpty(txtIdadeFilho.Text)) { filho.Idade = Convert.ToInt32(txtIdadeFilho.Text); } filho.Sexo = cboSexoFilho.Text; if (IdFilhoSelecionado == 0) { if (filho.Salvar()) { MessageBox.Show("Salvo com sucesso!"); } } else { if (filho.Atualizar(IdFilhoSelecionado)) { MessageBox.Show("Atualizado com sucesso!"); } } IdFilhoSelecionado = 0; txtNomeFilho.Text = null; txtIdadeFilho.Text = null; cboSexoFilho.Text = null; BuscarFilhos(); }
static void Main() { Pai p = new Pai(); Filho f = new Filho(); p.changeName("gg"); p.getName(); f.changename("ff"); f.getname(); p.getName(); }
// GET: filho/Details/5 public ActionResult Details(int id) { var filho = new Filho(); foreach (DataRow i in DB.GetById(id).Rows) { filho.Id = Int32.Parse(i["filhoId"].ToString()); filho.Nome = i["filhoNome"].ToString(); filho.Idade = i["filhoIdade"].ToString(); } return(View(filho)); }
public void Salvar(Filho filho) { try { var sql = "INSERT INTO filho(nome, dtCadastro) " + "VALUES(@nome, CURDATE())"; command = new MySqlCommand(sql, connection); command.Parameters.AddWithValue("@nome", filho.Nome); command.ExecuteNonQuery(); } catch (Exception erro) { throw new Exception("Erro ao registrar dado " + erro); } }
private void dtGridLista_CellClick(object sender, DataGridViewCellEventArgs e) { switch (tipoPesquisaLocal) { case TipoPesquisa.Pessoa: var controllerPessoa = new Pessoa(); switch (dtGridLista.Columns[e.ColumnIndex].Name) { case "btnEditar": var id = (int)dtGridLista.CurrentRow.Cells["Código"].Value; var pessoa = controllerPessoa.BuscarPorId(id); var frmPessoa = new frmCadastroPessoas(pessoa); frmPessoa.Show(); break; case "btnExcluir": var returnMsg = MessageBox.Show($"Deseja Excluir!", "Pergunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (returnMsg == DialogResult.Yes) { var idPessoa = (int)dtGridLista.CurrentRow.Cells["Código"].Value; var controllerFilho = new Filho(); controllerFilho.ExcluirPorIdDoPai(idPessoa); controllerPessoa.Excluir(idPessoa); popularDataGrid(); } break; default: break; } break; default: break; } }
public Filho AddFilho(string nome, string morada, string localidade, string codPostal, string telefone, string telemovel, string mail, string sexo, DateTime DataNascimento, int idEscola, int idProgenitor) { var filho = new Filho() { Nome = nome, Morada = morada, Localidade = localidade, CodPostal = codPostal, Telefone = telefone, Telemovel = telemovel, Mail = mail, Sexo = sexo, DataNascimento = DataNascimento, IdEscola = idEscola, IdProgenitor = idProgenitor, }; basedados.Pessoa.Add(filho); basedados.SaveChanges(); return(filho); }
private void btnExcluirFilho_Click(object sender, EventArgs e) { if (IdFilhoSelecionado == 0) { MessageBox.Show("Nenhum Filho Selecionado!"); return; } var result = MessageBox.Show($"Deseja excluir o filho(a) {txtNomeFilho.Text}?", "Pergunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { var filho = new Filho(); filho.ExecutarSQL($"DELETE FROM Filhos WHERE ID=" + dgvFilhos.CurrentRow.Cells["ID"].Value); txtNomeFilho.Text = null; txtIdadeFilho.Text = null; cboSexoFilho.Text = null; IdFilhoSelecionado = 0; } BuscarFilhos(); }
public ActionResult Edit(Filho filho, int idPai) { try { var pai = new Pai(); foreach (DataRow i in PaiDao.GetById(idPai).Rows) { pai.Id = Int32.Parse(i["id"].ToString()); pai.Nome = i["nome"].ToString(); pai.Cpf = i["cpf"].ToString(); } filho.Pai = pai; DB.Edit(filho); return(RedirectToAction("Index")); } catch { return(View()); } }
// GET: filho/Edit/5 public ActionResult Edit(int id) { var filho = new Filho(); var pais = new List <Pai>(); foreach (DataRow i in PaiDao.RetornaTodos().Rows) { var pai = new Pai { Id = Int32.Parse(i["id"].ToString()), Nome = i["nome"].ToString(), Cpf = i["cpf"].ToString() }; pais.Add(pai); } foreach (DataRow i in DB.GetById(id).Rows) { var pai = new Pai { Id = Int32.Parse(i["paiId"].ToString()), Nome = i["paiNome"].ToString(), Cpf = i["paiCpf"].ToString() }; filho.Id = Int32.Parse(i["filhoId"].ToString()); filho.Nome = i["filhoNome"].ToString(); filho.Idade = i["filhoIdade"].ToString(); filho.Pai = pai; } ViewBag.Pais = new SelectList(pais, "Id", "Nome", filho.Pai.Id); return(View(filho)); }
//Adicionar dados inseridos pelo operador do sistema. public static void AddFilho(Filho p1) { Filhos.Add(p1); }
public ActionResult Buscar(string tabela, string procurar) { var _tabela = tabela; var _procurar = procurar; var listViewModels = new List <PaiFilhoViewModels>(); var pais = new List <Pai>(); var filhos = new List <Filho>(); if (tabela == "Pai") { foreach (DataRow i in buscardao.BuscarPorNome("pai", procurar).Rows) { var pai = new Pai() { Id = Int32.Parse(i["id"].ToString()), Nome = i["nome"].ToString(), Cpf = i["cpf"].ToString(), }; pais.Add(pai); } return(View("_ResultPai", pais)); } else if (tabela == "Filho") { foreach (DataRow i in buscardao.BuscarPorNome("filho", procurar).Rows) { var pai = new Pai() { Id = Int32.Parse(i["paiId"].ToString()), Nome = i["paiNome"].ToString(), Cpf = i["paiCpf"].ToString(), }; var filho = new Filho() { Id = Int32.Parse(i["filhoId"].ToString()), Nome = i["filhoNome"].ToString(), Idade = i["filhoIdade"].ToString(), Pai = pai }; filhos.Add(filho); } return(View("_ResultFilho", filhos)); } else { foreach (DataRow i in buscardao.RetornaTodos().Rows) { var viewmodel = new PaiFilhoViewModels() { IdPai = Int32.Parse(i["paiId"].ToString()), Pai = i["paiNome"].ToString(), Cpf = i["paiCpf"].ToString(), IdFilho = Int32.Parse(i["filhoId"].ToString()), Filho = i["filhoNome"].ToString(), Idade = i["filhoIdade"].ToString() }; listViewModels.Add(viewmodel); } return(View("_Result", listViewModels)); } }
public static void Executar() { Filho filho = new Filho(); Console.WriteLine(filho.HonrarNome()); }
public PedirCafe() { var resultadoPai = new Pai("Joao").GetNome(); // Joao var resultadoFilho = new Filho("Lucas").GetNome(); // Lucas }