Ejemplo n.º 1
0
        private void btSalvar_Click(object sender, RoutedEventArgs e)
        {
            cc = new Contato
            {
                nome     = txtNome.Text,
                telefone = txtTelefone.Text,
                email    = txtEmail.Text
            };
            // contato com os dados da tela
            contato c = new contato();

            c.nome     = txtNome.Text;
            c.email    = txtEmail.Text;
            c.telefone = txtTelefone.Text;
            // gravar no banco
            if (operacao == "inserir")
            {
                using (agendaEntities ctx = new agendaEntities())
                {
                    ctx.contatos.Add(c);
                    ctx.SaveChanges();
                }
            }
            if (operacao == "alterar")
            {
            }
            this.ListarContatos();
            this.AlteraBotoes(1);
            this.LimpaCampos();
        }
Ejemplo n.º 2
0
 private void ListarContatos()
 {
     using (agendaEntities ctx = new agendaEntities())
     {
         int a = ctx.contatos.Count();
         lbQtdContatos.Content = "Número de contatos existente: " + a.ToString();
         var consulta = ctx.contatos;
         dgDados.ItemsSource = consulta.ToList();
     }
 }
Ejemplo n.º 3
0
 private void btLocalizar_Click(object sender, RoutedEventArgs e)
 {
     // buscar pelo id
     if (txtID.Text.Trim().Count() > 0)
     {
         try
         {
             int id = Convert.ToInt32(txtID.Text);
             using (agendaEntities ctx = new agendaEntities())
             {
                 contato c = ctx.contatos.Find(id);
                 dgDados.ItemsSource = new contato[1] {
                     c
                 };
             }
         } catch
         {
         }
     }
     // buscar pelo nome
     if (txtNome.Text.Trim().Count() > 0)
     {
         try
         {
             using (agendaEntities ctx = new agendaEntities())
             {
                 var consulta = from c in ctx.contatos
                                where c.nome.Contains(txtNome.Text)
                                select c;
                 dgDados.ItemsSource = consulta.ToList();
             }
         } catch
         {
         }
     }
     // buscar pelo email
     if (txtEmail.Text.Trim().Count() > 0)
     {
         try
         {
             using (agendaEntities ctx = new agendaEntities())
             {
                 var consulta = from c in ctx.contatos
                                where c.email.Contains(txtEmail.Text)
                                select c;
                 dgDados.ItemsSource = consulta.ToList();
             }
         }
         catch
         {
         }
     }
     // buscar pelo telefone
     if (txtTelefone.Text.Trim().Count() > 0)
     {
         try
         {
             using (agendaEntities ctx = new agendaEntities())
             {
                 var consulta = from c in ctx.contatos
                                where c.telefone.Contains(txtTelefone.Text)
                                select c;
                 dgDados.ItemsSource = consulta.ToList();
             }
         }
         catch
         {
         }
     }
 }