/// <summary>
        /// Select the record count according to category (overload)
        /// </summary>
        /// <param name="cat"></param>
        /// <param name="pageArray"></param>
        /// <param name="identifier"></param>
        /// <param name="lang"></param>
        /// <returns></returns>
        public int fetchCountByCategory(FileLibraryCategoryData cat, CmsPage[] pageArray, int identifier, CmsLanguage lang)
        {
            if (pageArray.Length == 0)
            {
                return(0);
            }

            StringBuilder pageId = new StringBuilder();

            foreach (CmsPage p in pageArray)
            {
                pageId.Append(p.ID.ToString() + ",");
            }
            pageId.Remove(pageId.Length - 1, 1);

            StringBuilder sql = new StringBuilder("SELECT Count(PageId) AS RecordCount FROM ");

            sql.Append(DETAILS_TABLE);
            sql.Append(" WHERE Deleted IS NULL");
            sql.Append(" AND CategoryId=" + cat.CategoryId.ToString());
            sql.Append(" AND PageId IN(" + pageId.ToString() + ")");
            sql.Append(" AND Identifier=" + identifier.ToString());
            sql.Append(" AND LangCode='" + dbEncode(lang.shortCode) + "'");

            DataSet ds = this.RunSelectQuery(sql.ToString());

            if (this.hasSingleRow(ds))
            {
                DataRow dr = ds.Tables[0].Rows[0];
                return(Convert.ToInt32(dr["RecordCount"]));
            }
            return(0);
        }
 /// <summary>
 /// Put datarow raw values to entity object
 /// </summary>
 /// <param name="dr"></param>
 /// <param name="entity"></param>
 protected void rowToData(DataRow dr, FileLibraryCategoryData entity)
 {
     entity.CategoryId    = Convert.ToInt32(dr["CategoryId"]);
     entity.Lang          = new CmsLanguage(dr["LangCode"].ToString());
     entity.EventRequired = Convert.ToBoolean(dr["EventRequired"]);
     entity.CategoryName  = dr["CategoryName"].ToString();
     entity.SortOrdinal   = Convert.ToInt32(dr["SortOrdinal"]);
 }
 /// <summary>
 /// Generate HTML SELECT and OPTION tags for FileLibraryCategory
 /// </summary>
 /// <param name="lang"></param>
 /// <param name="controlId"></param>
 /// <param name="selectedId"></param>
 /// <returns></returns>
 protected string getCategoryOption(CmsLanguage lang, string controlId, int selectedId)
 {
     StringBuilder html = new StringBuilder();
     string htmlName = controlId + "categoryId";
     string cssClass = "fileLibrary_categoryId_" + lang.shortCode;
     html.Append("<select name=\"" + htmlName + "\" id=\"" + htmlName + "\" class=\"" + cssClass + "\">" + EOL);
     html.Append(FileLibraryCategoryData.getCategoryOptionTag(lang, categoryList, selectedId));
     html.Append("</select>" + EOL);
     return html.ToString();
 }
        /// <summary>
        /// Delete from `FileLibraryCategory`
        /// (can't just set DELETED timestamp because foreign key still exists under this case)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool deleteCategoryData(FileLibraryCategoryData entity)
        {
            StringBuilder sql = new StringBuilder("DELETE FROM ");

            sql.Append(CATEGORY_TABLE);
            sql.Append(" WHERE CategoryId=" + entity.CategoryId.ToString() + ";");

            int affected = this.RunUpdateQuery(sql.ToString());

            return(affected > 0);
        }
Пример #5
0
        /// <summary>
        /// Check from all the category records to see if event is requried, given a
        /// selected category id
        /// </summary>
        /// <param name="list"></param>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public static bool isEventRequired(List <FileLibraryCategoryData> list, int categoryId)
        {
            FileLibraryCategoryData c = getCategoryFromList(list, categoryId);

            if (c != null)
            {
                return(c.EventRequired);
            }

            return(false);
        }
        /// <summary>
        /// Under edit mode, render the right hand side of the file details page as form (HTML INPUT or TEXTAREA, etc...)
        /// </summary>
        /// <param name="detailsPage"></param>
        /// <param name="identifier"></param>
        /// <param name="lang"></param>
        /// <param name="fileData"></param>
        /// <param name="controlId"></param>
        /// <returns></returns>
        protected string renderRightPaneForm(CmsPage detailsPage, int identifier, CmsLanguage lang, FileLibraryDetailsData fileData, string controlId, CmsUrlFormat fileUrlFormat)
        {
            string        fName = fileData.FileName;
            StringBuilder html  = new StringBuilder();

            html.Append("<div style=\"float: left;\" class=\"listing\">" + EOL);

            html.Append(renderDiv(getFileText(lang), FileLibraryDetailsData.getDownloadAnchorHtml(detailsPage, identifier, lang, fName, fileUrlFormat)));

            string cssClass                  = "fileLibrary_categoryId";
            string popupCategory             = FileLibraryCategoryData.getEditPopupAnchor(lang, cssClass, getEditText(lang));
            string htmlId                    = controlId + "categoryId";
            NameValueCollection categoryColl = new NameValueCollection();

            foreach (FileLibraryCategoryData c in categoryList)
            {
                categoryColl.Add(c.CategoryId.ToString(), c.CategoryName);
            }
            string selectCategory = getCategoryOption(lang, controlId, fileData.CategoryId);

            html.Append(renderDiv(getCategoryText(lang) + " " + popupCategory, selectCategory));

            htmlId = controlId + "author";
            html.Append(renderDiv(getAuthorText(lang), PageUtils.getInputTextHtml(htmlId, htmlId, fileData.Author, 30, 50)));

            htmlId = controlId + "description";
            html.Append(renderDiv(getDocumentAbstractText(lang), PageUtils.getTextAreaHtml(htmlId, htmlId, fileData.Description, 25, 5)));

            if (getFileTypeName(fileData).EndsWith("graphic", StringComparison.CurrentCultureIgnoreCase))
            {
                string imgPreviewUrl = CmsContext.UserInterface.ShowThumbnailPage.getThumbDisplayUrl(FileLibraryDetailsData.getDownloadUrl(detailsPage, identifier, lang, fName, fileUrlFormat), 200, -1);
                string imgTag        = "<img border=\"0\" src=\"" + imgPreviewUrl + "\"></a>";
                html.Append(renderDiv(getImagePreviewText(lang), FileLibraryDetailsData.getDownloadAnchorHtml(detailsPage, identifier, lang, fName, imgTag, "_blank", "", fileUrlFormat)));
            }

            bool eventRequired = FileLibraryCategoryData.isEventRequired(categoryList, fileData.CategoryId);

            if (eventRequired || fileData.EventPageId >= 0)
            {
                htmlId = controlId + "eventPageId";
                html.Append(renderDiv(getAttachedEventText(lang), getEventOption(lang, controlId, fileData.EventPageId, eventRequired)));
            }

            WebPortalUser u = WebPortalUser.FetchUser(fileData.CreatedBy, CmsPortalApplication.GetInstance());
            string        uploadPersonName = (u == null) ? fileData.CreatedBy : u.FullName;

            html.Append(renderDiv(getUploadedByText(lang), uploadPersonName));

            html.Append(renderDiv(getLastUpdatedText(lang), detailsPage.LastUpdatedDateTime.ToString("MMMM d yyyy h:mm tt")));

            html.Append("</div>" + EOL);
            return(html.ToString());
        }
            public static FileAggItem FromFileLibraryDetailsData(FileLibraryDetailsData sourceDetails, List <FileLibraryCategoryData> categoryList, CmsUrlFormat pageLinkUrlFormat, CmsUrlFormat fileLinkUrlFormat)
            {
                CmsPage  detailsPage     = CmsContext.getPageById(sourceDetails.DetailsPageId);
                string   PageDisplayURL  = detailsPage.getUrl(sourceDetails.Lang, pageLinkUrlFormat);
                string   FileDownloadURL = FileLibraryDetailsData.getDownloadUrl(detailsPage, sourceDetails.Identifier, sourceDetails.Lang, sourceDetails.FileName, fileLinkUrlFormat);
                string   Title           = detailsPage.getTitle(sourceDetails.Lang);
                string   Description     = sourceDetails.Description;
                string   CategoryName    = FileLibraryCategoryData.getCategoryFromList(categoryList, sourceDetails.CategoryId).CategoryName;
                DateTime lastModified    = detailsPage.LastUpdatedDateTime;

                return(new FileAggItem(PageDisplayURL, FileDownloadURL, Title, Description, CategoryName, lastModified));
            }
        /// <summary>
        /// Update `FileLibraryCategory`
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool updateCategoryData(FileLibraryCategoryData entity)
        {
            StringBuilder sql = new StringBuilder("UPDATE ");

            sql.Append(CATEGORY_TABLE);
            sql.Append(" SET EventRequired=" + entity.EventRequiredAsInt + ",");
            sql.Append(" CategoryName='" + dbEncode(entity.CategoryName) + "',");
            sql.Append(" SortOrdinal=" + entity.SortOrdinal.ToString());
            sql.Append(" WHERE CategoryId=" + entity.CategoryId.ToString());
            sql.Append(" AND LangCode='" + dbEncode(entity.Lang.shortCode) + "';");

            int affected = this.RunUpdateQuery(sql.ToString());

            return(affected > 0);
        }
        /// <summary>
        /// Insert into `FileLibraryCategory`
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool insertCategoryData(FileLibraryCategoryData entity)
        {
            StringBuilder sql = new StringBuilder("INSERT INTO ");

            sql.Append(CATEGORY_TABLE);
            sql.Append(" (CategoryId,LangCode,EventRequired,CategoryName,SortOrdinal) VALUES (");
            sql.Append(entity.CategoryId.ToString() + ",'");
            sql.Append(dbEncode(entity.Lang.shortCode) + "',");
            sql.Append(entity.EventRequiredAsInt + ",'");
            sql.Append(dbEncode(entity.CategoryName) + "',");
            sql.Append(entity.SortOrdinal.ToString() + ");");

            int affected = this.RunUpdateQuery(sql.ToString());

            return(affected > 0);
        }
Пример #10
0
        /// <summary>
        /// Select the record count according to category
        /// </summary>
        /// <param name="cat"></param>
        /// <returns></returns>
        public int fetchCountByCategory(FileLibraryCategoryData cat)
        {
            StringBuilder sql = new StringBuilder("SELECT Count(PageId) AS RecordCount FROM ");

            sql.Append(DETAILS_TABLE);
            sql.Append(" WHERE CategoryId=" + cat.CategoryId.ToString());
            sql.Append(" AND Deleted is null;");

            DataSet ds = this.RunSelectQuery(sql.ToString());

            if (this.hasSingleRow(ds))
            {
                DataRow dr = ds.Tables[0].Rows[0];
                return(Convert.ToInt32(dr["RecordCount"]));
            }
            return(0);
        }
        /// <summary>
        /// Render right hand side of the file details page (all details)
        /// </summary>
        /// <param name="detailsPage"></param>
        /// <param name="identifier"></param>
        /// <param name="lang"></param>
        /// <param name="fileData"></param>
        /// <returns></returns>
        protected string renderRightPane(CmsPage detailsPage, int identifier, CmsLanguage lang, FileLibraryDetailsData fileData, CmsUrlFormat fileUrlFormat)
        {
            string        fName = fileData.FileName;
            StringBuilder html  = new StringBuilder();

            html.Append("<div style=\"float: left;\" class=\"listing\">" + EOL);

            html.Append(renderDiv(getFileText(lang), FileLibraryDetailsData.getDownloadAnchorHtml(detailsPage, identifier, lang, fName, fileUrlFormat)));
            html.Append(renderDiv(getCategoryText(lang), fileData.getCategoryName(categoryList)));

            html.Append(renderDiv(getAuthorText(lang), fileData.Author));
            html.Append(renderDiv(getDocumentAbstractText(lang), StringUtils.nl2br(fileData.Description)));

            if (getFileTypeName(fileData).EndsWith("graphic", StringComparison.CurrentCultureIgnoreCase))
            {
                string imgPreviewUrl = CmsContext.UserInterface.ShowThumbnailPage.getThumbDisplayUrl(FileLibraryDetailsData.getDownloadUrl(detailsPage, identifier, lang, fName, fileUrlFormat), 200, -1);
                string imgTag        = "<img border=\"0\" src=\"" + imgPreviewUrl + "\"></a>";
                html.Append(renderDiv(getImagePreviewText(lang), FileLibraryDetailsData.getDownloadAnchorHtml(detailsPage, identifier, lang, fName, imgTag, "_blank", "", fileUrlFormat)));
            }

            bool eventRequired = FileLibraryCategoryData.isEventRequired(categoryList, fileData.CategoryId);

            if (eventRequired)
            {
                string eventHtml = "(n/a)";
                if (fileData.EventPageId > -1)
                {
                    CmsPage eventPage = CmsContext.getPageById(fileData.EventPageId);
                    eventHtml = "<a href=\"" + eventPage.getUrl(lang) + "\">" + eventPage.getTitle(lang) + "</a>" + EOL;
                }
                html.Append(renderDiv(getAttachedEventText(lang), eventHtml));
            }

            WebPortalUser u = WebPortalUser.FetchUser(fileData.CreatedBy, CmsPortalApplication.GetInstance());
            string        uploadPersonName = (u == null) ? fileData.CreatedBy : u.FullName;

            html.Append(renderDiv(getUploadedByText(lang), uploadPersonName));

            html.Append(renderDiv(getLastUpdatedText(lang), detailsPage.LastUpdatedDateTime.ToString("MMMM d yyyy h:mm tt")));

            html.Append("</div>" + EOL);
            return(html.ToString());
        }
Пример #12
0
        /// <summary>
        /// Select all records from `FileLibraryCategory`
        /// </summary>
        /// <returns></returns>
        public List <FileLibraryCategoryData> fetchCategoryList()
        {
            StringBuilder sql = new StringBuilder("SELECT CategoryId,LangCode,EventRequired,CategoryName,SortOrdinal FROM ");

            sql.Append(CATEGORY_TABLE);
            sql.Append(" ORDER BY SortOrdinal, CategoryId, LangCode;");

            DataSet ds = this.RunSelectQuery(sql.ToString());

            List <FileLibraryCategoryData> list = new List <FileLibraryCategoryData>();

            if (this.hasRows(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    FileLibraryCategoryData entity = new FileLibraryCategoryData();
                    rowToData(dr, entity);
                    list.Add(entity);
                }
            }
            return(list);
        }
Пример #13
0
        public List <FileLibraryDetailsData> fetchDetailsData(CmsPage[] pageArray, int identifier, CmsLanguage lang, FileLibraryCategoryData category, int offset, int count)
        {
            List <FileLibraryDetailsData> list = new List <FileLibraryDetailsData>();

            if (pageArray.Length == 0)
            {
                return(list);
            }

            List <string> pageIds = new List <string>();

            foreach (CmsPage p in pageArray)
            {
                pageIds.Add(p.ID.ToString());
            }

            StringBuilder sql = new StringBuilder("SELECT PageId,Identifier,LangCode,FileName,CategoryId,Author,Description,LastModified,CreatedBy,EventPageId FROM ");

            sql.Append(DETAILS_TABLE);
            sql.Append(" WHERE ");
            sql.Append(" PageId IN(" + string.Join(",", pageIds.ToArray()) + ")");
            if (identifier >= 0)
            {
                sql.Append(" AND Identifier=" + identifier.ToString());
            }
            sql.Append(" AND LangCode='" + dbEncode(lang.shortCode) + "'");
            if (category != null)
            {
                sql.Append(" AND CategoryId=" + category.CategoryId);
            }
            sql.Append(" AND Deleted IS NULL");

            if (category != null)
            {
                sql.Append(" ORDER BY PageId DESC");
            }
            else
            {
                sql.Append(" ORDER BY CategoryId DESC");
            }

            if (count > -1)
            {
                sql.Append(" LIMIT " + offset + "," + count + "");
            }
            else
            {
                sql.Append(";");
            }

            DataSet ds = this.RunSelectQuery(sql.ToString());

            if (this.hasRows(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    FileLibraryDetailsData entity = new FileLibraryDetailsData();
                    rowToData(dr, entity);
                    list.Add(entity);
                }
            }
            return(list);
        }
        public static FileLibraryDetailsData[] getFilesByCategory(List <FileLibraryDetailsData> haystack, FileLibraryCategoryData categoryToMatch)
        {
            List <FileLibraryDetailsData> ret = new List <FileLibraryDetailsData>();

            foreach (FileLibraryDetailsData f in haystack)
            {
                if (f.CategoryId == categoryToMatch.CategoryId)
                {
                    ret.Add(f);
                }
            }
            return(ret.ToArray());
        }