Example #1
0
        private void BtnSalvar_Click(object sender, RoutedEventArgs e)
        {
            //Gravar no Banco de Dados
            if (operacao == "inserir")
            {
                contato          = new agendum();
                contato.nome     = txtNome.Text;
                contato.email    = txtEmail.Text;
                contato.telefone = txtTelefone.Text;

                context.agenda.Add(contato);
                context.SaveChanges();
            }
            if (operacao == "alterar")
            {
                contato = context.agenda.Find(Convert.ToInt32(txtId.Text));
                if (context != null)
                {
                    contato.nome     = txtNome.Text;
                    contato.email    = txtEmail.Text;
                    contato.telefone = txtTelefone.Text;
                    context.SaveChanges();
                }
            }
            AlterarBotoes(1);
            ListarContatos();
            LimparCampos();
        }
Example #2
0
 private void DtGridResultado_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     if (dtGridResultado.SelectedIndex >= 0)
     {
         AlterarBotoes(3);
         contato          = (agendum)dtGridResultado.SelectedItem;
         txtId.Text       = contato.id.ToString();
         txtNome.Text     = contato.nome;
         txtEmail.Text    = contato.email;
         txtTelefone.Text = contato.telefone;
     }
 }
Example #3
0
 private void BtnExcluir_Click(object sender, RoutedEventArgs e)
 {
     contato = context.agenda.Find(Convert.ToInt32(txtId.Text));
     if (context != null)
     {
         context.agenda.Remove(contato);
         context.SaveChanges();
         AlterarBotoes(1);
         ListarContatos();
         LimparCampos();
     }
 }