private IList FindByLinea(int linea) { var lineaDAO = new LineaDAO(sess); var empresa = lineaDAO.FindById(linea).Empresa; var query = "from TipoDomicilio t where t.Linea.Id = :linea or (t.Linea is null and (t.Empresa is null or t.Empresa = :empresa))"; return(sess.CreateQuery(query).SetParameter("linea", linea).SetParameter("empresa", empresa).List()); }
private int GetIdEmpresa(int empresa, int linea) { var idempresa = empresa; if (empresa <= 0 && linea > 0) { var lineaDao = new LineaDAO(); var l = lineaDao.FindById(linea); idempresa = l.Empresa.Id; } return(idempresa); }
/// <summary> /// Finds all vehicle types associated to the specified location and base. /// </summary> /// <param name="empresas"></param> /// <param name="lineas"></param> /// <returns></returns> private IList <TipoCoche> FindByEmpresasYLineas(ICollection <int> empresas, ICollection <int> lineas) { var lineaDao = new LineaDAO(); foreach (var linea in lineas.Where(lin => lin > 0).Select(id => lineaDao.FindById(id)).Where(linea => linea.Empresa != null).Where(linea => !empresas.Contains(linea.Empresa.Id))) { empresas.Add(linea.Empresa.Id); } return(Session.Query <TipoCoche>().Where(tipo => !tipo.Baja && (empresas.Contains(-1) || empresas.Contains(0) || tipo.Empresa == null || empresas.Contains(tipo.Empresa.Id)) && (lineas.Contains(-1) || lineas.Contains(0) || (tipo.Linea == null && (tipo.Empresa == null || empresas.Contains(tipo.Empresa.Id))) || (tipo.Linea != null && lineas.Contains(tipo.Linea.Id)))).ToList()); }
/// <summary> /// Finds all vehicle types associated to the specified location and base. /// </summary> /// <param name="empresa"></param> /// <param name="linea"></param> /// <param name="user"></param> /// <returns></returns> public IList <TipoCoche> FindByEmpresasAndLineas(List <int> empresa, List <int> linea, Usuario user) { var tipos = FindByEmpresasYLineas(empresa, linea); if (user == null || !user.AppliesFilters || (user.Empresas.Count.Equals(0) && user.Lineas.Count.Equals(0))) { return(tipos); } var lineaDao = new LineaDAO(); var lineas = lineaDao.GetList(new[] { -1 }); var empresas = (from Linea l in lineas select l.Empresa); return((from TipoCoche tipo in tipos where (tipo.Empresa == null || (user.Empresas.Count > 0 && user.Empresas.Contains(tipo.Empresa) || (empresas.Any() && empresas.Contains(tipo.Empresa)))) && (tipo.Linea == null || (lineas.ToList().Count > 0 && lineas.Contains(tipo.Linea))) select tipo).ToList()); }
public static IQueryable <Linea> GetLineas(ISession session, IEnumerable <int> empresas, IEnumerable <int> lineas, Usuario user) { if (empresas == null && (user == null || !user.PorLinea) && IncludesAll(lineas)) { return(null); } var lineaDao = new LineaDAO(); var lineasU = user != null && user.PorLinea ? user.Lineas.AsQueryable() : lineaDao.FindAll(); lineasU = lineasU .FilterEmpresa(session, empresas, user) .Where(l => !l.Baja); if (!IncludesAll(lineas)) { lineasU = lineasU.Where(l => lineas.Contains(l.Id)); } return(lineasU); }
public IList FindList(int transportista, int linea, int vehiculo, DateTime desde, DateTime hasta, int estado, int equipo, Usuario usuario) { var script = @"select d from Documento d where d.Fecha >= :ini and d.Fecha <= :fin and d.Estado != -1 and d.Id in (select v0.Documento.Id from DocumentoValor v0 where v0.Parametro.TipoDato like 'Aseguradora' and v0.Valor = :ase) "; if (linea > 0) { script += @" and d.Linea.Id = :linea "; } if (estado > -1) { script += @" and ((:est = '0' and d.Id not in (select v.Documento.Id from DocumentoValor v where v.Parametro.Nombre like 'Estado Control' and v.Valor <> :est) ) or (:est <> '0' and d.Id in (select v.Documento.Id from DocumentoValor v where v.Parametro.Nombre like 'Estado Control' and v.Valor = :est))) "; } if (linea > 0 && vehiculo > 0) { script += @" and d.Id in (select v1.Documento.Id from DocumentoValor v1 where v1.Parametro.TipoDato like 'Coche' and v1.Valor = :vehiculo) "; } if (equipo > 0) { script += @" and d.Id in (select v3.Documento.Id from DocumentoValor v3 where v3.Parametro.Nombre like 'Equipo' and v3.Valor = :equ) "; } var q = Session.CreateQuery(script); q.SetParameter("ini", desde); q.SetParameter("fin", hasta); q.SetParameter("ase", transportista.ToString("#0")); if (linea > 0) { q.SetParameter("linea", linea); } if (estado > -1) { q.SetParameter("est", estado.ToString("#0")); } if (linea > 0 && vehiculo > 0) { q.SetParameter("vehiculo", vehiculo.ToString("#0")); } if (equipo > 0) { q.SetParameter("equ", equipo.ToString("#0")); } if (usuario == null) { return(q.List()); } var transportistaDao = new TransportistaDAO(); var lineaDao = new LineaDAO(); var userTransp = transportistaDao.GetList(new [] { -1 }, new [] { linea }); var userLines = lineaDao.GetList(new[] { -1 }); return((from Documento d in q.List() where (transportista != -1 || userTransp.Contains(d.Transportista)) && (linea != -1 || userLines.Contains(d.Linea)) select d).ToList()); }
public IList FindParteReport(int aseguradora, int locacion, int linea, int movil, int equipo, DateTime inicio, DateTime fin, int estado, int usuario) { var empresaDAO = new EmpresaDAO(); var lineaDAO = new LineaDAO(); var cocheDAO = new CocheDAO(); var lin = linea > 0 ? lineaDAO.FindById(linea) : null; var emp = lin != null ? lin.Empresa : locacion > 0 ? empresaDAO.FindById(locacion) : null; IEnumerable <string> coches; if (movil > 0) { coches = new List <string>(new[] { movil.ToString("#0") }); } else { coches = cocheDAO.GetList(new[] { emp != null ? emp.Id : -1 }, new[] { lin != null ? lin.Id : -1 }) .Select(c => c.Id.ToString("#0")) .ToList(); } var script = @"from Documento d where d.Fecha >= :ini and d.Fecha <= :fin and d.Estado != -1 and d.Id in (select v.Documento.Id from DocumentoValor v where v.Parametro.TipoDato like 'Aseguradora' and v.Valor = :ase) "; if (equipo > 0) { script += @" and d.Id in (select v.Documento.Id from DocumentoValor v where v.Parametro.Nombre like 'Equipo' and v.Valor = :equ) "; } if (estado >= 0) { script += @" and ((:est = '0' and d.Id not in (select v.Documento.Id from DocumentoValor v where v.Parametro.Nombre like 'Estado Control' and v.Valor <> :est) ) or (:est <> '0' and d.Id in (select v.Documento.Id from DocumentoValor v where v.Parametro.Nombre like 'Estado Control' and v.Valor = :est))) "; } script += " order by d.Fecha"; var q = Session.CreateQuery(script) .SetParameter("ini", inicio) .SetParameter("fin", fin) .SetParameter("ase", aseguradora.ToString("#0")); if (equipo > 0) { q.SetParameter("equ", equipo.ToString("#0")); } if (estado >= 0) { q.SetParameter("est", estado.ToString("#0")); } return(q.List().Cast <Documento>().Where(documento => documento.Parametros.OfType <DocumentoValor>().Any(v => v.Parametro.TipoDato.ToLower().Equals("coche") && coches.Contains(v.Valor))).ToList()); }