コード例 #1
0
        public static List <Produto> RetornaProdutoPesquisaSemFilial(produtosearch valor, string datasource, string schema, string cdentifilial)
        {
            List <Produto> lstResult = new List <Produto>();

            StringBuilder queryNmproduto = new StringBuilder();

            queryNmproduto.AppendLine(" select ");
            queryNmproduto.AppendLine(" cdproduto,");
            queryNmproduto.AppendLine(" UPPER(nmproduto) AS nmproduto,");
            queryNmproduto.AppendLine(" CASE WHEN ");
            queryNmproduto.AppendLine(" (select NVL(sum(estoque),0) from vw_tele_produto t where t.cdproduto = v.cdproduto) > 0 THEN 'DISPONÍVEL' ELSE 'INDISPONÍVEL' END AS ESTOQUE,");
            queryNmproduto.AppendLine(" 1 as cdentifilial,");
            queryNmproduto.AppendLine(" v.cdprodlegado,");
            queryNmproduto.AppendLine(" preco,'R$ ' || TRIM(TO_CHAR(preco,'L999G999G999G999D99','NLS_NUMERIC_CHARACTERS = '',. ''NLS_CURRENCY = '' '' ')) as precoview,");
            queryNmproduto.AppendLine(" NRPESO");
            queryNmproduto.AppendLine(" from vw_tele_produto v ");
            queryNmproduto.AppendFormat(" where cdproduto not in (select cdproduto from prodparceiro where cdentifornecedor = {0} and stexcluido=0)", valor.codforn);

            if (!string.IsNullOrEmpty(valor.codigoproduto))
            {
                queryNmproduto.AppendLine(string.Format(" and cdproduto = {0}", valor.codigoproduto));
            }
            else if (!string.IsNullOrEmpty(valor.nome))
            {
                queryNmproduto.AppendLine(string.Format(" and UPPER(nmproduto) LIKE UPPER('%{0}%')", valor.nome));
            }
            else
            {
                queryNmproduto.AppendLine(string.Format(" and cdprodlegado = '{0}'", valor.codigolegado));
            }

            queryNmproduto.AppendLine(" group by cdproduto,nmproduto,v.cdprodlegado,preco,NRPESO");

            using (OracleConnection connection = new OracleConnection(Util.OracleHelper.StrConn(schema, datasource)))
            {
                OracleCommand command = new OracleCommand(queryNmproduto.ToString(), connection);
                connection.Open();
                using (OracleDataReader reader = command.ExecuteReader())
                {
                    Produto pr = null;
                    while (reader.Read())
                    {
                        pr              = new Produto();
                        pr.cdproduto    = reader["cdproduto"].ToString();
                        pr.nmproduto    = reader["nmproduto"].ToString();
                        pr.estoque      = reader["estoque"].ToString();
                        pr.cdentifilial = reader["cdentifilial"].ToString();
                        pr.cdprodlegado = reader["cdprodlegado"].ToString();
                        pr.preco        = reader["preco"].ToString();
                        pr.precoview    = pr.estoque == "DISPONÍVEL" ? reader["precoview"].ToString() : "";
                        pr.peso         = Convert.ToDouble(reader["NRPESO"].ToString());
                        lstResult.Add(pr);
                    }
                }
            }
            return(lstResult);
        }
        public HttpResponseMessage ProdutoInsert(HttpRequestMessage request, [FromBody] produtosearch prod)
        {
            ConfigAppMembers cf  = Util.ConfigApp.getConfig();
            List <Produto>   ret = new List <Produto>();

            try
            {
                ret = Database.ProdutoADO.RetornaProdutoPesquisa(prod, cf.datasource, cf.schema, cf.cdentifilial);
            }
            catch (Exception e)
            {
                Util.LogUtil.GravaLog(this, "Produto search: " + e.ToString(), cf.Cnpj, Log.TipoLog.erro);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "ERRO"));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, ret));
        }
コード例 #3
0
        public static List <Produto> RetornaProdutoPesquisa(produtosearch valor, string datasource, string schema, string cdentifilial)
        {
            List <Produto> lstResult = new List <Produto>();

            StringBuilder queryNmproduto = new StringBuilder();

            queryNmproduto.AppendLine(string.Format("select * from vw_estoque_parceiro where cdentifilial ={0} ", cdentifilial));
            queryNmproduto.AppendFormat(" and cdproduto not in (select cdproduto from prodparceiro where cdentifornecedor = {0} and stexcluido=0)", valor.codforn);
            if (!string.IsNullOrEmpty(valor.codigoproduto))
            {
                queryNmproduto.AppendLine(string.Format(" and cdproduto = {0}", valor.codigoproduto));
            }
            else if (!string.IsNullOrEmpty(valor.nome))
            {
                queryNmproduto.AppendLine(string.Format(" and UPPER(nmproduto) LIKE UPPER('%{0}%')", valor.nome));
            }

            using (OracleConnection connection = new OracleConnection(Util.OracleHelper.StrConn(schema, datasource)))
            {
                OracleCommand command = new OracleCommand(queryNmproduto.ToString(), connection);
                connection.Open();
                using (OracleDataReader reader = command.ExecuteReader())
                {
                    Produto pr = null;
                    while (reader.Read())
                    {
                        pr              = new Produto();
                        pr.cdproduto    = reader["cdproduto"].ToString();
                        pr.nmproduto    = reader["nmproduto"].ToString();
                        pr.estoque      = reader["estoque"].ToString();
                        pr.cdentifilial = reader["cdentifilial"].ToString();
                        pr.cdprodlegado = reader["cdprodlegado"].ToString();
                        pr.preco        = reader["preco"].ToString();
                        pr.precoview    = pr.estoque == "DISPONÍVEL" ? reader["precoview"].ToString() : "";
                        pr.peso         = Convert.ToDouble(reader["NRPESO"].ToString());
                        lstResult.Add(pr);
                    }
                }
            }
            return(lstResult);
        }