Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using AtivaCliente.Models;
- namespace AtivaCliente
- {
- public partial class Form1 : Form
- {
- private readonly meu_bancoContext _context;
- public Form1()
- {
- InitializeComponent();
- _context= new meu_bancoContext();
- }
- private void btnPesquisarCodigo_Click(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(txtCodigoUsuario.Text))
- {
- Usuario usuario = _context.Usuarios.FirstOrDefault(x => x.Id == int.Parse(txtCodigoUsuario.Text));
- if (usuario == null)
- {
- MessageBox.Show("Usuário não encontrado");
- return;
- }
- txtNome.Text = usuario.Nome;
- txtEmail.Text = usuario.Email;
- chkAtivo.Checked = usuario.Ativo;
- }
- else
- {
- MessageBox.Show("Informar um código de usuário!");
- }
- }
- private void btnCancelar_Click(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(txtCodigoUsuario.Text))
- {
- Usuario usuario = _context.Usuarios.FirstOrDefault(x => x.Id == int.Parse(txtCodigoUsuario.Text));
- if (usuario == null)
- {
- MessageBox.Show("Usuário não encontrado");
- return;
- }
- usuario.Ativo = chkAtivo.Checked;
- _context.SaveChanges();
- MessageBox.Show("Usuário Salvo Com Sucesso!");
- return;
- }
- else
- {
- MessageBox.Show("Informar um código de usuário!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement