Esempio n. 1
0
        public XVar report_error(XVar _param_message)
        {
            XVar message = _param_message.Clone();

            MVCFunctions.EchoToOutput(message);
            return(null);
        }
Esempio n. 2
0
        virtual public void db_multipleInsertQuery(XVar qstringArray, XVar table = null, XVar isIdentityOffNeeded = null)
        {
            DbConnection connection = connectionsPool.FreeConnection;

            if (connection.State != System.Data.ConnectionState.Open)
            {
                connection.Open();
            }

            DbCommand cmd = GetCommand();

            cmd.Connection = connection;

            try
            {
                foreach (var qstring in qstringArray.GetEnumerator())
                {
                    if (GlobalVars.dDebug)
                    {
                        MVCFunctions.EchoToOutput(qstring.Value.ToString() + "<br />");
                    }

                    GlobalVars.strLastSQL = qstring.Value;
                    cmd.CommandText       = qstring.Value.ToString();
                    cmd.ExecuteNonQuery();
                }
            }
            finally
            {
                connection.Close();
            }
        }
Esempio n. 3
0
        // handlers

// After successful login
        public XVar AfterSuccessfulLogin(dynamic username, dynamic password, dynamic data, dynamic pageObject)
        {
            try
            {
                XSession.Session["ONI"] = data["ONI"];

                dynamic record;
                //string query = string.Format("EXEC get_empleado '{0}'", data["ONI"].ToString());
                //dynamic rs = DB.Query(query);
                dynamic rs = DB.Query("EXEC get_empleado '" + data["ONI"].ToString() + "'");

                while (record = rs.fetchAssoc())
                {
                    XSession.Session["nombre"]          = record["nombre"];
                    XSession.Session["departamento"]    = record["departamento"];
                    XSession.Session["tipo_empleado"]   = record["tipo_empleado"];
                    XSession.Session["horarios"]        = record["horarios"];
                    XSession.Session["id_departamento"] = record["id_departamento"];
                    XSession.Session["id_tipo"]         = record["id_tipo"];
                    XSession.Session["id_horarios"]     = record["id_horarios"];
                    XSession.Session["GrupoID"]         = record["GrupoID"];
                    XSession.Session["id_grupo_depar"]  = record["id_grupo"];
                }
            }catch (Exception e)
            {
                MVCFunctions.EchoToOutput("<div class=\"alert alert-danger\" ><strong>Error!</strong> en el evento AfterSuccessfulLogin al asignar las variables session: " + e.Message + "</div>");
            }


            return(null);
        }         // AfterSuccessfulLogin
Esempio n. 4
0
        }         // AfterAdd

// List page: Before SQL query
        public XVar BeforeQueryList(dynamic strSQL, ref dynamic strWhereClause, ref dynamic strOrderBy, dynamic pageObject)
        {
            try
            {
                if (XSession.Session["GrupoID"] == 3)// Si el  usuario tienen el rol de supervisor entoses
                {
                    // revisamos si el supervisor tiene un grupo asignado
                    if (string.IsNullOrEmpty(XSession.Session["id_grupo_depar"]))//Si la variable de session no tiene valor
                    {
                        strWhereClause = "dbo.EMPLEADO.id_departamento = " + XSession.Session["id_departamento"].ToString() + " and dbo.acceso_ugmembers.GroupID=1";
                    }
                    else
                    {
                        strWhereClause = "dbo.EMPLEADO.id_departamento = " + XSession.Session["id_departamento"].ToString() + " and dbo.EMPLEADO.id_grupo = " + XSession.Session["id_grupo_depar"].ToString() + "and dbo.acceso_ugmembers.GroupID=1";
                    }
                }

                if (XSession.Session["GrupoID"] == 4) // Si el  usuario tienen el rol de Jefe departamento entoses
                {
                    strWhereClause = "dbo.EMPLEADO.id_departamento = " + XSession.Session["id_departamento"].ToString();
                }
            }
            catch (Exception e)
            {
                MVCFunctions.EchoToOutput("<div class=\"alert alert-danger\" role=\"alert\"><strong>Error!</strong> en el evento BeforeQueryList al filtrar la tabla por ONI: " + e.Message + "</div>");
            }
            return(null);
        }         // BeforeQueryList
Esempio n. 5
0
        /**
         * An interface stub
         * Execute an SQL query
         * @param String sql
         */
        public QueryResult exec(XVar sql)
        {
            //db_exec
            if (GlobalVars.dDebug)
            {
                MVCFunctions.EchoToOutput(sql.ToString() + "<br />");
            }

            return(query(sql));
        }
Esempio n. 6
0
        }         // BeforeAdd

// List page: Before SQL query
        public XVar BeforeQueryList(dynamic strSQL, ref dynamic strWhereClause, ref dynamic strOrderBy, dynamic pageObject)
        {
            try
            {
                strWhereClause = "ONI = '" + XSession.Session["ONI"].ToString() + "'";
            }
            catch (Exception e)
            {
                MVCFunctions.EchoToOutput("<div class=\"alert alert-danger\" role=\"alert\"><strong>Error!</strong> en el evento BeforeQueryList al filtrar la tabla por ONI: " + e.Message + "</div>");
            }
// Place event code here.
// Use "Add Action" button to add code snippets.
            return(null);
        }         // BeforeQueryList
Esempio n. 7
0
        }         // AfterAppInit

        // onscreen events
        public XVar event_Informacion_usuario(dynamic header)
        {
            try
            {
                //Obtener Horas personales
                //dynamic personales;
                //dynamic rsp = DB.Query("EXEC getCantidadHorasPersonales '"+XSession.Session["ONI"].ToString()+"'");
                //personales = rsp.fetchAssoc();

                //Obtener Horas compesadas disponibles
                //string sqlcompesado= "SELECT dbo.EMPLEADO.saldo_compesado FROM dbo.EMPLEADO WHERE dbo.EMPLEADO.ONI='"+XSession.Session["ONI"].ToString()+"'";
                //XVar rsc = CommonFunctions.db_query(sqlcompesado, null);
                //XVar compesados = CommonFunctions.db_fetch_array(rsc);

                //dynamic compesados;
                //dynamic rsc = DB.Query("EXEC getCantidadHorasCompesadas '"+XSession.Session["ONI"].ToString()+"'");
                //compesados = rsc.fetchAssoc();


                //Obtener cantidad de permisos personales asignados
                string strSQLExists = string.Format("SELECT horas_permisos_personales from dbo.HORARIOS where id_horarios = '{0}'", XSession.Session["id_horarios"].ToString());
                XVar   rsExists     = CommonFunctions.db_query(strSQLExists, null);
                XVar   data         = CommonFunctions.db_fetch_array(rsExists);

                MVCFunctions.Echo("<div class =\"jumbotron\">");
                MVCFunctions.Echo("<div class =\"container\">");
                MVCFunctions.Echo("<h2 class =\"display-3\">Informacion de usuario</h2>");
                MVCFunctions.Echo("</br>");
                MVCFunctions.Echo("<p>ONI: " + XSession.Session["ONI"].ToString() + "</p>");
                MVCFunctions.Echo("<p>Nombre: " + XSession.Session["nombre"].ToString() + "</p>");
                MVCFunctions.Echo("<p>Cargo: " + XSession.Session["tipo_empleado"].ToString() + "</p>");
                MVCFunctions.Echo("<p>Departamento: " + XSession.Session["departamento"].ToString() + "</p>");
                MVCFunctions.Echo("<p>Horario: " + XSession.Session["horarios"].ToString() + "</p>");
                MVCFunctions.Echo("<p>Horas Personales Asignadas: " + data["horas_permisos_personales"].ToString() + "</p>");
                //MVCFunctions.Echo("<p>Horas Personales Usada: "+personales["total_horas"].ToString()+"</p>");
                //MVCFunctions.Echo("<p>Horas Compesadas Acumuladas: "+compesados["saldo_compesado"].ToString()+"</p>");
                MVCFunctions.Echo("</div>");
                MVCFunctions.Echo("</div>");
            }
            catch (Exception e)
            {
                MVCFunctions.EchoToOutput("<div class=\"alert alert-danger\" role=\"alert\"><strong>Error!</strong>Se presentado el siguiente error: " + e.Message + "</div>");
            }



            return(null);
        }
Esempio n. 8
0
        }         // BeforeAdd

// Before record updated
        public XVar BeforeEdit(dynamic values, dynamic where, dynamic oldvalues, dynamic keys, ref dynamic message, dynamic inline, dynamic pageObject)
        {
//obtener segundos de las fechas
            try
            {
                string fechaini = "";
                string fechafin = "";
                fechaini = values["desde"];
                fechafin = values["hasta"];
                dynamic validarFechas;
                dynamic rsv = DB.Query("SELECT DATEDIFF(second, '" + values["desde"].ToString() + "', '" + values["hasta"].ToString() + "') as total_segundos");
                validarFechas = rsv.fetchAssoc();

                if (fechaini != "" && fechafin != "" && fechaini != null && fechafin != null)
                {
                    if (validarFechas["total_segundos"] < 0)
                    {
                        message = "La Fecha final debe ser mayor a la fecha inicial";
                        MVCFunctions.EchoToOutput("La Fecha final debe ser mayor a la fecha inicial");
                        return(false);
                    }
                }
                else
                {
                    message = "Por favor revise fechas del compesado";
                    MVCFunctions.EchoToOutput("Por favor revise fechas del compesado");
                    return(false);
                }
            }catch (Exception e)
            {
                MVCFunctions.EchoToOutput("<div class=\"alert alert-danger\" ><strong>Error!</strong> en el evento BeforeEdit del formulario compensado al validar las fechas: " + e.Message + "</div>");
            }

            return(true);

            return(null);
        }         // BeforeEdit
Esempio n. 9
0
        /**
         * An interface stub
         * Send an SQL query
         * @param String sql
         * @return QueryResult
         */
        public QueryResult query(XVar sql)
        {
            //db_query
            //return new QueryResult( this, qHandle );

            if (GlobalVars.dDebug)
            {
                MVCFunctions.EchoToOutput(sql.ToString() + "<br />");
            }

            GlobalVars.strLastSQL = sql;
            DbCommand cmd     = null;
            DbCommand initCmd = null;

            try {
                DbConnection connection = connectionsPool.FreeConnection;
                if (connection.State != System.Data.ConnectionState.Open)
                {
                    connection.Open();
                    if (initializingSQL != null)
                    {
                        initCmd             = GetCommand();
                        initCmd.Connection  = connection;
                        initCmd.CommandText = initializingSQL;
                        initCmd.Prepare();
                        initCmd.ExecuteNonQuery();
                    }
                }
                cmd             = GetCommand();
                cmd.Connection  = connection;
                cmd.CommandText = sql;
                cmd.Prepare();

                string    commandStr      = sql.ToLower().Substring(0, 6);
                string [] stopCommandList = { "insert", "update", "delete", "create", "drop", "rename", "alter" };
                if (stopCommandList.Any(x => commandStr.Substring(0, x.Length) == x))
                {
                    cmd.ExecuteNonQuery();
                    CalculateLastInsertedId(commandStr, cmd);
                    cmd.Connection.Close();
                    return(null);
                }
                else
                {
                    RunnerDBReader rdr = cmd.ExecuteReader();
                    rdr.Connection = cmd.Connection;
                    return(new QueryResult(this, rdr));
                }
            }
            catch (Exception e)
            {
                GlobalVars.LastDBError = e.Message;
                if (cmd != null)
                {
                    cmd.Connection.Close();
                }

                if (!silentMode)
                {
                    if (!MVCFunctions.HandleError())
                    {
                        throw e;
                    }
                }
                return(null);
            }
        }
Esempio n. 10
0
        public XVar event_Mostrar_Horas(dynamic header)
        {
//Obtener segundos personales
            try
            {
                dynamic personales;
                dynamic rsp = DB.Query("EXEC getCantidadHorasPersonales '" + XSession.Session["ONI"].ToString() + "'");
                personales = rsp.fetchAssoc();



//Obtener Horas compesadas disponibles

                dynamic compesados;
                dynamic rsc = DB.Query("EXEC getCantidadHorasCompesadas '" + XSession.Session["ONI"].ToString() + "'");
                compesados = rsc.fetchAssoc();



//Obtener horas en los permisos compesados

                dynamic permisos_compesados;
                dynamic rspc = DB.Query("EXEC getHorasPermisoCompesados '" + XSession.Session["ONI"].ToString() + "'");
                permisos_compesados = rspc.fetchAssoc();


//Obtener cantidad de permisos personales asignados

                string strSQLExists = "SELECT horas_permisos_personales from dbo.HORARIOS where id_horarios = " + XSession.Session["id_horarios"].ToString();
                XVar   rsExists     = CommonFunctions.db_query(strSQLExists, null);
                XVar   data         = CommonFunctions.db_fetch_array(rsExists);



//Tiempo Personal

                int tsegundos = personales["total_segundos"];
                int horas     = (tsegundos / 3600);
                int minutos   = ((tsegundos - horas * 3600) / 60);
                int segundos  = tsegundos - (horas * 3600 + minutos * 60);


//Tiempo compesado acumulado

                int CAtsegundos = compesados["total_comp_segundos"];
                int CAhoras     = (CAtsegundos / 3600);
                int CAminutos   = ((CAtsegundos - CAhoras * 3600) / 60);
                int CAsegundos  = CAtsegundos - (CAhoras * 3600 + CAminutos * 60);


//Tiempo en los permisos compesados

                int PCtsegundos = permisos_compesados["total_segundos"];
                int PChoras     = (PCtsegundos / 3600);
                int PCminutos   = ((PCtsegundos - PChoras * 3600) / 60);
                int PCsegundos  = PCtsegundos - (horas * 3600 + PCminutos * 60);

                int compesado_disponible = CAtsegundos - PCtsegundos;

                int PDtsegundos = compesado_disponible;
                int PDhoras     = (PDtsegundos / 3600);
                int PDminutos   = ((PDtsegundos - PDhoras * 3600) / 60);
                int PDsegundos  = PDtsegundos - (PDhoras * 3600 + PDminutos * 60);

//Mostrar en pantalla los tiempos

                //MVCFunctions.Echo("<h4>Horas personales: <font size=\"4\" color=\"red\">"+personales["total_horas"].ToString()+"</font><font size=\"4\">/"+data["horas_permisos_personales"].ToString()+"</font> Horas Compesadas: <font size=\"4\" color=\"blue\">"+compesados["saldo_compesado"].ToString()+"</font></h4>");
                MVCFunctions.Echo("<p>TIEMPO PERSONAL TOMADO: <font size=\"4\" color=\"red\">" + horas.ToString() + ":" + minutos.ToString() + "</font></p>");
                MVCFunctions.Echo("<p>HORAS PERSONALES ASIGNADAS: <font size=\"4\">" + data["horas_permisos_personales"].ToString() + "</font></p>");
                MVCFunctions.Echo("<p>TIEMPO COMPESADO ACUMULADO: <font size=\"4\" color=\"blue\">" + CAhoras.ToString() + ":" + CAminutos.ToString() + "</font></p>");
                MVCFunctions.Echo("<p>TIEMPO COMPESADO TOMANDO: <font size=\"4\" color=\"blue\">" + PChoras.ToString() + ":" + PCminutos.ToString() + "</font></p>");
                MVCFunctions.Echo("<p>TIEMPO COMPESADO DISPONIBLE: <font size=\"4\" color=\"blue\">" + PDhoras.ToString() + ":" + PDminutos.ToString() + "</font></p>");
            }
            catch (Exception e)
            {
                MVCFunctions.EchoToOutput("<div class=\"alert alert-danger\" ><strong>Error!</strong> en el code_snippets Mostrar_Horas: " + e.Message + "</div>");
            }


            return(null);
        }
Esempio n. 11
0
        public override void db_multipleInsertQuery(XVar qstringArray, XVar table = null, XVar isIdentityOffNeeded = null)
        {
            try
            {
                DbConnection connection = connectionsPool.FreeConnection;
                if (connection.State != System.Data.ConnectionState.Open)
                {
                    connection.Open();
                }

                DbCommand cmd = GetCommand();
                cmd.Connection = connection;

                if (isIdentityOffNeeded)
                {
                    cmd.CommandText = "SET IDENTITY_INSERT " + table.ToString() + " ON";
                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                }
                foreach (var qstring in qstringArray.GetEnumerator())
                {
                    if (GlobalVars.dDebug)
                    {
                        MVCFunctions.EchoToOutput(qstring.Value.ToString() + "<br />");
                    }

                    GlobalVars.strLastSQL = qstring.Value;

                    cmd.CommandText = qstring.Value.ToString();

                    cmd.ExecuteNonQuery();
                }
                if (isIdentityOffNeeded)
                {
                    cmd.CommandText = "SET IDENTITY_INSERT " + table.ToString() + " OFF";
                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                }
                else
                {
                    cmd.CommandText = "select @@IDENTITY as indent";
                    cmd.Prepare();
                    RunnerDBReader rdr = cmd.ExecuteReader();
                    rdr.Connection = cmd.Connection;
                    if (rdr.Read())
                    {
                        lastInsertedID = new XVar(rdr["indent"]);
                    }
                }
                connection.Close();
            }
            catch (Exception e)
            {
                if (!silentMode)
                {
                    if (!MVCFunctions.HandleError())
                    {
                        throw e;
                    }
                }
            }
        }
Esempio n. 12
0
        }         // IsRecordEditable

// Before record added
        public XVar BeforeAdd(dynamic values, ref dynamic message, dynamic inline, dynamic pageObject)
        {
            try
            {
                //Obtener segundos personales
                dynamic personales;
                dynamic rsp = DB.Query("EXEC getCantidadHorasPersonales '" + XSession.Session["ONI"].ToString() + "'");
                personales = rsp.fetchAssoc();


                //Obtener Horas compesadas disponibles
                dynamic compesados;
                dynamic rsc = DB.Query("EXEC getCantidadHorasCompesadas '" + XSession.Session["ONI"].ToString() + "'");
                compesados = rsc.fetchAssoc();


                //Obtener horas en los permisos compesados
                dynamic permisos_compesados;
                dynamic rspc = DB.Query("EXEC getHorasPermisoCompesados '" + XSession.Session["ONI"].ToString() + "'");
                permisos_compesados = rspc.fetchAssoc();


                //Obtener cantidad de permisos personales asignados
                string strSQLExists = "SELECT horas_permisos_personales from dbo.HORARIOS where id_horarios = " + XSession.Session["id_horarios"].ToString();
                XVar   rsExists     = CommonFunctions.db_query(strSQLExists, null);
                XVar   data         = CommonFunctions.db_fetch_array(rsExists);


                //Tiempo en el permisos
                string SQLPermiso = "SELECT SUM(DATEDIFF(second, '" + values["fecha_inicio"].ToString() + "', '" + values["fecha_final"].ToString() + "')) as tiempo";
                XVar   rst        = CommonFunctions.db_query(SQLPermiso, null);
                XVar   permiso    = CommonFunctions.db_fetch_array(rst);


                // tiempo personal -> personales["total_segundos"]
                // segundos personales disponibles -> compesados["total_comp_segundos"]
                //  segundos en los permisos compesados -> permisos_compesados["total_segundos"]
                // cantidad de permisos personales asignados-> data["horas_permisos_personales"]
                // tiempo del permiso -> permiso["tiempo"]


                //crear variables para los calculos permiso
                int tiempo_permiso    = permiso["tiempo"];
                int tiempo_acumuladas = personales["total_segundos"];
                int tiempo_asignadas  = data["horas_permisos_personales"] * 3600;


                //Validar las fechas del permiso
                string fechaini = "";
                string fechafin = "";
                fechaini = values["fecha_inicio"];
                fechafin = values["fecha_final"];


                //Validar si las fechas  final no menor a la de inicio
                if (fechaini != "" && fechafin != "" && fechaini != null && fechafin != null)
                {
                    if (tiempo_permiso < 0)
                    {
                        message = "La Fecha final debe ser mayor a la fecha inicial";
                        MVCFunctions.EchoToOutput("La Fecha final debe ser mayor a la fecha inicial");
                        return(false);
                    }
                }
                else
                {
                    message = "Por favor revise fechas del Permiso";
                    MVCFunctions.EchoToOutput("Por favor revise fechas del Permiso");
                    return(false);
                }


                //validar el permiso
                if (values["id_tipopermiso"] == 1)                               // Si el permiso es personal
                {
                    if ((tiempo_permiso + tiempo_acumuladas) > tiempo_asignadas) // Si el tiempo del permiso mas el tiempo acumalado es mayo que el asignado
                    {
                        message = "El tiempo solicitado en el permiso excede la cantidad de horas personales asignadas |tiempo_permiso=" + tiempo_permiso.ToString() + "|tiempo_acumuladas=" + tiempo_acumuladas.ToString() + "|tiempo_asignadas=" + tiempo_asignadas.ToString() + "|SQLPermiso=" + SQLPermiso.ToString();
                        return(false);
                    }
                }
                else if (values["id_tipopermiso"] == 2)                     // Si el permiso es por tiempo compesado
                {
                    if (tiempo_permiso > compesados["total_comp_segundos"]) //Si el tiempo de permiso es mayo a las horas acumuladas
                    {
                        message = "El tiempo solicitado en el permiso excede la cantidad de horas compesadas disponibles |tiempo_permiso=" + tiempo_permiso.ToString() + "|compesados=" + compesados["total_comp_segundos"].ToString() + "|SQLPermiso=" + SQLPermiso.ToString();
                        return(false);
                    }
                }

                //Validar si una de la fechas solicitadas en el permiso ya se ha pasado de lo permitido por grupo o departamento.
                DateTime inicio = DateTime.Parse(fechaini);
                DateTime fin    = DateTime.Parse(fechafin);
                DateTime temp   = inicio;

                if (string.IsNullOrEmpty(XSession.Session["id_grupo_depar"])) // revisamos si el empleado tiene un grupo asignado
                {
                    while (temp <= fin)                                       // Si el empleado no tiene grupo asignado se recorrera las fechas que comprenden el permiso desde la fecha inicio hasta la fecha fin.
                    {
                        // Se consulta la cantidad de permisos del departamento del empleado que hay para esa fecha validar
                        string SQLPermisoGrupo = "SELECT COUNT(id_permisos) as permisos FROM dbo.PERMISOSGRUPOS where fecha_permisos = '" + temp.ToString("yyyy/MM/dd") + "' and id_departamento = " + XSession.Session["id_departamento"].ToString();
                        XVar   rsPG            = CommonFunctions.db_query(SQLPermisoGrupo, null);
                        XVar   PermisosxGrupos = CommonFunctions.db_fetch_array(rsPG);

                        if (PermisosxGrupos)//Si hay permisos para la fecha consultada se procede validar que no se haya alcanzado el valor limite de permisos diarios por departamento
                        {
                            //Consultamos el limite de permisos diarios asignado al departamento
                            string SQLlimitepermisos = "SELECT limite_permisos FROM DEPARTAMENTO WHERE id_departamento = " + XSession.Session["id_departamento"].ToString();
                            XVar   rsLP           = CommonFunctions.db_query(SQLlimitepermisos, null);
                            XVar   limitePermisos = CommonFunctions.db_fetch_array(rsLP);
                            if (PermisosxGrupos["permisos"] >= limitePermisos["limite_permisos"]) //Validamos si la cantidad de permisos para esta fecha ha alcanzado la cantidad de permisos permitido por dia
                            {
                                //Si la condicion es verdadera se muestra un mensaje y no se ingresa el permiso
                                message = "La fecha " + temp.ToString() + "Compredida en periodo del permiso que esta solicitando, sobrepasa el limte de permiso diarios de " + limitePermisos["limite_permisos"].ToString();
                                return(false);
                            }
                            else
                            {
                                //Si la condicion es falsa se inserta la fecha en la tabla PERMISOSGRUPOS.
                                string strSQLInsert = "insert into PERMISOSGRUPOS (fecha_permisos, id_departamento ) values ('" + temp.ToString("yyyy/MM/dd") + "', " + XSession.Session["id_departamento"].ToString() + ")";
                                CommonFunctions.db_exec(strSQLInsert, null);
                            }
                        }
                        temp = temp.AddDays(1);//Se suma un dia al bucle
                    }
                }
                else//El empleado si tiene un grupo asignado
                {
                    while (temp <= fin)    // Si el empleado tiene un grupo asignado se recorrera las fechas que comprenden el permiso desde la fecha inicio hasta la fecha fin.
                    {
                        // Se consulta la cantidad de permisos del grupo del empleado que hay para esta fecha
                        string SQLPermisoGrupo = "SELECT COUNT(id_permisos) as permisos FROM dbo.PERMISOSGRUPOS where fecha_permisos = '" + temp.ToString("yyyy/MM/dd") + "' and id_departamento = " + XSession.Session["id_departamento"].ToString() + "and id_grupo = " + XSession.Session["id_grupo_depar"].ToString();
                        XVar   rsPG            = CommonFunctions.db_query(SQLPermisoGrupo, null);
                        XVar   PermisosxGrupos = CommonFunctions.db_fetch_array(rsPG);

                        if (PermisosxGrupos)       //Si hay permisos para la fecha consultada se procede validar que no se haya alcanzado el valor limite de permisos diarios por departamento
                        {
                            //Consultamos el limite de permisos diarios asignado al departamento
                            string SQLlimitepermisos = "SELECT limite_permisos FROM DEPARTAMENTO WHERE id_departamento = " + XSession.Session["id_departamento"].ToString();
                            XVar   rsLP           = CommonFunctions.db_query(SQLlimitepermisos, null);
                            XVar   limitePermisos = CommonFunctions.db_fetch_array(rsLP);
                            if (PermisosxGrupos["permisos"] >= limitePermisos["limite_permisos"]) //Validamos si la cantidad de permisos para esta fecha ha alcanzado la cantidad de permisos permitido por dia
                            {
                                //Si la condicion es verdadera se muestra un mensaje y no se ingresa el permiso
                                message = "La fecha " + temp.ToString() + "Compredida en periodo del permiso que esta solicitando, sobrepasa el limte de permiso diarios de " + limitePermisos["limite_permisos"].ToString();
                                return(false);
                            }
                            else
                            {
                                //Si la condicion es falsa se inserta la fecha en la tabla PERMISOSGRUPOS.
                                string strSQLInsert = "insert into PERMISOSGRUPOS (fecha_permisos, id_departamento, id_grupo) values ('" + temp.ToString("yyyy/MM/dd") + "', " + XSession.Session["id_departamento"].ToString() + "," + XSession.Session["id_grupo_depar"].ToString() + ")";
                                CommonFunctions.db_exec(strSQLInsert, null);
                            }
                        }
                        temp = temp.AddDays(1);        //Se suma un dia al bucle
                    }
                }



                return(true);
            }catch (Exception e)
            {
                MVCFunctions.EchoToOutput("<div class=\"alert alert-danger\" ><strong>Error!</strong> en el evento BeforeAdd del fomulario de permisos al validar el permiso: " + e.Message + "</div>");
            }
            return(null);
        }         // BeforeAdd
Esempio n. 13
0
        }         // BeforeProcessAdd

// Before record added
        public XVar BeforeAdd(dynamic values, ref dynamic message, dynamic inline, dynamic pageObject)
        {
            try
            {
//Obtener segundos personales
                dynamic personales;
                dynamic rsp = DB.Query("EXEC getCantidadHorasPersonales '" + XSession.Session["ONI"].ToString() + "'");
                personales = rsp.fetchAssoc();

//Obtener Horas compesadas disponibles
                dynamic compesados;
                dynamic rsc = DB.Query("EXEC getCantidadHorasCompesadas '" + XSession.Session["ONI"].ToString() + "'");
                compesados = rsc.fetchAssoc();

//Obtener horas en los permisos compesados
                dynamic permisos_compesados;
                dynamic rspc = DB.Query("EXEC getHorasPermisoCompesados '" + XSession.Session["ONI"].ToString() + "'");
                permisos_compesados = rspc.fetchAssoc();

//Obtener cantidad de permisos personales asignados
                string strSQLExists = "SELECT horas_permisos_personales from dbo.HORARIOS where id_horarios = " + XSession.Session["id_horarios"].ToString();
                XVar   rsExists     = CommonFunctions.db_query(strSQLExists, null);
                XVar   data         = CommonFunctions.db_fetch_array(rsExists);

//Tiempo en el permisos
                string SQLPermiso = "SELECT SUM(DATEDIFF(second, '" + values["fecha_inicio"].ToString() + "', '" + values["fecha_final"].ToString() + "')) as tiempo";
                XVar   rst        = CommonFunctions.db_query(SQLPermiso, null);
                XVar   permiso    = CommonFunctions.db_fetch_array(rst);

// tiempo personal -> personales["total_segundos"]
// segundos personales disponibles -> compesados["total_comp_segundos"]
//  segundos en los permisos compesados -> permisos_compesados["total_segundos"]
// cantidad de permisos personales asignados-> data["horas_permisos_personales"]
// tiempo del permiso -> permiso["tiempo"]

//crear variables para los calculos permiso
                int tiempo_permiso    = permiso["tiempo"];
                int tiempo_acumuladas = personales["total_segundos"];
                int tiempo_asignadas  = data["horas_permisos_personales"] * 3600;

//Validar las fechas del permiso
                string fechaini = "";
                string fechafin = "";
                fechaini = values["fecha_inicio"];
                fechafin = values["fecha_final"];

//Validar si las fechas  final no menor a la de inicio
                if (fechaini != "" && fechafin != "" && fechaini != null && fechafin != null)
                {
                    if (tiempo_permiso < 0)
                    {
                        message = "La Fecha final debe ser mayor a la fecha inicial";
                        MVCFunctions.EchoToOutput("La Fecha final debe ser mayor a la fecha inicial");
                        return(false);
                    }
                }
                else
                {
                    message = "Por favor revise fechas del Permiso";
                    MVCFunctions.EchoToOutput("Por favor revise fechas del Permiso");
                    return(false);
                }



//validar el permiso
                if (values["id_tipopermiso"] == 1)                               // Si el permiso es personal
                {
                    if ((tiempo_permiso + tiempo_acumuladas) > tiempo_asignadas) // Si el tiempo del permiso mas el tiempo acumalado es mayo que el asignado
                    {
                        message = "El tiempo solicitado en el permiso excede la cantidad de horas personales asignadas |tiempo_permiso=" + tiempo_permiso.ToString() + "|tiempo_acumuladas=" + tiempo_acumuladas.ToString() + "|tiempo_asignadas=" + tiempo_asignadas.ToString() + "|SQLPermiso=" + SQLPermiso.ToString();
                        return(false);
                    }
                }
                else if (values["id_tipopermiso"] == 2)                     // Si el permiso es por tiempo compesado
                {
                    if (tiempo_permiso > compesados["total_comp_segundos"]) //Si el tiempo de permiso es mayo a las horas acumuladas
                    {
                        message = "El tiempo solicitado en el permiso excede la cantidad de horas compesadas disponibles |tiempo_permiso=" + tiempo_permiso.ToString() + "|compesados=" + compesados["total_comp_segundos"].ToString() + "|SQLPermiso=" + SQLPermiso.ToString();
                        return(false);
                    }
                }

                return(true);
            }catch (Exception e)
            {
                MVCFunctions.EchoToOutput("<div class=\"alert alert-danger\" ><strong>Error!</strong> en el evento BeforeAdd del fomulario de permisos al validar el permiso: " + e.Message + "</div>");
            }
            return(null);
        }         // BeforeAdd