Exemplo n.º 1
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            ClienteNegocios clienteNegocios = new ClienteNegocios();
            Cliente cliente = new Cliente();

            cliente.Nome = txtNome.Text;
            cliente.Logradouro = txtLogradouro.Text;
            cliente.Numero = Convert.ToInt32(txtNumero.Text);
            cliente.Bairro = txtBairro.Text;
            cliente.Telefone = txtTelefone.Text;

            var retorno = clienteNegocios.Salvar(cliente);
            try
            {
                int Id = Convert.ToInt32(retorno);
                MessageBox.Show("Cliente " + retorno + " inserido com sucesso", "AVISO", MessageBoxButtons.OK,
                MessageBoxIcon.Information);
            }
            catch (Exception)
            {

                MessageBox.Show("Cliente não pode ser inserido", "ERRO", MessageBoxButtons.OK,
                MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        public FrmCadastro(AcaoNaTela acaoNaTela, Cliente cliente)
        {
            _acaoNaTela = acaoNaTela;

            InitializeComponent();
            txtCodigo.ReadOnly = true;
            txtCodigo.TabStop = false;

            if (acaoNaTela == AcaoNaTela.Consultar)
            {

                txtCodigo.Text = cliente.Id.ToString();
                txtNome.Text = cliente.Nome;
                txtNome.ReadOnly = true;
                txtNome.TabStop = false;
                txtLogradouro.Text = cliente.Logradouro;
                txtLogradouro.ReadOnly = true;
                txtLogradouro.TabStop = false;
                txtNumero.Text = cliente.Numero.ToString();
                txtNumero.ReadOnly = true;
                txtNumero.TabStop = false;
                txtBairro.Text = cliente.Bairro;
                txtBairro.ReadOnly = true;
                txtBairro.TabStop = false;
                txtTelefone.Text = cliente.Telefone;
                txtTelefone.ReadOnly = true;
                txtTelefone.TabStop = false;

                btnSalvar.Enabled = false;
            }
        }
Exemplo n.º 3
0
 public ClienteViewModel(Cliente cliente)
 {
     Id = cliente.Id;
     Nome = cliente.Nome;
     Logradouro = cliente.Logradouro;
     Numero = cliente.Numero;
     Bairro = cliente.Bairro;
     Telefone = cliente.Telefone;
 }
Exemplo n.º 4
0
        private void btnBuscar_Click(object sender, EventArgs e)
        {
            ClienteNegocios clienteNegocios = new ClienteNegocios();
            Cliente cliente = new Cliente();

            cliente = clienteNegocios.ListarClienteTelefone(txtConsulta.Text);

            if (cliente == null)
            {
                MessageBox.Show("Cliente não localizado", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            FrmCadastro frm = new FrmCadastro(AcaoNaTela.Consultar, cliente);
            frm.ShowDialog();
        }
Exemplo n.º 5
0
        public ActionResult Editar(ClienteViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var cliente = new Cliente
            {
                Id = model.Id,
                Nome = model.Nome,
                Logradouro = model.Logradouro,
                Numero = model.Numero,
                Bairro = model.Bairro,
                Telefone = model.Telefone
            };

            _clienteNegocios.Salvar(cliente);

            return RedirectToAction("Index");
        }