/// <summary>
 /// Initializes the dependent fields.
 /// </summary>
 private void InitializeDependentFields()
 {
     this.Field             = UPCRMField.FieldWithFieldIdInfoAreaId(this.FieldId, this.Alternate.ParentExpand.InfoAreaId);
     this.boolEmptyCheck    = this.Field.FieldType == "B";
     this.numericEmptyCheck = this.Field.IsNumericField || this.Field.IsCatalogField;
     if (string.IsNullOrEmpty(this.FieldValue))
     {
         this.EmptyFieldValue = true;
     }
     else if (this.numericEmptyCheck && this.FieldValue == "0")
     {
         this.EmptyFieldValue = true;
     }
     else if (this.boolEmptyCheck && this.FieldValue == "false")
     {
         this.EmptyFieldValue = true;
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="UPConfigCatalogAttributes"/> class.
        /// </summary>
        /// <param name="filter">
        /// The filter.
        /// </param>
        public UPConfigCatalogAttributes(UPConfigFilter filter)
        {
            var rootTable = filter?.RootTable;
            var arr       = rootTable?.QueryConditions(string.Empty, false);

            if (arr == null || arr.Count != 1)
            {
                return;
            }

            var codeQueryCondition = arr[0];

            this.CrmField  = UPCRMField.FieldWithFieldIdInfoAreaId(codeQueryCondition.FieldId, rootTable.InfoAreaId);
            this.FieldInfo = UPCRMDataStore.DefaultStore.FieldInfoForField(this.CrmField);
            if (this.FieldInfo?.FieldType == "X")
            {
                this.FixedCatalog  = true;
                this.CatalogNumber = this.FieldInfo.CatNo;
            }
            else if (this.FieldInfo?.FieldType == "K")
            {
                this.FixedCatalog  = false;
                this.CatalogNumber = this.FieldInfo.CatNo;
            }
            else
            {
                this.FixedCatalog  = false;
                this.CatalogNumber = -1;
            }

            arr = rootTable.QueryConditions("Image", false);
            var imageQueryCondition = arr != null && arr.Count > 0 ? arr[0] : null;

            arr = rootTable.QueryConditions("Color", false);
            var colorKeyQueryCondition = arr != null && arr.Count > 0 ? arr[0] : null;

            var catCodes   = codeQueryCondition?.FieldValues;
            var imageNames = imageQueryCondition?.FieldValues;
            var colorKeys  = colorKeyQueryCondition?.FieldValues;

            var catCodesTemp = catCodes != null ? new List <object>(catCodes) : new List <object>();

            catCodesTemp.Remove(string.Empty);
            catCodes = catCodesTemp;

            int count = catCodes.Count, colorKeysCount = colorKeys?.Count ?? 0, imageNamesCount = imageNames?.Count ?? 0;

            var dict          = new Dictionary <int, UPConfigCatalogValueAttributes>(count);
            var rawDict       = new Dictionary <string, UPConfigCatalogValueAttributes>(count);
            var orderedValues = new List <UPConfigCatalogValueAttributes>(count);

            for (var i = 0; i < count; i++)
            {
                var image = i < imageNamesCount ? imageNames[i] as string : string.Empty;
                var color = i < colorKeysCount ? colorKeys[i] as string : string.Empty;
                if (image.StartsWith("#"))
                {
                    image = image.Substring(1);
                }

                if (color.StartsWith("#"))
                {
                    color = color.Substring(1);
                }

                var valueAttr = this.CatalogNumber >= 0
                                    ? new UPConfigCatalogValueAttributes(
                    JObjectExtensions.ToInt(catCodes[i]),
                    color,
                    image)
                                    : new UPConfigCatalogValueAttributes(
                    JObjectExtensions.ToInt(catCodes[i]),
                    color,
                    image);

                dict.SetObjectForKey(valueAttr, valueAttr.Code);
                rawDict.SetObjectForKey(valueAttr, valueAttr.RawValue);
                orderedValues.Add(valueAttr);
            }

            this.ValuesByCode     = dict;
            this.ValuesByRawValue = rawDict;
            this.ValueArray       = orderedValues;
        }