Пример #1
0
        /// <summary>
        /// Returns a collection of string Guid pairs from the business object
        /// collection provided. Each pair consists of a string version of a
        /// business object and the object's ID.
        /// </summary>
        /// <param name="col">The business object collection</param>
        /// <param name="sortByDisplayValue">Must the collection be sorted by the display value or not</param>
        /// <param name="coverter">The delegated converter that converts a primary key to the appropriate string</param>
        /// <returns>Returns a collection of display-value pairs</returns>
        public static Dictionary <string, string> CreateDisplayValueDictionary
            (IBusinessObjectCollection col, bool sortByDisplayValue, ConvertPrimaryKeyGetAsValueToString coverter)
        {
            if (sortByDisplayValue)
            {
                var keyLookupList = new SortedDictionary <string, string>();
                foreach (BusinessObject bo in col)
                {
                    var stringValue = GetAvailableDisplayValue(keyLookupList, bo.ToString());
                    keyLookupList.Add(stringValue, coverter(bo.ID.GetAsValue()));
                }

                var lookupList = new Dictionary <string, string>();
                foreach (var key in keyLookupList.Keys)
                {
                    AddBusinessObjectToLookupList(lookupList, keyLookupList[key], key);
                }
                return(lookupList);
            }
            else
            {
                var lookupList = new Dictionary <string, string>();
                foreach (BusinessObject bo in col)
                {
                    var stringValue = GetAvailableDisplayValue(lookupList, bo.ToString());
                    var objectID    = coverter(bo.ID.GetAsValue());
                    AddBusinessObjectToLookupList(lookupList, objectID, stringValue);
                }
                return(lookupList);
            }
        }
        /// <summary>
        /// Returns a collection of string Guid pairs from the business object
        /// collection provided. Each pair consists of a string version of a
        /// business object and the object's ID.
        /// </summary>
        /// <param name="col">The business object collection</param>
        /// <param name="sortByDisplayValue">Must the collection be sorted by the display value or not</param>
        /// <param name="coverter">The delegated converter that converts a primary key to the appropriate string</param>
        /// <returns>Returns a collection of display-value pairs</returns>
        public static Dictionary<string, string> CreateDisplayValueDictionary
            (IBusinessObjectCollection col, bool sortByDisplayValue, ConvertPrimaryKeyGetAsValueToString coverter)
        {
            if (sortByDisplayValue)
            {
                var keyLookupList = new SortedDictionary<string, string>();
                foreach (BusinessObject bo in col)
                {
                    var stringValue = GetAvailableDisplayValue(keyLookupList, bo.ToString());
                    keyLookupList.Add(stringValue, coverter(bo.ID.GetAsValue()));
                }

                var lookupList = new Dictionary<string, string>();
                foreach (var key in keyLookupList.Keys)
                {
                    AddBusinessObjectToLookupList(lookupList, keyLookupList[key], key);
                }
                return lookupList;
            }
            else
            {
                var lookupList = new Dictionary<string, string>();
                foreach (BusinessObject bo in col)
                {
                    var stringValue = GetAvailableDisplayValue(lookupList, bo.ToString());
                    var objectID = coverter(bo.ID.GetAsValue());
                    AddBusinessObjectToLookupList(lookupList, objectID, stringValue);
                }
                return lookupList;
            }

        }