Exemplo n.º 1
0
        /// <summary>
        /// Retrieves and returns the user list.
        /// </summary>
        /// <param name="modules">The modules for the current user.</param>
        /// <param name="currentPage">The current page.</param>
        /// <param name="filter">A given SQL Statement filter.</param>
        /// <returns>An HTML including the user list.</returns>
        public static string GetUserList(Dictionary<string, bool> modules, int currentPage, string filter)
        {
            string retval = "";
            string className = "";
            int total = 0;
            string sql = "SELECT COUNT(IdUser) AS HowMany FROM Users";
            filter = Common.StrAdd(filter, " AND ", "IdUser > 0");
            sql = Common.StrAdd(sql, " WHERE ", filter);
            double recordsPerPage = Config.RecordsPerPage();
            double totalRecords = Common.GetBDNum("HowMany", sql);
            int totalPages = 1;
            try
            {
                Convert.ToInt32(Math.Ceiling(totalRecords / recordsPerPage));
            }
            catch (OverflowException ex) { }

            if (currentPage > totalPages)
            {
                currentPage = totalPages;
            }
            if (currentPage == 0)
            {
                currentPage = 1;
            }

            retval = "<table width='100%'>";

            //Table Header
            retval += "<tr><th width='20px'>" + Text.Identifier + "</th><th>" + Text.Name + "</th><th>" + Text.Username + "</th><th>" + Text.RegistryDate + "</th></tr>";

            sql = "SELECT IdUser, LastName FROM (SELECT IdUser, LastName, ROW_NUMBER() OVER (ORDER BY LastName) AS RowNum FROM Users";
            sql = Common.StrAdd(sql, " WHERE ", filter);
            sql += ") AS U WHERE U.RowNum BETWEEN ((" + currentPage + " - 1) * " + recordsPerPage + ") + 1 AND " + recordsPerPage + " * (" + currentPage + ")";
            string[] idUserList = Common.CSVToArray(Common.GetBDList("IdUser", sql, false));
            foreach (string idUser in idUserList)
            {
                try
                {
                    User user = new User(Convert.ToInt32(idUser));
                    string fullName = Common.StrAdd(user.LastName, " ", user.MotherLastName);
                    fullName = Common.StrAdd(fullName, " ", user.Name);
                    className = Common.SwitchClass(className);
                    string extraStyle = "";
                    if (user.Status == Status.BLOCKED)
                    {
                        extraStyle = "color: #CC0000;";
                    }
                    else if (user.Status == Status.INACTIVE)
                    {
                        extraStyle = "font-style: italic;";
                    }
                    retval += "<tr class='" + className + "' onClick='showUser(" + idUser + ");' style='" + extraStyle + "'>";
                    //retval += "<td>" + DrawInput.InputCheckbox("user_" + idUser, idUser, false, "", "", "", "") + "</td>";
                    retval += "<td>" + user.IdUser + "</td>";
                    retval += "<td>" + fullName + "</td>";
                    retval += "<td>" + user.Username + "</td>";
                    retval += "<td>" + user.RegistryDate.ToShortDateString() + "</td>";
                    retval += "</tr>";
                    total++;
                }
                catch (Exception ex) { }
            }

            retval += "</table>";

            //footer / pagination
            retval += "<div align='center' class='pagination'>";
            retval += "<div align='left' style='width: 50%; display: inline-block;'>" + Common.StrLang(Text.ShowingXofY, total.ToString() + "," + totalRecords.ToString()) + " " + Text.Users + "</div>";
            retval += "<div align='right' style='width: 50%; display: inline-block;'>" + Common.StrLang(Text.PageXofY, currentPage.ToString() + "," + totalPages.ToString());
            retval += "&nbsp;<a href='#' class='dark' onClick='firstPage();'>&lt;&lt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='prevPage();'>&lt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='nextPage();'>&gt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='lastPage(" + totalPages + ");'>&gt;&gt;</a>";
            retval += "</div>";
            retval += "</div>";

            return retval;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Retrieves a list of Users.
 /// </summary>
 /// <param name="filter">A given SQL Statement filter.</param>
 /// <returns>A List of Users. (List&lt;User&gt;)</returns>
 public static List<User> GetUsers(string filter)
 {
     List<User> userList = new List<User>();
     string sql = "SELECT IdUser FROM Users";
     filter = Common.StrAdd(filter, " AND ", "IdUser > 0");
     sql = Common.StrAdd(sql, " WHERE ", filter);
     string[] idUserList = Common.CSVToArray(Common.GetBDList("IdUser", sql, false));
     foreach (string idUser in idUserList)
     {
         try
         {
             User user = new User(Convert.ToInt32(idUser));
             userList.Add(user);
         }
         catch (Exception ex) { }
     }
     return userList;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves an HTML String with the full listing of records.
        /// </summary>
        /// <param name="currentPage">The current page.</param>
        /// <param name="filter">A given SQL Statement filter.</param>
        /// <returns>An HTML including the log list.</returns>
        public static string GetLogList(int currentPage, string filter)
        {
            string retval = "";
            string className = "";
            int total = 0;
            double recordsPerPage = Config.RecordsPerPage();
            string sql = "SELECT COUNT(IdLog) AS howMany FROM SystemLog";
            if (SessionHandler.Id != -1)
            {
                filter = Common.StrAdd(filter, " AND ", "IdUser <> -1");
            }
            sql = Common.StrAdd(sql, " WHERE ", filter);
            double totalRecords = Common.GetBDNum("howMany", sql);
            int totalPages = Convert.ToInt32(Math.Ceiling(totalRecords / recordsPerPage));

            if (currentPage > totalPages)
            {
                currentPage = totalPages;
            }
            if (currentPage == 0)
            {
                currentPage = 1;
            }

            retval = "<table width='100%'>";

            //Table Header
            retval += "<tr><th>" + Text.DateTime + "</th><th>" + Text.Username + "</th><th>" + Text.Action + "</th><th>" + Text.Description + "</th></tr>";

            sql = "SELECT IdLog, TimeStamp FROM (SELECT IdLog, TimeStamp, ROW_NUMBER() OVER (ORDER BY TimeStamp DESC) AS RowNum FROM SystemLog";
            sql = Common.StrAdd(sql, " WHERE ", filter);
            sql += ") AS SL WHERE SL.RowNum BETWEEN ((" + currentPage + " - 1) * " + recordsPerPage + ") + 1 AND " + recordsPerPage + " * (" + currentPage + ")";
            string[] idLogList = Common.CSVToArray(Common.GetBDList("IdLog", sql, false));
            foreach (string idLog in idLogList)
            {
                try
                {
                    SystemLog log = new SystemLog(Convert.ToInt32(idLog));
                    User user = new User(log.IdUser);
                    string description = log.Description.Replace("#SESSION_START#", Text.SessionStarted + ": ").Replace("#SESSION_END#", Text.SessionClosed).Replace("#LOGIN_FAILED#", Text.LoginFailed + ": ").Replace("#FIELD_SEQUENCE#", Text.FieldSequence);
                    if (log.IdModule != 0)
                    {
                        Module module = new Module(log.IdModule);
                        description = Common.StrAdd(Modules.FriendlyModuleName(module.Name), ": ", description);
                        description += " [" + log.IdRelated + "]";
                        if (log.IdModule == Modules.IMPORT_USERS || log.IdModule == Modules.EVAL_IMPORT_EXAMS || log.IdModule == Modules.EVAL_ASSIGN || log.IdModule == Modules.EVAL_IMPORT_RESULTS)
                        {
                            description += "&nbsp;[<a href='#' class='dark' onClick='viewLog(" + log.IdRelated + "); return false;'>" + Text.Detail + "</a>]";
                        }
                    }
                    className = Common.SwitchClass(className);
                    retval += "<tr class='" + className + "'>";
                    retval += "<td>" + log.TimeStamp.ToString() + "</td>";
                    retval += "<td>" + user.Username + "</td>";
                    retval += "<td>" + LogKind.Name(log.Kind) + "</td>";
                    retval += "<td>" + description + "</td>";
                    retval += "</tr>";
                    total++;
                }
                catch (Exception ex) { }
            }
            retval += "</table>";

            //footer / pagination
            retval += "<div align='center' class='pagination'>";
            retval += "<div align='left' style='width: 50%; display: inline-block;'>" + Common.StrLang(Text.ShowingXofY, total.ToString() + "," + totalRecords.ToString()) + " " + Text.Records + "</div>";
            retval += "<div align='right' style='width: 50%; display: inline-block;'>" + Common.StrLang(Text.PageXofY, currentPage.ToString() + "," + totalPages.ToString());
            retval += "&nbsp;<a href='#' class='dark' onClick='firstPage();'>&lt;&lt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='prevPage();'>&lt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='nextPage();'>&gt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='lastPage(" + totalPages + ");'>&gt;&gt;</a>";
            retval += "</div>";
            retval += "</div>";

            return retval;
        }