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/TDijk1/erp-apps.eu/wwwroot/ERPApps/ERPWebParts/MultipleChoiceViewer.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CMS.SiteProvider;
using CMS.CMSHelper;
using System.Data;
using CMS.GlobalHelper;
using CMS.Helpers;
using CMS.CustomTables;
using CMS.Membership;

public partial class ERPApps_ERPWebParts_MultipleChoiceViewer : CMS.FormControls.FormEngineUserControl
{
    #region "Properties"

    /// <summary>
    /// Custom table name to be used as a data source
    /// </summary>
    public string CustomTableName
    {
        get
        {
            return ValidationHelper.GetString(GetValue("CustomTableName"), String.Empty);
        }
        set
        {
            SetValue("CustomTableName", value);
        }
    }

    string mValue = null;
    public override Object Value
    {
        get
        {
            return mValue;
        }
        set
        {
            // Ensure drop down list options
            mValue = ValidationHelper.GetString(value, null);
            InitViewer();
        }
    }

    public string StringValue
    {
        get
        {
            return mValue;
        }
    }

    #endregion

    protected void InitViewer()
    {
        if (!DataHelper.IsEmpty(StringValue))
        {
            Dictionary<int, string> options = LoadOptions();
            string result = "";

            foreach (string option in StringValue.Split('|'))
            {
                int key = ValidationHelper.GetInteger(option, 0);
                if (!options.ContainsKey(key))
                    continue;

                result += options[key] + ", ";
            }

            lblResult.Text = result.Substring(0, result.Length - 2);
        }
    }

    /// <summary>
    /// Load available options from custom table.
    /// </summary>
    /// <returns></returns>
    protected Dictionary<int, string> LoadOptions()
    {
        Dictionary<int, string> result = new Dictionary<int, string>();

        DataSet dsIndustries = CustomTableItemProvider.GetItems(CustomTableName, null, null);

        foreach (DataRow row in dsIndustries.Tables[0].Rows)
        {
            result.Add(ValidationHelper.GetInteger(row["ItemID"], 0), ValidationHelper.GetString(row["ItemName"], ""));
        }

        return result;
    }
}