public IEnumerable <PedidoConsulta> Filtrar(string campo, string valor, int codEmpresa, PedidoFiltro pedidoFiltro, int id = 0) { var model = new PedidoConsulta(); model.Data = Convert.ToDateTime("01/01/2019"); string sql = "SELECT PED.NUM_PEDIDO, PED.DATA, PED.COD_CLIENTE, CLI.NOME AS NOMECLIENTE, PED.SITUACAO, PED.TOTAL_LIQUIDO FROM PEDIDO PED"; sql += " INNER JOIN CLIENTE CLI ON PED.COD_CLIENTE = CLI.COD_CLIENTE"; if (id == 0) { sql += " WHERE PED.COD_EMPRESA = " + codEmpresa; sql += " AND " + campo + " CONTAINING(" + Funcao.QuotedStr(valor) + ")"; if (pedidoFiltro.CodCliente > 0) { sql += " AND PED.COD_CLIENTE = " + pedidoFiltro.CodCliente.ToString(); } if (pedidoFiltro.CodFornecedor > 0) { sql += " AND PED.COD_FOR = " + pedidoFiltro.CodFornecedor.ToString(); } if (pedidoFiltro.DataInicial.Trim() != "/ /") { sql += " AND PED.DATA >= @data"; // + string.Format(pedidoFiltro.DataInicial); } //if (pedidoFiltro.DataFinal.Trim() != "/ /") // sql += " AND PED.DATA <= '" + string.Format(pedidoFiltro.DataFinal, "MM/dd/yyyy") + "'"; if (pedidoFiltro.NumPedido > 0) { sql += " AND PED.NUM_PEDIDO = " + pedidoFiltro.NumPedido.ToString(); } if (pedidoFiltro.Situacao == "A") { sql += " AND PED.SITUACAO = 'A'"; } if (pedidoFiltro.Situacao == "E") { sql += " AND PED.SITUACAO = 'E'"; } sql += " ORDER BY PED.DATA "; } else { sql += " WHERE PED.NUM_PEDIDO = " + id; } return(_conexao.Query <PedidoConsulta>(sql)); }
public static List <PedidoConsulta> RetornaPedidosForn(PedidoPesquisa ped, string cdentifilial, string datasource, string schema, out string queryt) { List <PedidoConsulta> lstret = new List <PedidoConsulta>(); StringBuilder query = new StringBuilder(); query.AppendLine("select * from vw_consultacupom where 1=1 "); if (!string.IsNullOrEmpty(ped.datainicio) && !string.IsNullOrEmpty(ped.datafim)) { query.AppendLine(string.Format("and to_date(dataped,'DD/MM/YYYY') between to_date('{0}','DD/MM/YYYY') and to_date('{1}','DD/MM/YYYY')", ped.datainicio, ped.datafim)); } if (!string.IsNullOrEmpty(ped.cpfcnpj)) { var pcpf = ped.cpfcnpj.Replace(".", "").Replace("/", "").Replace("-", ""); query.AppendLine(string.Format("and cpfcnpj = '{0}'", pcpf)); } if (!string.IsNullOrEmpty(ped.statuspedido)) { query.AppendLine(string.Format("and cdstatpedido = {0}", ped.statuspedido)); } if (!string.IsNullOrEmpty(ped.codigopedido)) { query.AppendLine(string.Format("and cdpedido = {0}", ped.codigopedido)); } if (ped.perfil == "PARCEIRO") { if (!string.IsNullOrEmpty(ped.cdforn)) { query.AppendLine(string.Format("and CDFORN = {0}", ped.cdforn)); } } else { if (!string.IsNullOrEmpty(ped.cdpai)) { query.AppendLine(string.Format("and CDFORN = {0}", ped.cdpai)); } } if (!string.IsNullOrEmpty(ped.nome)) { query.AppendLine(string.Format("and nmentidade like upper('%{0}%')", ped.nome)); } if (!string.IsNullOrEmpty(cdentifilial)) { query.AppendLine(string.Format("and cdentifilial ={0}", cdentifilial)); } queryt = query.ToString(); PedidoConsulta pc; using (OracleConnection connection = new OracleConnection(Util.OracleHelper.StrConn(schema, datasource))) { OracleCommand command = new OracleCommand(query.ToString(), connection); connection.Open(); using (OracleDataReader reader = command.ExecuteReader()) { Produto pr = null; while (reader.Read()) { pc = new PedidoConsulta(); pc.cdentifilial = reader["CDENTIFILIAL"].ToString(); pc.cdpedido = reader["CDPEDIDO"].ToString(); pc.cdstatpedido = reader["CDSTATPEDIDO"].ToString(); //pc.cdstatuspedido = reader["cdstatuspedido"].ToString(); pc.cpfcnpj = reader["CPFCNPJ"].ToString(); pc.dataped = reader["DATAPED"].ToString(); pc.nmentidade = reader["NMENTIDADE"].ToString(); pc.nmstatus = reader["NMSTATUS"].ToString(); pc.quantidade = reader["QUANTIDADE"].ToString(); pc.statusnfe = reader["STATUSNFE"].ToString(); pc.valortotal = Convert.ToDouble(reader["VALORTOTAL"].ToString()); pc.cdnotafiscalsaida = string.IsNullOrEmpty(reader["CDNOTAFISCALSAIDA"].ToString()) ? "0" : reader["CDNOTAFISCALSAIDA"].ToString(); pc.flalteravel = reader["flalteravel"].ToString(); pc.comissao = Convert.ToDouble(reader["comissao"].ToString()); pc.over = Convert.ToDouble(reader["over"].ToString()); pc.totalcomissao = Convert.ToDouble(reader["totalcomissao"].ToString()); lstret.Add(pc); } } } return(lstret); }