Exemplo n.º 1
0
        public void ValidaDados(mCliente model)
        {
            if (model.CodPostal != null && model.Nom_pais == "Brasil")
            {
                Util.Validacoes.ValidaMasked(model.CodPostal, TCC.Regra.Util.TipoMasked.cep);
            }

            if (model.Email != null)
            {
                string email = Convert.ToString(model.Email);
                Util.Validacoes.ValidaEmail(email);
            }

            if (model.Ddi != null)
            {
                string ddi = Convert.ToString(model.Ddi);
                Util.Validacoes.ValidaMasked(ddi, TCC.Regra.Util.TipoMasked.ddd);
            }

            if (model.Ddd != null && model.Nom_pais == "Brasil")
            {
                string ddd = Convert.ToString(model.Ddd);
                Util.Validacoes.ValidaMasked(ddd, TCC.Regra.Util.TipoMasked.ddd);
            }

            if (model.TelefoneCliente != null && model.Nom_pais == "Brasil")
            {
                string tel = Convert.ToString(model.TelefoneCliente);
                Util.Validacoes.ValidaMasked(tel, TCC.Regra.Util.TipoMasked.tel);
            }

            if (model.Cpf != null)
            {
                Util.Validacoes.ValidaMasked(model.Cpf, TCC.Regra.Util.TipoMasked.cpf);
                if (this.ExisteCpf(model.Cpf) == true)
                {
                    throw new Regra.Exceptions.Cliente.CPFClienteExistente();
                }
            }

            if (model.Cnpj != null)
            {
                string cnpj = Convert.ToString(model.Cnpj);
                Util.Validacoes.ValidaMasked(cnpj, TCC.Regra.Util.TipoMasked.cnpj);
                if (this.ExisteCnpj(cnpj) == true)
                {
                    throw new Regra.Exceptions.Cliente.CNPJClienteExistente();
                }
            }

            if (model.IdentInter != null)
            {
                if (this.ExisteIdentInter(model.IdentInter) == true)
                {
                    throw new Regra.Exceptions.Cliente.IdentInterExistenteException();
                }
            }
        }
 private void btnLimpa_Click(object sender, EventArgs e)
 {
     base.LimpaDadosTela(this);
     this._modelCliente = null;
     this._listaModelVendaProduto = null;
 }
 private void btnCdCliente_Click(object sender, EventArgs e)
 {
     this._modelCliente = new mCliente();
     frmBuscaCliente objFrmCliente = new frmBuscaCliente(this._modelCliente);
     try
     {
         DialogResult resultado = objFrmCliente.ShowDialog();
         if (resultado == DialogResult.Cancel)
         {
             this._modelCliente = null;
             this.txtCdCliente.Text = string.Empty;
         }
         else
         {
             this.txtCdCliente.Text = this._modelCliente.NomeCliente;
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         objFrmCliente = null;
     }
 }
        /// <summary>
        /// Pega os dados que estão na tela e popula o model
        /// </summary>
        /// <returns>Model populado</returns>
        private mCliente PegaDadosTela()
        {
            mCliente model = new mCliente();
            rCliente regra = new rCliente();

            try
            {
                if (base.Alteracao == true)
                {
                    model.IdCliente = this._modelCliente.IdCliente;
                }
                else
                {
                    model.IdCliente = regra.BuscaIdMaximo();
                }
                model.NomeCliente = this.txtNome.Text;

                if (string.IsNullOrEmpty(this.txtDDI.Text) == true)
                {
                    model.Ddi = null;
                }
                else
                {
                    model.Ddi = this.txtDDI.Text;
                }
                if (string.IsNullOrEmpty(this.txtDDD.Text) == true)
                {
                    model.Ddd = null;
                }
                else
                {
                    model.Ddd = Convert.ToInt32(this.txtDDD.Text);
                }
                if (this.txtTelefone.Visible == true)
                {
                    string tel = this.txtTelefone.Text.Replace("-", string.Empty);
                    tel = tel.Replace(" ", string.Empty);
                    if (string.IsNullOrEmpty(tel) == true)
                    {
                        model.TelefoneCliente = null;
                    }
                    else
                    {
                        model.TelefoneCliente = Convert.ToInt32(tel);
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(this.txtTelefoneInter.Text) == true)
                    {
                        model.TelefoneCliente = null;
                    }
                    else
                    {
                        model.TelefoneCliente = Convert.ToInt32(this.txtTelefoneInter.Text);
                    }
                }

                model.NomeRua = this.txtRua.Text;
                if (string.IsNullOrEmpty(this.txtNumero.Text) == true)
                {
                    model.NumeroEndereco = null;
                }
                else
                {
                    model.NumeroEndereco = Convert.ToInt32(this.txtNumero.Text);
                }
                model.ComplementoEndereco = this.txtComplemento.Text;

                string cep = txtCep.Text.Replace("-", string.Empty);
                cep = cep.Replace(" ", string.Empty);
                if (this.txtCep.Visible == true)
                {
                    model.CodPostal = cep;
                }
                else
                {
                    model.CodPostal = this.txtCodPostal.Text;
                }

                if (string.IsNullOrEmpty(this.txtBairro.Text) == true)
                {
                    model.Bairro = null;
                }
                else
                {
                    model.Bairro = this.txtBairro.Text;
                }
                model.Cidade = this.txtCidade.Text;

                string cpf = this.txtCPF.Text.Replace("-", string.Empty);
                cpf = cpf.Replace(".", string.Empty);
                cpf = cpf.Replace(" ", string.Empty);
                if (string.IsNullOrEmpty(cpf) == true)
                {
                    model.Cpf = null;
                }
                else
                {
                    model.Cpf = cpf;
                }

                string cnpj = this.txtCnpj.Text.Replace("-", string.Empty);
                cnpj = cnpj.Replace(".", string.Empty);
                cnpj = cnpj.Replace("/", string.Empty);
                cnpj = cnpj.Replace(" ", string.Empty);
                if (string.IsNullOrEmpty(cnpj) == true)
                {
                    model.Cnpj = null;
                }
                else
                {
                    model.Cnpj = Convert.ToDecimal(cnpj);
                }

                model.DatAtl = DateTime.Now;
                model.FlgAtivo = true;
                if (string.IsNullOrEmpty(this.txtEmail.Text) == true)
                {
                    model.Email = null;
                }
                else
                {
                    model.Email = this.txtEmail.Text;
                }

                if (this.rdbBrasil.Checked == true)
                {
                    model.Nom_pais = "Brasil";
                    model.Nom_est_inter = null;
                    model.IdentInter = null;
                }
                else
                {
                    model.Nom_pais = this.txtPais.Text;
                    model.Nom_est_inter = this.txtEstado.Text;
                    model.IdentInter = this.txtIdentInter.Text;
                }

                if (this.cboEstado.Enabled == true)
                {
                    model.SlgEstado = this.cboEstado.GetItemText(this.cboEstado.SelectedItem);
                }
                else
                {
                    model.SlgEstado = null;
                }

                return model;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                model = null;
            }
        }
 private void btnLimpa_Click(object sender, EventArgs e)
 {
     base.LimpaDadosTela(this);
     this.rdbBrasil.Checked = true;
     this._modelCliente = null;
     base.Alteracao = false;
 }
 private void btnBuscaAlteracaoDelecao_Click(object sender, EventArgs e)
 {
     this.btnLimpa_Click(null, null);
     this._modelCliente = new mCliente();
     frmBuscaCliente objCliente = new frmBuscaCliente(this._modelCliente, true);
     try
     {
         DialogResult resultado = objCliente.ShowDialog();
         if (resultado == DialogResult.Cancel)
         {
             this._modelCliente = null;
         }
         else
         {
             this.PopulaTelaComModelAlteracao();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         objCliente = null;
     }
 }
 public frmBuscaCliente(mCliente modelCliente, bool alteracao)
 {
     InitializeComponent();
     this._model = modelCliente;
     this._alteracao = alteracao;
 }
 public frmBuscaCliente(mCliente modelCliente)
 {
     InitializeComponent();
     this._model = modelCliente;
     this._alteracao = false;
 }