コード例 #1
0
        private bool IsConditionDataMatch(string conditionData)
        {
            if (string.IsNullOrEmpty(conditionData))
            {
                return(true);
            }
            var jsonConverter = new DataSourceFiltersJsonConverter(_userConnection, _entity.Schema);

            jsonConverter.PreventRegisteringClientScript = true;
            var filterCollection = Json.Deserialize(conditionData, typeof(DataSourceFilterCollection), new List <JsonConverter> {
                jsonConverter
            }) as DataSourceFilterCollection;

            if (filterCollection == null)
            {
                return(true);
            }
            var esq = new EntitySchemaQuery(_entity.Schema);

            esq.AddColumn(_entity.Schema.PrimaryColumn.Name);
            esq.Filters.Add(filterCollection.ToEntitySchemaQueryFilterCollection(esq));
            var entity = esq.GetEntity(_userConnection, _entity.PrimaryColumnValue);

            return(entity != null);
        }
コード例 #2
0
        public virtual string GetSerializedFilter(Terrasoft.UI.WebControls.Controls.DataSource dataSource)
        {
            if (string.IsNullOrEmpty(FilterName))
            {
                FilterName = "FilterEdit";
            }
            var filter        = dataSource.CurrentStructure.Filters.FindByName(FilterName);
            var jsonConverter = new DataSourceFiltersJsonConverter(UserConnection, dataSource);

            return(Json.Serialize(filter, jsonConverter));
        }
コード例 #3
0
        public virtual void SetDeserializeFilter(string serializedString, Terrasoft.UI.WebControls.Controls.DataSource dataSource)
        {
            if (string.IsNullOrEmpty(serializedString))
            {
                if (string.IsNullOrEmpty(FilterName))
                {
                    FilterName = "FilterEdit";
                }
                var oldFilters = dataSource.CurrentStructure.Filters.FindByName(FilterName) as DataSourceFilterCollection;
                if (oldFilters != null)
                {
                    oldFilters.Clear();
                }
                return;
            }
            var jsonConverter = new DataSourceFiltersJsonConverter(UserConnection, dataSource)
            {
                PreventRegisteringClientScript = true
            };
            var filters = JsonConvert.DeserializeObject <DataSourceFilterCollection>(
                serializedString, jsonConverter);

            if (filters != null)
            {
                var existingFilterCollection = dataSource.CurrentStructure.Filters.FindByName(filters.Name) as DataSourceFilterCollection;
                if (existingFilterCollection != null)
                {
                    existingFilterCollection.Clear();
                    var filtersCollection = filters as DataSourceFilterCollection;
                    foreach (var filterItem in filtersCollection)
                    {
                        existingFilterCollection.Add(filterItem);
                    }
                    existingFilterCollection.LogicalOperation = filters.LogicalOperation;
                    existingFilterCollection.IsEnabled        = filters.IsEnabled;
                    existingFilterCollection.IsNot            = filters.IsNot;
                }
                else
                {
                    dataSource.CurrentStructure.Filters.Add(filters);
                }
            }
        }
コード例 #4
0
        private void AddColumnToEntitySchemaQuery(UserConnection userConnection, EntitySchemaQuery query, string caption, JArray columns,
                                                  Dictionary <string, string> dicEsq)
        {
            JObject column       = null;
            string  macrosColumn = string.Empty;

            for (int i = 0; i < columns.Count; i++)
            {
                var metaPathCaptionColumn = columns[i].Value <string>("metaPathCaption");
                var captionColumn         = columns[i].Value <string>("caption");
                metaPathCaptionColumn = metaPathCaptionColumn.Replace("\\", "\\\\");
                captionColumn         = captionColumn.Replace("\\", "\\\\");
                if (captionColumn.Trim() == caption.Trim())
                {
                    column       = columns[i] as JObject;
                    macrosColumn = captionColumn.Trim();
                    break;
                }
                else if (metaPathCaptionColumn.Trim() == caption.Trim())
                {
                    column       = columns[i] as JObject;
                    macrosColumn = metaPathCaptionColumn.Trim();
                    break;
                }
            }
            if (column == null)
            {
                return;
            }
            EntitySchemaQueryColumn queryColumn = null;

            foreach (var esqColumn in query.Columns)
            {
                if (esqColumn.Caption.Value == column.Value <string>("caption") ||
                    esqColumn.Caption.Value == column.Value <string>("metaPathCaption"))
                {
                    queryColumn = esqColumn;
                }
            }
            if (queryColumn == null)
            {
                if (string.IsNullOrEmpty(column.Value <string>("aggregationType")) ||
                    string.Compare(column.Value <string>("aggregationType"), "None", true) == 0)
                {
                    queryColumn = query.AddColumn(
                        query.RootSchema.GetSchemaColumnPathByMetaPath(column.Value <string>("metaPath")));
                    if (queryColumn.DisplayExpression != null)
                    {
                        string displayValueMetaPath = queryColumn.DisplayExpression.Path;
                        query.RemoveColumn(queryColumn.Name);
                        queryColumn = query.AddColumn(displayValueMetaPath);
                    }
                }
                else
                {
                    EntitySchemaQuery subQuery;
                    string            queryColumnName = StringUtilities.CleanUpColumnName(
                        query.RootSchema.GetSchemaColumnPathByMetaPath(column.Value <string>("metaPath")));
                    string uniqueSuffix = query.Columns.Any(x => x.Name == queryColumnName)
                                                ? query.Columns.Count.ToString()
                                                : string.Empty;
                    queryColumn = query.AddColumn(
                        query.RootSchema.GetSchemaColumnPathByMetaPath(column.Value <string>("metaPath")),
                        (AggregationTypeStrict)Enum.Parse(typeof(AggregationTypeStrict),
                                                          column.Value <string>("aggregationType")),
                        out subQuery);
                    if (!string.IsNullOrEmpty(column.Value <string>("subFilters")))
                    {
                        var converter = new DataSourceFiltersJsonConverter(userConnection, subQuery.RootSchema)
                        {
                            PreventRegisteringClientScript = true
                        };
                        var filters = JsonConvert.DeserializeObject <DataSourceFilterCollection>(
                            column.Value <string>("subFilters"), converter);
                        EntitySchemaQueryFilterCollection esqFilters =
                            filters.ToEntitySchemaQueryFilterCollection(subQuery);
                        DisableEmptyEntitySchemaQueryFilters(esqFilters);
                        subQuery.Filters.Add(esqFilters);
                    }
                    queryColumn.Name = queryColumnName + uniqueSuffix;
                }
            }
            queryColumn.UId = !string.IsNullOrEmpty(column.Value <string>("columnUId")) &&
                              !new Guid(column.Value <string>("columnUId")).IsEmpty()
                                ? new Guid(column.Value <string>("columnUId"))
                                : Guid.NewGuid();
            if (!string.IsNullOrEmpty(column.Value <string>("caption")))
            {
                queryColumn.Caption = column.Value <string>("caption");
            }
            else if (!string.IsNullOrEmpty(column.Value <string>("metaPathCaption")))
            {
                queryColumn.Caption = column.Value <string>("metaPathCaption");
            }
            queryColumn.IsAlwaysSelect = true;
            queryColumn.IsVisible      = true;
            dicEsq.Add(macrosColumn, queryColumn.Name);
        }