コード例 #1
0
ファイル: frmCADPessoa.cs プロジェクト: VyseClown/SistemaLoja
        private void btnAlterar_Click(object sender, EventArgs e)
        {
            Pessoa           pes       = new Pessoa();
            ClienteModel     cliModel  = new ClienteModel();
            FuncionarioModel funcModel = new FuncionarioModel();
            BLLPessoa        BLLObj    = new BLLPessoa();

            if (rbCliente.Checked)
            {
                if (IsCpf(txtCPF.Text) == true)
                {
                    cliModel = BLLObj.retornarPessoaCliente(idPessoaGlobal);
                    if (cliModel != null)
                    {
                        pes     = BLLObj.retornarPessoa(cliModel.id);
                        pes.CPF = txtCPF.Text;
                        BLLObj.AlterarPessoa(pes);
                    }
                    else
                    {
                        MessageBox.Show("Não há cadastro da pessoa como cliente !");
                        return;
                    }
                }
            }
            else
            {
                if (IsCpf(txtCPF.Text) == true)
                {
                    funcModel = BLLObj.retornarPessoaFuncionario(idPessoaGlobal);
                    if (funcModel != null)
                    {
                        pes     = BLLObj.retornarPessoa(funcModel.id);
                        pes.CPF = txtCPF.Text;
                        BLLObj.AlterarPessoa(pes);
                    }
                    else
                    {
                        MessageBox.Show("Não há cadastro da pessoa como funcionario !");
                        return;
                    }
                }
            }
            pes.celular        = txtCelular.Text;
            pes.celular2       = txtCelular2.Text;
            pes.datanascimento = dtpNascimento.Value;
            pes.email          = txtEmail.Text;
            pes.nome           = txtNome.Text;
            pes.telefone       = txtTelefone.Text;
            pes.telefone2      = txtTelefone2.Text;
            pes.RG             = txtRG.Text;



            if (IsCpf(txtCPF.Text) == true)
            {
                if (BLLObj.AlterarPessoa(pes) != false)
                {
                    Cliente     cli  = new Cliente();
                    Funcionario fun  = new Funcionario();
                    bool        func = false;


                    if (rbCliente.Checked)
                    {
                        //cli.idPessoa = pes.id;
                        cli = BLLObj.retornarCliente(idPessoaGlobal);
                        cli.limitecredito = Decimal.Parse(txtLimite.Text);
                        func = BLLObj.AlterarCliente(cli);
                    }
                    else
                    {
                        //fun.idPessoa = pes.id;
                        fun         = BLLObj.retornarFuncionario(idPessoaGlobal);
                        fun.Salario = Decimal.Parse(txtSalario.Text);
                        func        = BLLObj.AlterarFuncionario(fun);
                    }

                    if (func != false)
                    {
                        Endereco end = new Endereco();
                        end          = BLLObj.retornarEndereco(idPessoaGlobal);
                        end.bairro   = txtBairro.Text;
                        end.rua      = txtRua.Text;
                        end.numero   = txtNumero.Text;
                        end.idCidade = (int)cbCidade.SelectedValue;
                        end.CEP      = txtCEP.Text;
                        if (BLLObj.AlterarEndereco(end) != false)
                        {
                            cbEstado.DataSource    = BLLObj.listarEstados();
                            cbEstado.ValueMember   = "Id";
                            cbEstado.DisplayMember = "Acronym";

                            cbCidade.DataSource    = BLLObj.listarCidades(int.Parse(cbEstado.SelectedValue.ToString()));
                            cbCidade.ValueMember   = "Id";
                            cbCidade.DisplayMember = "name";

                            limparTextBoxes(this.Controls);
                            txtSalario.Text = "";
                            txtLimite.Text  = "";
                            MessageBox.Show("A pessoa foi alterada !");
                        }
                        else
                        {
                            //apagar ultimo item adicionado
                            limparTextBoxes(this.Controls);
                            txtSalario.Text = "";
                            txtLimite.Text  = "";
                        }
                    }
                    else
                    {
                        //apagar ultimo item adicionado
                        limparTextBoxes(this.Controls);
                        txtSalario.Text = "";
                        txtLimite.Text  = "";
                    }
                }
            }
            else
            {
                //mensagem de aviso
                MessageBox.Show("Informe o CPF correto");
            }
        }