public ClienteViewModel() { FiltroCliente = new ClienteFiltro(); Clientes = new List <ClienteConsulta>(); EmailsClientes = new List <ClienteEmail>(); ClienteModulos = new List <ClienteModulo>(); Campos = new List <ClienteCamposPesquisaViewModel>(); }
private List <ClienteConsulta> Filtro(ClienteViewModel model, ClienteFiltro filtrarCliente) { filtrarCliente.Ativo = "A"; filtrarCliente.EmpresaVinculada = "T"; filtrarCliente.Restricao = 2; var servico = new ClienteServico(); var lista = servico.FiltrarWeb(UsuarioId, filtrarCliente, 2, model.Campo, model.Texto); return(lista.ToList()); }
public async Task <IActionResult> Excel([FromQuery] ClienteFiltro filtro) { var clientes = await _clienteRepository.Filtro(filtro); using (var wb = new XLWorkbook()) { var ws = wb.AddWorksheet("Clientes"); var linhaAtual = 1; ws.Cell(linhaAtual, (int)ClienteColumns.NomeCompleto).Value = "Nome Completo"; ws.Cell(linhaAtual, (int)ClienteColumns.NomeCompleto).Style.Font.Bold = true; ws.Cell(linhaAtual, (int)ClienteColumns.Empresa).Value = "Empresa"; ws.Cell(linhaAtual, (int)ClienteColumns.Empresa).Style.Font.Bold = true; ws.Cell(linhaAtual, (int)ClienteColumns.Suporte).Value = "Suporte"; ws.Cell(linhaAtual, (int)ClienteColumns.Suporte).Style.Font.Bold = true; ws.Cell(linhaAtual, (int)ClienteColumns.Endereco).Value = "Endereço"; ws.Cell(linhaAtual, (int)ClienteColumns.Endereco).Style.Font.Bold = true; ws.Cell(linhaAtual, (int)ClienteColumns.Cidade).Value = "Cidade"; ws.Cell(linhaAtual, (int)ClienteColumns.Cidade).Style.Font.Bold = true; ws.Cell(linhaAtual, (int)ClienteColumns.Estado).Value = "Estado"; ws.Cell(linhaAtual, (int)ClienteColumns.Estado).Style.Font.Bold = true; ws.Cell(linhaAtual, (int)ClienteColumns.Pais).Value = "País"; ws.Cell(linhaAtual, (int)ClienteColumns.Pais).Style.Font.Bold = true; ws.Cell(linhaAtual, (int)ClienteColumns.CEP).Value = "CEP"; ws.Cell(linhaAtual, (int)ClienteColumns.CEP).Style.Font.Bold = true; ws.Cell(linhaAtual, (int)ClienteColumns.Fone).Value = "Fone"; ws.Cell(linhaAtual, (int)ClienteColumns.Fone).Style.Font.Bold = true; ws.Cell(linhaAtual, (int)ClienteColumns.Fax).Value = "Fax"; ws.Cell(linhaAtual, (int)ClienteColumns.Fax).Style.Font.Bold = true; ws.Cell(linhaAtual, (int)ClienteColumns.Email).Value = "Email"; ws.Cell(linhaAtual, (int)ClienteColumns.Email).Style.Font.Bold = true; foreach (var cliente in clientes) { linhaAtual++; ws.Cell(linhaAtual, (int)ClienteColumns.NomeCompleto).Value = $"{cliente.PrimeiroNome} {cliente.Sobrenome}"; ws.Cell(linhaAtual, (int)ClienteColumns.Empresa).Value = cliente.Empresa; ws.Cell(linhaAtual, (int)ClienteColumns.Suporte).Value = $"{cliente.Suporte?.PrimeiroNome} {cliente.Suporte?.Sobrenome}".Trim(); ws.Cell(linhaAtual, (int)ClienteColumns.Endereco).Value = cliente.Endereco; ws.Cell(linhaAtual, (int)ClienteColumns.Cidade).Value = cliente.Cidade; ws.Cell(linhaAtual, (int)ClienteColumns.Estado).Value = cliente.Estado; ws.Cell(linhaAtual, (int)ClienteColumns.Pais).Value = cliente.Pais; ws.Cell(linhaAtual, (int)ClienteColumns.CEP).Value = cliente.CEP; ws.Cell(linhaAtual, (int)ClienteColumns.Fone).Value = cliente.Fone; ws.Cell(linhaAtual, (int)ClienteColumns.Fax).Value = cliente.Fax; ws.Cell(linhaAtual, (int)ClienteColumns.Email).Value = cliente.Email; } return(await GerarArquivoExcel(wb, "funcionarios.xlsx")); } }
public List <ClienteConsulta> Filtrar(int idUsuario, ClienteFiltro filtro, int modelo, string campo, string valor) { var sb = new StringBuilder(); sb.AppendLine(" SELECT"); sb.AppendLine(" Cli_Id, Cli_Codigo, Cli_Nome, Cli_Fantasia, Cli_Dcto, Cli_Fone1, Cli_Enquadramento,"); sb.AppendLine(" Usu_Nome, Rev_Nome"); sb.AppendLine(" FROM Cliente"); sb.AppendLine(" INNER JOIN Revenda ON Cli_Revenda = Rev_Id"); sb.AppendLine(" LEFT JOIN Usuario ON Cli_Usuario = Usu_Id"); sb.AppendLine(" WHERE Cli_Id IS NOT NULL"); sb.AppendLine(" AND " + campo + " LIKE'%" + valor + "%'"); sb.AppendLine(" AND EXISTS("); sb.AppendLine(" SELECT 1 FROM Usuario WHERE ((Cli_Revenda = Usu_Revenda) OR (Usu_Revenda IS NULL))"); sb.AppendLine(" AND Usu_Id = "+ idUsuario + ")"); sb.AppendLine(" AND EXISTS("); sb.AppendLine(" SELECT 1 FROM Usuario WHERE ((Cli_Id = Usu_Cliente) OR (Usu_Cliente IS NULL))"); sb.AppendLine(" AND Usu_Id = "+ idUsuario + ")"); if (filtro.Ativo != "T") { if (filtro.Ativo == "A") { sb.AppendLine(" AND Cli_Ativo = 1"); } else { sb.AppendLine(" AND Cli_Ativo = 0"); } } if (filtro.UsuarioId > 0) { sb.AppendLine(" AND Cli_Usuario =" + filtro.UsuarioId); } if (filtro.RevendaId > 0) { sb.AppendLine(" AND Cli_Revenda =" + filtro.RevendaId); } if (filtro.Restricao < 2) { if (filtro.Restricao == 0) { sb.AppendLine(" AND Cli_Restricao = 1"); } if (filtro.Restricao == 1) { sb.AppendLine(" AND Cli_Restricao = 0"); } } if (filtro.Id > 0) { sb.AppendLine(" AND Cli_Id =" + filtro.Id); } if (!string.IsNullOrWhiteSpace(filtro.Enquadramento)) { sb.AppendLine(" AND Cli_Enquadramento = '" + filtro.Enquadramento + "'"); } if (filtro.CidadeId > 0) { sb.AppendLine(" AND Cli_Cidade =" + filtro.CidadeId); } if (!string.IsNullOrWhiteSpace(filtro.Versao)) { sb.AppendLine(" AND Cli_Versao = '" + filtro.Versao + "'"); } if (filtro.EmpresaVinculada == "S") { sb.AppendLine(" AND Cli_EmpresaVinculada > 0"); } if (filtro.EmpresaVinculada == "N") { sb.AppendLine(" AND ((Cli_EmpresaVinculada = 0) OR (Cli_EmpresaVinculada IS NULL))"); } if (modelo == 2) { if (filtro.ModuloId > 0) { sb.AppendLine(" AND CliMod_Modulo = " + filtro.ModuloId); } if (filtro.ProdutoId > 0) { sb.AppendLine(" AND CliMod_Produto = " + filtro.ProdutoId); } } else { if (filtro.ModuloId > 0) { sb.AppendLine(" AND EXISTS(SELECT 1 FROM Cliente_Modulo "); sb.AppendLine(" WHERE Cli_Id = CliMod_Cliente "); sb.AppendLine(" AND CliMod_Modulo = " + filtro.ModuloId + ")"); } if (filtro.ProdutoId > 0) { sb.AppendLine(" AND EXISTS(SELECT 1 FROM Cliente_Modulo "); sb.AppendLine(" WHERE Cli_Id = CliMod_Cliente "); sb.AppendLine(" AND CliMod_Produto = " + filtro.ProdutoId + ")"); } } var lista = new List <ClienteConsulta>(); using (var db = new BancoADO()) { db.RetornoReader(sb.ToString()); while (db.Read()) { var model = new ClienteConsulta { Documento = db.CampoStr("Cli_Dcto"), Enquadramento = db.CampoStr("Cli_Enquadramento"), Fantasia = db.CampoStr("Cli_Fantasia"), Id = db.CampoInt32("Cli_Id"), NomeConsultor = db.CampoStr("Usu_Nome"), NomeRevenda = db.CampoStr("Rev_Nome"), Razao = db.CampoStr("Cli_Nome"), Telefone = db.CampoStr("Cli_Fone1"), Versao = db.CampoStr("Cli_Versao") }; lista.Add(model); } db.CloseReader(); } return(lista); }
public IEnumerable <ClienteConsulta> FiltrarWeb(int idUsuario, ClienteFiltro filtro, int modelo, string campo, string valor, bool contem = true) { return(_rep.Filtrar(idUsuario, filtro, modelo, campo, valor, contem)); }
public ChamadoFiltroViewModel() { Revenda = new Revenda(); Modulo = new Modulo(); ClienteFiltro = new ClienteFiltro(); }
public List <ClienteConsulta> Filtrar(int idUsuario, ClienteFiltro filtro, int modelo, string campo, string valor, bool contem = true) { string sTexto = ""; sTexto = "'" + valor + "%'"; if (contem) { sTexto = "'%" + valor + "%'"; } var sb = new StringBuilder(); sb.AppendLine(" SELECT"); sb.AppendLine(" Cli_Codigo as Codigo"); sb.AppendLine(",Cli_Perfil as Perfil"); sb.AppendLine(",Cli_Versao as Versao"); sb.AppendLine(",Cli_Id as Id"); sb.AppendLine(",cli_Fantasia as Fantasia"); sb.AppendLine(",cli_Nome as Razao"); sb.AppendLine(",cli_Dcto as Documento"); sb.AppendLine(",Cli_Fone1 as Telefone"); sb.AppendLine(",Cli_Enquadramento as Enquadramento"); sb.AppendLine(",Usu_Nome as NomeConsultor, Rev_Nome"); sb.AppendLine(",Rev_Nome as NomeRevenda"); sb.AppendLine(" FROM Cliente"); sb.AppendLine(" INNER JOIN Revenda ON Cli_Revenda = Rev_Id"); sb.AppendLine(" LEFT JOIN Usuario ON Cli_Usuario = Usu_Id"); sb.AppendLine(" WHERE Cli_Id IS NOT NULL"); sb.AppendLine(" AND " + campo + " LIKE " + sTexto); sb.AppendLine(" AND EXISTS("); sb.AppendLine(" SELECT 1 FROM Usuario WHERE ((Cli_Revenda = Usu_Revenda) OR (Usu_Revenda IS NULL))"); sb.AppendLine(" AND Usu_Id = "+ idUsuario + ")"); sb.AppendLine(" AND EXISTS("); sb.AppendLine(" SELECT 1 FROM Usuario WHERE ((Cli_Id = Usu_Cliente) OR (Usu_Cliente IS NULL))"); sb.AppendLine(" AND Usu_Id = "+ idUsuario + ")"); if (filtro.Ativo != "T") { if (filtro.Ativo == "A") { sb.AppendLine(" AND Cli_Ativo = 1"); } else { sb.AppendLine(" AND Cli_Ativo = 0"); } } if (filtro.UsuarioId > 0) { sb.AppendLine(" AND Cli_Usuario =" + filtro.UsuarioId); } if (filtro.RevendaId > 0) { sb.AppendLine(" AND Cli_Revenda =" + filtro.RevendaId); } if (!string.IsNullOrEmpty(filtro.FiltroIdUsuario)) { sb.AppendLine(" AND Cli_Usuario in (" + filtro.FiltroIdUsuario + ")"); } if (filtro.Restricao < 2) { if (filtro.Restricao == 0) { sb.AppendLine(" AND Cli_Restricao = 1"); } if (filtro.Restricao == 1) { sb.AppendLine(" AND Cli_Restricao = 0"); } } if (filtro.Id > 0) { sb.AppendLine(" AND Cli_Id =" + filtro.Id); } if (!string.IsNullOrWhiteSpace(filtro.Enquadramento)) { sb.AppendLine(" AND Cli_Enquadramento = '" + filtro.Enquadramento + "'"); } if (filtro.CidadeId > 0) { sb.AppendLine(" AND Cli_Cidade =" + filtro.CidadeId); } if (!string.IsNullOrEmpty(filtro.FiltroIdCidade)) { sb.AppendLine(" AND Cli_Cidade in (" + filtro.FiltroIdCidade + ")"); } if (!string.IsNullOrWhiteSpace(filtro.Versao)) { sb.AppendLine(" AND Cli_Versao = '" + filtro.Versao + "'"); } if (filtro.EmpresaVinculada == "S") { sb.AppendLine(" AND Cli_EmpresaVinculada > 0"); } if (filtro.EmpresaVinculada == "N") { sb.AppendLine(" AND ((Cli_EmpresaVinculada = 0) OR (Cli_EmpresaVinculada IS NULL))"); } if (!string.IsNullOrWhiteSpace(filtro.Perfil)) { sb.AppendLine(" AND Cli_Perfil = '" + filtro.Perfil + "'"); } if (modelo == 2) { if (filtro.ModuloId > 0) { sb.AppendLine(" AND CliMod_Modulo = " + filtro.ModuloId); } if (!string.IsNullOrEmpty(filtro.FiltroIdModulo)) { sb.AppendLine(" AND CliMod_Modulo in (" + filtro.FiltroIdModulo + ")"); } if (filtro.ProdutoId > 0) { sb.AppendLine(" AND CliMod_Produto = " + filtro.ProdutoId); } if (!string.IsNullOrEmpty(filtro.FiltroIdProduto)) { sb.AppendLine(" AND CliMod_Produto in (" + filtro.FiltroIdProduto + ")"); } } else { if (filtro.ModuloId > 0) { sb.AppendLine(" AND EXISTS(SELECT 1 FROM Cliente_Modulo "); sb.AppendLine(" WHERE Cli_Id = CliMod_Cliente "); sb.AppendLine(" AND CliMod_Modulo = " + filtro.ModuloId + ")"); } if (!string.IsNullOrEmpty(filtro.FiltroIdModulo)) { sb.AppendLine(" AND EXISTS(SELECT 1 FROM Cliente_Modulo "); sb.AppendLine(" WHERE Cli_Id = CliMod_Cliente "); sb.AppendLine(" AND CliMod_Modulo IN (" + filtro.FiltroIdModulo + "))"); } if (filtro.ProdutoId > 0) { sb.AppendLine(" AND EXISTS(SELECT 1 FROM Cliente_Modulo "); sb.AppendLine(" WHERE Cli_Id = CliMod_Cliente "); sb.AppendLine(" AND CliMod_Produto = " + filtro.ProdutoId + ")"); } if (!string.IsNullOrEmpty(filtro.FiltroIdProduto)) { sb.AppendLine(" AND EXISTS(SELECT 1 FROM Cliente_Modulo "); sb.AppendLine(" WHERE Cli_Id = CliMod_Cliente "); sb.AppendLine(" AND CliMod_Produto in (" + filtro.FiltroIdProduto + "))"); } } sb.AppendLine(" ORDER BY " + campo); return(_repositorioDapper.GetAll(sb.ToString()).ToList()); }
public async Task <IList <ClienteViewModel> > GetAll([FromQuery] ClienteFiltro filtro) { return(_mapper.Map <IList <ClienteViewModel> >(await _clienteRepository.Filtro(filtro))); }
public async Task <IList <Cliente> > Filtro(ClienteFiltro filtro) { var clienteQuery = DbSet.AsNoTracking(); if (filtro != null) { if (!string.IsNullOrEmpty(filtro.PrimeiroNome)) { clienteQuery = clienteQuery.Where(c => c.PrimeiroNome.Contains(filtro.PrimeiroNome)); } if (!string.IsNullOrEmpty(filtro.Sobrenome)) { clienteQuery = clienteQuery.Where(c => c.Sobrenome.Contains(filtro.Sobrenome)); } if (!string.IsNullOrEmpty(filtro.Empresa)) { clienteQuery = clienteQuery.Where(c => c.Empresa.Contains(filtro.Empresa)); } if (!string.IsNullOrEmpty(filtro.Endereco)) { clienteQuery = clienteQuery.Where(c => c.Endereco.Contains(filtro.Endereco)); } if (!string.IsNullOrEmpty(filtro.Cidade)) { clienteQuery = clienteQuery.Where(c => c.Cidade.Contains(filtro.Cidade)); } if (!string.IsNullOrEmpty(filtro.Estado)) { clienteQuery = clienteQuery.Where(c => c.Estado.Contains(filtro.Estado)); } if (!string.IsNullOrEmpty(filtro.Pais)) { clienteQuery = clienteQuery.Where(c => c.Pais.Contains(filtro.Pais)); } if (!string.IsNullOrEmpty(filtro.CEP)) { clienteQuery = clienteQuery.Where(c => c.CEP.Contains(filtro.CEP)); } if (!string.IsNullOrEmpty(filtro.Fone)) { clienteQuery = clienteQuery.Where(c => c.Fone.Contains(filtro.Fone)); } if (!string.IsNullOrEmpty(filtro.Fax)) { clienteQuery = clienteQuery.Where(c => c.Fax.Contains(filtro.Fax)); } if (!string.IsNullOrEmpty(filtro.Email)) { clienteQuery = clienteQuery.Where(c => c.Email.Contains(filtro.Email)); } } return(await clienteQuery.ToListAsync()); }