コード例 #1
0
        public override string SQLWhere(BusinessFilter Filter)
        {
            string where;

            if (Filter["useObjectGlobalFilter"] == "0")
            {
                where = base.SQLWhere(Filter);
                string whereDelegacion = "";

                if (!Filter.Vacio("Direccion"))
                {
                    Data.AndWhere(ref whereDelegacion, "Direccion LIKE '%" + Filter["Direccion"].Replace("'", "''") + "%'");
                }
                if (!Filter.Vacio("CP"))
                {
                    Data.AndWhere(ref whereDelegacion, "CP LIKE '%" + Filter["CP"].Replace("'", "''") + "%'");
                }
                if (!Filter.Vacio("CIF"))
                {
                    Data.AndWhere(ref whereDelegacion, "CIF LIKE '%" + Filter["CIF"].Replace("'", "''") + "%'");
                }
                if (!Filter.Vacio("CodigoContabilidad"))
                {
                    Data.AndWhere(ref whereDelegacion, "CodigoContabilidad LIKE '%" + Filter["CodigoContabilidad"].Replace("'", "''") + "%'");
                }
                if (whereDelegacion != "")
                {
                    Data.OrWhere(ref where, "IDEmpresa in (Select IDEmpresa From EmpresaDelegacion Where " + whereDelegacion + ")");
                }

                Filter["lastuseObjectGlobalFilter"] = "1";
            }
            else
            {
                string   ogf  = Filter["objectGlobalFilter"].Replace("'", "''");
                string[] pals = ogf.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   sqlPalabrasDocumentos = "";

                where = "";

                foreach (string palUna in pals)
                {
                    string pal = palUna.Trim().Replace("'", "''");

                    if (pal != "")
                    {
                        string wParc           = "";
                        string whereDelegacion = "";

                        if (pal.Length == 5 && Lib.NoIntNulo(pal).ToString() == pal.ToString())
                        {
                            Data.OrWhere(ref where, @"Empresa.IDEmpresa in (SELECT IDEmpresa"
                                         + " FROM EmpresaDelegacion WHERE CP LIKE '%" + pal + "%')");
                        }
                        else
                        {
                            if (!(pal.StartsWith("[") && pal.EndsWith("]")))
                            {
                                Data.OrWhere(ref wParc, "Empresa.Razon Like '%" + pal + "%'");
                                Data.OrWhere(ref wParc, "Empresa.CIF Like '%" + pal + "%'");
                                Data.OrWhere(ref whereDelegacion, "Direccion LIKE '%" + pal + "%'");
                                Data.OrWhere(ref whereDelegacion, "CIF LIKE '%" + pal + "%'");
                                if (Lib.NoIntNulo(pal).ToString() == pal)
                                {
                                    Data.OrWhere(ref wParc, "Empresa.CodigoContabilidad Like '%" + pal + "%'");
                                    Data.OrWhere(ref whereDelegacion, "CodigoContabilidad LIKE '%" + pal + "%'");
                                    Data.OrWhere(ref whereDelegacion, "Telefono LIKE '%" + pal + "%'");
                                    if (pal.Length == 5)
                                    {
                                        Data.OrWhere(ref whereDelegacion, "CP = N'" + pal + "'");
                                    }
                                }
                            }
                            else
                            {
                                pal = pal.Replace("[", "").Replace("]", "").Trim();

                                if (pal != "")
                                {
                                    if (sqlPalabrasDocumentos != "")
                                    {
                                        sqlPalabrasDocumentos += ",";
                                    }
                                    sqlPalabrasDocumentos += "N'" + pal.Replace("'", "''") + "'";
                                }
                            }
                            if (wParc != "")
                            {
                                Data.OrWhere(ref wParc, @"Empresa.IDEmpresa in (SELECT IDEmpresa"
                                             + " FROM EmpresaDelegacion WHERE " + whereDelegacion + ")");

                                Data.AndWhere(ref where, "(" + wParc + ")");
                            }
                        }
                    }
                }

                if (sqlPalabrasDocumentos != "")
                {
                    string whereDR = "";

                    if (!UsuarioActual.Permiso("SEC", "Documento", "REST"))
                    {
                        whereDR = "Documento.Restringido = 0 AND ";
                    }

                    Data.AndWhere(ref where, @"Empresa.IDEmpresa IN (SELECT DISTINCT Documento.IDEmpresa
FROM DocumentoPalabra INNER JOIN
DocumentoPalabraInst ON DocumentoPalabra.IDDocumentoPalabra = DocumentoPalabraInst.IDDocumentoPalabra INNER JOIN
Documento ON DocumentoPalabraInst.IDDocumento = Documento.IDDocumento
WHERE " + whereDR + "(DocumentoPalabra.Palabra IN (" + sqlPalabrasDocumentos + ")))");


//Data.AndWhere(ref where, @"Empresa.IDEmpresa IN (SELECT DISTINCT Documento.IDEmpresa
//FROM DocumentoPalabra INNER JOIN
//DocumentoPalabraInst ON DocumentoPalabra.IDDocumentoPalabra = DocumentoPalabraInst.IDDocumentoPalabra INNER JOIN
//Documento ON DocumentoPalabraInst.IDDocumento = Documento.IDDocumento
//WHERE " + whereDR + "(NOT(Documento.IDEmpresa IS NULL)) AND (DocumentoPalabra.Palabra IN(" + sqlPalabrasDocumentos + ")))");
                }
            }

            return(where);
        }