Exemple #1
0
        private Sessao()
        {
            if (Empresa == null)
            {
                Empresa = new MLEmpresa();
            }

            if (Usuario == null)
            {
                Usuario = new MLUsuario();
            }

            if (Caixa == null)
            {
                Caixa = new MLCaixa();
            }

            if (Cliente == null)
            {
                Cliente = new MLCliente();
            }

            if (Configuracao == null)
            {
                Configuracao = new MLConfiguracaoGeral();
            }
        }
Exemple #2
0
        private void txtIdCnpj_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (txtIdCnpj.Text.Length > 10)
                {
                    string IdCnpj = "";

                    cliente = new MLCliente();
                    id      = 0;

                    if (decimal.TryParse(txtIdCnpj.Text, out decimal idcnpj))
                    {
                        if (txtIdCnpj.Text.Length == 11)
                        {
                            if (Utils.IsCpf(idcnpj.ToString()))
                            {
                                cliente.CPF = idcnpj.ToString();
                            }
                            else
                            {
                                lblInformacao.Text = "CPF INVÁLIDO!";
                                return;
                            }
                        }
                        else if (txtIdCnpj.Text.Length == 14)
                        {
                            if (Utils.IsCnpj(idcnpj.ToString()))
                            {
                                cliente.CNPJ = idcnpj.ToString();
                            }
                            else
                            {
                                lblInformacao.Text = "CNPJ INVÁLIDO!";
                                return;
                            }
                        }
                        else
                        {
                            lblInformacao.Text   = "Nenhum CPF ou CNPJ válido informado";
                            txtCliente.ForeColor = Color.Red;
                            return;
                        }

                        cliente.Ativo = true;
                    }
                    else
                    {
                        lblInformacao.Text = "Informe somente números!";
                        txtCliente.Text    = "Consumidor Final";
                        txtIdCnpj.Clear();
                        txtIdCnpj.Focus();
                        return;
                    }
                    cliente = new DLCliente().Listar(cliente).Where(c => c.CPF == idcnpj.ToString() || c.CNPJ == idcnpj.ToString()).FirstOrDefault();
                    if (cliente != null)
                    {
                        txtCliente.Text      = cliente.NomeRazaoSocial;
                        txtCliente.ForeColor = Color.Blue;

                        Sessao.Instance.Cliente.ClienteId       = cliente.ClienteId;
                        Sessao.Instance.Cliente.NomeRazaoSocial = cliente.NomeRazaoSocial;
                    }
                    else
                    {
                        txtCliente.Text = "Consumidor Final";
                        if (Utils.IsCnpj(idcnpj.ToString()) || Utils.IsCpf(idcnpj.ToString()))
                        {
                            txtCliente.ForeColor = Color.Blue;
                        }
                        else
                        {
                            txtCliente.ForeColor = Color.Red;
                        }

                        Sessao.Instance.Cliente.ClienteId       = 1;
                        Sessao.Instance.Cliente.NomeRazaoSocial = "Consumidor Final";
                    }

                    if (idcnpj.ToString().Length == 11)
                    {
                        lblInformacao.Text          = "CPF Válido - Pressione a tecla ENTER para incluir";
                        Sessao.Instance.Cliente.CPF = idcnpj.ToString();
                    }
                    else if (idcnpj.ToString().Length == 14)
                    {
                        lblInformacao.Text           = "CNPJ Válido - Pressione a tecla ENTER para incluir";
                        Sessao.Instance.Cliente.CNPJ = idcnpj.ToString();
                    }
                }
                else
                {
                    txtCliente.Text      = "Consumidor Final";
                    lblInformacao.Text   = "Nenhum CPF ou CNPJ válido informado";
                    txtCliente.ForeColor = Color.Red;
                }
            }
            catch (Exception ex)
            {
            }
        }