HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/RMourik/bassol.nl/wwwroot/CMSWebParts/Pux/Bassol/RandomRepeater.ascx.cs
using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CMS.PortalControls;
using CMS.Helpers;
using CMS.DocumentEngine;
using System.Collections.Generic;
using System.Linq;

public partial class CMSWebParts_Pux_Bassol_RandomRepeater : CMSAbstractWebPart
{
    #region "Properties"


    #endregion


    #region "Methods"

    /// <summary>
    /// Content loaded event handler.
    /// </summary>
    public override void OnContentLoaded()
    {
        base.OnContentLoaded();
        SetupControl();


    }

    public static Control FindControl(Repeater repeater, string controlName)
    {
        for (int i = 0; i < repeater.Controls.Count; i++)
            if (repeater.Controls[i].Controls[0].FindControl(controlName) != null)
                return repeater.Controls[i].Controls[0].FindControl(controlName);
        return null;

    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (this.StopProcessing)
        {
            // Do not process
        }
        else
        {
            List<string> repDocuments = (List<string>)RequestStockHelper.GetItem("documents");
            List<string> repDocumentsContent = (List<string>)RequestStockHelper.GetItem("contents");

            if (repDocuments == null)
            {
                repDocuments = new List<string>();
            }

            if (repDocumentsContent == null)
            {
                repDocumentsContent = new List<string>();
            }

            DocumentQuery image = null;

            if (repDocuments.Count > 0)
            {

                image = DocumentHelper.GetDocuments("Bassol.ParallaxPhoto")
                                     .Path("/Parallax/%")
                                     .WhereNotIn("DocumentName", repDocuments)
                                     .OrderBy("NewID()")
                                     .TopN(1).CombineWithDefaultCulture(true);
            }
            else
            {
                image = DocumentHelper.GetDocuments("Bassol.ParallaxPhoto")
                                               .Path("/Parallax/%")
                                               .OrderBy("NewID()")
                                               .TopN(1).CombineWithDefaultCulture(true);
            }

            var content = DocumentHelper.GetDocuments("Bassol.ParallaxContent")
                                  .Path("/Parallax/%")
                                  .WhereNotIn("DocumentName", repDocumentsContent)
                                  .OrderBy("NewID()")
                                  .TopN(1).CombineWithDefaultCulture(true);

            if (content.Count == 0)
            {
                content = DocumentHelper.GetDocuments("Bassol.ParallaxContent")
                                  .Path("/Parallax/%")
                                  .OrderBy("NewID()")
                                  .TopN(1).CombineWithDefaultCulture(true);
            }

            if (image != null && image.Count > 0 && content.Count > 0)
            {
                string documentName = image.ToList().FirstOrDefault().DocumentName;

                repDocuments.Add(documentName);
                RequestStockHelper.Add("documents", repDocuments);

                string documentNameContent = content.ToList().FirstOrDefault().DocumentName;

                repDocumentsContent.Add(documentNameContent);
                RequestStockHelper.Add("contents", repDocumentsContent);

                rptImage.DataSource = image;
                rptImage.DataBind();
                Repeater rptContent = (Repeater)FindControl(rptImage, "rptContent");
                rptContent.DataSource = content;
                rptContent.DataBind();

               
            }
        }

    }


    /// <summary>
    /// Reloads the control data.
    /// </summary>
    public override void ReloadData()
    {
        base.ReloadData();

        SetupControl();
    }

    #endregion
}