示例#1
0
        private void btnSalvarCliente_Click(object sender, EventArgs e)
        {
            string erros = "";

            //Validações
            if (txtNomeCliente.Text == "")
            {
                erros += "- Preencha o campo Nome do Cliente;\n";
            }

            mkdtxtCPF.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;

            if (mkdtxtCPF.Text == "")
            {
                erros += "- Preencha o campo CPF;\n";
            }

            mkdtxtTelefone.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;

            if (mkdtxtTelefone.Text == "")
            {
                erros += "- Preencha o campo Telefone;\n";
            }
            if (txtEstadoCliente.Text == "")
            {
                erros += "- Preencha o campo Estado;\n";
            }
            if (txtCidadeCliente.Text == "")
            {
                erros += "- Preencha o campo Cidade;\n";
            }

            mkdtxtCEP.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;

            if (mkdtxtCEP.Text == "")
            {
                erros += "- Preencha o campo CEP;\n";
            }
            if (txtBairroCliente.Text == "")
            {
                erros += "- Preencha o campo Bairro;\n";
            }
            if (txtLogradouroCliente.Text == "")
            {
                erros += "- Preencha o campo Logradouro;\n";
            }
            if (mkdtxtNumero.Text == "")
            {
                erros += "- Preencha o campo Numero;\n";
            }

            mkdtxtCPF.TextMaskFormat      = MaskFormat.IncludePromptAndLiterals;
            mkdtxtTelefone.TextMaskFormat = MaskFormat.IncludePromptAndLiterals;
            mkdtxtCEP.TextMaskFormat      = MaskFormat.IncludePromptAndLiterals;

            mkdtxtNumero.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;

            if (!string.IsNullOrEmpty(erros))
            {
                MessageBox.Show(erros);
            }
            else
            {
                ClienteEntity cliente = new ClienteEntity();
                {
                    cliente.NomeCliente = txtNomeCliente.Text;
                    cliente.CPF         = mkdtxtCPF.Text;
                    cliente.Telefone    = mkdtxtTelefone.Text;
                    cliente.Estado      = txtEstadoCliente.Text;
                    cliente.CEP         = mkdtxtCEP.Text;
                    cliente.Cidade      = txtCidadeCliente.Text;
                    cliente.Bairro      = txtBairroCliente.Text;
                    cliente.Logradouro  = txtLogradouroCliente.Text;
                    cliente.Numero      = int.Parse(mkdtxtNumero.Text);
                    cliente.Complemento = txtComplementoCliente.Text;
                }

                ClienteDao.AlterarCliente(cliente, this.CodigoCliente);
                MessageBox.Show("Cliente alterado com sucesso");
                this.Close();
            }
        }
示例#2
0
        private void BtnEditar_Click(object sender, RoutedEventArgs e)
        {
            Cliente cliente = new Cliente
            {
                NomeCliente = objetoSelecionadoDataGrid.NomeCliente
            };

            cliente = ClienteDao.BuscarClientePorNome(cliente);


            if (clickBotao == false)
            {
                btnCancelar.Visibility = Visibility.Visible;
                clickBotao             = true;
                btnEditar.Content      = "Salvar";
                btnEditar.IsEnabled    = true;
                btnBuscar.IsEnabled    = false;
                btnCadastrar.IsEnabled = false;
                txtNome.Text           = cliente.NomeCliente.ToUpper();
                txtContato.Text        = cliente.Contato.ToUpper();
                txtTelefone.Text       = cliente.Telefone;
                txtNome.IsEnabled      = false;
                txtContato.IsEnabled   = true;
                txtTelefone.IsEnabled  = true;
                txtContato.Focus();
            }
            else
            {
                if (txtNome != null || txtContato != null || txtTelefone != null)
                {
                    cliente.Contato  = txtContato.Text.ToUpper();
                    cliente.Telefone = txtTelefone.Text;

                    if (ClienteDao.AlterarCliente(cliente))
                    {
                        MessageBox.Show("Cadastro Alterado!",
                                        "Sistema de Orcamento", MessageBoxButton.OK, MessageBoxImage.Information);

                        LimparFormulario();
                        txtNome.IsEnabled      = false;
                        txtContato.IsEnabled   = false;
                        txtTelefone.IsEnabled  = false;
                        btnCancelar.Visibility = Visibility.Hidden;
                        btnSalvar.Visibility   = Visibility.Hidden;
                        btnBuscar.IsEnabled    = true;
                        btnCadastrar.IsEnabled = true;
                        btnEditar.Content      = "Editar";
                        btnEditar.IsEnabled    = false;

                        List <Cliente> c = ClienteDao.ListarClientes();
                        dtaCliente.ItemsSource = c;
                    }
                    else
                    {
                        MessageBox.Show("Este Cadastro não pode ser Alterado",
                                        "Sistema de Orcamento", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Por Favor Preencher todos os campos", "Sistema de Orcamento",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }