Пример #1
0
        /// <summary>
        /// Get select options for filter field
        /// </summary>
        /// <param name="field"></param>
        /// <param name="fk"></param>
        /// <returns></returns>
        public static Dictionary <string, string> GetSelectOptions(this ParentField field, View view, string fk, int?top, bool forFilter)
        {
            Dictionary <string, string> selectOptions = null;
            Dictionary <string, object> values        = new Dictionary <string, object>();

            if (field != null)
            {
                if (forFilter)
                {
                    FormCollection collection = null;
                    Json.Filter    filter     = null;

                    //Init collection
                    collection = new FormCollection(ViewHelper.GetSessionState(view.Name + "Filter"));
                    if (collection != null && collection["jsonFilter"] != null)
                    {
                        try
                        {
                            filter = Json.JsonSerializer.Deserialize <Json.Filter>(collection["jsonFilter"]);
                        }
                        catch (Exception ex)
                        {
                            Map.Logger.Log(string.Empty, string.Empty, "GetSelectOptions", ex, 3, string.Empty);
                        }
                    }

                    //Init json filter
                    if (filter != null)
                    {
                        foreach (Json.Field jsonField in filter.Fields.Values)
                        {
                            if (jsonField.Value != null && !string.IsNullOrEmpty(jsonField.Value.ToString()))
                            {
                                values.Add(jsonField.Name, jsonField.Value);
                            }
                        }
                    }
                }

                //Init useUniqueName
                bool useUniqueName = field.ParentHtmlControlType == ParentHtmlControlType.InsideDependencyUniqueNames;

                //Extract selectOptions
                if (string.IsNullOrEmpty(fk))
                {
                    selectOptions = field.GetSelectOptions(view, forFilter, useUniqueName, top, values);
                }
                else
                {
                    selectOptions = field.GetSelectOptions(view, fk, top, values, forFilter);
                }
            }
            else
            {
                selectOptions = new Dictionary <string, string>();
            }

            return(selectOptions);
        }