Exemple #1
0
        /// <summary>Método que representa la llamada al procedure 'Cliente_Insertar'</summary>
        static public int Insertar(Entity.Cliente Item, Cursor oCursor)
        {
            SqlCommand oComando = oCursor.ObtenerComando(Contexto.CnControlPresupuesto);
            string     Esquema  = Galeria.Conexiones[(int)Contexto.CnControlPresupuesto].EsquemaDefecto;

            oComando.CommandText = Esquema + "Cliente_Insertar";
            try
            {
                SqlParameterCollection oP = oComando.Parameters;
                oP.Add("idCliente", SqlDbType.Int).Direction = ParameterDirection.Output;
                oP.AddWithValue("ruc", Uso.NoNulo(Item.ruc, DBNull.Value));
                oP.AddWithValue("cliente", Uso.NoNulo(Item.cliente, DBNull.Value));
                oP.AddWithValue("direccion", Uso.NoNulo(Item.direccion, DBNull.Value));
                oP.AddWithValue("contacto", Uso.NoNulo(Item.contacto, DBNull.Value));
                oP.AddWithValue("correo", Uso.NoNulo(Item.correo, DBNull.Value));
                oP.AddWithValue("telefono", Uso.NoNulo(Item.telefono, DBNull.Value));
                oP.AddWithValue("idEstado", Uso.NoNulo(Item.idEstado, DBNull.Value));

                int NumFila = oComando.ExecuteNonQuery();

                Item.idCliente = (int?)Uso.NoNulo(oP["idCliente"].Value);

                return(NumFila);
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Exemple #2
0
        /// <summary>Método que representa la llamada al procedure 'Cliente_ListarDes'</summary>
        static public List <Entity.Cliente.ListarDes> ListarDes(Entity.Cliente Item, Cursor oCursor)
        {
            var        ResultSet = new List <Entity.Cliente.ListarDes>();
            SqlCommand oComando  = oCursor.ObtenerComando(Contexto.CnControlPresupuesto);
            string     Esquema   = Galeria.Conexiones[(int)Contexto.CnControlPresupuesto].EsquemaDefecto;

            oComando.CommandText = Esquema + "Cliente_ListarDes";
            try
            {
                SqlParameterCollection oP = oComando.Parameters;
                oP.AddWithValue("idEstado", Uso.NoNulo(Item.idEstado, DBNull.Value));

                using (SqlDataReader oLector = oComando.ExecuteReader())
                {
                    while (oLector.Read())
                    {
                        var LItem = new Entity.Cliente.ListarDes();
                        LItem.idCliente = (int)oLector["idCliente"];
                        LItem.cliente   = (string)oLector["cliente"];
                        ResultSet.Add(LItem);
                    }
                }
                return(ResultSet);
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Exemple #3
0
        public bool Update()
        {
            BeLifeEntities bbdd = new BeLifeEntities();

            try
            {
                //Trae un cliente.
                Entity.Cliente cli = bbdd.Cliente.Where(x => x.Rut == this.Rut).FirstOrDefault();
                if (cli != null)
                {
                    //sincroniza la clase de negocio con la entidad de BD.
                    CommonBC.Syncronize(this, cli);
                    cli.IdSexo   = this.Sexo.Id;
                    cli.IdEstado = this.EstadoCivil.Id;

                    //Modifica los cambios.
                    bbdd.SaveChanges();
                    return(true);
                }
                else
                {
                    throw new Exception("El cliente no existe.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error Actualizar Cliente. " + ex.Message);
            }
        }
Exemple #4
0
        /// <summary>
        /// Buscar un cliente por el parametro rut en la tabla Cliente.
        /// </summary>
        /// <param name="rut"></param>
        /// <returns></returns>
        public bool Read()
        {
            BeLifeEntities bbdd = new BeLifeEntities();

            try
            {
                Entity.Cliente cli = bbdd.Cliente.Where(x => x.Rut == this.Rut).FirstOrDefault();

                if (cli != null)
                {
                    //Sincroniza datos
                    CommonBC.Syncronize(cli, this);
                    CommonBC.Syncronize(cli.Sexo, Sexo);
                    CommonBC.Syncronize(cli.EstadoCivil, EstadoCivil);

                    return(true);
                }
                else
                {
                    return(false);

                    throw new Exception("El Cliente Rut : " + Rut + "  no existe.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error Read Cliente. " + ex.Message);
            }
        }
Exemple #5
0
        public bool Delete()
        {
            BeLifeEntities bbdd = new BeLifeEntities();

            try
            {
                Entity.Contrato contrato = bbdd.Contrato.Where(con => con.RutCliente == Rut).FirstOrDefault();
                if (contrato == null)
                {
                    Entity.Cliente cli = bbdd.Cliente.Where(x => x.Rut == this.Rut).FirstOrDefault();
                    if (cli != null)
                    {
                        //sincroniza la clase de la aplicacion con la entidad de BD y modifica los cambios
                        bbdd.Cliente.Remove(cli);
                        bbdd.SaveChanges();
                        return(true);
                    }
                    else
                    {
                        throw new Exception("El cliente no existe.");
                    }
                }
                else
                {
                    throw new Exception("El cliente tiene un contrato asociado.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error Delete Cliente. " + ex.Message);
            }
        }
Exemple #6
0
        public String ActualizarCliente(Entity.Cliente cl)
        {
            List <ClsParameter> lst = new List <ClsParameter>();
            String Mensaje          = "";

            try
            {
                lst.Add(new ClsParameter("@Ruc_client", cl.Ruc_client));
                lst.Add(new ClsParameter("@Business_name", cl.Business_name));
                lst.Add(new ClsParameter("@Brand", cl.Brand));
                lst.Add(new ClsParameter("@Address", cl.Address));
                lst.Add(new ClsParameter("@Email", cl.Email));
                lst.Add(new ClsParameter("@Telephone", cl.Telephone));
                lst.Add(new ClsParameter("@Status", cl.Status));
                lst.Add(new ClsParameter("@Condition", cl.Condition));
                lst.Add(new ClsParameter("@Updated_at", cl.updated_at));
                lst.Add(new ClsParameter("@Mensaje", "", SqlDbType.VarChar, ParameterDirection.Output, 50));
                M.EjecutarSP("ActualizarCliente", ref lst);
                Mensaje = lst[9].Valor.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Mensaje);
        }
Exemple #7
0
        /// <summary>
        /// Consulta um registro da tabela Cliente
        /// </summary>
        /// <param name="Sql">Síntaxe Sql</param>
        /// <returns></returns>
        public Entity.Cliente Consultar(string Sql)
        {
            SqlConnection oConn = new SqlConnection(oConexao.ConexaoBancoDeDados);
            SqlCommand oComm = new SqlCommand(Sql, oConn);

            SqlDataReader oDr;

            Entity.Cliente cliente = new Entity.Cliente();
            try
            {
                oConn.Open();
                oDr = oComm.ExecuteReader();

                while (oDr.Read())
                {
                    if (Coluna(oDr, "IDCliente")) cliente.IDCliente = (int)oDr["IDCliente"];
                    if (Coluna(oDr, "Loja_ID")) cliente.Loja_ID = (int)oDr["Loja_ID"];
                    if (Coluna(oDr, "TipoPessoa_ID")) cliente.TipoPessoa_ID = (int)oDr["TipoPessoa_ID"];
                    if (Coluna(oDr, "Tipo")) cliente.Tipo = oDr["Tipo"].ToString();
                    if (Coluna(oDr, "Nome")) cliente.Nome = oDr["Nome"].ToString();
                    if (Coluna(oDr, "Sobrenome")) cliente.Sobrenome = oDr["Sobrenome"].ToString();
                    if (Coluna(oDr, "RazaoSocial")) cliente.RazaoSocial = oDr["RazaoSocial"].ToString();
                    if (Coluna(oDr, "Cpf")) cliente.Cpf = oDr["Cpf"].ToString();
                    if (Coluna(oDr, "Cnpj")) cliente.Cnpj = oDr["Cnpj"].ToString();
                    if (Coluna(oDr, "Rg")) cliente.Rg = oDr["Rg"].ToString();
                    if (Coluna(oDr, "Ie")) cliente.Ie = oDr["Ie"].ToString();
                    if (Coluna(oDr, "Sexo")) cliente.Sexo = oDr["Sexo"].ToString();
                    if (Coluna(oDr, "Nascimento")) cliente.Nascimento = (DateTime)oDr["Nascimento"];
                    if (Coluna(oDr, "Telefone1")) cliente.Telefone1 = oDr["Telefone1"].ToString();
                    if (Coluna(oDr, "Telefone2")) cliente.Telefone2 = oDr["Telefone2"].ToString();
                    if (Coluna(oDr, "Email")) cliente.Email = oDr["Email"].ToString();
                    if (Coluna(oDr, "Senha")) cliente.Senha = oDr["Senha"].ToString();
                    if (Coluna(oDr, "Cep")) cliente.Cep = oDr["Cep"].ToString();
                    if (Coluna(oDr, "Endereco")) cliente.Endereco = oDr["Endereco"].ToString();
                    if (Coluna(oDr, "Numero")) cliente.Numero = oDr["Numero"].ToString();
                    if (Coluna(oDr, "Complemento")) cliente.Complemento = oDr["Complemento"].ToString();
                    if (Coluna(oDr, "Bairro")) cliente.Bairro = oDr["Bairro"].ToString();
                    if (Coluna(oDr, "Cidade")) cliente.Cidade = oDr["Cidade"].ToString();
                    if (Coluna(oDr, "Estado")) cliente.Estado = oDr["Estado"].ToString();
                    if (Coluna(oDr, "Referencia")) cliente.Referencia = oDr["Referencia"].ToString();
                    if (Coluna(oDr, "News")) cliente.News = (bool)oDr["News"];
                    if (Coluna(oDr, "DataInclusao")) cliente.DataInclusao = (DateTime)oDr["DataInclusao"];
                    cliente.Entregas = new Data.Cliente.Entrega().Listar("SELECT IDEntrega, Cliente_ID, Nome, Cep, Endereco, Numero, Complemento, Bairro, Cidade, Estado, Referencia, DataInclusao FROM Entrega WHERE Cliente_ID=" + cliente.IDCliente);
                }
            }
            catch (Exception e)
            {
                new Log(e);
            }
            finally
            {
                oDr = null;
                oComm = null;
                oConn.Close();
            }

            return cliente;
        }
        public static Entity.Cliente Criar(string nome, string cpf, DateTime dataNascimento, string nomePai, string nomeMae, IList <Endereco> enderecos)
        {
            var cliente = new Entity.Cliente(nome,
                                             new ValueObject.CPF(cpf),
                                             new ValueObject.DataNascimento(dataNascimento),
                                             new ValueObject.Filiacao(nomePai),
                                             new ValueObject.Filiacao(nomeMae));

            cliente.AdicionarEnderecos(enderecos);

            return(cliente);
        }
Exemple #9
0
        public String DeleteCliente(Entity.Cliente cl)
        {
            List <ClsParameter> lst = new List <ClsParameter>();
            String Mensaje          = "";

            try
            {
                lst.Add(new ClsParameter("@Ruc_client", cl.Ruc_client));
                lst.Add(new ClsParameter("@Mensaje", "", SqlDbType.VarChar, ParameterDirection.Output, 50));
                M.EjecutarSP("EliminarCliente", ref lst);
                Mensaje = lst[1].Valor.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Mensaje);
        }
Exemple #10
0
        public String ActualizarDireccionCliente(Entity.Cliente cl)
        {
            List <ClsParameter> lst = new List <ClsParameter>();
            String Mensaje          = "";

            try
            {
                lst.Add(new ClsParameter("@Ruc_client", cl.Ruc_client));
                lst.Add(new ClsParameter("@Address", cl.Address));
                lst.Add(new ClsParameter("@Updated_at", cl.updated_at));
                lst.Add(new ClsParameter("@Mensaje", "", SqlDbType.VarChar, ParameterDirection.Output, 50));
                M.EjecutarSP("ActualizarDireccoinCliente", ref lst);
                Mensaje = lst[3].Valor.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Mensaje);
        }
Exemple #11
0
        /// <summary>Método que representa la llamada al procedure 'Cliente_ListarUso'</summary>
        static public List <Entity.Cliente.ListarUso> ListarUso(Entity.Cliente Item, Cursor oCursor)
        {
            var        ResultSet = new List <Entity.Cliente.ListarUso>();
            SqlCommand oComando  = oCursor.ObtenerComando(Contexto.CnControlPresupuesto);
            string     Esquema   = Galeria.Conexiones[(int)Contexto.CnControlPresupuesto].EsquemaDefecto;

            oComando.CommandText = Esquema + "Cliente_ListarUso";
            try
            {
                SqlParameterCollection oP = oComando.Parameters;
                oP.AddWithValue("ruc", Uso.NoNulo(Item.ruc, DBNull.Value));
                oP.AddWithValue("cliente", Uso.NoNulo(Item.cliente, DBNull.Value));
                oP.AddWithValue("direccion", Uso.NoNulo(Item.direccion, DBNull.Value));
                oP.AddWithValue("contacto", Uso.NoNulo(Item.contacto, DBNull.Value));
                oP.AddWithValue("telefono", Uso.NoNulo(Item.telefono, DBNull.Value));

                using (SqlDataReader oLector = oComando.ExecuteReader())
                {
                    while (oLector.Read())
                    {
                        var LItem = new Entity.Cliente.ListarUso();
                        LItem.idCliente = (int)oLector["idCliente"];
                        LItem.ruc       = (string)oLector["ruc"];
                        LItem.cliente   = (string)oLector["cliente"];
                        LItem.direccion = (string)oLector["direccion"];
                        LItem.contacto  = (string)oLector["contacto"];
                        LItem.correo    = (string)Uso.NoNulo(oLector["correo"]);
                        LItem.telefono  = (string)oLector["telefono"];
                        LItem.estado    = (string)Uso.NoNulo(oLector["estado"]);
                        ResultSet.Add(LItem);
                    }
                }
                return(ResultSet);
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Exemple #12
0
        /// <summary>
        /// Crea un registro de Cliente en la BBDD
        /// </summary>
        /// <returns></returns>
        public bool Create()
        {
            bool crea = false;

            try
            {
                BeLifeEntities bbdd = new BeLifeEntities();
                Entity.Cliente cli  = new Entity.Cliente();

                //Ve si no existe el cliente para poder crearlo.
                if (!this.Read())
                {
                    //Sincroniza datos
                    CommonBC.Syncronize(this, cli);
                    CommonBC.Syncronize(this.Sexo, cli.Sexo);
                    cli.IdSexo = this.Sexo.Id;
                    CommonBC.Syncronize(this.EstadoCivil, cli.EstadoCivil);
                    cli.IdEstado = this.EstadoCivil.Id;

                    //Guarda los cambios
                    bbdd.Cliente.Add(cli);
                    bbdd.SaveChanges();
                    crea = true;
                }
                else
                {
                    throw new Exception("El cliente ya existe.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error Crear Cliente. " + ex.Message);
            }

            return(crea);
        }
 public ClienteBuilder Criar(string nome, string cpf, DateTime dtNascimento)
 {
     this.cliente = new Entity.Cliente(nome, new ValueObject.CPF(cpf), new ValueObject.DataNascimento(dtNascimento));
     return(this);
 }