/// <summary>
        /// Construye la tabla
        /// </summary>
        /// <param name="type"></param>
        /// <param name="schema"></param>
        /// <param name="sesion"></param>
        /// <returns></returns>
        public static string SELECT_BY_INSTRUCTOR_PROMOCION(long oid, DateTime fecha_inicio, DateTime fecha_fin)
        {
            string sip       = nHManager.Instance.GetSQLTable(typeof(Submodulo_Instructor_PromocionRecord));
            string submodulo = nHManager.Instance.GetSQLTable(typeof(SubmoduloRecord));
            string modulo    = nHManager.Instance.GetSQLTable(typeof(ModuloRecord));
            string promocion = nHManager.Instance.GetSQLTable(typeof(PromocionRecord));
            string si        = nHManager.Instance.GetSQLTable(typeof(Submodulo_InstructorRecord));

            string query;

            query = "SELECT SIP.*," +
                    "       COALESCE(M.\"NUMERO\",0) || ' ' || COALESCE(M.\"TEXTO\",'') AS \"MODULO\", " +
                    "       COALESCE(S.\"CODIGO\",'') || ' ' || COALESCE(S.\"TEXTO\",'') AS \"SUBMODULO\", " +
                    "       COALESCE(P.\"NUMERO\",'') || ' ' || COALESCE(P.\"NOMBRE\",'') AS \"PROMOCION\" , " +
                    "       M.\"OID\" AS \"OID_MODULO\"" +
                    " FROM " + sip + " AS SIP" +
                    " LEFT JOIN " + submodulo + " AS S ON SIP.\"OID_SUBMODULO\" = S.\"OID\"" +
                    " LEFT JOIN " + modulo + " AS M ON S.\"OID_MODULO\" = M.\"OID\"" +
                    " LEFT JOIN " + promocion + " AS P ON P.\"OID\" = SIP.\"OID_PROMOCION\"" +
                    " WHERE SIP.\"OID_INSTRUCTOR_PROMOCION\" = " + oid.ToString() + " ";

            if (ModulePrincipal.GetMostrarInstructoresAutorizadosSetting())
            {
                query += @" AND S.""OID"" NOT IN (	SELECT ""OID_SUBMODULO""
					                                        FROM "                     + si + @"
					                                        WHERE ('"                     + fecha_inicio.ToString("MM-dd-yyyy") + @"' BETWEEN COALESCE(""FECHA_INICIO"", '01-01-0001') AND COALESCE(""FECHA_FIN"", '12-31-2999') OR 
						                                        '"                         + fecha_fin.ToString("MM-dd-yyyy") + @"' BETWEEN COALESCE(""FECHA_INICIO"", '01-01-0001') AND COALESCE(""FECHA_FIN"", '12-31-2999'))
                                                                 AND ""OID_INSTRUCTOR"" = SIP.""OID_INSTRUCTOR"") ";
            }

            query += " ORDER BY M.\"NUMERO_ORDEN\", S.\"CODIGO_ORDEN\"";

            return(query);
        }
        /// <summary>
        /// Construye la tabla
        /// </summary>
        /// <param name="type"></param>
        /// <param name="schema"></param>
        /// <param name="sesion"></param>
        /// <returns></returns>
        public static string SELECT_BY_INSTRUCTOR_PROMOCION(long oid)
        {
            string sip                  = nHManager.Instance.GetSQLTable(typeof(Submodulo_Instructor_PromocionRecord));
            string submodulo            = nHManager.Instance.GetSQLTable(typeof(SubmoduloRecord));
            string modulo               = nHManager.Instance.GetSQLTable(typeof(ModuloRecord));
            string promocion            = nHManager.Instance.GetSQLTable(typeof(PromocionRecord));
            string submodulo_instructor = nHManager.Instance.GetSQLTable(typeof(Submodulo_InstructorRecord));

            string query;

            query = "SELECT SIP.*," +
                    "       COALESCE(M.\"NUMERO\",0) || ' ' || COALESCE(M.\"TEXTO\",'') AS \"MODULO\", " +
                    "       COALESCE(S.\"CODIGO\",'') || ' ' || COALESCE(S.\"TEXTO\",'') AS \"SUBMODULO\", " +
                    "       COALESCE(P.\"NUMERO\",'') || ' ' || COALESCE(P.\"NOMBRE\",'') AS \"PROMOCION\" , " +
                    "       M.\"OID\" AS \"OID_MODULO\"" +
                    " FROM " + sip + " AS SIP" +
                    " LEFT JOIN " + submodulo + " AS S ON SIP.\"OID_SUBMODULO\" = S.\"OID\"" +
                    " LEFT JOIN " + modulo + " AS M ON S.\"OID_MODULO\" = M.\"OID\"" +
                    " LEFT JOIN " + promocion + " AS P ON P.\"OID\" = SIP.\"OID_PROMOCION\"" +
                    " WHERE SIP.\"OID_INSTRUCTOR_PROMOCION\" = " + oid.ToString();

            if (ModulePrincipal.GetMostrarInstructoresAutorizadosSetting())
            {
                query += " AND S.\"OID\" NOT IN (	SELECT \"OID_SUBMODULO\" "+
                         "                               FROM " + submodulo_instructor + " " +
                         "                               WHERE \"OID_INSTRUCTOR\" = SIP.\"OID_INSTRUCTOR\" AND COALESCE(\"FECHA_FIN\", '12-31-2999') >= current_date) ";
            }

            query += " ORDER BY M.\"NUMERO_ORDEN\", S.\"CODIGO_ORDEN\"";

            return(query);
        }
Пример #3
0
        internal static string WHERE(QueryConditions conditions)
        {
            string query;
            string si = nHManager.Instance.GetSQLTable(typeof(Submodulo_InstructorRecord));

            query = "   WHERE TRUE";

            if (conditions.Instructor != null && conditions.Instructor.Oid > 0)
            {
                query += " AND SI.\"OID_INSTRUCTOR\" = " + conditions.Instructor.Oid;
            }

            if (ModulePrincipal.GetMostrarInstructoresAutorizadosSetting())
            {
                query += @" AND SI.""OID_SUBMODULO"" NOT IN (	SELECT ""OID_SUBMODULO""
					                                            FROM "                     + si + @"
					                                            WHERE ('"                     + conditions.FechaAuxIniLabel + @"' BETWEEN COALESCE(""FECHA_INICIO"", '01-01-0001') AND COALESCE(""FECHA_FIN"", '12-31-2999') OR 
						                                            '"                         + conditions.FechaAuxFinLabel + @"' BETWEEN COALESCE(""FECHA_INICIO"", '01-01-0001') AND COALESCE(""FECHA_FIN"", '12-31-2999'))";

                if (conditions.Instructor != null && conditions.Instructor.Oid > 0)
                {
                    query += " AND \"OID_INSTRUCTOR\" = " + conditions.Instructor.Oid;
                }

                query += ") ";
            }

            return(query);
        }
Пример #4
0
        public static string SELECT_PARTES_PRACTICAS()
        {
            string parte_asistencia     = nHManager.Instance.GetSQLTable(typeof(ParteAsistenciaRecord));
            string empleado             = nHManager.Instance.GetSQLTable(typeof(InstructorRecord));
            string horairo              = nHManager.Instance.GetSQLTable(typeof(HorarioRecord));
            string sesion               = nHManager.Instance.GetSQLTable(typeof(SesionRecord));
            string clase                = nHManager.Instance.GetSQLTable(typeof(ClasePracticaRecord));
            string clase_parte          = nHManager.Instance.GetSQLTable(typeof(Clase_ParteRecord));
            string promocion            = nHManager.Instance.GetSQLTable(typeof(PromocionRecord));
            string submodulo_instructor = nHManager.Instance.GetSQLTable(typeof(Submodulo_InstructorRecord));

            string query = string.Empty;

            if (ModulePrincipal.GetMostrarInstructoresAutorizadosSetting())
            {
                query = "SELECT DISTINCT PR.\"NOMBRE\" AS \"PROMOCION\", " +
                        "P.*, " +
                        "COALESCE(AU.\"AUTORIZADO\", I.\"NOMBRE\") AS \"INSTRUCTOR\", " +
                        "IE.\"NOMBRE\" AS \"INSTRUCTOR_EFECTIVO\" " +
                        "FROM " + parte_asistencia + " AS P " +
                        "INNER JOIN " + empleado + " AS I ON (P.\"OID_INSTRUCTOR\" = I.\"OID\") " +
                        "INNER JOIN " + empleado + " AS IE ON (P.\"OID_INSTRUCTOR_EFECTIVO\" = IE.\"OID\") " +
                        "INNER JOIN " + horairo + " AS H ON (P.\"OID_HORARIO\" = H.\"OID\") " +
                        "INNER JOIN " + sesion + " AS S ON (S.\"OID_HORARIO\" = H.\"OID\" AND S.\"FECHA\" = P.\"FECHA\") " +
                        "INNER JOIN " + clase + " AS CP ON (S.\"OID_CLASE_PRACTICA\" = CP.\"OID\") " +
                        "LEFT JOIN (    SELECT SI.\"OID_INSTRUCTOR\", SI.\"OID_SUBMODULO\", SI.\"FECHA_INICIO\", SI.\"FECHA_FIN\", IA.\"NOMBRE\" AS \"AUTORIZADO\"" +
                        "               FROM " + submodulo_instructor + " AS SI " +
                        "               INNER JOIN " + empleado + " AS IA ON IA.\"OID\" = SI.\"OID_INSTRUCTOR_SUPLENTE\") " +
                        "       AS AU ON AU.\"OID_INSTRUCTOR\" = I.\"OID\" AND AU.\"OID_SUBMODULO\" = CP.\"OID_SUBMODULO\" AND P.\"FECHA\" BETWEEN COALESCE(AU.\"FECHA_INICIO\", '01-01-0001') AND COALESCE(AU.\"FECHA_FIN\", '12-31-9999') " +
                        "INNER JOIN " + clase_parte + " AS C_P ON (C_P.\"OID_CLASE\" = CP.\"OID\" AND C_P.\"TIPO\" = 2 AND C_P.\"OID_PARTE\" = P.\"OID\") " +
                        "INNER JOIN " + promocion + " AS PR ON (H.\"OID_PROMOCION\" = PR.\"OID\") " +
                        "ORDER BY P.\"FECHA\", \"PROMOCION\";";
            }
            else
            {
                query = "SELECT DISTINCT PR.\"NOMBRE\" AS \"PROMOCION\", " +
                        "P.*, " +
                        "I.\"NOMBRE\" AS \"INSTRUCTOR\", " +
                        "IE.\"NOMBRE\" AS \"INSTRUCTOR_EFECTIVO\" " +
                        "FROM " + parte_asistencia + " AS P " +
                        "INNER JOIN " + empleado + " AS I ON (P.\"OID_INSTRUCTOR\" = I.\"OID\") " +
                        "INNER JOIN " + empleado + " AS IE ON (P.\"OID_INSTRUCTOR_EFECTIVO\" = IE.\"OID\") " +
                        "INNER JOIN " + horairo + " AS H ON (P.\"OID_HORARIO\" = H.\"OID\") " +
                        "INNER JOIN " + sesion + " AS S ON (S.\"OID_HORARIO\" = H.\"OID\" AND S.\"FECHA\" = P.\"FECHA\") " +
                        "INNER JOIN " + clase + " AS CP ON (S.\"OID_CLASE_PRACTICA\" = CP.\"OID\") " +
                        "INNER JOIN " + clase_parte + " AS C_P ON (C_P.\"OID_CLASE\" = CP.\"OID\" AND C_P.\"TIPO\" = 2 AND C_P.\"OID_PARTE\" = P.\"OID\") " +
                        "INNER JOIN " + promocion + " AS PR ON (H.\"OID_PROMOCION\" = PR.\"OID\") " +
                        "ORDER BY P.\"FECHA\", \"PROMOCION\";";
            }

            return(query);
        }
        internal static string SELECT_BY_HORARIO(long oid_horario, bool lock_table)
        {
            string s  = nHManager.Instance.GetSQLTable(typeof(SesionRecord));
            string i  = nHManager.Instance.GetSQLTable(typeof(InstructorRecord));
            string sm = nHManager.Instance.GetSQLTable(typeof(SubmoduloRecord));
            string ct = nHManager.Instance.GetSQLTable(typeof(ClaseTeoricaRecord));
            string cp = nHManager.Instance.GetSQLTable(typeof(ClasePracticaRecord));
            string ce = nHManager.Instance.GetSQLTable(typeof(ClaseExtraRecord));
            string si = nHManager.Instance.GetSQLTable(typeof(Submodulo_InstructorRecord));

            bool autorizados = ModulePrincipal.GetMostrarInstructoresAutorizadosSetting();

            string query;

            if (!autorizados)
            {
                query = "SELECT DISTINCT S.*, S.\"OID_PROFESOR\" AS \"OID_AUTORIZADO\" " +
                        " FROM " + s + " AS S" +
                        " WHERE S.\"OID_HORARIO\" = " + oid_horario.ToString() +
                        " ORDER BY S.\"FECHA\", S.\"HORA\"";
            }
            else
            {
                query = "SELECT DISTINCT S.*," +
                        " COALESCE(I.\"OID\", S.\"OID_PROFESOR\") AS \"OID_AUTORIZADO\"" +
                        " FROM " + s + " AS S" +
                        " INNER JOIN ( SELECT COALESCE(CT.\"OID_SUBMODULO\", COALESCE(CP.\"OID_SUBMODULO\", COALESCE(CE.\"OID_SUBMODULO\", 0))) AS \"OID_SUBMODULO\"," +
                        "           S.\"OID\" AS \"OID_SESION\"" +
                        "       FROM " + s + " AS S" +
                        "       LEFT JOIN " + ct + " AS CT ON CT.\"OID\" = S.\"OID_CLASE_TEORICA\"" +
                        "       LEFT JOIN " + cp + " AS CP ON CP.\"OID\" = S.\"OID_CLASE_PRACTICA\"" +
                        "       LEFT JOIN " + ce + " AS CE ON CE.\"OID\" = S.\"OID_CLASE_EXTRA\")" +
                        "   AS C ON C.\"OID_SESION\" = S.\"OID\"" +
                        " LEFT JOIN " + sm + " AS SM ON SM.\"OID\" = C.\"OID_SUBMODULO\"" +
                        " LEFT JOIN " + si + " AS SI ON SI.\"OID_SUBMODULO\" = SM.\"OID\" AND SI.\"OID_INSTRUCTOR\" = S.\"OID_PROFESOR\" AND S.\"FECHA\" BETWEEN COALESCE(SI.\"FECHA_INICIO\", '01-01-0001') AND COALESCE(SI.\"FECHA_FIN\", '12-31-2999')" +
                        " LEFT JOIN " + i + " AS I ON I.\"OID\" = SI.\"OID_INSTRUCTOR_SUPLENTE\"" +
                        " WHERE S.\"OID_HORARIO\" = " + oid_horario.ToString() +
                        " ORDER BY S.\"FECHA\", S.\"HORA\"";
            }

            //if (lock_table) query += " FOR UPDATE OF S NOWAIT";

            return(query);
        }
Пример #6
0
        private static string SELECT_DISPONIBILIDAD_SEMANAL(DateTime fecha_inicio, bool all)
        {
            string empleado       = nHManager.Instance.GetSQLTable(typeof(InstructorRecord));
            string disponibilidad = nHManager.Instance.GetSQLTable(typeof(DisponibilidadRecord));

            string fecha = fecha_inicio.Year.ToString("0000") +
                           "-" + fecha_inicio.Month.ToString("00") +
                           "-" + fecha_inicio.Day.ToString("00");

            long m_ini  = ModulePrincipal.GetHoraInicioDisponibilidadMananaSetting();
            long m_fin  = ModulePrincipal.GetHoraFinDisponibilidadMananaSetting();
            long t1_ini = ModulePrincipal.GetHoraInicioDisponibilidadTarde1Setting();
            long t1_fin = ModulePrincipal.GetHoraFinDisponibilidadTarde1Setting();
            long t2_ini = ModulePrincipal.GetHoraInicioDisponibilidadTarde2Setting();
            long t2_fin = ModulePrincipal.GetHoraFinDisponibilidadTarde2Setting();

            bool autorizados = ModulePrincipal.GetMostrarInstructoresAutorizadosSetting();

            string m_str   = string.Empty;
            string t1_str  = string.Empty;
            string t2_str  = string.Empty;
            string ms_str  = string.Empty;
            string t1s_str = string.Empty;
            string t2s_str = string.Empty;

            m_str = " \"L8AM\" = TRUE";
            for (long i = m_ini - 1; i < m_fin; i++)
            {
                m_str += " OR \"L" + i.ToString() + "\" = TRUE";

                if (i < 5)
                {
                    if (ms_str != string.Empty)
                    {
                        ms_str += " OR ";
                    }
                    ms_str += "\"S" + i.ToString() + "\" = TRUE";
                }
            }

            for (long i = t1_ini - 1; i < t1_fin; i++)
            {
                if (t1_str != string.Empty)
                {
                    t1_str += " OR ";
                }
                t1_str += "\"L" + i.ToString() + "\" = TRUE";

                if (i < 5)
                {
                    if (t1s_str != string.Empty)
                    {
                        t1s_str += " OR ";
                    }
                    t1s_str += "\"S" + i.ToString() + "\" = TRUE";
                }
            }

            for (long i = t2_ini - 1; i < t2_fin; i++)
            {
                if (t2_str != string.Empty)
                {
                    t2_str += " OR ";
                }
                t2_str += "\"L" + i.ToString() + "\" = TRUE";

                if (i < 5)
                {
                    if (t2s_str != string.Empty)
                    {
                        t2s_str += " OR ";
                    }
                    t2s_str += "\"S" + i.ToString() + "\" = TRUE";
                }
            }

            string query = "SELECT DISTINCT I.\"OID\", I.\"APELLIDOS\", I.\"NOMBRE_PROPIO\", ";

            query += " \"ND_L\" AS \"LUNES_ND\", \"ND_M\" AS \"MARTES_ND\", \"ND_X\" AS \"MIERCOLES_ND\", \"ND_J\" AS \"JUEVES_ND\", \"ND_V\" AS \"VIERNES_ND\", \"ND_S\" AS \"SABADO_ND\"";

            if (m_str != string.Empty)
            {
                query += ",(" + m_str + ") AS \"LUNES_M\" " +
                         ",(" + m_str.Replace("L", "M") + ") AS \"MARTES_M\" " +
                         ",(" + m_str.Replace("L", "X") + ") AS \"MIERCOLES_M\" " +
                         ",(" + m_str.Replace("L", "J") + ") AS \"JUEVES_M\" " +
                         ",(" + m_str.Replace("L", "V") + ") AS \"VIERNES_M\" ";
            }
            else
            {
                query += ", FALSE AS \"LUNES_M\" " +
                         ", FALSE AS \"MARTES_M\" " +
                         ", FALSE AS \"MIERCOLES_M\" " +
                         ", FALSE AS \"JUEVES_M\" " +
                         ", FALSE AS \"VIERNES_M\" ";
            }

            if (ms_str != string.Empty)
            {
                query += ",(" + ms_str + ") AS \"SABADO_M\" ";
            }
            else
            {
                query += ", FALSE AS \"SABADO_M\" ";
            }

            if (t1_str != string.Empty)
            {
                query += ",(" + t1_str + ") AS \"LUNES_T1\" " +
                         ",(" + t1_str.Replace("L", "M") + ") AS \"MARTES_T1\" " +
                         ",(" + t1_str.Replace("L", "X") + ") AS \"MIERCOLES_T1\" " +
                         ",(" + t1_str.Replace("L", "J") + ") AS \"JUEVES_T1\" " +
                         ",(" + t1_str.Replace("L", "V") + ") AS \"VIERNES_T1\" ";
            }
            else
            {
                query += ", FALSE AS \"LUNES_T1\" " +
                         ", FALSE AS \"MARTES_T1\" " +
                         ", FALSE AS \"MIERCOLES_T1\" " +
                         ", FALSE AS \"JUEVES_T1\" " +
                         ", FALSE AS \"VIERNES_T1\" ";
            }

            if (t1s_str != string.Empty)
            {
                query += ",(" + t1s_str + ") AS \"SABADO_T1\" ";
            }
            else
            {
                query += ", FALSE AS \"SABADO_T1\" ";
            }

            if (t2_str != string.Empty)
            {
                query += ",(" + t2_str + ") AS \"LUNES_T2\" " +
                         ",(" + t2_str.Replace("L", "M") + ") AS \"MARTES_T2\" " +
                         ",(" + t2_str.Replace("L", "X") + ") AS \"MIERCOLES_T2\" " +
                         ",(" + t2_str.Replace("L", "J") + ") AS \"JUEVES_T2\" " +
                         ",(" + t2_str.Replace("L", "V") + ") AS \"VIERNES_T2\" ";
            }
            else
            {
                query += ", FALSE AS \"LUNES_T2\" " +
                         ", FALSE AS \"MARTES_T2\" " +
                         ", FALSE AS \"MIERCOLES_T2\" " +
                         ", FALSE AS \"JUEVES_T2\" " +
                         ", FALSE AS \"VIERNES_T2\" ";
            }

            if (t2s_str != string.Empty)
            {
                query += ",(" + t2s_str + ") AS \"SABADO_T2\" ";
            }
            else
            {
                query += ", FALSE AS \"SABADO_T2\" ";
            }

            query += "FROM " + empleado + " AS I " +
                     "INNER JOIN " + disponibilidad + " AS D ON (D.\"OID_INSTRUCTOR\" = I.\"OID\") " +
                     "WHERE D.\"FECHA_INICIO\" = '" + fecha + "' " +
                     "AND (";

            for (long i = m_ini - 1; i < t2_fin; i++)
            {
                query += "\"L" + i.ToString() + "\" OR ";
                query += "\"M" + i.ToString() + "\" OR ";
                query += "\"X" + i.ToString() + "\" OR ";
                query += "\"J" + i.ToString() + "\" OR ";
                query += "\"V" + i.ToString() + "\" OR ";
            }

            for (long i = m_ini - 1; i < 5; i++)
            {
                query += "\"S" + i.ToString() + "\" OR ";
            }

            query += "\"L8AM\" OR \"M8AM\" OR \"X8AM\" OR \"J8AM\" OR \"V8AM\" OR \"ND_L\" OR \"ND_M\" OR \"ND_X\" OR \"ND_J\" OR \"ND_V\" OR \"ND_S\") ";
            if (autorizados)
            {
                query += "AND I.\"MTOE\" = 'TRUE' ";
            }


            if (all)
            {
                query +=
                    "UNION " +
                    "SELECT DISTINCT I.\"OID\", I.\"APELLIDOS\", I.\"NOMBRE_PROPIO\", ";

                query += " \"ND_L\" AS \"LUNES_ND\", \"ND_M\" AS \"MARTES_ND\", \"ND_X\" AS \"MIERCOLES_ND\", \"ND_J\" AS \"JUEVES_ND\", \"ND_V\" AS \"VIERNES_ND\", \"ND_S\" AS \"SABADO_ND\"";

                if (m_str != string.Empty)
                {
                    query += ",(" + m_str + ") AS \"LUNES_M\" " +
                             ",(" + m_str.Replace("L", "M") + ") AS \"MARTES_M\" " +
                             ",(" + m_str.Replace("L", "X") + ") AS \"MIERCOLES_M\" " +
                             ",(" + m_str.Replace("L", "J") + ") AS \"JUEVES_M\" " +
                             ",(" + m_str.Replace("L", "V") + ") AS \"VIERNES_M\" ";
                }
                else
                {
                    query += ", FALSE AS \"LUNES_M\" " +
                             ", FALSE AS \"MARTES_M\" " +
                             ", FALSE AS \"MIERCOLES_M\" " +
                             ", FALSE AS \"JUEVES_M\" " +
                             ", FALSE AS \"VIERNES_M\" ";
                }

                if (ms_str != string.Empty)
                {
                    query += ",(" + ms_str + ") AS \"SABADO_M\" ";
                }
                else
                {
                    query += ", FALSE AS \"SABADO_M\" ";
                }

                if (t1_str != string.Empty)
                {
                    query += ",(" + t1_str + ") AS \"LUNES_T1\" " +
                             ",(" + t1_str.Replace("L", "M") + ") AS \"MARTES_T1\" " +
                             ",(" + t1_str.Replace("L", "X") + ") AS \"MIERCOLES_T1\" " +
                             ",(" + t1_str.Replace("L", "J") + ") AS \"JUEVES_T1\" " +
                             ",(" + t1_str.Replace("L", "V") + ") AS \"VIERNES_T1\" ";
                }
                else
                {
                    query += ", FALSE AS \"LUNES_T1\" " +
                             ", FALSE AS \"MARTES_T1\" " +
                             ", FALSE AS \"MIERCOLES_T1\" " +
                             ", FALSE AS \"JUEVES_T1\" " +
                             ", FALSE AS \"VIERNES_T1\" ";
                }

                if (t1s_str != string.Empty)
                {
                    query += ",(" + t1s_str + ") AS \"SABADO_T1\" ";
                }
                else
                {
                    query += ", FALSE AS \"SABADO_T1\" ";
                }

                if (t2_str != string.Empty)
                {
                    query += ",(" + t2_str + ") AS \"LUNES_T2\" " +
                             ",(" + t2_str.Replace("L", "M") + ") AS \"MARTES_T2\" " +
                             ",(" + t2_str.Replace("L", "X") + ") AS \"MIERCOLES_T2\" " +
                             ",(" + t2_str.Replace("L", "J") + ") AS \"JUEVES_T2\" " +
                             ",(" + t2_str.Replace("L", "V") + ") AS \"VIERNES_T2\" ";
                }
                else
                {
                    query += ", FALSE AS \"LUNES_T2\" " +
                             ", FALSE AS \"MARTES_T2\" " +
                             ", FALSE AS \"MIERCOLES_T2\" " +
                             ", FALSE AS \"JUEVES_T2\" " +
                             ", FALSE AS \"VIERNES_T2\" ";
                }

                if (t2s_str != string.Empty)
                {
                    query += ",(" + t2s_str + ") AS \"SABADO_T2\" ";
                }
                else
                {
                    query += ", FALSE AS \"SABADO_T2\" ";
                }

                query += "FROM " + empleado + " AS I " +
                         "INNER JOIN " + disponibilidad + " AS D ON (D.\"OID_INSTRUCTOR\" = I.\"OID\") " +
                         "WHERE D.\"FECHA_INICIO\" = '" + fecha + "' " +
                         "AND NOT (";

                for (long i = m_ini - 1; i < t2_fin; i++)
                {
                    query += "\"L" + i.ToString() + "\" OR ";
                    query += "\"M" + i.ToString() + "\" OR ";
                    query += "\"X" + i.ToString() + "\" OR ";
                    query += "\"J" + i.ToString() + "\" OR ";
                    query += "\"V" + i.ToString() + "\" OR ";
                }

                for (long i = m_ini - 1; i < 5; i++)
                {
                    query += "\"S" + i.ToString() + "\" OR ";
                }

                query += "\"L8AM\" OR \"M8AM\" OR \"X8AM\" OR \"J8AM\" OR \"V8AM\" OR \"ND_L\" OR \"ND_M\" OR \"ND_X\" OR \"ND_J\" OR \"ND_V\" OR \"ND_S\") ";
                if (autorizados)
                {
                    query += "AND I.\"MTOE\" = 'TRUE' ";
                }

                query +=

                    "UNION  " +
                    "SELECT I.\"OID\", I.\"APELLIDOS\", I.\"NOMBRE_PROPIO\", " +
                    "FALSE AS \"LUNES_ND\", FALSE AS \"MARTES_ND\", FALSE AS \"MIERCOLES_ND\", FALSE AS \"JUEVES_ND\", FALSE AS \"VIERNES_ND\", FALSE AS \"SABADO_ND\", FALSE AS \"LUNES_M\", " +
                    "FALSE AS \"MARTES_M\", FALSE AS \"MIERCOLES_M\", FALSE AS \"JUEVES_M\", FALSE AS \"VIERNES_M\", " +
                    "FALSE AS \"SABADO_M\", FALSE AS \"LUNES_T1\", FALSE AS \"MARTES_T1\", FALSE AS \"MIERCOLES_T1\", " +
                    "FALSE AS \"JUEVES_T1\", FALSE AS \"VIERNES_T1\", FALSE AS \"SABADO_T1\", FALSE AS \"LUNES_T2\", " +
                    "FALSE AS \"MARTES_T2\", FALSE AS \"MIERCOLES_T2\", FALSE AS \"JUEVES_T2\", FALSE AS \"VIERNES_T2\", " +
                    "FALSE AS \"SABADO_T2\" " +
                    "FROM " + empleado + " AS I " +
                    "WHERE (I.\"ACTIVO\" = TRUE AND I.\"OID\" NOT IN (SELECT D.\"OID_INSTRUCTOR\" " +
                    "                        FROM " + disponibilidad + " AS D " +
                    "                        WHERE D.\"FECHA_INICIO\" = '" + fecha + "')) ";
                if (autorizados)
                {
                    query += "OR I.\"MTOE\" = 'FALSE' ";
                }
            }

            query += "ORDER BY \"APELLIDOS\", \"NOMBRE_PROPIO\";";

            return(query);
        }